1+ #ifndef EPD_WIDTH
2+ #define EPD_WIDTH 128
3+ #endif
4+
5+ #ifndef EPD_HEIGHT
6+ #define EPD_HEIGHT 250
7+ #endif
8+
9+ #ifndef TFT_WIDTH
10+ #define TFT_WIDTH EPD_WIDTH
11+ #endif
12+
13+ #ifndef TFT_HEIGHT
14+ #define TFT_HEIGHT EPD_HEIGHT
15+ #endif
16+
17+ #define EPD_COLOR_DEPTH 4
18+
19+
20+
21+ #define EPD_NOP 0xFF // No operation command (not supported)
22+ #define EPD_PNLSET 0x00 // Panel setting (R00H PSR)
23+ #define EPD_DISPON 0x04 // Power on (R04H PON)
24+ #define EPD_DISPOFF 0x02 // Power off (R02H POF)
25+ #define EPD_SLPIN 0x07 // Enter deep sleep (R07H DSLP)
26+ #define EPD_SLPOUT 0xFF // Exit sleep (not supported, requires wake-up)
27+ #define EPD_PTLIN 0x91 // Partial display in (R91H PTIN)
28+ #define EPD_PTLOUT 0x92 // Partial display out (R92H PTOUT)
29+ #define EPD_PTLW 0x90 // Partial display window setting (R90H PTL)
30+
31+ #define TFT_SWRST 0xFF // Software reset (not supported)
32+ #define TFT_CASET 0xFF // Column address setting (not supported)
33+ #define TFT_PASET 0xFF // Page address setting (not supported)
34+ #define TFT_RAMWR 0x13 // Write RAM (R13H DTM2, red data)
35+ #define TFT_RAMRD 0xFF // Read RAM (not supported)
36+ #define TFT_INVON 0xFF // Display inversion on (not supported)
37+ #define TFT_INVOFF 0xFF // Display inversion off (not supported)
38+ #define TFT_INIT_DELAY 0 // Initialization delay (none)
39+
40+ #ifdef TFT_BUSY
41+ #define CHECK_BUSY () \
42+ do \
43+ { \
44+ while (!digitalRead(TFT_BUSY)) \
45+ ; \
46+ } while (0)
47+ #else
48+ #define CHECK_BUSY ()
49+ #endif
50+
51+ #define EPD_INIT () \
52+ do \
53+ { \
54+ writecommand(0x4D);\
55+ writedata(0x78);\
56+ writecommand(0x00); \
57+ writedata(0x0F);\
58+ writedata(0x29);\
59+ writecommand(0x01); \
60+ writedata(0x07);\
61+ writecommand(0x03); \
62+ writedata(0x10);\
63+ writedata(0x54);\
64+ writedata(0x44);\
65+ writecommand(0x06); \
66+ writedata(0x0F);\
67+ writedata(0x0A);\
68+ writedata(0x2F);\
69+ writedata(0x25);\
70+ writedata(0x22);\
71+ writedata(0x2E);\
72+ writedata(0x21); \
73+ writecommand(0x50);\
74+ writedata(0x37);\
75+ writecommand(0x60); \
76+ writedata(0x02);\
77+ writedata(0x02);\
78+ writecommand(0x61); \
79+ writedata(128/256); \
80+ writedata (128 %256 ); \
81+ writedata (250 /256 ); \
82+ writedata (250 %256 ); \
83+ writecommand (0xE7 );\
84+ writedata (0x1C );\
85+ writecommand (0xE3 ); \
86+ writedata (0x22 );\
87+ writecommand (0xB4 );\
88+ writedata (0xD0 );\
89+ writecommand (0xB5 );\
90+ writedata (0x03 );\
91+ writecommand (0xE9 );\
92+ writedata (0x01 ); \
93+ writecommand (0x30 );\
94+ writedata (0x08 ); \
95+ writecommand (0x04 );\
96+ CHECK_BUSY (); \
97+ } while (0 )
98+
99+ #define EPD_UPDATE () \
100+ do \
101+ { \
102+ writecommand(0x12); \
103+ writedata(0x00); \
104+ CHECK_BUSY(); \
105+ } while (0)
106+
107+ #define EPD_SLEEP () \
108+ do \
109+ { \
110+ writecommand(0x02); \
111+ CHECK_BUSY(); \
112+ delay(100); \
113+ writecommand(0x07); \
114+ writedata(0xA5); \
115+ } while (0)
116+
117+ #define EPD_WAKEUP () \
118+ do \
119+ { \
120+ digitalWrite(TFT_RST, LOW); \
121+ delay(20); \
122+ digitalWrite(TFT_RST, HIGH); \
123+ delay(20); \
124+ CHECK_BUSY(); \
125+ EPD_INIT(); \
126+ } while (0)
127+
128+ #define EPD_SET_WINDOW (x1 , y1 , x2 , y2 ) \
129+ do \
130+ { \
131+ } while (0)
132+
133+ #define COLOR_GET (color ) ( \
134+ (color) == 0x00 ? 0x01 : \
135+ (color) == 0x01 ? 0x02 : \
136+ (color) == 0x02 ? 0x03 : \
137+ (color) == 0x03 ? 0x00 : \
138+ 0x00 \
139+ )
140+
141+ #define EPD_PUSH_NEW_COLORS (w , h , colors ) \
142+ do \
143+ { \
144+ uint16_t bytes_per_row = (w) / 2; \
145+ uint8_t temp1, temp2, temp3, temp4; \
146+ writecommand(0x10); \
147+ for (uint16_t row = 0; row < (h) ; row++) \
148+ { \
149+ for(uint16_t col = 0; col < bytes_per_row; col+=2) \
150+ { \
151+ uint8_t b = (colors[bytes_per_row *row+col ]) ; \
152+ uint8_t c = (colors[bytes_per_row *row+col + 1]) ; \
153+ temp1 = (b >> 4) & 0x0F;\
154+ temp2 = b & 0x0F;\
155+ temp3 = (c >> 4) & 0x0F;\
156+ temp4 = c & 0x0F;\
157+ writedata(((COLOR_GET(temp1) <<6)|( COLOR_GET(temp2) << 4 ) |( COLOR_GET(temp3) << 2 ) |( COLOR_GET(temp4) << 0 )));\
158+ } \
159+ } \
160+ } while (0)
161+
162+ #define EPD_PUSH_NEW_COLORS_FLIP (w , h , colors ) \
163+ do \
164+ { \
165+ uint16_t bytes_per_row = (w) / 2; \
166+ uint8_t temp1, temp2, temp3, temp4; \
167+ writecommand(0x10); \
168+ for (uint16_t row = 0; row < (h); row++) \
169+ { \
170+ uint16_t start = row * bytes_per_row; \
171+ for (uint16_t col = 0; col < bytes_per_row; col+=2) \
172+ { \
173+ uint8_t b = (colors[bytes_per_row *row + (bytes_per_row - 1 - col)]) ;\
174+ uint8_t c = (colors[bytes_per_row *row + (bytes_per_row - 1 - col) - 1]) ;\
175+ temp1 = (b >> 4) & 0x0F;\
176+ temp2 = b & 0x0F;\
177+ temp3 = (c >> 4) & 0x0F;\
178+ temp4 = c & 0x0F;\
179+ writedata(((COLOR_GET(temp1) <<6)|( COLOR_GET(temp2) << 4 ) |( COLOR_GET(temp3) << 2 ) |( COLOR_GET(temp4) << 0 )));\
180+ } \
181+ } \
182+ } while (0)
183+
184+ #define EPD_PUSH_OLD_COLORS (w , h , colors ) \
185+ do \
186+ { \
187+ } while (0)
188+
189+ #define EPD_PUSH_OLD_COLORS_FLIP (w , h , colors ) \
190+ do \
191+ { \
192+ \
193+ } while (0)
194+
195+ #define EPD_SET_TEMP (temp ) \
196+ do \
197+ { \
198+ } while (0)
0 commit comments