23#define IT8951_TCON_SYS_RUN      0x0001 
   24#define IT8951_TCON_STANDBY      0x0002 
   25#define IT8951_TCON_SLEEP        0x0003 
   26#define IT8951_TCON_REG_RD       0x0010 
   27#define IT8951_TCON_REG_WR       0x0011 
   28#define IT8951_TCON_LD_IMG       0x0020 
   29#define IT8951_TCON_LD_IMG_AREA  0x0021 
   30#define IT8951_TCON_LD_IMG_END   0x0022 
   33#define USDEF_I80_CMD_DPY_AREA     0x0034 
   34#define USDEF_I80_CMD_GET_DEV_INFO 0x0302 
   35#define USDEF_I80_CMD_DPY_BUF_AREA 0x0037 
   36#define USDEF_I80_CMD_VCOM       0x0039 
   39#define IT8951_ROTATE_0     0 
   40#define IT8951_ROTATE_90    1 
   41#define IT8951_ROTATE_180   2 
   42#define IT8951_ROTATE_270   3 
   51#define IT8951_LDIMG_L_ENDIAN   0 
   52#define IT8951_LDIMG_B_ENDIAN   1 
   54#define SYS_REG_BASE 0x0000 
   55#define I80CPCR (SYS_REG_BASE + 0x04) 
   56#define MCSR_BASE_ADDR 0x0200 
   57#define LISAR (MCSR_BASE_ADDR + 0x0008) 
   60  GxEPD2_EPD(cs, dc, rst, busy, LOW, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate),
 
   61  _spi_settings(24000000, MSBFIRST, SPI_MODE0),
 
   62  _spi_settings_for_read(1000000, MSBFIRST, SPI_MODE0)
 
 
   68  init(serial_diag_bitrate, 
true, 20, 
false);
 
 
   73  GxEPD2_EPD::init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
 
   78    digitalWrite(
_rst, LOW);
 
   80    digitalWrite(
_rst, HIGH);
 
   87  _readData16((uint16_t*)&IT8951DevInfo, 
sizeof(IT8951DevInfo) / 2);
 
   91    printf(
"Panel(W,H) = (%d,%d)\r\n",
 
   92           IT8951DevInfo.usPanelW, IT8951DevInfo.usPanelH );
 
   93    printf(
"Image Buffer Address = %lX\r\n",
 
   94           uint32_t(IT8951DevInfo.usImgBufAddrL) | (uint32_t(IT8951DevInfo.usImgBufAddrH) << 16));
 
   96    printf(
"FW Version = %s\r\n", (uint8_t*)IT8951DevInfo.usFWVersion);
 
   97    printf(
"LUT Version = %s\r\n", (uint8_t*)IT8951DevInfo.usLUTVersion);
 
  100  _IT8951WriteReg(
I80CPCR, 0x0001);
 
  101  if (
VCOM != _IT8951GetVCOM())
 
  103    _IT8951SetVCOM(
VCOM);
 
  104    printf(
"VCOM = -%.02fV\n", (
double)_IT8951GetVCOM() / 1000);
 
  106  printf(
"VCOM = -%.02fV\n", (
double)_IT8951GetVCOM() / 1000);
 
 
  116  SPI.beginTransaction(_spi_settings);
 
  117  if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  120  for (uint32_t i = 0; i < uint32_t(
WIDTH) * uint32_t(
HEIGHT); i++)
 
  123#if defined(ESP8266) || defined(ESP32) 
  124    if (0 == i % 10000) yield();
 
  127  if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  128  SPI.endTransaction();
 
 
  137  else _writeScreenBuffer(value);
 
 
  140void GxEPD2_it103_1872x1404::_writeScreenBuffer(uint8_t value)
 
  145  SPI.beginTransaction(_spi_settings);
 
  146  if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  149  for (uint32_t i = 0; i < uint32_t(
WIDTH) * uint32_t(
HEIGHT); i++)
 
  152#if defined(ESP8266) || defined(ESP32) 
  153    if (0 == i % 10000) yield();
 
  156  if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  157  SPI.endTransaction();
 
  166  int16_t wb = (w + 7) / 8; 
 
  169  int16_t x1 = x < 0 ? 0 : x; 
 
  170  int16_t y1 = y < 0 ? 0 : y; 
 
  171  int16_t w1 = x + w < int16_t(
WIDTH) ? w : int16_t(
WIDTH) - x; 
 
  172  int16_t h1 = y + h < int16_t(
HEIGHT) ? h : int16_t(
HEIGHT) - y; 
 
  177  if ((w1 <= 0) || (h1 <= 0)) 
return;
 
  179  _setPartialRamArea(x1, y1, w1, h1);
 
  180  SPI.beginTransaction(_spi_settings);
 
  181  if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  184  for (int16_t i = 0; i < h1; i++)
 
  186    for (int16_t j = 0; j < w1 / 8; j++)
 
  190      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);
 
  193#if defined(__AVR) || defined(ESP8266) || defined(ESP32) 
  194        data = pgm_read_byte(&bitmap[idx]);
 
  203      if (invert) data = ~data;
 
  206#if defined(ESP8266) || defined(ESP32) 
  210  if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  211  SPI.endTransaction();
 
 
  218                                 int16_t x, int16_t y, int16_t w, int16_t h, 
bool invert, 
bool mirror_y, 
bool pgm)
 
  222  if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) 
return;
 
  223  if ((x_part < 0) || (x_part >= w_bitmap)) 
return;
 
  224  if ((y_part < 0) || (y_part >= h_bitmap)) 
return;
 
  225  int16_t wb_bitmap = (w_bitmap + 7) / 8; 
 
  226  x_part -= x_part % 8; 
 
  227  w = w_bitmap - x_part < w ? w_bitmap - x_part : w; 
 
  228  h = h_bitmap - y_part < h ? h_bitmap - y_part : h; 
 
  230  w = 8 * ((w + 7) / 8); 
 
  231  int16_t x1 = x < 0 ? 0 : x; 
 
  232  int16_t y1 = y < 0 ? 0 : y; 
 
  233  int16_t w1 = x + w < int16_t(
WIDTH) ? w : int16_t(
WIDTH) - x; 
 
  234  int16_t h1 = y + h < int16_t(
HEIGHT) ? h : int16_t(
HEIGHT) - y; 
 
  239  if ((w1 <= 0) || (h1 <= 0)) 
return;
 
  241  _setPartialRamArea(x1, y1, w1, h1);
 
  242  SPI.beginTransaction(_spi_settings);
 
  243  if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  246  for (int16_t i = 0; i < h1; i++)
 
  248    for (int16_t j = 0; j < w1 / 8; j++)
 
  252      uint32_t idx = mirror_y ? x_part / 8 + (j + dx / 8) + uint32_t((h_bitmap - 1 - (y_part + i + dy))) * uint32_t(wb_bitmap) : x_part / 8 + j + dx / 8 + uint32_t(y_part + i + dy) * uint32_t(wb_bitmap);
 
  255#if defined(__AVR) || defined(ESP8266) || defined(ESP32) 
  256        data = pgm_read_byte(&bitmap[idx]);
 
  265      if (invert) data = ~data;
 
  269  if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  270  SPI.endTransaction();
 
 
  280    writeImage(black, x, y, w, h, invert, mirror_y, pgm);
 
 
  285                                 int16_t x, int16_t y, int16_t w, int16_t h, 
bool invert, 
bool mirror_y, 
bool pgm)
 
  289    writeImagePart(black, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
 
 
  299    int16_t x1 = x < 0 ? 0 : x; 
 
  300    int16_t y1 = y < 0 ? 0 : y; 
 
  301    int16_t w1 = x + w < int16_t(
WIDTH) ? w : int16_t(
WIDTH) - x; 
 
  302    int16_t h1 = y + h < int16_t(
HEIGHT) ? h : int16_t(
HEIGHT) - y; 
 
  307    if ((w1 <= 0) || (h1 <= 0)) 
return;
 
  309    _setPartialRamArea(x1, y1, w1, h1);
 
  310    SPI.beginTransaction(_spi_settings);
 
  311    if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  314    for (int16_t i = 0; i < h1; i++)
 
  316      for (int16_t j = 0; j < w1; j++)
 
  320        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);
 
  323#if defined(__AVR) || defined(ESP8266) || defined(ESP32) 
  324          data = pgm_read_byte(&data1[idx]);
 
  333        if (invert) data = ~data;
 
  336#if defined(ESP8266) || defined(ESP32) 
  340    if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  341    SPI.endTransaction();
 
 
  350  writeImage(bitmap, x, y, w, h, invert, mirror_y, pgm);
 
  351  _refresh(x, y, w, h, 
true);
 
 
  355                                int16_t x, int16_t y, int16_t w, int16_t h, 
bool invert, 
bool mirror_y, 
bool pgm)
 
  357  writeImagePart(bitmap, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
 
  358  _refresh(x, y, w, h, 
true);
 
 
  363  writeImage(black, color, x, y, w, h, invert, mirror_y, pgm);
 
  364  _refresh(x, y, w, h, 
true);
 
 
  368                                int16_t x, int16_t y, int16_t w, int16_t h, 
bool invert, 
bool mirror_y, 
bool pgm)
 
  370  writeImagePart(black, color, x_part, y_part, w_bitmap, h_bitmap, x, y, w, h, invert, mirror_y, pgm);
 
  371  _refresh(x, y, w, h, 
true);
 
 
  376  writeNative(data1, data2, x, y, w, h, invert, mirror_y, pgm);
 
  377  _refresh(x, y, w, h, 
false);
 
 
  382  _refresh(0, 0, 
WIDTH, 
HEIGHT, partial_update_mode);
 
 
  387  _refresh(x, y, w, h, 
true);
 
 
  390void GxEPD2_it103_1872x1404::_refresh(int16_t x, int16_t y, int16_t w, int16_t h, 
bool partial_update_mode)
 
  394  int16_t x1 = x < 0 ? 0 : x; 
 
  395  int16_t y1 = y < 0 ? 0 : y; 
 
  396  int16_t w1 = x + w < int16_t(
WIDTH) ? w : int16_t(
WIDTH) - x; 
 
  397  int16_t h1 = y + h < int16_t(
HEIGHT) ? h : int16_t(
HEIGHT) - y; 
 
  412  _writeData16(partial_update_mode ? 1 : 2); 
 
  434void GxEPD2_it103_1872x1404::_send8pixel(uint8_t data)
 
  436  for (uint8_t j = 0; j < 8; j++)
 
  438    SPI.transfer(data & 0x80 ? 0x00 : 0xFF);
 
  443void GxEPD2_it103_1872x1404::_setPartialRamArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
 
  457void GxEPD2_it103_1872x1404::_PowerOn()
 
  467void GxEPD2_it103_1872x1404::_PowerOff()
 
  475void GxEPD2_it103_1872x1404::_InitDisplay()
 
  480    digitalWrite(
_rst, LOW);
 
  482    digitalWrite(
_rst, HIGH);
 
  487void GxEPD2_it103_1872x1404::_Init_Full()
 
  494void GxEPD2_it103_1872x1404::_Init_Part()
 
  501void GxEPD2_it103_1872x1404::_waitWhileBusy2(
const char* comment, uint16_t busy_time)
 
  505    unsigned long start = micros();
 
  512        Serial.println(
"Busy Timeout!");
 
  518#if !defined(DISABLE_DIAGNOSTIC_OUTPUT) 
  521        unsigned long elapsed = micros() - start;
 
  524          Serial.print(comment);
 
  526          Serial.println(elapsed);
 
  533  else delay(busy_time);
 
  536uint16_t GxEPD2_it103_1872x1404::_transfer16(uint16_t value)
 
  538  uint16_t rv = SPI.transfer(value >> 8) << 8;
 
  539  return (rv | SPI.transfer(value));
 
  542void GxEPD2_it103_1872x1404::_writeCommand16(uint16_t c)
 
  544  String s = String(
"_writeCommand16(0x") + String(c, HEX) + String(
")");
 
  546  SPI.beginTransaction(_spi_settings);
 
  547  if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  551  if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  552  SPI.endTransaction();
 
  556void GxEPD2_it103_1872x1404::_writeData16(uint16_t d)
 
  559  SPI.beginTransaction(_spi_settings);
 
  560  if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  564  if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  565  SPI.endTransaction();
 
  568void GxEPD2_it103_1872x1404::_writeData16(
const uint16_t* d, uint32_t n)
 
  571  SPI.beginTransaction(_spi_settings);
 
  572  if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  575  for (uint32_t i = 0; i < n; i++)
 
  579  if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  580  SPI.endTransaction();
 
  583uint16_t GxEPD2_it103_1872x1404::_readData16()
 
  586  SPI.beginTransaction(_spi_settings);
 
  587  if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  592  uint16_t rv = _transfer16(0);
 
  593  if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  594  SPI.endTransaction();
 
  598void GxEPD2_it103_1872x1404::_readData16(uint16_t* d, uint32_t n)
 
  601  SPI.beginTransaction(_spi_settings);
 
  602  if (
_cs >= 0) digitalWrite(
_cs, LOW);
 
  607  for (uint32_t i = 0; i < n; i++)
 
  609    *d++ = _transfer16(0);
 
  612  if (
_cs >= 0) digitalWrite(
_cs, HIGH);
 
  613  SPI.endTransaction();
 
  616void GxEPD2_it103_1872x1404::_writeCommandData16(uint16_t c, 
const uint16_t* d, uint16_t n)
 
  619  for (uint16_t i = 0; i < n; i++)
 
  625void GxEPD2_it103_1872x1404::_IT8951SystemRun()
 
  630void GxEPD2_it103_1872x1404::_IT8951StandBy()
 
  635void GxEPD2_it103_1872x1404::_IT8951Sleep()
 
  640uint16_t GxEPD2_it103_1872x1404::_IT8951ReadReg(uint16_t usRegAddr)
 
  646  _writeData16(usRegAddr);
 
  648  usData = _readData16();
 
  652void GxEPD2_it103_1872x1404::_IT8951WriteReg(uint16_t usRegAddr, uint16_t usValue)
 
  656  _writeData16(usRegAddr);
 
  657  _writeData16(usValue);
 
  660uint16_t GxEPD2_it103_1872x1404::_IT8951GetVCOM(
void)
 
  668  vcom = _readData16();
 
  672void GxEPD2_it103_1872x1404::_IT8951SetVCOM(uint16_t vcom)
 
#define IT8951_TCON_SYS_RUN
 
#define IT8951_TCON_LD_IMG_AREA
 
#define IT8951_TCON_LD_IMG_END
 
#define IT8951_TCON_REG_RD
 
#define USDEF_I80_CMD_DPY_AREA
 
#define USDEF_I80_CMD_VCOM
 
#define IT8951_TCON_REG_WR
 
#define IT8951_LDIMG_B_ENDIAN
 
#define IT8951_TCON_SLEEP
 
#define IT8951_TCON_STANDBY
 
#define USDEF_I80_CMD_GET_DEV_INFO
 
virtual void init(uint32_t serial_diag_bitrate=0)
 
void _waitWhileBusy(const char *comment=0, uint16_t busy_time=5000)
 
static const uint16_t refresh_par_time
 
void writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap, int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
 
static const uint16_t full_refresh_time
 
static const uint16_t reset_to_ready_time
 
static const uint16_t default_wait_time
 
void drawImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap, int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
 
static const uint16_t diag_min_time
 
void writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
 
static const uint16_t WIDTH
 
void drawNative(const uint8_t *data1, const uint8_t *data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
 
void writeNative(const uint8_t *data1, const uint8_t *data2, int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
 
void refresh(bool partial_update_mode=false)
 
static const uint16_t power_on_time
 
void init(uint32_t serial_diag_bitrate=0)
 
void clearScreen(uint8_t value=0x33)
 
static const uint16_t set_vcom_time
 
void drawImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert=false, bool mirror_y=false, bool pgm=false)
 
static const uint16_t refresh_cmd_time
 
void writeScreenBuffer(uint8_t value=0x33)
 
static const uint16_t power_off_time
 
GxEPD2_it103_1872x1404(int16_t cs, int16_t dc, int16_t rst, int16_t busy)
 
static const uint16_t HEIGHT