Skip to content

Commit

Permalink
Merge pull request tock#4179 from mateir-7/pio-final
Browse files Browse the repository at this point in the history
PIO support for RP2040
  • Loading branch information
alevy authored Oct 20, 2024
2 parents e2aa263 + 1912a83 commit 87fade8
Show file tree
Hide file tree
Showing 5 changed files with 1,540 additions and 5 deletions.
20 changes: 15 additions & 5 deletions boards/pico_explorer_base/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ 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 All @@ -34,6 +35,8 @@ use rp2040::clocks::{
SystemAuxiliaryClockSource, SystemClockSource, UsbAuxiliaryClockSource,
};
use rp2040::gpio::{GpioFunction, RPGpio, RPGpioPin};
use rp2040::pio::{PIONumber, Pio, SMNumber, StateMachineConfiguration};
use rp2040::pio_pwm::PioPwm;
use rp2040::resets::Peripheral;
use rp2040::spi::Spi;
use rp2040::sysinfo;
Expand Down Expand Up @@ -376,11 +379,8 @@ pub unsafe fn start() -> (
.finalize(components::uart_mux_component_static!());

// Uncomment this to use UART as an output
// let uart_mux = components::console::UartMuxComponent::new(
// &peripherals.uart0,
// 115200,
// )
// .finalize(components::uart_mux_component_static!());
// let uart_mux = components::console::UartMuxComponent::new(&peripherals.uart0, 115200)
// .finalize(components::uart_mux_component_static!());

// Setup the console.
let console = components::console::ConsoleComponent::new(
Expand Down Expand Up @@ -694,6 +694,16 @@ pub unsafe fn start() -> (
debug!("{:?}", err);
});

//--------------------------------------------------------------------------
// PIO
//--------------------------------------------------------------------------

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

let pio_pwm = PioPwm::new(&mut pio);
pio_pwm.set_clocks(&peripherals.clocks);
pio_pwm.start(&RPGpio::GPIO7, 12_500_000, 50).unwrap();

(board_kernel, pico_explorer_base, chip)
}

Expand Down
12 changes: 12 additions & 0 deletions chips/rp2040/src/chip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::clocks::Clocks;
use crate::gpio::{RPGpio, RPPins, SIO};
use crate::i2c;
use crate::interrupts;
use crate::pio::Pio;
use crate::pwm;
use crate::resets::Resets;
use crate::rtc;
Expand Down Expand Up @@ -123,6 +124,8 @@ pub struct Rp2040DefaultPeripherals<'a> {
pub clocks: Clocks,
pub i2c0: i2c::I2c<'a, 'a>,
pub pins: RPPins<'a>,
pub pio0: Pio,
pub pio1: Pio,
pub pwm: pwm::Pwm<'a>,
pub resets: Resets,
pub sio: SIO,
Expand All @@ -144,6 +147,8 @@ impl<'a> Rp2040DefaultPeripherals<'a> {
clocks: Clocks::new(),
i2c0: i2c::I2c::new_i2c0(),
pins: RPPins::new(),
pio0: Pio::new_pio0(),
pio1: Pio::new_pio1(),
pwm: pwm::Pwm::new(),
resets: Resets::new(),
sio: SIO::new(),
Expand Down Expand Up @@ -176,6 +181,13 @@ impl<'a> Rp2040DefaultPeripherals<'a> {
impl InterruptService for Rp2040DefaultPeripherals<'_> {
unsafe fn service_interrupt(&self, interrupt: u32) -> bool {
match interrupt {
interrupts::PIO0_IRQ_0 => {
// As the current PIO interface does not provide support for interrupts, they are
// simply ignored.
//
// Note that PIO interrupts are raised only during unit tests.
true
}
interrupts::TIMER_IRQ_0 => {
self.timer.handle_interrupt();
true
Expand Down
2 changes: 2 additions & 0 deletions chips/rp2040/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod deferred_calls;
pub mod gpio;
pub mod i2c;
pub mod interrupts;
pub mod pio;
pub mod pio_pwm;
pub mod pwm;
pub mod resets;
pub mod rtc;
Expand Down
Loading

0 comments on commit 87fade8

Please sign in to comment.