ESPHome 2026.5.0b1
Loading...
Searching...
No Matches
hal.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4
5#include <cstdint>
6#include <esp_attr.h>
7#include <esp_cpu.h>
8#include <esp_task_wdt.h>
9#include <freertos/FreeRTOS.h>
10#include <freertos/task.h>
11
13
14#ifndef PROGMEM
15#define PROGMEM
16#endif
17
18namespace esphome::esp32 {}
19
20namespace esphome {
21
22// Forward decl from helpers.h (esphome/core/helpers.h) — kept here so this
23// header does not need to pull the rest of helpers.h.
24// NOLINTNEXTLINE(readability-redundant-declaration)
26
28__attribute__((always_inline)) inline bool in_isr_context() { return xPortInIsrContext() != 0; }
29
30// Forward decl from <esp_timer.h>.
31// NOLINTNEXTLINE(readability-redundant-declaration)
32extern "C" int64_t esp_timer_get_time(void);
33
34__attribute__((always_inline)) inline void yield() { vPortYield(); }
35__attribute__((always_inline)) inline void delay(uint32_t ms) { vTaskDelay(ms / portTICK_PERIOD_MS); }
36__attribute__((always_inline)) inline uint32_t micros() { return static_cast<uint32_t>(esp_timer_get_time()); }
38__attribute__((always_inline)) inline uint64_t millis_64() {
39 return micros_to_millis<uint64_t>(static_cast<uint64_t>(esp_timer_get_time()));
40}
41
42// NOLINTNEXTLINE(readability-identifier-naming)
43__attribute__((always_inline)) inline void delayMicroseconds(uint32_t us) { delay_microseconds_safe(us); }
44__attribute__((always_inline)) inline void arch_feed_wdt() { esp_task_wdt_reset(); }
45__attribute__((always_inline)) inline uint32_t arch_get_cpu_cycle_count() { return esp_cpu_get_cycle_count(); }
46
47void arch_init();
49
50} // namespace esphome
51
52#endif // USE_ESP32
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
void yield(void)
uint32_t arch_get_cpu_cycle_count()
Definition hal.cpp:71
void arch_init()
Definition hal.cpp:47
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
void HOT delay(uint32_t ms)
Definition hal.cpp:82
uint32_t IRAM_ATTR HOT millis()
Definition hal.cpp:28
int64_t esp_timer_get_time(void)
static void uint32_t