Skip to content

Commit 4baa312

Browse files
committed
Merge remote-tracking branch 'origin/master' into 4bpp_rotation
2 parents a5f204e + 9b0827e commit 4baa312

File tree

5 files changed

+140
-8
lines changed

5 files changed

+140
-8
lines changed

Extensions/EPaper.cpp

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ void EPaper::begin(uint8_t tc)
3333
void EPaper::update()
3434
{
3535
wake();
36-
EPD_SET_WINDOW(0, 0, (_width - 1), (_height - 1));
3736

3837
if(!_grayLevel)
3938
{
4039
#ifdef EPD_HORIZONTAL_MIRROR
40+
EPD_PUSH_OLD_COLORS_FLIP(_width, _height, _img8);
4141
EPD_PUSH_NEW_COLORS_FLIP(_width, _height, _img8);
4242
#else
43+
EPD_PUSH_OLD_COLORS(_width, _height, _img8);
4344
EPD_PUSH_NEW_COLORS(_width, _height, _img8);
4445
#endif
4546
EPD_UPDATE();
@@ -58,7 +59,46 @@ void EPaper::update()
5859
sleep();
5960
}
6061

62+
#ifdef USE_PARTIAL_EPAPER
63+
void EPaper::updataPartial(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
64+
{
65+
uint16_t x0 = x & ~7;
66+
uint16_t x1 = (x + w + 7) & ~7;
67+
uint16_t w_aligned = x1 - x0;
68+
69+
uint16_t stride = _width >> 3;
70+
uint16_t win_bytes_per_row = w_aligned >> 3;
71+
72+
const uint8_t* src0 = _img8 + (y * stride) + (x0 >> 3);
73+
74+
size_t win_size = (size_t)win_bytes_per_row * h;
75+
uint8_t* winbuf = (uint8_t*)malloc(win_size);
76+
if (!winbuf) return;
77+
78+
79+
for (uint16_t row = 0; row < h; row++) {
80+
memcpy(winbuf + row * win_bytes_per_row,
81+
src0 + row * stride,
82+
win_bytes_per_row);
83+
}
84+
85+
if (_sleep) { EPD_WAKEUP_PARTIAL(); _sleep = false; }
86+
87+
#ifdef EPD_HORIZONTAL_MIRROR
88+
EPD_SET_WINDOW(x0, y, x0 + w_aligned - 1, y + h - 1);
89+
EPD_PUSH_NEW_COLORS_PART_FLIP(w_aligned, h, winbuf);
90+
#else
91+
EPD_SET_WINDOW(x0, y, x0 + w_aligned - 1, y + h - 1);
92+
EPD_PUSH_NEW_COLORS_PART(w_aligned, h, winbuf);
93+
#endif
94+
EPD_UPDATE();
6195

96+
free(winbuf);
97+
sleep();
98+
}
99+
100+
101+
#endif
62102

63103
void EPaper::update(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t *data)
64104
{
@@ -77,7 +117,6 @@ void EPaper::update(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t *da
77117
pushImage(x, y, w, h / 2 , (uint16_t *)p);
78118
else
79119
pushImage(x, y, w, h , (uint16_t *)p);
80-
EPD_SET_WINDOW(x, y, (x + w - 1), (y + h - 1));
81120
#ifdef EPD_HORIZONTAL_MIRROR
82121
EPD_PUSH_NEW_COLORS_FLIP(w, h, p);
83122
#else

Extensions/EPaper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class EPaper : public TFT_eSprite
99
void drawBufferPixel(int32_t x, int32_t y, uint32_t color, uint8_t bpp);
1010
void update();
1111
void update(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t *data);
12-
12+
void updataPartial(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
1313

1414
#ifdef USE_MUTIGRAY_EPAPER
1515
void initGrayMode(uint8_t grayLevel);
@@ -24,6 +24,8 @@ class EPaper : public TFT_eSprite
2424
float getTemp();
2525
void setHumi(GetHumiCallback callback);
2626
float getHumi();
27+
28+
2729
private:
2830
uint8_t _grayLevel;
2931
bool _sleep;

TFT_Drivers/T133A01_Init.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
digitalWrite(TFT_ENABLE, HIGH);
77
#endif
88
pinMode(TFT_CS1, OUTPUT);
9-
digitalWrite(TFT_CS1, HIGH);
9+
digitalWrite(TFT_CS1, HIGH);
10+
digitalWrite(TFT_RST, LOW);
11+
delay(20);
12+
digitalWrite(TFT_RST, HIGH);
13+
delay(20);

TFT_Drivers/UC8179_Defines.h

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#define EPD_COLOR_DEPTH 1
1919

20+
#define USE_PARTIAL_EPAPER
2021
#define USE_MUTIGRAY_EPAPER
2122
#define GRAY_LEVEL4 4
2223

@@ -56,6 +57,7 @@
5657
do \
5758
{ \
5859
writecommand(0x12); \
60+
delay(1); \
5961
CHECK_BUSY(); \
6062
} while (0)
6163

@@ -162,15 +164,15 @@
162164
#define EPD_INIT_PARTIAL() \
163165
do \
164166
{ \
167+
writecommand(0x00); \
168+
writedata(0x1F); \
165169
writecommand(0x04); \
166170
delay(100); \
167171
CHECK_BUSY(); \
168172
writecommand(0xE0); \
169173
writedata(0x02); \
170174
writecommand(0xE5); \
171175
writedata(0x6E); \
172-
writecommand(0x00); \
173-
writedata(0x1F); \
174176
} while (0)
175177

176178
#define EPD_WAKEUP() \
@@ -186,11 +188,66 @@
186188

187189
#define EPD_WAKEUP_GRAY EPD_WAKEUP
188190

191+
#define EPD_WAKEUP_PARTIAL() \
192+
do \
193+
{ \
194+
digitalWrite(TFT_RST, LOW); \
195+
delay(10); \
196+
digitalWrite(TFT_RST, HIGH); \
197+
delay(10); \
198+
CHECK_BUSY(); \
199+
EPD_INIT_PARTIAL(); \
200+
} while (0);
201+
202+
189203
#define EPD_SET_WINDOW(x1, y1, x2, y2) \
190204
do \
191205
{ \
206+
writecommand(0x50); \
207+
writedata(0xA9); \
208+
writedata(0x07); \
209+
writecommand(0x91); \
210+
writecommand(0x90); \
211+
writedata (x1 >> 8); \
212+
writedata (x1& 0xFF); \
213+
writedata (x2 >> 8); \
214+
writedata ((x2& 0xFF)-1); \
215+
writedata (y1 >> 8); \
216+
writedata (y1& 0xFF); \
217+
writedata (y2 >> 8); \
218+
writedata ((y2& 0xFF)-1); \
219+
writedata (0x01); \
220+
} while (0)
221+
222+
#define EPD_PUSH_NEW_COLORS_PART(w, h, colors) \
223+
do \
224+
{ \
225+
writecommand(0x13); \
226+
for (int i = 0; i < w * h / 8; i++) \
227+
{ \
228+
writedata(colors[i]); \
229+
} \
192230
} while (0)
193231

232+
#define EPD_PUSH_NEW_COLORS_PART_FLIP(w, h, colors) \
233+
do \
234+
{ \
235+
writecommand(0x13); \
236+
uint16_t bytes_per_row = (w) / 8; \
237+
for (uint16_t row = 0; row < (h); row++) \
238+
{ \
239+
uint16_t start = row * bytes_per_row; \
240+
for (uint16_t col = 0; col < bytes_per_row; col++) \
241+
{ \
242+
uint8_t b = colors[start + (bytes_per_row - 1 - col)]; \
243+
b = ((b & 0xF0) >> 4) | ((b & 0x0F) << 4); \
244+
b = ((b & 0xCC) >> 2) | ((b & 0x33) << 2); \
245+
b = ((b & 0xAA) >> 1) | ((b & 0x55) << 1); \
246+
writedata(b); \
247+
} \
248+
} \
249+
} while (0)
250+
194251
#define EPD_PUSH_NEW_COLORS(w, h, colors) \
195252
do \
196253
{ \
@@ -215,7 +272,7 @@
215272
b = ((b & 0xF0) >> 4) | ((b & 0x0F) << 4); \
216273
b = ((b & 0xCC) >> 2) | ((b & 0x33) << 2); \
217274
b = ((b & 0xAA) >> 1) | ((b & 0x55) << 1); \
218-
writedata(b); \
275+
writedata(~b); \
219276
} \
220277
} \
221278
} while (0)
@@ -342,7 +399,7 @@
342399
writecommand(0x10); \
343400
for (int i = 0; i < w * h / 8; i++) \
344401
{ \
345-
writedata(~colors[i]); \
402+
writedata(colors[i]); \
346403
} \
347404
} while (0)
348405

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "TFT_eSPI.h"
2+
3+
#ifdef EPAPER_ENABLE // Only compile this code if the EPAPER_ENABLE is defined in User_Setup.h
4+
EPaper epaper;
5+
#endif
6+
7+
void setup()
8+
{
9+
#ifdef EPAPER_ENABLE
10+
epaper.begin();
11+
epaper.fillScreen(TFT_WHITE);
12+
13+
epaper.fillCircle(25, 25, 15, TFT_BLACK);
14+
epaper.fillRect(epaper.width() - 40, 10, 30, 30, TFT_BLACK);
15+
epaper.update();
16+
for (int i = 0; i < epaper.height() / 80; i++)
17+
{
18+
epaper.setTextSize(i + 1);
19+
epaper.drawString("Hello ePaper", 10, 80 + 60 * i);
20+
epaper.updataPartial(10, 80 + 60 * i,( i + 1 ) * 12 * 6, ( i + 1 ) * 8);
21+
}
22+
epaper.update(); // update the display
23+
24+
#endif
25+
}
26+
27+
void loop()
28+
{
29+
// put your main code here, to run repeatedly:
30+
}

0 commit comments

Comments
 (0)