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