rp2040/test/
pwm.rs
1use kernel::debug;
35use kernel::hil::pwm::Pwm;
36use kernel::hil::pwm::PwmPin;
37
38use crate::chip::Rp2040DefaultPeripherals;
39use crate::gpio::{GpioFunction, RPGpio};
40
41pub struct PwmTest {
43 peripherals: &'static Rp2040DefaultPeripherals<'static>,
44}
45
46pub fn new(peripherals: &'static Rp2040DefaultPeripherals<'static>) -> PwmTest {
48 PwmTest { peripherals }
49}
50
51impl PwmTest {
52 pub fn hello_pwm(&self) {
54 self.peripherals
55 .pins
56 .get_pin(RPGpio::GPIO14)
57 .set_function(GpioFunction::PWM);
58 self.peripherals
59 .pins
60 .get_pin(RPGpio::GPIO15)
61 .set_function(GpioFunction::PWM);
62 let pwm_pin_14 = self.peripherals.pwm.gpio_to_pwm_pin(RPGpio::GPIO14);
63 let max_freq = pwm_pin_14.get_maximum_frequency_hz();
64 let max_duty_cycle = pwm_pin_14.get_maximum_duty_cycle();
65 assert_eq!(pwm_pin_14.start(max_freq / 8, max_duty_cycle / 2), Ok(()));
66 let pwm = &self.peripherals.pwm;
67 debug!("PWM pin 14 started");
68 let max_freq = pwm.get_maximum_frequency_hz();
69 let max_duty_cycle = pwm.get_maximum_duty_cycle();
70 assert_eq!(
71 pwm.start(&RPGpio::GPIO15, max_freq / 8, max_duty_cycle / 8 * 7),
72 Ok(())
73 );
74 debug!("PWM pin 15 started");
75 }
76}