Skip to content

Commit db32965

Browse files
committed
update to RGB Bus
1 parent 6fffcda commit db32965

File tree

2 files changed

+33
-42
lines changed

2 files changed

+33
-42
lines changed

builder/esp32.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,6 @@ def compile(): # NOQA
751751
elif flash_mode == 'STR':
752752
base_config.append('CONFIG_ESPTOOLPY_FLASH_SAMPLE_MODE_STR=y')
753753
else:
754-
755754
base_config.append(f'CONFIG_ESPTOOLPY_FLASHMODE_{flash_mode}=y')
756755

757756
if onboard_mem_speed is not None:

ext_mod/lcd_bus/esp32_src/rgb_bus.c

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,58 +53,50 @@
5353
uint8_t bb_fb_index; // Current frame buffer index which used by bounce buffer
5454
} rgb_panel_t;
5555

56-
bool callback_from_isr(mp_obj_t cb)
57-
{
58-
volatile uint32_t sp = (uint32_t)esp_cpu_get_sp();
59-
bool ret = false;
60-
61-
// Calling micropython from ISR
62-
// See: https://github.com/micropython/micropython/issues/4895
63-
void *old_state = mp_thread_get_state();
64-
65-
mp_state_thread_t ts; // local thread state for the ISR
66-
mp_thread_set_state(&ts);
67-
mp_stack_set_top((void*)sp); // need to include in root-pointer scan
68-
mp_stack_set_limit(CONFIG_FREERTOS_IDLE_TASK_STACKSIZE - 1024); // tune based on ISR thread stack size
69-
mp_locals_set(mp_state_ctx.thread.dict_locals); // use main thread's locals
70-
mp_globals_set(mp_state_ctx.thread.dict_globals); // use main thread's globals
71-
72-
mp_sched_lock(); // prevent VM from switching to another MicroPython thread
73-
gc_lock(); // prevent memory allocation
74-
75-
nlr_buf_t nlr;
76-
if (nlr_push(&nlr) == 0) {
77-
mp_call_function_n_kw(cb,0, 0, NULL);
78-
ret = true;
79-
nlr_pop();
80-
} else {
81-
ets_printf("Uncaught exception in IRQ callback handler!\n");
82-
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val)); // changed to &mp_plat_print to fit this context
83-
}
84-
85-
gc_unlock();
86-
mp_sched_unlock();
87-
88-
mp_thread_set_state(old_state);
89-
mp_hal_wake_main_task_from_isr();
90-
91-
return ret;
92-
}
9356

94-
IRAM_ATTR static bool rgb_bus_trans_done_cb(esp_lcd_panel_handle_t panel, const esp_lcd_rgb_panel_event_data_t *edata, void *user_ctx)
57+
static bool rgb_bus_trans_done_cb(esp_lcd_panel_handle_t panel, const esp_lcd_rgb_panel_event_data_t *edata, void *user_ctx)
9558
{
9659
LCD_UNUSED(edata);
9760
LCD_UNUSED(panel);
9861

9962
// rgb_panel_t *rgb_panel = __containerof(panel, rgb_panel_t, base);
10063

10164
mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)user_ctx;
102-
bool ret = false;
10365

10466
if (self->callback != mp_const_none && mp_obj_is_callable(self->callback)) {
105-
ret = callback_from_isr(self->callback);
67+
volatile uint32_t sp = (uint32_t)esp_cpu_get_sp();
68+
69+
// Calling micropython from ISR
70+
// See: https://github.com/micropython/micropython/issues/4895
71+
void *old_state = mp_thread_get_state();
72+
73+
mp_state_thread_t ts; // local thread state for the ISR
74+
mp_thread_set_state(&ts);
75+
mp_stack_set_top((void*)sp); // need to include in root-pointer scan
76+
mp_stack_set_limit(CONFIG_FREERTOS_IDLE_TASK_STACKSIZE - 1024); // tune based on ISR thread stack size
77+
mp_locals_set(mp_state_ctx.thread.dict_locals); // use main thread's locals
78+
mp_globals_set(mp_state_ctx.thread.dict_globals); // use main thread's globals
79+
80+
mp_sched_lock(); // prevent VM from switching to another MicroPython thread
81+
gc_lock(); // prevent memory allocation
82+
83+
nlr_buf_t nlr;
84+
if (nlr_push(&nlr) == 0) {
85+
mp_call_function_n_kw(cb,0, 0, NULL);
86+
nlr_pop();
87+
} else {
88+
ets_printf("Uncaught exception in IRQ callback handler!\n");
89+
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val)); // changed to &mp_plat_print to fit this context
90+
}
91+
92+
gc_unlock();
93+
mp_sched_unlock();
94+
95+
mp_thread_set_state(old_state);
96+
mp_hal_wake_main_task_from_isr();
10697
}
107-
return ret;
98+
99+
return false;
108100
}
109101

110102
esp_lcd_rgb_panel_event_callbacks_t callbacks = { .on_vsync = rgb_bus_trans_done_cb };

0 commit comments

Comments
 (0)