From e64cb619f79a3c888dd56b957d8f48ce74f35735 Mon Sep 17 00:00:00 2001 From: Clemens Kirchgatterer Date: Sun, 22 Mar 2020 13:16:39 +0100 Subject: [PATCH] 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() --- cores/esp8266/core_esp8266_wiring_digital.cpp | 17 +++++++++++------ cores/esp8266/wiring_private.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cores/esp8266/core_esp8266_wiring_digital.cpp b/cores/esp8266/core_esp8266_wiring_digital.cpp index 47eeebf86..a81cf069c 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.cpp +++ b/cores/esp8266/core_esp8266_wiring_digital.cpp @@ -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); } @@ -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)); diff --git a/cores/esp8266/wiring_private.h b/cores/esp8266/wiring_private.h index 2c53565a6..cb52f0539 100644 --- a/cores/esp8266/wiring_private.h +++ b/cores/esp8266/wiring_private.h @@ -37,6 +37,7 @@ extern "C" { typedef void (*voidFuncPtr)(void); void initPins(); +void resetPins(); #ifdef __cplusplus } // extern "C"