|
53 | 53 | uint8_t bb_fb_index; // Current frame buffer index which used by bounce buffer
|
54 | 54 | } rgb_panel_t;
|
55 | 55 |
|
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 |
| - } |
93 | 56 |
|
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) |
95 | 58 | {
|
96 | 59 | LCD_UNUSED(edata);
|
97 | 60 | LCD_UNUSED(panel);
|
98 | 61 |
|
99 | 62 | // rgb_panel_t *rgb_panel = __containerof(panel, rgb_panel_t, base);
|
100 | 63 |
|
101 | 64 | mp_lcd_rgb_bus_obj_t *self = (mp_lcd_rgb_bus_obj_t *)user_ctx;
|
102 |
| - bool ret = false; |
103 | 65 |
|
104 | 66 | 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(); |
106 | 97 | }
|
107 |
| - return ret; |
| 98 | + |
| 99 | + return false; |
108 | 100 | }
|
109 | 101 |
|
110 | 102 | esp_lcd_rgb_panel_event_callbacks_t callbacks = { .on_vsync = rgb_bus_trans_done_cb };
|
|
0 commit comments