mirror of
https://github.com/esphome/esphome.git
synced 2024-11-23 15:38:11 +01:00
pulse_counter: conditionally compile ULP
This commit is contained in:
parent
30d4a7fb34
commit
fe533952cc
2 changed files with 12 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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"),
|
||||
|
|
Loading…
Reference in a new issue