Skip to content

Commit 7991938

Browse files
wemosearlephilhower
authored andcommitted
Fix digitalPinToBitMask(), portOutputRegister(), portInputRegister() … (#4964)
* fix digitalPinToBitMask(), portOutputRegister(), portInputRegister() and portModeRegister() error when the pin is GPIO16.
1 parent 03ea61a commit 7991938

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

cores/esp8266/Arduino.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,13 @@ void loop(void);
224224
void yield(void);
225225
void optimistic_yield(uint32_t interval_us);
226226

227-
#define digitalPinToPort(pin) (0)
228-
#define digitalPinToBitMask(pin) (1UL << (pin))
227+
#define _PORT_GPIO16 1
228+
#define digitalPinToPort(pin) (((pin)==16)?(_PORT_GPIO16):(0))
229+
#define digitalPinToBitMask(pin) (((pin)==16)?(1):(1UL << (pin)))
229230
#define digitalPinToTimer(pin) (0)
230-
#define portOutputRegister(port) ((volatile uint32_t*) &GPO)
231-
#define portInputRegister(port) ((volatile uint32_t*) &GPI)
232-
#define portModeRegister(port) ((volatile uint32_t*) &GPE)
231+
#define portOutputRegister(port) (((port)==_PORT_GPIO16)?((volatile uint32_t*) &GP16O):((volatile uint32_t*) &GPO))
232+
#define portInputRegister(port) (((port)==_PORT_GPIO16)?((volatile uint32_t*) &GP16I):((volatile uint32_t*) &GPI))
233+
#define portModeRegister(port) (((port)==_PORT_GPIO16)?((volatile uint32_t*) &GP16E):((volatile uint32_t*) &GPE))
233234

234235
#define NOT_A_PIN -1
235236
#define NOT_A_PORT -1

0 commit comments

Comments
 (0)