summaryrefslogtreecommitdiff
path: root/shared-bindings/nativeio/I2C.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott.shawcroft@gmail.com>2016-12-06 10:31:38 -0800
committerScott Shawcroft <scott.shawcroft@gmail.com>2016-12-07 15:21:14 -0800
commit0ae344841ff048424b886e1f386b16c0c9ba4ee2 (patch)
tree358f0e2044672d38dc863b243aea734b2e41337c /shared-bindings/nativeio/I2C.c
parentbb9c751b502a7bda49027d5ee195f8110b1493f9 (diff)
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.
Diffstat (limited to 'shared-bindings/nativeio/I2C.c')
-rw-r--r--shared-bindings/nativeio/I2C.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/shared-bindings/nativeio/I2C.c b/shared-bindings/nativeio/I2C.c
index a29d2b275..2aca80cf6 100644
--- a/shared-bindings/nativeio/I2C.c
+++ b/shared-bindings/nativeio/I2C.c
@@ -63,7 +63,9 @@ STATIC mp_obj_t nativeio_i2c_make_new(const mp_obj_type_t *type, size_t n_args,
assert_pin(args[ARG_scl].u_obj, false);
assert_pin(args[ARG_sda].u_obj, false);
const mcu_pin_obj_t* scl = MP_OBJ_TO_PTR(args[ARG_scl].u_obj);
+ assert_pin_free(scl);
const mcu_pin_obj_t* sda = MP_OBJ_TO_PTR(args[ARG_sda].u_obj);
+ assert_pin_free(sda);
common_hal_nativeio_i2c_construct(self, scl, sda, args[ARG_frequency].u_int);
return (mp_obj_t)self;
}