14#if defined(ESP8266) || defined(ESP32)
17#include <avr/pgmspace.h>
21 uint16_t w, uint16_t h,
GxEPD2::Panel p,
bool c,
bool pu,
bool fpu) :
22 WIDTH(w), HEIGHT(h), panel(p), hasColor(c), hasPartialUpdate(pu), hasFastPartialUpdate(fpu),
23 _cs(cs), _dc(dc), _rst(rst), _busy(busy), _busy_level(busy_level), _busy_timeout(busy_timeout), _diag_enabled(false),
24 _pSPIx(&SPI), _spi_settings(4000000, MSBFIRST, SPI_MODE0)
38 init(serial_diag_bitrate,
true, 10,
false);
41void GxEPD2_EPD::init(uint32_t serial_diag_bitrate,
bool initial, uint16_t reset_duration,
bool pulldown_rst_mode)
50 if (serial_diag_bitrate > 0)
52 Serial.begin(serial_diag_bitrate);
57 digitalWrite(
_cs, HIGH);
62 digitalWrite(
_dc, HIGH);
68 pinMode(
_busy, INPUT);
73 pinMode(
_busy, INPUT);
99 digitalWrite(
_rst, LOW);
100 pinMode(
_rst, OUTPUT);
102 pinMode(
_rst, INPUT_PULLUP);
107 digitalWrite(
_rst, HIGH);
108 pinMode(
_rst, OUTPUT);
110 digitalWrite(
_rst, LOW);
112 digitalWrite(
_rst, HIGH);
124 unsigned long start = micros();
133 Serial.println(
"Busy Timeout!");
136#if defined(ESP8266) || defined(ESP32)
142#if !defined(DISABLE_DIAGNOSTIC_OUTPUT)
145 unsigned long elapsed = micros() - start;
146 Serial.print(comment);
148 Serial.println(elapsed);
154 else delay(busy_time);
160 if (
_dc >= 0) digitalWrite(
_dc, LOW);
161 if (
_cs >= 0) digitalWrite(
_cs, LOW);
163 if (
_cs >= 0) digitalWrite(
_cs, HIGH);
164 if (
_dc >= 0) digitalWrite(
_dc, HIGH);
171 if (
_cs >= 0) digitalWrite(
_cs, LOW);
173 if (
_cs >= 0) digitalWrite(
_cs, HIGH);
180 if (
_cs >= 0) digitalWrite(
_cs, LOW);
181 for (uint16_t i = 0; i < n; i++)
183 _pSPIx->transfer(*data++);
185 if (
_cs >= 0) digitalWrite(
_cs, HIGH);
192 if (
_cs >= 0) digitalWrite(
_cs, LOW);
193 for (uint16_t i = 0; i < n; i++)
195 _pSPIx->transfer(pgm_read_byte(&*data++));
197 while (fill_with_zeroes > 0)
202 if (
_cs >= 0) digitalWrite(
_cs, HIGH);
209 for (uint8_t i = 0; i < n; i++)
211 if (
_cs >= 0) digitalWrite(
_cs, LOW);
212 _pSPIx->transfer(pgm_read_byte(&*data++));
213 if (
_cs >= 0) digitalWrite(
_cs, HIGH);
215 while (fill_with_zeroes > 0)
217 if (
_cs >= 0) digitalWrite(
_cs, LOW);
220 if (
_cs >= 0) digitalWrite(
_cs, HIGH);
228 if (
_dc >= 0) digitalWrite(
_dc, LOW);
229 if (
_cs >= 0) digitalWrite(
_cs, LOW);
230 _pSPIx->transfer(*pCommandData++);
231 if (
_dc >= 0) digitalWrite(
_dc, HIGH);
232 for (uint8_t i = 0; i < datalen - 1; i++)
234 _pSPIx->transfer(*pCommandData++);
236 if (
_cs >= 0) digitalWrite(
_cs, HIGH);
243 if (
_dc >= 0) digitalWrite(
_dc, LOW);
244 if (
_cs >= 0) digitalWrite(
_cs, LOW);
245 _pSPIx->transfer(pgm_read_byte(&*pCommandData++));
246 if (
_dc >= 0) digitalWrite(
_dc, HIGH);
247 for (uint8_t i = 0; i < datalen - 1; i++)
249 _pSPIx->transfer(pgm_read_byte(&*pCommandData++));
251 if (
_cs >= 0) digitalWrite(
_cs, HIGH);
258 if (
_cs >= 0) digitalWrite(
_cs, LOW);
268 if (
_cs >= 0) digitalWrite(
_cs, HIGH);
void _writeCommand(uint8_t c)
void _writeData(uint8_t d)
virtual void init(uint32_t serial_diag_bitrate=0)
void _waitWhileBusy(const char *comment=0, uint16_t busy_time=5000)
void(* _busy_callback)(const void *)
void _writeCommandDataPGM(const uint8_t *pCommandData, uint8_t datalen)
void selectSPI(SPIClass &spi, SPISettings spi_settings)
void _transfer(uint8_t value)
GxEPD2_EPD(int16_t cs, int16_t dc, int16_t rst, int16_t busy, int16_t busy_level, uint32_t busy_timeout, uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu)
void _writeDataPGM_sCS(const uint8_t *data, uint16_t n, int16_t fill_with_zeroes=0)
const void * _busy_callback_parameter
void _writeCommandData(const uint8_t *pCommandData, uint8_t datalen)
SPISettings _spi_settings
void _writeDataPGM(const uint8_t *data, uint16_t n, int16_t fill_with_zeroes=0)
void setBusyCallback(void(*busyCallback)(const void *), const void *busy_callback_parameter=0)