Skip to content

Commit d9bca30

Browse files
committed
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>
1 parent 96a2cc5 commit d9bca30

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

ports/esp8266/machine_pin.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
(GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)) & ~GPIO_PIN_INT_TYPE_MASK) \
4747
| GPIO_PIN_INT_TYPE_SET(trig))) \
4848

49+
#define ENABLE_OPEN_DRAIN(phys_port) \
50+
(GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(phys_port)), \
51+
GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(phys_port))) \
52+
| GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)))
53+
54+
#define DISABLE_OPEN_DRAIN(phys_port) \
55+
(GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(phys_port)), \
56+
GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(phys_port))) \
57+
& ~GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))) \
58+
4959
typedef struct _pin_irq_obj_t {
5060
mp_obj_base_t base;
5161
uint16_t phys_port;
@@ -165,9 +175,7 @@ void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin_id) {
165175

166176
ETS_GPIO_INTR_DISABLE();
167177
PIN_FUNC_SELECT(pin->periph, pin->func);
168-
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->phys_port)),
169-
GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->phys_port)))
170-
| GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); // open drain
178+
ENABLE_OPEN_DRAIN(pin->phys_port);
171179
GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS,
172180
GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << pin->phys_port));
173181
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
271279
mp_raise_ValueError(MP_ERROR_TEXT("Pin(16) doesn't support pull"));
272280
}
273281
} else {
282+
DISABLE_OPEN_DRAIN(self->phys_port);
274283
PIN_FUNC_SELECT(self->periph, self->func);
275284
#if 0
276285
// Removed in SDK 1.1.0

0 commit comments

Comments
 (0)