Skip to content

esp32: cled.cpp.hpp — replace Arduino ledcAttach/ledcSetup/ledcWrite with IDF driver/ledc.h #3719

Closed

Description

@zackees

Part of #3715.

Problem

src/platforms/esp/32/drivers/cled.cpp.hpp (CLED status-LED PWM) still calls the Arduino LEDC wrapper API and forks on the Arduino core version:

  • Line 56–60: #if ESP_ARDUINO_VERSION_MAJOR >= 3 fork (Arduino core 2.x vs 3.x renamed its LEDC API).
  • Line 62: ledcAttach(...) (Arduino 3.x API).
  • Lines 74–75: ledcAttachPin(...) / ledcSetup(...) (Arduino 2.x API).
  • Line 132: ledcWrite(...) fallback when driver/ledc.h is unavailable.
  • Line 14: #include "fl/system/arduino.h" to reach those symbols.

Meanwhile the primary path already uses IDF LEDC (FL_CLED_HAS_LEDC → driver/ledc.h), and src/platforms/esp/32/pin_esp32_native_impl.hpp contains a complete, version-aware native LEDC implementation (ledc_timer_config + ledc_channel_config + ledc_set_duty/ledc_update_duty, including the ledc_find_suitable_duty_resolution (IDF 5.3+) vs manual-resolution fork at line ~275).

Fix

  1. Delete the Arduino LEDC branches and the ESP_ARDUINO_VERSION_MAJOR fork from cled.cpp.hpp; make the IDF driver/ledc.h path unconditional.
  2. Reuse the LEDC setup logic from pin_esp32_native_impl.hpp rather than duplicating it (factor a small shared helper if needed — both files configure a timer + channel + duty).
  3. Remove the fl/system/arduino.h include.

IDF compat notes (3.x/4.x/5.x/6.x)

  • ledc_timer_config_t gained clk_cfg in IDF 4.x and changed default-clock enums again in 5.x (LEDC_AUTO_CLK availability) — gate with esp_version.h predicates, following what pin_esp32_native_impl.hpp already does.
  • ledc_find_suitable_duty_resolution is IDF 5.3+ only; keep the manual fallback.
  • IDF 3.x LEDC used ledc_timer_config_t::bit_num instead of duty_resolution — the idf33 leg will catch this; fork if it bites.

Acceptance criteria

  • No ledcAttach/ledcAttachPin/ledcSetup/ledcWrite calls and no ESP_ARDUINO_VERSION references remain under src/platforms/esp/.
  • CLED status LED still works on an Arduino build (the IDF LEDC driver is bundled with Arduino-ESP32, so behavior must be identical).
  • All IDF CI legs green.

Activity

  1. added
    type: feature
    platform: esp32
    area: drivers
    on Jul 22, 2026
  2. added a commit that references this issue on Jul 22, 2026
    35c685f
  3. moved this from Triage to Done in FastLED Trackeron Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: driversplatform: esp32type: feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions