use esp_idf_hal::delay::FreeRtos;
use esp_idf_hal::ledc::*;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::prelude::*;

fn main() -> anyhow::Result<()> {
    esp_idf_sys::link_patches();

    println!("Configuring output channel");

    let peripherals = Peripherals::take().unwrap();
    let mut channel = LedcDriver::new(
        peripherals.ledc.channel0,
        LedcTimerDriver::new(
            peripherals.ledc.timer0,
            &config::TimerConfig::new().frequency(25.kHz().into()),
        )?,
        peripherals.pins.gpio3,
    )?;

    println!("Starting duty-cycle loop");

    loop {
        let mut duty = 0;
        let max_duty = channel.get_max_duty();
        
        while duty < max_duty {
            channel.set_duty(duty)?;
            FreeRtos::delay_ms(1);
            duty += 5;
        }

        while duty > 0 {
            channel.set_duty(duty)?;
            FreeRtos::delay_ms(1);
            duty -= 5;
        }
    }
}
$abcdeabcde151015202530fghijfghij