need to gpio_set_dir() at some point

This commit is contained in:
Dan Halbert 2021-02-26 15:27:35 -05:00
parent d0f1cfb039
commit d9234ffa82

View File

@ -99,23 +99,20 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
void common_hal_digitalio_digitalinout_set_value( void common_hal_digitalio_digitalinout_set_value(
digitalio_digitalinout_obj_t* self, bool value) { digitalio_digitalinout_obj_t* self, bool value) {
const uint8_t pin = self->pin->number; const uint8_t pin = self->pin->number;
if (value) { if (self->open_drain && value) {
// If true, set the direction -before- setting the pin value, to // If true and open-drain, set the direction -before- setting
// to avoid a glitch true 3.3v on the pin before switching from output to input for open drain. // the pin value, to to avoid a high glitch on the pin before
if (self->open_drain) { // switching from output to input for open-drain.
gpio_set_dir(pin, GPIO_IN); gpio_set_dir(pin, GPIO_IN);
} gpio_put(pin, value);
gpio_put(pin, true);
} else { } else {
// If false, set the direction -after- setting the pin value, // Otherwise set the direction -after- setting the pin value,
// to avoid a glitch 3.3v on the pin before switching from input to output for open drain, // to avoid a glitch which might occur if the old value was
// when previous value was high. // different and the pin was previously set to input.
gpio_put(pin, false); gpio_put(pin, value);
if (self->open_drain) {
gpio_set_dir(pin, GPIO_OUT); gpio_set_dir(pin, GPIO_OUT);
} }
} }
}
bool common_hal_digitalio_digitalinout_get_value( bool common_hal_digitalio_digitalinout_get_value(
digitalio_digitalinout_obj_t* self) { digitalio_digitalinout_obj_t* self) {