diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-03-26 16:01:37 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-03-27 15:18:06 +0100 |
| commit | d41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch) | |
| tree | 678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-rp/src/pio_programs/uart.rs | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-rp/src/pio_programs/uart.rs')
| -rw-r--r-- | embassy-rp/src/pio_programs/uart.rs | 45 |
1 files changed, 23 insertions, 22 deletions
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; | |||
| 10 | use crate::pio::{ | 10 | use crate::pio::{ |
| 11 | Common, Config, Direction as PioDirection, FifoJoin, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine, | 11 | Common, Config, Direction as PioDirection, FifoJoin, Instance, LoadedProgram, PioPin, ShiftDirection, StateMachine, |
| 12 | }; | 12 | }; |
| 13 | use crate::Peri; | ||
| 13 | 14 | ||
| 14 | /// This struct represents a uart tx program loaded into pio instruction memory. | 15 | /// This struct represents a uart tx program loaded into pio instruction memory. |
| 15 | pub struct PioUartTxProgram<'a, PIO: Instance> { | 16 | pub struct PioUartTxProgram<'d, PIO: Instance> { |
| 16 | prg: LoadedProgram<'a, PIO>, | 17 | prg: LoadedProgram<'d, PIO>, |
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | impl<'a, PIO: Instance> PioUartTxProgram<'a, PIO> { | 20 | impl<'d, PIO: Instance> PioUartTxProgram<'d, PIO> { |
| 20 | /// Load the uart tx program into the given pio | 21 | /// Load the uart tx program into the given pio |
| 21 | pub fn new(common: &mut Common<'a, PIO>) -> Self { | 22 | pub fn new(common: &mut Common<'d, PIO>) -> Self { |
| 22 | let prg = pio::pio_asm!( | 23 | let prg = pio::pio_asm!( |
| 23 | r#" | 24 | r#" |
| 24 | .side_set 1 opt | 25 | .side_set 1 opt |
| @@ -41,18 +42,18 @@ impl<'a, PIO: Instance> PioUartTxProgram<'a, PIO> { | |||
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | /// PIO backed Uart transmitter | 44 | /// PIO backed Uart transmitter |
| 44 | pub struct PioUartTx<'a, PIO: Instance, const SM: usize> { | 45 | pub struct PioUartTx<'d, PIO: Instance, const SM: usize> { |
| 45 | sm_tx: StateMachine<'a, PIO, SM>, | 46 | sm_tx: StateMachine<'d, PIO, SM>, |
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | impl<'a, PIO: Instance, const SM: usize> PioUartTx<'a, PIO, SM> { | 49 | impl<'d, PIO: Instance, const SM: usize> PioUartTx<'d, PIO, SM> { |
| 49 | /// Configure a pio state machine to use the loaded tx program. | 50 | /// Configure a pio state machine to use the loaded tx program. |
| 50 | pub fn new( | 51 | pub fn new( |
| 51 | baud: u32, | 52 | baud: u32, |
| 52 | common: &mut Common<'a, PIO>, | 53 | common: &mut Common<'d, PIO>, |
| 53 | mut sm_tx: StateMachine<'a, PIO, SM>, | 54 | mut sm_tx: StateMachine<'d, PIO, SM>, |
| 54 | tx_pin: impl PioPin, | 55 | tx_pin: Peri<'d, impl PioPin>, |
| 55 | program: &PioUartTxProgram<'a, PIO>, | 56 | program: &PioUartTxProgram<'d, PIO>, |
| 56 | ) -> Self { | 57 | ) -> Self { |
| 57 | let tx_pin = common.make_pio_pin(tx_pin); | 58 | let tx_pin = common.make_pio_pin(tx_pin); |
| 58 | sm_tx.set_pins(Level::High, &[&tx_pin]); | 59 | sm_tx.set_pins(Level::High, &[&tx_pin]); |
| @@ -92,13 +93,13 @@ impl<PIO: Instance, const SM: usize> Write for PioUartTx<'_, PIO, SM> { | |||
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | /// This struct represents a Uart Rx program loaded into pio instruction memory. | 95 | /// This struct represents a Uart Rx program loaded into pio instruction memory. |
| 95 | pub struct PioUartRxProgram<'a, PIO: Instance> { | 96 | pub struct PioUartRxProgram<'d, PIO: Instance> { |
| 96 | prg: LoadedProgram<'a, PIO>, | 97 | prg: LoadedProgram<'d, PIO>, |
| 97 | } | 98 | } |
| 98 | 99 | ||
| 99 | impl<'a, PIO: Instance> PioUartRxProgram<'a, PIO> { | 100 | impl<'d, PIO: Instance> PioUartRxProgram<'d, PIO> { |
| 100 | /// Load the uart rx program into the given pio | 101 | /// Load the uart rx program into the given pio |
| 101 | pub fn new(common: &mut Common<'a, PIO>) -> Self { | 102 | pub fn new(common: &mut Common<'d, PIO>) -> Self { |
| 102 | let prg = pio::pio_asm!( | 103 | let prg = pio::pio_asm!( |
| 103 | r#" | 104 | r#" |
| 104 | ; Slightly more fleshed-out 8n1 UART receiver which handles framing errors and | 105 | ; Slightly more fleshed-out 8n1 UART receiver which handles framing errors and |
| @@ -130,18 +131,18 @@ impl<'a, PIO: Instance> PioUartRxProgram<'a, PIO> { | |||
| 130 | } | 131 | } |
| 131 | 132 | ||
| 132 | /// PIO backed Uart reciever | 133 | /// PIO backed Uart reciever |
| 133 | pub struct PioUartRx<'a, PIO: Instance, const SM: usize> { | 134 | pub struct PioUartRx<'d, PIO: Instance, const SM: usize> { |
| 134 | sm_rx: StateMachine<'a, PIO, SM>, | 135 | sm_rx: StateMachine<'d, PIO, SM>, |
| 135 | } | 136 | } |
| 136 | 137 | ||
| 137 | impl<'a, PIO: Instance, const SM: usize> PioUartRx<'a, PIO, SM> { | 138 | impl<'d, PIO: Instance, const SM: usize> PioUartRx<'d, PIO, SM> { |
| 138 | /// Configure a pio state machine to use the loaded rx program. | 139 | /// Configure a pio state machine to use the loaded rx program. |
| 139 | pub fn new( | 140 | pub fn new( |
| 140 | baud: u32, | 141 | baud: u32, |
| 141 | common: &mut Common<'a, PIO>, | 142 | common: &mut Common<'d, PIO>, |
| 142 | mut sm_rx: StateMachine<'a, PIO, SM>, | 143 | mut sm_rx: StateMachine<'d, PIO, SM>, |
| 143 | rx_pin: impl PioPin, | 144 | rx_pin: Peri<'d, impl PioPin>, |
| 144 | program: &PioUartRxProgram<'a, PIO>, | 145 | program: &PioUartRxProgram<'d, PIO>, |
| 145 | ) -> Self { | 146 | ) -> Self { |
| 146 | let mut cfg = Config::default(); | 147 | let mut cfg = Config::default(); |
| 147 | cfg.use_program(&program.prg, &[]); | 148 | cfg.use_program(&program.prg, &[]); |
