diff options
Diffstat (limited to 'embassy-rp/src/pio_programs/i2s.rs')
| -rw-r--r-- | embassy-rp/src/pio_programs/i2s.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/embassy-rp/src/pio_programs/i2s.rs b/embassy-rp/src/pio_programs/i2s.rs index 2382a3f9f..5c49beecb 100644 --- a/embassy-rp/src/pio_programs/i2s.rs +++ b/embassy-rp/src/pio_programs/i2s.rs | |||
| @@ -1,15 +1,15 @@ | |||
| 1 | //! Pio backed I2s output and output drivers | 1 | //! Pio backed I2S output and output drivers |
| 2 | 2 | ||
| 3 | use fixed::traits::ToFixed; | 3 | use fixed::traits::ToFixed; |
| 4 | 4 | ||
| 5 | use crate::Peri; | ||
| 5 | use crate::dma::{AnyChannel, Channel, Transfer}; | 6 | use crate::dma::{AnyChannel, Channel, Transfer}; |
| 6 | use crate::gpio::Pull; | 7 | use crate::gpio::Pull; |
| 7 | use crate::pio::{ | 8 | use crate::pio::{ |
| 8 | Common, Config, Direction, FifoJoin, Instance, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine, | 9 | Common, Config, Direction, FifoJoin, Instance, LoadedProgram, PioPin, ShiftConfig, ShiftDirection, StateMachine, |
| 9 | }; | 10 | }; |
| 10 | use crate::Peri; | ||
| 11 | 11 | ||
| 12 | /// This struct represents an i2s receiver & controller driver program | 12 | /// This struct represents an I2S receiver & controller driver program |
| 13 | pub struct PioI2sInProgram<'d, PIO: Instance> { | 13 | pub struct PioI2sInProgram<'d, PIO: Instance> { |
| 14 | prg: LoadedProgram<'d, PIO>, | 14 | prg: LoadedProgram<'d, PIO>, |
| 15 | } | 15 | } |
| @@ -35,7 +35,7 @@ impl<'d, PIO: Instance> PioI2sInProgram<'d, PIO> { | |||
| 35 | } | 35 | } |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | /// Pio backed I2s input driver | 38 | /// Pio backed I2S input driver |
| 39 | pub struct PioI2sIn<'d, P: Instance, const S: usize> { | 39 | pub struct PioI2sIn<'d, P: Instance, const S: usize> { |
| 40 | dma: Peri<'d, AnyChannel>, | 40 | dma: Peri<'d, AnyChannel>, |
| 41 | sm: StateMachine<'d, P, S>, | 41 | sm: StateMachine<'d, P, S>, |
| @@ -50,7 +50,7 @@ impl<'d, P: Instance, const S: usize> PioI2sIn<'d, P, S> { | |||
| 50 | // Whether or not to use the MCU's internal pull-down resistor, as the | 50 | // Whether or not to use the MCU's internal pull-down resistor, as the |
| 51 | // Pico 2 is known to have problems with the inbuilt pulldowns, many | 51 | // Pico 2 is known to have problems with the inbuilt pulldowns, many |
| 52 | // opt to just use an external pull down resistor to meet requirements of common | 52 | // opt to just use an external pull down resistor to meet requirements of common |
| 53 | // i2s microphones such as the INMP441 | 53 | // I2S microphones such as the INMP441 |
| 54 | data_pulldown: bool, | 54 | data_pulldown: bool, |
| 55 | data_pin: Peri<'d, impl PioPin>, | 55 | data_pin: Peri<'d, impl PioPin>, |
| 56 | bit_clock_pin: Peri<'d, impl PioPin>, | 56 | bit_clock_pin: Peri<'d, impl PioPin>, |
| @@ -90,13 +90,13 @@ impl<'d, P: Instance, const S: usize> PioI2sIn<'d, P, S> { | |||
| 90 | Self { dma: dma.into(), sm } | 90 | Self { dma: dma.into(), sm } |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | /// Return an in-prograss dma transfer future. Awaiting it will guarentee a complete transfer. | 93 | /// Return an in-progress dma transfer future. Awaiting it will guarantee a complete transfer. |
| 94 | pub fn read<'b>(&'b mut self, buff: &'b mut [u32]) -> Transfer<'b, AnyChannel> { | 94 | pub fn read<'b>(&'b mut self, buff: &'b mut [u32]) -> Transfer<'b, AnyChannel> { |
| 95 | self.sm.rx().dma_pull(self.dma.reborrow(), buff, false) | 95 | self.sm.rx().dma_pull(self.dma.reborrow(), buff, false) |
| 96 | } | 96 | } |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | /// This struct represents an i2s output driver program | 99 | /// This struct represents an I2S output driver program |
| 100 | /// | 100 | /// |
| 101 | /// The sample bit-depth is set through scratch register `Y`. | 101 | /// The sample bit-depth is set through scratch register `Y`. |
| 102 | /// `Y` has to be set to sample bit-depth - 2. | 102 | /// `Y` has to be set to sample bit-depth - 2. |
| @@ -128,14 +128,14 @@ impl<'d, PIO: Instance> PioI2sOutProgram<'d, PIO> { | |||
| 128 | } | 128 | } |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | /// Pio backed I2s output driver | 131 | /// Pio backed I2S output driver |
| 132 | pub struct PioI2sOut<'d, P: Instance, const S: usize> { | 132 | pub struct PioI2sOut<'d, P: Instance, const S: usize> { |
| 133 | dma: Peri<'d, AnyChannel>, | 133 | dma: Peri<'d, AnyChannel>, |
| 134 | sm: StateMachine<'d, P, S>, | 134 | sm: StateMachine<'d, P, S>, |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | impl<'d, P: Instance, const S: usize> PioI2sOut<'d, P, S> { | 137 | impl<'d, P: Instance, const S: usize> PioI2sOut<'d, P, S> { |
| 138 | /// Configure a state machine to output I2s | 138 | /// Configure a state machine to output I2S |
| 139 | pub fn new( | 139 | pub fn new( |
| 140 | common: &mut Common<'d, P>, | 140 | common: &mut Common<'d, P>, |
| 141 | mut sm: StateMachine<'d, P, S>, | 141 | mut sm: StateMachine<'d, P, S>, |
| @@ -179,7 +179,7 @@ impl<'d, P: Instance, const S: usize> PioI2sOut<'d, P, S> { | |||
| 179 | Self { dma: dma.into(), sm } | 179 | Self { dma: dma.into(), sm } |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | /// Return an in-prograss dma transfer future. Awaiting it will guarentee a complete transfer. | 182 | /// Return an in-progress dma transfer future. Awaiting it will guarantee a complete transfer. |
| 183 | pub fn write<'b>(&'b mut self, buff: &'b [u32]) -> Transfer<'b, AnyChannel> { | 183 | pub fn write<'b>(&'b mut self, buff: &'b [u32]) -> Transfer<'b, AnyChannel> { |
| 184 | self.sm.tx().dma_push(self.dma.reborrow(), buff, false) | 184 | self.sm.tx().dma_push(self.dma.reborrow(), buff, false) |
| 185 | } | 185 | } |
