GxEPD2_SD_AVR_Example.ino 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. // GxEPD2_SD_AVR_Example : Display Library example for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
  2. // Requires HW SPI and Adafruit_GFX. Caution: the e-paper panels require 3.3V supply AND data lines!
  3. //
  4. // Display Library based on Demo Example from Good Display: http://www.e-paper-display.com/download_list/downloadcategoryid=34&isMode=false.html
  5. //
  6. // BMP handling code extracts taken from: https://github.com/prenticedavid/MCUFRIEND_kbv/tree/master/examples/showBMP_kbv_Uno
  7. //
  8. // Author: Jean-Marc Zingg
  9. //
  10. // Version: see library.properties
  11. //
  12. // Library: https://github.com/ZinggJM/GxEPD2
  13. // Supporting Arduino Forum Topics:
  14. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  15. // Good Display ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  16. // mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
  17. // BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
  18. // NOTE: connect 3.3k pull-down from D8 to GND if your board or shield has level converters
  19. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case, or 4k7 pull-down
  20. // mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
  21. // BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  22. // NOTE: connect 3.3k pull-down from GPIO15 to GND if your board or shield has level converters
  23. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case, or 3.3k pull-down
  24. // mapping of Waveshare e-Paper ESP8266 Driver Board, new version (see GxEPD2_boards_added.h for old version)
  25. // BUSY -> GPIO5, RST -> GPIO2, DC -> GPIO4, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  26. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, add a 3.3k pull-down in case
  27. // the e-Paper ESP8266 Driver Board should have no boot mode issue, as it doesn't use level converters
  28. // mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
  29. // NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
  30. // BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V
  31. // mapping of Waveshare ESP32 Driver Board
  32. // BUSY -> 25, RST -> 26, DC -> 27, CS-> 15, CLK -> 13, DIN -> 14
  33. // NOTE: this board uses "unusual" SPI pins and requires re-mapping of HW SPI to these pins in SPIClass
  34. // see example GxEPD2_WS_ESP32_Driver.ino, it shows how this can be done easily
  35. // new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
  36. // BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
  37. // mapping suggestion for AVR, UNO, NANO etc.
  38. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11
  39. // mapping suggestion for Arduino MEGA
  40. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 53, CLK -> 52, DIN -> 51
  41. //
  42. // **** NOTE that the mapping suggestion may need modification depending on SD board used! ****
  43. // ********************************************************************************************
  44. //
  45. //#define SD_CS SS // e.g. for RobotDyn Wemos D1 mini SD board
  46. //#define EPD_CS D1 // alternative I use with RobotDyn Wemos D1 mini SD board
  47. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  48. //#include <GFX.h>
  49. // Note: if you use this with ENABLE_GxEPD2_GFX 1:
  50. // uncomment it in GxEPD2_GFX.h too, or add #include <GFX.h> before any #include <GxEPD2_GFX.h>
  51. #include <GxEPD2_BW.h>
  52. #include <GxEPD2_3C.h>
  53. #include <Fonts/FreeMonoBold9pt7b.h>
  54. #if defined(ESP32)
  55. // has support for FAT32 support with long filenames
  56. #include "FS.h"
  57. #include "SD.h"
  58. #include "SPI.h"
  59. #define SdFile File
  60. #define seekSet seek
  61. #else
  62. // include SdFat for FAT32 support with long filenames; available through Library Manager
  63. #include <SdFat.h>
  64. SdFat SD;
  65. #endif
  66. #if defined(__AVR)
  67. #define SD_CS 6 // adapt to your wiring
  68. #define EPD_CS SS // adapt to your wiring
  69. // select one and adapt to your mapping
  70. //GxEPD2_154 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEP015OC1 no longer available
  71. //GxEPD2_154_D67 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEH0154D67
  72. //GxEPD2_154_D67 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEH0154D67
  73. //GxEPD2_154_T8 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEW0154T8 152x152
  74. //GxEPD2_154_M09 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEW0154M09 200x200
  75. //GxEPD2_154_M10 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEW0154M10 152x152
  76. //GxEPD2_213 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  77. //GxEPD2_213_B72 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEH0213B72
  78. //GxEPD2_213_B73 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEH0213B73
  79. //GxEPD2_213_flex display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEW0213I5F
  80. //GxEPD2_290 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  81. //GxEPD2_290_T5 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEW029T5
  82. //GxEPD2_260 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  83. //GxEPD2_270 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  84. //GxEPD2_371 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  85. //GxEPD2_420 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  86. //GxEPD2_583 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  87. //GxEPD2_583_T8 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  88. //GxEPD2_750 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  89. //GxEPD2_750_T7 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEW075T7 800x480
  90. // 3-color e-papers
  91. // !!! can't be used for this //GxEPD2_154c display(GxEPD2_154c(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEW0154Z04 no longer available
  92. //GxEPD2_154_Z90c display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEH0154Z90
  93. //GxEPD2_213c display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  94. //GxEPD2_290c display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  95. //GxEPD2_270c display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  96. //GxEPD2_420c display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  97. //GxEPD2_750c display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  98. //GxEPD2_750c_Z08 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7); // GDEW075Z08 800x480
  99. #endif
  100. // non-AVR board can also be used with GxEPD2 base display classes, e.g. for SD bitmap drawing
  101. // uncomment your display for your board in the following included header file and adapt to your mapping
  102. #include "GxEPD2_SD_AVR_boards_added.h"
  103. // function declaration with default parameter
  104. void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color = true);
  105. void setup()
  106. {
  107. Serial.begin(115200);
  108. Serial.println();
  109. Serial.println(F("setup"));
  110. display.init(115200);
  111. Serial.print(F("Initializing SD card..."));
  112. if (!SD.begin(SD_CS))
  113. {
  114. Serial.println(F("SD failed!"));
  115. return;
  116. }
  117. Serial.println(F("SD OK!"));
  118. drawBitmaps_200x200();
  119. drawBitmaps_other();
  120. //drawBitmaps_test();
  121. }
  122. void loop(void)
  123. {
  124. }
  125. void drawBitmaps_200x200()
  126. {
  127. int16_t x = (int16_t(display.WIDTH) - 200) / 2;
  128. int16_t y = (int16_t(display.HEIGHT) - 200) / 2;
  129. drawBitmapFromSD("logo200x200.bmp", x, y);
  130. delay(2000);
  131. drawBitmapFromSD("first200x200.bmp", x, y);
  132. delay(2000);
  133. drawBitmapFromSD("second200x200.bmp", x, y);
  134. delay(2000);
  135. drawBitmapFromSD("third200x200.bmp", x, y);
  136. delay(2000);
  137. drawBitmapFromSD("fourth200x200.bmp", x, y);
  138. delay(2000);
  139. drawBitmapFromSD("fifth200x200.bmp", x, y);
  140. delay(2000);
  141. drawBitmapFromSD("sixth200x200.bmp", x, y);
  142. delay(2000);
  143. drawBitmapFromSD("seventh200x200.bmp", x, y);
  144. delay(2000);
  145. drawBitmapFromSD("eighth200x200.bmp", x, y);
  146. delay(2000);
  147. }
  148. void drawBitmaps_other()
  149. {
  150. int16_t w2 = display.WIDTH / 2;
  151. int16_t h2 = display.HEIGHT / 2;
  152. drawBitmapFromSD("parrot.bmp", w2 - 64, h2 - 80);
  153. delay(2000);
  154. drawBitmapFromSD("betty_1.bmp", w2 - 100, h2 - 160);
  155. delay(2000);
  156. drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
  157. delay(2000);
  158. drawBitmapFromSD("marilyn_240x240x8.bmp", w2 - 120, h2 - 120);
  159. delay(2000);
  160. drawBitmapFromSD("miniwoof.bmp", w2 - 60, h2 - 80);
  161. delay(2000);
  162. drawBitmapFromSD("t200x200.bmp", w2 - 100, h2 - 100);
  163. delay(2000);
  164. drawBitmapFromSD("test.bmp", w2 - 120, h2 - 160);
  165. delay(2000);
  166. drawBitmapFromSD("tiger.bmp", w2 - 160, h2 - 120);
  167. delay(2000);
  168. drawBitmapFromSD("tiger_178x160x4.bmp", w2 - 89, h2 - 80);
  169. delay(2000);
  170. drawBitmapFromSD("tiger_240x317x4.bmp", w2 - 120, h2 - 160);
  171. delay(2000);
  172. drawBitmapFromSD("tiger_320x200x24.bmp", w2 - 160, h2 - 100);
  173. delay(2000);
  174. drawBitmapFromSD("tiger16T.bmp", w2 - 160, h2 - 120);
  175. delay(2000);
  176. drawBitmapFromSD("woof.bmp", w2 - 120, h2 - 160);
  177. delay(2000);
  178. drawBitmapFromSD("bitmap640x384_1.bmp", 0, 0);
  179. delay(2000);
  180. }
  181. void drawBitmaps_test()
  182. {
  183. int16_t w2 = display.WIDTH / 2;
  184. int16_t h2 = display.HEIGHT / 2;
  185. drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
  186. delay(2000);
  187. }
  188. static const uint16_t input_buffer_pixels = 20; // may affect performance
  189. static const uint16_t max_row_width = 640; // for up to 7.5" display
  190. static const uint16_t max_palette_pixels = 256; // for depth <= 8
  191. uint8_t input_buffer[3 * input_buffer_pixels]; // up to depth 24
  192. uint8_t output_row_mono_buffer[max_row_width / 8]; // buffer for at least one row of b/w bits
  193. uint8_t output_row_color_buffer[max_row_width / 8]; // buffer for at least one row of color bits
  194. uint8_t mono_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 b/w
  195. uint8_t color_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 c/w
  196. void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color)
  197. {
  198. SdFile file;
  199. bool valid = false; // valid format to be handled
  200. bool flip = true; // bitmap is stored bottom-to-top
  201. uint32_t startTime = millis();
  202. //Serial.println(); Serial.print(x); Serial.print(" "); Serial.print(y); Serial.print(" "); Serial.println(filename);
  203. if ((x >= int16_t(display.WIDTH)) || (y >= int16_t(display.HEIGHT))) return;
  204. Serial.println();
  205. Serial.print(F("Loading image '"));
  206. Serial.print(filename);
  207. Serial.println('\'');
  208. #if defined(ESP32)
  209. file = SD.open(String("/") + filename, FILE_READ);
  210. if (!file)
  211. {
  212. Serial.print(F("File not found"));
  213. return;
  214. }
  215. #else
  216. if (!file.open(filename, FILE_READ))
  217. {
  218. Serial.print(F("File not found"));
  219. return;
  220. }
  221. #endif
  222. // Parse BMP header
  223. if (read16(file) == 0x4D42) // BMP signature
  224. {
  225. uint32_t fileSize = read32(file);
  226. uint32_t creatorBytes = read32(file);
  227. uint32_t imageOffset = read32(file); // Start of image data
  228. uint32_t headerSize = read32(file);
  229. uint32_t width = read32(file);
  230. uint32_t height = read32(file);
  231. uint16_t planes = read16(file);
  232. uint16_t depth = read16(file); // bits per pixel
  233. uint32_t format = read32(file);
  234. if ((planes == 1) && ((format == 0) || (format == 3))) // uncompressed is handled, 565 also
  235. {
  236. Serial.print(F("File size: ")); Serial.println(fileSize);
  237. Serial.print(F("Image Offset: ")); Serial.println(imageOffset);
  238. Serial.print(F("Header size: ")); Serial.println(headerSize);
  239. Serial.print(F("Bit Depth: ")); Serial.println(depth);
  240. Serial.print(F("Image size: "));
  241. Serial.print(width);
  242. Serial.print('x');
  243. Serial.println(height);
  244. // BMP rows are padded (if needed) to 4-byte boundary
  245. uint32_t rowSize = (width * depth / 8 + 3) & ~3;
  246. if (height < 0)
  247. {
  248. height = -height;
  249. flip = false;
  250. }
  251. uint16_t w = width;
  252. uint16_t h = height;
  253. if ((x + w - 1) >= int16_t(display.WIDTH)) w = int16_t(display.WIDTH) - x;
  254. if ((y + h - 1) >= int16_t(display.HEIGHT)) h = int16_t(display.HEIGHT) - y;
  255. if (w <= max_row_width) // handle with direct drawing
  256. {
  257. valid = true;
  258. uint8_t bitmask = 0xFF;
  259. uint8_t bitshift = 8 - depth;
  260. uint16_t red, green, blue;
  261. bool whitish, colored;
  262. if (depth == 1) with_color = false;
  263. if (depth <= 8)
  264. {
  265. if (depth < 8) bitmask >>= depth;
  266. //file.seekSet(54); //palette is always @ 54
  267. file.seekSet(imageOffset - (4 << depth)); // 54 for regular, diff for colorsimportant
  268. for (uint16_t pn = 0; pn < (1 << depth); pn++)
  269. {
  270. blue = file.read();
  271. green = file.read();
  272. red = file.read();
  273. file.read();
  274. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  275. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  276. if (0 == pn % 8) mono_palette_buffer[pn / 8] = 0;
  277. mono_palette_buffer[pn / 8] |= whitish << pn % 8;
  278. if (0 == pn % 8) color_palette_buffer[pn / 8] = 0;
  279. color_palette_buffer[pn / 8] |= colored << pn % 8;
  280. }
  281. }
  282. display.clearScreen();
  283. uint32_t rowPosition = flip ? imageOffset + (height - h) * rowSize : imageOffset;
  284. for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
  285. {
  286. uint32_t in_remain = rowSize;
  287. uint32_t in_idx = 0;
  288. uint32_t in_bytes = 0;
  289. uint8_t in_byte = 0; // for depth <= 8
  290. uint8_t in_bits = 0; // for depth <= 8
  291. uint8_t out_byte = 0xFF; // white (for w%8!=0 border)
  292. uint8_t out_color_byte = 0xFF; // white (for w%8!=0 border)
  293. uint32_t out_idx = 0;
  294. file.seekSet(rowPosition);
  295. for (uint16_t col = 0; col < w; col++) // for each pixel
  296. {
  297. // Time to read more pixel data?
  298. if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
  299. {
  300. in_bytes = file.read(input_buffer, in_remain > sizeof(input_buffer) ? sizeof(input_buffer) : in_remain);
  301. in_remain -= in_bytes;
  302. in_idx = 0;
  303. }
  304. switch (depth)
  305. {
  306. case 24:
  307. blue = input_buffer[in_idx++];
  308. green = input_buffer[in_idx++];
  309. red = input_buffer[in_idx++];
  310. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  311. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  312. break;
  313. case 16:
  314. {
  315. uint8_t lsb = input_buffer[in_idx++];
  316. uint8_t msb = input_buffer[in_idx++];
  317. if (format == 0) // 555
  318. {
  319. blue = (lsb & 0x1F) << 3;
  320. green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
  321. red = (msb & 0x7C) << 1;
  322. }
  323. else // 565
  324. {
  325. blue = (lsb & 0x1F) << 3;
  326. green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
  327. red = (msb & 0xF8);
  328. }
  329. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  330. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  331. }
  332. break;
  333. case 1:
  334. case 4:
  335. case 8:
  336. {
  337. if (0 == in_bits)
  338. {
  339. in_byte = input_buffer[in_idx++];
  340. in_bits = 8;
  341. }
  342. uint16_t pn = (in_byte >> bitshift) & bitmask;
  343. whitish = mono_palette_buffer[pn / 8] & (0x1 << pn % 8);
  344. colored = color_palette_buffer[pn / 8] & (0x1 << pn % 8);
  345. in_byte <<= depth;
  346. in_bits -= depth;
  347. }
  348. break;
  349. }
  350. if (whitish)
  351. {
  352. //out_byte |= 0x80 >> col % 8; // not black
  353. //out_color_byte |= 0x80 >> col % 8; // not colored
  354. // keep white
  355. }
  356. else if (colored && with_color)
  357. {
  358. //out_byte |= 0x80 >> col % 8; // not black
  359. out_color_byte &= ~(0x80 >> col % 8); // colored
  360. }
  361. else
  362. {
  363. //out_color_byte |= 0x80 >> col % 8; // not colored
  364. out_byte &= ~(0x80 >> col % 8); // black
  365. }
  366. if ((7 == col % 8) || (col == w - 1)) // write that last byte! (for w%8!=0 border)
  367. {
  368. output_row_color_buffer[out_idx] = out_color_byte;
  369. output_row_mono_buffer[out_idx++] = out_byte;
  370. out_byte = 0xFF; // white (for w%8!=0 border)
  371. out_color_byte = 0xFF; // white (for w%8!=0 border)
  372. }
  373. } // end pixel
  374. uint16_t yrow = y + (flip ? h - row - 1 : row);
  375. display.writeImage(output_row_mono_buffer, output_row_color_buffer, x, yrow, w, 1);
  376. } // end line
  377. Serial.print(F("loaded in ")); Serial.print(millis() - startTime); Serial.println(F(" ms"));
  378. display.refresh();
  379. }
  380. }
  381. }
  382. //Serial.print(F("end curPosition ")); Serial.println(file.curPosition());
  383. file.close();
  384. if (!valid)
  385. {
  386. Serial.println(F("bitmap format not handled."));
  387. }
  388. }
  389. uint16_t read16(SdFile& f)
  390. {
  391. // BMP data is stored little-endian, same as Arduino.
  392. uint16_t result;
  393. ((uint8_t *)&result)[0] = f.read(); // LSB
  394. ((uint8_t *)&result)[1] = f.read(); // MSB
  395. return result;
  396. }
  397. uint32_t read32(SdFile& f)
  398. {
  399. // BMP data is stored little-endian, same as Arduino.
  400. uint32_t result;
  401. ((uint8_t *)&result)[0] = f.read(); // LSB
  402. ((uint8_t *)&result)[1] = f.read();
  403. ((uint8_t *)&result)[2] = f.read();
  404. ((uint8_t *)&result)[3] = f.read(); // MSB
  405. return result;
  406. }