mirror of
https://github.com/esphome/esphome.git
synced 2026-09-14 00:28:39 +00:00
[core] Move per-platform hal_<platform>.h into components/<platform>/hal.h
Last step in the HAL reorg started in #15977 and continued in the per-platform follow-ups #16111 (esp32), #16112 (esp8266), #16113 (libretiny), #16114 (rp2040), #16115 (host), #16116 (zephyr) — each of which moved its platform's out-of-line HAL bodies from components/<platform>/core.cpp into a new components/<platform>/hal.cpp. This PR moves each platform's HAL header next to its hal.cpp inside components/<platform>/, rather than under core/hal/. The dispatcher core/hal.h is updated to include from the new locations and the now-empty core/hal/ directory is removed. Unlike the wake split (#15978) where freertos-class platforms (ESP32 + LibreTiny) share a single wake_freertos.{h,cpp}, HAL primitives are genuinely per-platform — there is no shared HAL implementation across platforms — so the natural home is alongside each platform component rather than in a separate core/ subdirectory. Each .h file gains an empty 'namespace esphome::<platform> {}' block to satisfy ci-custom's lint_namespace check. HAL functions live in 'namespace esphome' (root); they are not part of the per-component API, matching the convention used by the corresponding hal.cpp files. Comment-only updates to the components/<platform>/hal.cpp files to reflect the new include path. No public API change, no behavior change.
This commit is contained in:
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
@@ -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;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#define IRAM_ATTR
|
||||
#define PROGMEM
|
||||
|
||||
namespace esphome::host {}
|
||||
|
||||
namespace esphome {
|
||||
|
||||
/// Returns true when executing inside an interrupt handler.
|
||||
@@ -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();
|
||||
|
||||
@@ -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.
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
@@ -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
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#define IRAM_ATTR
|
||||
#define PROGMEM
|
||||
|
||||
namespace esphome::zephyr {}
|
||||
|
||||
namespace esphome {
|
||||
|
||||
/// Returns true when executing inside an interrupt handler.
|
||||
+12
-12
@@ -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_<platform> and re-enters namespace esphome {} so it
|
||||
// is safe to be re-included.
|
||||
// helpers) live next to each platform component as components/<platform>/hal.h
|
||||
// and are dispatched here based on the active USE_* platform define. Each
|
||||
// header guards its body with the matching #ifdef USE_<platform> 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_<platform>.h.
|
||||
// components/<platform>/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; }
|
||||
|
||||
Reference in New Issue
Block a user