ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
hal.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP8266
4
5#include <c_types.h>
6#include <core_esp8266_features.h>
7#include <cstdint>
8#include <pgmspace.h>
9
11
12#ifndef PROGMEM
13#define PROGMEM ICACHE_RODATA_ATTR
14#endif
15
16// Forward decls from Arduino's <Arduino.h> for the inline wrappers below.
17// NOLINTBEGIN(google-runtime-int,readability-identifier-naming,readability-redundant-declaration)
18extern "C" void yield(void);
19extern "C" void delay(unsigned long ms);
20extern "C" unsigned long micros(void);
21extern "C" unsigned long millis(void);
22// NOLINTEND(google-runtime-int,readability-identifier-naming,readability-redundant-declaration)
23
24// Forward decl from <user_interface.h> for arch_feed_wdt() inline below.
25// NOLINTNEXTLINE(readability-redundant-declaration)
26extern "C" void system_soft_wdt_feed(void);
27
28namespace esphome::esp8266 {}
29
30namespace esphome {
31
32// Forward decl from helpers.h so this header stays cheap.
33// NOLINTNEXTLINE(readability-redundant-declaration)
35
41__attribute__((always_inline)) inline bool in_isr_context() { return false; }
42
43__attribute__((always_inline)) inline void yield() { ::yield(); }
44__attribute__((always_inline)) inline uint32_t micros() { return static_cast<uint32_t>(::micros()); }
45void delay(uint32_t ms);
47__attribute__((always_inline)) inline uint64_t millis_64() { return Millis64Impl::compute(millis()); }
48
49// ESP8266: pgm_read_* does aligned 32-bit flash reads on Harvard architecture.
50// Inline-forward to the platform macros so the wrappers themselves don't
51// occupy IRAM/flash on every call site.
52__attribute__((always_inline)) inline uint8_t progmem_read_byte(const uint8_t *addr) {
53 return pgm_read_byte(addr); // NOLINT
54}
55__attribute__((always_inline)) inline const char *progmem_read_ptr(const char *const *addr) {
56 return reinterpret_cast<const char *>(pgm_read_ptr(addr)); // NOLINT
57}
58__attribute__((always_inline)) inline uint16_t progmem_read_uint16(const uint16_t *addr) {
59 return pgm_read_word(addr); // NOLINT
60}
61
62// NOLINTNEXTLINE(readability-identifier-naming)
63__attribute__((always_inline)) inline void delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); }
64__attribute__((always_inline)) inline void arch_feed_wdt() { system_soft_wdt_feed(); }
65__attribute__((always_inline)) inline void arch_init() {}
66// esp_get_cycle_count() declared in <core_esp8266_features.h>; F_CPU is a
67// compiler-driven macro from the ESP8266 Arduino board defs (-DF_CPU=...).
68__attribute__((always_inline)) inline uint32_t arch_get_cpu_cycle_count() { return esp_get_cycle_count(); }
69__attribute__((always_inline)) inline uint32_t arch_get_cpu_freq_hz() { return F_CPU; }
70
71} // namespace esphome
72
73#endif // USE_ESP8266
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
unsigned long millis(void)
void delay(unsigned long ms)
unsigned long micros(void)
void system_soft_wdt_feed(void)
void yield(void)
uint32_t arch_get_cpu_cycle_count()
Definition hal.cpp:71
void arch_init()
Definition hal.cpp:47
const char * progmem_read_ptr(const char *const *addr)
Definition hal.h:43
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
Definition hal.cpp:48
uint32_t arch_get_cpu_freq_hz()
Definition hal.cpp:63
uint64_t millis_64()
Definition hal.cpp:29
uint32_t IRAM_ATTR HOT micros()
Definition hal.cpp:43
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:786
void arch_feed_wdt()
Definition hal.cpp:53
uint16_t progmem_read_uint16(const uint16_t *addr)
Definition hal.h:44
void HOT delay(uint32_t ms)
Definition hal.cpp:82
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:28
uint8_t progmem_read_byte(const uint8_t *addr)
Definition hal.h:42
static void uint32_t