Skip to content

Commit

Permalink
Pull GPIO initialization into its own 'weak' function. (#7044)
Browse files Browse the repository at this point in the history
* 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()
  • Loading branch information
everslick committed Mar 22, 2020
1 parent db75d2c commit e64cb61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
17 changes: 11 additions & 6 deletions cores/esp8266/core_esp8266_wiring_digital.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,7 @@ extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int mode)
__attachInterruptFunctionalArg(pin, (voidFuncPtrArg)userFunc, 0, mode, false);
}

extern void initPins() {
//Disable UART interrupts
system_set_os_print(0);
U0IE = 0;
U1IE = 0;

extern void __resetPins() {
for (int i = 0; i <= 5; ++i) {
pinMode(i, INPUT);
}
Expand All @@ -250,6 +245,16 @@ extern void initPins() {
}
}

extern void initPins() {
//Disable UART interrupts
system_set_os_print(0);
U0IE = 0;
U1IE = 0;

resetPins();
}

extern void resetPins() __attribute__ ((weak, alias("__resetPins")));
extern void pinMode(uint8_t pin, uint8_t mode) __attribute__ ((weak, alias("__pinMode")));
extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("__digitalWrite")));
extern int digitalRead(uint8_t pin) __attribute__ ((weak, alias("__digitalRead"), nothrow));
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/wiring_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extern "C" {
typedef void (*voidFuncPtr)(void);

void initPins();
void resetPins();

#ifdef __cplusplus
} // extern "C"
Expand Down

0 comments on commit e64cb61

Please sign in to comment.