|
46 | 46 | (GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)) & ~GPIO_PIN_INT_TYPE_MASK) \
|
47 | 47 | | GPIO_PIN_INT_TYPE_SET(trig))) \
|
48 | 48 |
|
| 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 | + |
49 | 59 | typedef struct _pin_irq_obj_t {
|
50 | 60 | mp_obj_base_t base;
|
51 | 61 | uint16_t phys_port;
|
@@ -165,9 +175,7 @@ void mp_hal_pin_open_drain(mp_hal_pin_obj_t pin_id) {
|
165 | 175 |
|
166 | 176 | ETS_GPIO_INTR_DISABLE();
|
167 | 177 | 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); |
171 | 179 | GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS,
|
172 | 180 | GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << pin->phys_port));
|
173 | 181 | 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
|
271 | 279 | mp_raise_ValueError(MP_ERROR_TEXT("Pin(16) doesn't support pull"));
|
272 | 280 | }
|
273 | 281 | } else {
|
| 282 | + DISABLE_OPEN_DRAIN(self->phys_port); |
274 | 283 | PIN_FUNC_SELECT(self->periph, self->func);
|
275 | 284 | #if 0
|
276 | 285 | // Removed in SDK 1.1.0
|
|
0 commit comments