Skip to content

Commit d9234ff

Browse files
committed
need to gpio_set_dir() at some point
1 parent d0f1cfb commit d9234ff

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,18 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
9999
void common_hal_digitalio_digitalinout_set_value(
100100
digitalio_digitalinout_obj_t* self, bool value) {
101101
const uint8_t pin = self->pin->number;
102-
if (value) {
103-
// If true, set the direction -before- setting the pin value, to
104-
// to avoid a glitch true 3.3v on the pin before switching from output to input for open drain.
105-
if (self->open_drain) {
106-
gpio_set_dir(pin, GPIO_IN);
107-
}
108-
gpio_put(pin, true);
102+
if (self->open_drain && value) {
103+
// If true and open-drain, set the direction -before- setting
104+
// the pin value, to to avoid a high glitch on the pin before
105+
// switching from output to input for open-drain.
106+
gpio_set_dir(pin, GPIO_IN);
107+
gpio_put(pin, value);
109108
} else {
110-
// If false, set the direction -after- setting the pin value,
111-
// to avoid a glitch 3.3v on the pin before switching from input to output for open drain,
112-
// when previous value was high.
113-
gpio_put(pin, false);
114-
if (self->open_drain) {
115-
gpio_set_dir(pin, GPIO_OUT);
116-
}
109+
// Otherwise set the direction -after- setting the pin value,
110+
// to avoid a glitch which might occur if the old value was
111+
// different and the pin was previously set to input.
112+
gpio_put(pin, value);
113+
gpio_set_dir(pin, GPIO_OUT);
117114
}
118115
}
119116

0 commit comments

Comments
 (0)