Skip to content

Commit c64cb02

Browse files
authored
feat(led): allow LEDC ISR to be configured onto specific cores (#328)
* feat(led): allow LEDC ISR to be configured onto specific cores * add missing include / dep * update style of comment
1 parent 654374c commit c64cb02

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

components/led/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
idf_component_register(
22
INCLUDE_DIRS "include"
3-
REQUIRES base_component driver)
3+
REQUIRES base_component driver task)

components/led/include/led.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <freertos/semphr.h>
1111

1212
#include "base_component.hpp"
13+
#include "run_on_core.hpp"
1314

1415
namespace espp {
1516
/**
@@ -42,9 +43,13 @@ class Led : public BaseComponent {
4243
* channels that should be associated.
4344
*/
4445
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. */
4853
std::vector<ChannelConfig> channels; /**< The LED channels that you want to control. */
4954
ledc_timer_bit_t duty_resolution{
5055
LEDC_TIMER_13_BIT}; /**< The resolution of the duty cycle for these LEDs. @note this is
@@ -94,9 +99,14 @@ class Led : public BaseComponent {
9499
logger_.info("Initializing the fade service");
95100
static bool fade_service_installed = false;
96101
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;
99108
}
109+
100110
ledc_cbs_t callbacks = {.fade_cb = &Led::cb_ledc_fade_end_event};
101111

102112
// we associate each channel with its own semaphore so that they can be

0 commit comments

Comments
 (0)