Skip to content

Commit

Permalink
Merge pull request tock#4219 from alevy/rp2040-pio-nit
Browse files Browse the repository at this point in the history
rp2040: pio: replace unnecessary OptionalCell
  • Loading branch information
alevy authored Nov 3, 2024
2 parents 7d9d16b + 39c2836 commit f363a97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
3 changes: 1 addition & 2 deletions boards/pico_explorer_base/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,7 @@ pub unsafe fn start() -> (

let mut pio: Pio = Pio::new_pio0();

let pio_pwm = PioPwm::new(&mut pio);
pio_pwm.set_clocks(&peripherals.clocks);
let _pio_pwm = PioPwm::new(&mut pio, &peripherals.clocks);
// This will start a PWM with PIO with the set frequency and duty cycle on the specified pin.
// pio_pwm
// .start(
Expand Down
16 changes: 5 additions & 11 deletions chips/rp2040/src/pio_pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@ use crate::clocks::{self};
use crate::gpio::RPGpio;
use crate::pio::{PIONumber, Pio, SMNumber, StateMachineConfiguration};

use kernel::utilities::cells::{OptionalCell, TakeCell};
use kernel::utilities::cells::TakeCell;
use kernel::{hil, ErrorCode};

pub struct PioPwm<'a> {
clocks: OptionalCell<&'a clocks::Clocks>,
clocks: &'a clocks::Clocks,
pio: TakeCell<'a, Pio>,
}

impl<'a> PioPwm<'a> {
pub fn new(pio: &'a mut Pio) -> Self {
pub fn new(pio: &'a mut Pio, clocks: &'a clocks::Clocks) -> Self {
Self {
clocks: OptionalCell::empty(),
clocks,
pio: TakeCell::new(pio),
}
}

pub fn set_clocks(&self, clocks: &'a clocks::Clocks) {
self.clocks.set(clocks);
}
}

impl<'a> hil::pwm::Pwm for PioPwm<'a> {
Expand Down Expand Up @@ -101,8 +97,6 @@ impl<'a> hil::pwm::Pwm for PioPwm<'a> {
// For the rp2040, this will always return 125_000_000. Watch out as any value above
// 1_000_000 is not precise and WILL give modified frequency and duty cycle values.
fn get_maximum_frequency_hz(&self) -> usize {
self.clocks
.unwrap_or_panic()
.get_frequency(clocks::Clock::System) as usize
self.clocks.get_frequency(clocks::Clock::System) as usize
}
}

0 comments on commit f363a97

Please sign in to comment.