diff --git a/src/omv/common/usbdbg.c b/src/omv/common/usbdbg.c index e03791293..f063d77ae 100644 --- a/src/omv/common/usbdbg.c +++ b/src/omv/common/usbdbg.c @@ -16,7 +16,6 @@ #include "py/obj.h" #include "py/objstr.h" #include "py/runtime.h" -#include "pendsv.h" #include "imlib.h" #if MICROPY_PY_SENSOR @@ -111,18 +110,17 @@ static void usbdbg_interrupt_vm(bool ready) { // Disable IDE IRQ (re-enabled by pyexec or main). usbdbg_set_irq_enabled(false); - // Clear interrupt traceback - mp_obj_exception_clear_traceback(&ide_exception); - #if (__ARM_ARCH >= 7) // Remove the BASEPRI masking (if any) __set_BASEPRI(0); #endif - // Interrupt running REPL - // Note: setting pendsv explicitly here because the VM is probably - // waiting in REPL and the soft interrupt flag will not be checked. - pendsv_nlr_jump(&ide_exception); + // Clear interrupt traceback + mp_obj_exception_clear_traceback(&ide_exception); + mp_sched_exception(&ide_exception); + + // Abort the VM. + mp_sched_vm_abort(); } bool usbdbg_get_irq_enabled() { diff --git a/src/omv/modules/py_display_data.c b/src/omv/modules/py_display_data.c index abd42aa3f..4020ffb11 100644 --- a/src/omv/modules/py_display_data.c +++ b/src/omv/modules/py_display_data.c @@ -189,8 +189,7 @@ mp_obj_t py_display_data_make_new(const mp_obj_type_t *type, size_t n_args, size mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - py_display_data_obj_t *self = m_new_obj_with_finaliser(py_display_data_obj_t); - self->base.type = &py_display_data_type; + py_display_data_obj_t *self = mp_obj_malloc_with_finaliser(py_display_data_obj_t, &py_display_data_type); #if OMV_DISPLAY_CEC_ENABLE self->cec_enabled = args[ARG_cec].u_bool; diff --git a/src/omv/modules/py_ft5x06.c b/src/omv/modules/py_ft5x06.c index fed3ddeab..40634e29f 100644 --- a/src/omv/modules/py_ft5x06.c +++ b/src/omv/modules/py_ft5x06.c @@ -219,8 +219,7 @@ mp_obj_t py_ft5x06_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_k mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - py_ft5x06_obj_t *self = m_new_obj_with_finaliser(py_ft5x06_obj_t); - self->base.type = &py_ft5x06_type; + py_ft5x06_obj_t *self = mp_obj_malloc_with_finaliser(py_ft5x06_obj_t, &py_ft5x06_type); self->i2c_addr = args[ARG_i2c_addr].u_int; self->i2c_bus = MP_OBJ_TYPE_GET_SLOT( &mp_machine_soft_i2c_type, make_new) (&mp_machine_soft_i2c_type, 2, 0, (const mp_obj_t []) { diff --git a/src/omv/modules/py_gif.c b/src/omv/modules/py_gif.c index 18cd3b4ff..4a6179528 100644 --- a/src/omv/modules/py_gif.c +++ b/src/omv/modules/py_gif.c @@ -114,8 +114,7 @@ static mp_obj_t py_gif_open(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - py_gif_obj_t *gif = m_new_obj_with_finaliser(py_gif_obj_t); - gif->base.type = &py_gif_type; + py_gif_obj_t *gif = mp_obj_malloc_with_finaliser(py_gif_obj_t, &py_gif_type); gif->width = (args[ARG_width].u_int == -1) ? framebuffer_get_width() : args[ARG_width].u_int; gif->height = (args[ARG_height].u_int == -1) ? framebuffer_get_height() : args[ARG_height].u_int; gif->color = (args[ARG_color].u_int == -1) ? (framebuffer_get_depth() >= 2) : args[ARG_color].u_bool; diff --git a/src/omv/modules/py_imageio.c b/src/omv/modules/py_imageio.c index 9a5ff6777..8e311414f 100644 --- a/src/omv/modules/py_imageio.c +++ b/src/omv/modules/py_imageio.c @@ -476,8 +476,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(py_imageio_close_obj, py_imageio_close); static mp_obj_t py_imageio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 2, 2, false); - py_imageio_obj_t *stream = m_new_obj_with_finaliser(py_imageio_obj_t); - stream->base.type = &py_imageio_type; + py_imageio_obj_t *stream = mp_obj_malloc_with_finaliser(py_imageio_obj_t, &py_imageio_type); stream->closed = false; if (0) { diff --git a/src/omv/modules/py_mjpeg.c b/src/omv/modules/py_mjpeg.c index 1d453057b..46e8a4460 100644 --- a/src/omv/modules/py_mjpeg.c +++ b/src/omv/modules/py_mjpeg.c @@ -173,9 +173,12 @@ static mp_obj_t py_mjpeg_open(uint n_args, const mp_obj_t *pos_args, mp_map_t *k mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - py_mjpeg_obj_t *mjpeg = m_new_obj_with_finaliser(py_mjpeg_obj_t); - memset(mjpeg, 0, sizeof(py_mjpeg_obj_t)); - mjpeg->base.type = &py_mjpeg_type; + py_mjpeg_obj_t *mjpeg = mp_obj_malloc_with_finaliser(py_mjpeg_obj_t, &py_mjpeg_type); + mjpeg->frames = 0; + mjpeg->bytes = 0; + mjpeg->us_old = 0; + mjpeg->us_avg = 0; + mjpeg->closed = 0; mjpeg->width = (args[ARG_width].u_int == -1) ? framebuffer_get_width() : args[ARG_width].u_int; mjpeg->height = (args[ARG_height].u_int == -1) ? framebuffer_get_height() : args[ARG_height].u_int; diff --git a/src/omv/modules/py_ml.c b/src/omv/modules/py_ml.c index f9cefd698..c0bf49c81 100644 --- a/src/omv/modules/py_ml.c +++ b/src/omv/modules/py_ml.c @@ -399,8 +399,7 @@ mp_obj_t py_ml_model_make_new(const mp_obj_type_t *type, size_t n_args, size_t n const char *path = mp_obj_str_get_str(args[ARG_path].u_obj); - py_ml_model_obj_t *model = m_new_obj_with_finaliser(py_ml_model_obj_t); - model->base.type = &py_ml_model_type; + py_ml_model_obj_t *model = mp_obj_malloc_with_finaliser(py_ml_model_obj_t, &py_ml_model_type); model->data = NULL; model->fb_alloc = args[ARG_load_to_fb].u_int; mp_obj_list_t *labels = NULL; diff --git a/src/omv/modules/py_spi_display.c b/src/omv/modules/py_spi_display.c index 17bcc83a4..3646d5db6 100644 --- a/src/omv/modules/py_spi_display.c +++ b/src/omv/modules/py_spi_display.c @@ -342,8 +342,7 @@ mp_obj_t spi_display_make_new(const mp_obj_type_t *type, size_t n_args, size_t n mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid Refresh Rate!")); } - py_display_obj_t *self = m_new_obj_with_finaliser(py_display_obj_t); - self->base.type = &py_spi_display_type; + py_display_obj_t *self = mp_obj_malloc_with_finaliser(py_display_obj_t, &py_spi_display_type); self->framebuffer_tail = 0; self->framebuffer_head = 0; self->width = args[ARG_width].u_int; diff --git a/src/omv/modules/py_tfp410.c b/src/omv/modules/py_tfp410.c index 24ce2dcc9..b55ba797e 100644 --- a/src/omv/modules/py_tfp410.c +++ b/src/omv/modules/py_tfp410.c @@ -99,8 +99,7 @@ mp_obj_t py_tfp410_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_k mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - py_tfp410_obj_t *self = m_new_obj_with_finaliser(py_tfp410_obj_t); - self->base.type = &py_tfp410_type; + py_tfp410_obj_t *self = mp_obj_malloc_with_finaliser(py_tfp410_obj_t, &py_tfp410_type); self->hotplug_callback = mp_const_none; self->i2c_addr = args[ARG_i2c_addr].u_int; self->i2c_bus = MP_OBJ_TYPE_GET_SLOT( diff --git a/src/omv/ports/stm32/modules/py_display.c b/src/omv/ports/stm32/modules/py_display.c index 963ad4cfc..888e3ba0f 100644 --- a/src/omv/ports/stm32/modules/py_display.c +++ b/src/omv/ports/stm32/modules/py_display.c @@ -577,11 +577,11 @@ mp_obj_t display_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, mp_raise_msg(&mp_type_ValueError, MP_ERROR_TEXT("Invalid Refresh Rate!")); } - py_display_obj_t *self = (py_display_obj_t *) m_new_obj_with_finaliser(py_display_obj_t); + py_display_obj_t *self; #ifdef OMV_DSI_DISPLAY_CONTROLLER - self->base.type = &py_dsi_display_type; + self = mp_obj_malloc_with_finaliser(py_display_obj_t, &py_dsi_display_type); #else - self->base.type = &py_rgb_display_type; + self = mp_obj_malloc_with_finaliser(py_display_obj_t, &py_rgb_display_type); #endif self->vcid = args[ARG_channel].u_int; self->refresh = args[ARG_refresh].u_int;