summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shared-bindings/touchio/TouchIn.c3
-rw-r--r--shared-module/touchio/TouchIn.c7
2 files changed, 8 insertions, 2 deletions
diff --git a/shared-bindings/touchio/TouchIn.c b/shared-bindings/touchio/TouchIn.c
index 78fceef41..33d369c74 100644
--- a/shared-bindings/touchio/TouchIn.c
+++ b/shared-bindings/touchio/TouchIn.c
@@ -68,10 +68,11 @@ STATIC mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type,
// 1st argument is the pin
mp_obj_t pin_obj = args[0];
assert_pin(pin_obj, false);
+ const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
+ assert_pin_free(pin);
touchio_touchin_obj_t *self = m_new_obj(touchio_touchin_obj_t);
self->base.type = &touchio_touchin_type;
- const mcu_pin_obj_t *pin = MP_OBJ_TO_PTR(pin_obj);
common_hal_touchio_touchin_construct(self, pin);
return (mp_obj_t) self;
diff --git a/shared-module/touchio/TouchIn.c b/shared-module/touchio/TouchIn.c
index 056556c90..88d12b8b8 100644
--- a/shared-module/touchio/TouchIn.c
+++ b/shared-module/touchio/TouchIn.c
@@ -67,12 +67,17 @@ static uint16_t get_raw_reading(touchio_touchin_obj_t *self) {
}
void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, const mcu_pin_obj_t *pin) {
+ claim_pin(pin);
self->digitalinout = m_new_obj(digitalio_digitalinout_obj_t);
self->digitalinout->base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(self->digitalinout, pin);
- self->threshold = get_raw_reading(self) * 1.05 + 100;
+ uint16_t raw_reading = get_raw_reading(self);
+ if (raw_reading == TIMEOUT_TICKS) {
+ mp_raise_ValueError(translate("No pulldown on pin; 1Mohm recommended"));
+ }
+ self->threshold = raw_reading * 1.05 + 100;
}
bool common_hal_touchio_touchin_deinited(touchio_touchin_obj_t* self) {