diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-02-19 14:23:29 +0100 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-02-19 14:23:29 +0100 |
| commit | d67968e3c33938c10fe909ef88852e7651419c20 (patch) | |
| tree | 71b801421961fed90f7ce54124fd882ee72bff3c /shared-bindings/microcontroller/Pin.c | |
| parent | 39ac7240a8b96c3aeaca2184e88862805f8769f3 (diff) | |
Add print support to Pin. #83 #76
Diffstat (limited to 'shared-bindings/microcontroller/Pin.c')
| -rw-r--r-- | shared-bindings/microcontroller/Pin.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index 6ef219dfb..ca717fe23 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -24,6 +24,8 @@ * THE SOFTWARE. */ +#include "shared-bindings/board/__init__.h" +#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" #include "py/nlr.h" @@ -43,9 +45,31 @@ //| `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. + 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)); + 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)); + return; + } + } +} + const mp_obj_type_t mcu_pin_type = { { &mp_type_type }, .name = MP_QSTR_Pin, + .print = mcu_pin_print }; void assert_pin(mp_obj_t obj, bool none_ok) { |
