@@ -6,6 +6,7 @@ use crate::gpio::{self, NoPin};
66use crate :: pac;
77use crate :: rcc;
88use crate :: rcc:: Clocks ;
9+ use crate :: rcc:: Reset ;
910use fugit:: HertzU32 as Hertz ;
1011
1112#[ cfg( feature = "stm32_i2s_v12x" ) ]
@@ -131,16 +132,16 @@ impl<I: Instance> I2s<I> {
131132 }
132133}
133134
134- /// Implements stm32_i2s_v12x::I2sPeripheral for I2s<$SPIX, _ > and creates an I2s::$spix function
135+ /// Implements stm32_i2s_v12x::I2sPeripheral for I2s<$SPI > and creates an I2s::$spix function
135136/// to create and enable the peripheral
136137///
137- /// $SPIX : The fully-capitalized name of the SPI peripheral (example: SPI1)
138- /// $i2sx : The lowercase I2S name of the peripheral (example: i2s1). This is the name of the
139- /// function that creates an I2s and enables the peripheral clock .
138+ /// $SPI : The fully-capitalized name of the SPI peripheral from pac module (example: SPI1)
139+ /// $I2s : The CamelCase I2S alias name for hal I2s wrapper (example: I2s1).
140+ /// $i2s: module containing the Ws pin definition. (example: i2s1) .
140141/// $clock: The name of the Clocks function that returns the frequency of the I2S clock input
141142/// to this SPI peripheral (i2s_cl, i2s_apb1_clk, or i2s2_apb_clk)
142143macro_rules! i2s {
143- ( $SPI: ty, $I2s: ident, $clock: ident) => {
144+ ( $SPI: ty, $I2s: ident, $i2s : ident , $ clock: ident) => {
144145 pub type $I2s = I2s <$SPI>;
145146
146147 impl Instance for $SPI { }
@@ -154,18 +155,37 @@ macro_rules! i2s {
154155 }
155156
156157 #[ cfg( feature = "stm32_i2s_v12x" ) ]
157- unsafe impl stm32_i2s_v12x:: I2sPeripheral for I2s <$SPI> {
158+ impl stm32_i2s_v12x:: WsPin for gpio:: alt:: $i2s:: Ws {
159+ fn is_high( & self ) -> bool {
160+ use crate :: gpio:: ReadPin ;
161+ <Self as ReadPin >:: is_high( self )
162+ }
163+ fn is_low( & self ) -> bool {
164+ use crate :: gpio:: ReadPin ;
165+ <Self as ReadPin >:: is_low( self )
166+ }
167+ }
168+
169+ #[ cfg( feature = "stm32_i2s_v12x" ) ]
170+ unsafe impl stm32_i2s_v12x:: I2sPeripheral for I2s <$SPI>
171+ where
172+ $SPI: rcc:: Reset ,
173+ {
174+ type WsPin = gpio:: alt:: $i2s:: Ws ;
158175 const REGISTERS : * const ( ) = <$SPI>:: ptr( ) as * const _;
159176 fn i2s_freq( & self ) -> u32 {
160177 self . input_clock. raw( )
161178 }
162- fn ws_is_high( & self ) -> bool {
163- use crate :: gpio:: ReadPin ;
164- self . ws_pin( ) . is_high( )
179+ fn ws_pin( & self ) -> & Self :: WsPin {
180+ self . ws_pin( )
165181 }
166- fn ws_is_low( & self ) -> bool {
167- use crate :: gpio:: ReadPin ;
168- self . ws_pin( ) . is_low( )
182+ fn ws_pin_mut( & mut self ) -> & mut Self :: WsPin {
183+ self . ws_pin_mut( )
184+ }
185+ fn rcc_reset( & mut self ) {
186+ unsafe {
187+ <$SPI>:: reset_unchecked( ) ;
188+ }
169189 }
170190 }
171191 } ;
@@ -176,15 +196,15 @@ macro_rules! i2s {
176196// have two different I2S clocks while other models have only one.
177197
178198#[ cfg( any( feature = "gpio-f410" , feature = "gpio-f411" ) ) ]
179- i2s ! ( pac:: SPI1 , I2s1 , i2s_clk) ;
199+ i2s ! ( pac:: SPI1 , I2s1 , i2s1 , i2s_clk) ;
180200#[ cfg( any( feature = "gpio-f412" , feature = "gpio-f413" , feature = "gpio-f446" , ) ) ]
181- i2s ! ( pac:: SPI1 , I2s1 , i2s_apb2_clk) ;
201+ i2s ! ( pac:: SPI1 , I2s1 , i2s1 , i2s_apb2_clk) ;
182202
183203// All STM32F4 models support SPI2/I2S2
184204#[ cfg( not( any( feature = "gpio-f412" , feature = "gpio-f413" , feature = "gpio-f446" , ) ) ) ]
185- i2s ! ( pac:: SPI2 , I2s2 , i2s_clk) ;
205+ i2s ! ( pac:: SPI2 , I2s2 , i2s2 , i2s_clk) ;
186206#[ cfg( any( feature = "gpio-f412" , feature = "gpio-f413" , feature = "gpio-f446" , ) ) ]
187- i2s ! ( pac:: SPI2 , I2s2 , i2s_apb1_clk) ;
207+ i2s ! ( pac:: SPI2 , I2s2 , i2s2 , i2s_apb1_clk) ;
188208
189209// All STM32F4 models except STM32F410 support SPI3/I2S3
190210#[ cfg( any(
@@ -194,19 +214,19 @@ i2s!(pac::SPI2, I2s2, i2s_apb1_clk);
194214 feature = "gpio-f427" ,
195215 feature = "gpio-f469" ,
196216) ) ]
197- i2s ! ( pac:: SPI3 , I2s3 , i2s_clk) ;
217+ i2s ! ( pac:: SPI3 , I2s3 , i2s3 , i2s_clk) ;
198218#[ cfg( any( feature = "gpio-f412" , feature = "gpio-f413" , feature = "gpio-f446" , ) ) ]
199- i2s ! ( pac:: SPI3 , I2s3 , i2s_apb1_clk) ;
219+ i2s ! ( pac:: SPI3 , I2s3 , i2s3 , i2s_apb1_clk) ;
200220
201221#[ cfg( feature = "gpio-f411" ) ]
202- i2s ! ( pac:: SPI4 , I2s4 , i2s_clk) ;
222+ i2s ! ( pac:: SPI4 , I2s4 , i2s4 , i2s_clk) ;
203223#[ cfg( any( feature = "gpio-f412" , feature = "gpio-f413" ) ) ]
204- i2s ! ( pac:: SPI4 , I2s4 , i2s_apb2_clk) ;
224+ i2s ! ( pac:: SPI4 , I2s4 , i2s4 , i2s_apb2_clk) ;
205225
206226#[ cfg( any( feature = "gpio-f410" , feature = "gpio-f411" ) ) ]
207- i2s ! ( pac:: SPI5 , I2s5 , i2s_clk) ;
227+ i2s ! ( pac:: SPI5 , I2s5 , i2s5 , i2s_clk) ;
208228#[ cfg( any( feature = "gpio-f412" , feature = "gpio-f413" ) ) ]
209- i2s ! ( pac:: SPI5 , I2s5 , i2s_apb2_clk) ;
229+ i2s ! ( pac:: SPI5 , I2s5 , i2s5 , i2s_apb2_clk) ;
210230
211231// DMA support: reuse existing mappings for SPI
212232#[ cfg( feature = "stm32_i2s_v12x" ) ]
@@ -227,8 +247,7 @@ mod dma {
227247 type MemSize = u16 ;
228248
229249 fn address ( & self ) -> u32 {
230- let registers = & * self . i2s_peripheral ( ) . spi ;
231- & registers. dr as * const _ as u32
250+ self . data_register_address ( )
232251 }
233252 }
234253
0 commit comments