GxEPD2_579_GDEY0579T93.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. // Display Library 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. // based on Demo Example from Good Display, available here: https://www.good-display.com/comp/xcompanyFile/downloadNew.do?appId=24&fid=1781&id=1133
  5. // Panel: GDEY0579T93 : https://www.good-display.com/product/439.html
  6. // Controller : SSD1683 : https://v4.cecdn.yun300.cn/100001_1909185148/SSD1683.PDF
  7. //
  8. // Author: Jean-Marc Zingg
  9. //
  10. // Version: see library.properties
  11. //
  12. // Library: https://github.com/ZinggJM/GxEPD2
  13. #include "GxEPD2_579_GDEY0579T93.h"
  14. GxEPD2_579_GDEY0579T93::GxEPD2_579_GDEY0579T93(int16_t cs, int16_t dc, int16_t rst, int16_t busy) :
  15. GxEPD2_EPD(cs, dc, rst, busy, HIGH, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
  16. {
  17. }
  18. void GxEPD2_579_GDEY0579T93::clearScreen(uint8_t value)
  19. {
  20. // full refresh needed for all cases (previous != screen)
  21. _writeScreenBuffer(0x26, value); // set previous
  22. _writeScreenBuffer(0x24, value); // set current
  23. refresh(false); // full refresh
  24. _initial_write = false;
  25. }
  26. void GxEPD2_579_GDEY0579T93::writeScreenBuffer(uint8_t value)
  27. {
  28. if (_initial_write) return clearScreen(value);
  29. _writeScreenBuffer(0x24, value); // set current
  30. }
  31. void GxEPD2_579_GDEY0579T93::writeScreenBufferAgain(uint8_t value)
  32. {
  33. _writeScreenBuffer(0x24, value); // set current
  34. _writeScreenBuffer(0x26, value); // set previous
  35. }
  36. void GxEPD2_579_GDEY0579T93::_writeScreenBuffer(uint8_t command, uint8_t value)
  37. {
  38. if (!_init_display_done) _InitDisplay();
  39. _setPartialRamAreaMaster(0, 0, WIDTH / 2, HEIGHT);
  40. _writeCommand(command);
  41. _startTransfer();
  42. for (uint32_t i = 0; i < uint32_t(WIDTH / 2) * uint32_t(HEIGHT) / 8; i++)
  43. {
  44. _transfer(value);
  45. }
  46. _endTransfer();
  47. _setPartialRamAreaMaster(0, HEIGHT / 2, WIDTH / 2, HEIGHT);
  48. _writeCommand(command);
  49. _startTransfer();
  50. for (uint32_t i = 0; i < uint32_t(WIDTH / 2) * uint32_t(HEIGHT) / 8; i++)
  51. {
  52. _transfer(value);
  53. }
  54. _endTransfer();
  55. _setPartialRamAreaSlave(0, 0, WIDTH / 2, HEIGHT / 2);
  56. _writeCommand(command | 0x80);
  57. _startTransfer();
  58. for (uint32_t i = 0; i < uint32_t(WIDTH / 2) * uint32_t(HEIGHT) / 8; i++)
  59. {
  60. _transfer(value);
  61. }
  62. _endTransfer();
  63. _setPartialRamAreaSlave(0, HEIGHT / 2, WIDTH / 2, HEIGHT);
  64. _writeCommand(command | 0x80);
  65. _startTransfer();
  66. for (uint32_t i = 0; i < uint32_t(WIDTH / 2) * uint32_t(HEIGHT) / 8; i++)
  67. {
  68. _transfer(value);
  69. }
  70. _endTransfer();
  71. }
  72. void GxEPD2_579_GDEY0579T93::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  73. {
  74. _writeImage(0x24, bitmap, x, y, w, h, invert, mirror_y, pgm);
  75. }
  76. void GxEPD2_579_GDEY0579T93::writeImageForFullRefresh(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  77. {
  78. _writeImage(0x26, bitmap, x, y, w, h, invert, mirror_y, pgm); // set previous
  79. _writeImage(0x24, bitmap, x, y, w, h, invert, mirror_y, pgm); // set current
  80. }
  81. void GxEPD2_579_GDEY0579T93::writeImageAgain(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  82. {
  83. _writeImage(0x26, bitmap, x, y, w, h, invert, mirror_y, pgm); // set previous
  84. _writeImage(0x24, bitmap, x, y, w, h, invert, mirror_y, pgm); // set current
  85. }
  86. void GxEPD2_579_GDEY0579T93::_writeImage(uint8_t command, const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  87. {
  88. //Serial.print("writeImage("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  89. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  90. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  91. int16_t wbb = (w + 7) / 8; // width bytes, bitmaps are padded
  92. x -= x >= 0 ? x % 8 : -x % 8; // byte boundary
  93. w = wbb * 8; // byte boundary
  94. int16_t x1 = x < 0 ? 0 : x; // limit
  95. int16_t y1 = y < 0 ? 0 : y; // limit
  96. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  97. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  98. int16_t dx1 = x1 - x; // offset into bitmap
  99. int16_t dy1 = y1 - y; // offset into bitmap
  100. w1 -= dx1;
  101. h1 -= dy1;
  102. if ((w1 <= 0) || (h1 <= 0)) return;
  103. if (!_init_display_done) _InitDisplay();
  104. if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
  105. _writeFromImage(command, bitmap, x1, y1, w1, h1, wbb, h, dx1, dy1, invert, mirror_y, pgm);
  106. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  107. }
  108. void GxEPD2_579_GDEY0579T93::_writeFromImage(uint8_t command, const uint8_t bitmap[], int16_t x1, int16_t y1, int16_t w1, int16_t h1,
  109. int16_t wbb, int16_t hb, int16_t dx, int16_t dy, bool invert, bool mirror_y, bool pgm)
  110. {
  111. if ((x1 < WIDTH / 2) && (y1 < HEIGHT / 2) && true) // upper left, near connector
  112. { // memory is on slave controller
  113. int16_t ws = x1 + w1 <= WIDTH / 2 ? w1 : WIDTH / 2 - x1;
  114. int16_t hs = y1 + h1 <= HEIGHT / 2 ? h1 : HEIGHT / 2 - y1;
  115. //Serial.print("upper left ws="); Serial.print(ws); Serial.print(" hs="); Serial.print(hs); Serial.print(" dx="); Serial.print(dx); Serial.print(" dy="); Serial.println(dy);
  116. _setPartialRamAreaSlave(x1, y1, ws, hs, 0x03);
  117. _writeCommand(command | 0x80);
  118. _writeDataFromImage(bitmap, ws, hs, wbb, hb, dx, dy, invert, mirror_y, pgm);
  119. }
  120. if (((x1 + w1) > WIDTH / 2) && (y1 < HEIGHT / 2) && true) // upper right, opposite to connector
  121. { // memory is on master controller
  122. int16_t wm = x1 >= WIDTH / 2 ? w1 : (x1 + w1) - WIDTH / 2;
  123. int16_t hm = y1 + h1 <= HEIGHT / 2 ? h1 : HEIGHT / 2 - y1;
  124. int16_t xm = x1 < WIDTH / 2 ? WIDTH / 2 - wm : WIDTH - x1 - wm;
  125. int16_t ym = y1 < HEIGHT / 2 ? HEIGHT / 2 - hm : HEIGHT - y1 - hm;
  126. //Serial.print("upper right wm="); Serial.print(wm); Serial.print(" hm="); Serial.print(hm); Serial.print(" dx="); Serial.print(dx); Serial.print(" dy="); Serial.println(dy);
  127. _setPartialRamAreaMaster(xm, y1, wm, hm, 0x02);
  128. _writeCommand(command);
  129. _writeDataFromImage(bitmap, wm, hm, wbb, hb, dx + w1 - wm, dy, invert, mirror_y, pgm);
  130. }
  131. if ((x1 < WIDTH / 2) && ((y1 + h1) > HEIGHT / 2) && true) // lower left, near connector
  132. { // memory is on slave controller
  133. int16_t ws = x1 + w1 <= WIDTH / 2 ? w1 : WIDTH / 2 - x1;
  134. int16_t hs = y1 >= HEIGHT / 2 ? h1 : (y1 + h1) - HEIGHT / 2;
  135. int16_t ys = y1 >= HEIGHT / 2 ? y1 : HEIGHT / 2;
  136. //Serial.print("lower left ws="); Serial.print(ws); Serial.print(" hs="); Serial.print(hs); Serial.print(" dx="); Serial.print(dx); Serial.print(" dy="); Serial.println(dy);
  137. _setPartialRamAreaSlave(x1, ys, ws, hs, 0x03);
  138. _writeCommand(command | 0x80);
  139. _writeDataFromImage(bitmap, ws, hs, wbb, hb, dx, dy + h1 - hs, invert, mirror_y, pgm);
  140. }
  141. if (((x1 + w1) > WIDTH / 2) && ((y1 + h1) > HEIGHT / 2) && true) // lower right, opposite to connector
  142. { // memory is on master controller
  143. int16_t wm = x1 >= WIDTH / 2 ? w1 : (x1 + w1) - WIDTH / 2;
  144. int16_t hm = y1 >= HEIGHT / 2 ? h1 : (y1 + h1) - HEIGHT / 2;
  145. int16_t xm = x1 < WIDTH / 2 ? WIDTH / 2 - wm : WIDTH - x1 - wm;
  146. int16_t ym = y1 >= HEIGHT / 2 ? y1 : HEIGHT / 2;
  147. //Serial.print("lower right wm="); Serial.print(wm); Serial.print(" hm="); Serial.print(hm); Serial.print(" dx="); Serial.print(dx); Serial.print(" dy="); Serial.println(dy);
  148. _setPartialRamAreaMaster(xm, ym, wm, hm, 0x02);
  149. _writeCommand(command);
  150. _writeDataFromImage(bitmap, wm, hm, wbb, hb, dx + w1 - wm, dy + h1 - hm, invert, mirror_y, pgm);
  151. }
  152. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  153. }
  154. void GxEPD2_579_GDEY0579T93::_writeDataFromImage(const uint8_t bitmap[], int16_t w, int16_t h, int16_t wbb, int16_t hb, int16_t dx, int16_t dy, bool invert, bool mirror_y, bool pgm)
  155. {
  156. _startTransfer();
  157. for (int16_t i = 0; i < h; i++)
  158. {
  159. for (int16_t j = 0; j < w; j += 8)
  160. {
  161. uint8_t data;
  162. // use wbb, h of bitmap for index!
  163. int16_t idx = mirror_y ? ((j + dx) / 8 + ((hb - 1 - (i + dy))) * wbb) : ((j + dx) / 8 + (i + dy) * wbb);
  164. if (pgm)
  165. {
  166. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  167. data = pgm_read_byte(&bitmap[idx]);
  168. #else
  169. data = bitmap[idx];
  170. #endif
  171. }
  172. else
  173. {
  174. data = bitmap[idx];
  175. }
  176. if (invert) data = ~data;
  177. _transfer(data);
  178. }
  179. }
  180. _endTransfer();
  181. }
  182. void GxEPD2_579_GDEY0579T93::writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  183. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  184. {
  185. _writeImagePart(0x24, bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  186. }
  187. void GxEPD2_579_GDEY0579T93::writeImagePartAgain(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  188. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  189. {
  190. _writeImagePart(0x24, bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  191. _writeImagePart(0x26, bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  192. }
  193. void GxEPD2_579_GDEY0579T93::_writeImagePart(uint8_t command, const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  194. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  195. {
  196. //Serial.print("writeImagePart("); Serial.print(x_part); Serial.print(", "); Serial.print(y_part); Serial.print(", ");
  197. //Serial.print(w_bitmap); Serial.print(", "); Serial.print(h_bitmap); Serial.print(", ");
  198. //Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  199. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  200. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  201. if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return;
  202. if ((x_part < 0) || (x_part >= w_bitmap)) return;
  203. if ((y_part < 0) || (y_part >= h_bitmap)) return;
  204. int16_t wb_bitmap = (w_bitmap + 7) / 8; // width bytes, bitmaps are padded
  205. x_part -= x_part % 8; // byte boundary
  206. w = w_bitmap - x_part < w ? w_bitmap - x_part : w; // limit
  207. h = h_bitmap - y_part < h ? h_bitmap - y_part : h; // limit
  208. x -= x % 8; // byte boundary
  209. w = 8 * ((w + 7) / 8); // byte boundary, bitmaps are padded
  210. int16_t x1 = x < 0 ? 0 : x; // limit
  211. int16_t y1 = y < 0 ? 0 : y; // limit
  212. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  213. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  214. int16_t dx = x1 - x;
  215. int16_t dy = y1 - y;
  216. w1 -= dx;
  217. h1 -= dy;
  218. if ((w1 <= 0) || (h1 <= 0)) return;
  219. if (!_init_display_done) _InitDisplay();
  220. if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
  221. _writeFromImage(command, bitmap, x1, y1, w1, h1, wb_bitmap, h_bitmap, dx + x_part, dy + y_part, invert, mirror_y, pgm);
  222. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  223. }
  224. void GxEPD2_579_GDEY0579T93::writeImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  225. {
  226. if (black)
  227. {
  228. writeImage(black, x, y, w, h, invert, mirror_y, pgm);
  229. }
  230. }
  231. void GxEPD2_579_GDEY0579T93::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,
  232. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  233. {
  234. if (black)
  235. {
  236. writeImagePart(black, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  237. }
  238. }
  239. void GxEPD2_579_GDEY0579T93::writeNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  240. {
  241. if (data1)
  242. {
  243. writeImage(data1, x, y, w, h, invert, mirror_y, pgm);
  244. }
  245. }
  246. void GxEPD2_579_GDEY0579T93::drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  247. {
  248. writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
  249. refresh(x, y, w, h);
  250. writeImageAgain(bitmap, x, y, w, h, invert, mirror_y, pgm);
  251. }
  252. void GxEPD2_579_GDEY0579T93::drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  253. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  254. {
  255. writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  256. refresh(x, y, w, h);
  257. writeImagePartAgain(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  258. }
  259. void GxEPD2_579_GDEY0579T93::drawImage(const uint8_t* black, const uint8_t* color, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  260. {
  261. if (black)
  262. {
  263. drawImage(black, x, y, w, h, invert, mirror_y, pgm);
  264. }
  265. }
  266. void GxEPD2_579_GDEY0579T93::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,
  267. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  268. {
  269. if (black)
  270. {
  271. drawImagePart(black, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  272. }
  273. }
  274. void GxEPD2_579_GDEY0579T93::drawNative(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  275. {
  276. if (data1)
  277. {
  278. drawImage(data1, x, y, w, h, invert, mirror_y, pgm);
  279. }
  280. }
  281. void GxEPD2_579_GDEY0579T93::refresh(bool partial_update_mode)
  282. {
  283. if (partial_update_mode) refresh(0, 0, WIDTH, HEIGHT);
  284. else
  285. {
  286. _setPartialRamAreaSlave(0, 0, WIDTH / 2, HEIGHT);
  287. _setPartialRamAreaMaster(0, 0, WIDTH / 2, HEIGHT);
  288. _Update_Full();
  289. _initial_refresh = false; // initial full update done
  290. }
  291. }
  292. void GxEPD2_579_GDEY0579T93::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
  293. {
  294. if (_initial_refresh) return refresh(false); // initial update needs be full update
  295. // intersection with screen
  296. int16_t w1 = x < 0 ? w + x : w; // reduce
  297. int16_t h1 = y < 0 ? h + y : h; // reduce
  298. int16_t x1 = x < 0 ? 0 : x; // limit
  299. int16_t y1 = y < 0 ? 0 : y; // limit
  300. w1 = x1 + w1 < int16_t(WIDTH) ? w1 : int16_t(WIDTH) - x1; // limit
  301. h1 = y1 + h1 < int16_t(HEIGHT) ? h1 : int16_t(HEIGHT) - y1; // limit
  302. if ((w1 <= 0) || (h1 <= 0)) return;
  303. // make x1, w1 multiple of 8
  304. w1 += x1 % 8;
  305. if (w1 % 8 > 0) w1 += 8 - w1 % 8;
  306. x1 -= x1 % 8;
  307. _setPartialRamAreaSlave(0, 0, WIDTH / 2, HEIGHT);
  308. _setPartialRamAreaMaster(0, 0, WIDTH / 2, HEIGHT);
  309. _Update_Part();
  310. }
  311. void GxEPD2_579_GDEY0579T93::powerOff()
  312. {
  313. _PowerOff();
  314. }
  315. void GxEPD2_579_GDEY0579T93::hibernate()
  316. {
  317. _PowerOff();
  318. if (_rst >= 0)
  319. {
  320. _writeCommand(0x10); // deep sleep mode
  321. _writeData(0x1); // enter deep sleep
  322. _hibernating = true;
  323. _init_display_done = false;
  324. }
  325. }
  326. void GxEPD2_579_GDEY0579T93::_setPartialRamAreaMaster(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t mode)
  327. {
  328. //Serial.print("_setPartialRamAreaMaster("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  329. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  330. _setPartialRamArea(x, y, w, h, mode, 0x00);
  331. }
  332. void GxEPD2_579_GDEY0579T93::_setPartialRamAreaSlave(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t mode)
  333. {
  334. //Serial.print("_setPartialRamAreaSlave("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  335. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  336. _setPartialRamArea(x, y, w, h, mode, 0x80);
  337. }
  338. void GxEPD2_579_GDEY0579T93::_setPartialRamArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t mode, uint8_t target)
  339. {
  340. _writeCommand(0x11 | target); // set ram entry mode
  341. _writeData(mode);
  342. switch (mode)
  343. {
  344. case 0x00: // x decrement, y decrement
  345. _writeCommand(0x44 | target);
  346. _writeData((x + w - 1) / 8);
  347. _writeData(x / 8);
  348. _writeCommand(0x45 | target);
  349. _writeData((y + h - 1) % 256);
  350. _writeData((y + h - 1) / 256);
  351. _writeData(y % 256);
  352. _writeData(y / 256);
  353. _writeCommand(0x4e | target);
  354. _writeData((x + w - 1) / 8);
  355. _writeCommand(0x4f | target);
  356. _writeData((y + h - 1) % 256);
  357. _writeData((y + h - 1) / 256);
  358. break;
  359. case 0x01: // x increment, y decrement
  360. _writeCommand(0x44 | target);
  361. _writeData(x / 8);
  362. _writeData((x + w - 1) / 8);
  363. _writeCommand(0x45 | target);
  364. _writeData((y + h - 1) % 256);
  365. _writeData((y + h - 1) / 256);
  366. _writeData(y % 256);
  367. _writeData(y / 256);
  368. _writeCommand(0x4e | target);
  369. _writeData(x / 8);
  370. _writeCommand(0x4f | target);
  371. _writeData((y + h - 1) % 256);
  372. _writeData((y + h - 1) / 256);
  373. break;
  374. case 0x02: // x decrement, y increment
  375. _writeCommand(0x44 | target);
  376. _writeData((x + w - 1) / 8);
  377. _writeData(x / 8);
  378. _writeCommand(0x45 | target);
  379. _writeData(y % 256);
  380. _writeData(y / 256);
  381. _writeData((y + h - 1) % 256);
  382. _writeData((y + h - 1) / 256);
  383. _writeCommand(0x4e | target);
  384. _writeData((x + w - 1) / 8);
  385. _writeCommand(0x4f | target);
  386. _writeData(y % 256);
  387. _writeData(y / 256);
  388. break;
  389. case 0x03: // x increment, y increment
  390. _writeCommand(0x44 | target);
  391. _writeData(x / 8);
  392. _writeData((x + w - 1) / 8);
  393. _writeCommand(0x45 | target);
  394. _writeData(y % 256);
  395. _writeData(y / 256);
  396. _writeData((y + h - 1) % 256);
  397. _writeData((y + h - 1) / 256);
  398. _writeCommand(0x4e | target);
  399. _writeData(x / 8);
  400. _writeCommand(0x4f | target);
  401. _writeData(y % 256);
  402. _writeData(y / 256);
  403. break;
  404. }
  405. delay(2);
  406. }
  407. void GxEPD2_579_GDEY0579T93::_PowerOn()
  408. {
  409. if (!_power_is_on)
  410. {
  411. _writeCommand(0x22);
  412. _writeData(0xe0);
  413. _writeCommand(0x20);
  414. _waitWhileBusy("_PowerOn", power_on_time);
  415. }
  416. _power_is_on = true;
  417. }
  418. void GxEPD2_579_GDEY0579T93::_PowerOff()
  419. {
  420. if (_power_is_on)
  421. {
  422. _writeCommand(0x22);
  423. _writeData(0x83);
  424. _writeCommand(0x20);
  425. _waitWhileBusy("_PowerOff", power_off_time);
  426. }
  427. _power_is_on = false;
  428. _using_partial_mode = false;
  429. }
  430. void GxEPD2_579_GDEY0579T93::_InitDisplay()
  431. {
  432. if (_hibernating) _reset();
  433. _writeCommand(0x12); //SWRESET
  434. delay(10); // 10ms according to specs, 4ms measured
  435. _writeCommand(0x18); // Temperature Sensor Control
  436. _writeData(0x80); // Internal temperature sensor
  437. _writeCommand(0x22); // Display Update Control 2
  438. //_writeData(0xB1); // Enable clock signal, Load temperature value, Load LUT (3-color mode), Disable clock signal
  439. _writeData(0xB1); // Enable clock signal, Load temperature value, Load LUT (black/white mode), Disable clock signal
  440. _writeCommand(0x20); // Master Activation
  441. delay(10); // 4ms measured
  442. _writeCommand(0x1A); // Write to temperature register
  443. _writeData(0x64);
  444. _writeData(0x00);
  445. _writeCommand(0x22); // Display Update Control 2
  446. _writeData(0x91); // Load temperature value, Load LUT (black/white mode), Disable clock signal
  447. _writeCommand(0x20); // Master Activation
  448. delay(10); // 4ms measured
  449. _init_display_done = true;
  450. }
  451. void GxEPD2_579_GDEY0579T93::_Update_Full()
  452. {
  453. _writeCommand(0x21); // Display Update Control
  454. _writeData(0x40); // bypass RED as 0
  455. _writeData(0x10); // cascade application
  456. if (useFastFullUpdate)
  457. {
  458. _writeCommand(0x1A); // Write to temperature register
  459. _writeData(0x64);
  460. _writeData(0x00);
  461. _writeCommand(0x22); // Display Update Control 2
  462. _writeData(0xd7);
  463. }
  464. else
  465. {
  466. _writeCommand(0x22); // Display Update Control 2
  467. _writeData(0xF7);
  468. }
  469. _writeCommand(0x20); // Master Activation
  470. _waitWhileBusy("_Update_Full", full_refresh_time);
  471. _power_is_on = false;
  472. }
  473. void GxEPD2_579_GDEY0579T93::_Update_Part()
  474. {
  475. _writeCommand(0x3C); // Border Waveform Control
  476. _writeData(0x80); // VCOM
  477. _writeCommand(0x21); // Display Update Control
  478. _writeData(0x00); // RED normal
  479. _writeData(0x10); // cascade application
  480. _writeCommand(0x22); // Display Update Control 2
  481. _writeData(0xFF);
  482. _writeCommand(0x20);
  483. _waitWhileBusy("_Update_Part", partial_refresh_time);
  484. _power_is_on = false;
  485. }