GxEPD2_SD_Example.ino 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. // GxEPD2_SD_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. //
  14. // note that BMP bitmaps are drawn at physical position in physical orientation of the screen
  15. // Supporting Arduino Forum Topics:
  16. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  17. // Good Display ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  18. // mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
  19. // BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
  20. // NOTE: connect 3.3k pull-down from D8 to GND if your board or shield has level converters
  21. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case, or 4k7 pull-down
  22. // mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
  23. // BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  24. // NOTE: connect 3.3k pull-down from GPIO15 to GND if your board or shield has level converters
  25. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case, or 3.3k pull-down
  26. // mapping of Waveshare e-Paper ESP8266 Driver Board, new version (see GxEPD2_boards_added.h for old version)
  27. // BUSY -> GPIO5, RST -> GPIO2, DC -> GPIO4, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  28. // NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, add a 3.3k pull-down in case
  29. // the e-Paper ESP8266 Driver Board should have no boot mode issue, as it doesn't use level converters
  30. // mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
  31. // NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
  32. // BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V
  33. // mapping of Waveshare ESP32 Driver Board
  34. // BUSY -> 25, RST -> 26, DC -> 27, CS-> 15, CLK -> 13, DIN -> 14
  35. // NOTE: this board uses "unusual" SPI pins and requires re-mapping of HW SPI to these pins in SPIClass
  36. // see example GxEPD2_WS_ESP32_Driver.ino, it shows how this can be done easily
  37. // new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
  38. // BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
  39. // mapping suggestion for AVR, UNO, NANO etc.
  40. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11
  41. // mapping of Waveshare Universal e-Paper Raw Panel Driver Shield for Arduino / NUCLEO
  42. // BUSY -> 7, RST -> 8, DC -> 9, CS-> 10, CLK -> 13, DIN -> 11
  43. // mapping suggestion for Arduino MEGA
  44. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 53, CLK -> 52, DIN -> 51
  45. // **** NOTE that the mapping suggestion may need modification depending on SD board used! ****
  46. // ********************************************************************************************
  47. //
  48. //#define SD_CS SS // e.g. for RobotDyn Wemos D1 mini SD board
  49. //#define EPD_CS D1 // alternative I use with RobotDyn Wemos D1 mini SD board
  50. // base class GxEPD2_GFX can be used to pass references or pointers to the display instance as parameter, uses ~1.2k more code
  51. // enable or disable GxEPD2_GFX base class
  52. #define ENABLE_GxEPD2_GFX 0
  53. // uncomment next line to use class GFX of library GFX_Root instead of Adafruit_GFX
  54. //#include <GFX.h>
  55. // Note: if you use this with ENABLE_GxEPD2_GFX 1:
  56. // uncomment it in GxEPD2_GFX.h too, or add #include <GFX.h> before any #include <GxEPD2_GFX.h>
  57. #include <GxEPD2_BW.h>
  58. #include <GxEPD2_3C.h>
  59. #include <GxEPD2_7C.h>
  60. #include <Fonts/FreeMonoBold9pt7b.h>
  61. #if defined(ESP32)
  62. // has support for FAT32 support with long filenames
  63. #include "FS.h"
  64. #include "SD.h"
  65. #include "SPI.h"
  66. #define SdFile File
  67. #define seekSet seek
  68. #else
  69. // include SdFat for FAT32 support with long filenames; available through Library Manager
  70. #include <SdFat.h>
  71. SdFat SD;
  72. #endif
  73. #if defined (ESP8266)
  74. #define SD_CS SS // e.g. for RobotDyn Wemos D1 mini SD board
  75. #define EPD_CS D1 // alternative I use with RobotDyn Wemos D1 mini SD board
  76. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  77. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEP015OC1 no longer available
  78. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0154D67
  79. //GxEPD2_BW<GxEPD2_154_T8, GxEPD2_154_T8::HEIGHT> display(GxEPD2_154_T8(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0154T8 152x152
  80. //GxEPD2_BW<GxEPD2_154_M09, GxEPD2_154_M09::HEIGHT> display(GxEPD2_154_M09(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0154M09 200x200
  81. //GxEPD2_BW<GxEPD2_154_M10, GxEPD2_154_M10::HEIGHT> display(GxEPD2_154_M10(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0154M10 152x152
  82. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  83. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0213B72
  84. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0213B73
  85. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0213I5F
  86. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  87. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW029T5
  88. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  89. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  90. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  91. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  92. // can use only half buffer size
  93. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  94. //GxEPD2_BW < GxEPD2_583_T8, GxEPD2_583_T8::HEIGHT / 2 > display(GxEPD2_583_T8(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  95. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  96. //GxEPD2_BW < GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT / 2 > display(GxEPD2_750_T7(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW075T7 800x480
  97. // 3-color e-papers
  98. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW0154Z04 no longer available
  99. //GxEPD2_3C<GxEPD2_154_Z90c, GxEPD2_154_Z90c::HEIGHT> display(GxEPD2_154_Z90c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH0154Z90
  100. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  101. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  102. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  103. // can use only half buffer size
  104. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  105. // can use only quarter buffer size
  106. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  107. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  108. //GxEPD2_3C < GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT / 4 > display(GxEPD2_750c_Z08(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEW075Z08 800x480
  109. //GxEPD2_3C < GxEPD2_750c_Z90, GxEPD2_750c_Z90::HEIGHT / 4 > display(GxEPD2_750c_Z90(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDEH075Z90 880x528
  110. // 7-color e-paper
  111. //GxEPD2_3C < GxEPD2_565c, GxEPD2_565c::HEIGHT / 4 > display(GxEPD2_565c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // Waveshare 5.65" 7-color (3C graphics)
  112. //GxEPD2_7C < GxEPD2_565c, GxEPD2_565c::HEIGHT / 4 > display(GxEPD2_565c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // Waveshare 5.65" 7-color
  113. // grey levels parallel IF e-papers on Waveshare e-Paper IT8951 Driver HAT
  114. // HRDY -> 4, RST -> 2, CS -> SS(15), SCK -> SCK(14), MOSI -> MOSI(D7(13)), MISO -> MISO(D6(12)), GND -> GND, 5V -> 5V
  115. // note: 5V supply needs to be exact and strong; 5V pin of USB powered Wemos D1 mini doesn't work!
  116. //GxEPD2_BW<GxEPD2_it60, GxEPD2_it60::HEIGHT / 8> display(GxEPD2_it60(/*CS=5*/ EPD_CS, /*DC=*/ 0, /*RST=*/ 2, /*BUSY=*/ 4));
  117. //GxEPD2_BW < GxEPD2_it60_1448x1072, GxEPD2_it60_1448x1072::HEIGHT / 8 > display(GxEPD2_it60_1448x1072(/*CS=5*/ EPD_CS, /*DC=*/ 0, /*RST=*/ 2, /*BUSY=*/ 4));
  118. // ***** for mapping of Waveshare e-Paper ESP8266 Driver Board *****
  119. // select one , can use full buffer size (full HEIGHT)
  120. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEP015OC1 no longer available
  121. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH0154D67
  122. //GxEPD2_BW<GxEPD2_154_T8, GxEPD2_154_T8::HEIGHT> display(GxEPD2_154_T8(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0154T8 152x152
  123. //GxEPD2_BW<GxEPD2_154_M09, GxEPD2_154_M09::HEIGHT> display(GxEPD2_154_M09(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0154M09 200x200
  124. //GxEPD2_BW<GxEPD2_154_M10, GxEPD2_154_M10::HEIGHT> display(GxEPD2_154_M10(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0154M10 152x152
  125. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDE0213B1, phased out
  126. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH0213B72
  127. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH0213B73
  128. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0213I5F
  129. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  130. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW029T5
  131. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  132. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  133. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  134. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  135. // can use only half buffer size
  136. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  137. //GxEPD2_BW < GxEPD2_583_T8, GxEPD2_583_T8::HEIGHT / 2 > display(GxEPD2_583_T8(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  138. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  139. //GxEPD2_BW < GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT / 2 > display(GxEPD2_750_T7(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW075T7 800x480
  140. // 3-color e-papers
  141. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW0154Z04 no longer available
  142. //GxEPD2_3C<GxEPD2_154_Z90c, GxEPD2_154_Z90c::HEIGHT> display(GxEPD2_154_Z90c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH0154Z90
  143. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  144. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  145. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  146. // can use only half buffer size
  147. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  148. // can use only quarter buffer size
  149. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  150. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  151. //GxEPD2_3C<GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT / 4> display(GxEPD2_750c_Z08(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEW075Z08 800x480
  152. //GxEPD2_3C<GxEPD2_750c_Z90, GxEPD2_750c_Z90::HEIGHT / 4> display(GxEPD2_750c_Z90(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // GDEH075Z90 880x528
  153. // 7-color e-paper
  154. //GxEPD2_7C < GxEPD2_565c, GxEPD2_565c::HEIGHT / 4 > display(GxEPD2_565c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5)); // Waveshare 5.65" 7-color
  155. #endif
  156. #if defined(ESP32)
  157. #define SD_CS 2 // adapt to your wiring
  158. #define EPD_CS SS // adapt to your wiring
  159. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  160. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEP015OC1 no longer available
  161. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0154D67
  162. //GxEPD2_BW<GxEPD2_154_T8, GxEPD2_154_T8::HEIGHT> display(GxEPD2_154_T8(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0154T8 152x152
  163. //GxEPD2_BW<GxEPD2_154_M09, GxEPD2_154_M09::HEIGHT> display(GxEPD2_154_M09(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0154M09 200x200
  164. //GxEPD2_BW<GxEPD2_154_M10, GxEPD2_154_M10::HEIGHT> display(GxEPD2_154_M10(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0154M10 152x152
  165. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDE0213B1, phased out
  166. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B72
  167. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B73
  168. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0213I5F
  169. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  170. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW029T5
  171. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  172. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  173. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  174. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  175. //GxEPD2_BW<GxEPD2_583, GxEPD2_583::HEIGHT> display(GxEPD2_583(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  176. //GxEPD2_BW<GxEPD2_583_T8, GxEPD2_583_T8::HEIGHT> display(GxEPD2_583_T8(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  177. //GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  178. //GxEPD2_BW<GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT> display(GxEPD2_750_T7(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW075T7 800x480
  179. // 3-color e-papers
  180. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0154Z04 no longer available
  181. //GxEPD2_3C<GxEPD2_154_Z90c, GxEPD2_154_Z90c::HEIGHT> display(GxEPD2_154_Z90c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0154Z90
  182. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  183. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  184. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  185. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT> display(GxEPD2_420c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  186. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT> display(GxEPD2_583c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  187. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT> display(GxEPD2_750c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  188. //GxEPD2_3C<GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT> display(GxEPD2_750c_Z08(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW075Z08 800x480
  189. //GxEPD2_3C<GxEPD2_750c_Z90, GxEPD2_750c_Z90::HEIGHT / 2> display(GxEPD2_750c_Z90(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH075Z90 880x528
  190. // 7-color e-paper
  191. //GxEPD2_7C < GxEPD2_565c, GxEPD2_565c::HEIGHT / 2 > display(GxEPD2_565c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // Waveshare 5.65" 7-color
  192. // grey levels parallel IF e-papers on Waveshare e-Paper IT8951 Driver HAT
  193. // HRDY -> 4, RST -> 16, CS -> SS(5), SCK -> SCK(18), MOSI -> MOSI(23), MISO -> MISO(19), GND -> GND, 5V -> 5V
  194. // note: 5V supply needs to be exact and strong; 5V over diode from USB (e.g. Wemos D1 mini) doesn't work!
  195. //GxEPD2_BW<GxEPD2_it60, GxEPD2_it60::HEIGHT> display(GxEPD2_it60(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  196. GxEPD2_BW < GxEPD2_it60_1448x1072, GxEPD2_it60_1448x1072::HEIGHT / 4 > display(GxEPD2_it60_1448x1072(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  197. // Waveshare 12.48 b/w SPI display board and frame or Good Display 12.48 b/w panel GDEW1248T3
  198. // general constructor for use with all parameters, e.g. for Waveshare ESP32 driver board mounted on connection board
  199. //GxEPD2_BW < GxEPD2_1248, GxEPD2_1248::HEIGHT / 4 >
  200. //display(GxEPD2_1248(/*sck=*/ 13, /*miso=*/ 12, /*mosi=*/ 14, /*cs_m1=*/ 23, /*cs_s1=*/ 22, /*cs_m2=*/ 16, /*cs_s2=*/ 19,
  201. // /*dc1=*/ 25, /*dc2=*/ 17, /*rst1=*/ 33, /*rst2=*/ 5, /*busy_m1=*/ 32, /*busy_s1=*/ 26, /*busy_m2=*/ 18, /*busy_s2=*/ 4));
  202. #endif
  203. // can't use package "STMF1 Boards (STM32Duino.com)" (Roger Clark) anymore with Adafruit_GFX, use "STM32 Boards (selected from submenu)" (STMicroelectronics)
  204. #if defined(ARDUINO_ARCH_STM32)
  205. #define SD_CS 0 // adapt to your wiring
  206. #define EPD_CS SS // adapt to your wiring
  207. #define MAX_DISPLAY_BUFFER_SIZE 15000ul // ~15k is a good compromise
  208. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  209. // select one and adapt to your mapping
  210. //GxEPD2_BW<GxEPD2_154, MAX_HEIGHT(GxEPD2_154)> display(GxEPD2_154(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEP015OC1 no longer available
  211. //GxEPD2_BW<GxEPD2_154_D67, MAX_HEIGHT(GxEPD2_154_D67)> display(GxEPD2_154_D67(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH0154D67
  212. //GxEPD2_BW<GxEPD2_154_T8, MAX_HEIGHT(GxEPD2_154_T8)> display(GxEPD2_154_T8(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0154T8 152x152
  213. //GxEPD2_BW<GxEPD2_154_M09, MAX_HEIGHT(GxEPD2_154_M09)> display(GxEPD2_154_M09(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0154M09 200x200
  214. //GxEPD2_BW<GxEPD2_154_M10, MAX_HEIGHT(GxEPD2_154_M10)> display(GxEPD2_154_M10(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0154M10 152x152
  215. //GxEPD2_BW<GxEPD2_213, MAX_HEIGHT(GxEPD2_213)> display(GxEPD2_213(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDE0213B1, phased out
  216. //GxEPD2_BW<GxEPD2_213_B72, MAX_HEIGHT(GxEPD2_213_B72)> display(GxEPD2_213_B72(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH0213B72
  217. //GxEPD2_BW<GxEPD2_213_B73, MAX_HEIGHT(GxEPD2_213_B73)> display(GxEPD2_213_B73(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH0213B73
  218. //GxEPD2_BW<GxEPD2_213_flex, MAX_HEIGHT(GxEPD2_213_flex)> display(GxEPD2_213_flex(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0213I5F
  219. //GxEPD2_BW<GxEPD2_290, MAX_HEIGHT(GxEPD2_290)> display(GxEPD2_290(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  220. //GxEPD2_BW<GxEPD2_290_T5, MAX_HEIGHT(GxEPD2_290_T5)> display(GxEPD2_290_T5(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW029T5
  221. //GxEPD2_BW<GxEPD2_260, MAX_HEIGHT(GxEPD2_260)> display(GxEPD2_260(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  222. //GxEPD2_BW<GxEPD2_270, MAX_HEIGHT(GxEPD2_270)> display(GxEPD2_270(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  223. //GxEPD2_BW<GxEPD2_371, MAX_HEIGHT(GxEPD2_371)> display(GxEPD2_371(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  224. //GxEPD2_BW<GxEPD2_420, MAX_HEIGHT(GxEPD2_420)> display(GxEPD2_420(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  225. //GxEPD2_BW<GxEPD2_583, MAX_HEIGHT(GxEPD2_583)> display(GxEPD2_583(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  226. //GxEPD2_BW <GxEPD2_583_T8, MAX_HEIGHT(GxEPD2_583_T8)> display(GxEPD2_583_T8(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  227. //GxEPD2_BW<GxEPD2_750, MAX_HEIGHT(GxEPD2_750)> display(GxEPD2_750(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  228. //GxEPD2_BW<GxEPD2_750_T7, MAX_HEIGHT(GxEPD2_750_T7)> display(GxEPD2_750_T7(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW075T7 800x480
  229. // 3-color e-papers
  230. #define MAX_HEIGHT_3C(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  231. //GxEPD2_3C<GxEPD2_154c, MAX_HEIGHT_3C(GxEPD2_154c)> display(GxEPD2_154c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW0154Z04 no longer available
  232. //GxEPD2_3C<GxEPD2_154_Z90c, MAX_HEIGHT_3C(GxEPD2_154_Z90c)> display(GxEPD2_154_Z90c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH0154Z90
  233. //GxEPD2_3C<GxEPD2_213c, MAX_HEIGHT_3C(GxEPD2_213c)> display(GxEPD2_213c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  234. //GxEPD2_3C<GxEPD2_290c, MAX_HEIGHT_3C(GxEPD2_290c)> display(GxEPD2_290c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  235. //GxEPD2_3C<GxEPD2_270c, MAX_HEIGHT_3C(GxEPD2_270c)> display(GxEPD2_270c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  236. //GxEPD2_3C<GxEPD2_420c, MAX_HEIGHT_3C(GxEPD2_420c)> display(GxEPD2_420c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  237. //GxEPD2_3C<GxEPD2_583c, MAX_HEIGHT_3C(GxEPD2_583c)> display(GxEPD2_583c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  238. //GxEPD2_3C<GxEPD2_750c, MAX_HEIGHT_3C(GxEPD2_750c)> display(GxEPD2_750c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  239. //GxEPD2_3C<GxEPD2_750c_Z08, MAX_HEIGHT_3C(GxEPD2_750c_Z08)> display(GxEPD2_750c_Z08(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEW075Z08 800x480
  240. //GxEPD2_3C<GxEPD2_750c_Z90, MAX_HEIGHT_3C(GxEPD2_750c_Z90)> display(GxEPD2_750c_Z90(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // GDEH075Z90 880x528
  241. // 7-color e-paper
  242. #define MAX_HEIGHT_7C(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2)) // 2 pixel per byte
  243. //GxEPD2_7C<GxEPD2_565c, MAX_HEIGHT_7C(GxEPD2_565c)> display(GxEPD2_565c(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1)); // Waveshare 5.65" 7-color
  244. #endif
  245. #if defined(__AVR)
  246. #define SD_CS 6 // adapt to your wiring
  247. #define EPD_CS SS // adapt to your wiring
  248. // most AVR Arduinos have not enough RAM for use with SD and buffered graphics
  249. // !!! use GxEPD2_SD_AVR_Example.ino instead !!!
  250. //GxEPD2_154 display(/*CS=10*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7);
  251. #endif
  252. // function declaration with default parameter
  253. // note that BMP bitmaps are drawn at physical position in physical orientation of the screen
  254. void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color = true);
  255. // bitmap drawing using buffered graphics, e.g. for small bitmaps or for GxEPD2_154c
  256. // draws BMP bitmap according to set orientation
  257. // partial_update selects refresh mode (not effective for GxEPD2_154c)
  258. // overwrite = true does not clear buffer before drawing, use only if buffer is full height
  259. void drawBitmapFromSD_Buffered(const char *filename, int16_t x, int16_t y, bool with_color = true, bool partial_update = false, bool overwrite = false);
  260. void setup()
  261. {
  262. Serial.begin(115200);
  263. Serial.println();
  264. Serial.println("GxEPD2_SD_Example");
  265. display.init(115200);
  266. Serial.print("Initializing SD card...");
  267. if (!SD.begin(SD_CS))
  268. {
  269. Serial.println("SD failed!");
  270. return;
  271. }
  272. Serial.println("SD OK!");
  273. if ((display.epd2.panel == GxEPD2::GDEW0154Z04) || (display.epd2.panel == GxEPD2::ACeP565) || false)
  274. {
  275. drawBitmapsBuffered_200x200();
  276. drawBitmapsBuffered_other();
  277. }
  278. else
  279. {
  280. drawBitmaps_200x200();
  281. drawBitmaps_other();
  282. }
  283. //drawBitmaps_test();
  284. //drawBitmapsBuffered_test();
  285. Serial.println("GxEPD2_SD_Example done");
  286. }
  287. void loop(void)
  288. {
  289. }
  290. void drawBitmaps_200x200()
  291. {
  292. int16_t x = (display.width() - 200) / 2;
  293. int16_t y = (display.height() - 200) / 2;
  294. drawBitmapFromSD("logo200x200.bmp", x, y);
  295. delay(2000);
  296. drawBitmapFromSD("first200x200.bmp", x, y);
  297. delay(2000);
  298. drawBitmapFromSD("second200x200.bmp", x, y);
  299. delay(2000);
  300. drawBitmapFromSD("third200x200.bmp", x, y);
  301. delay(2000);
  302. drawBitmapFromSD("fourth200x200.bmp", x, y);
  303. delay(2000);
  304. drawBitmapFromSD("fifth200x200.bmp", x, y);
  305. delay(2000);
  306. drawBitmapFromSD("sixth200x200.bmp", x, y);
  307. delay(2000);
  308. drawBitmapFromSD("seventh200x200.bmp", x, y);
  309. delay(2000);
  310. drawBitmapFromSD("eighth200x200.bmp", x, y);
  311. delay(2000);
  312. }
  313. void drawBitmaps_other()
  314. {
  315. int16_t w2 = display.width() / 2;
  316. int16_t h2 = display.height() / 2;
  317. drawBitmapFromSD("parrot.bmp", w2 - 64, h2 - 80);
  318. delay(2000);
  319. drawBitmapFromSD("betty_1.bmp", w2 - 100, h2 - 160);
  320. delay(2000);
  321. drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
  322. delay(2000);
  323. drawBitmapFromSD("marilyn_240x240x8.bmp", w2 - 120, h2 - 120);
  324. delay(2000);
  325. drawBitmapFromSD("miniwoof.bmp", w2 - 60, h2 - 80);
  326. delay(2000);
  327. drawBitmapFromSD("t200x200.bmp", w2 - 100, h2 - 100);
  328. delay(2000);
  329. drawBitmapFromSD("test.bmp", w2 - 120, h2 - 160);
  330. delay(2000);
  331. drawBitmapFromSD("tiger.bmp", w2 - 160, h2 - 120);
  332. delay(2000);
  333. drawBitmapFromSD("tiger_178x160x4.bmp", w2 - 89, h2 - 80);
  334. delay(2000);
  335. drawBitmapFromSD("tiger_240x317x4.bmp", w2 - 120, h2 - 160);
  336. delay(2000);
  337. drawBitmapFromSD("tiger_320x200x24.bmp", w2 - 160, h2 - 100);
  338. delay(2000);
  339. drawBitmapFromSD("tiger16T.bmp", w2 - 160, h2 - 120);
  340. delay(2000);
  341. drawBitmapFromSD("woof.bmp", w2 - 120, h2 - 160);
  342. delay(2000);
  343. drawBitmapFromSD("bitmap640x384_1.bmp", 0, 0);
  344. delay(2000);
  345. }
  346. void drawBitmaps_test()
  347. {
  348. int16_t w2 = display.width() / 2;
  349. int16_t h2 = display.height() / 2;
  350. drawBitmapFromSD("betty_4.bmp", w2 - 102, h2 - 126);
  351. delay(2000);
  352. drawBitmapFromSD("bb4.bmp", 0, 0);
  353. delay(2000);
  354. drawBitmapFromSD("output5.bmp", 0, 0);
  355. delay(2000);
  356. drawBitmapFromSD("output6.bmp", 0, 0);
  357. delay(2000);
  358. drawBitmapFromSD("tractor_1.bmp", 0, 0);
  359. delay(2000);
  360. drawBitmapFromSD("tractor_4.bmp", 0, 0);
  361. delay(2000);
  362. drawBitmapFromSD("tractor_8.bmp", 0, 0);
  363. delay(2000);
  364. drawBitmapFromSD("tractor_11.bmp", 0, 0);
  365. delay(2000);
  366. drawBitmapFromSD("tractor_44.bmp", 0, 0);
  367. delay(2000);
  368. drawBitmapFromSD("tractor_88.bmp", 0, 0);
  369. delay(2000);
  370. }
  371. void drawBitmapsBuffered_200x200()
  372. {
  373. int16_t x = (display.width() - 200) / 2;
  374. int16_t y = (display.height() - 200) / 2;
  375. drawBitmapFromSD_Buffered("logo200x200.bmp", x, y);
  376. delay(2000);
  377. drawBitmapFromSD_Buffered("first200x200.bmp", x, y);
  378. delay(2000);
  379. drawBitmapFromSD_Buffered("second200x200.bmp", x, y);
  380. delay(2000);
  381. drawBitmapFromSD_Buffered("third200x200.bmp", x, y);
  382. delay(2000);
  383. drawBitmapFromSD_Buffered("fourth200x200.bmp", x, y);
  384. delay(2000);
  385. drawBitmapFromSD_Buffered("fifth200x200.bmp", x, y);
  386. delay(2000);
  387. drawBitmapFromSD_Buffered("sixth200x200.bmp", x, y);
  388. delay(2000);
  389. drawBitmapFromSD_Buffered("seventh200x200.bmp", x, y);
  390. delay(2000);
  391. drawBitmapFromSD_Buffered("eighth200x200.bmp", x, y);
  392. delay(2000);
  393. }
  394. void drawBitmapsBuffered_other()
  395. {
  396. int16_t w2 = display.width() / 2;
  397. int16_t h2 = display.height() / 2;
  398. drawBitmapFromSD_Buffered("parrot.bmp", w2 - 64, h2 - 80);
  399. delay(2000);
  400. drawBitmapFromSD_Buffered("betty_1.bmp", w2 - 100, h2 - 160);
  401. delay(2000);
  402. drawBitmapFromSD_Buffered("betty_4.bmp", w2 - 102, h2 - 126);
  403. delay(2000);
  404. drawBitmapFromSD_Buffered("marilyn_240x240x8.bmp", w2 - 120, h2 - 120);
  405. delay(2000);
  406. drawBitmapFromSD_Buffered("miniwoof.bmp", w2 - 60, h2 - 80);
  407. delay(2000);
  408. drawBitmapFromSD_Buffered("t200x200.bmp", w2 - 100, h2 - 100);
  409. delay(2000);
  410. drawBitmapFromSD_Buffered("test.bmp", w2 - 120, h2 - 160);
  411. delay(2000);
  412. drawBitmapFromSD_Buffered("tiger.bmp", w2 - 160, h2 - 120);
  413. delay(2000);
  414. drawBitmapFromSD_Buffered("tiger_178x160x4.bmp", w2 - 89, h2 - 80);
  415. delay(2000);
  416. drawBitmapFromSD_Buffered("tiger_240x317x4.bmp", w2 - 120, h2 - 160);
  417. delay(2000);
  418. drawBitmapFromSD_Buffered("tiger_320x200x24.bmp", w2 - 160, h2 - 100);
  419. delay(2000);
  420. drawBitmapFromSD_Buffered("tiger16T.bmp", w2 - 160, h2 - 120);
  421. delay(2000);
  422. drawBitmapFromSD_Buffered("woof.bmp", w2 - 120, h2 - 160);
  423. delay(2000);
  424. drawBitmapFromSD_Buffered("bitmap640x384_1.bmp", 0, 0);
  425. delay(2000);
  426. }
  427. void drawBitmapsBuffered_test()
  428. {
  429. int16_t w2 = display.width() / 2;
  430. int16_t h2 = display.height() / 2;
  431. drawBitmapFromSD_Buffered("betty_4.bmp", w2 - 102, h2 - 126);
  432. delay(2000);
  433. drawBitmapFromSD_Buffered("bb4.bmp", 0, 0, false, true, true);
  434. delay(2000);
  435. }
  436. //static const uint16_t input_buffer_pixels = 20; // may affect performance
  437. static const uint16_t input_buffer_pixels = 800; // may affect performance
  438. static const uint16_t max_row_width = 1448; // for up to 6" display 1448x1072
  439. static const uint16_t max_palette_pixels = 256; // for depth <= 8
  440. uint8_t input_buffer[3 * input_buffer_pixels]; // up to depth 24
  441. uint8_t output_row_mono_buffer[max_row_width / 8]; // buffer for at least one row of b/w bits
  442. uint8_t output_row_color_buffer[max_row_width / 8]; // buffer for at least one row of color bits
  443. uint8_t mono_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 b/w
  444. uint8_t color_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 c/w
  445. uint16_t rgb_palette_buffer[max_palette_pixels]; // palette buffer for depth <= 8 for buffered graphics, needed for 7-color display
  446. void drawBitmapFromSD(const char *filename, int16_t x, int16_t y, bool with_color)
  447. {
  448. SdFile file;
  449. bool valid = false; // valid format to be handled
  450. bool flip = true; // bitmap is stored bottom-to-top
  451. uint32_t startTime = millis();
  452. if ((x >= display.epd2.WIDTH) || (y >= display.epd2.HEIGHT)) return;
  453. Serial.println();
  454. Serial.print("Loading image '");
  455. Serial.print(filename);
  456. Serial.println('\'');
  457. #if defined(ESP32)
  458. file = SD.open(String("/") + filename, FILE_READ);
  459. if (!file)
  460. {
  461. Serial.print("File not found");
  462. return;
  463. }
  464. #else
  465. if (!file.open(filename, FILE_READ))
  466. {
  467. Serial.print("File not found");
  468. return;
  469. }
  470. #endif
  471. // Parse BMP header
  472. if (read16(file) == 0x4D42) // BMP signature
  473. {
  474. uint32_t fileSize = read32(file);
  475. uint32_t creatorBytes = read32(file);
  476. uint32_t imageOffset = read32(file); // Start of image data
  477. uint32_t headerSize = read32(file);
  478. uint32_t width = read32(file);
  479. uint32_t height = read32(file);
  480. uint16_t planes = read16(file);
  481. uint16_t depth = read16(file); // bits per pixel
  482. uint32_t format = read32(file);
  483. if ((planes == 1) && ((format == 0) || (format == 3))) // uncompressed is handled, 565 also
  484. {
  485. Serial.print("File size: "); Serial.println(fileSize);
  486. Serial.print("Image Offset: "); Serial.println(imageOffset);
  487. Serial.print("Header size: "); Serial.println(headerSize);
  488. Serial.print("Bit Depth: "); Serial.println(depth);
  489. Serial.print("Image size: ");
  490. Serial.print(width);
  491. Serial.print('x');
  492. Serial.println(height);
  493. // BMP rows are padded (if needed) to 4-byte boundary
  494. uint32_t rowSize = (width * depth / 8 + 3) & ~3;
  495. if (depth < 8) rowSize = ((width * depth + 8 - depth) / 8 + 3) & ~3;
  496. if (height < 0)
  497. {
  498. height = -height;
  499. flip = false;
  500. }
  501. uint16_t w = width;
  502. uint16_t h = height;
  503. if ((x + w - 1) >= display.epd2.WIDTH) w = display.epd2.WIDTH - x;
  504. if ((y + h - 1) >= display.epd2.HEIGHT) h = display.epd2.HEIGHT - y;
  505. if (w <= max_row_width) // handle with direct drawing
  506. {
  507. valid = true;
  508. uint8_t bitmask = 0xFF;
  509. uint8_t bitshift = 8 - depth;
  510. uint16_t red, green, blue;
  511. bool whitish, colored;
  512. if (depth == 1) with_color = false;
  513. if (depth <= 8)
  514. {
  515. if (depth < 8) bitmask >>= depth;
  516. //file.seekSet(54); //palette is always @ 54
  517. file.seekSet(imageOffset - (4 << depth)); // 54 for regular, diff for colorsimportant
  518. for (uint16_t pn = 0; pn < (1 << depth); pn++)
  519. {
  520. blue = file.read();
  521. green = file.read();
  522. red = file.read();
  523. file.read();
  524. //Serial.print(red); Serial.print(" "); Serial.print(green); Serial.print(" "); Serial.println(blue);
  525. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  526. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  527. if (0 == pn % 8) mono_palette_buffer[pn / 8] = 0;
  528. mono_palette_buffer[pn / 8] |= whitish << pn % 8;
  529. if (0 == pn % 8) color_palette_buffer[pn / 8] = 0;
  530. color_palette_buffer[pn / 8] |= colored << pn % 8;
  531. }
  532. }
  533. display.clearScreen();
  534. uint32_t rowPosition = flip ? imageOffset + (height - h) * rowSize : imageOffset;
  535. for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
  536. {
  537. uint32_t in_remain = rowSize;
  538. uint32_t in_idx = 0;
  539. uint32_t in_bytes = 0;
  540. uint8_t in_byte = 0; // for depth <= 8
  541. uint8_t in_bits = 0; // for depth <= 8
  542. uint8_t out_byte = 0xFF; // white (for w%8!=0 border)
  543. uint8_t out_color_byte = 0xFF; // white (for w%8!=0 border)
  544. uint32_t out_idx = 0;
  545. file.seekSet(rowPosition);
  546. for (uint16_t col = 0; col < w; col++) // for each pixel
  547. {
  548. // Time to read more pixel data?
  549. if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
  550. {
  551. in_bytes = file.read(input_buffer, in_remain > sizeof(input_buffer) ? sizeof(input_buffer) : in_remain);
  552. in_remain -= in_bytes;
  553. in_idx = 0;
  554. }
  555. switch (depth)
  556. {
  557. case 24:
  558. blue = input_buffer[in_idx++];
  559. green = input_buffer[in_idx++];
  560. red = input_buffer[in_idx++];
  561. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  562. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  563. break;
  564. case 16:
  565. {
  566. uint8_t lsb = input_buffer[in_idx++];
  567. uint8_t msb = input_buffer[in_idx++];
  568. if (format == 0) // 555
  569. {
  570. blue = (lsb & 0x1F) << 3;
  571. green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
  572. red = (msb & 0x7C) << 1;
  573. }
  574. else // 565
  575. {
  576. blue = (lsb & 0x1F) << 3;
  577. green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
  578. red = (msb & 0xF8);
  579. }
  580. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  581. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  582. }
  583. break;
  584. case 1:
  585. case 4:
  586. case 8:
  587. {
  588. if (0 == in_bits)
  589. {
  590. in_byte = input_buffer[in_idx++];
  591. in_bits = 8;
  592. }
  593. uint16_t pn = (in_byte >> bitshift) & bitmask;
  594. whitish = mono_palette_buffer[pn / 8] & (0x1 << pn % 8);
  595. colored = color_palette_buffer[pn / 8] & (0x1 << pn % 8);
  596. in_byte <<= depth;
  597. in_bits -= depth;
  598. }
  599. break;
  600. }
  601. if (whitish)
  602. {
  603. // keep white
  604. }
  605. else if (colored && with_color)
  606. {
  607. out_color_byte &= ~(0x80 >> col % 8); // colored
  608. }
  609. else
  610. {
  611. out_byte &= ~(0x80 >> col % 8); // black
  612. }
  613. if ((7 == col % 8) || (col == w - 1)) // write that last byte! (for w%8!=0 border)
  614. {
  615. output_row_color_buffer[out_idx] = out_color_byte;
  616. output_row_mono_buffer[out_idx++] = out_byte;
  617. out_byte = 0xFF; // white (for w%8!=0 border)
  618. out_color_byte = 0xFF; // white (for w%8!=0 border)
  619. }
  620. } // end pixel
  621. uint16_t yrow = y + (flip ? h - row - 1 : row);
  622. display.writeImage(output_row_mono_buffer, output_row_color_buffer, x, yrow, w, 1);
  623. } // end line
  624. Serial.print("loaded in "); Serial.print(millis() - startTime); Serial.println(" ms");
  625. display.refresh();
  626. }
  627. }
  628. }
  629. file.close();
  630. if (!valid)
  631. {
  632. Serial.println("bitmap format not handled.");
  633. }
  634. }
  635. void drawBitmapFromSD_Buffered(const char *filename, int16_t x, int16_t y, bool with_color, bool partial_update, bool overwrite)
  636. {
  637. SdFile file;
  638. bool valid = false; // valid format to be handled
  639. bool flip = true; // bitmap is stored bottom-to-top
  640. bool has_multicolors = display.epd2.panel == GxEPD2::ACeP565;
  641. uint32_t startTime = millis();
  642. if ((x >= display.width()) || (y >= display.height())) return;
  643. Serial.println();
  644. Serial.print("Loading image '");
  645. Serial.print(filename);
  646. Serial.println('\'');
  647. #if defined(ESP32)
  648. file = SD.open(String("/") + filename, FILE_READ);
  649. if (!file)
  650. {
  651. Serial.print("File not found");
  652. return;
  653. }
  654. #else
  655. if (!file.open(filename, FILE_READ))
  656. {
  657. Serial.print("File not found");
  658. return;
  659. }
  660. #endif
  661. // Parse BMP header
  662. if (read16(file) == 0x4D42) // BMP signature
  663. {
  664. uint32_t fileSize = read32(file);
  665. uint32_t creatorBytes = read32(file);
  666. uint32_t imageOffset = read32(file); // Start of image data
  667. uint32_t headerSize = read32(file);
  668. uint32_t width = read32(file);
  669. uint32_t height = read32(file);
  670. uint16_t planes = read16(file);
  671. uint16_t depth = read16(file); // bits per pixel
  672. uint32_t format = read32(file);
  673. if ((planes == 1) && ((format == 0) || (format == 3))) // uncompressed is handled, 565 also
  674. {
  675. Serial.print("File size: "); Serial.println(fileSize);
  676. Serial.print("Image Offset: "); Serial.println(imageOffset);
  677. Serial.print("Header size: "); Serial.println(headerSize);
  678. Serial.print("Bit Depth: "); Serial.println(depth);
  679. Serial.print("Image size: ");
  680. Serial.print(width);
  681. Serial.print('x');
  682. Serial.println(height);
  683. // BMP rows are padded (if needed) to 4-byte boundary
  684. uint32_t rowSize = (width * depth / 8 + 3) & ~3;
  685. if (depth < 8) rowSize = ((width * depth + 8 - depth) / 8 + 3) & ~3;
  686. if (height < 0)
  687. {
  688. height = -height;
  689. flip = false;
  690. }
  691. uint16_t w = width;
  692. uint16_t h = height;
  693. if ((x + w - 1) >= display.width()) w = display.width() - x;
  694. if ((y + h - 1) >= display.height()) h = display.height() - y;
  695. //if (w <= max_row_width) // handle with direct drawing
  696. {
  697. valid = true;
  698. uint8_t bitmask = 0xFF;
  699. uint8_t bitshift = 8 - depth;
  700. uint16_t red, green, blue;
  701. bool whitish, colored;
  702. if (depth == 1) with_color = false;
  703. if (depth <= 8)
  704. {
  705. if (depth < 8) bitmask >>= depth;
  706. //file.seekSet(54); //palette is always @ 54
  707. file.seekSet(imageOffset - (4 << depth)); //54 for regular, diff for colorsimportant
  708. for (uint16_t pn = 0; pn < (1 << depth); pn++)
  709. {
  710. blue = file.read();
  711. green = file.read();
  712. red = file.read();
  713. file.read();
  714. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  715. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  716. if (0 == pn % 8) mono_palette_buffer[pn / 8] = 0;
  717. mono_palette_buffer[pn / 8] |= whitish << pn % 8;
  718. if (0 == pn % 8) color_palette_buffer[pn / 8] = 0;
  719. color_palette_buffer[pn / 8] |= colored << pn % 8;
  720. rgb_palette_buffer[pn] = ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ((blue & 0xF8) >> 3);
  721. }
  722. }
  723. if (partial_update) display.setPartialWindow(x, y, w, h);
  724. else display.setFullWindow();
  725. display.firstPage();
  726. do
  727. {
  728. //if (!overwrite) display.fillScreen(GxEPD_WHITE);
  729. uint32_t rowPosition = flip ? imageOffset + (height - h) * rowSize : imageOffset;
  730. for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
  731. {
  732. uint32_t in_remain = rowSize;
  733. uint32_t in_idx = 0;
  734. uint32_t in_bytes = 0;
  735. uint8_t in_byte = 0; // for depth <= 8
  736. uint8_t in_bits = 0; // for depth <= 8
  737. uint16_t color = GxEPD_WHITE;
  738. file.seekSet(rowPosition);
  739. for (uint16_t col = 0; col < w; col++) // for each pixel
  740. {
  741. // Time to read more pixel data?
  742. if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
  743. {
  744. in_bytes = file.read(input_buffer, in_remain > sizeof(input_buffer) ? sizeof(input_buffer) : in_remain);
  745. in_remain -= in_bytes;
  746. in_idx = 0;
  747. }
  748. switch (depth)
  749. {
  750. case 24:
  751. blue = input_buffer[in_idx++];
  752. green = input_buffer[in_idx++];
  753. red = input_buffer[in_idx++];
  754. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  755. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  756. color = ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ((blue & 0xF8) >> 3);
  757. break;
  758. case 16:
  759. {
  760. uint8_t lsb = input_buffer[in_idx++];
  761. uint8_t msb = input_buffer[in_idx++];
  762. if (format == 0) // 555
  763. {
  764. blue = (lsb & 0x1F) << 3;
  765. green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
  766. red = (msb & 0x7C) << 1;
  767. color = ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | ((blue & 0xF8) >> 3);
  768. }
  769. else // 565
  770. {
  771. blue = (lsb & 0x1F) << 3;
  772. green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
  773. red = (msb & 0xF8);
  774. color = (msb << 8) | lsb;
  775. }
  776. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  777. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  778. }
  779. break;
  780. case 1:
  781. case 4:
  782. case 8:
  783. {
  784. if (0 == in_bits)
  785. {
  786. in_byte = input_buffer[in_idx++];
  787. in_bits = 8;
  788. }
  789. uint16_t pn = (in_byte >> bitshift) & bitmask;
  790. whitish = mono_palette_buffer[pn / 8] & (0x1 << pn % 8);
  791. colored = color_palette_buffer[pn / 8] & (0x1 << pn % 8);
  792. in_byte <<= depth;
  793. in_bits -= depth;
  794. color = rgb_palette_buffer[pn];
  795. }
  796. break;
  797. }
  798. if (with_color && has_multicolors)
  799. {
  800. // keep color
  801. }
  802. else if (whitish)
  803. {
  804. color = GxEPD_WHITE;
  805. }
  806. else if (colored && with_color)
  807. {
  808. color = GxEPD_COLORED;
  809. }
  810. else
  811. {
  812. color = GxEPD_BLACK;
  813. }
  814. uint16_t yrow = y + (flip ? h - row - 1 : row);
  815. display.drawPixel(x + col, yrow, color);
  816. } // end pixel
  817. } // end line
  818. Serial.print("page loaded in "); Serial.print(millis() - startTime); Serial.println(" ms");
  819. }
  820. while (display.nextPage());
  821. Serial.print("loaded in "); Serial.print(millis() - startTime); Serial.println(" ms");
  822. }
  823. }
  824. }
  825. file.close();
  826. if (!valid)
  827. {
  828. Serial.println("bitmap format not handled.");
  829. }
  830. }
  831. uint16_t read16(SdFile& f)
  832. {
  833. // BMP data is stored little-endian, same as Arduino.
  834. uint16_t result;
  835. ((uint8_t *)&result)[0] = f.read(); // LSB
  836. ((uint8_t *)&result)[1] = f.read(); // MSB
  837. return result;
  838. }
  839. uint32_t read32(SdFile& f)
  840. {
  841. // BMP data is stored little-endian, same as Arduino.
  842. uint32_t result;
  843. ((uint8_t *)&result)[0] = f.read(); // LSB
  844. ((uint8_t *)&result)[1] = f.read();
  845. ((uint8_t *)&result)[2] = f.read();
  846. ((uint8_t *)&result)[3] = f.read(); // MSB
  847. return result;
  848. }