ESPHome  2024.2.1
core.cpp
Go to the documentation of this file.
1 #ifdef USE_ESP8266
2 
3 #include "core.h"
4 #include "esphome/core/defines.h"
5 #include "esphome/core/hal.h"
6 #include "esphome/core/helpers.h"
7 #include "preferences.h"
8 #include <Arduino.h>
9 #include <Esp.h>
10 
11 namespace esphome {
12 
13 void IRAM_ATTR HOT yield() { ::yield(); }
14 uint32_t IRAM_ATTR HOT millis() { return ::millis(); }
15 void IRAM_ATTR HOT delay(uint32_t ms) { ::delay(ms); }
16 uint32_t IRAM_ATTR HOT micros() { return ::micros(); }
17 void IRAM_ATTR HOT delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); }
18 void 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 }
25 void arch_init() {}
26 void IRAM_ATTR HOT arch_feed_wdt() {
27  ESP.wdtFeed(); // NOLINT(readability-static-accessed-through-instance)
28 }
29 
30 uint8_t progmem_read_byte(const uint8_t *addr) {
31  return pgm_read_byte(addr); // NOLINT
32 }
33 uint32_t IRAM_ATTR HOT arch_get_cpu_cycle_count() {
34  return ESP.getCycleCount(); // NOLINT(readability-static-accessed-through-instance)
35 }
36 uint32_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 
52 extern "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
void IRAM_ATTR HOT arch_feed_wdt()
Definition: core.cpp:53
uint16_t x
Definition: tt21100.cpp:17
void delay_microseconds_safe(uint32_t us)
Delay for the given amount of microseconds, possibly yielding to other processes during the wait...
Definition: helpers.cpp:599
uint32_t IRAM_ATTR HOT micros()
Definition: core.cpp:27
const uint8_t ESPHOME_ESP8266_GPIO_INITIAL_MODE[16]
uint32_t IRAM_ATTR HOT millis()
Definition: core.cpp:25
void resetPins()
Definition: core.cpp:52
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:151
uint32_t arch_get_cpu_freq_hz()
Definition: core.cpp:61
void arch_restart()
Definition: core.cpp:29
void force_link_symbols()
Definition: core.cpp:38
uint8_t progmem_read_byte(const uint8_t *addr)
Definition: core.cpp:55
void IRAM_ATTR HOT yield()
Definition: core.cpp:24
const uint8_t ESPHOME_WEBSERVER_INDEX_HTML [] PROGMEM
Definition: web_server.h:22
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
const uint8_t ESPHOME_ESP8266_GPIO_INITIAL_LEVEL[16]
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition: core.cpp:28
void arch_init()
Definition: core.cpp:37
uint32_t arch_get_cpu_cycle_count()
Definition: core.cpp:57
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:26