@@ -6,6 +6,7 @@ use crate::gpio::{self, NoPin};
6
6
use crate :: pac;
7
7
use crate :: rcc;
8
8
use crate :: rcc:: Clocks ;
9
+ use crate :: rcc:: Reset ;
9
10
use fugit:: HertzU32 as Hertz ;
10
11
11
12
#[ cfg( feature = "stm32_i2s_v12x" ) ]
@@ -131,16 +132,16 @@ impl<I: Instance> I2s<I> {
131
132
}
132
133
}
133
134
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
135
136
/// to create and enable the peripheral
136
137
///
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) .
140
141
/// $clock: The name of the Clocks function that returns the frequency of the I2S clock input
141
142
/// to this SPI peripheral (i2s_cl, i2s_apb1_clk, or i2s2_apb_clk)
142
143
macro_rules! i2s {
143
- ( $SPI: ty, $I2s: ident, $clock: ident) => {
144
+ ( $SPI: ty, $I2s: ident, $i2s : ident , $ clock: ident) => {
144
145
pub type $I2s = I2s <$SPI>;
145
146
146
147
impl Instance for $SPI { }
@@ -154,18 +155,37 @@ macro_rules! i2s {
154
155
}
155
156
156
157
#[ 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 ;
158
175
const REGISTERS : * const ( ) = <$SPI>:: ptr( ) as * const _;
159
176
fn i2s_freq( & self ) -> u32 {
160
177
self . input_clock. raw( )
161
178
}
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( )
165
181
}
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
+ }
169
189
}
170
190
}
171
191
} ;
@@ -176,15 +196,15 @@ macro_rules! i2s {
176
196
// have two different I2S clocks while other models have only one.
177
197
178
198
#[ cfg( any( feature = "gpio-f410" , feature = "gpio-f411" ) ) ]
179
- i2s ! ( pac:: SPI1 , I2s1 , i2s_clk) ;
199
+ i2s ! ( pac:: SPI1 , I2s1 , i2s1 , i2s_clk) ;
180
200
#[ 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) ;
182
202
183
203
// All STM32F4 models support SPI2/I2S2
184
204
#[ 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) ;
186
206
#[ 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) ;
188
208
189
209
// All STM32F4 models except STM32F410 support SPI3/I2S3
190
210
#[ cfg( any(
@@ -194,19 +214,19 @@ i2s!(pac::SPI2, I2s2, i2s_apb1_clk);
194
214
feature = "gpio-f427" ,
195
215
feature = "gpio-f469" ,
196
216
) ) ]
197
- i2s ! ( pac:: SPI3 , I2s3 , i2s_clk) ;
217
+ i2s ! ( pac:: SPI3 , I2s3 , i2s3 , i2s_clk) ;
198
218
#[ 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) ;
200
220
201
221
#[ cfg( feature = "gpio-f411" ) ]
202
- i2s ! ( pac:: SPI4 , I2s4 , i2s_clk) ;
222
+ i2s ! ( pac:: SPI4 , I2s4 , i2s4 , i2s_clk) ;
203
223
#[ 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) ;
205
225
206
226
#[ cfg( any( feature = "gpio-f410" , feature = "gpio-f411" ) ) ]
207
- i2s ! ( pac:: SPI5 , I2s5 , i2s_clk) ;
227
+ i2s ! ( pac:: SPI5 , I2s5 , i2s5 , i2s_clk) ;
208
228
#[ 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) ;
210
230
211
231
// DMA support: reuse existing mappings for SPI
212
232
#[ cfg( feature = "stm32_i2s_v12x" ) ]
@@ -227,8 +247,7 @@ mod dma {
227
247
type MemSize = u16 ;
228
248
229
249
fn address ( & self ) -> u32 {
230
- let registers = & * self . i2s_peripheral ( ) . spi ;
231
- & registers. dr as * const _ as u32
250
+ self . data_register_address ( )
232
251
}
233
252
}
234
253
0 commit comments