From 4d69f1635481cf618ca4c74b301c1bb4c7bbf8be Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Sat, 2 Nov 2019 16:06:15 +0100 Subject: [PATCH 1/2] Save 16 bytes RAM by placing the array in PROGMEM. --- cores/esp8266/core_esp8266_wiring_digital.cpp | 2 +- cores/esp8266/esp8266_peri.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/core_esp8266_wiring_digital.cpp b/cores/esp8266/core_esp8266_wiring_digital.cpp index 5ed0a40ab7..1bd78816ea 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.cpp +++ b/cores/esp8266/core_esp8266_wiring_digital.cpp @@ -30,7 +30,7 @@ extern "C" { -uint8_t esp8266_gpioToFn[16] = {0x34, 0x18, 0x38, 0x14, 0x3C, 0x40, 0x1C, 0x20, 0x24, 0x28, 0x2C, 0x30, 0x04, 0x08, 0x0C, 0x10}; +const uint8_t esp8266_gpioToFn[16] PROGMEM = { 0x34, 0x18, 0x38, 0x14, 0x3C, 0x40, 0x1C, 0x20, 0x24, 0x28, 0x2C, 0x30, 0x04, 0x08, 0x0C, 0x10 }; extern void __pinMode(uint8_t pin, uint8_t mode) { if(pin < 16){ diff --git a/cores/esp8266/esp8266_peri.h b/cores/esp8266/esp8266_peri.h index 15a596aa6c..0f784aa3b9 100644 --- a/cores/esp8266/esp8266_peri.h +++ b/cores/esp8266/esp8266_peri.h @@ -102,8 +102,8 @@ #define GPF14 ESP8266_REG(0x80C) #define GPF15 ESP8266_REG(0x810) -extern uint8_t esp8266_gpioToFn[16]; -#define GPF(p) ESP8266_REG(0x800 + esp8266_gpioToFn[(p & 0xF)]) +extern const uint8_t esp8266_gpioToFn[16]; +#define GPF(p) ESP8266_REG(0x800 + pgm_read_byte(esp8266_gpioToFn + (p & 0xF))) //GPIO (0-15) PIN Function Bits #define GPFSOE 0 //Sleep OE From 01055fbbe6fe8d01f1d9e84f26a61d067924bec6 Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" Date: Sun, 3 Nov 2019 13:36:24 +0100 Subject: [PATCH 2/2] Reduce runtime computation at expense of switching from uint8_t[16] to uint32_t*[16] --- cores/esp8266/core_esp8266_wiring_digital.cpp | 2 +- cores/esp8266/esp8266_peri.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/esp8266/core_esp8266_wiring_digital.cpp b/cores/esp8266/core_esp8266_wiring_digital.cpp index 1bd78816ea..47eeebf862 100644 --- a/cores/esp8266/core_esp8266_wiring_digital.cpp +++ b/cores/esp8266/core_esp8266_wiring_digital.cpp @@ -30,7 +30,7 @@ extern "C" { -const uint8_t esp8266_gpioToFn[16] PROGMEM = { 0x34, 0x18, 0x38, 0x14, 0x3C, 0x40, 0x1C, 0x20, 0x24, 0x28, 0x2C, 0x30, 0x04, 0x08, 0x0C, 0x10 }; +volatile uint32_t* const esp8266_gpioToFn[16] PROGMEM = { &GPF0, &GPF1, &GPF2, &GPF3, &GPF4, &GPF5, &GPF6, &GPF7, &GPF8, &GPF9, &GPF10, &GPF11, &GPF12, &GPF13, &GPF14, &GPF15 }; extern void __pinMode(uint8_t pin, uint8_t mode) { if(pin < 16){ diff --git a/cores/esp8266/esp8266_peri.h b/cores/esp8266/esp8266_peri.h index 0f784aa3b9..4d9b8406f3 100644 --- a/cores/esp8266/esp8266_peri.h +++ b/cores/esp8266/esp8266_peri.h @@ -102,8 +102,8 @@ #define GPF14 ESP8266_REG(0x80C) #define GPF15 ESP8266_REG(0x810) -extern const uint8_t esp8266_gpioToFn[16]; -#define GPF(p) ESP8266_REG(0x800 + pgm_read_byte(esp8266_gpioToFn + (p & 0xF))) +extern volatile uint32_t* const esp8266_gpioToFn[16]; +#define GPF(p) (*esp8266_gpioToFn[(p & 0xF)]) //GPIO (0-15) PIN Function Bits #define GPFSOE 0 //Sleep OE