Skip to content

Commit de6b05a

Browse files
committed
Fix DigitalInOut.pull on RP2040
It used to always return None. Fixes #4035
1 parent 0dfa9fb commit de6b05a

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

ports/raspberrypi/common-hal/digitalio/DigitalInOut.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
7676
digitalio_drive_mode_t drive_mode) {
7777
const uint8_t pin = self->pin->number;
7878
gpio_set_dir(pin, GPIO_OUT);
79-
// Turn on "strong" pin driving (more current available). See DRVSTR doc in datasheet.
80-
// hri_port_set_PINCFG_DRVSTR_bit(PORT, (enum gpio_port)GPIO_PORT(pin), GPIO_PIN(pin));
79+
// TODO: Turn on "strong" pin driving (more current available).
8180

8281
self->output = true;
8382
common_hal_digitalio_digitalinout_set_drive_mode(self, drive_mode);
@@ -140,18 +139,16 @@ void common_hal_digitalio_digitalinout_set_pull(
140139

141140
digitalio_pull_t common_hal_digitalio_digitalinout_get_pull(
142141
digitalio_digitalinout_obj_t* self) {
143-
// uint32_t pin = self->pin->number;
144-
// if (self->output) {
145-
// mp_raise_AttributeError(translate("Cannot get pull while in output mode"));
146-
// return PULL_NONE;
147-
// } else {
148-
// if (hri_port_get_PINCFG_PULLEN_bit(PORT, GPIO_PORT(pin), GPIO_PIN(pin)) == 0) {
149-
// return PULL_NONE;
150-
// } if (hri_port_get_OUT_reg(PORT, GPIO_PORT(pin), 1U << GPIO_PIN(pin)) > 0) {
151-
// return PULL_UP;
152-
// } else {
153-
// return PULL_DOWN;
154-
// }
155-
// }
142+
uint32_t pin = self->pin->number;
143+
if (self->output) {
144+
mp_raise_AttributeError(translate("Cannot get pull while in output mode"));
145+
return PULL_NONE;
146+
} else {
147+
if (gpio_is_pulled_up(pin)) {
148+
return PULL_UP;
149+
} else if (gpio_is_pulled_down(pin)) {
150+
return PULL_DOWN;
151+
}
152+
}
156153
return PULL_NONE;
157154
}

0 commit comments

Comments
 (0)