summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-02-28 12:38:28 +1100
committerDamien George <damien.p.george@gmail.com>2019-03-14 07:26:59 +1100
commit349b54525e0b9715dde713c4ff64ca2660163fe9 (patch)
tree746315f65c089658c7ea9ef791160a9b17cb038e
parentea2fcdd338b9a9a545c119a7d86de1b8caf77314 (diff)
esp32/machine_pin: Make it so None as pull value disables pull up/down.
Previously specifying None as the pull value would leave the pull up/down state unchanged. This change makes it so -1 leaves the state unchanged and None makes the pin float, as per the docs.
-rw-r--r--ports/esp32/machine_pin.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/ports/esp32/machine_pin.c b/ports/esp32/machine_pin.c
index a899fa62a..648674f9a 100644
--- a/ports/esp32/machine_pin.c
+++ b/ports/esp32/machine_pin.c
@@ -137,7 +137,7 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
enum { ARG_mode, ARG_pull, ARG_value };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_mode, MP_ARG_OBJ, {.u_obj = mp_const_none}},
- { MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = mp_const_none}},
+ { MP_QSTR_pull, MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)}},
{ MP_QSTR_value, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL}},
};
@@ -164,8 +164,12 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
}
// configure pull
- if (args[ARG_pull].u_obj != mp_const_none) {
- gpio_set_pull_mode(self->id, mp_obj_get_int(args[ARG_pull].u_obj));
+ if (args[ARG_pull].u_obj != MP_OBJ_NEW_SMALL_INT(-1)) {
+ if (args[ARG_pull].u_obj == mp_const_none) {
+ gpio_set_pull_mode(self->id, GPIO_FLOATING);
+ } else {
+ gpio_set_pull_mode(self->id, mp_obj_get_int(args[ARG_pull].u_obj));
+ }
}
return mp_const_none;