Skip to content

Commit 05ba143

Browse files
committed
esp32s2: espidf: Add IDFError
this is an exception class for "generic" IDF errors that don't have their own exception type.
1 parent d024df6 commit 05ba143

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

ports/esp32s2/bindings/espidf/__init__.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ STATIC mp_obj_t espidf_heap_caps_get_largest_free_block(void) {
6565
}
6666
MP_DEFINE_CONST_FUN_OBJ_0(espidf_heap_caps_get_largest_free_block_obj, espidf_heap_caps_get_largest_free_block);
6767

68-
//| class MemoryError(MemoryError):
69-
//| """Raised when an ESP IDF memory allocation fails."""
68+
//| class IDFError(OSError):
69+
//| """Raised for certain generic ESP IDF errors."""
7070
//| ...
7171
//|
72-
NORETURN void mp_raise_espidf_MemoryError(void) {
73-
nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError));
72+
NORETURN void mp_raise_espidf_IDFError(void) {
73+
nlr_raise(mp_obj_new_exception(&mp_type_espidf_IDFError));
7474
}
7575

7676
void espidf_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
@@ -83,6 +83,24 @@ void espidf_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kin
8383
mp_obj_exception_print(print, o_in, kind);
8484
}
8585

86+
const mp_obj_type_t mp_type_espidf_IDFError = {
87+
{ &mp_type_type },
88+
.name = MP_QSTR_IDFError,
89+
.print = espidf_exception_print,
90+
.make_new = mp_obj_exception_make_new,
91+
.attr = mp_obj_exception_attr,
92+
.parent = &mp_type_OSError,
93+
};
94+
95+
96+
//| class MemoryError(MemoryError):
97+
//| """Raised when an ESP IDF memory allocation fails."""
98+
//| ...
99+
//|
100+
NORETURN void mp_raise_espidf_MemoryError(void) {
101+
nlr_raise(mp_obj_new_exception(&mp_type_espidf_MemoryError));
102+
}
103+
86104
const mp_obj_type_t mp_type_espidf_MemoryError = {
87105
{ &mp_type_type },
88106
.name = MP_QSTR_MemoryError,
@@ -99,6 +117,7 @@ STATIC const mp_rom_map_elem_t espidf_module_globals_table[] = {
99117
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_free_size), MP_ROM_PTR(&espidf_heap_caps_get_free_size_obj)},
100118
{ MP_ROM_QSTR(MP_QSTR_heap_caps_get_largest_free_block), MP_ROM_PTR(&espidf_heap_caps_get_largest_free_block_obj)},
101119

120+
{ MP_ROM_QSTR(MP_QSTR_IDFError), MP_ROM_PTR(&mp_type_espidf_IDFError) },
102121
{ MP_ROM_QSTR(MP_QSTR_MemoryError), MP_ROM_PTR(&mp_type_espidf_MemoryError) },
103122
};
104123

ports/esp32s2/bindings/espidf/__init__.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#ifndef MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H
2828
#define MICROPY_INCLUDED_ESP32S2_BINDINGS_ESPIDF___INIT___H
2929

30+
extern const mp_obj_type_t mp_type_espidf_IDFError;
3031
extern const mp_obj_type_t mp_type_espidf_MemoryError;
3132

3233
NORETURN void mp_raise_espidf_MemoryError(void);

0 commit comments

Comments
 (0)