Skip to content

Commit eac8b2d

Browse files
authored
fix port{Input,Output,Mode}Register macros for chips with <=32 pins (espressif#5402)
Closes espressif#5378
1 parent a9bd39d commit eac8b2d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Diff for: cores/esp32/Arduino.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,23 @@
9999
#define bit(b) (1UL << (b))
100100
#define _BV(b) (1UL << (b))
101101

102-
#define digitalPinToPort(pin) (((pin)>31)?1:0)
103-
#define digitalPinToBitMask(pin) (1UL << (((pin)>31)?((pin)-32):(pin)))
104102
#define digitalPinToTimer(pin) (0)
105103
#define analogInPinToBit(P) (P)
104+
#if SOC_GPIO_PIN_COUNT <= 32
105+
#define digitalPinToPort(pin) (0)
106+
#define digitalPinToBitMask(pin) (1UL << (pin))
107+
#define portOutputRegister(port) ((volatile uint32_t*)GPIO_OUT_REG)
108+
#define portInputRegister(port) ((volatile uint32_t*)GPIO_IN_REG)
109+
#define portModeRegister(port) ((volatile uint32_t*)GPIO_ENABLE_REG)
110+
#elif SOC_GPIO_PIN_COUNT <= 64
111+
#define digitalPinToPort(pin) (((pin)>31)?1:0)
112+
#define digitalPinToBitMask(pin) (1UL << (((pin)>31)?((pin)-32):(pin)))
106113
#define portOutputRegister(port) ((volatile uint32_t*)((port)?GPIO_OUT1_REG:GPIO_OUT_REG))
107114
#define portInputRegister(port) ((volatile uint32_t*)((port)?GPIO_IN1_REG:GPIO_IN_REG))
108115
#define portModeRegister(port) ((volatile uint32_t*)((port)?GPIO_ENABLE1_REG:GPIO_ENABLE_REG))
116+
#else
117+
#error SOC_GPIO_PIN_COUNT > 64 not implemented
118+
#endif
109119

110120
#define NOT_A_PIN -1
111121
#define NOT_A_PORT -1

0 commit comments

Comments
 (0)