|
10 | 10 | #include <freertos/semphr.h>
|
11 | 11 |
|
12 | 12 | #include "base_component.hpp"
|
| 13 | +#include "run_on_core.hpp" |
13 | 14 |
|
14 | 15 | namespace espp {
|
15 | 16 | /**
|
@@ -42,9 +43,13 @@ class Led : public BaseComponent {
|
42 | 43 | * channels that should be associated.
|
43 | 44 | */
|
44 | 45 | struct Config {
|
45 |
| - ledc_timer_t timer; /**< The LEDC timer that you want associated with the LEDs. */ |
46 |
| - size_t frequency_hz; /**< The frequency that you want to run the PWM hardawre for the LEDs at. |
47 |
| - @note this is inversely related to the duty resolution configuration. */ |
| 46 | + int isr_core_id = -1; /**< The core to install the LEDC fade function (interrupt) on. If |
| 47 | + -1, then the LEDC interrupt is installed on the core that this |
| 48 | + constructor is called on. If 0 or 1, then the LEDC interrupt is |
| 49 | + installed on the specified core. */ |
| 50 | + ledc_timer_t timer; /**< The LEDC timer that you want associated with the LEDs. */ |
| 51 | + size_t frequency_hz; /**< The frequency that you want to run the PWM hardawre for the LEDs at. |
| 52 | + @note this is inversely related to the duty resolution configuration. */ |
48 | 53 | std::vector<ChannelConfig> channels; /**< The LED channels that you want to control. */
|
49 | 54 | ledc_timer_bit_t duty_resolution{
|
50 | 55 | LEDC_TIMER_13_BIT}; /**< The resolution of the duty cycle for these LEDs. @note this is
|
@@ -94,9 +99,14 @@ class Led : public BaseComponent {
|
94 | 99 | logger_.info("Initializing the fade service");
|
95 | 100 | static bool fade_service_installed = false;
|
96 | 101 | if (!fade_service_installed) {
|
97 |
| - ledc_fade_func_install(0); |
98 |
| - fade_service_installed = true; |
| 102 | + auto install_fn = []() -> esp_err_t { return ledc_fade_func_install(0); }; |
| 103 | + auto err = espp::task::run_on_core(install_fn, config.isr_core_id); |
| 104 | + if (err != ESP_OK) { |
| 105 | + logger_.error("install ledc fade service failed {}", esp_err_to_name(err)); |
| 106 | + } |
| 107 | + fade_service_installed = err == ESP_OK; |
99 | 108 | }
|
| 109 | + |
100 | 110 | ledc_cbs_t callbacks = {.fade_cb = &Led::cb_ledc_fade_end_event};
|
101 | 111 |
|
102 | 112 | // we associate each channel with its own semaphore so that they can be
|
|
0 commit comments