embassy/examples/rp/src/bin/pwm.rs
Dario Nieuwenhuis 2fcdfc4876 rp: don't use SetConfig trait in PWM and PIO.
It was intended to allow changing baudrate on shared spi/i2c. There's no
advantage in using it for PWM or PIO, and makes it less usable because you have to
have `embassy-embedded-hal` as a dep to use it.
2023-05-13 02:13:26 +02:00

27 lines
698 B
Rust

#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::*;
use embassy_executor::Spawner;
use embassy_rp::pwm::{Config, Pwm};
use embassy_time::{Duration, Timer};
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let mut c: Config = Default::default();
c.top = 0x8000;
c.compare_b = 8;
let mut pwm = Pwm::new_output_b(p.PWM_CH4, p.PIN_25, c.clone());
loop {
info!("current LED duty cycle: {}/32768", c.compare_b);
Timer::after(Duration::from_secs(1)).await;
c.compare_b = c.compare_b.rotate_left(4);
pwm.set_config(&c);
}
}