diff --git a/esphome/core/hal/hal_esp32.h b/esphome/components/esp32/hal.h similarity index 98% rename from esphome/core/hal/hal_esp32.h rename to esphome/components/esp32/hal.h index d5d7752bf6..2180f07f6c 100644 --- a/esphome/core/hal/hal_esp32.h +++ b/esphome/components/esp32/hal.h @@ -15,6 +15,8 @@ #define PROGMEM #endif +namespace esphome::esp32 {} + namespace esphome { // Forward decl from helpers.h (esphome/core/helpers.h) — kept here so this diff --git a/esphome/components/esp8266/hal.cpp b/esphome/components/esp8266/hal.cpp index 56910e5b39..e8f472dc8a 100644 --- a/esphome/components/esp8266/hal.cpp +++ b/esphome/components/esp8266/hal.cpp @@ -18,7 +18,7 @@ namespace esphome::esp8266 {} // namespace esphome::esp8266 namespace esphome { // yield(), micros(), millis_64(), delayMicroseconds(), arch_feed_wdt(), -// progmem_read_*() are inlined in core/hal/hal_esp8266.h. +// progmem_read_*() are inlined in components/esp8266/hal.h. // // Fast accumulator replacement for Arduino's millis() (~3.3 μs via 4× 64-bit // multiplies on the LX106). Tracks a running ms counter from 32-bit diff --git a/esphome/core/hal/hal_esp8266.h b/esphome/components/esp8266/hal.h similarity index 98% rename from esphome/core/hal/hal_esp8266.h rename to esphome/components/esp8266/hal.h index b6e3b1ee3c..effa9c9371 100644 --- a/esphome/core/hal/hal_esp8266.h +++ b/esphome/components/esp8266/hal.h @@ -25,6 +25,8 @@ extern "C" unsigned long millis(void); // NOLINTNEXTLINE(readability-redundant-declaration) extern "C" void system_soft_wdt_feed(void); +namespace esphome::esp8266 {} + namespace esphome { // Forward decl from helpers.h so this header stays cheap. diff --git a/esphome/components/host/hal.cpp b/esphome/components/host/hal.cpp index 256a12ac62..c7fef8d2e8 100644 --- a/esphome/components/host/hal.cpp +++ b/esphome/components/host/hal.cpp @@ -15,7 +15,7 @@ namespace esphome::host {} // namespace esphome::host namespace esphome { // yield(), arch_init(), arch_feed_wdt(), arch_get_cpu_freq_hz() inlined in -// core/hal/hal_host.h. +// components/host/hal.h. uint32_t IRAM_ATTR HOT millis() { struct timespec spec; diff --git a/esphome/core/hal/hal_host.h b/esphome/components/host/hal.h similarity index 96% rename from esphome/core/hal/hal_host.h rename to esphome/components/host/hal.h index d7f317176e..12abf6684d 100644 --- a/esphome/core/hal/hal_host.h +++ b/esphome/components/host/hal.h @@ -8,6 +8,8 @@ #define IRAM_ATTR #define PROGMEM +namespace esphome::host {} + namespace esphome { /// Returns true when executing inside an interrupt handler. diff --git a/esphome/components/libretiny/hal.cpp b/esphome/components/libretiny/hal.cpp index e6dbb7296c..67e902024d 100644 --- a/esphome/components/libretiny/hal.cpp +++ b/esphome/components/libretiny/hal.cpp @@ -16,7 +16,7 @@ namespace esphome { // yield(), delay(), micros(), millis(), millis_64(), delayMicroseconds(), // arch_feed_wdt(), arch_get_cpu_cycle_count(), arch_get_cpu_freq_hz() -// inlined in core/hal/hal_libretiny.h. +// inlined in components/libretiny/hal.h. void arch_init() { libretiny::setup_preferences(); diff --git a/esphome/core/hal/hal_libretiny.h b/esphome/components/libretiny/hal.h similarity index 99% rename from esphome/core/hal/hal_libretiny.h rename to esphome/components/libretiny/hal.h index db0fc11bfb..9c512504b7 100644 --- a/esphome/core/hal/hal_libretiny.h +++ b/esphome/components/libretiny/hal.h @@ -61,6 +61,8 @@ extern "C" void lt_wdt_feed(void); extern "C" uint32_t lt_cpu_get_cycle_count(void); extern "C" uint32_t lt_cpu_get_freq(void); +namespace esphome::libretiny {} + namespace esphome { /// Returns true when executing inside an interrupt handler. diff --git a/esphome/components/rp2040/hal.cpp b/esphome/components/rp2040/hal.cpp index 7475205d60..e71d3fd54d 100644 --- a/esphome/components/rp2040/hal.cpp +++ b/esphome/components/rp2040/hal.cpp @@ -17,7 +17,7 @@ namespace esphome::rp2040 {} // namespace esphome::rp2040 namespace esphome { // yield(), delay(), micros(), millis(), millis_64(), delayMicroseconds(), -// arch_feed_wdt(), arch_get_cpu_cycle_count() inlined in core/hal/hal_rp2040.h. +// arch_feed_wdt(), arch_get_cpu_cycle_count() inlined in components/rp2040/hal.h. void arch_restart() { watchdog_reboot(0, 0, 10); while (1) { diff --git a/esphome/core/hal/hal_rp2040.h b/esphome/components/rp2040/hal.h similarity index 98% rename from esphome/core/hal/hal_rp2040.h rename to esphome/components/rp2040/hal.h index 27a9b23c0b..c9c61c921d 100644 --- a/esphome/core/hal/hal_rp2040.h +++ b/esphome/components/rp2040/hal.h @@ -25,6 +25,8 @@ extern "C" uint64_t time_us_64(void); extern "C" void watchdog_update(void); extern "C" unsigned long ulMainGetRunTimeCounterValue(void); +namespace esphome::rp2040 {} + namespace esphome { // Forward decl from helpers.h. diff --git a/esphome/components/zephyr/hal.cpp b/esphome/components/zephyr/hal.cpp index 5c08ed2519..6c405b650e 100644 --- a/esphome/components/zephyr/hal.cpp +++ b/esphome/components/zephyr/hal.cpp @@ -20,7 +20,7 @@ static const device *const WDT = DEVICE_DT_GET(DT_ALIAS(watchdog0)); // yield(), delay(), micros(), millis(), millis_64(), delayMicroseconds(), // arch_get_cpu_cycle_count(), arch_get_cpu_freq_hz() inlined in -// core/hal/hal_zephyr.h. +// components/zephyr/hal.h. void arch_init() { #ifdef CONFIG_WATCHDOG diff --git a/esphome/core/hal/hal_zephyr.h b/esphome/components/zephyr/hal.h similarity index 97% rename from esphome/core/hal/hal_zephyr.h rename to esphome/components/zephyr/hal.h index 613b3911c1..11994b68b7 100644 --- a/esphome/core/hal/hal_zephyr.h +++ b/esphome/components/zephyr/hal.h @@ -9,6 +9,8 @@ #define IRAM_ATTR #define PROGMEM +namespace esphome::zephyr {} + namespace esphome { /// Returns true when executing inside an interrupt handler. diff --git a/esphome/core/hal.h b/esphome/core/hal.h index a53296979c..4babda807d 100644 --- a/esphome/core/hal.h +++ b/esphome/core/hal.h @@ -8,22 +8,22 @@ // Per-platform HAL bits (IRAM_ATTR / PROGMEM macros, in_isr_context(), // inline yield/delay/micros/millis/millis_64 wrappers, ESP8266 progmem -// helpers) live under esphome/core/hal/ and are dispatched here based on -// the active USE_* platform define. Each header guards its body with the -// matching #ifdef USE_ and re-enters namespace esphome {} so it -// is safe to be re-included. +// helpers) live next to each platform component as components//hal.h +// and are dispatched here based on the active USE_* platform define. Each +// header guards its body with the matching #ifdef USE_ and re-enters +// namespace esphome {} so it is safe to be re-included. #if defined(USE_ESP32) -#include "esphome/core/hal/hal_esp32.h" +#include "esphome/components/esp32/hal.h" #elif defined(USE_ESP8266) -#include "esphome/core/hal/hal_esp8266.h" +#include "esphome/components/esp8266/hal.h" #elif defined(USE_LIBRETINY) -#include "esphome/core/hal/hal_libretiny.h" +#include "esphome/components/libretiny/hal.h" #elif defined(USE_RP2040) -#include "esphome/core/hal/hal_rp2040.h" +#include "esphome/components/rp2040/hal.h" #elif defined(USE_HOST) -#include "esphome/core/hal/hal_host.h" +#include "esphome/components/host/hal.h" #elif defined(USE_ZEPHYR) -#include "esphome/core/hal/hal_zephyr.h" +#include "esphome/components/zephyr/hal.h" #else #error "hal.h: not implemented for this platform" #endif @@ -33,12 +33,12 @@ namespace esphome { // Cross-platform declarations. delayMicroseconds(), arch_feed_wdt(), // arch_get_cpu_cycle_count(), arch_init(), arch_get_cpu_freq_hz() vary // per platform (some inline, some out-of-line) so they live in -// hal/hal_.h. +// components//hal.h. void __attribute__((noreturn)) arch_restart(); #ifndef USE_ESP8266 // All non-ESP8266 platforms: PROGMEM is a no-op, so these are direct dereferences. -// ESP8266's out-of-line declarations live in hal/hal_esp8266.h. +// ESP8266's out-of-line declarations live in components/esp8266/hal.h. inline uint8_t progmem_read_byte(const uint8_t *addr) { return *addr; } inline const char *progmem_read_ptr(const char *const *addr) { return *addr; } inline uint16_t progmem_read_uint16(const uint16_t *addr) { return *addr; }