Skip to content

Commit

Permalink
Merge pull request tock#4212 from mateir-7/pio-final
Browse files Browse the repository at this point in the history
Pio last update
  • Loading branch information
lschuermann authored Oct 23, 2024
2 parents 0ee6231 + 00d99a8 commit 9ae0348
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions boards/pico_explorer_base/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use components::led::LedsComponent;
use enum_primitive::cast::FromPrimitive;
use kernel::component::Component;
use kernel::hil::led::LedHigh;
use kernel::hil::pwm::Pwm;
use kernel::hil::usb::Client;
use kernel::platform::{KernelResources, SyscallDriverLookup};
use kernel::scheduler::round_robin::RoundRobinSched;
Expand Down Expand Up @@ -702,7 +701,14 @@ pub unsafe fn start() -> (

let pio_pwm = PioPwm::new(&mut pio);
pio_pwm.set_clocks(&peripherals.clocks);
pio_pwm.start(&RPGpio::GPIO7, 12_500_000, 50).unwrap();
// This will start a PWM with PIO with the set frequency and duty cycle on the specified pin.
// pio_pwm
// .start(
// &RPGpio::GPIO7,
// pio_pwm.get_maximum_frequency_hz() / 125000, /*1_000*/
// pio_pwm.get_maximum_duty_cycle() / 2,
// )
// .unwrap();

(board_kernel, pico_explorer_base, chip)
}
Expand Down
6 changes: 4 additions & 2 deletions chips/rp2040/src/pio_pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a> hil::pwm::Pwm for PioPwm<'a> {
custom_config.side_set_opt_enable = true;
custom_config.side_set_pindirs = false;
let max_freq = self.get_maximum_frequency_hz();
let pwm_period = (max_freq / frequency_hz) as u32;
let pwm_period = ((max_freq / frequency_hz) / 3) as u32;
let sm_number = SMNumber::SM0;
let duty_cycle = duty_cycle_percentage as u32;
pio.pwm_program_init(
Expand All @@ -94,10 +94,12 @@ impl<'a> hil::pwm::Pwm for PioPwm<'a> {
}

fn get_maximum_duty_cycle(&self) -> usize {
// being a percentage, max duty cycle is 100
// being a percentage out of 10000, max duty cycle is 10000
10000
}

// 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()
Expand Down

0 comments on commit 9ae0348

Please sign in to comment.