acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

ImgViewerBmp.ino (6662B)

      1 /*******************************************************************************
      2  * BMP Image Viewer
      3  * This is a simple BMP image viewer example
      4  * Image Source: https://github.blog/2014-11-24-from-sticker-to-sculpture-the-making-of-the-octocat-figurine/
      5  *
      6  * Setup steps:
      7  * 1. Change your LCD parameters in Arduino_GFX setting
      8  * 2. Upload BMP file
      9  *   FFat (ESP32):
     10  *     upload FFat (FatFS) data with ESP32 Sketch Data Upload:
     11  *     ESP32: https://github.com/lorol/arduino-esp32fs-plugin
     12  *   LittleFS (ESP32 / ESP8266 / Pico):
     13  *     upload LittleFS data with ESP8266 LittleFS Data Upload:
     14  *     ESP32: https://github.com/lorol/arduino-esp32fs-plugin
     15  *     ESP8266: https://github.com/earlephilhower/arduino-esp8266littlefs-plugin
     16  *     Pico: https://github.com/earlephilhower/arduino-pico-littlefs-plugin.git
     17  *   SPIFFS (ESP32):
     18  *     upload SPIFFS data with ESP32 Sketch Data Upload:
     19  *     ESP32: https://github.com/lorol/arduino-esp32fs-plugin
     20  *   SD:
     21  *     Most Arduino system built-in support SD file system.
     22  *     Wio Terminal require extra dependant Libraries:
     23  *     - Seeed_Arduino_FS: https://github.com/Seeed-Studio/Seeed_Arduino_FS.git
     24  *     - Seeed_Arduino_SFUD: https://github.com/Seeed-Studio/Seeed_Arduino_SFUD.git
     25  ******************************************************************************/
     26 // #define BMP_FILENAME "/octocatS.bmp" // 243x128@IndexedColor
     27 #define BMP_FILENAME "/octocatM.bmp" // 456x240@16bit
     28 // #define BMP_FILENAME "/octocatL.bmp" // 608x320@24bit
     29 
     30 /*******************************************************************************
     31  * Start of Arduino_GFX setting
     32  *
     33  * Arduino_GFX try to find the settings depends on selected board in Arduino IDE
     34  * Or you can define the display dev kit not in the board list
     35  * Defalult pin list for non display dev kit:
     36  * Arduino Nano, Micro and more: CS:  9, DC:  8, RST:  7, BL:  6, SCK: 13, MOSI: 11, MISO: 12
     37  * ESP32 various dev board     : CS:  5, DC: 27, RST: 33, BL: 22, SCK: 18, MOSI: 23, MISO: nil
     38  * ESP32-C3 various dev board  : CS:  7, DC:  2, RST:  1, BL:  3, SCK:  4, MOSI:  6, MISO: nil
     39  * ESP32-S2 various dev board  : CS: 34, DC: 38, RST: 33, BL: 21, SCK: 36, MOSI: 35, MISO: nil
     40  * ESP32-S3 various dev board  : CS: 40, DC: 41, RST: 42, BL: 48, SCK: 36, MOSI: 35, MISO: nil
     41  * ESP8266 various dev board   : CS: 15, DC:  4, RST:  2, BL:  5, SCK: 14, MOSI: 13, MISO: 12
     42  * Raspberry Pi Pico dev board : CS: 17, DC: 27, RST: 26, BL: 28, SCK: 18, MOSI: 19, MISO: 16
     43  * RTL8720 BW16 old patch core : CS: 18, DC: 17, RST:  2, BL: 23, SCK: 19, MOSI: 21, MISO: 20
     44  * RTL8720_BW16 Official core  : CS:  9, DC:  8, RST:  6, BL:  3, SCK: 10, MOSI: 12, MISO: 11
     45  * RTL8722 dev board           : CS: 18, DC: 17, RST: 22, BL: 23, SCK: 13, MOSI: 11, MISO: 12
     46  * RTL8722_mini dev board      : CS: 12, DC: 14, RST: 15, BL: 13, SCK: 11, MOSI:  9, MISO: 10
     47  * Seeeduino XIAO dev board    : CS:  3, DC:  2, RST:  1, BL:  0, SCK:  8, MOSI: 10, MISO:  9
     48  * Teensy 4.1 dev board        : CS: 39, DC: 41, RST: 40, BL: 22, SCK: 13, MOSI: 11, MISO: 12
     49  ******************************************************************************/
     50 #include <Arduino_GFX_Library.h>
     51 
     52 #define GFX_BL DF_GFX_BL // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
     53 
     54 /* More dev device declaration: https://github.com/moononournation/Arduino_GFX/wiki/Dev-Device-Declaration */
     55 #if defined(DISPLAY_DEV_KIT)
     56 Arduino_GFX *gfx = create_default_Arduino_GFX();
     57 #else /* !defined(DISPLAY_DEV_KIT) */
     58 
     59 /* More data bus class: https://github.com/moononournation/Arduino_GFX/wiki/Data-Bus-Class */
     60 Arduino_DataBus *bus = create_default_Arduino_DataBus();
     61 
     62 /* More display class: https://github.com/moononournation/Arduino_GFX/wiki/Display-Class */
     63 Arduino_GFX *gfx = new Arduino_ILI9341(bus, DF_GFX_RST, 3 /* rotation */, false /* IPS */);
     64 
     65 #endif /* !defined(DISPLAY_DEV_KIT) */
     66 /*******************************************************************************
     67  * End of Arduino_GFX setting
     68  ******************************************************************************/
     69 
     70 /* Wio Terminal */
     71 #if defined(ARDUINO_ARCH_SAMD) && defined(SEEED_GROVE_UI_WIRELESS)
     72 #include <Seeed_FS.h>
     73 #include <SD/Seeed_SD.h>
     74 #elif defined(TARGET_RP2040)
     75 #include <LittleFS.h>
     76 #include <SD.h>
     77 #elif defined(ESP32)
     78 #include <FFat.h>
     79 #include <LittleFS.h>
     80 #include <SPIFFS.h>
     81 #include <SD.h>
     82 #elif defined(ESP8266)
     83 #include <LittleFS.h>
     84 #include <SD.h>
     85 #else
     86 #include <SD.h>
     87 #endif
     88 
     89 #include "BmpClass.h"
     90 static BmpClass bmpClass;
     91 
     92 // pixel drawing callback
     93 static void bmpDrawCallback(int16_t x, int16_t y, uint16_t *bitmap, int16_t w, int16_t h)
     94 {
     95   // Serial.printf("Draw pos = %d, %d. size = %d x %d\n", x, y, w, h);
     96   gfx->draw16bitRGBBitmap(x, y, bitmap, w, h);
     97 }
     98 
     99 void setup()
    100 {
    101   Serial.begin(115200);
    102   // Serial.setDebugOutput(true);
    103   // while(!Serial);
    104   Serial.println("BMP Image Viewer");
    105 
    106 #ifdef GFX_EXTRA_PRE_INIT
    107   GFX_EXTRA_PRE_INIT();
    108 #endif
    109 
    110   // Init Display
    111   gfx->begin();
    112   gfx->fillScreen(BLACK);
    113 
    114 #ifdef GFX_BL
    115   pinMode(GFX_BL, OUTPUT);
    116   digitalWrite(GFX_BL, HIGH);
    117 #endif
    118 
    119 /* Wio Terminal */
    120 #if defined(ARDUINO_ARCH_SAMD) && defined(SEEED_GROVE_UI_WIRELESS)
    121   if (!SD.begin(SDCARD_SS_PIN, SDCARD_SPI, 4000000UL))
    122 #elif defined(TARGET_RP2040)
    123   if (!LittleFS.begin())
    124   // if (!SD.begin(SS))
    125 #elif defined(ESP32)
    126   // if (!FFat.begin())
    127   if (!LittleFS.begin())
    128   // if (!SPIFFS.begin())
    129   // if (!SD.begin(SS))
    130 #elif defined(ESP8266)
    131   if (!LittleFS.begin())
    132   // if (!SD.begin())
    133 #else
    134   if (!SD.begin())
    135 #endif
    136   {
    137     Serial.println(F("ERROR: File System Mount Failed!"));
    138     gfx->println(F("ERROR: File System Mount Failed!"));
    139   }
    140   else
    141   {
    142     unsigned long start = millis();
    143 
    144 #if defined(ARDUINO_ARCH_SAMD) && defined(SEEED_GROVE_UI_WIRELESS)
    145     File bmpFile = SD.open(BMP_FILENAME, "r");
    146 #elif defined(TARGET_RP2040)
    147     File bmpFile = LittleFS.open(BMP_FILENAME, "r");
    148     // File bmpFile = SD.open(BMP_FILENAME, "r");
    149 #elif defined(ESP32)
    150     // File bmpFile = FFat.open(BMP_FILENAME, "r");
    151     File bmpFile = LittleFS.open(BMP_FILENAME, "r");
    152     // File bmpFile = SPIFFS.open(BMP_FILENAME, "r");
    153     // File bmpFile = SD.open(BMP_FILENAME, "r");
    154 #elif defined(ESP8266)
    155     File bmpFile = LittleFS.open(BMP_FILENAME, "r");
    156     // File bmpFile = SD.open(BMP_FILENAME, "r");
    157 #else
    158     File bmpFile = SD.open(BMP_FILENAME, FILE_READ);
    159 #endif
    160 
    161     // read BMP file header
    162     bmpClass.draw(
    163         &bmpFile, bmpDrawCallback, false /* useBigEndian */,
    164         0 /* x */, 0 /* y */, gfx->width() /* widthLimit */, gfx->height() /* heightLimit */);
    165 
    166     bmpFile.close();
    167 
    168     Serial.print("Time used: ");
    169     Serial.println(millis() - start);
    170   }
    171 }
    172 
    173 void loop()
    174 {
    175 }