Skip to content

Commit 5d4ae86

Browse files
authored
Check ESP8285 at runtime (#8604)
* esp_is_8285() at runtime * less code with less statics, just read again
1 parent 8decdc3 commit 5d4ae86

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

cores/esp8266/core_esp8266_features.cpp

+19-4
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
2020
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2121
*/
2222

23+
#include <eagle_soc.h>
2324
#include <stdint.h>
2425

26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
2530
/* precache()
2631
* pre-loads flash data into the flash cache
2732
* if f==0, preloads instructions starting at the address we were called from.
2833
* otherwise preloads flash at the given address.
2934
* All preloads are word aligned.
3035
*/
31-
#ifdef __cplusplus
32-
extern "C" {
33-
#endif
34-
3536
void precache(void *f, uint32_t bytes) {
3637
// Size of a cache page in bytes. We only need to read one word per
3738
// page (ie 1 word in 8) for this to work.
@@ -46,6 +47,20 @@ void precache(void *f, uint32_t bytes) {
4647
(void)x;
4748
}
4849

50+
/** based on efuse data, we could determine what type of chip this is
51+
* - https://github.com/espressif/esptool/blob/f04d34bcab29ace798d2d3800ba87020cccbbfdd/esptool.py#L1060-L1070
52+
* - https://github.com/espressif/ESP8266_RTOS_SDK/blob/3c055779e9793e5f082afff63a011d6615e73639/components/esp8266/include/esp8266/efuse_register.h#L20-L21
53+
*/
54+
bool esp_is_8285() {
55+
const uint32_t data[] {
56+
READ_PERI_REG(0x3ff00050), // aka MAC0
57+
READ_PERI_REG(0x3ff00058), // aka CHIPID
58+
};
59+
60+
return ((data[0] & (1 << 4)) > 0)
61+
|| ((data[1] & (1 << 16)) > 0);
62+
}
63+
4964
#ifdef __cplusplus
5065
}
5166
#endif

cores/esp8266/core_esp8266_features.h

+11
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,21 @@ inline int esp_get_cpu_freq_mhz()
122122
}
123123
#endif
124124

125+
125126
// Call this function in your setup() to cause the phase locked version of the generator to
126127
// be linked in automatically. Otherwise, the default PWM locked version will be used.
127128
void enablePhaseLockedWaveform(void);
128129

130+
// Determine when the sketch runs on ESP8285
131+
#if !defined(CORE_MOCK)
132+
bool __attribute__((const, nothrow)) esp_is_8285();
133+
#else
134+
inline bool esp_is_8285()
135+
{
136+
return false;
137+
}
138+
#endif
139+
129140
#ifdef __cplusplus
130141
}
131142
#endif

variants/generic/common.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
#define NUM_DIGITAL_PINS 17
3131
#define NUM_ANALOG_INPUTS 1
3232

33-
#define isFlashInterfacePin(p) ((p) >= 6 && (p) <= 11)
33+
#define isFlashInterfacePin(p)\
34+
(esp_is_8285()\
35+
? ((p) == 6 || (p) == 7 || (p) == 8 || (p) == 11)\
36+
: ((p) >= 6 && (p) <= 11))
3437

3538
#define analogInputToDigitalPin(p) ((p > 0) ? NOT_A_PIN : 0)
3639
#define digitalPinToInterrupt(p) (((p) < EXTERNAL_NUM_INTERRUPTS)? (p) : NOT_AN_INTERRUPT)

0 commit comments

Comments
 (0)