aboutsummaryrefslogtreecommitdiff
path: root/embassy-rp/src/pio_programs/uart.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2025-03-26 16:01:37 +0100
committerDario Nieuwenhuis <[email protected]>2025-03-27 15:18:06 +0100
commitd41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch)
tree678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-rp/src/pio_programs/uart.rs
parent9edf5b7f049f95742b60b041e4443967d8a6b708 (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.rs45
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;
10use crate::pio::{ 10use 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};
13use 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.
15pub struct PioUartTxProgram<'a, PIO: Instance> { 16pub struct PioUartTxProgram<'d, PIO: Instance> {
16 prg: LoadedProgram<'a, PIO>, 17 prg: LoadedProgram<'d, PIO>,
17} 18}
18 19
19impl<'a, PIO: Instance> PioUartTxProgram<'a, PIO> { 20impl<'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
44pub struct PioUartTx<'a, PIO: Instance, const SM: usize> { 45pub 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
48impl<'a, PIO: Instance, const SM: usize> PioUartTx<'a, PIO, SM> { 49impl<'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.
95pub struct PioUartRxProgram<'a, PIO: Instance> { 96pub struct PioUartRxProgram<'d, PIO: Instance> {
96 prg: LoadedProgram<'a, PIO>, 97 prg: LoadedProgram<'d, PIO>,
97} 98}
98 99
99impl<'a, PIO: Instance> PioUartRxProgram<'a, PIO> { 100impl<'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
133pub struct PioUartRx<'a, PIO: Instance, const SM: usize> { 134pub 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
137impl<'a, PIO: Instance, const SM: usize> PioUartRx<'a, PIO, SM> { 138impl<'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, &[]);