GxEPD2_EPD.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.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. #ifndef _GxEPD2_EPD_H_
  12. #define _GxEPD2_EPD_H_
  13. #include <Arduino.h>
  14. #include <SPI.h>
  15. #include <GxEPD2.h>
  16. #pragma GCC diagnostic ignored "-Wunused-parameter"
  17. class GxEPD2_EPD
  18. {
  19. public:
  20. // attributes
  21. const uint16_t WIDTH;
  22. const uint16_t HEIGHT;
  23. const GxEPD2::Panel panel;
  24. const bool hasColor;
  25. const bool hasPartialUpdate;
  26. const bool hasFastPartialUpdate;
  27. // constructor
  28. GxEPD2_EPD(int8_t cs, int8_t dc, int8_t rst, int8_t busy, int8_t busy_level, uint32_t busy_timeout,
  29. uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu);
  30. virtual void init(uint32_t serial_diag_bitrate = 0); // serial_diag_bitrate = 0 : disabled
  31. virtual void init(uint32_t serial_diag_bitrate, bool initial, bool pulldown_rst_mode = false);
  32. // Support for Bitmaps (Sprites) to Controller Buffer and to Screen
  33. virtual void clearScreen(uint8_t value) = 0; // init controller memory and screen (default white)
  34. virtual void writeScreenBuffer(uint8_t value) = 0; // init controller memory (default white)
  35. // write to controller memory, without screen refresh; x and w should be multiple of 8
  36. 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;
  37. virtual void writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  38. int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  39. 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;
  40. virtual void writeImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  41. int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  42. // write sprite of native data to controller memory, without screen refresh; x and w should be multiple of 8
  43. virtual void writeNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  44. // for differential update: set current and previous buffers equal (for fast partial update to work correctly)
  45. virtual void writeScreenBufferAgain(uint8_t value = 0xFF) // init controller memory (default white)
  46. {
  47. // most controllers with differential update do switch buffers on refresh, can use:
  48. writeScreenBuffer(value);
  49. }
  50. virtual void writeImageAgain(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)
  51. {
  52. // most controllers with differential update do switch buffers on refresh, can use:
  53. writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
  54. }
  55. virtual void writeImagePartAgain(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  56. int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
  57. {
  58. // most controllers with differential update do switch buffers on refresh, can use:
  59. writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  60. }
  61. // write to controller memory, with screen refresh; x and w should be multiple of 8
  62. 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;
  63. virtual void drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  64. int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  65. 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;
  66. virtual void drawImagePart(const uint8_t* black, const uint8_t* color, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  67. int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  68. // write sprite of native data to controller memory, with screen refresh; x and w should be multiple of 8
  69. virtual void drawNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  70. virtual void refresh(bool partial_update_mode = false) = 0; // screen refresh from controller memory to full screen
  71. virtual void refresh(int16_t x, int16_t y, int16_t w, int16_t h) = 0; // screen refresh from controller memory, partial screen
  72. virtual void powerOff() = 0; // turns off generation of panel driving voltages, avoids screen fading over time
  73. virtual void hibernate() = 0; // turns powerOff() and sets controller to deep sleep for minimum power use, ONLY if wakeable by RST (rst >= 0)
  74. virtual void setPaged() {}; // for GxEPD2_154c paged workaround
  75. static inline uint16_t gx_uint16_min(uint16_t a, uint16_t b)
  76. {
  77. return (a < b ? a : b);
  78. };
  79. static inline uint16_t gx_uint16_max(uint16_t a, uint16_t b)
  80. {
  81. return (a > b ? a : b);
  82. };
  83. protected:
  84. void _reset();
  85. void _waitWhileBusy(const char* comment = 0, uint16_t busy_time = 5000);
  86. void _writeCommand(uint8_t c);
  87. void _writeData(uint8_t d);
  88. void _writeData(const uint8_t* data, uint16_t n);
  89. void _writeDataPGM(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes = 0);
  90. void _writeDataPGM_sCS(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes = 0);
  91. void _writeCommandData(const uint8_t* pCommandData, uint8_t datalen);
  92. void _writeCommandDataPGM(const uint8_t* pCommandData, uint8_t datalen);
  93. protected:
  94. int8_t _cs, _dc, _rst, _busy, _busy_level;
  95. uint32_t _busy_timeout;
  96. bool _diag_enabled, _pulldown_rst_mode;
  97. SPISettings _spi_settings;
  98. bool _initial_write, _initial_refresh;
  99. bool _power_is_on, _using_partial_mode, _hibernating;
  100. };
  101. #endif