Skip to content

Commit 9025671

Browse files
iabdalkaderdpgeorge
authored andcommitted
drivers/ninaw10: Fix ESP32 input-only pins.
ESP32 pins 34, 35, 36 and 39 are input only, and should not be configured as output.
1 parent 5652f1f commit 9025671

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

drivers/ninaw10/machine_pin_nina.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#define NINA_GPIO_MODE (0x50)
4444
#define NINA_GPIO_READ (0x53)
4545
#define NINA_GPIO_WRITE (0x51)
46+
#define NINA_GPIO_IS_INPUT_ONLY(p) ((p >= 34 && p <= 36) || (p == 39))
4647

4748
static uint8_t pin_map[MICROPY_HW_PIN_EXT_COUNT] = {
4849
27, // LEDR
@@ -82,12 +83,17 @@ void machine_pin_ext_config(machine_pin_obj_t *self, int mode, int value) {
8283
} else if (mode == MACHINE_PIN_MODE_OUT) {
8384
mode = NINA_GPIO_OUTPUT;
8485
self->is_output = true;
85-
machine_pin_ext_set(self, value);
8686
} else {
8787
mp_raise_ValueError("only Pin.OUT and Pin.IN are supported for this pin");
8888
}
8989
if (self->id >= 0 && self->id < MICROPY_HW_PIN_EXT_COUNT) {
9090
uint8_t buf[] = {pin_map[self->id], mode};
91+
if (mode == NINA_GPIO_OUTPUT) {
92+
if (NINA_GPIO_IS_INPUT_ONLY(buf[0])) {
93+
mp_raise_ValueError("only Pin.IN is supported for this pin");
94+
}
95+
machine_pin_ext_set(self, value);
96+
}
9197
nina_ioctl(NINA_GPIO_MODE, sizeof(buf), buf, 0);
9298
}
9399
}

0 commit comments

Comments
 (0)