GxEPD2_1085_GDEM1085T51.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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/companyfile/32/
  5. // Panel: GDEM1085T51 : https://www.good-display.com/product/503.html
  6. // Controller : JD79686AB :
  7. //
  8. // Author: Jean-Marc Zingg
  9. //
  10. // Version: see library.properties
  11. //
  12. // Library: https://github.com/ZinggJM/GxEPD2
  13. #include "GxEPD2_1085_GDEM1085T51.h"
  14. GxEPD2_1085_GDEM1085T51::GxEPD2_1085_GDEM1085T51(int16_t cs, int16_t dc, int16_t rst, int16_t busy, int16_t cs2) :
  15. GxEPD2_EPD(cs, dc, rst, busy, LOW, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
  16. {
  17. _cs2 = cs2;
  18. }
  19. void GxEPD2_1085_GDEM1085T51::init(uint32_t serial_diag_bitrate)
  20. {
  21. if (_cs2 >= 0)
  22. {
  23. digitalWrite(_cs2, HIGH); // preset (less glitch for any analyzer)
  24. pinMode(_cs2, OUTPUT);
  25. digitalWrite(_cs2, HIGH); // set (needed e.g. for RP2040)
  26. }
  27. GxEPD2_EPD::init(serial_diag_bitrate);
  28. }
  29. void GxEPD2_1085_GDEM1085T51::init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration, bool pulldown_rst_mode)
  30. {
  31. if (_cs2 >= 0)
  32. {
  33. digitalWrite(_cs2, HIGH); // preset (less glitch for any analyzer)
  34. pinMode(_cs2, OUTPUT);
  35. digitalWrite(_cs2, HIGH); // set (needed e.g. for RP2040)
  36. }
  37. GxEPD2_EPD::init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
  38. }
  39. void GxEPD2_1085_GDEM1085T51::clearScreen(uint8_t value)
  40. {
  41. // full refresh needed for all cases (previous != screen)
  42. _writeScreenBuffer(0x10, value); // set previous
  43. _writeScreenBuffer(0x13, value); // set current
  44. refresh(false); // full refresh
  45. _initial_write = false;
  46. }
  47. void GxEPD2_1085_GDEM1085T51::writeScreenBuffer(uint8_t value)
  48. {
  49. if (_initial_write) return clearScreen(value);
  50. _writeScreenBuffer(0x13, value); // set current
  51. }
  52. void GxEPD2_1085_GDEM1085T51::writeScreenBufferAgain(uint8_t value)
  53. {
  54. _writeScreenBuffer(0x10, value); // set previous
  55. _writeScreenBuffer(0x13, value); // set current
  56. }
  57. void GxEPD2_1085_GDEM1085T51::_writeScreenBuffer(uint8_t command, uint8_t value)
  58. {
  59. if (!_init_display_done) _InitDisplay();
  60. _writeCommandToMaster(command);
  61. _startTransferToMaster();
  62. for (uint32_t i = 0; i < uint32_t(WIDTH / 2) * uint32_t(HEIGHT) / 8; i++)
  63. {
  64. _transfer(value);
  65. }
  66. _endTransferToMaster();
  67. _writeCommandToSlave(command);
  68. _startTransferToSlave();
  69. for (uint32_t i = 0; i < uint32_t(WIDTH / 2) * uint32_t(HEIGHT) / 8; i++)
  70. {
  71. _transfer(value);
  72. }
  73. _endTransferToSlave();
  74. }
  75. void GxEPD2_1085_GDEM1085T51::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  76. {
  77. //Serial.print("writeImage("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", "); Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  78. _writeImage(0x13, bitmap, x, y, w, h, invert, mirror_y, pgm); // set current
  79. }
  80. //void GxEPD2_1085_GDEM1085T51::writeImageForFullRefresh(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  81. //{
  82. // //Serial.print("writeImageForFullRefresh("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", "); Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  83. // _writeImage(0x10, bitmap, x, y, w, h, invert, mirror_y, pgm); // set previous
  84. // _writeImage(0x13, bitmap, x, y, w, h, invert, mirror_y, pgm); // set current
  85. //}
  86. void GxEPD2_1085_GDEM1085T51::writeImageAgain(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("writeImageAgain("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", "); Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  89. _writeImage(0x10, bitmap, x, y, w, h, invert, mirror_y, pgm); // set previous
  90. _writeImage(0x13, bitmap, x, y, w, h, invert, mirror_y, pgm); // set current
  91. }
  92. void GxEPD2_1085_GDEM1085T51::writeImageToPrevious(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  93. {
  94. _writeImage(0x10, bitmap, x, y, w, h, invert, mirror_y, pgm);
  95. }
  96. void GxEPD2_1085_GDEM1085T51::_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)
  97. {
  98. //Serial.print("_writeImage("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", "); Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  99. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  100. int16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded
  101. x -= x % 8; // byte boundary
  102. w = wb * 8; // byte boundary
  103. int16_t x1 = x < 0 ? 0 : x; // limit
  104. int16_t y1 = y < 0 ? 0 : y; // limit
  105. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  106. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  107. int16_t dx = x1 - x;
  108. int16_t dy = y1 - y;
  109. w1 -= dx;
  110. h1 -= dy;
  111. if ((w1 <= 0) || (h1 <= 0)) return;
  112. if (!_init_display_done) _InitDisplay();
  113. if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
  114. if (x1 < WIDTH / 2)
  115. {
  116. int16_t wm = x1 + w1 <= WIDTH / 2 ? w1 : WIDTH / 2 - x1;
  117. _writeCommandToMaster(0x91); // partial in
  118. _setPartialRamAreaMaster(x1, y1, wm, h1);
  119. _writeCommandToMaster(command);
  120. _startTransferToMaster();
  121. for (int16_t i = 0; i < h1; i++)
  122. {
  123. for (int16_t j = 0; j < wm / 8; j++)
  124. {
  125. uint8_t data;
  126. // use wb, h of bitmap for index!
  127. int32_t idx = mirror_y ? j + dx / 8 + int32_t((h - 1 - (i + dy))) * wb : j + dx / 8 + int32_t(i + dy) * wb;
  128. if (pgm)
  129. {
  130. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  131. data = pgm_read_byte(&bitmap[idx]);
  132. #else
  133. data = bitmap[idx];
  134. #endif
  135. }
  136. else
  137. {
  138. data = bitmap[idx];
  139. }
  140. if (invert) data = ~data;
  141. _transfer(data);
  142. }
  143. }
  144. _endTransferToMaster();
  145. _writeCommandToMaster(0x92); // partial out
  146. }
  147. if (x1 + w1 > WIDTH / 2)
  148. {
  149. int16_t xs = x1 <= WIDTH / 2 ? WIDTH / 2 : x1;
  150. int16_t ws = x1 <= WIDTH / 2 ? x1 + w1 - WIDTH / 2 : w1;
  151. _writeCommandToSlave(0x91); // partial in
  152. _setPartialRamAreaSlave(xs - WIDTH / 2, y1, ws, h1);
  153. _writeCommandToSlave(command);
  154. _startTransferToSlave();
  155. for (int16_t i = 0; i < h1; i++)
  156. {
  157. for (int16_t j = 0; j < ws / 8; j++)
  158. {
  159. uint8_t data;
  160. // use wb, h of bitmap for index!
  161. int32_t idx = mirror_y ? (xs - x1) / 8 + j + int32_t((h - 1 - (i + dy))) * wb : (xs - x1) / 8 + j + int32_t(i + dy) * wb;
  162. if (pgm)
  163. {
  164. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  165. data = pgm_read_byte(&bitmap[idx]);
  166. #else
  167. data = bitmap[idx];
  168. #endif
  169. }
  170. else
  171. {
  172. data = bitmap[idx];
  173. }
  174. if (invert) data = ~data;
  175. _transfer(data);
  176. }
  177. }
  178. _endTransferToSlave();
  179. _writeCommandToSlave(0x92); // partial out
  180. }
  181. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  182. }
  183. void GxEPD2_1085_GDEM1085T51::writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  184. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  185. {
  186. _writeImagePart(0x13, bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  187. }
  188. void GxEPD2_1085_GDEM1085T51::writeImagePartAgain(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  189. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  190. {
  191. _writeImagePart(0x10, bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  192. }
  193. void GxEPD2_1085_GDEM1085T51::writeImagePartToPrevious(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. _writeImagePart(0x10, bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  197. }
  198. void GxEPD2_1085_GDEM1085T51::_writeImagePart(uint8_t command, const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  199. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  200. {
  201. //Serial.print("_writeImagePart("); Serial.print(x_part); Serial.print(", "); Serial.print(y_part); Serial.print(", "); Serial.print(w_bitmap); Serial.print(", "); Serial.print(h_bitmap); Serial.print(", ");
  202. //Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", "); Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  203. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  204. if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return;
  205. if ((x_part < 0) || (x_part >= w_bitmap)) return;
  206. if ((y_part < 0) || (y_part >= h_bitmap)) return;
  207. int16_t wb_bitmap = (w_bitmap + 7) / 8; // width bytes, bitmaps are padded
  208. x_part -= x_part % 8; // byte boundary
  209. w = w_bitmap - x_part < w ? w_bitmap - x_part : w; // limit
  210. h = h_bitmap - y_part < h ? h_bitmap - y_part : h; // limit
  211. x -= x % 8; // byte boundary
  212. w = 8 * ((w + 7) / 8); // byte boundary, bitmaps are padded
  213. int16_t x1 = x < 0 ? 0 : x; // limit
  214. int16_t y1 = y < 0 ? 0 : y; // limit
  215. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  216. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  217. int16_t dx = x1 - x;
  218. int16_t dy = y1 - y;
  219. w1 -= dx;
  220. h1 -= dy;
  221. if ((w1 <= 0) || (h1 <= 0)) return;
  222. if (!_init_display_done) _InitDisplay();
  223. if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
  224. if (x1 < WIDTH / 2)
  225. {
  226. int16_t wm = x1 + w1 <= WIDTH / 2 ? w1 : WIDTH / 2 - x1;
  227. _writeCommandToMaster(0x91); // partial in
  228. _setPartialRamAreaMaster(x1, y1, wm, h1);
  229. _writeCommandToMaster(command);
  230. _startTransferToMaster();
  231. for (int16_t i = 0; i < h1; i++)
  232. {
  233. for (int16_t j = 0; j < wm / 8; j++)
  234. {
  235. uint8_t data;
  236. // use wb_bitmap, h_bitmap of bitmap for index!
  237. int32_t idx = mirror_y ? x_part / 8 + j + dx / 8 + int32_t((h_bitmap - 1 - (y_part + i + dy))) * wb_bitmap : x_part / 8 + j + dx / 8 + int32_t(y_part + i + dy) * wb_bitmap;
  238. if (pgm)
  239. {
  240. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  241. data = pgm_read_byte(&bitmap[idx]);
  242. #else
  243. data = bitmap[idx];
  244. #endif
  245. }
  246. else
  247. {
  248. data = bitmap[idx];
  249. }
  250. if (invert) data = ~data;
  251. _transfer(data);
  252. }
  253. }
  254. _endTransferToMaster();
  255. _writeCommandToMaster(0x92); // partial out
  256. }
  257. if (x1 + w1 > WIDTH / 2)
  258. {
  259. int16_t xs = x1 <= WIDTH / 2 ? WIDTH / 2 : x1;
  260. int16_t ws = x1 <= WIDTH / 2 ? x1 + w1 - WIDTH / 2 : w1;
  261. _writeCommandToSlave(0x91); // partial in
  262. _setPartialRamAreaSlave(xs - WIDTH / 2, y1, ws, h1);
  263. _writeCommandToSlave(command);
  264. _startTransferToSlave();
  265. for (int16_t i = 0; i < h1; i++)
  266. {
  267. for (int16_t j = 0; j < ws / 8; j++)
  268. {
  269. uint8_t data;
  270. // use wb_bitmap, h_bitmap of bitmap for index!
  271. int32_t idx = mirror_y ? x_part / 8 + (xs - x1) / 8 + j + dx / 8 + int32_t((h_bitmap - 1 - (y_part + i + dy))) * wb_bitmap : x_part / 8 + (xs - x1) / 8 + j + dx / 8 + int32_t(y_part + i + dy) * wb_bitmap;
  272. if (pgm)
  273. {
  274. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  275. data = pgm_read_byte(&bitmap[idx]);
  276. #else
  277. data = bitmap[idx];
  278. #endif
  279. }
  280. else
  281. {
  282. data = bitmap[idx];
  283. }
  284. if (invert) data = ~data;
  285. _transfer(data);
  286. }
  287. }
  288. _endTransferToSlave();
  289. _writeCommandToSlave(0x92); // partial out
  290. }
  291. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  292. }
  293. void GxEPD2_1085_GDEM1085T51::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)
  294. {
  295. if (black)
  296. {
  297. writeImage(black, x, y, w, h, invert, mirror_y, pgm);
  298. }
  299. }
  300. void GxEPD2_1085_GDEM1085T51::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,
  301. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  302. {
  303. if (black)
  304. {
  305. writeImagePart(black, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  306. }
  307. }
  308. void GxEPD2_1085_GDEM1085T51::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)
  309. {
  310. if (data1)
  311. {
  312. writeImage(data1, x, y, w, h, invert, mirror_y, pgm);
  313. }
  314. }
  315. void GxEPD2_1085_GDEM1085T51::drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  316. {
  317. writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
  318. refresh(x, y, w, h);
  319. writeImageAgain(bitmap, x, y, w, h, invert, mirror_y, pgm);
  320. }
  321. void GxEPD2_1085_GDEM1085T51::drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  322. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  323. {
  324. writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  325. refresh(x, y, w, h);
  326. writeImagePartAgain(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  327. }
  328. void GxEPD2_1085_GDEM1085T51::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)
  329. {
  330. if (black)
  331. {
  332. drawImage(black, x, y, w, h, invert, mirror_y, pgm);
  333. }
  334. }
  335. void GxEPD2_1085_GDEM1085T51::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,
  336. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  337. {
  338. if (black)
  339. {
  340. drawImagePart(black, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  341. }
  342. }
  343. void GxEPD2_1085_GDEM1085T51::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)
  344. {
  345. if (data1)
  346. {
  347. drawImage(data1, x, y, w, h, invert, mirror_y, pgm);
  348. }
  349. }
  350. void GxEPD2_1085_GDEM1085T51::refresh(bool partial_update_mode)
  351. {
  352. if (partial_update_mode) refresh(0, 0, WIDTH, HEIGHT);
  353. else
  354. {
  355. if (_using_partial_mode) _Init_Full();
  356. _Update_Full();
  357. _initial_refresh = false; // initial full update done
  358. }
  359. }
  360. void GxEPD2_1085_GDEM1085T51::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
  361. {
  362. if (_initial_refresh) return refresh(false); // initial update needs be full update
  363. // intersection with screen
  364. int16_t w1 = x < 0 ? w + x : w; // reduce
  365. int16_t h1 = y < 0 ? h + y : h; // reduce
  366. int16_t x1 = x < 0 ? 0 : x; // limit
  367. int16_t y1 = y < 0 ? 0 : y; // limit
  368. w1 = x1 + w1 < int16_t(WIDTH) ? w1 : int16_t(WIDTH) - x1; // limit
  369. h1 = y1 + h1 < int16_t(HEIGHT) ? h1 : int16_t(HEIGHT) - y1; // limit
  370. if ((w1 <= 0) || (h1 <= 0)) return;
  371. // make x1, w1 multiple of 8
  372. w1 += x1 % 8;
  373. if (w1 % 8 > 0) w1 += 8 - w1 % 8;
  374. x1 -= x1 % 8;
  375. if (!_using_partial_mode) _Init_Part();
  376. #if 0
  377. //_writeCommandToBoth(0x91); // partial in
  378. if (x1 < WIDTH / 2)
  379. {
  380. int16_t wm = x1 + w1 <= WIDTH / 2 ? w1 : WIDTH / 2 - x1;
  381. _writeCommandToMaster(0x91); // partial in
  382. _setPartialRamAreaMaster(x1, y1, wm, h1);
  383. }
  384. if (x1 + w1 > WIDTH / 2)
  385. {
  386. int16_t xs = x1 <= WIDTH / 2 ? WIDTH / 2 : x1;
  387. int16_t ws = x1 <= WIDTH / 2 ? x1 + w1 - WIDTH / 2 : w1;
  388. _writeCommandToSlave(0x91); // partial in
  389. _setPartialRamAreaSlave(xs - WIDTH / 2, y1, ws, h1);
  390. }
  391. _Update_Part();
  392. _writeCommandToBoth(0x92); // partial out
  393. #else
  394. _setPartialRamAreaMaster(0, 0, WIDTH / 2, HEIGHT);
  395. _setPartialRamAreaSlave(0, 0, WIDTH / 2, HEIGHT);
  396. _Update_Part();
  397. #endif
  398. }
  399. void GxEPD2_1085_GDEM1085T51::powerOff(void)
  400. {
  401. _PowerOff();
  402. }
  403. void GxEPD2_1085_GDEM1085T51::hibernate()
  404. {
  405. _PowerOff();
  406. if (_rst >= 0)
  407. {
  408. _writeCommand(0x07); // deep sleep
  409. _writeData(0xA5); // check code
  410. _hibernating = true;
  411. _init_display_done = false;
  412. }
  413. }
  414. void GxEPD2_1085_GDEM1085T51::_writeCommandToMaster(uint8_t c)
  415. {
  416. _writeCommand(c);
  417. }
  418. void GxEPD2_1085_GDEM1085T51::_writeCommandToSlave(uint8_t c)
  419. {
  420. _pSPIx->beginTransaction(_spi_settings);
  421. if (_dc >= 0) digitalWrite(_dc, LOW);
  422. if (_cs2 >= 0) digitalWrite(_cs2, LOW);
  423. _pSPIx->transfer(c);
  424. if (_cs2 >= 0) digitalWrite(_cs2, HIGH);
  425. if (_dc >= 0) digitalWrite(_dc, HIGH);
  426. _pSPIx->endTransaction();
  427. }
  428. void GxEPD2_1085_GDEM1085T51::_writeCommandToBoth(uint8_t c)
  429. {
  430. _pSPIx->beginTransaction(_spi_settings);
  431. if (_dc >= 0) digitalWrite(_dc, LOW);
  432. if (_cs >= 0) digitalWrite(_cs, LOW);
  433. if (_cs2 >= 0) digitalWrite(_cs2, LOW);
  434. _pSPIx->transfer(c);
  435. if (_cs2 >= 0) digitalWrite(_cs2, HIGH);
  436. if (_cs >= 0) digitalWrite(_cs, HIGH);
  437. if (_dc >= 0) digitalWrite(_dc, HIGH);
  438. _pSPIx->endTransaction();
  439. }
  440. void GxEPD2_1085_GDEM1085T51::_writeDataToMaster(uint8_t d)
  441. {
  442. _writeData(d);
  443. }
  444. void GxEPD2_1085_GDEM1085T51::_writeDataToSlave(uint8_t d)
  445. {
  446. _pSPIx->beginTransaction(_spi_settings);
  447. if (_cs >= 0) digitalWrite(_cs2, LOW);
  448. _pSPIx->transfer(d);
  449. if (_cs >= 0) digitalWrite(_cs2, HIGH);
  450. _pSPIx->endTransaction();
  451. }
  452. void GxEPD2_1085_GDEM1085T51::_writeDataToBoth(uint8_t d)
  453. {
  454. _pSPIx->beginTransaction(_spi_settings);
  455. if (_cs >= 0) digitalWrite(_cs, LOW);
  456. if (_cs >= 0) digitalWrite(_cs2, LOW);
  457. _pSPIx->transfer(d);
  458. if (_cs2 >= 0) digitalWrite(_cs2, HIGH);
  459. if (_cs >= 0) digitalWrite(_cs, HIGH);
  460. _pSPIx->endTransaction();
  461. }
  462. void GxEPD2_1085_GDEM1085T51::_startTransferToMaster()
  463. {
  464. _startTransfer();
  465. }
  466. void GxEPD2_1085_GDEM1085T51::_startTransferToSlave()
  467. {
  468. _pSPIx->beginTransaction(_spi_settings);
  469. if (_cs >= 0) digitalWrite(_cs2, LOW);
  470. }
  471. void GxEPD2_1085_GDEM1085T51::_endTransferToMaster()
  472. {
  473. _endTransfer();
  474. }
  475. void GxEPD2_1085_GDEM1085T51::_endTransferToSlave()
  476. {
  477. if (_cs >= 0) digitalWrite(_cs2, HIGH);
  478. _pSPIx->endTransaction();
  479. }
  480. void GxEPD2_1085_GDEM1085T51::_setPartialRamAreaMaster(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
  481. {
  482. //Serial.print("_setPartialRamAreaMaster("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", "); Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  483. uint16_t xe = (x + w - 1) | 0x0007; // byte boundary inclusive (last byte)
  484. uint16_t ye = y + h - 1;
  485. x &= 0xFFF8; // byte boundary
  486. _writeCommandToMaster(0x90); // partial window
  487. _writeDataToMaster(x / 256);
  488. _writeDataToMaster(x % 256);
  489. _writeDataToMaster(xe / 256);
  490. _writeDataToMaster(xe % 256);
  491. _writeDataToMaster(y / 256);
  492. _writeDataToMaster(y % 256);
  493. _writeDataToMaster(ye / 256);
  494. _writeDataToMaster(ye % 256);
  495. _writeDataToMaster(0x01); // don't see any difference
  496. //_writeDataToMaster(0x00); // don't see any difference
  497. }
  498. void GxEPD2_1085_GDEM1085T51::_setPartialRamAreaSlave(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
  499. {
  500. //Serial.print("_setPartialRamAreaSlave("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", "); Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  501. uint16_t xe = (x + w - 1) | 0x0007; // byte boundary inclusive (last byte)
  502. uint16_t ye = y + h - 1;
  503. x &= 0xFFF8; // byte boundary
  504. _writeCommandToSlave(0x90); // partial window
  505. _writeDataToSlave(x / 256);
  506. _writeDataToSlave(x % 256);
  507. _writeDataToSlave(xe / 256);
  508. _writeDataToSlave(xe % 256);
  509. _writeDataToSlave(y / 256);
  510. _writeDataToSlave(y % 256);
  511. _writeDataToSlave(ye / 256);
  512. _writeDataToSlave(ye % 256);
  513. _writeDataToSlave(0x01); // don't see any difference
  514. //_writeData(0x00); // don't see any difference
  515. }
  516. void GxEPD2_1085_GDEM1085T51::_PowerOn()
  517. {
  518. if (!_power_is_on)
  519. {
  520. _writeCommandToBoth(0x04);
  521. _waitWhileBusy("_PowerOn", power_on_time);
  522. }
  523. _power_is_on = true;
  524. }
  525. void GxEPD2_1085_GDEM1085T51::_PowerOff()
  526. {
  527. if (_power_is_on)
  528. {
  529. _writeCommandToBoth(0x02); // power off
  530. _waitWhileBusy("_PowerOff", power_off_time);
  531. _power_is_on = false;
  532. }
  533. }
  534. void GxEPD2_1085_GDEM1085T51::_soft_reset()
  535. {
  536. if (_hibernating) _reset();
  537. _writeCommandToBoth(0x00); // Panel setting
  538. _writeDataToBoth(0x9E); // RST_N
  539. delay(2);
  540. _writeCommandToBoth(0x00); // Panel setting
  541. _writeDataToBoth(0x9F); // otp
  542. _waitWhileBusy("_soft_reset", power_on_time);
  543. _power_is_on = false;
  544. }
  545. void GxEPD2_1085_GDEM1085T51::_InitDisplay()
  546. {
  547. if (_hibernating) _reset();
  548. // from A32-GDEM1085T51-P-20240314
  549. _writeCommandToBoth(0x4D);
  550. _writeDataToBoth(0x55);
  551. _writeCommandToBoth(0xA6);
  552. _writeDataToBoth(0x38);
  553. _writeCommandToBoth(0xB4);
  554. _writeDataToBoth(0x5D);
  555. _writeCommandToBoth(0xB6);
  556. _writeDataToBoth(0x80);
  557. _writeCommandToBoth(0xB7);
  558. _writeDataToBoth(0x00);
  559. _writeCommandToBoth(0xF7);
  560. _writeDataToBoth(0x02);
  561. _writeCommandToSlave(0xAE);
  562. _writeDataToSlave(0xA0);
  563. _writeCommandToBoth(0xE0); // Cascade Setting (CCSET)
  564. _writeDataToBoth(0x01); // CCEN (clock for slave)
  565. //
  566. _writeCommandToBoth(0x00); // Panel setting
  567. _writeDataToBoth(0x9F); // otp
  568. _writeDataToBoth(0x0D); // TS_AUTO, TIEG, no NORG, VC_LUTZ
  569. _writeCommandToBoth(0x06); // Booster Setting
  570. _writeDataToBoth(0x57); // 20ms, str 3, period 8
  571. _writeDataToBoth(0x24); // 10ms, str 5, period 5
  572. _writeDataToBoth(0x28); // 10ms, str 6, period 1
  573. _writeDataToBoth(0x32); // ??
  574. _writeDataToBoth(0x08); // ??
  575. _writeDataToBoth(0x48); // ??
  576. _writeCommandToBoth(0x50); // VCOM and DATA interval setting
  577. _writeDataToBoth(0x97); // LUTBW, 10 hsync
  578. _writeCommandToBoth(0x60); // TCON setting
  579. _writeDataToBoth(0x31); // ??
  580. _writeCommandToBoth(0x61); // Resolution setting
  581. _writeDataToBoth(0X02); // 640
  582. _writeDataToBoth(0XA8);
  583. _writeDataToBoth(0X01); // 480
  584. _writeDataToBoth(0XE0);
  585. _writeCommandToBoth(0x62); // Source & gate start setting
  586. _writeDataToBoth(0x00);
  587. _writeDataToBoth(0x00);
  588. _writeDataToBoth(0x00);
  589. _writeDataToBoth(0x00);
  590. //_writeCommandToBoth(0xE8);
  591. //_writeDataToBoth(0x01);
  592. _init_display_done = true;
  593. }
  594. void GxEPD2_1085_GDEM1085T51::_Init_Full()
  595. {
  596. //Serial.println("_Init_Full");
  597. if (_using_partial_mode) _soft_reset();
  598. _InitDisplay();
  599. _writeCommandToBoth(0xE8);
  600. _writeDataToBoth(0x01);
  601. _PowerOn();
  602. _using_partial_mode = false;
  603. }
  604. void GxEPD2_1085_GDEM1085T51::_Init_Part()
  605. {
  606. //Serial.println("_Init_Part");
  607. if (!_using_partial_mode) _soft_reset();
  608. _InitDisplay();
  609. _writeCommandToBoth(0xE0); // Cascade Setting (CCSET)
  610. _writeDataToBoth(0x03); // TSFIX, CCEN (clock for slave)
  611. _writeCommandToBoth(0xE5); // Force Temperature
  612. _writeDataToBoth(0x64); // 100, differential update
  613. _PowerOn();
  614. _using_partial_mode = true;
  615. }
  616. void GxEPD2_1085_GDEM1085T51::_Update_Full()
  617. {
  618. _PowerOn();
  619. _writeCommandToBoth(0xE0); // Cascade Setting (CCSET)
  620. _writeDataToBoth(0x01); // no TSFIX, CCEN (clock for slave)
  621. _writeCommandToBoth(0xE8);
  622. _writeDataToBoth(0x01);
  623. _writeCommandToBoth(0x12); //display refresh
  624. _waitWhileBusy("_Update_Full", full_refresh_time);
  625. }
  626. void GxEPD2_1085_GDEM1085T51::_Update_Part()
  627. {
  628. _PowerOn();
  629. _writeCommandToBoth(0x12); //display refresh
  630. _waitWhileBusy("_Update_Part", partial_refresh_time);
  631. }