mirror of
https://github.com/esphome/esphome.git
synced 2024-12-03 20:24:14 +01:00
pulse_counter_ulp: Remove unnecessary configuration variables
This commit is contained in:
parent
9c70733028
commit
5f98bf4808
2 changed files with 16 additions and 59 deletions
|
@ -1,12 +1,10 @@
|
|||
#include "pulse_counter_ulp_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
#ifdef CONF_USE_ULP
|
||||
#include "esp32/ulp.h"
|
||||
#include "ulp_main.h"
|
||||
#include "soc/rtc_periph.h"
|
||||
#include "driver/rtc_io.h"
|
||||
#include <esp_sleep.h>
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace pulse_counter {
|
||||
|
@ -142,8 +140,6 @@ 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");
|
||||
|
||||
|
@ -239,8 +235,6 @@ pulse_counter_t UlpPulseCounterStorage::read_raw_value() {
|
|||
return count;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* === END ULP ===*/
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,8 +24,6 @@ from esphome.const import (
|
|||
)
|
||||
from esphome.core import CORE
|
||||
|
||||
CONF_USE_PCNT = "use_pcnt"
|
||||
CONF_USE_ULP = "use_ulp"
|
||||
CONF_STORAGE_ID = "storage"
|
||||
|
||||
pulse_counter_ns = cg.esphome_ns.namespace("pulse_counter")
|
||||
|
@ -47,26 +45,6 @@ SetTotalPulsesAction = pulse_counter_ns.class_(
|
|||
)
|
||||
|
||||
|
||||
def validate_internal_filter(value):
|
||||
use_pcnt = value.get(CONF_USE_PCNT)
|
||||
use_ulp = value.get(CONF_USE_ULP)
|
||||
|
||||
if CORE.is_esp8266 and (use_pcnt or use_ulp):
|
||||
raise cv.Invalid(
|
||||
"Using hardware pulse counters is only available on ESP32",
|
||||
[CONF_USE_PCNT],
|
||||
)
|
||||
|
||||
if CORE.is_esp32 and use_pcnt:
|
||||
if value.get(CONF_INTERNAL_FILTER).total_microseconds > 13:
|
||||
raise cv.Invalid(
|
||||
"Maximum internal filter value when using ESP32 hardware PCNT is 13us",
|
||||
[CONF_INTERNAL_FILTER],
|
||||
)
|
||||
|
||||
return value
|
||||
|
||||
|
||||
def validate_pulse_counter_pin(value):
|
||||
value = pins.internal_gpio_input_pin_schema(value)
|
||||
if CORE.is_esp8266 and value[CONF_NUMBER] >= 16:
|
||||
|
@ -113,8 +91,6 @@ CONFIG_SCHEMA = cv.All(
|
|||
),
|
||||
validate_count_mode,
|
||||
),
|
||||
cv.SplitDefault(CONF_USE_PCNT, esp32=True): cv.boolean,
|
||||
cv.Optional(CONF_USE_ULP): cv.boolean,
|
||||
cv.Optional(
|
||||
CONF_INTERNAL_FILTER, default="13us"
|
||||
): cv.positive_time_period_microseconds,
|
||||
|
@ -131,39 +107,26 @@ CONFIG_SCHEMA = cv.All(
|
|||
},
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s")),
|
||||
validate_internal_filter,
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
if config.get(CONF_USE_ULP):
|
||||
cg.add_define("CONF_USE_ULP", True)
|
||||
storage = cg.Pvariable(
|
||||
config[CONF_STORAGE_ID],
|
||||
cg.RawExpression("new pulse_counter::UlpPulseCounterStorage()"),
|
||||
)
|
||||
esp32.add_extra_build_file(
|
||||
"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"),
|
||||
)
|
||||
esp32.add_idf_sdkconfig_option("CONFIG_ULP_COPROC_ENABLED", True)
|
||||
esp32.add_idf_sdkconfig_option("CONFIG_ULP_COPROC_TYPE_FSM", True)
|
||||
esp32.add_idf_sdkconfig_option("CONFIG_ULP_COPROC_RESERVE_MEM", 1024)
|
||||
elif config.get(CONF_USE_PCNT):
|
||||
storage = cg.Pvariable(
|
||||
config[CONF_STORAGE_ID],
|
||||
cg.RawExpression("new pulse_counter::HwPulseCounterStorage()"),
|
||||
)
|
||||
else:
|
||||
storage = cg.Pvariable(
|
||||
config[CONF_STORAGE_ID],
|
||||
cg.RawExpression("new pulse_counter::BasicPulseCounterStorage()"),
|
||||
)
|
||||
storage = cg.Pvariable(
|
||||
config[CONF_STORAGE_ID],
|
||||
cg.RawExpression("new pulse_counter::UlpPulseCounterStorage()"),
|
||||
)
|
||||
esp32.add_extra_build_file(
|
||||
"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"),
|
||||
)
|
||||
esp32.add_idf_sdkconfig_option("CONFIG_ULP_COPROC_ENABLED", True)
|
||||
esp32.add_idf_sdkconfig_option("CONFIG_ULP_COPROC_TYPE_FSM", True)
|
||||
esp32.add_idf_sdkconfig_option("CONFIG_ULP_COPROC_RESERVE_MEM", 1024)
|
||||
var = await sensor.new_sensor(config, storage)
|
||||
await cg.register_component(var, config)
|
||||
|
||||
|
|
Loading…
Reference in a new issue