diff options
Diffstat (limited to 'shared-bindings/microcontroller')
| -rw-r--r-- | shared-bindings/microcontroller/Pin.c | 6 | ||||
| -rw-r--r-- | shared-bindings/microcontroller/Pin.h | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/shared-bindings/microcontroller/Pin.c b/shared-bindings/microcontroller/Pin.c index c691a9a17..d564d6d10 100644 --- a/shared-bindings/microcontroller/Pin.c +++ b/shared-bindings/microcontroller/Pin.c @@ -53,3 +53,9 @@ void assert_pin(mp_obj_t obj, bool none_ok) { nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "Expected a Pin")); } } + +void assert_pin_free(const mcu_pin_obj_t* pin) { + if (pin != NULL && !common_hal_mcu_pin_is_free(pin)) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "Pin %q in use", pin->name)); + } +} diff --git a/shared-bindings/microcontroller/Pin.h b/shared-bindings/microcontroller/Pin.h index d31ba040c..46a531a6d 100644 --- a/shared-bindings/microcontroller/Pin.h +++ b/shared-bindings/microcontroller/Pin.h @@ -27,11 +27,15 @@ #ifndef __MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H__ #define __MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H__ +#include "common-hal/microcontroller/types.h" #include "py/obj.h" // Type object used in Python. Should be shared between ports. extern const mp_obj_type_t mcu_pin_type; void assert_pin(mp_obj_t obj, bool none_ok); +void assert_pin_free(const mcu_pin_obj_t* pin); + +bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin); #endif // __MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PIN_H__ |
