GxEPD2_SerialFlash_Example.ino 33 KB

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