void GxGDEW042T2_FPU::_writeToWindow(uint16_t xs, uint16_t ys, uint16_t xd, uint16_t yd, uint16_t w, uint16_t h) { //Serial.printf("_writeToWindow(%d, %d, %d, %d, %d, %d)\n", xs, ys, xd, yd, w, h); // the screen limits are the hard limits if (xs >= GxGDEW042T2_FPU_WIDTH) return; if (ys >= GxGDEW042T2_FPU_HEIGHT) return; if (xd >= GxGDEW042T2_FPU_WIDTH) return; if (yd >= GxGDEW042T2_FPU_HEIGHT) return; uint16_t xde = min(GxGDEW042T2_FPU_WIDTH, xd + w) - 1; uint16_t yde = min(GxGDEW042T2_FPU_HEIGHT, yd + h) - 1; // soft limits, must send as many bytes as set by _SetRamArea uint16_t yse = ys + yde - yd; uint16_t xss_d8 = xs / 8; IO.writeCommandTransaction(0x91); // partial in uint16_t xse_d8 = xss_d8 + _setPartialRamArea(xd, yd, xde, yde); IO.writeCommandTransaction(0x13); for (int16_t y1 = ys; y1 <= yse; y1++) { for (int16_t x1 = xss_d8; x1 < xse_d8; x1++) { uint16_t idx = y1 * (GxGDEW042T2_FPU_WIDTH / 8) + x1; uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00; IO.writeDataTransaction(~data); } } delay(2); IO.writeCommandTransaction(0x92); // partial out }
void GxEPD2_270::writeScreenBufferAgain(uint8_t value) { if (!_using_partial_mode) _Init_Part(); _setPartialRamArea(0x14, 0, 0, WIDTH, HEIGHT); for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++) { _writeData(value); } }
void GxEPD2_270::_writeImagePart(uint8_t command, 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, bool mirror_y, bool pgm) { if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean delay(1); // yield() to avoid WDT on ESP8266 and ESP32 if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return; if ((x_part < 0) || (x_part >= w_bitmap)) return; if ((y_part < 0) || (y_part >= h_bitmap)) return; int16_t wb_bitmap = (w_bitmap + 7) / 8; // width bytes, bitmaps are padded x_part -= x_part % 8; // byte boundary w = w_bitmap - x_part < w ? w_bitmap - x_part : w; // limit h = h_bitmap - y_part < h ? h_bitmap - y_part : h; // limit x -= x % 8; // byte boundary w = 8 * ((w + 7) / 8); // byte boundary, bitmaps are padded int16_t x1 = x < 0 ? 0 : x; // limit int16_t y1 = y < 0 ? 0 : y; // limit int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit int16_t dx = x1 - x; int16_t dy = y1 - y; w1 -= dx; h1 -= dy; if ((w1 <= 0) || (h1 <= 0)) return; if (!_using_partial_mode) _Init_Part(); _setPartialRamArea(command, x1, y1, w1, h1); for (int16_t i = 0; i < h1; i++) { for (int16_t j = 0; j < w1 / 8; j++) { uint8_t data; // use wb_bitmap, h_bitmap of bitmap for index! int16_t idx = mirror_y ? x_part / 8 + j + dx / 8 + ((h_bitmap - 1 - (y_part + i + dy))) * wb_bitmap : x_part / 8 + j + dx / 8 + (y_part + i + dy) * wb_bitmap; if (pgm) { #if defined(__AVR) || defined(ESP8266) || defined(ESP32) data = pgm_read_byte(&bitmap[idx]); #else data = bitmap[idx]; #endif } else { data = bitmap[idx]; } if (invert) data = ~data; _writeData(data); } } delay(1); // yield() to avoid WDT on ESP8266 and ESP32 }
void GxEPD2_213c::refresh(int16_t x, int16_t y, int16_t w, int16_t h) { x -= x % 8; // byte boundary w -= x % 8; // byte boundary int16_t x1 = x < 0 ? 0 : x; // limit int16_t y1 = y < 0 ? 0 : y; // limit int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit w1 -= x1 - x; h1 -= y1 - y; _Init_Part(); _setPartialRamArea(x1, y1, w1, h1); _Update_Part(); }
void GxEPD2_213c::writeScreenBuffer(uint8_t black_value, uint8_t color_value) { _initial_write = false; // initial full screen buffer clean done _Init_Part(); _writeCommand(0x91); // partial in _setPartialRamArea(0, 0, WIDTH, HEIGHT); _writeCommand(0x10); for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++) { _writeData(black_value); } _writeCommand(0x13); for (uint32_t i = 0; i < uint32_t(WIDTH) * uint32_t(HEIGHT) / 8; i++) { _writeData(color_value); } _writeCommand(0x92); // partial out }
void GxGDEW042T2_FPU::eraseDisplay(bool using_partial_update) { if (_current_page != -1) return; if (using_partial_update) { _using_partial_mode = true; // remember _wakeUp(); _Init_PartialUpdate(); // set full screen IO.writeCommandTransaction(0x91); // partial in _setPartialRamArea(0, 0, GxGDEW042T2_FPU_WIDTH - 1, GxGDEW042T2_FPU_HEIGHT - 1); IO.writeCommandTransaction(0x13); for (uint32_t i = 0; i < GxGDEW042T2_FPU_BUFFER_SIZE; i++) { IO.writeDataTransaction(0xFF); } IO.writeCommandTransaction(0x10); for (uint32_t i = 0; i < GxGDEW042T2_FPU_BUFFER_SIZE; i++) { IO.writeDataTransaction(0xFF); } IO.writeCommandTransaction(0x92); // partial out IO.writeCommandTransaction(0x12); //display refresh _waitWhileBusy("eraseDisplay"); } else { _using_partial_mode = false; // remember _wakeUp(); IO.writeCommandTransaction(0x13); for (uint32_t i = 0; i < GxGDEW042T2_FPU_BUFFER_SIZE; i++) { IO.writeDataTransaction(0xFF); } IO.writeCommandTransaction(0x12); //display refresh _waitWhileBusy("eraseDisplay"); _sleep(); } }
void GxEPD2_213c::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) { if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean delay(1); // yield() to avoid WDT on ESP8266 and ESP32 int16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded x -= x % 8; // byte boundary w = wb * 8; // byte boundary int16_t x1 = x < 0 ? 0 : x; // limit int16_t y1 = y < 0 ? 0 : y; // limit int16_t w1 = x + w < int16_t(WIDTH) ? w : int16_t(WIDTH) - x; // limit int16_t h1 = y + h < int16_t(HEIGHT) ? h : int16_t(HEIGHT) - y; // limit int16_t dx = x1 - x; int16_t dy = y1 - y; w1 -= dx; h1 -= dy; if ((w1 <= 0) || (h1 <= 0)) return; _Init_Part(); _writeCommand(0x91); // partial in _setPartialRamArea(x1, y1, w1, h1); _writeCommand(0x10); for (int16_t i = 0; i < h1; i++) { for (int16_t j = 0; j < w1 / 8; j++) { uint8_t data = 0xFF; if (black) { // use wb, h of bitmap for index! int16_t idx = mirror_y ? j + dx / 8 + ((h - 1 - (i + dy))) * wb : j + dx / 8 + (i + dy) * wb; if (pgm) { #if defined(__AVR) || defined(ESP8266) || defined(ESP32) data = pgm_read_byte(&black[idx]); #else data = black[idx]; #endif } else { data = black[idx]; } if (invert) data = ~data; } _writeData(data); } } _writeCommand(0x13); for (int16_t i = 0; i < h1; i++) { for (int16_t j = 0; j < w1 / 8; j++) { uint8_t data = 0xFF; if (color) { // use wb, h of bitmap for index! int16_t idx = mirror_y ? j + dx / 8 + ((h - 1 - (i + dy))) * wb : j + dx / 8 + (i + dy) * wb; if (pgm) { #if defined(__AVR) || defined(ESP8266) || defined(ESP32) data = pgm_read_byte(&color[idx]); #else data = color[idx]; #endif } else { data = color[idx]; } if (invert) data = ~data; } _writeData(data); } } _writeCommand(0x92); // partial out delay(1); // yield() to avoid WDT on ESP8266 and ESP32 }
void GxGDEW042T2_FPU::updateWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h, bool using_rotation) { if (_current_page != -1) return; if (using_rotation) { switch (getRotation()) { case 1: swap(x, y); swap(w, h); x = GxGDEW042T2_FPU_WIDTH - x - w - 1; break; case 2: x = GxGDEW042T2_FPU_WIDTH - x - w - 1; y = GxGDEW042T2_FPU_HEIGHT - y - h - 1; break; case 3: swap(x, y); swap(w, h); y = GxGDEW042T2_FPU_HEIGHT - y - h - 1; break; } } //fillScreen(0x0); if (x >= GxGDEW042T2_FPU_WIDTH) return; if (y >= GxGDEW042T2_FPU_HEIGHT) return; // x &= 0xFFF8; // byte boundary, not here, use encompassing rectangle uint16_t xe = min(GxGDEW042T2_FPU_WIDTH, x + w) - 1; uint16_t ye = min(GxGDEW042T2_FPU_HEIGHT, y + h) - 1; // x &= 0xFFF8; // byte boundary, not needed here uint16_t xs_bx = x / 8; uint16_t xe_bx = (xe + 7) / 8; if (!_using_partial_mode) _wakeUp(); _using_partial_mode = true; _Init_PartialUpdate(); IO.writeCommandTransaction(0x91); // partial in _setPartialRamArea(x, y, xe, ye); IO.writeCommandTransaction(0x13); for (int16_t y1 = y; y1 <= ye; y1++) { for (int16_t x1 = xs_bx; x1 < xe_bx; x1++) { uint16_t idx = y1 * (GxGDEW042T2_FPU_WIDTH / 8) + x1; uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00; IO.writeDataTransaction(~data); } } IO.writeCommandTransaction(0x92); // partial out IO.writeCommandTransaction(0x12); //display refresh _waitWhileBusy("updateWindow"); IO.writeCommandTransaction(0x91); // partial in _setPartialRamArea(x, y, xe, ye); IO.writeCommandTransaction(0x13); for (int16_t y1 = y; y1 <= ye; y1++) { for (int16_t x1 = xs_bx; x1 < xe_bx; x1++) { uint16_t idx = y1 * (GxGDEW042T2_FPU_WIDTH / 8) + x1; uint8_t data = (idx < sizeof(_buffer)) ? _buffer[idx] : 0x00; IO.writeDataTransaction(~data); } } IO.writeCommandTransaction(0x92); // partial out }
void GxGDEW042T2_FPU::drawBitmap(const uint8_t *bitmap, uint32_t size, int16_t mode) { if (_current_page != -1) return; if (mode & bm_default) mode |= bm_normal; if (mode & bm_partial_update) { _using_partial_mode = true; // remember _wakeUp(); _Init_PartialUpdate(); // set full screen IO.writeCommandTransaction(0x91); // partial in _setPartialRamArea(0, 0, GxGDEW042T2_FPU_WIDTH - 1, GxGDEW042T2_FPU_HEIGHT - 1); IO.writeCommandTransaction(0x13); for (uint32_t i = 0; i < GxGDEW042T2_FPU_BUFFER_SIZE; i++) { uint8_t data = 0xFF; // white is 0xFF on device if (i < size) { #if defined(__AVR) || defined(ESP8266) || defined(ESP32) data = pgm_read_byte(&bitmap[i]); #else data = bitmap[i]; #endif if (mode & bm_invert) data = ~data; } IO.writeDataTransaction(data); } IO.writeCommandTransaction(0x92); // partial out IO.writeCommandTransaction(0x12); //display refresh _waitWhileBusy("drawBitmap"); // update erase buffer IO.writeCommandTransaction(0x91); // partial in _setPartialRamArea(0, 0, GxGDEW042T2_FPU_WIDTH - 1, GxGDEW042T2_FPU_HEIGHT - 1); IO.writeCommandTransaction(0x13); for (uint32_t i = 0; i < GxGDEW042T2_FPU_BUFFER_SIZE; i++) { uint8_t data = 0xFF; // white is 0xFF on device if (i < size) { #if defined(__AVR) || defined(ESP8266) || defined(ESP32) data = pgm_read_byte(&bitmap[i]); #else data = bitmap[i]; #endif if (mode & bm_invert) data = ~data; } IO.writeDataTransaction(data); } IO.writeCommandTransaction(0x92); // partial out _waitWhileBusy("drawBitmap"); } else { _using_partial_mode = false; // remember _wakeUp(); IO.writeCommandTransaction(0x13); for (uint32_t i = 0; i < GxGDEW042T2_FPU_BUFFER_SIZE; i++) { uint8_t data = 0xFF; // white is 0xFF on device if (i < size) { #if defined(__AVR) || defined(ESP8266) || defined(ESP32) data = pgm_read_byte(&bitmap[i]); #else data = bitmap[i]; #endif if (mode & bm_invert) data = ~data; } IO.writeDataTransaction(data); } IO.writeCommandTransaction(0x12); //display refresh _waitWhileBusy("drawBitmap"); _sleep(); } }