Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check ESP8285 at runtime #8604

Merged
merged 3 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions cores/esp8266/core_esp8266_features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
11 changes: 11 additions & 0 deletions cores/esp8266/core_esp8266_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion variants/generic/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down