From fe533952cc5643aa6cc3fe0ef3042f0655d4579b Mon Sep 17 00:00:00 2001 From: brisk Date: Thu, 4 Apr 2024 21:35:00 +1030 Subject: [PATCH] pulse_counter: conditionally compile ULP --- .../pulse_counter/pulse_counter_sensor.cpp | 13 +++++++++++-- esphome/components/pulse_counter/sensor.py | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/esphome/components/pulse_counter/pulse_counter_sensor.cpp b/esphome/components/pulse_counter/pulse_counter_sensor.cpp index 35994778bd..f5d630bdd0 100644 --- a/esphome/components/pulse_counter/pulse_counter_sensor.cpp +++ b/esphome/components/pulse_counter/pulse_counter_sensor.cpp @@ -1,10 +1,11 @@ #include "pulse_counter_sensor.h" #include "esphome/core/log.h" -// TODO This cannot be a general dependency for this file +#ifdef CONF_USE_ULP #include "esp32/ulp.h" #include "ulp_main.h" #include "soc/rtc_periph.h" #include "driver/rtc_io.h" +#endif namespace esphome { namespace pulse_counter { @@ -20,8 +21,12 @@ PulseCounterStorageBase *get_storage(Storage storage) { return new BasicPulseCounterStorage; case Storage::pcnt: return new HwPulseCounterStorage; +#ifdef CONF_USE_ULP case Storage::ulp: return new UlpPulseCounterStorage; +#endif + default: + return new BasicPulseCounterStorage; } return new BasicPulseCounterStorage; } @@ -156,6 +161,8 @@ pulse_counter_t HwPulseCounterStorage::read_raw_value() { /* === ULP === */ +#ifdef CONF_USE_ULP + extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start"); extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end"); @@ -241,11 +248,13 @@ bool UlpPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) { pulse_counter_t UlpPulseCounterStorage::read_raw_value() { // TODO count edges separately - uint32_t count = (ulp_edge_count & UINT16_MAX) / 2; + uint32_t count = ulp_edge_count; ulp_edge_count = 0; return count; } +#endif + /* === END ULP ===*/ #endif diff --git a/esphome/components/pulse_counter/sensor.py b/esphome/components/pulse_counter/sensor.py index b5a720fa07..17b02e10c8 100644 --- a/esphome/components/pulse_counter/sensor.py +++ b/esphome/components/pulse_counter/sensor.py @@ -134,6 +134,7 @@ async def to_code(config): else: var = await sensor.new_sensor(config, config.get(CONF_USE_PCNT)) if config.get(CONF_USE_ULP): + var.add_define("CONF_USE_ULP", True) esp32.add_extra_build_file( "src/CMakeLists.txt", os.path.join(os.path.dirname(__file__), "CMakeLists.txt"),