Skip to content

Commit

Permalink
feat(led): allow LEDC ISR to be configured onto specific cores (esp-c…
Browse files Browse the repository at this point in the history
…pp#328)

* feat(led): allow LEDC ISR to be configured onto specific cores

* add missing include / dep

* update style of comment
  • Loading branch information
finger563 authored and SquaredPotato committed Jan 27, 2025
1 parent e2f63c6 commit dfebbfe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/led/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
idf_component_register(
INCLUDE_DIRS "include"
REQUIRES base_component driver)
REQUIRES base_component driver task)
20 changes: 15 additions & 5 deletions components/led/include/led.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <freertos/semphr.h>

#include "base_component.hpp"
#include "run_on_core.hpp"

namespace espp {
/**
Expand Down Expand Up @@ -42,9 +43,13 @@ class Led : public BaseComponent {
* channels that should be associated.
*/
struct Config {
ledc_timer_t timer; /**< The LEDC timer that you want associated with the LEDs. */
size_t frequency_hz; /**< The frequency that you want to run the PWM hardawre for the LEDs at.
@note this is inversely related to the duty resolution configuration. */
int isr_core_id = -1; /**< The core to install the LEDC fade function (interrupt) on. If
-1, then the LEDC interrupt is installed on the core that this
constructor is called on. If 0 or 1, then the LEDC interrupt is
installed on the specified core. */
ledc_timer_t timer; /**< The LEDC timer that you want associated with the LEDs. */
size_t frequency_hz; /**< The frequency that you want to run the PWM hardawre for the LEDs at.
@note this is inversely related to the duty resolution configuration. */
std::vector<ChannelConfig> channels; /**< The LED channels that you want to control. */
ledc_timer_bit_t duty_resolution{
LEDC_TIMER_13_BIT}; /**< The resolution of the duty cycle for these LEDs. @note this is
Expand Down Expand Up @@ -94,9 +99,14 @@ class Led : public BaseComponent {
logger_.info("Initializing the fade service");
static bool fade_service_installed = false;
if (!fade_service_installed) {
ledc_fade_func_install(0);
fade_service_installed = true;
auto install_fn = []() -> esp_err_t { return ledc_fade_func_install(0); };
auto err = espp::task::run_on_core(install_fn, config.isr_core_id);
if (err != ESP_OK) {
logger_.error("install ledc fade service failed {}", esp_err_to_name(err));
}
fade_service_installed = err == ESP_OK;
}

ledc_cbs_t callbacks = {.fade_cb = &Led::cb_ledc_fade_end_event};

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

0 comments on commit dfebbfe

Please sign in to comment.