ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
core.cpp
Go to the documentation of this file.
1#ifdef USE_ESP8266
2
3#include "core.h"
5#include "esphome/core/hal.h"
8#include "preferences.h"
9#include <Arduino.h>
10#include <core_esp8266_features.h>
11
12extern "C" {
13#include <user_interface.h>
14}
15
16namespace esphome {
17
18void HOT yield() { ::yield(); }
19uint32_t IRAM_ATTR HOT millis() { return ::millis(); }
20uint64_t millis_64() { return Millis64Impl::compute(::millis()); }
21void HOT delay(uint32_t ms) { ::delay(ms); }
22uint32_t IRAM_ATTR HOT micros() { return ::micros(); }
23void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); }
24void arch_restart() {
25 system_restart();
26 // restart() doesn't always end execution
27 while (true) { // NOLINT(clang-diagnostic-unreachable-code)
28 yield();
29 }
30}
31void arch_init() {}
32void HOT arch_feed_wdt() { system_soft_wdt_feed(); }
33
34uint8_t progmem_read_byte(const uint8_t *addr) {
35 return pgm_read_byte(addr); // NOLINT
36}
37const char *progmem_read_ptr(const char *const *addr) {
38 return reinterpret_cast<const char *>(pgm_read_ptr(addr)); // NOLINT
39}
40uint16_t progmem_read_uint16(const uint16_t *addr) {
41 return pgm_read_word(addr); // NOLINT
42}
43uint32_t IRAM_ATTR HOT arch_get_cpu_cycle_count() { return esp_get_cycle_count(); }
44uint32_t arch_get_cpu_freq_hz() { return F_CPU; }
45
47 // Tasmota uses magic bytes in the binary to check if an OTA firmware is compatible
48 // with their settings - ESPHome uses a different settings system (that can also survive
49 // erases). So set magic bytes indicating all tasmota versions are supported.
50 // This only adds 12 bytes of binary size, which is an acceptable price to pay for easier support
51 // for Tasmota.
52 // https://github.com/arendst/Tasmota/blob/b05301b1497942167a015a6113b7f424e42942cd/tasmota/settings.ino#L346-L380
53 // https://github.com/arendst/Tasmota/blob/b05301b1497942167a015a6113b7f424e42942cd/tasmota/i18n.h#L652-L654
54 const static uint32_t TASMOTA_MAGIC_BYTES[] PROGMEM = {0x5AA55AA5, 0xFFFFFFFF, 0xA55AA55A};
55 // Force link symbol by using a volatile integer (GCC attribute used does not work because of LTO)
56 volatile int x = 0;
57 x = TASMOTA_MAGIC_BYTES[x];
58}
59
60extern "C" void resetPins() { // NOLINT
61 // Added in framework 2.7.0
62 // usually this sets up all pins to be in INPUT mode
63 // however, not strictly needed as we set up the pins properly
64 // ourselves and this causes pins to toggle during reboot.
66
67#ifdef USE_ESP8266_EARLY_PIN_INIT
68 for (int i = 0; i < 16; i++) {
71 if (mode != 255)
72 pinMode(i, mode); // NOLINT
73 if (level != 255)
74 digitalWrite(i, level); // NOLINT
75 }
76#endif
77}
78
79} // namespace esphome
80
81#endif // USE_ESP8266
BedjetMode mode
BedJet operating mode.
const uint8_t ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[16]
const uint8_t ESPHOME_ESP8266_GPIO_INITIAL_MODE[16]
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint32_t arch_get_cpu_cycle_count()
Definition core.cpp:56
void arch_init()
Definition core.cpp:39
const char * progmem_read_ptr(const char *const *addr)
Definition core.cpp:37
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:30
void HOT yield()
Definition core.cpp:25
uint32_t arch_get_cpu_freq_hz()
Definition core.cpp:57
uint64_t HOT millis_64()
Definition core.cpp:27
uint32_t IRAM_ATTR HOT micros()
Definition core.cpp:29
void IRAM_ATTR HOT delay_microseconds_safe(uint32_t us)
Delay for the given amount of microseconds, possibly yielding to other processes during the wait.
Definition helpers.cpp:908
void HOT arch_feed_wdt()
Definition core.cpp:54
uint16_t progmem_read_uint16(const uint16_t *addr)
Definition core.cpp:40
void resetPins()
Definition core.cpp:60
void HOT delay(uint32_t ms)
Definition core.cpp:28
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:26
void arch_restart()
Definition core.cpp:31
void force_link_symbols()
Definition core.cpp:46
uint8_t progmem_read_byte(const uint8_t *addr)
Definition core.cpp:34
static void uint32_t
uint16_t x
Definition tt21100.cpp:5
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM
Definition web_server.h:28