Skip to content

Commit faade1b

Browse files
committed
fixes deadlock with RGBus
1 parent 971cba9 commit faade1b

File tree

2 files changed

+96
-16
lines changed

2 files changed

+96
-16
lines changed

ext_mod/lcd_bus/esp32_src/rgb_bus.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@
501501
self->y_end = y_end;
502502
self->rotation = rotation;
503503

504+
rgb_bus_event_set(&self->partial_copy);
504505
if (last_update) rgb_bus_event_set(&self->last_update);
505-
printf("rgb_tx_color\n");
506506
rgb_bus_lock_release(&self->copy_lock);
507507

508508
return LCD_OK;

ext_mod/lcd_bus/esp32_src/rgb_bus_rotation.c

Lines changed: 95 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,53 @@
2626

2727
void rgb_bus_event_init(rgb_bus_event_t *event)
2828
{
29+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
30+
printf("rgb_bus_event_init\n");
31+
#endif
2932
event->handle = xEventGroupCreateStatic(&event->buffer);
3033
}
3134

3235

3336
void rgb_bus_event_delete(rgb_bus_event_t *event)
3437
{
38+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
39+
printf("rgb_bus_event_delete\n");
40+
#endif
3541
xEventGroupSetBits(event->handle, RGB_BIT_0);
3642
vEventGroupDelete(event->handle);
43+
3744
}
3845

3946

4047
bool rgb_bus_event_isset(rgb_bus_event_t *event)
4148
{
42-
return (bool)(xEventGroupGetBits(event->handle) == RGB_BIT_0);
49+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
50+
printf("rgb_bus_event_isset\n");
51+
#endif
52+
return (bool)(xEventGroupGetBits(event->handle) & RGB_BIT_0);
4353
}
4454

4555

4656
bool rgb_bus_event_isset_from_isr(rgb_bus_event_t *event)
4757
{
48-
return (bool)(xEventGroupGetBitsFromISR(event->handle) == RGB_BIT_0);
58+
return (bool)(xEventGroupGetBitsFromISR(event->handle) & RGB_BIT_0);
4959
}
5060

5161

5262
void rgb_bus_event_set(rgb_bus_event_t *event)
5363
{
64+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
65+
printf("rgb_bus_event_set\n");
66+
#endif
5467
xEventGroupSetBits(event->handle, RGB_BIT_0);
5568
}
5669

5770

5871
void rgb_bus_event_clear(rgb_bus_event_t *event)
5972
{
73+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
74+
printf("rgb_bus_event_clear\n");
75+
#endif
6076
xEventGroupClearBits(event->handle, RGB_BIT_0);
6177
}
6278

@@ -73,12 +89,18 @@
7389

7490
int rgb_bus_lock_acquire(rgb_bus_lock_t *lock, int32_t wait_ms)
7591
{
92+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
93+
printf("rgb_bus_lock_acquire\n");
94+
#endif
7695
return pdTRUE == xSemaphoreTake(lock->handle, wait_ms < 0 ? portMAX_DELAY : pdMS_TO_TICKS((uint16_t)wait_ms));
7796
}
7897

7998

8099
void rgb_bus_lock_release(rgb_bus_lock_t *lock)
81100
{
101+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
102+
printf("rgb_bus_lock_release\n");
103+
#endif
82104
xSemaphoreGive(lock->handle);
83105
}
84106

@@ -91,13 +113,19 @@
91113

92114
void rgb_bus_lock_init(rgb_bus_lock_t *lock)
93115
{
116+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
117+
printf("rgb_bus_lock_init\n");
118+
#endif
94119
lock->handle = xSemaphoreCreateBinaryStatic(&lock->buffer);
95120
xSemaphoreGive(lock->handle);
96121
}
97122

98123

99124
void rgb_bus_lock_delete(rgb_bus_lock_t *lock)
100125
{
126+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
127+
printf("rgb_bus_lock_delete\n");
128+
#endif
101129
vSemaphoreDelete(lock->handle);
102130
}
103131

@@ -136,7 +164,9 @@
136164
}
137165

138166
void rgb_bus_copy_task(void *self_in) {
167+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
139168
printf("rgb_bus_copy_task - STARTED\n");
169+
#endif
140170

141171
mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)self_in;
142172

@@ -160,12 +190,19 @@
160190

161191
rgb_bus_lock_acquire(&self->copy_lock, -1);
162192

163-
while (!rgb_bus_event_isset(&self->copy_task_exit)) {
193+
bool exit = rgb_bus_event_isset(&self->copy_task_exit);
194+
195+
while (!exit) {
164196
rgb_bus_lock_acquire(&self->copy_lock, -1);
197+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
198+
printf("!rgb_bus_event_isset(&self->copy_task_exit)\n");
199+
#endif
165200

166201
if (rgb_bus_event_isset(&self->partial_copy)) {
167202
rgb_bus_event_clear(&self->partial_copy);
168-
printf("rgb_bus_copy_task - partial_copy\n");
203+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
204+
printf("rgb_bus_event_isset(&self->partial_copy)\n");
205+
#endif
169206

170207

171208
copy_pixels(
@@ -192,7 +229,17 @@
192229

193230
nlr_buf_t nlr;
194231
if (nlr_push(&nlr) == 0) {
232+
233+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
234+
printf("mp_call_function_n_kw(1)\n");
235+
#endif
236+
195237
mp_call_function_n_kw(self->callback, 0, 0, NULL);
238+
239+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
240+
printf("mp_call_function_n_kw(2)\n");
241+
#endif
242+
196243
nlr_pop();
197244
} else {
198245
ets_printf("Uncaught exception in IRQ callback handler!\n");
@@ -208,12 +255,14 @@
208255

209256
if (rgb_bus_event_isset(&self->last_update)) {
210257
rgb_bus_event_clear(&self->last_update);
211-
printf("rgb_bus_copy_task - last_update\n");
258+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
259+
printf("rgb_bus_event_isset(&self->last_update)\n");
260+
#endif
212261

213262
uint8_t *idle_fb = self->idle_fb;
214263
rgb_bus_event_set(&self->swap_bufs);
215264

216-
esp_lcd_panel_draw_bitmap(
265+
mp_lcd_err_t ret = esp_lcd_panel_draw_bitmap(
217266
self->panel_handle,
218267
0,
219268
0,
@@ -222,9 +271,15 @@
222271
idle_fb
223272
);
224273

225-
rgb_bus_lock_acquire(&self->swap_lock, -1);
226-
memcpy(self->idle_fb, self->active_fb, self->width * self->height * bytes_per_pixel);
274+
if (ret != 0) {
275+
printf("esp_lcd_panel_draw_bitmap error (%d)\n", ret);
276+
} else {
277+
rgb_bus_lock_acquire(&self->swap_lock, -1);
278+
memcpy(self->idle_fb, self->active_fb, self->width * self->height * bytes_per_pixel);
279+
}
227280
}
281+
282+
exit = rgb_bus_event_isset(&self->copy_task_exit);
228283
}
229284
}
230285

@@ -242,7 +297,10 @@
242297
copy_func_cb_t func,
243298
uint8_t rotate
244299
) {
245-
300+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
301+
printf("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",
302+
x_start, y_start, x_end, y_end, h_res, v_res, bytes_per_pixel, rotate);
303+
#endif
246304
if (rotate == RGB_BUS_ROTATION_90 || rotate == RGB_BUS_ROTATION_270) {
247305
x_start = MIN(x_start, v_res);
248306
x_end = MIN(x_end, v_res);
@@ -255,22 +313,38 @@
255313
y_end = MIN(y_end, v_res);
256314
}
257315

258-
uint16_t copy_bytes_per_line = (x_end - x_start) * (uint16_t)bytes_per_pixel;
316+
uint16_t copy_bytes_per_line = (x_end - x_start + 1) * (uint16_t)bytes_per_pixel;
259317
int pixels_per_line = h_res;
260318
uint32_t bytes_per_line = bytes_per_pixel * pixels_per_line;
261319
size_t offset = y_start * copy_bytes_per_line + x_start * bytes_per_pixel;
262320

321+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
322+
printf("x_start=%lu, y_start=%lu, x_end=%lu, y_end=%lu, copy_bytes_per_line=%hu, bytes_per_line=%lu, offset=%d\n",
323+
x_start, y_start, x_end, y_end, copy_bytes_per_line, bytes_per_line, offset);
324+
#endif
325+
263326
switch (rotate) {
264327
case RGB_BUS_ROTATION_0:
328+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
329+
printf("RGB_BUS_ROTATION_0\n");
330+
#endif
265331
uint8_t *fb = to + (y_start * h_res + x_start) * bytes_per_pixel;
266-
for (int y = y_start; y < y_end; y++) {
267-
memcpy(fb, from, copy_bytes_per_line);
268-
fb += bytes_per_line;
269-
from += copy_bytes_per_line;
332+
333+
if (x_start == 0 && x_end == (h_res - 1)) {
334+
memcpy(fb, from, bytes_per_line * (y_end - y_start + 1));
335+
} else {
336+
for (int y = y_start; y < y_end; y++) {
337+
memcpy(fb, from, bytes_per_line);
338+
fb += bytes_per_line;
339+
from += copy_bytes_per_line;
340+
}
270341
}
271-
break;
272342

343+
break;
273344
case RGB_BUS_ROTATION_180:
345+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
346+
printf("RGB_BUS_ROTATION_180\n");
347+
#endif
274348
uint32_t index;
275349
for (int y = y_start; y < y_end; y++) {
276350
index = ((v_res - 1 - y) * h_res + (h_res - 1 - x_start)) * bytes_per_pixel;
@@ -284,6 +358,9 @@
284358
break;
285359

286360
case RGB_BUS_ROTATION_90:
361+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
362+
printf("RGB_BUS_ROTATION_90\n");
363+
#endif
287364
uint32_t j;
288365
uint32_t i;
289366

@@ -297,6 +374,9 @@
297374
break;
298375

299376
case RGB_BUS_ROTATION_270:
377+
#if CONFIG_LCD_ENABLE_DEBUG_LOG
378+
printf("RGB_BUS_ROTATION_270\n");
379+
#endif
300380
uint32_t jj;
301381
uint32_t ii;
302382

0 commit comments

Comments
 (0)