GxEPD2_730c_GDEP073E01.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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: https://www.good-display.com/comp/xcompanyFile/downloadNew.do?appId=24&fid=2006&id=1435
  5. // Panel: GDEP073E01 : https://www.good-display.com/product/533.html
  6. // Controller: unknown
  7. //
  8. // Author: Jean-Marc Zingg
  9. //
  10. // Version: see library.properties
  11. //
  12. // Library: https://github.com/ZinggJM/GxEPD2
  13. #include "GxEPD2_730c_GDEP073E01.h"
  14. GxEPD2_730c_GDEP073E01::GxEPD2_730c_GDEP073E01(int16_t cs, int16_t dc, int16_t rst, int16_t busy) :
  15. GxEPD2_EPD(cs, dc, rst, busy, LOW, 20000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
  16. {
  17. _paged = false;
  18. }
  19. void GxEPD2_730c_GDEP073E01::clearScreen(uint8_t value)
  20. {
  21. clearScreen(value, 0xFF);
  22. }
  23. void GxEPD2_730c_GDEP073E01::clearScreen(uint8_t black_value, uint8_t color_value)
  24. {
  25. writeScreenBuffer(black_value, color_value);
  26. refresh();
  27. }
  28. void GxEPD2_730c_GDEP073E01::writeScreenBuffer(uint8_t value)
  29. {
  30. writeScreenBuffer(value, 0xFF);
  31. }
  32. void GxEPD2_730c_GDEP073E01::writeScreenBuffer(uint8_t black_value, uint8_t color_value)
  33. {
  34. if (!_init_display_done) _InitDisplay();
  35. _writeCommand(0x10);
  36. _startTransfer();
  37. for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 2; i++)
  38. {
  39. //_transfer(0x11);
  40. _transfer(0xFF == black_value ? 0x11 : black_value);
  41. }
  42. _endTransfer();
  43. }
  44. void GxEPD2_730c_GDEP073E01::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  45. {
  46. //Serial.print("writeImage("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  47. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  48. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  49. if (!_init_display_done) _InitDisplay();
  50. if (_paged && (x == 0) && (w == int16_t(WIDTH)) && (h < int16_t(HEIGHT)))
  51. {
  52. //Serial.println("paged");
  53. _startTransfer();
  54. for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(h) / 8; i++)
  55. {
  56. uint8_t data = bitmap[i];
  57. for (int16_t k = 0; k < 4; k++)
  58. {
  59. uint8_t data2 = (data & 0x80 ? 0x10 : 0x00) | (data & 0x40 ? 0x01 : 0x00);
  60. data <<= 2;
  61. _transfer(data2);
  62. }
  63. }
  64. _endTransfer();
  65. if (y + h == HEIGHT) // last page
  66. {
  67. //Serial.println("paged ended");
  68. _paged = false;
  69. }
  70. }
  71. else
  72. {
  73. _paged = false;
  74. int16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded
  75. x -= x % 8; // byte boundary
  76. w = wb * 8; // byte boundary
  77. if ((w <= 0) || (h <= 0)) return;
  78. _writeCommand(0x10);
  79. _startTransfer();
  80. for (int16_t i = 0; i < int16_t(HEIGHT); i++)
  81. {
  82. for (int16_t j = 0; j < int16_t(WIDTH); j += 8)
  83. {
  84. uint8_t data = 0xFF;
  85. if ((j >= x) && (j <= x + w) && (i >= y) && (i < y + h))
  86. {
  87. uint32_t idx = mirror_y ? (j - x) / 8 + uint32_t((h - 1 - (i - y))) * wb : (j - x) / 8 + uint32_t(i - y) * wb;
  88. if (pgm)
  89. {
  90. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  91. data = pgm_read_byte(&bitmap[idx]);
  92. #else
  93. data = bitmap[idx];
  94. #endif
  95. }
  96. else
  97. {
  98. data = bitmap[idx];
  99. }
  100. if (invert) data = ~data;
  101. }
  102. for (int16_t k = 0; k < 4; k++)
  103. {
  104. uint8_t data2 = (data & 0x80 ? 0x10 : 0x00) | (data & 0x40 ? 0x01 : 0x00);
  105. data <<= 2;
  106. _transfer(data2);
  107. }
  108. }
  109. }
  110. _endTransfer();
  111. }
  112. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  113. }
  114. void GxEPD2_730c_GDEP073E01::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)
  115. {
  116. if (!black && !color) return;
  117. if (!color) return writeImage(black, x, y, w, h, invert, mirror_y, pgm);
  118. //Serial.print("writeImage("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  119. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  120. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  121. if (!_init_display_done) _InitDisplay();
  122. if (_paged && (x == 0) && (w == int16_t(WIDTH)) && (h < int16_t(HEIGHT)))
  123. {
  124. //Serial.println("paged");
  125. _startTransfer();
  126. for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(h) / 8; i++)
  127. {
  128. uint8_t black_data = black[i];
  129. uint8_t color_data = color[i];
  130. for (int16_t k = 0; k < 4; k++)
  131. {
  132. uint8_t out_data = 0x00;
  133. for (int16_t l = 0; l < 2; l++)
  134. {
  135. out_data <<= 4;
  136. if (!(color_data & 0x80)) out_data |= 0x04;
  137. else out_data |= black_data & 0x80 ? 0x01 : 0x00;
  138. black_data <<= 1;
  139. color_data <<= 1;
  140. }
  141. _transfer(out_data);
  142. }
  143. }
  144. _endTransfer();
  145. if (y + h == HEIGHT) // last page
  146. {
  147. //Serial.println("paged ended");
  148. _paged = false;
  149. }
  150. }
  151. else
  152. {
  153. _paged = false;
  154. int16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded
  155. x -= x % 8; // byte boundary
  156. w = wb * 8; // byte boundary
  157. if ((w <= 0) || (h <= 0)) return;
  158. _writeCommand(0x10);
  159. _startTransfer();
  160. for (int16_t i = 0; i < int16_t(HEIGHT); i++)
  161. {
  162. for (int16_t j = 0; j < int16_t(WIDTH); j += 8)
  163. {
  164. uint8_t black_data = 0xFF, color_data = 0xFF;
  165. if ((j >= x) && (j < x + w) && (i >= y) && (i < y + h))
  166. {
  167. uint32_t idx = mirror_y ? (j - x) / 8 + uint32_t((h - 1 - (i - y))) * wb : (j - x) / 8 + uint32_t(i - y) * wb;
  168. if (pgm)
  169. {
  170. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  171. black_data = pgm_read_byte(&black[idx]);
  172. color_data = pgm_read_byte(&color[idx]);
  173. #else
  174. black_data = black[idx];
  175. color_data = color[idx];
  176. #endif
  177. }
  178. else
  179. {
  180. black_data = black[idx];
  181. color_data = color[idx];
  182. }
  183. if (invert)
  184. {
  185. black_data = ~black_data;
  186. color_data = ~color_data;
  187. }
  188. }
  189. for (int16_t k = 0; k < 4; k++)
  190. {
  191. uint8_t out_data = 0x00;
  192. for (int16_t l = 0; l < 2; l++)
  193. {
  194. out_data <<= 4;
  195. if (!(color_data & 0x80)) out_data |= 0x04;
  196. else out_data |= black_data & 0x80 ? 0x01 : 0x00;
  197. black_data <<= 1;
  198. color_data <<= 1;
  199. }
  200. _transfer(out_data);
  201. }
  202. }
  203. }
  204. _endTransfer();
  205. }
  206. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  207. }
  208. void GxEPD2_730c_GDEP073E01::writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  209. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  210. {
  211. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  212. if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return;
  213. if ((x_part < 0) || (x_part >= w_bitmap)) return;
  214. if ((y_part < 0) || (y_part >= h_bitmap)) return;
  215. int16_t wb_bitmap = (w_bitmap + 7) / 8; // width bytes, bitmaps are padded
  216. x_part -= x_part % 8; // byte boundary
  217. w = w_bitmap - x_part < w ? w_bitmap - x_part : w; // limit
  218. h = h_bitmap - y_part < h ? h_bitmap - y_part : h; // limit
  219. x -= x % 8; // byte boundary
  220. w = 8 * ((w + 7) / 8); // byte boundary, bitmaps are padded
  221. int16_t x1 = x < 0 ? 0 : x; // limit
  222. int16_t y1 = y < 0 ? 0 : y; // limit
  223. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  224. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  225. int16_t dx = x1 - x;
  226. int16_t dy = y1 - y;
  227. w1 -= dx;
  228. h1 -= dy;
  229. if ((w1 <= 0) || (h1 <= 0)) return;
  230. if (!_init_display_done) _InitDisplay();
  231. _writeCommand(0x10);
  232. _startTransfer();
  233. for (int16_t i = 0; i < int16_t(HEIGHT); i++)
  234. {
  235. for (int16_t j = 0; j < int16_t(WIDTH); j += 8)
  236. {
  237. uint8_t data = 0xFF;
  238. if ((j >= x1) && (j < x1 + w) && (i >= y1) && (i < y1 + h))
  239. {
  240. // use wb_bitmap, h_bitmap of bitmap for index!
  241. uint32_t idx = mirror_y ? (x_part + j - x1) / 8 + uint32_t((h_bitmap - 1 - (y_part + i - y1))) * wb_bitmap : (x_part + j - x1) / 8 + uint32_t(y_part + i - y1) * wb_bitmap;
  242. if (pgm)
  243. {
  244. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  245. data = pgm_read_byte(&bitmap[idx]);
  246. #else
  247. data = bitmap[idx];
  248. #endif
  249. }
  250. else
  251. {
  252. data = bitmap[idx];
  253. }
  254. if (invert) data = ~data;
  255. }
  256. for (int16_t k = 0; k < 4; k++)
  257. {
  258. uint8_t data2 = (data & 0x80 ? 0x10 : 0x00) | (data & 0x40 ? 0x01 : 0x00);
  259. data <<= 2;
  260. _transfer(data2);
  261. }
  262. }
  263. }
  264. _endTransfer();
  265. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  266. }
  267. void GxEPD2_730c_GDEP073E01::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,
  268. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  269. {
  270. //Serial.print("writeImagePart("); Serial.print(x_part); Serial.print(", "); Serial.print(y_part); Serial.print(", ");
  271. //Serial.print(w_bitmap); Serial.print(", "); Serial.print(h_bitmap); Serial.print(", ");
  272. //Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  273. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  274. if (!black && !color) return;
  275. if (!color) return writeImagePart(black, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  276. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  277. if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return;
  278. if ((x_part < 0) || (x_part >= w_bitmap)) return;
  279. if ((y_part < 0) || (y_part >= h_bitmap)) return;
  280. int16_t wb_bitmap = (w_bitmap + 7) / 8; // width bytes, bitmaps are padded
  281. x_part -= x_part % 8; // byte boundary
  282. w = w_bitmap - x_part < w ? w_bitmap - x_part : w; // limit
  283. h = h_bitmap - y_part < h ? h_bitmap - y_part : h; // limit
  284. x -= x % 8; // byte boundary
  285. w = 8 * ((w + 7) / 8); // byte boundary, bitmaps are padded
  286. int16_t x1 = x < 0 ? 0 : x; // limit
  287. int16_t y1 = y < 0 ? 0 : y; // limit
  288. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  289. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  290. int16_t dx = x1 - x;
  291. int16_t dy = y1 - y;
  292. w1 -= dx;
  293. h1 -= dy;
  294. if ((w1 <= 0) || (h1 <= 0)) return;
  295. if (!_init_display_done) _InitDisplay();
  296. _writeCommand(0x10);
  297. _startTransfer();
  298. for (int16_t i = 0; i < int16_t(HEIGHT); i++)
  299. {
  300. for (int16_t j = 0; j < int16_t(WIDTH); j += 8)
  301. {
  302. uint8_t black_data = 0xFF, color_data = 0xFF;
  303. if ((j >= x1) && (j < x1 + w) && (i >= y1) && (i < y1 + h))
  304. {
  305. // use wb_bitmap, h_bitmap of bitmap for index!
  306. uint32_t idx = mirror_y ? (x_part + j - x1) / 8 + uint32_t((h_bitmap - 1 - (y_part + i - y1))) * wb_bitmap : (x_part + j - x1) / 8 + uint32_t(y_part + i - y1) * wb_bitmap;
  307. if (pgm)
  308. {
  309. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  310. black_data = pgm_read_byte(&black[idx]);
  311. color_data = pgm_read_byte(&color[idx]);
  312. #else
  313. black_data = black[idx];
  314. color_data = color[idx];
  315. #endif
  316. }
  317. else
  318. {
  319. black_data = black[idx];
  320. color_data = color[idx];
  321. }
  322. if (invert)
  323. {
  324. black_data = ~black_data;
  325. color_data = ~color_data;
  326. }
  327. }
  328. for (int16_t k = 0; k < 4; k++)
  329. {
  330. uint8_t out_data = 0x00;
  331. for (int16_t l = 0; l < 2; l++)
  332. {
  333. out_data <<= 4;
  334. if (!(color_data & 0x80)) out_data |= 0x04;
  335. else out_data |= black_data & 0x80 ? 0x01 : 0x00;
  336. black_data <<= 1;
  337. color_data <<= 1;
  338. }
  339. _transfer(out_data);
  340. }
  341. }
  342. }
  343. _endTransfer();
  344. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  345. }
  346. void GxEPD2_730c_GDEP073E01::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)
  347. {
  348. if (data1)
  349. {
  350. //Serial.print("writeNative("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  351. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  352. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  353. if (!_init_display_done) _InitDisplay();
  354. if (_paged && (x == 0) && (w == int16_t(WIDTH)) && (h < int16_t(HEIGHT)))
  355. {
  356. //Serial.println("paged");
  357. _startTransfer();
  358. for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(h) / 2; i++)
  359. {
  360. uint8_t data = data1[i];
  361. if (!invert) data = _convert_to_native(data);
  362. _transfer(data);
  363. }
  364. _endTransfer();
  365. if (y + h == HEIGHT) // last page
  366. {
  367. //Serial.println("paged ended");
  368. _paged = false;
  369. }
  370. }
  371. else
  372. {
  373. _paged = false;
  374. int16_t wb = (w + 1) / 2; // width bytes, bitmaps are padded
  375. x -= x % 2; // byte boundary
  376. w = wb * 2; // byte boundary
  377. if ((w <= 0) || (h <= 0)) return;
  378. _writeCommand(0x10);
  379. _startTransfer();
  380. for (int16_t i = 0; i < int16_t(HEIGHT); i++)
  381. {
  382. for (int16_t j = 0; j < int16_t(WIDTH); j += 2)
  383. {
  384. uint8_t data = 0x11;
  385. if (data1)
  386. {
  387. if ((j >= x) && (j < x + w) && (i >= y) && (i < y + h))
  388. {
  389. uint32_t idx = mirror_y ? (j - x) / 2 + uint32_t((h - 1 - (i - y))) * wb : (j - x) / 2 + uint32_t(i - y) * wb;
  390. if (pgm)
  391. {
  392. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  393. data = pgm_read_byte(&data1[idx]);
  394. #else
  395. data = data1[idx];
  396. #endif
  397. }
  398. else
  399. {
  400. data = data1[idx];
  401. }
  402. if (!invert) data = _convert_to_native(data);
  403. }
  404. }
  405. _transfer(data);
  406. }
  407. }
  408. _endTransfer();
  409. }
  410. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  411. }
  412. }
  413. void GxEPD2_730c_GDEP073E01::writeNativePart(const uint8_t* data1, const uint8_t* data2, int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  414. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  415. {
  416. //Serial.print("writeNativePart("); Serial.print(x_part); Serial.print(", "); Serial.print(y_part); Serial.print(", ");
  417. //Serial.print(w_bitmap); Serial.print(", "); Serial.print(h_bitmap); Serial.print(", ");
  418. //Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  419. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  420. if (!data1) return;
  421. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  422. if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return;
  423. if ((x_part < 0) || (x_part >= w_bitmap)) return;
  424. if ((y_part < 0) || (y_part >= h_bitmap)) return;
  425. int16_t wb_bitmap = (w_bitmap + 1) / 2; // width bytes, bitmaps are padded
  426. x_part -= x_part % 2; // byte boundary
  427. w = w_bitmap - x_part < w ? w_bitmap - x_part : w; // limit
  428. h = h_bitmap - y_part < h ? h_bitmap - y_part : h; // limit
  429. x -= x % 2; // byte boundary
  430. w = 2 * ((w + 1) / 2); // byte boundary, bitmaps are padded
  431. int16_t x1 = x < 0 ? 0 : x; // limit
  432. int16_t y1 = y < 0 ? 0 : y; // limit
  433. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  434. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  435. int16_t dx = x1 - x;
  436. int16_t dy = y1 - y;
  437. w1 -= dx;
  438. h1 -= dy;
  439. if ((w1 <= 0) || (h1 <= 0)) return;
  440. if (!_init_display_done) _InitDisplay();
  441. _writeCommand(0x10);
  442. _startTransfer();
  443. for (int16_t i = 0; i < int16_t(HEIGHT); i++)
  444. {
  445. for (int16_t j = 0; j < int16_t(WIDTH); j += 2)
  446. {
  447. uint8_t data = 0x11;
  448. if ((j >= x1) && (j < x1 + w) && (i >= y1) && (i < y1 + h))
  449. {
  450. // use wb_bitmap, h_bitmap of bitmap for index!
  451. uint32_t idx = mirror_y ? (x_part + j - x1) / 2 + uint32_t((h_bitmap - 1 - (y_part + i - y1))) * wb_bitmap : (x_part + j - x1) / 2 + uint32_t(y_part + i - y1) * wb_bitmap;
  452. if (pgm)
  453. {
  454. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  455. data = pgm_read_byte(&data1[idx]);
  456. #else
  457. data = data1[idx];
  458. #endif
  459. }
  460. else
  461. {
  462. data = data1[idx];
  463. }
  464. if (!invert) data = _convert_to_native(data);
  465. }
  466. _transfer(data);
  467. }
  468. }
  469. _endTransfer();
  470. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  471. }
  472. void GxEPD2_730c_GDEP073E01::drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  473. {
  474. writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
  475. refresh(x, y, w, h);
  476. }
  477. void GxEPD2_730c_GDEP073E01::drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
  478. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  479. {
  480. writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  481. refresh(x, y, w, h);
  482. }
  483. void GxEPD2_730c_GDEP073E01::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)
  484. {
  485. writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
  486. refresh(x, y, w, h);
  487. }
  488. void GxEPD2_730c_GDEP073E01::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,
  489. int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  490. {
  491. writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
  492. refresh(x, y, w, h);
  493. }
  494. void GxEPD2_730c_GDEP073E01::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)
  495. {
  496. writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
  497. refresh(x, y, w, h);
  498. }
  499. void GxEPD2_730c_GDEP073E01::refresh(bool partial_update_mode)
  500. {
  501. _PowerOn();
  502. _writeCommand(0x12); // Display Refresh
  503. _writeData(0x00);
  504. delay(1);
  505. _waitWhileBusy("_refresh", full_refresh_time);
  506. }
  507. void GxEPD2_730c_GDEP073E01::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
  508. {
  509. _PowerOn();
  510. _writeCommand(0x12); // Display Refresh
  511. _writeData(0x00);
  512. delay(1);
  513. _waitWhileBusy("_refresh", full_refresh_time);
  514. }
  515. void GxEPD2_730c_GDEP073E01::powerOff()
  516. {
  517. _PowerOff();
  518. }
  519. void GxEPD2_730c_GDEP073E01::hibernate()
  520. {
  521. _PowerOff();
  522. if (_rst >= 0)
  523. {
  524. _writeCommand(0x07); // deep sleep
  525. _writeData(0xA5); // control code
  526. _hibernating = true;
  527. _init_display_done = false;
  528. }
  529. }
  530. void GxEPD2_730c_GDEP073E01::setPaged()
  531. {
  532. _paged = true;
  533. if (!_init_display_done) _InitDisplay();
  534. _writeCommand(0x10);
  535. }
  536. void GxEPD2_730c_GDEP073E01::_PowerOn()
  537. {
  538. if (!_power_is_on)
  539. {
  540. _writeCommand(0x04);
  541. _waitWhileBusy("_PowerOn", power_on_time);
  542. }
  543. _power_is_on = true;
  544. }
  545. void GxEPD2_730c_GDEP073E01::_PowerOff()
  546. {
  547. if (_power_is_on)
  548. {
  549. _writeCommand(0x02);
  550. _writeData(0x00);
  551. _waitWhileBusy("_PowerOff", power_off_time);
  552. }
  553. _power_is_on = false;
  554. }
  555. void GxEPD2_730c_GDEP073E01::_InitDisplay()
  556. {
  557. if ((_rst >= 0) && (_hibernating || _initial_write))
  558. {
  559. pinMode(_rst, OUTPUT); // just in case
  560. digitalWrite(_rst, HIGH);
  561. delay(50); // needs a little longer
  562. digitalWrite(_rst, LOW);
  563. delay(20);
  564. digitalWrite(_rst, HIGH);
  565. delay(10); // 4ms measured
  566. //_waitWhileBusy("_InitDisplay reset", power_on_time); // 4000us
  567. _initial_write = false; // used for initial reset done
  568. _hibernating = false;
  569. _power_is_on = false;
  570. }
  571. #define PSR 0x00
  572. #define PWRR 0x01
  573. #define POF 0x02
  574. #define POFS 0x03
  575. #define PON 0x04
  576. #define BTST1 0x05
  577. #define BTST2 0x06
  578. #define DSLP 0x07
  579. #define BTST3 0x08
  580. #define DTM 0x10
  581. #define DRF 0x12
  582. #define PLL 0x30
  583. #define CDI 0x50
  584. #define TCON 0x60
  585. #define TRES 0x61
  586. #define REV 0x70
  587. #define VDCS 0x82
  588. #define T_VDCS 0x84
  589. #define PWS 0xE3
  590. _writeCommand(0xAA); // CMDH
  591. _writeData(0x49);
  592. _writeData(0x55);
  593. _writeData(0x20);
  594. _writeData(0x08);
  595. _writeData(0x09);
  596. _writeData(0x18);
  597. _writeCommand(PWRR);//
  598. _writeData(0x3F);
  599. _writeCommand(PSR);
  600. _writeData(0x5F);
  601. _writeData(0x69);
  602. _writeCommand(POFS);
  603. _writeData(0x00);
  604. _writeData(0x54);
  605. _writeData(0x00);
  606. _writeData(0x44);
  607. _writeCommand(BTST1);
  608. _writeData(0x40);
  609. _writeData(0x1F);
  610. _writeData(0x1F);
  611. _writeData(0x2C);
  612. _writeCommand(BTST2);
  613. _writeData(0x6F);
  614. _writeData(0x1F);
  615. _writeData(0x17);
  616. _writeData(0x49);
  617. _writeCommand(BTST3);
  618. _writeData(0x6F);
  619. _writeData(0x1F);
  620. _writeData(0x1F);
  621. _writeData(0x22);
  622. _writeCommand(PLL);
  623. _writeData(0x08);
  624. _writeCommand(CDI);
  625. _writeData(0x3F);
  626. _writeCommand(TCON);
  627. _writeData(0x02);
  628. _writeData(0x00);
  629. _writeCommand(TRES);
  630. _writeData(0x03);
  631. _writeData(0x20);
  632. _writeData(0x01);
  633. _writeData(0xE0);
  634. _writeCommand(T_VDCS);
  635. _writeData(0x01);
  636. _writeCommand(PWS);
  637. _writeData(0x2F);
  638. _PowerOn();
  639. _init_display_done = true;
  640. }
  641. uint8_t GxEPD2_730c_GDEP073E01::_colorOfDemoBitmap(uint8_t from, int16_t mode)
  642. {
  643. switch (mode)
  644. {
  645. case 0:
  646. {
  647. switch (from)
  648. {
  649. case 0xFF: return (0x01); // white;
  650. case 0xFC: return (0x02); // yellow;
  651. case 0xF1: return (0x04); // orange;
  652. case 0xE5: return (0x03); // red;
  653. case 0x4B: return (0x05); // blue;
  654. case 0x39: return (0x06); // green;
  655. case 0x00: return (0x00); // black;
  656. default: return (0x01); // white;
  657. }
  658. }
  659. case 1:
  660. {
  661. switch (from)
  662. {
  663. case 0x00: // Black
  664. return (0x00); // 对应原始图像数据 0000
  665. case 0xff: // White
  666. return (0x01); // 对应原始图像数据 0001
  667. case 0xfc: // Yellow
  668. return (0x02); // 对应原始图像数据 0010
  669. case 0xE0: // Red
  670. return (0x03); // 对应原始图像数据 0011
  671. case 0x03: // Blue
  672. return (0x05); // 对应原始图像数据 0101
  673. case 0x1c: // Green
  674. return (0x06); // 对应原始图像数据 0110
  675. default:
  676. return (0x00); // 默认为黑色
  677. //default: return (0x01); // white;
  678. }
  679. }
  680. default: return (0x01); // white;
  681. }
  682. }
  683. void GxEPD2_730c_GDEP073E01::writeDemoBitmap(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, int16_t mode, bool mirror_y, bool pgm)
  684. {
  685. (void) mode;
  686. if (data1)
  687. {
  688. //Serial.print("writeNative("); Serial.print(x); Serial.print(", "); Serial.print(y); Serial.print(", ");
  689. //Serial.print(w); Serial.print(", "); Serial.print(h); Serial.println(")");
  690. if (!_init_display_done) _InitDisplay();
  691. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  692. {
  693. _paged = false;
  694. if ((w <= 0) || (h <= 0)) return;
  695. _writeCommand(0x10);
  696. _startTransfer();
  697. for (int16_t i = 0; i < int16_t(HEIGHT); i++)
  698. {
  699. for (int16_t j = 0; j < int16_t(WIDTH); j += 2)
  700. {
  701. uint8_t data = 0x11;
  702. if (data1)
  703. {
  704. if ((j >= x) && (j < x + w) && (i >= y) && (i < y + h))
  705. {
  706. uint32_t idx = mirror_y ? (j - x) + uint32_t((h - 1 - (i - y))) * w : (j - x) + uint32_t(i - y) * w;
  707. if (pgm)
  708. {
  709. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  710. data = _colorOfDemoBitmap(pgm_read_byte(&data1[idx++]), mode) << 4;
  711. data |= _colorOfDemoBitmap(pgm_read_byte(&data1[idx]), mode);
  712. #else
  713. data = _colorOfDemoBitmap(data1[idx++], mode) << 4;
  714. data |= _colorOfDemoBitmap(data1[idx], mode);
  715. #endif
  716. }
  717. else
  718. {
  719. data = _colorOfDemoBitmap(data1[idx++], mode) << 4;
  720. data |= _colorOfDemoBitmap(data1[idx], mode);
  721. }
  722. }
  723. }
  724. _transfer(data);
  725. }
  726. }
  727. _endTransfer();
  728. }
  729. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  730. }
  731. }
  732. void GxEPD2_730c_GDEP073E01::drawDemoBitmap(const uint8_t* data1, const uint8_t* data2, int16_t x, int16_t y, int16_t w, int16_t h, int16_t mode, bool mirror_y, bool pgm)
  733. {
  734. writeDemoBitmap(data1, data2, x, y, w, h, mode, mirror_y, pgm);
  735. refresh(x, y, w, h);
  736. }
  737. void GxEPD2_730c_GDEP073E01::drawNativeColors()
  738. {
  739. const uint16_t colors = 7;
  740. //const uint16_t colors = 8; // 7 is white
  741. //const uint16_t colors = 16; // repeated for 8..15
  742. const uint16_t h1 = HEIGHT / colors;
  743. _writeCommand(0x10);
  744. _startTransfer();
  745. for (uint16_t cn = 0; cn < colors; cn++)
  746. {
  747. for (uint16_t hnb = 0; hnb < h1 * WIDTH / 2; hnb++)
  748. {
  749. _transfer((cn << 4) | cn);
  750. }
  751. }
  752. _endTransfer();
  753. refresh();
  754. }
  755. uint8_t GxEPD2_730c_GDEP073E01::_convert_to_native(uint8_t data)
  756. {
  757. uint8_t result = 0x00;
  758. for (int i = 0; i < 2; i++)
  759. {
  760. switch (data & 0x07)
  761. {
  762. case 0x00 : result |= 0x00 << 4; break; // black
  763. case 0x01 : result |= 0x01 << 4; break; // white
  764. case 0x02 : result |= 0x06 << 4; break; // green
  765. case 0x03 : result |= 0x05 << 4; break; // blue
  766. case 0x04 : result |= 0x03 << 4; break; // red
  767. case 0x05 : result |= 0x02 << 4; break; // yellow
  768. case 0x06 : result |= 0x04 << 4; break; // orange
  769. case 0x07 : result |= 0x07 << 4; break; // white
  770. }
  771. if (i == 1) break;
  772. data >>= 4;
  773. result >>= 4;
  774. }
  775. return result;
  776. }