GxEPD2_SerialFlash_Example.ino 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. // GxEPD2_SerialFlash_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. // this example uses the SerialFlash library from: https://github.com/PaulStoffregen/SerialFlash
  15. // with a modification for use with ESP32 or the STM32 package available here: https://github.com/ZinggJM/SerialFlash
  16. // download it as .zip file and install with Library Mananger method "Add .ZIP Library..."
  17. //
  18. // note that BMP bitmaps are drawn at physical position in physical orientation of the screen
  19. // Supporting Arduino Forum Topics:
  20. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  21. // Good Display ePaper for Arduino : https://forum.arduino.cc/index.php?topic=436411.0
  22. //
  23. // this example uses the SerialFlash library from: https://github.com/PaulStoffregen/SerialFlash
  24. // with a modification for use with ESP32 or the STM32 package available here: https://github.com/ZinggJM/SerialFlash
  25. // download it as .zip file and install with Library Mananger method "Add .ZIP Library..."
  26. // mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
  27. // BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
  28. // mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
  29. // BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  30. // mapping of Waveshare e-Paper ESP8266 Driver Board
  31. // BUSY -> GPIO16, RST -> GPIO5, DC -> GPIO4, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
  32. // mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
  33. // NOTE: there are variants with different pins for SPI ! CHECK SPI PINS OF YOUR BOARD
  34. // BUSY -> 4, RST -> 16, DC -> 17, CS -> SS(5), CLK -> SCK(18), DIN -> MOSI(23), GND -> GND, 3.3V -> 3.3V
  35. // new mapping suggestion for STM32F1, e.g. STM32F103C8T6 "BluePill"
  36. // BUSY -> A1, RST -> A2, DC -> A3, CS-> A4, CLK -> A5, DIN -> A7
  37. // mapping suggestion for AVR, UNO, NANO etc.
  38. // BUSY -> 7, RST -> 9, DC -> 8, CS-> 10, CLK -> 13, DIN -> 11
  39. //
  40. #include <GxEPD2_BW.h>
  41. #include <GxEPD2_3C.h>
  42. #include <Fonts/FreeMonoBold9pt7b.h>
  43. #include <SerialFlash.h>
  44. #define EPD_CS SS
  45. #if defined (ESP8266)
  46. const int FlashChipSelect = D1; // digital pin for flash chip CS pin
  47. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  48. //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
  49. //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
  50. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4)); // GDE0213B1, phased out
  51. //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
  52. //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
  53. //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
  54. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  55. //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
  56. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  57. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  58. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  59. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  60. // can use only half buffer size
  61. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  62. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  63. //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
  64. // 3-color e-papers
  65. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  66. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  67. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  68. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  69. // can use only half buffer size
  70. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  71. // can use only quarter buffer size
  72. //GxEPD2_3C < GxEPD2_583c, GxEPD2_583c::HEIGHT / 4 > display(GxEPD2_583c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  73. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  74. //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
  75. // ***** for mapping of Waveshare e-Paper ESP8266 Driver Board *****
  76. // select one , can use full buffer size (full HEIGHT)
  77. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEP015OC1 no longer available
  78. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEH0154D67
  79. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDE0213B1, phased out
  80. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEH0213B72
  81. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEH0213B73
  82. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW0213I5F
  83. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  84. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW029T5
  85. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  86. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  87. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  88. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  89. // can use only half buffer size
  90. //GxEPD2_BW < GxEPD2_583, GxEPD2_583::HEIGHT / 2 > display(GxEPD2_583(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  91. //GxEPD2_BW < GxEPD2_750, GxEPD2_750::HEIGHT / 2 > display(GxEPD2_750(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  92. //GxEPD2_BW < GxEPD2_750_T7, GxEPD2_750_T7::HEIGHT / 2 > display(GxEPD2_750_T7(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW075T7 800x480
  93. // 3-color e-papers
  94. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  95. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  96. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  97. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  98. // can use only half buffer size
  99. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT / 2> display(GxEPD2_420c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  100. // can use only quarter buffer size
  101. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT / 4> display(GxEPD2_583c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  102. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT / 4> display(GxEPD2_750c(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  103. //GxEPD2_3C<GxEPD2_750c_Z08, GxEPD2_750c_Z08::HEIGHT / 4> display(GxEPD2_750c_Z08(/*CS=15*/ SS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16)); // GDEW075Z08 800x480
  104. #endif
  105. #if defined(ESP32)
  106. const int FlashChipSelect = 17; // as used with my ESP32 breadboard
  107. // select one and adapt to your mapping, can use full buffer size (full HEIGHT)
  108. //GxEPD2_BW<GxEPD2_154, GxEPD2_154::HEIGHT> display(GxEPD2_154(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEP015OC1 no longer available
  109. //GxEPD2_BW<GxEPD2_154_D67, GxEPD2_154_D67::HEIGHT> display(GxEPD2_154_D67(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0154D67
  110. //GxEPD2_BW<GxEPD2_213, GxEPD2_213::HEIGHT> display(GxEPD2_213(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDE0213B1, phased out
  111. //GxEPD2_BW<GxEPD2_213_B72, GxEPD2_213_B72::HEIGHT> display(GxEPD2_213_B72(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B72
  112. //GxEPD2_BW<GxEPD2_213_B73, GxEPD2_213_B73::HEIGHT> display(GxEPD2_213_B73(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEH0213B73
  113. //GxEPD2_BW<GxEPD2_213_flex, GxEPD2_213_flex::HEIGHT> display(GxEPD2_213_flex(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW0213I5F
  114. //GxEPD2_BW<GxEPD2_290, GxEPD2_290::HEIGHT> display(GxEPD2_290(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  115. //GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4)); // GDEW029T5
  116. //GxEPD2_BW<GxEPD2_260, GxEPD2_260::HEIGHT> display(GxEPD2_260(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  117. //GxEPD2_BW<GxEPD2_270, GxEPD2_270::HEIGHT> display(GxEPD2_270(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  118. //GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> display(GxEPD2_371(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  119. //GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> display(GxEPD2_420(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  120. //GxEPD2_BW<GxEPD2_583, GxEPD2_583::HEIGHT> display(GxEPD2_583(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  121. //GxEPD2_BW<GxEPD2_750, GxEPD2_750::HEIGHT> display(GxEPD2_750(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  122. //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
  123. // 3-color e-papers
  124. //GxEPD2_3C<GxEPD2_154c, GxEPD2_154c::HEIGHT> display(GxEPD2_154c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  125. //GxEPD2_3C<GxEPD2_213c, GxEPD2_213c::HEIGHT> display(GxEPD2_213c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  126. //GxEPD2_3C<GxEPD2_290c, GxEPD2_290c::HEIGHT> display(GxEPD2_290c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  127. //GxEPD2_3C<GxEPD2_270c, GxEPD2_270c::HEIGHT> display(GxEPD2_270c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  128. //GxEPD2_3C<GxEPD2_420c, GxEPD2_420c::HEIGHT> display(GxEPD2_420c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  129. //GxEPD2_3C<GxEPD2_583c, GxEPD2_583c::HEIGHT> display(GxEPD2_583c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  130. //GxEPD2_3C<GxEPD2_750c, GxEPD2_750c::HEIGHT> display(GxEPD2_750c(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  131. //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
  132. #endif
  133. // function declaration with default parameter
  134. // note that BMP bitmaps are drawn at physical position in physical orientation of the screen
  135. void drawBitmapFromSerialFlash(const char *filename, int16_t x, int16_t y, bool with_color = true);
  136. // bitmap drawing using buffered graphics, e.g. for small bitmaps or for GxEPD2_154c
  137. // draws BMP bitmap according to set orientation
  138. // partial_update selects refresh mode (not effective for GxEPD2_154c)
  139. // overwrite = true does not clear buffer before drawing, use only if buffer is full height
  140. void drawBitmapFromSerialFlash_Buffered(const char *filename, int16_t x, int16_t y, bool with_color = true, bool partial_update = false, bool overwrite = false);
  141. void setup()
  142. {
  143. Serial.begin(115200);
  144. Serial.println();
  145. Serial.println("GxEPD2_SerialFlash_Example");
  146. display.init();
  147. if (!SerialFlash.begin(FlashChipSelect))
  148. {
  149. Serial.println("Unable to access SPI Flash chip");
  150. return;
  151. }
  152. Serial.println("SerialFlash started");
  153. listFiles();
  154. if ((display.epd2.panel == GxEPD2::GDEW0154Z04) || false)
  155. {
  156. drawBitmapsBuffered_200x200();
  157. drawBitmapsBuffered_other();
  158. }
  159. else
  160. {
  161. drawBitmaps_200x200();
  162. drawBitmaps_other();
  163. //drawBitmaps_test();
  164. }
  165. Serial.println("GxEPD2_SerialFlash_Example done");
  166. }
  167. void loop(void)
  168. {
  169. }
  170. void listFiles()
  171. {
  172. Serial.println("All Files on SPI Flash chip:");
  173. SerialFlash.opendir();
  174. while (1)
  175. {
  176. char filename[64];
  177. uint32_t filesize;
  178. if (SerialFlash.readdir(filename, sizeof(filename), filesize))
  179. {
  180. Serial.print(" ");
  181. Serial.print(filename);
  182. spaces(20 - strlen(filename));
  183. Serial.print(" ");
  184. Serial.print(filesize);
  185. Serial.print(" bytes");
  186. Serial.println();
  187. }
  188. else
  189. {
  190. Serial.println("no more files...");
  191. break; // no more files
  192. }
  193. }
  194. }
  195. void spaces(int num)
  196. {
  197. for (int i = 0; i < num; i++)
  198. {
  199. Serial.print(" ");
  200. }
  201. }
  202. void drawBitmaps_200x200()
  203. {
  204. int16_t x = (display.width() - 200) / 2;
  205. int16_t y = (display.height() - 200) / 2;
  206. drawBitmapFromSerialFlash("logo200x200.bmp", x, y);
  207. delay(2000);
  208. drawBitmapFromSerialFlash("first200x200.bmp", x, y);
  209. delay(2000);
  210. drawBitmapFromSerialFlash("second200x200.bmp", x, y);
  211. delay(2000);
  212. drawBitmapFromSerialFlash("third200x200.bmp", x, y);
  213. delay(2000);
  214. drawBitmapFromSerialFlash("fourth200x200.bmp", x, y);
  215. delay(2000);
  216. drawBitmapFromSerialFlash("fifth200x200.bmp", x, y);
  217. delay(2000);
  218. drawBitmapFromSerialFlash("sixth200x200.bmp", x, y);
  219. delay(2000);
  220. drawBitmapFromSerialFlash("seventh200x200.bmp", x, y);
  221. delay(2000);
  222. drawBitmapFromSerialFlash("eighth200x200.bmp", x, y);
  223. delay(2000);
  224. }
  225. void drawBitmaps_other()
  226. {
  227. int16_t w2 = display.width() / 2;
  228. int16_t h2 = display.height() / 2;
  229. drawBitmapFromSerialFlash("chanceflurries.bmp", w2 - 50, h2 - 50, false);
  230. delay(2000);
  231. drawBitmapFromSerialFlash("betty_1.bmp", w2 - 100, h2 - 160);
  232. delay(2000);
  233. drawBitmapFromSerialFlash("betty_4.bmp", w2 - 102, h2 - 126);
  234. delay(2000);
  235. drawBitmapFromSerialFlash("marilyn_240x240x8.bmp", w2 - 120, h2 - 120);
  236. delay(2000);
  237. drawBitmapFromSerialFlash("miniwoof.bmp", w2 - 60, h2 - 80);
  238. delay(2000);
  239. drawBitmapFromSerialFlash("tiger.bmp", w2 - 160, h2 - 120);
  240. delay(2000);
  241. drawBitmapFromSerialFlash("tiger_178x160x4.bmp", w2 - 89, h2 - 80);
  242. delay(2000);
  243. drawBitmapFromSerialFlash("tiger_240x317x4.bmp", w2 - 120, h2 - 160);
  244. delay(2000);
  245. drawBitmapFromSerialFlash("tiger_320x200x24.bmp", w2 - 160, h2 - 100);
  246. delay(2000);
  247. drawBitmapFromSerialFlash("woof.bmp", w2 - 120, h2 - 160);
  248. delay(2000);
  249. }
  250. void drawBitmaps_test()
  251. {
  252. drawBitmapFromSerialFlash("output5.bmp", 0, 0);
  253. delay(2000);
  254. drawBitmapFromSerialFlash("output6.bmp", 0, 0);
  255. delay(2000);
  256. drawBitmapFromSerialFlash("tractor_1.bmp", 0, 0);
  257. delay(2000);
  258. drawBitmapFromSerialFlash("tractor_4.bmp", 0, 0);
  259. delay(2000);
  260. drawBitmapFromSerialFlash("tractor_8.bmp", 0, 0);
  261. delay(2000);
  262. drawBitmapFromSerialFlash("tractor_11.bmp", 0, 0);
  263. delay(2000);
  264. drawBitmapFromSerialFlash("tractor_44.bmp", 0, 0);
  265. delay(2000);
  266. drawBitmapFromSerialFlash("tractor_88.bmp", 0, 0);
  267. delay(2000);
  268. }
  269. void drawBitmapsBuffered_200x200()
  270. {
  271. int16_t x = (display.width() - 200) / 2;
  272. int16_t y = (display.height() - 200) / 2;
  273. drawBitmapFromSerialFlash_Buffered("logo200x200.bmp", x, y);
  274. delay(2000);
  275. drawBitmapFromSerialFlash_Buffered("first200x200.bmp", x, y);
  276. delay(2000);
  277. drawBitmapFromSerialFlash_Buffered("second200x200.bmp", x, y);
  278. delay(2000);
  279. drawBitmapFromSerialFlash_Buffered("third200x200.bmp", x, y);
  280. delay(2000);
  281. drawBitmapFromSerialFlash_Buffered("fourth200x200.bmp", x, y);
  282. delay(2000);
  283. drawBitmapFromSerialFlash_Buffered("fifth200x200.bmp", x, y);
  284. delay(2000);
  285. drawBitmapFromSerialFlash_Buffered("sixth200x200.bmp", x, y);
  286. delay(2000);
  287. drawBitmapFromSerialFlash_Buffered("seventh200x200.bmp", x, y);
  288. delay(2000);
  289. drawBitmapFromSerialFlash_Buffered("eighth200x200.bmp", x, y);
  290. delay(2000);
  291. }
  292. void drawBitmapsBuffered_other()
  293. {
  294. int16_t w2 = display.width() / 2;
  295. int16_t h2 = display.height() / 2;
  296. drawBitmapFromSerialFlash_Buffered("chanceflurries.bmp", w2 - 50, h2 - 50, false);
  297. delay(2000);
  298. drawBitmapFromSerialFlash_Buffered("betty_1.bmp", w2 - 100, h2 - 160);
  299. delay(2000);
  300. drawBitmapFromSerialFlash_Buffered("betty_4.bmp", w2 - 102, h2 - 126);
  301. delay(2000);
  302. drawBitmapFromSerialFlash_Buffered("marilyn_240x240x8.bmp", w2 - 120, h2 - 120);
  303. delay(2000);
  304. drawBitmapFromSerialFlash_Buffered("miniwoof.bmp", w2 - 60, h2 - 80);
  305. delay(2000);
  306. drawBitmapFromSerialFlash_Buffered("tiger.bmp", w2 - 160, h2 - 120);
  307. delay(2000);
  308. drawBitmapFromSerialFlash_Buffered("tiger_178x160x4.bmp", w2 - 89, h2 - 80);
  309. delay(2000);
  310. drawBitmapFromSerialFlash_Buffered("tiger_240x317x4.bmp", w2 - 120, h2 - 160);
  311. delay(2000);
  312. drawBitmapFromSerialFlash_Buffered("tiger_320x200x24.bmp", w2 - 160, h2 - 100);
  313. delay(2000);
  314. drawBitmapFromSerialFlash_Buffered("woof.bmp", w2 - 120, h2 - 160);
  315. delay(2000);
  316. }
  317. static const uint16_t input_buffer_pixels = 800; // may affect performance
  318. static const uint16_t max_row_width = 800; // for up to 7.5" display 800x480
  319. static const uint16_t max_palette_pixels = 256; // for depth <= 8
  320. uint8_t input_buffer[3 * input_buffer_pixels]; // up to depth 24
  321. uint8_t output_row_mono_buffer[max_row_width / 8]; // buffer for at least one row of b/w bits
  322. uint8_t output_row_color_buffer[max_row_width / 8]; // buffer for at least one row of color bits
  323. uint8_t mono_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 b/w
  324. uint8_t color_palette_buffer[max_palette_pixels / 8]; // palette buffer for depth <= 8 c/w
  325. void drawBitmapFromSerialFlash(const char *filename, int16_t x, int16_t y, bool with_color)
  326. {
  327. bool valid = false; // valid format to be handled
  328. bool flip = true; // bitmap is stored bottom-to-top
  329. uint32_t startTime = millis();
  330. if ((x >= display.epd2.WIDTH) || (y >= display.epd2.HEIGHT)) return;
  331. Serial.println();
  332. Serial.print("Loading image '");
  333. Serial.print(filename);
  334. Serial.println('\'');
  335. SerialFlashFile file = SerialFlash.open(filename);
  336. if (!file)
  337. {
  338. Serial.print("File not found");
  339. return;
  340. }
  341. // Parse BMP header
  342. if (read16(file) == 0x4D42) // BMP signature
  343. {
  344. uint32_t fileSize = read32(file);
  345. uint32_t creatorBytes = read32(file);
  346. uint32_t imageOffset = read32(file); // Start of image data
  347. uint32_t headerSize = read32(file);
  348. uint32_t width = read32(file);
  349. uint32_t height = read32(file);
  350. uint16_t planes = read16(file);
  351. uint16_t depth = read16(file); // bits per pixel
  352. uint32_t format = read32(file);
  353. if ((planes == 1) && ((format == 0) || (format == 3))) // uncompressed is handled, 565 also
  354. {
  355. Serial.print("File size: "); Serial.println(fileSize);
  356. Serial.print("Image Offset: "); Serial.println(imageOffset);
  357. Serial.print("Header size: "); Serial.println(headerSize);
  358. Serial.print("Bit Depth: "); Serial.println(depth);
  359. Serial.print("Image size: ");
  360. Serial.print(width);
  361. Serial.print('x');
  362. Serial.println(height);
  363. // BMP rows are padded (if needed) to 4-byte boundary
  364. uint32_t rowSize = (width * depth / 8 + 3) & ~3;
  365. if (depth < 8) rowSize = ((width * depth + 8 - depth) / 8 + 3) & ~3;
  366. if (height < 0)
  367. {
  368. height = -height;
  369. flip = false;
  370. }
  371. uint16_t w = width;
  372. uint16_t h = height;
  373. if ((x + w - 1) >= display.epd2.WIDTH) w = display.epd2.WIDTH - x;
  374. if ((y + h - 1) >= display.epd2.HEIGHT) h = display.epd2.HEIGHT - y;
  375. if (w <= max_row_width) // handle with direct drawing
  376. {
  377. valid = true;
  378. uint8_t bitmask = 0xFF;
  379. uint8_t bitshift = 8 - depth;
  380. uint16_t red, green, blue;
  381. bool whitish, colored;
  382. if (depth == 1) with_color = false;
  383. if (depth <= 8)
  384. {
  385. if (depth < 8) bitmask >>= depth;
  386. //file.seek(54); //palette is always @ 54
  387. file.seek(imageOffset - (4 << depth)); // 54 for regular, diff for colorsimportant
  388. for (uint16_t pn = 0; pn < (1 << depth); pn++)
  389. {
  390. blue = read8(file);
  391. green = read8(file);
  392. red = read8(file);
  393. read8(file);
  394. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  395. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  396. if (0 == pn % 8) mono_palette_buffer[pn / 8] = 0;
  397. mono_palette_buffer[pn / 8] |= whitish << pn % 8;
  398. if (0 == pn % 8) color_palette_buffer[pn / 8] = 0;
  399. color_palette_buffer[pn / 8] |= colored << pn % 8;
  400. }
  401. }
  402. display.clearScreen();
  403. uint32_t rowPosition = flip ? imageOffset + (height - h) * rowSize : imageOffset;
  404. for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
  405. {
  406. uint32_t in_remain = rowSize;
  407. uint32_t in_idx = 0;
  408. uint32_t in_bytes = 0;
  409. uint8_t in_byte = 0; // for depth <= 8
  410. uint8_t in_bits = 0; // for depth <= 8
  411. uint8_t out_byte = 0xFF; // white (for w%8!=0 border)
  412. uint8_t out_color_byte = 0xFF; // white (for w%8!=0 border)
  413. uint32_t out_idx = 0;
  414. file.seek(rowPosition);
  415. for (uint16_t col = 0; col < w; col++) // for each pixel
  416. {
  417. // Time to read more pixel data?
  418. if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
  419. {
  420. in_bytes = file.read(input_buffer, in_remain > sizeof(input_buffer) ? sizeof(input_buffer) : in_remain);
  421. in_remain -= in_bytes;
  422. in_idx = 0;
  423. }
  424. switch (depth)
  425. {
  426. case 24:
  427. blue = input_buffer[in_idx++];
  428. green = input_buffer[in_idx++];
  429. red = input_buffer[in_idx++];
  430. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  431. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  432. break;
  433. case 16:
  434. {
  435. uint8_t lsb = input_buffer[in_idx++];
  436. uint8_t msb = input_buffer[in_idx++];
  437. if (format == 0) // 555
  438. {
  439. blue = (lsb & 0x1F) << 3;
  440. green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
  441. red = (msb & 0x7C) << 1;
  442. }
  443. else // 565
  444. {
  445. blue = (lsb & 0x1F) << 3;
  446. green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
  447. red = (msb & 0xF8);
  448. }
  449. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  450. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  451. }
  452. break;
  453. case 1:
  454. case 4:
  455. case 8:
  456. {
  457. if (0 == in_bits)
  458. {
  459. in_byte = input_buffer[in_idx++];
  460. in_bits = 8;
  461. }
  462. uint16_t pn = (in_byte >> bitshift) & bitmask;
  463. whitish = mono_palette_buffer[pn / 8] & (0x1 << pn % 8);
  464. colored = color_palette_buffer[pn / 8] & (0x1 << pn % 8);
  465. in_byte <<= depth;
  466. in_bits -= depth;
  467. }
  468. break;
  469. }
  470. if (whitish)
  471. {
  472. // keep white
  473. }
  474. else if (colored && with_color)
  475. {
  476. out_color_byte &= ~(0x80 >> col % 8); // colored
  477. }
  478. else
  479. {
  480. out_byte &= ~(0x80 >> col % 8); // black
  481. }
  482. if ((7 == col % 8) || (col == w - 1)) // write that last byte! (for w%8!=0 border)
  483. {
  484. output_row_color_buffer[out_idx] = out_color_byte;
  485. output_row_mono_buffer[out_idx++] = out_byte;
  486. out_byte = 0xFF; // white (for w%8!=0 border)
  487. out_color_byte = 0xFF; // white (for w%8!=0 border)
  488. }
  489. } // end pixel
  490. uint16_t yrow = y + (flip ? h - row - 1 : row);
  491. display.writeImage(output_row_mono_buffer, output_row_color_buffer, x, yrow, w, 1);
  492. } // end line
  493. Serial.print("loaded in "); Serial.print(millis() - startTime); Serial.println(" ms");
  494. display.refresh();
  495. }
  496. }
  497. }
  498. file.close();
  499. if (!valid)
  500. {
  501. Serial.println("bitmap format not handled.");
  502. }
  503. }
  504. void drawBitmapFromSerialFlash_Buffered(const char *filename, int16_t x, int16_t y, bool with_color, bool partial_update, bool overwrite)
  505. {
  506. bool valid = false; // valid format to be handled
  507. bool flip = true; // bitmap is stored bottom-to-top
  508. uint32_t startTime = millis();
  509. if ((x >= display.width()) || (y >= display.height())) return;
  510. Serial.println();
  511. Serial.print("Loading image '");
  512. Serial.print(filename);
  513. Serial.println('\'');
  514. SerialFlashFile file = SerialFlash.open(filename);
  515. if (!file)
  516. {
  517. Serial.print("File not found");
  518. return;
  519. }
  520. // Parse BMP header
  521. if (read16(file) == 0x4D42) // BMP signature
  522. {
  523. uint32_t fileSize = read32(file);
  524. uint32_t creatorBytes = read32(file);
  525. uint32_t imageOffset = read32(file); // Start of image data
  526. uint32_t headerSize = read32(file);
  527. uint32_t width = read32(file);
  528. uint32_t height = read32(file);
  529. uint16_t planes = read16(file);
  530. uint16_t depth = read16(file); // bits per pixel
  531. uint32_t format = read32(file);
  532. if ((planes == 1) && ((format == 0) || (format == 3))) // uncompressed is handled, 565 also
  533. {
  534. Serial.print("File size: "); Serial.println(fileSize);
  535. Serial.print("Image Offset: "); Serial.println(imageOffset);
  536. Serial.print("Header size: "); Serial.println(headerSize);
  537. Serial.print("Bit Depth: "); Serial.println(depth);
  538. Serial.print("Image size: ");
  539. Serial.print(width);
  540. Serial.print('x');
  541. Serial.println(height);
  542. // BMP rows are padded (if needed) to 4-byte boundary
  543. uint32_t rowSize = (width * depth / 8 + 3) & ~3;
  544. if (depth < 8) rowSize = ((width * depth + 8 - depth) / 8 + 3) & ~3;
  545. if (height < 0)
  546. {
  547. height = -height;
  548. flip = false;
  549. }
  550. uint16_t w = width;
  551. uint16_t h = height;
  552. if ((x + w - 1) >= display.width()) w = display.width() - x;
  553. if ((y + h - 1) >= display.height()) h = display.height() - y;
  554. //if (w <= max_row_width) // handle with direct drawing
  555. {
  556. valid = true;
  557. uint8_t bitmask = 0xFF;
  558. uint8_t bitshift = 8 - depth;
  559. uint16_t red, green, blue;
  560. bool whitish, colored;
  561. if (depth == 1) with_color = false;
  562. if (depth <= 8)
  563. {
  564. if (depth < 8) bitmask >>= depth;
  565. //file.seek(54); //palette is always @ 54
  566. file.seek(imageOffset - (4 << depth)); // 54 for regular, diff for colorsimportant
  567. for (uint16_t pn = 0; pn < (1 << depth); pn++)
  568. {
  569. blue = read8(file);
  570. green = read8(file);
  571. red = read8(file);
  572. read8(file);
  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. if (0 == pn % 8) mono_palette_buffer[pn / 8] = 0;
  576. mono_palette_buffer[pn / 8] |= whitish << pn % 8;
  577. if (0 == pn % 8) color_palette_buffer[pn / 8] = 0;
  578. color_palette_buffer[pn / 8] |= colored << pn % 8;
  579. }
  580. }
  581. if (partial_update) display.setPartialWindow(x, y, w, h);
  582. else display.setFullWindow();
  583. display.firstPage();
  584. do
  585. {
  586. if (!overwrite) display.fillScreen(GxEPD_WHITE);
  587. uint32_t rowPosition = flip ? imageOffset + (height - h) * rowSize : imageOffset;
  588. for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
  589. {
  590. uint32_t in_remain = rowSize;
  591. uint32_t in_idx = 0;
  592. uint32_t in_bytes = 0;
  593. uint8_t in_byte = 0; // for depth <= 8
  594. uint8_t in_bits = 0; // for depth <= 8
  595. uint16_t color = GxEPD_WHITE;
  596. file.seek(rowPosition);
  597. for (uint16_t col = 0; col < w; col++) // for each pixel
  598. {
  599. // Time to read more pixel data?
  600. if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
  601. {
  602. in_bytes = file.read(input_buffer, in_remain > sizeof(input_buffer) ? sizeof(input_buffer) : in_remain);
  603. in_remain -= in_bytes;
  604. in_idx = 0;
  605. }
  606. switch (depth)
  607. {
  608. case 24:
  609. blue = input_buffer[in_idx++];
  610. green = input_buffer[in_idx++];
  611. red = input_buffer[in_idx++];
  612. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  613. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  614. break;
  615. case 16:
  616. {
  617. uint8_t lsb = input_buffer[in_idx++];
  618. uint8_t msb = input_buffer[in_idx++];
  619. if (format == 0) // 555
  620. {
  621. blue = (lsb & 0x1F) << 3;
  622. green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
  623. red = (msb & 0x7C) << 1;
  624. }
  625. else // 565
  626. {
  627. blue = (lsb & 0x1F) << 3;
  628. green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
  629. red = (msb & 0xF8);
  630. }
  631. whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80); // whitish
  632. colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0)); // reddish or yellowish?
  633. }
  634. break;
  635. case 1:
  636. case 4:
  637. case 8:
  638. {
  639. if (0 == in_bits)
  640. {
  641. in_byte = input_buffer[in_idx++];
  642. in_bits = 8;
  643. }
  644. uint16_t pn = (in_byte >> bitshift) & bitmask;
  645. whitish = mono_palette_buffer[pn / 8] & (0x1 << pn % 8);
  646. colored = color_palette_buffer[pn / 8] & (0x1 << pn % 8);
  647. in_byte <<= depth;
  648. in_bits -= depth;
  649. }
  650. break;
  651. }
  652. if (whitish)
  653. {
  654. color = GxEPD_WHITE;
  655. }
  656. else if (colored && with_color)
  657. {
  658. color = GxEPD_COLORED;
  659. }
  660. else
  661. {
  662. color = GxEPD_BLACK;
  663. }
  664. uint16_t yrow = y + (flip ? h - row - 1 : row);
  665. display.drawPixel(x + col, yrow, color);
  666. } // end pixel
  667. } // end line
  668. }
  669. while (display.nextPage());
  670. Serial.print("loaded in "); Serial.print(millis() - startTime); Serial.println(" ms");
  671. }
  672. }
  673. }
  674. file.close();
  675. if (!valid)
  676. {
  677. Serial.println("bitmap format not handled.");
  678. }
  679. }
  680. uint8_t read8(SerialFlashFile& f)
  681. {
  682. uint8_t result;
  683. f.read((void*)&result, 1);
  684. return result;
  685. }
  686. uint16_t read16(SerialFlashFile& f)
  687. {
  688. // BMP data is stored little-endian, same as Arduino.
  689. uint16_t result;
  690. f.read((void*)&result, 2);
  691. return result;
  692. }
  693. uint32_t read32(SerialFlashFile& f)
  694. {
  695. // BMP data is stored little-endian, same as Arduino.
  696. uint32_t result;
  697. f.read((void*)&result, 4);
  698. return result;
  699. }