diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2018-07-31 14:01:01 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2018-08-02 13:59:05 -0700 |
| commit | 168aa394dba31449cdb267444992b4f636906aaa (patch) | |
| tree | 9eb83b7feef219a49700810dddd1ac4a0c215a65 /shared-bindings/microcontroller | |
| parent | e7ae5a3070a1422cf7287f546004b12eec9d0d49 (diff) | |
Move pin struct to the peripherals library.
Its slimmed down by removing the qstr and bit packing TCC info.
The trinket m0 build actually grows by 20 bytes. The arduino zero
build shrinks by 188 bytes.
Diffstat (limited to 'shared-bindings/microcontroller')
| -rw-r--r-- | shared-bindings/microcontroller/Pin.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index 33bd43347..c456a030f 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -46,27 +46,37 @@ //| `board` or `microcontroller.pin` to reference the desired pin. //| -STATIC void mcu_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - mcu_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); - // If the pin is in board, print its version there. +static void get_pin_name(const mcu_pin_obj_t *self, qstr* package, qstr* module, qstr* name) { const mp_map_t* board_map = &board_module_globals.map; for (uint8_t i = 0; i < board_map->alloc; i++) { if (board_map->table[i].value == self) { - mp_printf(print, "%q.%q", MP_QSTR_board, - MP_OBJ_QSTR_VALUE(board_map->table[i].key)); + *package = 0; + *module = MP_QSTR_board; + *name = MP_OBJ_QSTR_VALUE(board_map->table[i].key); return; } } const mp_map_t* mcu_map = &mcu_pin_globals.map; for (uint8_t i = 0; i < mcu_map->alloc; i++) { if (mcu_map->table[i].value == self) { - mp_printf(print, "%q.%q.%q", MP_QSTR_microcontroller, MP_QSTR_pin, - MP_OBJ_QSTR_VALUE(mcu_map->table[i].key)); + *package = MP_QSTR_microcontroller; + *module = MP_QSTR_pin; + *name = MP_OBJ_QSTR_VALUE(mcu_map->table[i].key); return; } } } +STATIC void mcu_pin_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + mcu_pin_obj_t *self = MP_OBJ_TO_PTR(self_in); + qstr package; + qstr module; + qstr name; + + get_pin_name(self, &package, &module, &name); + mp_printf(print, "%q.%q.%q", MP_QSTR_microcontroller, MP_QSTR_pin, name); +} + const mp_obj_type_t mcu_pin_type = { { &mp_type_type }, .name = MP_QSTR_Pin, @@ -81,6 +91,11 @@ void assert_pin(mp_obj_t obj, bool none_ok) { void assert_pin_free(const mcu_pin_obj_t* pin) { if (pin != NULL && pin != MP_OBJ_TO_PTR(mp_const_none) && !common_hal_mcu_pin_is_free(pin)) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin %q in use", pin->name)); + qstr package; + qstr module; + qstr name; + + get_pin_name(pin, &package, &module, &name); + mp_raise_ValueError_varg("%q in use", name); } } |
