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 533999a92f..d8ac39e92c 100644 --- a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp +++ b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.cpp @@ -11,6 +11,7 @@ namespace pulse_counter_ulp { static const char *const TAG = "pulse_counter_ulp"; +namespace { const char *to_string(CountMode count_mode) { switch (count_mode) { case CountMode::disable: @@ -22,8 +23,7 @@ const char *to_string(CountMode count_mode) { } return "UNKNOWN MODE"; } - -/* === ULP === */ +} // namespace 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"); @@ -42,15 +42,8 @@ std::unique_ptr UlpProgram::start(const Config &config) { ESP_LOGE(TAG, "GPIO used for pulse counting must be an RTC IO"); } - /* Initialize some variables used by ULP program. - * Each 'ulp_xyz' variable corresponds to 'xyz' variable in the ULP program. - * These variables are declared in an auto generated header file, - * 'ulp_main.h', name of this file is defined in component.mk as ULP_APP_NAME. - * These variables are located in RTC_SLOW_MEM and can be accessed both by the - * ULP and the main CPUs. - * - * Note that the ULP reads only the lower 16 bits of these variables. - */ + /* Initialize variables in ULP program. + * Note that the ULP reads only the lower 16 bits of these variables. */ ulp_rising_edge_count = 0; ulp_falling_edge_count = 0; ulp_run_count = 0; @@ -65,9 +58,7 @@ std::unique_ptr UlpProgram::start(const Config &config) { rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_INPUT_ONLY); rtc_gpio_hold_en(gpio_num); - /* Set ULP wake up period T - * Minimum pulse width has to be T * (ulp_debounce_counter + 1). - */ + /* Minimum pulse width is sleep_duration_ * (ulp_debounce_counter + 1). */ ulp_set_wakeup_period(0, config.sleep_duration_ / std::chrono::microseconds{1}); /* Start the program */ @@ -103,8 +94,6 @@ void UlpProgram::set_mean_exec_time(microseconds mean_exec_time) { ulp_mean_exec_time = static_cast(mean_exec_time / microseconds{1}); } -/* === END ULP ===*/ - void PulseCounterUlpSensor::setup() { ESP_LOGCONFIG(TAG, "Setting up pulse counter '%s'...", this->name_.c_str()); diff --git a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.h b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.h index 962fae8401..bf736aaadf 100644 --- a/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.h +++ b/esphome/components/pulse_counter_ulp/pulse_counter_ulp_sensor.h @@ -3,7 +3,6 @@ #include "esphome/core/component.h" #include "esphome/core/hal.h" #include "esphome/components/sensor/sensor.h" -#include "driver/rtc_io.h" // For gpio_num_t #include #include @@ -14,7 +13,6 @@ namespace pulse_counter_ulp { enum class CountMode { disable = 0, increment = 1, decrement = -1 }; -// millis() jumps when a time component synchronises, so we use steady_clock instead using clock = std::chrono::steady_clock; using microseconds = std::chrono::duration; @@ -50,7 +48,6 @@ class PulseCounterUlpSensor : public sensor::Sensor, public PollingComponent { void set_sleep_duration(uint32_t duration_us) { this->config_.sleep_duration_ = duration_us * microseconds{1}; } void set_debounce(uint16_t debounce) { this->config_.debounce_ = debounce; } - /// Unit of measurement is "pulses/min". void setup() override; void update() override; float get_setup_priority() const override { return setup_priority::DATA; } diff --git a/esphome/components/pulse_counter_ulp/sensor.py b/esphome/components/pulse_counter_ulp/sensor.py index 354f8a7412..dd2be479e6 100644 --- a/esphome/components/pulse_counter_ulp/sensor.py +++ b/esphome/components/pulse_counter_ulp/sensor.py @@ -94,7 +94,6 @@ async def to_code(config): "src/CMakeLists.txt", os.path.join(os.path.dirname(__file__), "CMakeLists.txt"), ) - # FIXME These files don't get cleared when the config changes, necessitating deleting .esphome esp32.add_extra_build_file( "ulp/pulse_cnt.S", os.path.join(os.path.dirname(__file__), "ulp/pulse_cnt.S"),