@@ -40,7 +40,21 @@ void GigaDisplay_GFX::startWrite() {
4040
4141void 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
4660void 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
103117void 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
216232void 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
226244void 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}
0 commit comments