Skip to content

Commit a730f9a

Browse files
committed
add mono mode for grayscale 4.2"
1 parent d06d0e1 commit a730f9a

File tree

4 files changed

+66
-16
lines changed

4 files changed

+66
-16
lines changed

src/Adafruit_ThinkInk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ typedef enum {
1616
#include "panels/ThinkInk_154_Grayscale4_T8.h"
1717
#include "panels/ThinkInk_213_Grayscale4_T5.h"
1818
#include "panels/ThinkInk_290_Grayscale4_T5.h"
19+
#include "panels/ThinkInk_420_Grayscale4_T2.h"
1920

2021
#include "panels/ThinkInk_154_Mono_D27.h"
2122
#include "panels/ThinkInk_154_Mono_D67.h"

src/drivers/Adafruit_IL0398.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33

44
#define BUSY_WAIT 500
55

6+
// clang-format off
7+
8+
const uint8_t il0398_default_init_code[] {
9+
0xFF, 20, // busy wait
10+
IL0398_BOOSTER_SOFT_START, 3, 0x17, 0x17, 0x17,
11+
IL0398_POWER_ON, 0,
12+
0xFF, 20, // busy wait
13+
IL0398_PANEL_SETTING, 2, 0x0F, 0x0, // lut from OTP & vcom = 0v
14+
IL0398_VCOM, 1, 0xD7,
15+
0xFE};
16+
17+
// clang-format on
18+
619
/**************************************************************************/
720
/*!
821
@brief constructor if using external SRAM chip and software SPI
@@ -51,8 +64,9 @@ Adafruit_IL0398::Adafruit_IL0398(int width, int height, int8_t SID, int8_t SCLK,
5164
*/
5265
/**************************************************************************/
5366
Adafruit_IL0398::Adafruit_IL0398(int width, int height, int8_t DC, int8_t RST,
54-
int8_t CS, int8_t SRCS, int8_t BUSY)
55-
: Adafruit_EPD(width, height, DC, RST, CS, SRCS, BUSY) {
67+
int8_t CS, int8_t SRCS, int8_t BUSY,
68+
SPIClass *spi)
69+
: Adafruit_EPD(width, height, DC, RST, CS, SRCS, BUSY, spi) {
5670

5771
buffer1_size = ((uint32_t)width * (uint32_t)height) / 8;
5872
buffer2_size = buffer1_size;
@@ -78,7 +92,7 @@ void Adafruit_IL0398::busy_wait(void) {
7892
do {
7993
EPD_command(IL0398_GETSTATUS);
8094
delay(10);
81-
} while (digitalRead(_busy_pin)); // wait for busy low
95+
} while (! digitalRead(_busy_pin)); // wait for busy HIGH
8296
delay(200);
8397
} else {
8498
delay(BUSY_WAIT);
@@ -125,16 +139,11 @@ void Adafruit_IL0398::powerUp() {
125139

126140
hardwareReset();
127141

128-
buf[0] = 0x17;
129-
buf[1] = 0x17;
130-
buf[2] = 0x17;
131-
EPD_command(IL0398_BOOSTER_SOFT_START, buf, 3);
132-
133-
EPD_command(IL0398_POWER_ON);
134-
busy_wait();
135-
136-
buf[0] = 0x0F;
137-
EPD_command(IL0398_PANEL_SETTING, buf, 1);
142+
const uint8_t *init_code = il0398_default_init_code;
143+
if (_epd_init_code != NULL) {
144+
init_code = _epd_init_code;
145+
}
146+
EPD_commandList(init_code);
138147

139148
buf[0] = (HEIGHT >> 8) & 0xFF;
140149
buf[1] = HEIGHT & 0xFF;
@@ -158,8 +167,11 @@ void Adafruit_IL0398::powerDown() {
158167
EPD_command(IL0398_VCOM, buf, 1);
159168
EPD_command(IL0398_POWER_OFF);
160169
busy_wait();
161-
buf[0] = 0xA5; // deep sleep
162-
EPD_command(IL0398_DEEP_SLEEP, buf, 1);
170+
// Only deep sleep if we can get out of it
171+
if (_reset_pin >= 0) {
172+
buf[0] = 0xA5; // deep sleep
173+
EPD_command(UC8276_DEEPSLEEP, buf, 1);
174+
}
163175
delay(100);
164176
}
165177

src/drivers/Adafruit_IL0398.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Adafruit_IL0398 : public Adafruit_EPD {
6363
int8_t RST, int8_t CS, int8_t SRCS, int8_t MISO,
6464
int8_t BUSY = -1);
6565
Adafruit_IL0398(int width, int height, int8_t DC, int8_t RST, int8_t CS,
66-
int8_t SRCS, int8_t BUSY = -1);
66+
int8_t SRCS, int8_t BUSY = -1, SPIClass *spi = &SPI);
6767

6868
void begin(bool reset = true);
6969
void powerUp();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef _THINKINK_420_GRAY4_T2_H
2+
#define _THINKINK_420_GRAY4_T2_H
3+
4+
#include "Adafruit_EPD.h"
5+
6+
class ThinkInk_420_Grayscale4_T2 : public Adafruit_IL0398 {
7+
private:
8+
public:
9+
ThinkInk_420_Grayscale4_T2(int8_t SID, int8_t SCLK, int8_t DC, int8_t RST,
10+
int8_t CS, int8_t SRCS, int8_t MISO, int8_t BUSY = -1)
11+
: Adafruit_IL0398(300, 400, SID, SCLK, DC, RST, CS, SRCS, MISO, BUSY){};
12+
13+
ThinkInk_420_Grayscale4_T2(int8_t DC, int8_t RST, int8_t CS, int8_t SRCS,
14+
int8_t BUSY = -1, SPIClass *spi = &SPI)
15+
: Adafruit_IL0398(300, 400, DC, RST, CS, SRCS, BUSY, spi){};
16+
17+
void begin(thinkinkmode_t mode = THINKINK_MONO) {
18+
Adafruit_EPD::begin(true);
19+
setColorBuffer(0, true); // layer 0 uninverted
20+
setBlackBuffer(1, true); // layer 1 uninverted
21+
22+
if (mode == THINKINK_MONO) {
23+
layer_colors[EPD_WHITE] = 0b00;
24+
layer_colors[EPD_BLACK] = 0b01;
25+
layer_colors[EPD_RED] = 0b01;
26+
layer_colors[EPD_GRAY] = 0b01;
27+
layer_colors[EPD_LIGHT] = 0b00;
28+
layer_colors[EPD_DARK] = 0b01;
29+
}
30+
31+
default_refresh_delay = 1000;
32+
setRotation(1);
33+
powerDown();
34+
};
35+
};
36+
37+
#endif // _THINKINK_420_GRAY4_T2_H

0 commit comments

Comments
 (0)