Module esp32c3_hal::ledc

source ·
Expand description

LEDC (LED PWM Controller) peripheral control

Currently only supports fixed-frequency output. Hardware fade support and interrupts are not currently implemented. High Speed channels are availble for the ESP32 only, while Low Speed channels are available for all supported chips.

LowSpeed Example:

The following will configure the Low Speed Channel0 to 24kHz output with 10% duty using the ABPClock

let mut ledc = LEDC::new(peripherals.LEDC, &clock_control, &mut system.peripheral_clock_control);
ledc.set_global_slow_clock(LSGlobalClkSource::APBClk);

let mut lstimer0 = ledc.get_timer::<LowSpeed>(timer::Number::Timer0);
lstimer0
.configure(timer::config::Config {
           duty: timer::config::Duty::Duty5Bit,
           clock_source: timer::LSClockSource::APBClk,
           frequency: 24u32.kHz(),
       })
       .unwrap();

let mut channel0 = ledc.get_channel(channel::Number::Channel0, led);
channel0
    .configure(channel::config::Config {
        timer: &lstimer0,
        duty: 10,
    })
    .unwrap();

HighSpeed Example (ESP32 only):

The following will configure the High Speed Channel0 to 24kHz output with 10% duty using the ABPClock

let ledc = LEDC::new(peripherals.LEDC, &clock_control, &mut system.peripheral_clock_control);

let mut hstimer0 = ledc.get_timer::<HighSpeed>(timer::Number::Timer0);
hstimer0
.configure(timer::config::Config {
           duty: timer::config::Duty::Duty5Bit,
           clock_source: timer::HSClockSource::APBClk,
           frequency: 24u32.kHz(),
       })
       .unwrap();

let mut channel0 = ledc.get_channel(channel::Number::Channel0, led);
channel0
    .configure(channel::config::Config {
        timer: &hstimer0,
        duty: 10,
    })
    .unwrap();

TODO

  • Source clock selection
  • Hardware fade support
  • Interrupts

Modules

Structs

  • LEDC (LED PWM Controller)
  • Used to specify LowSpeed Timer/Channel

Enums

Traits