From d41eeeae79388f219bf6a84e2f7bde9f6b532516 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 26 Mar 2025 16:01:37 +0100 Subject: Remove Peripheral trait, rename PeripheralRef->Peri. --- embassy-rp/src/pio_programs/hd44780.rs | 24 +++++++------- embassy-rp/src/pio_programs/i2s.rs | 39 ++++++++++------------- embassy-rp/src/pio_programs/onewire.rs | 3 +- embassy-rp/src/pio_programs/pwm.rs | 4 +-- embassy-rp/src/pio_programs/rotary_encoder.rs | 5 +-- embassy-rp/src/pio_programs/stepper.rs | 9 +++--- embassy-rp/src/pio_programs/uart.rs | 45 ++++++++++++++------------- embassy-rp/src/pio_programs/ws2812.rs | 15 +++------ 8 files changed, 68 insertions(+), 76 deletions(-) (limited to 'embassy-rp/src/pio_programs') diff --git a/embassy-rp/src/pio_programs/hd44780.rs b/embassy-rp/src/pio_programs/hd44780.rs index 6997b91f3..5846a8027 100644 --- a/embassy-rp/src/pio_programs/hd44780.rs +++ b/embassy-rp/src/pio_programs/hd44780.rs @@ -5,7 +5,7 @@ use crate::pio::{ Common, Config, Direction, FifoJoin, Instance, Irq, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine, }; -use crate::{into_ref, Peripheral, PeripheralRef}; +use crate::Peri; /// This struct represents a HD44780 program that takes command words ( <0:4>) pub struct PioHD44780CommandWordProgram<'a, PIO: Instance> { @@ -99,7 +99,7 @@ impl<'a, PIO: Instance> PioHD44780CommandSequenceProgram<'a, PIO> { /// Pio backed HD44780 driver pub struct PioHD44780<'l, P: Instance, const S: usize> { - dma: PeripheralRef<'l, AnyChannel>, + dma: Peri<'l, AnyChannel>, sm: StateMachine<'l, P, S>, buf: [u8; 40], @@ -111,19 +111,17 @@ impl<'l, P: Instance, const S: usize> PioHD44780<'l, P, S> { common: &mut Common<'l, P>, mut sm: StateMachine<'l, P, S>, mut irq: Irq<'l, P, S>, - dma: impl Peripheral

+ 'l, - rs: impl PioPin, - rw: impl PioPin, - e: impl PioPin, - db4: impl PioPin, - db5: impl PioPin, - db6: impl PioPin, - db7: impl PioPin, + mut dma: Peri<'l, impl Channel>, + rs: Peri<'l, impl PioPin>, + rw: Peri<'l, impl PioPin>, + e: Peri<'l, impl PioPin>, + db4: Peri<'l, impl PioPin>, + db5: Peri<'l, impl PioPin>, + db6: Peri<'l, impl PioPin>, + db7: Peri<'l, impl PioPin>, word_prg: &PioHD44780CommandWordProgram<'l, P>, seq_prg: &PioHD44780CommandSequenceProgram<'l, P>, ) -> PioHD44780<'l, P, S> { - into_ref!(dma); - let rs = common.make_pio_pin(rs); let rw = common.make_pio_pin(rw); let e = common.make_pio_pin(e); @@ -176,7 +174,7 @@ impl<'l, P: Instance, const S: usize> PioHD44780<'l, P, S> { sm.tx().dma_push(dma.reborrow(), &[0x81u8, 0x0f, 1], false).await; Self { - dma: dma.map_into(), + dma: dma.into(), sm, buf: [0x20; 40], } diff --git a/embassy-rp/src/pio_programs/i2s.rs b/embassy-rp/src/pio_programs/i2s.rs index 17e321405..b967f0160 100644 --- a/embassy-rp/src/pio_programs/i2s.rs +++ b/embassy-rp/src/pio_programs/i2s.rs @@ -6,16 +6,16 @@ use crate::dma::{AnyChannel, Channel, Transfer}; use crate::pio::{ Common, Config, Direction, FifoJoin, Instance, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine, }; -use crate::{into_ref, Peripheral, PeripheralRef}; +use crate::Peri; /// This struct represents an i2s output driver program -pub struct PioI2sOutProgram<'a, PIO: Instance> { - prg: LoadedProgram<'a, PIO>, +pub struct PioI2sOutProgram<'d, PIO: Instance> { + prg: LoadedProgram<'d, PIO>, } -impl<'a, PIO: Instance> PioI2sOutProgram<'a, PIO> { +impl<'d, PIO: Instance> PioI2sOutProgram<'d, PIO> { /// Load the program into the given pio - pub fn new(common: &mut Common<'a, PIO>) -> Self { + pub fn new(common: &mut Common<'d, PIO>) -> Self { let prg = pio::pio_asm!( ".side_set 2", " set x, 14 side 0b01", // side 0bWB - W = Word Clock, B = Bit Clock @@ -37,27 +37,25 @@ impl<'a, PIO: Instance> PioI2sOutProgram<'a, PIO> { } /// Pio backed I2s output driver -pub struct PioI2sOut<'a, P: Instance, const S: usize> { - dma: PeripheralRef<'a, AnyChannel>, - sm: StateMachine<'a, P, S>, +pub struct PioI2sOut<'d, P: Instance, const S: usize> { + dma: Peri<'d, AnyChannel>, + sm: StateMachine<'d, P, S>, } -impl<'a, P: Instance, const S: usize> PioI2sOut<'a, P, S> { +impl<'d, P: Instance, const S: usize> PioI2sOut<'d, P, S> { /// Configure a state machine to output I2s pub fn new( - common: &mut Common<'a, P>, - mut sm: StateMachine<'a, P, S>, - dma: impl Peripheral

+ 'a, - data_pin: impl PioPin, - bit_clock_pin: impl PioPin, - lr_clock_pin: impl PioPin, + common: &mut Common<'d, P>, + mut sm: StateMachine<'d, P, S>, + dma: Peri<'d, impl Channel>, + data_pin: Peri<'d, impl PioPin>, + bit_clock_pin: Peri<'d, impl PioPin>, + lr_clock_pin: Peri<'d, impl PioPin>, sample_rate: u32, bit_depth: u32, channels: u32, - program: &PioI2sOutProgram<'a, P>, + program: &PioI2sOutProgram<'d, P>, ) -> Self { - into_ref!(dma); - let data_pin = common.make_pio_pin(data_pin); let bit_clock_pin = common.make_pio_pin(bit_clock_pin); let left_right_clock_pin = common.make_pio_pin(lr_clock_pin); @@ -82,10 +80,7 @@ impl<'a, P: Instance, const S: usize> PioI2sOut<'a, P, S> { sm.set_enable(true); - Self { - dma: dma.map_into(), - sm, - } + Self { dma: dma.into(), sm } } /// Return an in-prograss dma transfer future. Awaiting it will guarentee a complete transfer. diff --git a/embassy-rp/src/pio_programs/onewire.rs b/embassy-rp/src/pio_programs/onewire.rs index 040333e76..00783aab0 100644 --- a/embassy-rp/src/pio_programs/onewire.rs +++ b/embassy-rp/src/pio_programs/onewire.rs @@ -1,6 +1,7 @@ //! OneWire pio driver use crate::pio::{Common, Config, Instance, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine}; +use crate::Peri; /// This struct represents an onewire driver program pub struct PioOneWireProgram<'a, PIO: Instance> { @@ -69,7 +70,7 @@ impl<'d, PIO: Instance, const SM: usize> PioOneWire<'d, PIO, SM> { pub fn new( common: &mut Common<'d, PIO>, mut sm: StateMachine<'d, PIO, SM>, - pin: impl PioPin, + pin: Peri<'d, impl PioPin>, program: &PioOneWireProgram<'d, PIO>, ) -> Self { let pin = common.make_pio_pin(pin); diff --git a/embassy-rp/src/pio_programs/pwm.rs b/embassy-rp/src/pio_programs/pwm.rs index 01ffe012a..f0f837bc5 100644 --- a/embassy-rp/src/pio_programs/pwm.rs +++ b/embassy-rp/src/pio_programs/pwm.rs @@ -4,9 +4,9 @@ use core::time::Duration; use pio::InstructionOperands; -use crate::clocks; use crate::gpio::Level; use crate::pio::{Common, Config, Direction, Instance, LoadedProgram, Pin, PioPin, StateMachine}; +use crate::{clocks, Peri}; /// This converts the duration provided into the number of cycles the PIO needs to run to make it take the same time fn to_pio_cycles(duration: Duration) -> u32 { @@ -52,7 +52,7 @@ impl<'d, T: Instance, const SM: usize> PioPwm<'d, T, SM> { pub fn new( pio: &mut Common<'d, T>, mut sm: StateMachine<'d, T, SM>, - pin: impl PioPin, + pin: Peri<'d, impl PioPin>, program: &PioPwmProgram<'d, T>, ) -> Self { let pin = pio.make_pio_pin(pin); diff --git a/embassy-rp/src/pio_programs/rotary_encoder.rs b/embassy-rp/src/pio_programs/rotary_encoder.rs index f2fb02aca..e520da8a3 100644 --- a/embassy-rp/src/pio_programs/rotary_encoder.rs +++ b/embassy-rp/src/pio_programs/rotary_encoder.rs @@ -6,6 +6,7 @@ use crate::gpio::Pull; use crate::pio::{ Common, Config, Direction as PioDirection, FifoJoin, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine, }; +use crate::Peri; /// This struct represents an Encoder program loaded into pio instruction memory. pub struct PioEncoderProgram<'a, PIO: Instance> { @@ -33,8 +34,8 @@ impl<'d, T: Instance, const SM: usize> PioEncoder<'d, T, SM> { pub fn new( pio: &mut Common<'d, T>, mut sm: StateMachine<'d, T, SM>, - pin_a: impl PioPin, - pin_b: impl PioPin, + pin_a: Peri<'d, impl PioPin>, + pin_b: Peri<'d, impl PioPin>, program: &PioEncoderProgram<'d, T>, ) -> Self { let mut pin_a = pio.make_pio_pin(pin_a); diff --git a/embassy-rp/src/pio_programs/stepper.rs b/embassy-rp/src/pio_programs/stepper.rs index c8f74167d..495191659 100644 --- a/embassy-rp/src/pio_programs/stepper.rs +++ b/embassy-rp/src/pio_programs/stepper.rs @@ -7,6 +7,7 @@ use fixed::types::extra::U8; use fixed::FixedU32; use crate::pio::{Common, Config, Direction, Instance, Irq, LoadedProgram, PioPin, StateMachine}; +use crate::Peri; /// This struct represents a Stepper driver program loaded into pio instruction memory. pub struct PioStepperProgram<'a, PIO: Instance> { @@ -50,10 +51,10 @@ impl<'d, T: Instance, const SM: usize> PioStepper<'d, T, SM> { pio: &mut Common<'d, T>, mut sm: StateMachine<'d, T, SM>, irq: Irq<'d, T, SM>, - pin0: impl PioPin, - pin1: impl PioPin, - pin2: impl PioPin, - pin3: impl PioPin, + pin0: Peri<'d, impl PioPin>, + pin1: Peri<'d, impl PioPin>, + pin2: Peri<'d, impl PioPin>, + pin3: Peri<'d, impl PioPin>, program: &PioStepperProgram<'d, T>, ) -> Self { let pin0 = pio.make_pio_pin(pin0); diff --git a/embassy-rp/src/pio_programs/uart.rs b/embassy-rp/src/pio_programs/uart.rs index 641daca61..04e39a571 100644 --- a/embassy-rp/src/pio_programs/uart.rs +++ b/embassy-rp/src/pio_programs/uart.rs @@ -10,15 +10,16 @@ use crate::gpio::Level; use crate::pio::{ Common, Config, Direction as PioDirection, FifoJoin, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine, }; +use crate::Peri; /// This struct represents a uart tx program loaded into pio instruction memory. -pub struct PioUartTxProgram<'a, PIO: Instance> { - prg: LoadedProgram<'a, PIO>, +pub struct PioUartTxProgram<'d, PIO: Instance> { + prg: LoadedProgram<'d, PIO>, } -impl<'a, PIO: Instance> PioUartTxProgram<'a, PIO> { +impl<'d, PIO: Instance> PioUartTxProgram<'d, PIO> { /// Load the uart tx program into the given pio - pub fn new(common: &mut Common<'a, PIO>) -> Self { + pub fn new(common: &mut Common<'d, PIO>) -> Self { let prg = pio::pio_asm!( r#" .side_set 1 opt @@ -41,18 +42,18 @@ impl<'a, PIO: Instance> PioUartTxProgram<'a, PIO> { } /// PIO backed Uart transmitter -pub struct PioUartTx<'a, PIO: Instance, const SM: usize> { - sm_tx: StateMachine<'a, PIO, SM>, +pub struct PioUartTx<'d, PIO: Instance, const SM: usize> { + sm_tx: StateMachine<'d, PIO, SM>, } -impl<'a, PIO: Instance, const SM: usize> PioUartTx<'a, PIO, SM> { +impl<'d, PIO: Instance, const SM: usize> PioUartTx<'d, PIO, SM> { /// Configure a pio state machine to use the loaded tx program. pub fn new( baud: u32, - common: &mut Common<'a, PIO>, - mut sm_tx: StateMachine<'a, PIO, SM>, - tx_pin: impl PioPin, - program: &PioUartTxProgram<'a, PIO>, + common: &mut Common<'d, PIO>, + mut sm_tx: StateMachine<'d, PIO, SM>, + tx_pin: Peri<'d, impl PioPin>, + program: &PioUartTxProgram<'d, PIO>, ) -> Self { let tx_pin = common.make_pio_pin(tx_pin); sm_tx.set_pins(Level::High, &[&tx_pin]); @@ -92,13 +93,13 @@ impl Write for PioUartTx<'_, PIO, SM> { } /// This struct represents a Uart Rx program loaded into pio instruction memory. -pub struct PioUartRxProgram<'a, PIO: Instance> { - prg: LoadedProgram<'a, PIO>, +pub struct PioUartRxProgram<'d, PIO: Instance> { + prg: LoadedProgram<'d, PIO>, } -impl<'a, PIO: Instance> PioUartRxProgram<'a, PIO> { +impl<'d, PIO: Instance> PioUartRxProgram<'d, PIO> { /// Load the uart rx program into the given pio - pub fn new(common: &mut Common<'a, PIO>) -> Self { + pub fn new(common: &mut Common<'d, PIO>) -> Self { let prg = pio::pio_asm!( r#" ; Slightly more fleshed-out 8n1 UART receiver which handles framing errors and @@ -130,18 +131,18 @@ impl<'a, PIO: Instance> PioUartRxProgram<'a, PIO> { } /// PIO backed Uart reciever -pub struct PioUartRx<'a, PIO: Instance, const SM: usize> { - sm_rx: StateMachine<'a, PIO, SM>, +pub struct PioUartRx<'d, PIO: Instance, const SM: usize> { + sm_rx: StateMachine<'d, PIO, SM>, } -impl<'a, PIO: Instance, const SM: usize> PioUartRx<'a, PIO, SM> { +impl<'d, PIO: Instance, const SM: usize> PioUartRx<'d, PIO, SM> { /// Configure a pio state machine to use the loaded rx program. pub fn new( baud: u32, - common: &mut Common<'a, PIO>, - mut sm_rx: StateMachine<'a, PIO, SM>, - rx_pin: impl PioPin, - program: &PioUartRxProgram<'a, PIO>, + common: &mut Common<'d, PIO>, + mut sm_rx: StateMachine<'d, PIO, SM>, + rx_pin: Peri<'d, impl PioPin>, + program: &PioUartRxProgram<'d, PIO>, ) -> Self { let mut cfg = Config::default(); cfg.use_program(&program.prg, &[]); diff --git a/embassy-rp/src/pio_programs/ws2812.rs b/embassy-rp/src/pio_programs/ws2812.rs index 2462a64e6..578937e11 100644 --- a/embassy-rp/src/pio_programs/ws2812.rs +++ b/embassy-rp/src/pio_programs/ws2812.rs @@ -9,7 +9,7 @@ use crate::dma::{AnyChannel, Channel}; use crate::pio::{ Common, Config, FifoJoin, Instance, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine, }; -use crate::{into_ref, Peripheral, PeripheralRef}; +use crate::Peri; const T1: u8 = 2; // start bit const T2: u8 = 5; // data bit @@ -53,7 +53,7 @@ impl<'a, PIO: Instance> PioWs2812Program<'a, PIO> { /// Pio backed ws2812 driver /// Const N is the number of ws2812 leds attached to this pin pub struct PioWs2812<'d, P: Instance, const S: usize, const N: usize> { - dma: PeripheralRef<'d, AnyChannel>, + dma: Peri<'d, AnyChannel>, sm: StateMachine<'d, P, S>, } @@ -62,12 +62,10 @@ impl<'d, P: Instance, const S: usize, const N: usize> PioWs2812<'d, P, S, N> { pub fn new( pio: &mut Common<'d, P>, mut sm: StateMachine<'d, P, S>, - dma: impl Peripheral

+ 'd, - pin: impl PioPin, + dma: Peri<'d, impl Channel>, + pin: Peri<'d, impl PioPin>, program: &PioWs2812Program<'d, P>, ) -> Self { - into_ref!(dma); - // Setup sm0 let mut cfg = Config::default(); @@ -95,10 +93,7 @@ impl<'d, P: Instance, const S: usize, const N: usize> PioWs2812<'d, P, S, N> { sm.set_config(&cfg); sm.set_enable(true); - Self { - dma: dma.map_into(), - sm, - } + Self { dma: dma.into(), sm } } /// Write a buffer of [smart_leds::RGB8] to the ws2812 string -- cgit