mirror of
https://github.com/esphome/esphome.git
synced 2024-12-20 16:18:49 +01:00
[pulse_counter] Fix volatile increment/decrement deprecation warnings (#7954)
This commit is contained in:
parent
88742e0399
commit
ce7ff15c8a
@ -13,9 +13,9 @@ PulseCounterStorageBase *get_storage(bool hw_pcnt) {
|
|||||||
return (hw_pcnt ? (PulseCounterStorageBase *) (new HwPulseCounterStorage)
|
return (hw_pcnt ? (PulseCounterStorageBase *) (new HwPulseCounterStorage)
|
||||||
: (PulseCounterStorageBase *) (new BasicPulseCounterStorage));
|
: (PulseCounterStorageBase *) (new BasicPulseCounterStorage));
|
||||||
}
|
}
|
||||||
#else
|
#else // HAS_PCNT
|
||||||
PulseCounterStorageBase *get_storage(bool) { return new BasicPulseCounterStorage; }
|
PulseCounterStorageBase *get_storage(bool) { return new BasicPulseCounterStorage; }
|
||||||
#endif
|
#endif // HAS_PCNT
|
||||||
|
|
||||||
void IRAM_ATTR BasicPulseCounterStorage::gpio_intr(BasicPulseCounterStorage *arg) {
|
void IRAM_ATTR BasicPulseCounterStorage::gpio_intr(BasicPulseCounterStorage *arg) {
|
||||||
const uint32_t now = micros();
|
const uint32_t now = micros();
|
||||||
@ -28,14 +28,17 @@ void IRAM_ATTR BasicPulseCounterStorage::gpio_intr(BasicPulseCounterStorage *arg
|
|||||||
switch (mode) {
|
switch (mode) {
|
||||||
case PULSE_COUNTER_DISABLE:
|
case PULSE_COUNTER_DISABLE:
|
||||||
break;
|
break;
|
||||||
case PULSE_COUNTER_INCREMENT:
|
case PULSE_COUNTER_INCREMENT: {
|
||||||
arg->counter++;
|
auto x = arg->counter + 1;
|
||||||
break;
|
arg->counter = x;
|
||||||
case PULSE_COUNTER_DECREMENT:
|
} break;
|
||||||
arg->counter--;
|
case PULSE_COUNTER_DECREMENT: {
|
||||||
break;
|
auto x = arg->counter - 1;
|
||||||
|
arg->counter = x;
|
||||||
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BasicPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) {
|
bool BasicPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) {
|
||||||
this->pin = pin;
|
this->pin = pin;
|
||||||
this->pin->setup();
|
this->pin->setup();
|
||||||
@ -43,6 +46,7 @@ bool BasicPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) {
|
|||||||
this->pin->attach_interrupt(BasicPulseCounterStorage::gpio_intr, this, gpio::INTERRUPT_ANY_EDGE);
|
this->pin->attach_interrupt(BasicPulseCounterStorage::gpio_intr, this, gpio::INTERRUPT_ANY_EDGE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pulse_counter_t BasicPulseCounterStorage::read_raw_value() {
|
pulse_counter_t BasicPulseCounterStorage::read_raw_value() {
|
||||||
pulse_counter_t counter = this->counter;
|
pulse_counter_t counter = this->counter;
|
||||||
pulse_counter_t ret = counter - this->last_value;
|
pulse_counter_t ret = counter - this->last_value;
|
||||||
@ -141,6 +145,7 @@ bool HwPulseCounterStorage::pulse_counter_setup(InternalGPIOPin *pin) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
pulse_counter_t HwPulseCounterStorage::read_raw_value() {
|
pulse_counter_t HwPulseCounterStorage::read_raw_value() {
|
||||||
pulse_counter_t counter;
|
pulse_counter_t counter;
|
||||||
pcnt_get_counter_value(this->pcnt_unit, &counter);
|
pcnt_get_counter_value(this->pcnt_unit, &counter);
|
||||||
@ -148,7 +153,7 @@ pulse_counter_t HwPulseCounterStorage::read_raw_value() {
|
|||||||
this->last_value = counter;
|
this->last_value = counter;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif // HAS_PCNT
|
||||||
|
|
||||||
void PulseCounterSensor::setup() {
|
void PulseCounterSensor::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());
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3)
|
#if defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3)
|
||||||
#include <driver/pcnt.h>
|
#include <driver/pcnt.h>
|
||||||
#define HAS_PCNT
|
#define HAS_PCNT
|
||||||
#endif
|
#endif // defined(USE_ESP32) && !defined(USE_ESP32_VARIANT_ESP32C3)
|
||||||
|
|
||||||
namespace esphome {
|
namespace esphome {
|
||||||
namespace pulse_counter {
|
namespace pulse_counter {
|
||||||
@ -22,9 +22,9 @@ enum PulseCounterCountMode {
|
|||||||
|
|
||||||
#ifdef HAS_PCNT
|
#ifdef HAS_PCNT
|
||||||
using pulse_counter_t = int16_t;
|
using pulse_counter_t = int16_t;
|
||||||
#else
|
#else // HAS_PCNT
|
||||||
using pulse_counter_t = int32_t;
|
using pulse_counter_t = int32_t;
|
||||||
#endif
|
#endif // HAS_PCNT
|
||||||
|
|
||||||
struct PulseCounterStorageBase {
|
struct PulseCounterStorageBase {
|
||||||
virtual bool pulse_counter_setup(InternalGPIOPin *pin) = 0;
|
virtual bool pulse_counter_setup(InternalGPIOPin *pin) = 0;
|
||||||
@ -57,7 +57,7 @@ struct HwPulseCounterStorage : public PulseCounterStorageBase {
|
|||||||
pcnt_unit_t pcnt_unit;
|
pcnt_unit_t pcnt_unit;
|
||||||
pcnt_channel_t pcnt_channel;
|
pcnt_channel_t pcnt_channel;
|
||||||
};
|
};
|
||||||
#endif
|
#endif // HAS_PCNT
|
||||||
|
|
||||||
PulseCounterStorageBase *get_storage(bool hw_pcnt = false);
|
PulseCounterStorageBase *get_storage(bool hw_pcnt = false);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user