mirror of
https://github.com/esphome/esphome.git
synced 2026-06-02 03:02:19 +08:00
[ac_dimmer] Use a shared ESP32 GPTimer for multiple dimmers (#13523)
Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com>
This commit is contained in:
@@ -199,12 +199,19 @@ void AcDimmer::setup() {
|
|||||||
setTimer1Callback(&timer_interrupt);
|
setTimer1Callback(&timer_interrupt);
|
||||||
#endif
|
#endif
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
|
if (dimmer_timer == nullptr) {
|
||||||
dimmer_timer = timer_begin(TIMER_FREQUENCY_HZ);
|
dimmer_timer = timer_begin(TIMER_FREQUENCY_HZ);
|
||||||
|
if (dimmer_timer == nullptr) {
|
||||||
|
ESP_LOGE(TAG, "Failed to create GPTimer for AC dimmer");
|
||||||
|
this->mark_failed();
|
||||||
|
return;
|
||||||
|
}
|
||||||
timer_attach_interrupt(dimmer_timer, &AcDimmerDataStore::s_timer_intr);
|
timer_attach_interrupt(dimmer_timer, &AcDimmerDataStore::s_timer_intr);
|
||||||
// For ESP32, we can't use dynamic interval calculation because the timerX functions
|
// For ESP32, we can't use dynamic interval calculation because the timerX functions
|
||||||
// are not callable from ISR (placed in flash storage).
|
// are not callable from ISR (placed in flash storage).
|
||||||
// Here we just use an interrupt firing every 50 µs.
|
// Here we just use an interrupt firing every 50 µs.
|
||||||
timer_alarm(dimmer_timer, TIMER_INTERVAL_US, true, 0);
|
timer_alarm(dimmer_timer, TIMER_INTERVAL_US, true, 0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user