From 0ae344841ff048424b886e1f386b16c0c9ba4ee2 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 6 Dec 2016 10:31:38 -0800 Subject: atmel-samd & esp8266: Make sure pins are not already in use. This prevents corrupting previous functional objects by stealing their pins out from under them. It prevents this by ensuring that pins are in default state before claiming them. It also verifies pins are released correctly and reset on soft reset. Fixes #4, instantiating a second class will fail. Fixes #29, pins are now reset too. --- shared-bindings/microcontroller/Pin.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'shared-bindings/microcontroller/Pin.c') 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)); + } +} -- cgit v1.2.3