diff --git a/atmel-samd/common-hal/nativeio/DigitalInOut.c b/atmel-samd/common-hal/nativeio/DigitalInOut.c index 119832ff69..a002050e4b 100644 --- a/atmel-samd/common-hal/nativeio/DigitalInOut.c +++ b/atmel-samd/common-hal/nativeio/DigitalInOut.c @@ -175,7 +175,7 @@ enum digitalinout_pull_t common_hal_nativeio_digitalinout_get_pull( "Cannot get pull while in output mode.")); return PULL_NONE; } else { - if (port_base->PINCFG[pin % 32].bit.PULLEN != 0) { + if (port_base->PINCFG[pin % 32].bit.PULLEN == 0) { return PULL_NONE; } if ((port_base->OUT.reg & pin_mask) > 0) { return PULL_UP; diff --git a/shared-bindings/nativeio/DigitalInOut.c b/shared-bindings/nativeio/DigitalInOut.c index f3f9bf0387..d06c9b5f52 100644 --- a/shared-bindings/nativeio/DigitalInOut.c +++ b/shared-bindings/nativeio/DigitalInOut.c @@ -302,14 +302,20 @@ STATIC mp_obj_t nativeio_digitalinout_obj_get_pull(mp_obj_t self_in) { } MP_DEFINE_CONST_FUN_OBJ_1(nativeio_digitalinout_get_pull_obj, nativeio_digitalinout_obj_get_pull); -STATIC mp_obj_t nativeio_digitalinout_obj_set_pull(mp_obj_t self_in, mp_obj_t pull) { +STATIC mp_obj_t nativeio_digitalinout_obj_set_pull(mp_obj_t self_in, mp_obj_t pull_obj) { nativeio_digitalinout_obj_t *self = MP_OBJ_TO_PTR(self_in); if (common_hal_nativeio_digitalinout_get_direction(self) == DIRECTION_OUT) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Pull not used when direction is output.")); return mp_const_none; } - common_hal_nativeio_digitalinout_set_pull(self, (enum digitalinout_pull_t) MP_OBJ_SMALL_INT_VALUE(pull)); + enum digitalinout_pull_t pull = PULL_NONE; + if (pull_obj == &nativeio_digitalinout_pull_up_obj) { + pull = PULL_UP; + } else if (pull_obj == &nativeio_digitalinout_pull_down_obj) { + pull = PULL_DOWN; + } + common_hal_nativeio_digitalinout_set_pull(self, pull); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(nativeio_digitalinout_set_pull_obj, nativeio_digitalinout_obj_set_pull);