|
27 | 27 | #include "py/obj.h" |
28 | 28 | #include "py/runtime.h" |
29 | 29 |
|
| 30 | +#include "bindings/espidf/__init__.h" |
| 31 | + |
30 | 32 | #include "esp-idf/components/heap/include/esp_heap_caps.h" |
31 | 33 |
|
32 | 34 | //| """Direct access to a few ESP-IDF details. This module *should not* include any functionality |
@@ -63,12 +65,41 @@ STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) { |
63 | 65 | } |
64 | 66 | MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_heap_caps_get_largest_free_block); |
65 | 67 |
|
| 68 | +//| class MemoryError(MemoryError): |
| 69 | +//| """Raised when an ESP IDF memory allocation fails.""" |
| 70 | +//| ... |
| 71 | +//| |
| 72 | +NORETURN void mp_raise_espidf_MemoryError(void) { |
| 73 | + nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError)); |
| 74 | +} |
| 75 | + |
| 76 | +void espidf_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { |
| 77 | + mp_print_kind_t k = kind & ~PRINT_EXC_SUBCLASS; |
| 78 | + bool is_subclass = kind & PRINT_EXC_SUBCLASS; |
| 79 | + if (!is_subclass && (k == PRINT_EXC)) { |
| 80 | + mp_print_str(print, qstr_str(MP_OBJ_QSTR_VALUE(MP_QSTR_espidf))); |
| 81 | + mp_print_str(print, "."); |
| 82 | + } |
| 83 | + mp_obj_exception_print(print, o_in, kind); |
| 84 | +} |
| 85 | + |
| 86 | +const mp_obj_type_t mp_type_espidf_MemoryError = { |
| 87 | + { &mp_type_type }, |
| 88 | + .name = MP_QSTR_MemoryError, |
| 89 | + .print = espidf_exception_print, |
| 90 | + .make_new = mp_obj_exception_make_new, |
| 91 | + .attr = mp_obj_exception_attr, |
| 92 | + .parent = &mp_type_MemoryError, |
| 93 | +}; |
| 94 | + |
66 | 95 | STATIC const mp_rom_map_elem_t espidf_module_globals_table[] = { |
67 | 96 | { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_espidf) }, |
68 | 97 |
|
69 | 98 | { MP_ROM_QSTR(MP_QSTR_heap_caps_get_total_size), MP_ROM_PTR(&espidf_heap_caps_get_total_size_obj)}, |
70 | 99 | { MP_ROM_QSTR(MP_QSTR_heap_caps_get_free_size), MP_ROM_PTR(&espidf_heap_caps_get_free_size_obj)}, |
71 | 100 | { MP_ROM_QSTR(MP_QSTR_heap_caps_get_largest_free_block), MP_ROM_PTR(&espidf_heap_caps_get_largest_free_block_obj)}, |
| 101 | + |
| 102 | + { MP_ROM_QSTR(MP_QSTR_MemoryError), MP_ROM_PTR(&mp_type_espidf_MemoryError) }, |
72 | 103 | }; |
73 | 104 |
|
74 | 105 | STATIC MP_DEFINE_CONST_DICT(espidf_module_globals, espidf_module_globals_table); |
|
0 commit comments