diff --git a/cores/esp8266/core_esp8266_features.cpp b/cores/esp8266/core_esp8266_features.cpp index 68f631d05c..383f3c2d8c 100644 --- a/cores/esp8266/core_esp8266_features.cpp +++ b/cores/esp8266/core_esp8266_features.cpp @@ -20,18 +20,19 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include #include +#ifdef __cplusplus +extern "C" { +#endif + /* precache() * pre-loads flash data into the flash cache * if f==0, preloads instructions starting at the address we were called from. * otherwise preloads flash at the given address. * All preloads are word aligned. */ -#ifdef __cplusplus -extern "C" { -#endif - void precache(void *f, uint32_t bytes) { // Size of a cache page in bytes. We only need to read one word per // page (ie 1 word in 8) for this to work. @@ -46,6 +47,20 @@ void precache(void *f, uint32_t bytes) { (void)x; } +/** based on efuse data, we could determine what type of chip this is + * - https://github.com/espressif/esptool/blob/f04d34bcab29ace798d2d3800ba87020cccbbfdd/esptool.py#L1060-L1070 + * - https://github.com/espressif/ESP8266_RTOS_SDK/blob/3c055779e9793e5f082afff63a011d6615e73639/components/esp8266/include/esp8266/efuse_register.h#L20-L21 + */ +bool esp_is_8285() { + const uint32_t data[] { + READ_PERI_REG(0x3ff00050), // aka MAC0 + READ_PERI_REG(0x3ff00058), // aka CHIPID + }; + + return ((data[0] & (1 << 4)) > 0) + || ((data[1] & (1 << 16)) > 0); +} + #ifdef __cplusplus } #endif diff --git a/cores/esp8266/core_esp8266_features.h b/cores/esp8266/core_esp8266_features.h index 6609a0d082..43ba31674e 100644 --- a/cores/esp8266/core_esp8266_features.h +++ b/cores/esp8266/core_esp8266_features.h @@ -122,10 +122,21 @@ inline int esp_get_cpu_freq_mhz() } #endif + // Call this function in your setup() to cause the phase locked version of the generator to // be linked in automatically. Otherwise, the default PWM locked version will be used. void enablePhaseLockedWaveform(void); +// Determine when the sketch runs on ESP8285 +#if !defined(CORE_MOCK) +bool __attribute__((const, nothrow)) esp_is_8285(); +#else +inline bool esp_is_8285() +{ + return false; +} +#endif + #ifdef __cplusplus } #endif diff --git a/variants/generic/common.h b/variants/generic/common.h index 4d5ffcf4ab..ebff2ca9e8 100644 --- a/variants/generic/common.h +++ b/variants/generic/common.h @@ -30,7 +30,10 @@ #define NUM_DIGITAL_PINS 17 #define NUM_ANALOG_INPUTS 1 -#define isFlashInterfacePin(p) ((p) >= 6 && (p) <= 11) +#define isFlashInterfacePin(p)\ + (esp_is_8285()\ + ? ((p) == 6 || (p) == 7 || (p) == 8 || (p) == 11)\ + : ((p) >= 6 && (p) <= 11)) #define analogInputToDigitalPin(p) ((p > 0) ? NOT_A_PIN : 0) #define digitalPinToInterrupt(p) (((p) < EXTERNAL_NUM_INTERRUPTS)? (p) : NOT_AN_INTERRUPT)