GxEPD2_SD_Example.ino 49 KB

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