Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
Hosted Weblate 2021-03-01 22:14:18 +01:00
commit d140066a26

View File

@ -43,6 +43,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
self->output = false;
self->open_drain = false;
// Set to input. No output value.
gpio_init(pin->number);
return DIGITALINOUT_OK;
}
@ -75,11 +76,17 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
digitalio_digitalinout_obj_t* self, bool value,
digitalio_drive_mode_t drive_mode) {
const uint8_t pin = self->pin->number;
gpio_set_dir(pin, GPIO_OUT);
// TODO: Turn on "strong" pin driving (more current available).
gpio_disable_pulls(pin);
// Turn on "strong" pin driving (more current available).
hw_write_masked(&padsbank0_hw->io[pin],
PADS_BANK0_GPIO0_DRIVE_VALUE_12MA << PADS_BANK0_GPIO0_DRIVE_LSB,
PADS_BANK0_GPIO0_DRIVE_BITS);
self->output = true;
common_hal_digitalio_digitalinout_set_drive_mode(self, drive_mode);
self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN;
// Pin direction is ultimately set in set_value. We don't need to do it here.
common_hal_digitalio_digitalinout_set_value(self, value);
return DIGITALINOUT_OK;
}
@ -92,10 +99,18 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
void common_hal_digitalio_digitalinout_set_value(
digitalio_digitalinout_obj_t* self, bool value) {
const uint8_t pin = self->pin->number;
if (self->open_drain) {
gpio_set_dir(pin, value ? GPIO_IN : GPIO_OUT);
} else {
if (self->open_drain && value) {
// If true and open-drain, set the direction -before- setting
// the pin value, to to avoid a high glitch on the pin before
// switching from output to input for open-drain.
gpio_set_dir(pin, GPIO_IN);
gpio_put(pin, value);
} else {
// Otherwise set the direction -after- setting the pin value,
// to avoid a glitch which might occur if the old value was
// different and the pin was previously set to input.
gpio_put(pin, value);
gpio_set_dir(pin, GPIO_OUT);
}
}
@ -110,9 +125,6 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
const uint8_t pin = self->pin->number;
bool value = common_hal_digitalio_digitalinout_get_value(self);
self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN;
if (self->open_drain) {
gpio_put(pin, false);
}
// True is implemented differently between modes so reset the value to make
// sure it's correct for the new mode.
if (value) {