Skip to content

Commit 199a8ce

Browse files
committed
change DigitalInOut direction only when necessary; strong drive strength
1 parent d4bf0d5 commit 199a8ce

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
4343
self->output = false;
4444
self->open_drain = false;
4545

46+
// Set to input. No output value.
4647
gpio_init(pin->number);
4748
return DIGITALINOUT_OK;
4849
}
@@ -75,10 +76,15 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output(
7576
digitalio_digitalinout_obj_t* self, bool value,
7677
digitalio_drive_mode_t drive_mode) {
7778
const uint8_t pin = self->pin->number;
78-
gpio_set_dir(pin, GPIO_OUT);
79-
// TODO: Turn on "strong" pin driving (more current available).
79+
gpio_disable_pulls(pin);
80+
81+
// Turn on "strong" pin driving (more current available).
82+
hw_write_masked(&padsbank0_hw->io[pin],
83+
PADS_BANK0_GPIO0_DRIVE_VALUE_12MA << PADS_BANK0_GPIO0_DRIVE_LSB,
84+
PADS_BANK0_GPIO0_DRIVE_BITS);
8085

8186
self->output = true;
87+
// Pin direction is ultimately set in set_value. We don't need to do it here.
8288
common_hal_digitalio_digitalinout_set_drive_mode(self, drive_mode);
8389
common_hal_digitalio_digitalinout_set_value(self, value);
8490
return DIGITALINOUT_OK;
@@ -110,9 +116,6 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode(
110116
const uint8_t pin = self->pin->number;
111117
bool value = common_hal_digitalio_digitalinout_get_value(self);
112118
self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN;
113-
if (self->open_drain) {
114-
gpio_put(pin, false);
115-
}
116119
// True is implemented differently between modes so reset the value to make
117120
// sure it's correct for the new mode.
118121
if (value) {

0 commit comments

Comments
 (0)