GxEPD2_EPD.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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, uint16_t reset_duration = 20, 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 writeImageForFullRefresh(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)
  38. {
  39. // writeImage is independent from refresh mode for most controllers, exception e.g. SSD1681
  40. writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
  41. }
  42. virtual void writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  43. int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  44. // 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;
  45. // 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,
  46. // int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  47. // write sprite of native data to controller memory, without screen refresh; x and w should be multiple of 8
  48. // 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;
  49. // for differential update: set current and previous buffers equal (for fast partial update to work correctly)
  50. virtual void writeScreenBufferAgain(uint8_t value = 0xFF) // init controller memory (default white)
  51. {
  52. // most controllers with differential update do switch buffers on refresh, can use:
  53. writeScreenBuffer(value);
  54. }
  55. 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)
  56. {
  57. // most controllers with differential update do switch buffers on refresh, can use:
  58. writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
  59. }
  60. virtual void writeImagePartAgain(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  61. int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false)
  62. {
  63. // most controllers with differential update do switch buffers on refresh, can use:
  64. writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  65. }
  66. // write to controller memory, with screen refresh; x and w should be multiple of 8
  67. // 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;
  68. // virtual void drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  69. // 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 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;
  71. // 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,
  72. // int16_t x, int16_t y, int16_t w, int16_t h, bool invert = false, bool mirror_y = false, bool pgm = false) = 0;
  73. // write sprite of native data to controller memory, with screen refresh; x and w should be multiple of 8
  74. // 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;
  75. virtual void refresh(bool partial_update_mode = false) = 0; // screen refresh from controller memory to full screen
  76. virtual void refresh(int16_t x, int16_t y, int16_t w, int16_t h) = 0; // screen refresh from controller memory, partial screen
  77. virtual void powerOff() = 0; // turns off generation of panel driving voltages, avoids screen fading over time
  78. virtual void hibernate() = 0; // turns powerOff() and sets controller to deep sleep for minimum power use, ONLY if wakeable by RST (rst >= 0)
  79. virtual void setPaged() {}; // for GxEPD2_154c paged workaround
  80. static inline uint16_t gx_uint16_min(uint16_t a, uint16_t b)
  81. {
  82. return (a < b ? a : b);
  83. };
  84. static inline uint16_t gx_uint16_max(uint16_t a, uint16_t b)
  85. {
  86. return (a > b ? a : b);
  87. };
  88. protected:
  89. void _reset();
  90. void _waitWhileBusy(const char* comment = 0, uint16_t busy_time = 5000);
  91. void _writeCommand(uint8_t c);
  92. void _writeData(uint8_t d);
  93. void _writeData(const uint8_t* data, uint16_t n);
  94. void _writeDataPGM(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes = 0);
  95. void _writeDataPGM_sCS(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes = 0);
  96. void _writeCommandData(const uint8_t* pCommandData, uint8_t datalen);
  97. void _writeCommandDataPGM(const uint8_t* pCommandData, uint8_t datalen);
  98. void _startTransfer();
  99. void _transfer(uint8_t value);
  100. void _endTransfer();
  101. protected:
  102. int8_t _cs, _dc, _rst, _busy, _busy_level;
  103. uint32_t _busy_timeout;
  104. bool _diag_enabled, _pulldown_rst_mode;
  105. SPISettings _spi_settings;
  106. bool _initial_write, _initial_refresh;
  107. bool _power_is_on, _using_partial_mode, _hibernating;
  108. uint16_t _reset_duration;
  109. };
  110. #endif