mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
pulse_counter_ulp: Tidy comments
This commit is contained in:
parent
c57ad9fff9
commit
7b9d000522
3 changed files with 5 additions and 20 deletions
|
@ -11,6 +11,7 @@ namespace pulse_counter_ulp {
|
||||||
|
|
||||||
static const char *const TAG = "pulse_counter_ulp";
|
static const char *const TAG = "pulse_counter_ulp";
|
||||||
|
|
||||||
|
namespace {
|
||||||
const char *to_string(CountMode count_mode) {
|
const char *to_string(CountMode count_mode) {
|
||||||
switch (count_mode) {
|
switch (count_mode) {
|
||||||
case CountMode::disable:
|
case CountMode::disable:
|
||||||
|
@ -22,8 +23,7 @@ const char *to_string(CountMode count_mode) {
|
||||||
}
|
}
|
||||||
return "UNKNOWN MODE";
|
return "UNKNOWN MODE";
|
||||||
}
|
}
|
||||||
|
} // namespace
|
||||||
/* === ULP === */
|
|
||||||
|
|
||||||
extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start");
|
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");
|
extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end");
|
||||||
|
@ -42,15 +42,8 @@ std::unique_ptr<UlpProgram> UlpProgram::start(const Config &config) {
|
||||||
ESP_LOGE(TAG, "GPIO used for pulse counting must be an RTC IO");
|
ESP_LOGE(TAG, "GPIO used for pulse counting must be an RTC IO");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize some variables used by ULP program.
|
/* Initialize variables in ULP program.
|
||||||
* Each 'ulp_xyz' variable corresponds to 'xyz' variable in the ULP program.
|
* Note that the ULP reads only the lower 16 bits of these variables. */
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
ulp_rising_edge_count = 0;
|
ulp_rising_edge_count = 0;
|
||||||
ulp_falling_edge_count = 0;
|
ulp_falling_edge_count = 0;
|
||||||
ulp_run_count = 0;
|
ulp_run_count = 0;
|
||||||
|
@ -65,9 +58,7 @@ std::unique_ptr<UlpProgram> UlpProgram::start(const Config &config) {
|
||||||
rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_INPUT_ONLY);
|
rtc_gpio_set_direction(gpio_num, RTC_GPIO_MODE_INPUT_ONLY);
|
||||||
rtc_gpio_hold_en(gpio_num);
|
rtc_gpio_hold_en(gpio_num);
|
||||||
|
|
||||||
/* Set ULP wake up period T
|
/* Minimum pulse width is sleep_duration_ * (ulp_debounce_counter + 1). */
|
||||||
* Minimum pulse width has to be T * (ulp_debounce_counter + 1).
|
|
||||||
*/
|
|
||||||
ulp_set_wakeup_period(0, config.sleep_duration_ / std::chrono::microseconds{1});
|
ulp_set_wakeup_period(0, config.sleep_duration_ / std::chrono::microseconds{1});
|
||||||
|
|
||||||
/* Start the program */
|
/* Start the program */
|
||||||
|
@ -103,8 +94,6 @@ void UlpProgram::set_mean_exec_time(microseconds mean_exec_time) {
|
||||||
ulp_mean_exec_time = static_cast<uint16_t>(mean_exec_time / microseconds{1});
|
ulp_mean_exec_time = static_cast<uint16_t>(mean_exec_time / microseconds{1});
|
||||||
}
|
}
|
||||||
|
|
||||||
/* === END ULP ===*/
|
|
||||||
|
|
||||||
void PulseCounterUlpSensor::setup() {
|
void PulseCounterUlpSensor::setup() {
|
||||||
ESP_LOGCONFIG(TAG, "Setting up pulse counter '%s'...", this->name_.c_str());
|
ESP_LOGCONFIG(TAG, "Setting up pulse counter '%s'...", this->name_.c_str());
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
#include "esphome/core/component.h"
|
#include "esphome/core/component.h"
|
||||||
#include "esphome/core/hal.h"
|
#include "esphome/core/hal.h"
|
||||||
#include "esphome/components/sensor/sensor.h"
|
#include "esphome/components/sensor/sensor.h"
|
||||||
#include "driver/rtc_io.h" // For gpio_num_t
|
|
||||||
|
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
@ -14,7 +13,6 @@ namespace pulse_counter_ulp {
|
||||||
|
|
||||||
enum class CountMode { disable = 0, increment = 1, decrement = -1 };
|
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 clock = std::chrono::steady_clock;
|
||||||
using microseconds = std::chrono::duration<uint32_t, std::micro>;
|
using microseconds = std::chrono::duration<uint32_t, std::micro>;
|
||||||
|
|
||||||
|
@ -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_sleep_duration(uint32_t duration_us) { this->config_.sleep_duration_ = duration_us * microseconds{1}; }
|
||||||
void set_debounce(uint16_t debounce) { this->config_.debounce_ = debounce; }
|
void set_debounce(uint16_t debounce) { this->config_.debounce_ = debounce; }
|
||||||
|
|
||||||
/// Unit of measurement is "pulses/min".
|
|
||||||
void setup() override;
|
void setup() override;
|
||||||
void update() override;
|
void update() override;
|
||||||
float get_setup_priority() const override { return setup_priority::DATA; }
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
||||||
|
|
|
@ -94,7 +94,6 @@ async def to_code(config):
|
||||||
"src/CMakeLists.txt",
|
"src/CMakeLists.txt",
|
||||||
os.path.join(os.path.dirname(__file__), "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(
|
esp32.add_extra_build_file(
|
||||||
"ulp/pulse_cnt.S",
|
"ulp/pulse_cnt.S",
|
||||||
os.path.join(os.path.dirname(__file__), "ulp/pulse_cnt.S"),
|
os.path.join(os.path.dirname(__file__), "ulp/pulse_cnt.S"),
|
||||||
|
|
Loading…
Reference in a new issue