1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-03 07:02:28 +03:00

Check ESP8285 at runtime (#8604)

* esp_is_8285() at runtime
* less code with less statics, just read again
This commit is contained in:
Max Prokhorov 2022-06-25 23:23:45 +03:00 committed by GitHub
parent 8decdc380a
commit 5d4ae86565
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 5 deletions

View File

@ -20,18 +20,19 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <eagle_soc.h>
#include <stdint.h>
#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

View File

@ -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

View File

@ -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)