Skip to content

Commit e25c5cb

Browse files
committed
esp32/machine_pin: Make check for non-output pins respect chip variant.
Fixes issue micropython#7631. Signed-off-by: Damien George <[email protected]>
1 parent 5b65566 commit e25c5cb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ports/esp32/machine_pin.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
#define GPIO_PULL_UP (2)
5050
#define GPIO_PULL_HOLD (4)
5151

52+
#if CONFIG_IDF_TARGET_ESP32
53+
#define GPIO_FIRST_NON_OUTPUT (34)
54+
#elif CONFIG_IDF_TARGET_ESP32S2
55+
#define GPIO_FIRST_NON_OUTPUT (46)
56+
#endif
57+
5258
typedef struct _machine_pin_obj_t {
5359
mp_obj_base_t base;
5460
gpio_num_t id;
@@ -265,11 +271,12 @@ STATIC mp_obj_t machine_pin_obj_init_helper(const machine_pin_obj_t *self, size_
265271
// configure mode
266272
if (args[ARG_mode].u_obj != mp_const_none) {
267273
mp_int_t pin_io_mode = mp_obj_get_int(args[ARG_mode].u_obj);
268-
if (self->id >= 34 && (pin_io_mode & GPIO_MODE_DEF_OUTPUT)) {
274+
#ifdef GPIO_FIRST_NON_OUTPUT
275+
if (self->id >= GPIO_FIRST_NON_OUTPUT && (pin_io_mode & GPIO_MODE_DEF_OUTPUT)) {
269276
mp_raise_ValueError(MP_ERROR_TEXT("pin can only be input"));
270-
} else {
271-
gpio_set_direction(self->id, pin_io_mode);
272277
}
278+
#endif
279+
gpio_set_direction(self->id, pin_io_mode);
273280
}
274281

275282
// configure pull

0 commit comments

Comments
 (0)