Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading