Skip to content

Commit a765a82

Browse files
authored
Merge pull request #7 from gilesp1729/master
Allow caller to control when screen is updated
2 parents a9392d7 + f37a8f2 commit a765a82

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/Arduino_GigaDisplay_GFX.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,21 @@ void GigaDisplay_GFX::startWrite() {
4040

4141
void GigaDisplay_GFX::endWrite() {
4242
//refresh_sem.release();
43-
_refresh_thd->flags_set(0x1);
43+
if (!buffering)
44+
_refresh_thd->flags_set(0x1);
45+
}
46+
47+
// If buffering, defer endWrite calls until endBuffering is called.
48+
void GigaDisplay_GFX::startBuffering() {
49+
buffering = true;
50+
}
51+
52+
void GigaDisplay_GFX::endBuffering() {
53+
if (buffering)
54+
{
55+
buffering = false;
56+
endWrite();
57+
}
4458
}
4559

4660
void GigaDisplay_GFX::drawPixel(int16_t x, int16_t y, uint16_t color) {
@@ -102,6 +116,7 @@ uint16_t GigaDisplay_GFX::getRawPixel(int16_t x, int16_t y) {
102116

103117
void GigaDisplay_GFX::fillScreen(uint16_t color) {
104118
if (hasBuffer()) {
119+
startWrite(); // PR #3
105120
uint8_t hi = color >> 8, lo = color & 0xFF;
106121
if (hi == lo) {
107122
memset(buffer, lo, WIDTH * HEIGHT * 2);
@@ -110,6 +125,7 @@ void GigaDisplay_GFX::fillScreen(uint16_t color) {
110125
for (i = 0; i < pixels; i++)
111126
buffer[i] = color;
112127
}
128+
endWrite(); // PR #3
113129
}
114130
}
115131

@@ -215,19 +231,23 @@ void GigaDisplay_GFX::drawFastHLine(int16_t x, int16_t y, int16_t w,
215231

216232
void GigaDisplay_GFX::drawFastRawVLine(int16_t x, int16_t y, int16_t h,
217233
uint16_t color) {
234+
startWrite();
218235
// x & y already in raw (rotation 0) coordinates, no need to transform.
219236
uint16_t *buffer_ptr = buffer + y * WIDTH + x;
220237
for (int16_t i = 0; i < h; i++) {
221238
(*buffer_ptr) = color;
222239
buffer_ptr += WIDTH;
223240
}
241+
endWrite();
224242
}
225243

226244
void GigaDisplay_GFX::drawFastRawHLine(int16_t x, int16_t y, int16_t w,
227245
uint16_t color) {
246+
startWrite();
228247
// x & y already in raw (rotation 0) coordinates, no need to transform.
229248
uint32_t buffer_index = y * WIDTH + x;
230249
for (uint32_t i = buffer_index; i < buffer_index + w; i++) {
231250
buffer[i] = color;
232251
}
252+
endWrite();
233253
}

src/Arduino_GigaDisplay_GFX.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class GigaDisplay_GFX : public Adafruit_GFX {
3131

3232
void startWrite();
3333
void endWrite();
34+
void startBuffering();
35+
void endBuffering();
3436

3537
uint16_t color565(uint8_t red, uint8_t green, uint8_t blue) {
3638
return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
@@ -45,7 +47,8 @@ class GigaDisplay_GFX : public Adafruit_GFX {
4547
private:
4648
Arduino_H7_Video* display;
4749
void refresh_if_needed();
48-
bool need_refresh = false;
50+
//bool need_refresh = false;
51+
bool buffering = false;
4952
uint32_t last_refresh = 0;
5053
rtos::Thread* _refresh_thd;
5154
};

0 commit comments

Comments
 (0)