diff options
| author | Damien George <damien@micropython.org> | 2022-11-15 12:44:29 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2022-11-15 12:51:39 +1100 |
| commit | d9bca305e576a98192724c212c31413395d31cb4 (patch) | |
| tree | b8ca4ab98b17a04db40d95f28bd3be9443c219b9 | |
| parent | 96a2cc5e13113338c3e4b12a145a852819b623cf (diff) | |
esp8266/machine_pin: Disable open drain when pin becomes input/output.
Otherwise the pin stays in open drain mode.
Signed-off-by: Damien George <damien@micropython.org>
| -rw-r--r-- | ports/esp8266/machine_pin.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/ports/esp8266/machine_pin.c b/ports/esp8266/machine_pin.c index f5e17c7e1..a76f55423 100644 --- a/ports/esp8266/machine_pin.c +++ b/ports/esp8266/machine_pin.c @@ -46,6 +46,16 @@ (GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)) & ~GPIO_PIN_INT_TYPE_MASK) \ | GPIO_PIN_INT_TYPE_SET(trig))) \ +#define ENABLE_OPEN_DRAIN(phys_port) \ + (GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(phys_port)), \ + GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(phys_port))) \ + | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))) + +#define DISABLE_OPEN_DRAIN(phys_port) \ + (GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(phys_port)), \ + GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(phys_port))) \ + & ~GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))) \ + typedef struct _pin_irq_obj_t { mp_obj_base_t base; uint16_t phys_port; @@ -165,9 +175,7 @@ void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin_id) { ETS_GPIO_INTR_DISABLE(); PIN_FUNC_SELECT(pin->periph, pin->func); - GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->phys_port)), - GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->phys_port))) - | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); // open drain + ENABLE_OPEN_DRAIN(pin->phys_port); GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << pin->phys_port)); ETS_GPIO_INTR_ENABLE(); @@ -271,6 +279,7 @@ STATIC mp_obj_t pyb_pin_obj_init_helper(pyb_pin_obj_t *self, size_t n_args, cons mp_raise_ValueError(MP_ERROR_TEXT("Pin(16) doesn't support pull")); } } else { + DISABLE_OPEN_DRAIN(self->phys_port); PIN_FUNC_SELECT(self->periph, self->func); #if 0 // Removed in SDK 1.1.0 |
