Skip to content

Commit 4e1f7d4

Browse files
committed
added exception for PULL_UP; corrected open_drain handling
1 parent 441ce2a commit 4e1f7d4

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct(
4545
WRITE_PERI_REG(RTC_GPIO_CONF, READ_PERI_REG(RTC_GPIO_CONF) & ~1); //mux configuration for out enable
4646
WRITE_PERI_REG(RTC_GPIO_ENABLE, READ_PERI_REG(RTC_GPIO_ENABLE) & ~1); //out disable
4747
gpio16_in_use = true;
48-
} else {
48+
} else {
4949
PIN_FUNC_SELECT(self->pin->peripheral, self->pin->gpio_function);
50-
}
50+
}
5151
return DIGITALINOUT_OK;
5252
}
5353

@@ -112,7 +112,7 @@ digitalio_direction_t common_hal_digitalio_digitalinout_get_direction(
112112
void common_hal_digitalio_digitalinout_set_value(
113113
digitalio_digitalinout_obj_t* self, bool value) {
114114
if (self->pin->gpio_number == 16) {
115-
if (self->open_drain) {
115+
if (self->open_drain && value) {
116116
// configure GPIO16 as input with output register holding 0
117117
WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | 1);
118118
WRITE_PERI_REG(RTC_GPIO_CONF, READ_PERI_REG(RTC_GPIO_CONF) & ~1);
@@ -158,7 +158,11 @@ bool common_hal_digitalio_digitalinout_get_value(
158158
return GPIO_INPUT_GET(self->pin->gpio_number);
159159
} else {
160160
if (self->pin->gpio_number == 16) {
161-
return READ_PERI_REG(RTC_GPIO_OUT) & 1;
161+
if (self->open_drain && (READ_PERI_REG(RTC_GPIO_OUT) | READ_PERI_REG(RTC_GPIO_ENABLE)) == 0) {
162+
return true;
163+
} else {
164+
return READ_PERI_REG(RTC_GPIO_OUT) & 1;
165+
}
162166
} else {
163167
uint32_t pin_mask = 1 << self->pin->gpio_number;
164168
if (self->open_drain && ((*PIN_DIR) & pin_mask) == 0) {
@@ -199,9 +203,14 @@ void common_hal_digitalio_digitalinout_set_pull(
199203
return;
200204
}
201205
if (self->pin->gpio_number == 16) {
202-
// PULL_DOWN is the only hardware pull direction available on GPIO16
206+
// PULL_DOWN is the only hardware pull direction available on GPIO16.
203207
// since we don't support pull down, just return without attempting
204-
// to set pull (which won't work anyway).
208+
// to set pull (which won't work anyway). If PULL_UP is requested,
209+
// raise the exception so the user knows PULL_UP is not available
210+
if (pull != PULL_NONE){
211+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError,
212+
"GPIO16 does not support pull up."));
213+
}
205214
return;
206215
}
207216
if (pull == PULL_NONE) {

0 commit comments

Comments
 (0)