Skip to content

Commit e64cb61

Browse files
authored
Pull GPIO initialization into its own 'weak' function. (#7044)
* Pull GPIO initialization into its own 'weak' function. By pulling GPIO init into its own weak function, it can be overridden by the user. This is important in cases when GPIOs should not toggle during reboot, exceptions or other crashes. Fixes #7041. * Add prototype for resetPins()
1 parent db75d2c commit e64cb61

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Diff for: cores/esp8266/core_esp8266_wiring_digital.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,7 @@ extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int mode)
235235
__attachInterruptFunctionalArg(pin, (voidFuncPtrArg)userFunc, 0, mode, false);
236236
}
237237

238-
extern void initPins() {
239-
//Disable UART interrupts
240-
system_set_os_print(0);
241-
U0IE = 0;
242-
U1IE = 0;
243-
238+
extern void __resetPins() {
244239
for (int i = 0; i <= 5; ++i) {
245240
pinMode(i, INPUT);
246241
}
@@ -250,6 +245,16 @@ extern void initPins() {
250245
}
251246
}
252247

248+
extern void initPins() {
249+
//Disable UART interrupts
250+
system_set_os_print(0);
251+
U0IE = 0;
252+
U1IE = 0;
253+
254+
resetPins();
255+
}
256+
257+
extern void resetPins() __attribute__ ((weak, alias("__resetPins")));
253258
extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pinMode")));
254259
extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("__digitalWrite")));
255260
extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias("__digitalRead"), nothrow));

Diff for: cores/esp8266/wiring_private.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extern "C" {
3737
typedef void (*voidFuncPtr)(void);
3838

3939
void initPins();
40+
void resetPins();
4041

4142
#ifdef __cplusplus
4243
} // extern "C"

0 commit comments

Comments
 (0)