Skip to content

Commit 8656fc1

Browse files
committed
messing with RGB driver
1 parent ddf53d7 commit 8656fc1

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

ext_mod/lcd_bus/esp32_src/rgb_bus.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,9 @@
491491
printf("rgb_tx_color(self, lcd_cmd=%d, color, color_size=%d, x_start=%d, y_start=%d, x_end=%d, y_end=%d)\n", lcd_cmd, color_size, x_start, y_start, x_end, y_end);
492492
#endif
493493

494-
mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)obj;
494+
LCD_UNUSED(color_size);
495495

496+
mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)obj;
496497
self->partial_buf = (uint8_t *)color;
497498
self->x_start = x_start;
498499
self->y_start = y_start;
@@ -501,7 +502,7 @@
501502
self->rotation = rotation;
502503

503504
if (last_update) rgb_bus_event_set(&self->last_update);
504-
505+
printf("rgb_tx_color\n");
505506
rgb_bus_lock_release(&self->copy_lock);
506507

507508
return LCD_OK;

ext_mod/lcd_bus/esp32_src/rgb_bus_rotation.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#include "freertos/semphr.h"
1212
#include "freertos/event_groups.h"
1313
#include "freertos/idf_additions.h"
14+
#include "rom/ets_sys.h"
15+
#include "esp_system.h"
16+
#include "esp_cpu.h"
1417

1518
#include "esp_lcd_panel_ops.h"
1619

@@ -133,6 +136,8 @@
133136
}
134137

135138
void rgb_bus_copy_task(void *self_in) {
139+
printf("rgb_bus_copy_task - STARTED\n");
140+
136141
mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)self_in;
137142

138143
copy_func_cb_t func;
@@ -160,6 +165,8 @@
160165

161166
if (rgb_bus_event_isset(&self->partial_copy)) {
162167
rgb_bus_event_clear(&self->partial_copy);
168+
printf("rgb_bus_copy_task - partial_copy\n");
169+
163170

164171
copy_pixels(
165172
self->idle_fb, self->partial_buf,
@@ -168,11 +175,40 @@
168175
self->width, self->height,
169176
bytes_per_pixel, func, self->rotation);
170177

171-
if (self->callback != mp_const_none) mp_sched_schedule(self->callback, MP_OBJ_FROM_PTR(self));
172-
}
178+
if (self->callback != mp_const_none) {
179+
volatile uint32_t sp = (uint32_t)esp_cpu_get_sp();
180+
181+
void *old_state = mp_thread_get_state();
182+
183+
mp_state_thread_t ts;
184+
mp_thread_set_state(&ts);
185+
mp_stack_set_top((void*)sp);
186+
mp_stack_set_limit(CONFIG_FREERTOS_IDLE_TASK_STACKSIZE - 1024);
187+
mp_locals_set(mp_state_ctx.thread.dict_locals);
188+
mp_globals_set(mp_state_ctx.thread.dict_globals);
189+
190+
mp_sched_lock();
191+
gc_lock();
192+
193+
nlr_buf_t nlr;
194+
if (nlr_push(&nlr) == 0) {
195+
mp_call_function_n_kw(self->callback, 0, 0, NULL);
196+
nlr_pop();
197+
} else {
198+
ets_printf("Uncaught exception in IRQ callback handler!\n");
199+
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
200+
}
201+
202+
gc_unlock();
203+
mp_sched_unlock();
204+
205+
mp_thread_set_state(old_state);
206+
}
173207

174208
if (rgb_bus_event_isset(&self->last_update)) {
175209
rgb_bus_event_clear(&self->last_update);
210+
printf("rgb_bus_copy_task - last_update\n");
211+
176212
uint8_t *idle_fb = self->idle_fb;
177213
rgb_bus_event_set(&self->swap_bufs);
178214

0 commit comments

Comments
 (0)