GxEPD2_it60.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  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. // GxEPD2_it60 class is based on Demo Example from Waveshare for Raspberry PI https://github.com/waveshare/IT8951/archive/master.zip
  5. // Controller: IT8951 : https://www.waveshare.com/w/upload/1/18/IT8951_D_V0.2.4.3_20170728.pdf
  6. //
  7. // The GxEPD2_it60 driver class supports the Waveshare e-Paper IT8951 Driver HAT connected with SPI for the ED060SCT 6" e-paper panel (parallel IF)
  8. // https://www.waveshare.com/product/mini-pc/raspberry-pi/hats/6inch-e-paper-hat.htm
  9. // This Driver HAT requires 5V power supply but works with 3.3V data lines; requires both MOSI and MISO SPI lines.
  10. //
  11. // Author: Jean-Marc Zingg
  12. //
  13. // Version: see library.properties
  14. //
  15. // Library: https://github.com/ZinggJM/GxEPD2
  16. #include "GxEPD2_it60.h"
  17. #define VCOM 1500 //e.g. -1.53 = 1530 = 0x5FA
  18. //Built in I80 Command Code
  19. #define IT8951_TCON_SYS_RUN 0x0001
  20. #define IT8951_TCON_STANDBY 0x0002
  21. #define IT8951_TCON_SLEEP 0x0003
  22. #define IT8951_TCON_REG_RD 0x0010
  23. #define IT8951_TCON_REG_WR 0x0011
  24. #define IT8951_TCON_LD_IMG 0x0020
  25. #define IT8951_TCON_LD_IMG_AREA 0x0021
  26. #define IT8951_TCON_LD_IMG_END 0x0022
  27. //I80 User defined command code
  28. #define USDEF_I80_CMD_DPY_AREA 0x0034
  29. #define USDEF_I80_CMD_GET_DEV_INFO 0x0302
  30. #define USDEF_I80_CMD_DPY_BUF_AREA 0x0037
  31. #define USDEF_I80_CMD_VCOM 0x0039
  32. //Rotate mode
  33. #define IT8951_ROTATE_0 0
  34. #define IT8951_ROTATE_90 1
  35. #define IT8951_ROTATE_180 2
  36. #define IT8951_ROTATE_270 3
  37. //Pixel mode , BPP - Bit per Pixel
  38. #define IT8951_2BPP 0
  39. #define IT8951_3BPP 1
  40. #define IT8951_4BPP 2
  41. #define IT8951_8BPP 3
  42. //Endian Type
  43. #define IT8951_LDIMG_L_ENDIAN 0
  44. #define IT8951_LDIMG_B_ENDIAN 1
  45. #define SYS_REG_BASE 0x0000
  46. #define I80CPCR (SYS_REG_BASE + 0x04)
  47. #define MCSR_BASE_ADDR 0x0200
  48. #define LISAR (MCSR_BASE_ADDR + 0x0008)
  49. GxEPD2_it60::GxEPD2_it60(int8_t cs, int8_t dc, int8_t rst, int8_t busy) :
  50. GxEPD2_EPD(cs, dc, rst, busy, LOW, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate),
  51. _spi_settings(24000000, MSBFIRST, SPI_MODE0),
  52. _spi_settings_for_read(1000000, MSBFIRST, SPI_MODE0)
  53. {
  54. }
  55. void GxEPD2_it60::init(uint32_t serial_diag_bitrate)
  56. {
  57. init(serial_diag_bitrate, true, false);
  58. }
  59. void GxEPD2_it60::init(uint32_t serial_diag_bitrate, bool initial, bool pulldown_rst_mode)
  60. {
  61. GxEPD2_EPD::init(serial_diag_bitrate, initial, pulldown_rst_mode);
  62. // we need a long reset pulse
  63. if (_rst >= 0)
  64. {
  65. digitalWrite(_rst, LOW);
  66. delay(200);
  67. digitalWrite(_rst, HIGH);
  68. delay(200);
  69. _waitWhileBusy("init reset_to_ready", reset_to_ready_time);
  70. }
  71. _writeCommand16(USDEF_I80_CMD_GET_DEV_INFO);
  72. _waitWhileBusy("GetIT8951SystemInfo", power_on_time);
  73. _readData16((uint16_t*)&IT8951DevInfo, sizeof(IT8951DevInfo) / 2);
  74. if (_diag_enabled)
  75. {
  76. //Show Device information of IT8951
  77. printf("Panel(W,H) = (%d,%d)\r\n",
  78. IT8951DevInfo.usPanelW, IT8951DevInfo.usPanelH );
  79. printf("Image Buffer Address = %X\r\n",
  80. IT8951DevInfo.usImgBufAddrL | (IT8951DevInfo.usImgBufAddrH << 16));
  81. //Show Firmware and LUT Version
  82. printf("FW Version = %s\r\n", (uint8_t*)IT8951DevInfo.usFWVersion);
  83. printf("LUT Version = %s\r\n", (uint8_t*)IT8951DevInfo.usLUTVersion);
  84. }
  85. //Set to Enable I80 Packed mode
  86. _IT8951WriteReg(I80CPCR, 0x0001);
  87. if (VCOM != _IT8951GetVCOM())
  88. {
  89. _IT8951SetVCOM(VCOM);
  90. printf("VCOM = -%.02fV\n", (float)_IT8951GetVCOM() / 1000);
  91. }
  92. printf("VCOM = -%.02fV\n", (float)_IT8951GetVCOM() / 1000);
  93. }
  94. void GxEPD2_it60::clearScreen(uint8_t value)
  95. {
  96. if (_initial) _Init_Full();
  97. else _Init_Part();
  98. _initial = false;
  99. _setPartialRamArea(0, 0, WIDTH, HEIGHT);
  100. SPI.beginTransaction(_spi_settings);
  101. if (_cs >= 0) digitalWrite(_cs, LOW);
  102. _transfer16(0x0000); // preamble for write data
  103. _waitWhileBusy2("clearScreen preamble", default_wait_time);
  104. for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT); i++)
  105. {
  106. SPI.transfer(value);
  107. #if defined(ESP8266) || defined(ESP32)
  108. if (0 == i % 10000) yield();
  109. #endif
  110. }
  111. if (_cs >= 0) digitalWrite(_cs, HIGH);
  112. SPI.endTransaction();
  113. _writeCommand16(IT8951_TCON_LD_IMG_END);
  114. _waitWhileBusy2("clearScreen load end", default_wait_time);
  115. _refresh(0, 0, WIDTH, HEIGHT, false);
  116. }
  117. void GxEPD2_it60::writeScreenBuffer(uint8_t value)
  118. {
  119. if (_initial) clearScreen(value);
  120. else _writeScreenBuffer(value);
  121. }
  122. void GxEPD2_it60::_writeScreenBuffer(uint8_t value)
  123. {
  124. if (!_using_partial_mode) _Init_Part();
  125. _setPartialRamArea(0, 0, WIDTH, HEIGHT);
  126. SPI.beginTransaction(_spi_settings);
  127. if (_cs >= 0) digitalWrite(_cs, LOW);
  128. _transfer16(0x0000); // preamble for write data
  129. _waitWhileBusy2("clearScreen preamble", default_wait_time);
  130. for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT); i++)
  131. {
  132. SPI.transfer(value);
  133. #if defined(ESP8266) || defined(ESP32)
  134. if (0 == i % 10000) yield();
  135. #endif
  136. }
  137. if (_cs >= 0) digitalWrite(_cs, HIGH);
  138. SPI.endTransaction();
  139. _writeCommand16(IT8951_TCON_LD_IMG_END);
  140. _waitWhileBusy2("_writeScreenBuffer load end", default_wait_time);
  141. }
  142. void GxEPD2_it60::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  143. {
  144. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  145. int16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded
  146. x -= x % 8; // byte boundary
  147. w = wb * 8; // byte boundary
  148. int16_t x1 = x < 0 ? 0 : x; // limit
  149. int16_t y1 = y < 0 ? 0 : y; // limit
  150. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  151. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  152. int16_t dx = x1 - x;
  153. int16_t dy = y1 - y;
  154. w1 -= dx;
  155. h1 -= dy;
  156. if ((w1 <= 0) || (h1 <= 0)) return;
  157. if (!_using_partial_mode) _Init_Part();
  158. _setPartialRamArea(x1, y1, w1, h1);
  159. SPI.beginTransaction(_spi_settings);
  160. if (_cs >= 0) digitalWrite(_cs, LOW);
  161. _transfer16(0x0000); // preamble for write data
  162. _waitWhileBusy2("writeImage preamble", default_wait_time);
  163. for (int16_t i = 0; i < h1; i++)
  164. {
  165. for (int16_t j = 0; j < w1 / 8; j++)
  166. {
  167. uint8_t data;
  168. // use wb, h of bitmap for index!
  169. uint32_t idx = mirror_y ? uint32_t(j + dx / 8) + uint32_t((h - 1 - (i + dy))) * uint32_t(wb) : uint32_t(j + dx / 8) + uint32_t(i + dy) * uint32_t(wb);
  170. if (pgm)
  171. {
  172. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  173. data = pgm_read_byte(&bitmap[idx]);
  174. #else
  175. data = bitmap[idx];
  176. #endif
  177. }
  178. else
  179. {
  180. data = bitmap[idx];
  181. }
  182. if (invert) data = ~data;
  183. _send8pixel(~data);
  184. }
  185. #if defined(ESP8266) || defined(ESP32)
  186. yield();
  187. #endif
  188. }
  189. if (_cs >= 0) digitalWrite(_cs, HIGH);
  190. SPI.endTransaction();
  191. _writeCommand16(IT8951_TCON_LD_IMG_END);
  192. _waitWhileBusy2("writeImage load end", default_wait_time);
  193. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  194. }
  195. void GxEPD2_it60::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)
  196. {
  197. if (black)
  198. {
  199. writeImage(black, x, y, w, h, invert, mirror_y, pgm);
  200. }
  201. }
  202. void GxEPD2_it60::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)
  203. {
  204. if (data1)
  205. {
  206. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  207. int16_t x1 = x < 0 ? 0 : x; // limit
  208. int16_t y1 = y < 0 ? 0 : y; // limit
  209. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  210. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  211. int16_t dx = x1 - x;
  212. int16_t dy = y1 - y;
  213. w1 -= dx;
  214. h1 -= dy;
  215. if ((w1 <= 0) || (h1 <= 0)) return;
  216. if (!_using_partial_mode) _Init_Part();
  217. _setPartialRamArea(x1, y1, w1, h1);
  218. SPI.beginTransaction(_spi_settings);
  219. if (_cs >= 0) digitalWrite(_cs, LOW);
  220. _transfer16(0x0000); // preamble for write data
  221. _waitWhileBusy2("writeNative preamble", default_wait_time);
  222. for (int16_t i = 0; i < h1; i++)
  223. {
  224. for (int16_t j = 0; j < w1; j++)
  225. {
  226. uint8_t data;
  227. // use w, h of bitmap for index!
  228. uint32_t idx = mirror_y ? uint32_t(j + dx) + uint32_t((h - 1 - (i + dy))) * uint32_t(w) : uint32_t(j + dx) + uint32_t(i + dy) * uint32_t(w);
  229. if (pgm)
  230. {
  231. #if defined(__AVR) || defined(ESP8266) || defined(ESP32)
  232. data = pgm_read_byte(&data1[idx]);
  233. #else
  234. data = data1[idx];
  235. #endif
  236. }
  237. else
  238. {
  239. data = data1[idx];
  240. }
  241. if (invert) data = ~data;
  242. SPI.transfer(data);
  243. }
  244. #if defined(ESP8266) || defined(ESP32)
  245. yield();
  246. #endif
  247. }
  248. if (_cs >= 0) digitalWrite(_cs, HIGH);
  249. SPI.endTransaction();
  250. _writeCommand16(IT8951_TCON_LD_IMG_END);
  251. _waitWhileBusy2("writeNative load end", default_wait_time);
  252. delay(1); // yield() to avoid WDT on ESP8266 and ESP32
  253. }
  254. }
  255. void GxEPD2_it60::drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
  256. {
  257. writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
  258. _refresh(x, y, w, h, true);
  259. }
  260. void GxEPD2_it60::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)
  261. {
  262. writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
  263. _refresh(x, y, w, h, true);
  264. }
  265. void GxEPD2_it60::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)
  266. {
  267. writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
  268. _refresh(x, y, w, h, false);
  269. }
  270. void GxEPD2_it60::refresh(bool partial_update_mode)
  271. {
  272. _refresh(0, 0, WIDTH, HEIGHT, partial_update_mode);
  273. }
  274. void GxEPD2_it60::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
  275. {
  276. _refresh(x, y, w, h, true);
  277. }
  278. void GxEPD2_it60::_refresh(int16_t x, int16_t y, int16_t w, int16_t h, bool partial_update_mode)
  279. {
  280. //x -= x % 8; // byte boundary
  281. //w -= x % 8; // byte boundary
  282. int16_t x1 = x < 0 ? 0 : x; // limit
  283. int16_t y1 = y < 0 ? 0 : y; // limit
  284. int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit
  285. int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit
  286. w1 -= x1 - x;
  287. h1 -= y1 - y;
  288. //Send I80 Display Command (User defined command of IT8951)
  289. _writeCommand16(USDEF_I80_CMD_DPY_AREA); //0x0034
  290. _waitWhileBusy2("refresh cmd", refresh_cmd_time);
  291. //Write arguments
  292. _writeData16(x1);
  293. _waitWhileBusy2("refresh x", refresh_par_time);
  294. _writeData16(y1);
  295. _waitWhileBusy2("refresh y", refresh_par_time);
  296. _writeData16(w1);
  297. _waitWhileBusy2("refresh w", refresh_par_time);
  298. _writeData16(h1);
  299. _waitWhileBusy2("refresh h", refresh_par_time);
  300. _writeData16(partial_update_mode ? 1 : 2); // mode
  301. _waitWhileBusy("refresh", full_refresh_time);
  302. }
  303. void GxEPD2_it60::powerOff(void)
  304. {
  305. _PowerOff();
  306. }
  307. void GxEPD2_it60::hibernate()
  308. {
  309. if (_power_is_on) _PowerOff();
  310. if (_rst >= 0)
  311. {
  312. // this does not work, does not reduce power, uses more than in stand by mode
  313. //delay(1000);
  314. //_IT8951Sleep();
  315. //delay(1000);
  316. //_hibernating = true;
  317. }
  318. }
  319. void GxEPD2_it60::_send8pixel(uint8_t data)
  320. {
  321. for (uint8_t j = 0; j < 8; j++)
  322. {
  323. SPI.transfer(data & 0x80 ? 0x00 : 0xFF);
  324. data <<= 1;
  325. }
  326. }
  327. void GxEPD2_it60::_setPartialRamArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
  328. {
  329. //_IT8951WriteReg(LISAR + 2 , IT8951DevInfo.usImgBufAddrH);
  330. //_IT8951WriteReg(LISAR , IT8951DevInfo.usImgBufAddrL);
  331. uint16_t usArg[5];
  332. //usArg[0] = (IT8951_LDIMG_L_ENDIAN << 8 ) | (IT8951_8BPP << 4) | (IT8951_ROTATE_0);
  333. usArg[0] = (IT8951_LDIMG_B_ENDIAN << 8 ) | (IT8951_8BPP << 4) | (IT8951_ROTATE_0);
  334. usArg[1] = x;
  335. usArg[2] = y;
  336. usArg[3] = w;
  337. usArg[4] = h;
  338. _writeCommandData16(IT8951_TCON_LD_IMG_AREA , usArg , 5);
  339. }
  340. void GxEPD2_it60::_PowerOn()
  341. {
  342. if (!_power_is_on)
  343. {
  344. _IT8951SystemRun();
  345. _waitWhileBusy("_PowerOn", power_on_time);
  346. }
  347. _power_is_on = true;
  348. }
  349. void GxEPD2_it60::_PowerOff()
  350. {
  351. _IT8951StandBy();
  352. _waitWhileBusy("_PowerOff", power_off_time);
  353. _power_is_on = false;
  354. _using_partial_mode = false;
  355. }
  356. void GxEPD2_it60::_InitDisplay()
  357. {
  358. // we need a long reset pulse
  359. if (_hibernating && (_rst >= 0))
  360. {
  361. digitalWrite(_rst, LOW);
  362. delay(200);
  363. digitalWrite(_rst, HIGH);
  364. delay(200);
  365. }
  366. }
  367. void GxEPD2_it60::_Init_Full()
  368. {
  369. _InitDisplay();
  370. _PowerOn();
  371. _using_partial_mode = false;
  372. }
  373. void GxEPD2_it60::_Init_Part()
  374. {
  375. _InitDisplay();
  376. _PowerOn();
  377. _using_partial_mode = true;
  378. }
  379. void GxEPD2_it60::_waitWhileBusy2(const char* comment, uint16_t busy_time)
  380. {
  381. if (_busy >= 0)
  382. {
  383. unsigned long start = micros();
  384. while (1)
  385. {
  386. if (digitalRead(_busy) != _busy_level) break;
  387. delay(1);
  388. if (micros() - start > _busy_timeout)
  389. {
  390. Serial.println("Busy Timeout!");
  391. break;
  392. }
  393. }
  394. if (comment)
  395. {
  396. #if !defined(DISABLE_DIAGNOSTIC_OUTPUT)
  397. if (_diag_enabled)
  398. {
  399. unsigned long elapsed = micros() - start;
  400. if (elapsed > diag_min_time * 1000)
  401. {
  402. Serial.print(comment);
  403. Serial.print(" : ");
  404. Serial.println(elapsed);
  405. }
  406. }
  407. #endif
  408. }
  409. (void) start;
  410. }
  411. else delay(busy_time);
  412. }
  413. uint16_t GxEPD2_it60::_transfer16(uint16_t value)
  414. {
  415. uint16_t rv = SPI.transfer(value >> 8) << 8;
  416. return (rv | SPI.transfer(value));
  417. }
  418. void GxEPD2_it60::_writeCommand16(uint16_t c)
  419. {
  420. String s = String("_writeCommand16(0x") + String(c, HEX) + String(")");
  421. _waitWhileBusy2(s.c_str(), default_wait_time);
  422. SPI.beginTransaction(_spi_settings);
  423. if (_cs >= 0) digitalWrite(_cs, LOW);
  424. _transfer16(0x6000); // preamble for write command
  425. _waitWhileBusy2("_writeCommand16 preamble", default_wait_time);
  426. _transfer16(c);
  427. if (_cs >= 0) digitalWrite(_cs, HIGH);
  428. SPI.endTransaction();
  429. //_waitWhileBusy(s.c_str(), default_wait_time);
  430. }
  431. void GxEPD2_it60::_writeData16(uint16_t d)
  432. {
  433. _waitWhileBusy2("_writeData16", default_wait_time);
  434. SPI.beginTransaction(_spi_settings);
  435. if (_cs >= 0) digitalWrite(_cs, LOW);
  436. _transfer16(0x0000); // preamble for write data
  437. _waitWhileBusy2("_writeData16 preamble", default_wait_time);
  438. _transfer16(d);
  439. if (_cs >= 0) digitalWrite(_cs, HIGH);
  440. SPI.endTransaction();
  441. }
  442. void GxEPD2_it60::_writeData16(const uint16_t* d, uint32_t n)
  443. {
  444. _waitWhileBusy2("_writeData16", default_wait_time);
  445. SPI.beginTransaction(_spi_settings);
  446. if (_cs >= 0) digitalWrite(_cs, LOW);
  447. _transfer16(0x0000); // preamble for write data
  448. _waitWhileBusy2("_writeData16 preamble", default_wait_time);
  449. for (uint32_t i = 0; i < n; i++)
  450. {
  451. _transfer16(*d++);
  452. }
  453. if (_cs >= 0) digitalWrite(_cs, HIGH);
  454. SPI.endTransaction();
  455. }
  456. uint16_t GxEPD2_it60::_readData16()
  457. {
  458. _waitWhileBusy2("_readData16", default_wait_time);
  459. SPI.beginTransaction(_spi_settings);
  460. if (_cs >= 0) digitalWrite(_cs, LOW);
  461. _transfer16(0x1000); // preamble for read data
  462. _waitWhileBusy2("_readData16 preamble", default_wait_time);
  463. _transfer16(0); // dummy
  464. _waitWhileBusy2("_readData16 dummy", default_wait_time);
  465. uint16_t rv = _transfer16(0);
  466. if (_cs >= 0) digitalWrite(_cs, HIGH);
  467. SPI.endTransaction();
  468. return rv;
  469. }
  470. void GxEPD2_it60::_readData16(uint16_t* d, uint32_t n)
  471. {
  472. _waitWhileBusy2("_readData16", default_wait_time);
  473. SPI.beginTransaction(_spi_settings);
  474. if (_cs >= 0) digitalWrite(_cs, LOW);
  475. _transfer16(0x1000); // preamble for read data
  476. _waitWhileBusy2("_readData16 preamble", default_wait_time);
  477. _transfer16(0); // dummy
  478. _waitWhileBusy2("_readData16 dummy", default_wait_time);
  479. for (uint32_t i = 0; i < n; i++)
  480. {
  481. *d++ = _transfer16(0);
  482. //_waitWhileBusy("_readData16 data", default_wait_time);
  483. }
  484. if (_cs >= 0) digitalWrite(_cs, HIGH);
  485. SPI.endTransaction();
  486. }
  487. void GxEPD2_it60::_writeCommandData16(uint16_t c, const uint16_t* d, uint16_t n)
  488. {
  489. _writeCommand16(c);
  490. for (uint16_t i = 0; i < n; i++)
  491. {
  492. _writeData16(d[i]);
  493. }
  494. }
  495. void GxEPD2_it60::_IT8951SystemRun()
  496. {
  497. _writeCommand16(IT8951_TCON_SYS_RUN);
  498. }
  499. void GxEPD2_it60::_IT8951StandBy()
  500. {
  501. _writeCommand16(IT8951_TCON_STANDBY);
  502. }
  503. void GxEPD2_it60::_IT8951Sleep()
  504. {
  505. _writeCommand16(IT8951_TCON_SLEEP);
  506. }
  507. uint16_t GxEPD2_it60::_IT8951ReadReg(uint16_t usRegAddr)
  508. {
  509. uint16_t usData;
  510. //Send Cmd and Register Address
  511. _writeCommand16(IT8951_TCON_REG_RD);
  512. _writeData16(usRegAddr);
  513. //Read data from Host Data bus
  514. usData = _readData16();
  515. return usData;
  516. }
  517. void GxEPD2_it60::_IT8951WriteReg(uint16_t usRegAddr, uint16_t usValue)
  518. {
  519. //Send Cmd , Register Address and Write Value
  520. _writeCommand16(IT8951_TCON_REG_WR);
  521. _writeData16(usRegAddr);
  522. _writeData16(usValue);
  523. }
  524. uint16_t GxEPD2_it60::_IT8951GetVCOM(void)
  525. {
  526. uint16_t vcom;
  527. _writeCommand16(USDEF_I80_CMD_VCOM);
  528. _waitWhileBusy2("_IT8951GetVCOM", default_wait_time);
  529. _writeData16(0);
  530. //Read data from Host Data bus
  531. vcom = _readData16();
  532. return vcom;
  533. }
  534. void GxEPD2_it60::_IT8951SetVCOM(uint16_t vcom)
  535. {
  536. _writeCommand16(USDEF_I80_CMD_VCOM);
  537. _waitWhileBusy2("_IT8951SetVCOM", default_wait_time);
  538. _writeData16(1);
  539. //Read data from Host Data bus
  540. _writeData16(vcom);
  541. _waitWhileBusy2("_IT8951SetVCOM", set_vcom_time);
  542. }