Skip to content

Commit b46f799

Browse files
committed
Fixes RGB Driver
Fixes tearing Fixes triple image
1 parent c82302f commit b46f799

File tree

3 files changed

+19
-82
lines changed

3 files changed

+19
-82
lines changed

ext_mod/lcd_bus/esp32_include/rgb_bus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@
6767
uint16_t height;
6868
uint8_t rotation: 2;
6969
uint8_t bytes_per_pixel: 2;
70+
uint8_t last_update: 1;
7071

7172
rgb_bus_lock_t copy_lock;
7273
rgb_bus_event_t copy_task_exit;
73-
rgb_bus_event_t last_update;
7474
rgb_bus_lock_t tx_color_lock;
7575
rgb_bus_event_t swap_bufs;
7676
rgb_bus_lock_t swap_lock;

ext_mod/lcd_bus/esp32_src/rgb_bus.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@
279279

280280
if (self->view1 != NULL || self->view2 != NULL) {
281281
mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("Framebuffers have not been released"));
282-
return mp_const_none;
282+
return LCD_FAIL;
283283
}
284284

285285
rgb_bus_lock_acquire(&self->tx_color_lock, -1);
@@ -295,7 +295,6 @@
295295
rgb_bus_lock_delete(&self->swap_lock);
296296

297297
rgb_bus_event_delete(&self->swap_bufs);
298-
rgb_bus_event_delete(&self->last_update);
299298
rgb_bus_event_delete(&self->copy_task_exit);
300299

301300
return ret;
@@ -481,7 +480,6 @@
481480
rgb_bus_lock_init(&self->copy_lock);
482481
rgb_bus_lock_init(&self->tx_color_lock);
483482
rgb_bus_event_init(&self->copy_task_exit);
484-
rgb_bus_event_init(&self->last_update);
485483
rgb_bus_event_init(&self->swap_bufs);
486484
rgb_bus_lock_init(&self->swap_lock);
487485

@@ -517,14 +515,14 @@
517515

518516
rgb_bus_lock_acquire(&self->tx_color_lock, -1);
519517

518+
self->last_update = (uint8_t)last_update;
520519
self->partial_buf = (uint8_t *)color;
521520
self->x_start = x_start;
522521
self->y_start = y_start;
523522
self->x_end = x_end;
524523
self->y_end = y_end;
525524
self->rotation = rotation;
526525

527-
if (last_update) rgb_bus_event_set(&self->last_update);
528526
rgb_bus_lock_release(&self->copy_lock);
529527

530528
return LCD_OK;

ext_mod/lcd_bus/esp32_src/rgb_bus_rotation.c

Lines changed: 16 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,11 @@
2626

2727
void rgb_bus_event_init(rgb_bus_event_t *event)
2828
{
29-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
30-
mp_printf(&mp_plat_print, "rgb_bus_event_init\n");
31-
#endif
3229
event->handle = xEventGroupCreateStatic(&event->buffer);
3330
}
3431

3532
void rgb_bus_event_delete(rgb_bus_event_t *event)
3633
{
37-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
38-
mp_printf(&mp_plat_print, "rgb_bus_event_delete\n");
39-
#endif
4034
xEventGroupSetBits(event->handle, RGB_BIT_0);
4135
vEventGroupDelete(event->handle);
4236

@@ -45,9 +39,6 @@
4539

4640
bool rgb_bus_event_isset(rgb_bus_event_t *event)
4741
{
48-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
49-
mp_printf(&mp_plat_print, "rgb_bus_event_isset\n");
50-
#endif
5142
return (bool)(xEventGroupGetBits(event->handle) & RGB_BIT_0);
5243
}
5344

@@ -60,18 +51,12 @@
6051

6152
void rgb_bus_event_set(rgb_bus_event_t *event)
6253
{
63-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
64-
mp_printf(&mp_plat_print, "rgb_bus_event_set\n");
65-
#endif
6654
xEventGroupSetBits(event->handle, RGB_BIT_0);
6755
}
6856

6957

7058
void rgb_bus_event_clear(rgb_bus_event_t *event)
7159
{
72-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
73-
mp_printf(&mp_plat_print, "rgb_bus_event_clear\n");
74-
#endif
7560
xEventGroupClearBits(event->handle, RGB_BIT_0);
7661
}
7762

@@ -88,18 +73,12 @@
8873

8974
int rgb_bus_lock_acquire(rgb_bus_lock_t *lock, int32_t wait_ms)
9075
{
91-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
92-
mp_printf(&mp_plat_print, "rgb_bus_lock_acquire\n");
93-
#endif
9476
return pdTRUE == xSemaphoreTake(lock->handle, wait_ms < 0 ? portMAX_DELAY : pdMS_TO_TICKS((uint16_t)wait_ms));
9577
}
9678

9779

9880
void rgb_bus_lock_release(rgb_bus_lock_t *lock)
9981
{
100-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
101-
mp_printf(&mp_plat_print, "rgb_bus_lock_release\n");
102-
#endif
10382
xSemaphoreGive(lock->handle);
10483
}
10584

@@ -112,19 +91,13 @@
11291

11392
void rgb_bus_lock_init(rgb_bus_lock_t *lock)
11493
{
115-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
116-
mp_printf(&mp_plat_print, "rgb_bus_lock_init\n");
117-
#endif
11894
lock->handle = xSemaphoreCreateBinaryStatic(&lock->buffer);
11995
xSemaphoreGive(lock->handle);
12096
}
12197

12298

12399
void rgb_bus_lock_delete(rgb_bus_lock_t *lock)
124100
{
125-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
126-
mp_printf(&mp_plat_print, "rgb_bus_lock_delete\n");
127-
#endif
128101
vSemaphoreDelete(lock->handle);
129102
}
130103

@@ -169,6 +142,7 @@
169142

170143
mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)self_in;
171144

145+
uint8_t *idle_fb;
172146
copy_func_cb_t func;
173147
uint8_t bytes_per_pixel = self->bytes_per_pixel;
174148

@@ -198,14 +172,13 @@
198172

199173
while (!exit) {
200174
rgb_bus_lock_acquire(&self->copy_lock, -1);
201-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
202-
mp_printf(&mp_plat_print, "!rgb_bus_event_isset(&self->copy_task_exit)\n");
203-
#endif
204175

205176
if (self->partial_buf == NULL) break;
206177

178+
idle_fb = self->idle_fb;
179+
207180
copy_pixels(
208-
self->idle_fb, self->partial_buf,
181+
idle_fb, self->partial_buf,
209182
self->x_start, self->y_start,
210183
self->x_end, self->y_end,
211184
self->width, self->height,
@@ -241,19 +214,12 @@
241214
mp_thread_set_state(old_state);
242215
}
243216

244-
if (rgb_bus_event_isset(&self->last_update)) {
245-
rgb_bus_event_clear(&self->last_update);
217+
if (self->last_update) {
246218
// the reason why this locked is released this way is to ensure that the partial
247219
// buffer has been copied correctly before another one gets into the queue
248220
// it is places here after the partial check to ensure the setting of the partial doesn't overlap
249221
// with the wrong partial buffer
250222
rgb_bus_lock_release(&self->tx_color_lock);
251-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
252-
mp_printf(&mp_plat_print, "rgb_bus_event_isset(&self->last_update)\n");
253-
#endif
254-
255-
uint8_t *idle_fb = self->idle_fb;
256-
rgb_bus_event_set(&self->swap_bufs);
257223

258224
mp_lcd_err_t ret = esp_lcd_panel_draw_bitmap(
259225
self->panel_handle,
@@ -267,8 +233,9 @@
267233
if (ret != 0) {
268234
mp_printf(&mp_plat_print, "esp_lcd_panel_draw_bitmap error (%d)\n", ret);
269235
} else {
236+
rgb_bus_event_set(&self->swap_bufs);
270237
rgb_bus_lock_acquire(&self->swap_lock, -1);
271-
memcpy(self->idle_fb, self->active_fb, self->width * self->height * bytes_per_pixel);
238+
memcpy( self->active_fb, self->idle_fb, self->width * self->height * bytes_per_pixel);
272239
}
273240
} else {
274241
rgb_bus_lock_release(&self->tx_color_lock);
@@ -283,23 +250,10 @@
283250
}
284251

285252

286-
void copy_pixels(
287-
uint8_t *to,
288-
uint8_t *from,
289-
uint32_t x_start,
290-
uint32_t y_start,
291-
uint32_t x_end,
292-
uint32_t y_end,
293-
uint32_t h_res,
294-
uint32_t v_res,
295-
uint32_t bytes_per_pixel,
296-
copy_func_cb_t func,
297-
uint8_t rotate
298-
) {
299-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
300-
mp_printf(&mp_plat_print, "copy_pixels(to, from, x_start=%lu, y_start=%lu, x_end=%lu, y_end=%lu, h_res=%lu, v_res=%lu, bytes_per_pixel=%lu, func, rotate=%u)\n",
301-
x_start, y_start, x_end, y_end, h_res, v_res, bytes_per_pixel, rotate);
302-
#endif
253+
void copy_pixels(uint8_t *to, uint8_t *from, uint32_t x_start, uint32_t y_start,
254+
uint32_t x_end, uint32_t y_end, uint32_t h_res, uint32_t v_res,
255+
uint32_t bytes_per_pixel, copy_func_cb_t func, uint8_t rotate)
256+
{
303257
if (rotate == RGB_BUS_ROTATION_90 || rotate == RGB_BUS_ROTATION_270) {
304258
x_start = MIN(x_start, v_res);
305259
x_end = MIN(x_end, v_res);
@@ -317,33 +271,26 @@
317271
uint32_t bytes_per_line = bytes_per_pixel * pixels_per_line;
318272
size_t offset = y_start * copy_bytes_per_line + x_start * bytes_per_pixel;
319273

320-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
321-
mp_printf(&mp_plat_print, "x_start=%lu, y_start=%lu, x_end=%lu, y_end=%lu, copy_bytes_per_line=%hu, bytes_per_line=%lu, offset=%d\n",
322-
x_start, y_start, x_end, y_end, copy_bytes_per_line, bytes_per_line, offset);
323-
#endif
274+
// mp_printf(&mp_plat_print, "x_start=%lu, y_start=%lu, x_end=%lu, y_end=%lu, copy_bytes_per_line=%u, bytes_per_line=%lu, %lu\n",
275+
// x_start, y_start, x_end, y_end, copy_bytes_per_line, bytes_per_line, (uint32_t)((y_start * h_res + x_start) * bytes_per_pixel));
324276

325277
switch (rotate) {
326278
case RGB_BUS_ROTATION_0:
327-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
328-
mp_printf(&mp_plat_print, "RGB_BUS_ROTATION_0\n");
329-
#endif
330-
uint8_t *fb = to + (y_start * h_res + x_start) * bytes_per_pixel;
279+
uint8_t *fb = to + ((y_start * h_res + x_start) * bytes_per_pixel);
331280

332281
if (x_start == 0 && x_end == (h_res - 1)) {
333282
memcpy(fb, from, bytes_per_line * (y_end - y_start + 1));
334283
} else {
335284
for (int y = y_start; y < y_end; y++) {
336-
memcpy(fb, from, bytes_per_line);
285+
memcpy(fb, from, copy_bytes_per_line);
337286
fb += bytes_per_line;
338287
from += copy_bytes_per_line;
339288
}
340289
}
341290

342291
break;
292+
343293
case RGB_BUS_ROTATION_180:
344-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
345-
mp_printf(&mp_plat_print, "RGB_BUS_ROTATION_180\n");
346-
#endif
347294
uint32_t index;
348295
for (int y = y_start; y < y_end; y++) {
349296
index = ((v_res - 1 - y) * h_res + (h_res - 1 - x_start)) * bytes_per_pixel;
@@ -356,9 +303,6 @@
356303
break;
357304

358305
case RGB_BUS_ROTATION_90:
359-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
360-
mp_printf(&mp_plat_print, "RGB_BUS_ROTATION_90\n");
361-
#endif
362306
uint32_t j;
363307
uint32_t i;
364308

@@ -371,12 +315,7 @@
371315
}
372316
break;
373317

374-
375-
376318
case RGB_BUS_ROTATION_270:
377-
#if CONFIG_LCD_ENABLE_DEBUG_LOG
378-
mp_printf(&mp_plat_print, "RGB_BUS_ROTATION_270\n");
379-
#endif
380319
uint32_t jj;
381320
uint32_t ii;
382321

0 commit comments

Comments
 (0)