pulse_counter: conditionally compile ULP

This commit is contained in:
brisk 2024-04-04 21:35:00 +10:30
parent 30d4a7fb34
commit fe533952cc
2 changed files with 12 additions and 2 deletions

View file

@ -1,10 +1,11 @@
#include "pulse_counter_sensor.h" #include "pulse_counter_sensor.h"
#include "esphome/core/log.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 "esp32/ulp.h"
#include "ulp_main.h" #include "ulp_main.h"
#include "soc/rtc_periph.h" #include "soc/rtc_periph.h"
#include "driver/rtc_io.h" #include "driver/rtc_io.h"
#endif
namespace esphome { namespace esphome {
namespace pulse_counter { namespace pulse_counter {
@ -20,8 +21,12 @@ PulseCounterStorageBase *get_storage(Storage storage) {
return new BasicPulseCounterStorage; return new BasicPulseCounterStorage;
case Storage::pcnt: case Storage::pcnt:
return new HwPulseCounterStorage; return new HwPulseCounterStorage;
#ifdef CONF_USE_ULP
case Storage::ulp: case Storage::ulp:
return new UlpPulseCounterStorage; return new UlpPulseCounterStorage;
#endif
default:
return new BasicPulseCounterStorage;
} }
return new BasicPulseCounterStorage; return new BasicPulseCounterStorage;
} }
@ -156,6 +161,8 @@ pulse_counter_t HwPulseCounterStorage::read_raw_value() {
/* === ULP === */ /* === 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_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");
@ -241,11 +248,13 @@ bool UlpPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) {
pulse_counter_t UlpPulseCounterStorage::read_raw_value() { pulse_counter_t UlpPulseCounterStorage::read_raw_value() {
// TODO count edges separately // TODO count edges separately
uint32_t count = (ulp_edge_count & UINT16_MAX) / 2; uint32_t count = ulp_edge_count;
ulp_edge_count = 0; ulp_edge_count = 0;
return count; return count;
} }
#endif
/* === END ULP ===*/ /* === END ULP ===*/
#endif #endif

View file

@ -134,6 +134,7 @@ async def to_code(config):
else: else:
var = await sensor.new_sensor(config, config.get(CONF_USE_PCNT)) var = await sensor.new_sensor(config, config.get(CONF_USE_PCNT))
if config.get(CONF_USE_ULP): if config.get(CONF_USE_ULP):
var.add_define("CONF_USE_ULP", True)
esp32.add_extra_build_file( esp32.add_extra_build_file(
"src/CMakeLists.txt", "src/CMakeLists.txt",
os.path.join(os.path.dirname(__file__), "CMakeLists.txt"), os.path.join(os.path.dirname(__file__), "CMakeLists.txt"),