GxEPD2_EPD.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Display Library for SPI e-paper panels from Dalian Good Display and boards from Waveshare.
  2. // Requires HW SPI and Adafruit_GFX. Caution: these e-papers require 3.3V supply AND data lines!
  3. //
  4. // based on Demo Example from Good Display: http://www.good-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. #ifndef _GxEPD2_EPD_H_
  12. #define _GxEPD2_EPD_H_
  13. #include <Arduino.h>
  14. #include <SPI.h>
  15. #define GxEPD_BLACK 0x0000
  16. #define GxEPD_DARKGREY 0x7BEF /* 128, 128, 128 */
  17. #define GxEPD_LIGHTGREY 0xC618 /* 192, 192, 192 */
  18. #define GxEPD_WHITE 0xFFFF
  19. #define GxEPD_RED 0xF800 /* 255, 0, 0 */
  20. #define GxEPD_YELLOW GxEPD_RED
  21. #define GxEPD_COLORED GxEPD_RED
  22. class GxEPD2
  23. {
  24. public:
  25. enum Panel
  26. {
  27. GDEP015OC1, Waveshare_1_54_bw = GDEP015OC1,
  28. GDE0213B1, Waveshare_2_13_bw = GDE0213B1,
  29. GDEH029A1, Waveshare_2_9_bw = GDEH029A1,
  30. GDEW027W3, Waveshare_2_7_bw = GDEW027W3,
  31. GDEW042T2, Waveshare_4_2_bw = GDEW042T2,
  32. GDEW0583T7, Waveshare_5_83_bw = GDEW0583T7,
  33. GDEW075T8, Waveshare_7_5_bw = GDEW075T8,
  34. // 3-color
  35. GDEW0154Z04, Waveshare_1_54_bwr = GDEW0154Z04,
  36. GDEW0213Z16, Waveshare_2_13_bwr = GDEW0213Z16,
  37. GDEW029Z10, Waveshare_2_9_bwr = GDEW029Z10,
  38. GDEW027C44, Waveshare_2_7_bwr = GDEW027C44,
  39. GDEW042Z15, Waveshare_4_2_bwr = GDEW042Z15,
  40. GDEW0583Z21, Waveshare_5_83_bwr = GDEW0583Z21,
  41. GDEW075Z09, Waveshare_7_5_bwr = GDEW075Z09
  42. };
  43. };
  44. class GxEPD2_EPD
  45. {
  46. public:
  47. // attributes
  48. const uint16_t WIDTH;
  49. const uint16_t HEIGHT;
  50. const GxEPD2::Panel panel;
  51. const bool hasColor;
  52. const bool hasPartialUpdate;
  53. const bool hasFastPartialUpdate;
  54. // constructor
  55. GxEPD2_EPD(int8_t cs, int8_t dc, int8_t rst, int8_t busy, int8_t busy_level, uint32_t busy_timeout,
  56. uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu);
  57. virtual void init(uint32_t serial_diag_bitrate = 0) = 0; // serial_diag_bitrate = 0 : disabled
  58. // Support for Bitmaps (Sprites) to Controller Buffer and to Screen
  59. virtual void clearScreen(uint8_t value) = 0; // init controller memory and screen (default white)
  60. virtual void writeScreenBuffer(uint8_t value) = 0; // init controller memory (default white)
  61. // write to controller memory, without screen refresh; x and w should be multiple of 8
  62. virtual void writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  63. virtual void writeImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  64. // write to controller memory, with screen refresh; x and w should be multiple of 8
  65. virtual void drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  66. virtual void drawImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  67. virtual void refresh(bool partial_update_mode = false) = 0; // screen refresh from controller memory to full screen
  68. virtual void refresh(int16_t x, int16_t y, int16_t w, int16_t h) = 0; // screen refresh from controller memory, partial screen
  69. virtual void setPaged() {}; // for GxEPD2_154c paged workaround
  70. static inline uint16_t gx_uint16_min(uint16_t a, uint16_t b)
  71. {
  72. return (a < b ? a : b);
  73. };
  74. static inline uint16_t gx_uint16_max(uint16_t a, uint16_t b)
  75. {
  76. return (a > b ? a : b);
  77. };
  78. protected:
  79. void _waitWhileBusy(const char* comment = 0, uint16_t busy_time = 5000);
  80. void _writeCommand(uint8_t c);
  81. void _writeData(uint8_t d);
  82. void _writeData(const uint8_t* data, uint16_t n);
  83. void _writeDataPGM(const uint8_t* data, uint16_t n);
  84. void _writeCommandData(const uint8_t* pCommandData, uint8_t datalen);
  85. void _writeCommandDataPGM(const uint8_t* pCommandData, uint8_t datalen);
  86. protected:
  87. int8_t _cs, _dc, _rst, _busy, _busy_level;
  88. uint32_t _busy_timeout;
  89. bool _diag_enabled;
  90. SPISettings _spi_settings;
  91. };
  92. #endif