ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
hal.h
Go to the documentation of this file.
1#pragma once
2#include <cstdint>
3#include <cstring>
4#include <string>
5#include "gpio.h"
9
10// Per-platform HAL bits (IRAM_ATTR / PROGMEM macros, in_isr_context(),
11// inline yield/delay/micros/millis/millis_64 wrappers, ESP8266 progmem
12// helpers) live next to each platform component as components/<platform>/hal.h
13// and are dispatched here based on the active USE_* platform define. Each
14// header guards its body with the matching #ifdef USE_<platform> and re-enters
15// namespace esphome {} so it is safe to be re-included.
16#if defined(USE_ESP32)
18#elif defined(USE_ESP8266)
20#elif defined(USE_LIBRETINY)
22#elif defined(USE_RP2040)
24#elif defined(USE_HOST)
26#elif defined(USE_ZEPHYR)
28#else
29#error "hal.h: not implemented for this platform"
30#endif
31
32namespace esphome {
33
34// Cross-platform declarations. delayMicroseconds(), arch_feed_wdt(),
35// arch_get_cpu_cycle_count(), arch_init(), arch_get_cpu_freq_hz() vary
36// per platform (some inline, some out-of-line) so they live in
37// components/<platform>/hal.h.
38void __attribute__((noreturn)) arch_restart();
39
40#ifndef USE_ESP8266
41// All non-ESP8266 platforms: PROGMEM is a no-op, so these are direct dereferences.
42// ESP8266's out-of-line declarations live in components/esp8266/hal.h.
43inline uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; }
44inline const char *progmem_read_ptr(const char *const *addr) { return *addr; }
45inline uint16_t progmem_read_uint16(const uint16_t *addr) { return *addr; }
46// Bulk copy out of PROGMEM. PROGMEM is a no-op everywhere except ESP8266, so a
47// plain `std::memcpy` is correct and the fast path here.
48inline void progmem_memcpy(void *dst, const void *src, size_t len) { std::memcpy(dst, src, len); }
49#endif
50
51} // namespace esphome
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
const char * progmem_read_ptr(const char *const *addr)
Definition hal.h:44
void progmem_memcpy(void *dst, const void *src, size_t len)
Definition hal.h:48
const void size_t len
Definition hal.h:64
uint16_t progmem_read_uint16(const uint16_t *addr)
Definition hal.h:45
const void * src
Definition hal.h:64
void arch_restart()
Definition hal.cpp:39
uint8_t progmem_read_byte(const uint8_t *addr)
Definition hal.h:43