Allow use of all pulse count unit channels if needed. (#7550)

This commit is contained in:
Tobias Hoff 2024-10-06 21:53:57 +02:00 committed by GitHub
parent 6a8e88b1cc
commit e31a96bfe2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -53,12 +53,19 @@ pulse_counter_t BasicPulseCounterStorage::read_raw_value() {
#ifdef HAS_PCNT
bool HwPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) {
static pcnt_unit_t next_pcnt_unit = PCNT_UNIT_0;
static pcnt_channel_t next_pcnt_channel = PCNT_CHANNEL_0;
this->pin = pin;
this->pin->setup();
this->pcnt_unit = next_pcnt_unit;
this->pcnt_channel = next_pcnt_channel;
next_pcnt_unit = pcnt_unit_t(int(next_pcnt_unit) + 1);
if (int(next_pcnt_unit) >= PCNT_UNIT_0 + PCNT_UNIT_MAX) {
next_pcnt_unit = PCNT_UNIT_0;
next_pcnt_channel = pcnt_channel_t(int(next_pcnt_channel) + 1);
}
ESP_LOGCONFIG(TAG, " PCNT Unit Number: %u", this->pcnt_unit);
ESP_LOGCONFIG(TAG, " PCNT Channel Number: %u", this->pcnt_channel);
pcnt_count_mode_t rising = PCNT_COUNT_DIS, falling = PCNT_COUNT_DIS;
switch (this->rising_edge_mode) {
@ -94,7 +101,7 @@ bool HwPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) {
.counter_h_lim = 0,
.counter_l_lim = 0,
.unit = this->pcnt_unit,
.channel = PCNT_CHANNEL_0,
.channel = this->pcnt_channel,
};
esp_err_t error = pcnt_unit_config(&pcnt_config);
if (error != ESP_OK) {

View File

@ -55,6 +55,7 @@ struct HwPulseCounterStorage : public PulseCounterStorageBase {
pulse_counter_t read_raw_value() override;
pcnt_unit_t pcnt_unit;
pcnt_channel_t pcnt_channel;
};
#endif