1+ #ifndef EPD_WIDTH
2+ #define EPD_WIDTH 128
3+ #endif
4+
5+ #ifndef EPD_HEIGHT
6+ #define EPD_HEIGHT 296
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+ writedata(0x00);\
62+ writecommand(0x03); \
63+ writedata(0x10);\
64+ writedata(0x54);\
65+ writedata(0x44);\
66+ writecommand(0x06); \
67+ writedata(0x05);\
68+ writedata(0x00);\
69+ writedata(0x3F);\
70+ writedata(0x0A);\
71+ writedata(0x25);\
72+ writedata(0x12);\
73+ writedata(0x1A); \
74+ writecommand(0x50);\
75+ writedata(0x37);\
76+ writecommand(0x60); \
77+ writedata(0x02);\
78+ writedata(0x02);\
79+ writecommand(0x61); \
80+ writedata(128/256); \
81+ writedata (128 %256 ); \
82+ writedata (296 /256 ); \
83+ writedata (296 %256 ); \
84+ writecommand (0xE7 );\
85+ writedata (0x1C );\
86+ writecommand (0xE3 ); \
87+ writedata (0x22 );\
88+ writecommand (0xB4 );\
89+ writedata (0xD0 );\
90+ writecommand (0xB5 );\
91+ writedata (0x03 );\
92+ writecommand (0xE9 );\
93+ writedata (0x01 ); \
94+ writecommand (0x30 );\
95+ writedata (0x08 ); \
96+ writecommand (0x04 );\
97+ CHECK_BUSY (); \
98+ } while (0 )
99+
100+ #define EPD_UPDATE () \
101+ do \
102+ { \
103+ writecommand(0x12); \
104+ writedata(0x00); \
105+ CHECK_BUSY(); \
106+ } while (0)
107+
108+ #define EPD_SLEEP () \
109+ do \
110+ { \
111+ writecommand(0x02); \
112+ CHECK_BUSY(); \
113+ delay(100); \
114+ writecommand(0x07); \
115+ writedata(0xA5); \
116+ } while (0)
117+
118+ #define EPD_WAKEUP () \
119+ do \
120+ { \
121+ digitalWrite(TFT_RST, LOW); \
122+ delay(20); \
123+ digitalWrite(TFT_RST, HIGH); \
124+ delay(20); \
125+ CHECK_BUSY(); \
126+ EPD_INIT(); \
127+ } while (0)
128+
129+ #define EPD_SET_WINDOW (x1 , y1 , x2 , y2 ) \
130+ do \
131+ { \
132+ } while (0)
133+
134+ #define COLOR_GET (color ) ( \
135+ (color) == 0x00 ? 0x01 : \
136+ (color) == 0x01 ? 0x02 : \
137+ (color) == 0x02 ? 0x03 : \
138+ (color) == 0x03 ? 0x00 : \
139+ 0x00 \
140+ )
141+
142+ #define EPD_PUSH_NEW_COLORS (w , h , colors ) \
143+ do \
144+ { \
145+ uint16_t bytes_per_row = (w) / 2; \
146+ uint8_t temp1, temp2, temp3, temp4; \
147+ writecommand(0x10); \
148+ for (uint16_t row = 0; row < (h) ; row++) \
149+ { \
150+ for(uint16_t col = 0; col < bytes_per_row; col+=2) \
151+ { \
152+ uint8_t b = (colors[bytes_per_row *row+col ]) ; \
153+ uint8_t c = (colors[bytes_per_row *row+col + 1]) ; \
154+ temp1 = (b >> 4) & 0x0F;\
155+ temp2 = b & 0x0F;\
156+ temp3 = (c >> 4) & 0x0F;\
157+ temp4 = c & 0x0F;\
158+ writedata(((COLOR_GET(temp1) <<6)|( COLOR_GET(temp2) << 4 ) |( COLOR_GET(temp3) << 2 ) |( COLOR_GET(temp4) << 0 )));\
159+ } \
160+ } \
161+ } while (0)
162+
163+ #define EPD_PUSH_NEW_COLORS_FLIP (w , h , colors ) \
164+ do \
165+ { \
166+ uint16_t bytes_per_row = (w) / 2; \
167+ uint8_t temp1, temp2, temp3, temp4; \
168+ writecommand(0x10); \
169+ for (uint16_t row = 0; row < (h); row++) \
170+ { \
171+ uint16_t start = row * bytes_per_row; \
172+ for (uint16_t col = 0; col < bytes_per_row; col+=2) \
173+ { \
174+ uint8_t b = (colors[bytes_per_row *row + (bytes_per_row - 1 - col)]) ;\
175+ uint8_t c = (colors[bytes_per_row *row + (bytes_per_row - 1 - col) - 1]) ;\
176+ temp1 = (b >> 4) & 0x0F;\
177+ temp2 = b & 0x0F;\
178+ temp3 = (c >> 4) & 0x0F;\
179+ temp4 = c & 0x0F;\
180+ writedata(((COLOR_GET(temp1) <<6)|( COLOR_GET(temp2) << 4 ) |( COLOR_GET(temp3) << 2 ) |( COLOR_GET(temp4) << 0 )));\
181+ } \
182+ } \
183+ } while (0)
184+
185+ #define EPD_PUSH_OLD_COLORS (w , h , colors ) \
186+ do \
187+ { \
188+ } while (0)
189+
190+ #define EPD_PUSH_OLD_COLORS_FLIP (w , h , colors ) \
191+ do \
192+ { \
193+ \
194+ } while (0)
195+
196+ #define EPD_SET_TEMP (temp ) \
197+ do \
198+ { \
199+ } while (0)
0 commit comments