ESPHome 2026.11.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"
7
10
12#if defined(USE_ESP8266) && defined(__GNUC__) && !defined(__clang__)
13#define ESPHOME_FLASH_CONSTINIT constinit
14#else
15#define ESPHOME_FLASH_CONSTINIT
16#endif
17
18// Per-platform HAL bits (IRAM_ATTR / PROGMEM macros, in_isr_context(),
19// inline yield/delay/micros/millis/millis_64 wrappers, ESP8266 progmem
20// helpers) live next to each platform component as components/<platform>/hal.h
21// and are dispatched here based on the active USE_* platform define. Each
22// header guards its body with the matching #ifdef USE_<platform> and re-enters
23// namespace esphome {} so it is safe to be re-included.
24#if defined(USE_ESP32)
26#elif defined(USE_ESP8266)
28#elif defined(USE_LIBRETINY)
30#elif defined(USE_RP2)
32#elif defined(USE_HOST)
34#elif defined(USE_ZEPHYR)
36#else
37#error "hal.h: not implemented for this platform"
38#endif
39
40namespace esphome {
41
42// Cross-platform declarations. delayMicroseconds(), arch_feed_wdt(),
43// arch_get_cpu_cycle_count(), arch_init(), arch_get_cpu_freq_hz() vary
44// per platform (some inline, some out-of-line) so they live in
45// components/<platform>/hal.h.
46void __attribute__((noreturn)) arch_restart();
47
48#ifndef USE_ESP8266
49// All non-ESP8266 platforms: PROGMEM is a no-op, so these are direct dereferences.
50// ESP8266's out-of-line declarations live in components/esp8266/hal.h.
51inline uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; }
52inline const char *progmem_read_ptr(const char *const *addr) { return *addr; }
53inline uint16_t progmem_read_uint16(const uint16_t *addr) { return *addr; }
54// Bulk copy out of PROGMEM. PROGMEM is a no-op everywhere except ESP8266, so a
55// plain `std::memcpy` is correct and the fast path here.
56inline void progmem_memcpy(void *dst, const void *src, size_t len) { std::memcpy(dst, src, len); }
57#endif
58
59} // namespace esphome
struct @66::@67 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:45
const char * progmem_read_ptr(const char *const *addr)
Definition hal.h:52
void progmem_memcpy(void *dst, const void *src, size_t len)
Definition hal.h:56
const void size_t len
Definition hal.h:68
uint16_t progmem_read_uint16(const uint16_t *addr)
Definition hal.h:53
const void * src
Definition hal.h:68
void arch_restart()
Definition hal.cpp:36
uint8_t progmem_read_byte(const uint8_t *addr)
Definition hal.h:51