Skip to content

Commit eac8b2d

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

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cores/esp32/Arduino.h

Lines changed: 12 additions & 2 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy