Commit Graph
27953 Commits
Author SHA1 Message Date
J. Nick Koston 66a3e3a705 [ld24xx] Replace heap-allocated SensorWithDedup with inline LazySensorWithDedup
Replace heap-allocated SensorWithDedup wrapper with inline
LazySensorWithDedup that stores the sensor pointer and deduplicator
directly in the component, eliminating heap allocations and reducing
RAM usage for configured sensors.
2026-04-12 11:04:17 -10:00
J. Nick Koston eb7799631d Merge remote-tracking branch 'origin/ltr390-reduce-blocking' into integration 2026-04-12 10:50:48 -10:00
Jesse Hills a408b5a4fe Bump version to 2026.4.0b2 2026-04-13 08:48:19 +12:00
Clyde StubbsandJesse Hills e264c97454 [lvgl] Fix use of rotation on host SDL (#15611)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2026-04-13 08:48:19 +12:00
J. Nick Koston 8790dec137 [packages] Fix false deprecation warning and wrong error paths in nested packages (#15605) 2026-04-13 08:48:19 +12:00
Jonathan Swoboda 6480868e6e [esp32] Bump platform to 55.03.38, Arduino to 3.3.8, ESP-IDF to 5.5.4 (#15666) 2026-04-13 08:48:19 +12:00
Jonathan Swoboda 0578e43352 [canbus] Fix canbus.send can_id compile error (#15668) 2026-04-13 08:48:19 +12:00
Jonathan Swoboda 2a89d4835f [mdns] Bump espressif/mdns to 1.11.0 (#15670) 2026-04-13 08:48:19 +12:00
dependabot[bot] 5084c61016 Bump aioesphomeapi from 44.13.2 to 44.13.3 (#15641)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-13 08:48:19 +12:00
dependabot[bot] b45f94d511 Bump aioesphomeapi from 44.13.1 to 44.13.2 (#15637)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-13 08:48:18 +12:00
J. Nick KostonandCopilot 66a4752e13 [rp2040] Fix W5500 Ethernet pbuf corruption by mirroring LWIPMutex semantics (#15624)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-13 08:48:18 +12:00
Jonathan Swoboda 4d4f78de81 [sx127x][cc1101][sx126x] Use GPIO interrupt to wake loop (#15627) 2026-04-13 08:48:18 +12:00
Kevin Ahrendt 0faa641c8a [micro_wake_word] Pin esp-nn version (#15628) 2026-04-13 08:48:18 +12:00
J. Nick Koston 0f16d27a72 [api] Add (inline_encode) proto option for sub-message inlining (#15599) 2026-04-13 08:48:18 +12:00
J. Nick Koston 835ee456a5 [mcp23016] Add interrupt pin support (#15616) 2026-04-13 08:48:18 +12:00
J. Nick Koston 17f3b7dbd5 [pca6416a] Add interrupt pin support (#15614) 2026-04-13 08:48:18 +12:00
J. Nick Koston 171a429526 [tca9555] Add interrupt pin support (#15613) 2026-04-13 08:48:18 +12:00
Jesse Hills e4ee2b7c04 [hbridge] Move light pin switching to loop (#15615) 2026-04-13 08:48:18 +12:00
Jonathan Swoboda c85a062e23 [sx127x][cc1101] Disable loop when packet mode is inactive (#15606) 2026-04-13 08:48:18 +12:00
J. Nick Koston 873378fa1f [gdk101] Increase reset retries for slow-booting sensor MCU (#15584) 2026-04-13 08:48:18 +12:00
dependabot[bot] 4f00ad409e Bump aioesphomeapi from 44.12.0 to 44.13.1 (#15600)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-04-13 08:48:18 +12:00
J. Nick Koston 20b516ff11 [api] Fix ListEntitiesRequest not read due to LWIP rcvevent tracking (#15589) 2026-04-13 08:48:18 +12:00
Clyde StubbsandJesse Hills 8754bbfa89 [lvgl] Fix use of rotation on host SDL (#15611)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
2026-04-12 20:29:11 +00:00
J. Nick Koston 6d92cc3d2b [packages] Fix false deprecation warning and wrong error paths in nested packages (#15605) 2026-04-13 08:24:23 +12:00
J. Nick Koston 09e544125a Merge remote-tracking branch 'upstream/dev' into integration 2026-04-12 10:07:28 -10:00
Jonathan Swoboda 2f684bf4f3 [esp32] Bump platform to 55.03.38, Arduino to 3.3.8, ESP-IDF to 5.5.4 (#15666) 2026-04-12 10:07:04 -10:00
Jonathan Swoboda 45af21bf38 [canbus] Fix canbus.send can_id compile error (#15668) 2026-04-12 09:58:51 -10:00
Jonathan Swoboda e6318a2d16 [mdns] Bump espressif/mdns to 1.11.0 (#15670) 2026-04-12 09:54:30 -10:00
J. Nick Koston b286a67334 Merge remote-tracking branch 'upstream/fast-millis-esp32' into integration 2026-04-12 09:50:55 -10:00
J. Nick Koston e5a0246c80 [core] Document clock divergence between millis() and millis_64_from_()
On ESP32, millis() uses xTaskGetTickCount (tick clock) but
millis_64_from_() discards the 32-bit value and calls millis_64()
(esp_timer clock). Safe because scheduling only compares millis_64
against millis_64. On ESP8266, both use the same accumulator clock.
2026-04-12 09:49:28 -10:00
J. Nick Koston 0249c30cbf [esp32] Document why millis_64() uses a different clock than millis()
millis() uses xTaskGetTickCount (tick clock) while millis_64() uses
esp_timer_get_time (hardware timer). Safe because they are never
cross-compared: Scheduler::millis_64_from_() on ESP32 discards the
32-bit millis parameter and calls millis_64() directly, keeping all
64-bit scheduling on the esp_timer clock.
2026-04-12 09:48:23 -10:00
J. Nick Koston e06c54d100 Merge branch 'fast-millis-esp32' into integration 2026-04-12 09:37:12 -10:00
J. Nick Koston 2cd54b209d Merge branch 'fast-millis-esp8266' into integration 2026-04-12 09:37:02 -10:00
J. Nick Koston b5a2d58b80 [esp32] Keep millis() out-of-line with IRAM_ATTR, add ISR context check
Revert the inline hal.h approach — millis() must remain IRAM_ATTR
because Wiegand and ZyAura call it from IRAM_ATTR ISR handlers on
all platforms including ESP32.

Use xPortInIsrContext() to dispatch to xTaskGetTickCountFromISR()
from ISR or xTaskGetTickCount() from task context, satisfying the
FreeRTOS API contract. ISR check is [[unlikely]] so the hot path
stays fast.

Benchmarked: 686 ns -> 361 ns (1.9x faster). Correctness verified.
2026-04-12 09:07:08 -10:00
J. Nick Koston c155f41110 [esp32] Inline millis() in hal.h, drop IRAM_ATTR
Move millis() to an inline function in hal.h that just returns
xTaskGetTickCount() -- eliminates the function call entirely at every
call site. No IRAM consumed, no flash function call.

Drop IRAM_ATTR from the fallback path. The original IRAM placement was
inherited from ESP8266 where Arduino millis() is called from ISR
handlers (Wiegand, ZyAura). ESPHome does not call millis() from ISR
on ESP32.
2026-04-12 08:49:04 -10:00
J. Nick Koston a8cb5b44cd [esp8266] Address review: fix misleading comment, add named constants
- Remove 'No __umulsidi3' claim from top comment — the rare path
  does use it via /1000. Reworded to 'pure 32-bit ops on the common
  path'.
- Extract MILLIS_RARE_PATH_THRESHOLD_US and US_PER_MS constants to
  replace magic numbers 10000 and 1000.
2026-04-12 00:03:23 -10:00
J. Nick Koston c863a204e8 [esp8266] Fix incorrect claim about delay() usage scope
delay() is called from component loop() and update() methods too
(NFC, RTTTL, sensors), not just setup/OTA.
2026-04-11 23:36:40 -10:00
J. Nick Koston ebbc3b57c7 [esp8266] Document delay() semantic difference from Arduino
Arduino's delay() uses esp_suspend() with a one-shot os_timer for
efficient single-suspension waiting. Our replacement polls millis()
with optimistic_yield(), which also enters esp_schedule/esp_suspend
via yield() but resumes repeatedly. Functionally correct for ESPHome
(delay is cold path, SDK tasks run via yield), just less power-
efficient for long delays.
2026-04-11 23:34:14 -10:00
J. Nick Koston b882d8c721 [esp8266] Fix stale s_last_us reference in comment
Updated to state.last_us to match the struct refactor.
2026-04-11 23:31:48 -10:00
J. Nick Koston da9c44d28d [esp8266] Bound the critical section in millis() accumulator
Split the μs→ms conversion into two paths to keep the interrupt-
disabled critical section bounded:

- Common path (delta < 10 ms): while loop runs at most 10 iterations
  (~100 ns). This covers the normal hot-path case where millis() is
  called thousands of times per second.

- Rare path (delta >= 10 ms): constant-time multiply-by-reciprocal
  via /1000 (compiled to __umulsidi3, ~2.5 μs). Only fires after a
  long block (WiFi scan, boot, component stall), where the extra
  latency is negligible relative to the block that caused it.

Addresses the concern that a multi-second WiFi scan block could cause
the unbounded while loop to hold interrupts for tens of microseconds.
2026-04-11 23:21:15 -10:00
J. Nick Koston aec0be356f [esp8266] Remove unused USE_FAST_MILLIS_ACCUMULATOR define 2026-04-11 23:16:06 -10:00
J. Nick Koston 3d3e26d141 [esp8266] Merge millis_accumulator into millis(), use struct for statics
Merge the separate millis_accumulator() function directly into millis()
to eliminate the extra function call overhead and prologue/epilogue.
Pack the three statics into a struct so the compiler loads one base
address instead of three literal pool entries.

Saves ~12 bytes of IRAM (87+6 → 81 bytes).
2026-04-11 23:10:19 -10:00
J. Nick Koston bf20403558 [esp8266] Revert init() wrap — micros64() needs the overflow timer
Arduino's micros64() reads the same overflow tracking statics that
init() sets up. Wrapping init() as a no-op would cause micros64()
to silently return wrong values after 71 minutes. The overflow timer
cost is negligible (~3 μs per 60 seconds).
2026-04-11 23:08:53 -10:00
J. Nick Koston dff7757d1e [esp8266] Suppress clang-tidy for __wrap_millis reserved identifier
The __wrap_ prefix is required by the GNU linker's --wrap feature.
It's a reserved identifier by C++ rules but mandated by the toolchain.
2026-04-11 23:02:16 -10:00
J. Nick Koston cb654a1e50 [esp8266] Handle delay(0) as a yield point
Arduino's delay(0) calls yield() once — used as a yield point by some
code. Our millis-based loop would skip yielding entirely since
0 < 0 is false. Add explicit delay(0) → yield() handling.
2026-04-11 22:59:12 -10:00
J. Nick Koston 325d9db499 [esp8266] Replace delay() with yield loop to allow GC of original millis
Arduino's ::delay() is implemented in core_esp8266_wiring.cpp alongside
millis(). Because __delay calls millis() within the same compilation
unit, --wrap=millis can't intercept that intra-object reference, which
prevents the linker from garbage-collecting the original millis body
(~80 bytes of IRAM).

Replace esphome::delay() with a simple yield loop that uses our fast
millis() accumulator. This has the same behavior as Arduino's delay:
feeds the watchdog and processes SDK tasks via yield(), keeping WiFi
alive. With __delay unreferenced, the linker can now GC both __delay
and the original millis function.
2026-04-11 22:56:59 -10:00
J. Nick Koston dff6199fc8 [esp8266] Add USE_FAST_MILLIS_ACCUMULATOR define for benchmark guard 2026-04-11 22:37:45 -10:00
J. Nick Koston 16f7effcf3 [esp8266] Fix clang-format: drop trailing underscore from static function 2026-04-11 22:21:57 -10:00
J. Nick Koston 406546876a [esp8266] Replace millis() with fast accumulator, wrap Arduino callers
Arduino ESP8266's millis() uses 4x 64-bit multiplies with magic
constants to convert system_get_time() to ms while tracking overflow.
On the LX106 (no hardware multiply-high instruction), each 64-bit
multiply goes through the __umulsidi3 software helper — costing
~3.3 us per call.

Replace with a simple accumulator that tracks a running millis counter
from system_get_time() deltas using pure 32-bit integer ops (subtract,
add, compare, subtract). No 64-bit math, no __umulsidi3.

Use -Wl,--wrap=millis to intercept all ::millis() calls site-wide so
Arduino libraries and ISR handlers (Wiegand, ZyAura) also get the fast
version. Brief interrupt disable (~125 ns) protects the static state.

Overflow safety: unsigned 32-bit delta arithmetic handles the 71-minute
system_get_time() wrap correctly for one wrap. ESPHome calls millis()
thousands of times per second, so missing a full wrap is not a realistic
concern. At boot, both the accumulator and system_get_time() start at 0,
so no special initialization is needed.

Benchmarked on real ESP8266 hardware:
  Before: 3348 ns/call (Arduino 4x 64-bit multiply)
  After:  ~800-900 ns/call (accumulator, estimated)
2026-04-11 22:16:38 -10:00
J. Nick Koston 6ac705cd66 [esp32] Use xTaskGetTickCount() for millis() when tick rate is 1kHz
ESPHome sets CONFIG_FREERTOS_HZ=1000, so one FreeRTOS tick equals one
millisecond and xTaskGetTickCount() returns ms directly. This replaces
esp_timer_get_time() + micros_to_millis() (a hardware timer read plus
a 64-bit multiply-shift conversion) with a single volatile memory read.

Benchmarked on real ESP32 hardware:
  Before: 686 ns/call (esp_timer_get_time + micros_to_millis)
  After:  ~20 ns/call (volatile read of xTickCount)

millis() is called 1+N times per main loop iteration (once at the top
and once per component via WarnIfComponentBlockingGuard::finish()), so
on a 5-component device this saves ~3.4 μs per loop iteration.

millis_64() is left on esp_timer_get_time() for full 64-bit μs
precision — it is only called once per loop by the Scheduler.
micros() is also unchanged (runtime_stats needs μs precision).

Falls back to the original implementation if CONFIG_FREERTOS_HZ != 1000
(non-standard user override).
2026-04-11 22:13:33 -10:00