From 2ba3b8544036cfeb5cc13291ec1f615d1f509cc4 Mon Sep 17 00:00:00 2001 From: brisk Date: Sun, 21 Jul 2024 22:11:13 +0930 Subject: [PATCH] pulse_counter_ulp: Add run_count to ULP program --- .../pulse_counter_ulp/pulse_counter_ulp_sensor.cpp | 1 + esphome/components/pulse_counter_ulp/ulp/pulse_cnt.S | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp index 0e7ff85d99..1d07385ac3 100644 --- a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp +++ b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp @@ -65,6 +65,7 @@ bool UlpPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) { * Note that the ULP reads only the lower 16 bits of these variables. */ ulp_edge_count = 0; + ulp_run_count = 0; ulp_debounce_counter = 3; ulp_debounce_max_count = 3; ulp_next_edge = 0; diff --git a/esphome/components/pulse_counter_ulp/ulp/pulse_cnt.S b/esphome/components/pulse_counter_ulp/ulp/pulse_cnt.S index b6625a8db4..578d77d314 100644 --- a/esphome/components/pulse_counter_ulp/ulp/pulse_cnt.S +++ b/esphome/components/pulse_counter_ulp/ulp/pulse_cnt.S @@ -55,6 +55,11 @@ debounce_max_count: edge_count: .long 0 + /* Number of times program run since last read */ + .global run_count +run_count: + .long 0 + /* Total number of signal edges acquired */ .global edge_count_total edge_count_total: @@ -70,6 +75,12 @@ io_number: .text .global entry entry: + /* Increment run_count */ + move r3, run_count + ld r2, r3, 0 + add r2, r2, 1 + st r2, r3, 0 + /* Load io_number */ move r3, io_number ld r3, r3, 0