ESPHome 2025.5.0
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"
7#include "preferences.h"
8#include <Arduino.h>
9#include <Esp.h>
10
11namespace esphome {
12
13void IRAM_ATTR HOT yield() { ::yield(); }
14uint32_t IRAM_ATTR HOT millis() { return ::millis(); }
15void IRAM_ATTR HOT delay(uint32_t ms) { ::delay(ms); }
16uint32_t IRAM_ATTR HOT micros() { return ::micros(); }
17void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); }
18void arch_restart() {
19 ESP.restart(); // NOLINT(readability-static-accessed-through-instance)
20 // restart() doesn't always end execution
21 while (true) { // NOLINT(clang-diagnostic-unreachable-code)
22 yield();
23 }
24}
25void arch_init() {}
26void IRAM_ATTR HOT arch_feed_wdt() {
27 ESP.wdtFeed(); // NOLINT(readability-static-accessed-through-instance)
28}
29
30uint8_t progmem_read_byte(const uint8_t *addr) {
31 return pgm_read_byte(addr); // NOLINT
32}
33uint32_t IRAM_ATTR HOT arch_get_cpu_cycle_count() {
34 return ESP.getCycleCount(); // NOLINT(readability-static-accessed-through-instance)
35}
36uint32_t arch_get_cpu_freq_hz() { return F_CPU; }
37
39 // Tasmota uses magic bytes in the binary to check if an OTA firmware is compatible
40 // with their settings - ESPHome uses a different settings system (that can also survive
41 // erases). So set magic bytes indicating all tasmota versions are supported.
42 // This only adds 12 bytes of binary size, which is an acceptable price to pay for easier support
43 // for Tasmota.
44 // https://github.com/arendst/Tasmota/blob/b05301b1497942167a015a6113b7f424e42942cd/tasmota/settings.ino#L346-L380
45 // https://github.com/arendst/Tasmota/blob/b05301b1497942167a015a6113b7f424e42942cd/tasmota/i18n.h#L652-L654
46 const static uint32_t TASMOTA_MAGIC_BYTES[] PROGMEM = {0x5AA55AA5, 0xFFFFFFFF, 0xA55AA55A};
47 // Force link symbol by using a volatile integer (GCC attribute used does not work because of LTO)
48 volatile int x = 0;
49 x = TASMOTA_MAGIC_BYTES[x];
50}
51
52extern "C" void resetPins() { // NOLINT
53 // Added in framework 2.7.0
54 // usually this sets up all pins to be in INPUT mode
55 // however, not strictly needed as we set up the pins properly
56 // ourselves and this causes pins to toggle during reboot.
58
59#ifdef USE_ESP8266_EARLY_PIN_INIT
60 for (int i = 0; i < 16; i++) {
62 uint8_t level = ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[i];
63 if (mode != 255)
64 pinMode(i, mode); // NOLINT
65 if (level != 255)
66 digitalWrite(i, level); // NOLINT
67 }
68#endif
69}
70
71} // namespace esphome
72
73#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:59
void arch_init()
Definition core.cpp:39
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition core.cpp:30
void IRAM_ATTR HOT yield()
Definition core.cpp:26
uint32_t arch_get_cpu_freq_hz()
Definition core.cpp:63
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:773
void IRAM_ATTR HOT arch_feed_wdt()
Definition core.cpp:55
void resetPins()
Definition core.cpp:52
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:28
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:27
void arch_restart()
Definition core.cpp:31
void force_link_symbols()
Definition core.cpp:38
uint8_t progmem_read_byte(const uint8_t *addr)
Definition core.cpp:57
uint16_t x
Definition tt21100.cpp:5
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML[] PROGMEM
Definition web_server.h:29