GxEPD2_display_selection_new_style.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // 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. // Author: Jean-Marc Zingg
  7. //
  8. // Version: see library.properties
  9. //
  10. // Library: https://github.com/ZinggJM/GxEPD2
  11. // Supporting Arduino Forum Topics:
  12. // Waveshare e-paper displays with SPI: http://forum.arduino.cc/index.php?topic=487007.0
  13. // Good Display ePaper for Arduino: https://forum.arduino.cc/index.php?topic=436411.0
  14. // select the display class (only one), matching the kind of display panel
  15. #define GxEPD2_DISPLAY_CLASS GxEPD2_BW
  16. //#define GxEPD2_DISPLAY_CLASS GxEPD2_3C
  17. //#define GxEPD2_DISPLAY_CLASS GxEPD2_7C
  18. // select the display driver class (only one) for your panel
  19. //#define GxEPD2_DRIVER_CLASS GxEPD2_154 // GDEP015OC1 200x200, no longer available
  20. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_D67 // GDEH0154D67 200x200
  21. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_T8 // GDEW0154T8 152x152
  22. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_M09 // GDEW0154M09 200x200
  23. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_M10 // GDEW0154M10 152x152
  24. //#define GxEPD2_DRIVER_CLASS GxEPD2_213 // GDE0213B1 128x250, phased out
  25. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_B72 // GDEH0213B72 128x250
  26. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_B73 // GDEH0213B73 128x250
  27. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_flex // GDEW0213I5F 104x212
  28. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_M21 // GDEW0213M21 104x212
  29. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_T5D // GDEW0213T5D 104x212
  30. //#define GxEPD2_DRIVER_CLASS GxEPD2_290 // GDEH029A1 128x296
  31. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T5 // GDEW029T5 128x296
  32. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T5D // GDEW029T5D 128x296
  33. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_T94 // GDEM029T94 128x296
  34. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_M06 // GDEW029M06 128x296
  35. //#define GxEPD2_DRIVER_CLASS GxEPD2_260 // GDEW026T0 152x296
  36. //#define GxEPD2_DRIVER_CLASS GxEPD2_260_M01 // GDEW026M01 152x296
  37. //#define GxEPD2_DRIVER_CLASS GxEPD2_270 // GDEW027W3 176x264
  38. //#define GxEPD2_DRIVER_CLASS GxEPD2_371 // GDEW0371W7 240x416
  39. //#define GxEPD2_DRIVER_CLASS GxEPD2_420 // GDEW042T2 400x300
  40. //#define GxEPD2_DRIVER_CLASS GxEPD2_420_M01 // GDEW042M01 400x300
  41. //#define GxEPD2_DRIVER_CLASS GxEPD2_583 // GDEW0583T7 600x448
  42. //#define GxEPD2_DRIVER_CLASS GxEPD2_583_T8 // GDEW0583T8 648x480
  43. //#define GxEPD2_DRIVER_CLASS GxEPD2_750 // GDEW075T8 640x384
  44. //#define GxEPD2_DRIVER_CLASS GxEPD2_750_T7 // GDEW075T7 800x480
  45. // 3-color e-papers
  46. //#define GxEPD2_DRIVER_CLASS GxEPD2_154c // GDEW0154Z04 200x200, no longer available
  47. //#define GxEPD2_DRIVER_CLASS GxEPD2_154_Z90c // GDEH0154Z90 200x200
  48. //#define GxEPD2_DRIVER_CLASS GxEPD2_213c // GDEW0213Z16 104x212
  49. //#define GxEPD2_DRIVER_CLASS GxEPD2_213_Z19c // GDEW0213Z19 104x212
  50. //#define GxEPD2_DRIVER_CLASS GxEPD2_290c // GDEW029Z10 128x296
  51. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_Z13c // GDEH029Z13 128x296
  52. //#define GxEPD2_DRIVER_CLASS GxEPD2_290_C90c // GDEM029C90 128x296
  53. //#define GxEPD2_DRIVER_CLASS GxEPD2_270c // GDEW027C44 176x264
  54. //#define GxEPD2_DRIVER_CLASS GxEPD2_420c // GDEW042Z15 400x300
  55. //#define GxEPD2_DRIVER_CLASS GxEPD2_583c // GDEW0583Z21 600x448
  56. //#define GxEPD2_DRIVER_CLASS GxEPD2_750c // GDEW075Z09 640x384
  57. //#define GxEPD2_DRIVER_CLASS GxEPD2_750c_Z08 // GDEW075Z08 800x480
  58. //#define GxEPD2_DRIVER_CLASS GxEPD2_750c_Z90 // GDEH075Z90 880x528
  59. //#define GxEPD2_DRIVER_CLASS GxEPD2_1248 // GDEW1248T3 1303x984
  60. // 7-color e-paper
  61. //#define GxEPD2_DRIVER_CLASS GxEPD2_565c // Waveshare 5.65" 7-color (3C graphics)
  62. // grey levels parallel IF e-papers on Waveshare e-Paper IT8951 Driver HAT
  63. //#define GxEPD2_DRIVER_CLASS GxEPD2_it60 // ED060SCT 800x600
  64. //#define GxEPD2_DRIVER_CLASS GxEPD2_it60_1448x1072 // ED060KC1 1448x1072
  65. // SS is usually used for CS. define here for easy change
  66. #ifndef EPD_CS
  67. #define EPD_CS SS
  68. #endif
  69. #if defined(GxEPD2_DISPLAY_CLASS) && defined(GxEPD2_DRIVER_CLASS)
  70. // somehow there should be an easier way to do this
  71. #define GxEPD2_BW_IS_GxEPD2_BW true
  72. #define GxEPD2_3C_IS_GxEPD2_3C true
  73. #define GxEPD2_7C_IS_GxEPD2_7C true
  74. #define GxEPD2_1248_IS_GxEPD2_1248 true
  75. #define IS_GxEPD(c, x) (c##x)
  76. #define IS_GxEPD2_BW(x) IS_GxEPD(GxEPD2_BW_IS_, x)
  77. #define IS_GxEPD2_3C(x) IS_GxEPD(GxEPD2_3C_IS_, x)
  78. #define IS_GxEPD2_7C(x) IS_GxEPD(GxEPD2_7C_IS_, x)
  79. #define IS_GxEPD2_1248(x) IS_GxEPD(GxEPD2_1248_IS_, x)
  80. #include "GxEPD2_selection_check.h"
  81. #if defined (ESP8266)
  82. #define MAX_DISPLAY_BUFFER_SIZE (81920ul-34000ul-5000ul) // ~34000 base use, change 5000 to your application use
  83. #if IS_GxEPD2_BW(GxEPD2_DISPLAY_CLASS)
  84. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  85. #elif IS_GxEPD2_3C(GxEPD2_DISPLAY_CLASS)
  86. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  87. #elif IS_GxEPD2_7C(GxEPD2_DISPLAY_CLASS)
  88. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2))
  89. #endif
  90. // adapt the constructor parameters to your wiring
  91. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=D8*/ EPD_CS, /*DC=D3*/ 0, /*RST=D4*/ 2, /*BUSY=D2*/ 4));
  92. // mapping of Waveshare e-Paper ESP8266 Driver Board, new version
  93. //GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=15*/ EPD_CS, /*DC=4*/ 4, /*RST=2*/ 2, /*BUSY=5*/ 5));
  94. // mapping of Waveshare e-Paper ESP8266 Driver Board, old version
  95. //GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=15*/ EPD_CS, /*DC=4*/ 4, /*RST=5*/ 5, /*BUSY=16*/ 16));
  96. #endif
  97. #if defined(ESP32)
  98. #define MAX_DISPLAY_BUFFER_SIZE 65536ul // e.g.
  99. #if IS_GxEPD2_BW(GxEPD2_DISPLAY_CLASS)
  100. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  101. #elif IS_GxEPD2_3C(GxEPD2_DISPLAY_CLASS)
  102. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  103. #elif IS_GxEPD2_7C(GxEPD2_DISPLAY_CLASS)
  104. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2))
  105. #endif
  106. // adapt the constructor parameters to your wiring
  107. #if !IS_GxEPD2_1248(GxEPD2_DRIVER_CLASS)
  108. #if defined(ARDUINO_LOLIN_D32_PRO)
  109. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=5*/ EPD_CS, /*DC=*/ 0, /*RST=*/ 2, /*BUSY=*/ 15));
  110. #elif defined(ARDUINO_ESP32_DEV) // e.g. TTGO T8 ESP32-WROVER
  111. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=5*/ EPD_CS, /*DC=*/ 2, /*RST=*/ 0, /*BUSY=*/ 4));
  112. #else
  113. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=5*/ EPD_CS, /*DC=*/ 17, /*RST=*/ 16, /*BUSY=*/ 4));
  114. #endif
  115. #else // GxEPD2_1248
  116. // Waveshare 12.48 b/w SPI display board and frame or Good Display 12.48 b/w panel GDEW1248T3
  117. // general constructor for use with all parameters, e.g. for Waveshare ESP32 driver board mounted on connection board
  118. GxEPD2_BW < GxEPD2_1248, GxEPD2_1248::HEIGHT / 4 > display(GxEPD2_1248(/*sck=*/ 13, /*miso=*/ 12, /*mosi=*/ 14,
  119. /*cs_m1=*/ 23, /*cs_s1=*/ 22, /*cs_m2=*/ 16, /*cs_s2=*/ 19,
  120. /*dc1=*/ 25, /*dc2=*/ 17, /*rst1=*/ 33, /*rst2=*/ 5,
  121. /*busy_m1=*/ 32, /*busy_s1=*/ 26, /*busy_m2=*/ 18, /*busy_s2=*/ 4));
  122. #endif
  123. #endif
  124. // can't use package "STMF1 Boards (STM32Duino.com)" (Roger Clark) anymore with Adafruit_GFX, use "STM32 Boards (selected from submenu)" (STMicroelectronics)
  125. #if defined(ARDUINO_ARCH_STM32)
  126. #define MAX_DISPLAY_BUFFER_SIZE 15000ul // ~15k is a good compromise
  127. #if IS_GxEPD2_BW(GxEPD2_DISPLAY_CLASS)
  128. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  129. #elif IS_GxEPD2_3C(GxEPD2_DISPLAY_CLASS)
  130. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  131. #elif IS_GxEPD2_7C(GxEPD2_DISPLAY_CLASS)
  132. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2))
  133. #endif
  134. // adapt the constructor parameters to your wiring
  135. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=4*/ EPD_CS, /*DC=*/ 3, /*RST=*/ 2, /*BUSY=*/ 1));
  136. #endif
  137. #if defined(__AVR)
  138. #if defined (ARDUINO_AVR_MEGA2560) // Note: SS is on 53 on MEGA
  139. #define MAX_DISPLAY_BUFFER_SIZE 5000 // e.g. full height for 200x200
  140. #else // Note: SS is on 10 on UNO, NANO
  141. #define MAX_DISPLAY_BUFFER_SIZE 800 //
  142. #endif
  143. #if IS_GxEPD2_BW(GxEPD2_DISPLAY_CLASS)
  144. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  145. #elif IS_GxEPD2_3C(GxEPD2_DISPLAY_CLASS)
  146. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  147. #elif IS_GxEPD2_7C(GxEPD2_DISPLAY_CLASS)
  148. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2))
  149. #endif
  150. // adapt the constructor parameters to your wiring
  151. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  152. #endif
  153. #if defined(ARDUINO_ARCH_SAM)
  154. #define MAX_DISPLAY_BUFFER_SIZE 32768ul // e.g., up to 96k
  155. #if IS_GxEPD2_BW(GxEPD2_DISPLAY_CLASS)
  156. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  157. #elif IS_GxEPD2_3C(GxEPD2_DISPLAY_CLASS)
  158. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  159. #elif IS_GxEPD2_7C(GxEPD2_DISPLAY_CLASS)
  160. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2))
  161. #endif
  162. // adapt the constructor parameters to your wiring
  163. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=77*/ EPD_CS, /*DC=*/ 8, /*RST=*/ 9, /*BUSY=*/ 7));
  164. #endif
  165. #if defined(ARDUINO_ARCH_SAMD)
  166. #define MAX_DISPLAY_BUFFER_SIZE 15000ul // ~15k is a good compromise
  167. #if IS_GxEPD2_BW(GxEPD2_DISPLAY_CLASS)
  168. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8) ? EPD::HEIGHT : MAX_DISPLAY_BUFFER_SIZE / (EPD::WIDTH / 8))
  169. #elif IS_GxEPD2_3C(GxEPD2_DISPLAY_CLASS)
  170. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE / 2) / (EPD::WIDTH / 8))
  171. #elif IS_GxEPD2_7C(GxEPD2_DISPLAY_CLASS)
  172. #define MAX_HEIGHT(EPD) (EPD::HEIGHT <= (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2) ? EPD::HEIGHT : (MAX_DISPLAY_BUFFER_SIZE) / (EPD::WIDTH / 2))
  173. #endif
  174. // adapt the constructor parameters to your wiring
  175. GxEPD2_DISPLAY_CLASS<GxEPD2_DRIVER_CLASS, MAX_HEIGHT(GxEPD2_DRIVER_CLASS)> display(GxEPD2_DRIVER_CLASS(/*CS=4*/ 4, /*DC=*/ 7, /*RST=*/ 6, /*BUSY=*/ 5));
  176. #endif
  177. #endif