@@ -17,10 +17,13 @@ use core::{
17
17
} ;
18
18
use embedded_dma:: { StaticReadBuffer , StaticWriteBuffer } ;
19
19
20
+ use crate :: pac:: RCC ;
21
+ use crate :: rcc;
22
+
20
23
pub mod traits;
21
24
use traits:: {
22
25
sealed:: { Bits , Sealed } ,
23
- Channel , DMASet , Direction , Instance , PeriAddress , RccEnable , Stream , StreamISR ,
26
+ Channel , DMASet , Direction , Instance , PeriAddress , Stream , StreamISR ,
24
27
} ;
25
28
26
29
/// Errors.
@@ -202,6 +205,12 @@ pub struct StreamX<DMA, const S: u8> {
202
205
_dma : PhantomData < DMA > ,
203
206
}
204
207
208
+ impl < DMA , const S : u8 > StreamX < DMA , S > {
209
+ fn new ( ) -> Self {
210
+ Self { _dma : PhantomData }
211
+ }
212
+ }
213
+
205
214
/// Stream 0 on the DMA controller.
206
215
pub type Stream0 < DMA > = StreamX < DMA , 0 > ;
207
216
/// Stream 1 on the DMA controller.
@@ -240,19 +249,24 @@ pub struct StreamsTuple<T>(
240
249
pub StreamX < T , 7 > ,
241
250
) ;
242
251
243
- impl < T : RccEnable > StreamsTuple < T > {
252
+ impl < T : rcc :: Enable + rcc :: Reset > StreamsTuple < T > {
244
253
/// Splits the DMA peripheral into streams.
245
- pub fn new ( regs : T ) -> Self {
246
- regs. rcc_enable ( ) ;
254
+ pub fn new ( _regs : T ) -> Self {
255
+ unsafe {
256
+ //NOTE(unsafe) this reference will only be used for atomic writes with no side effects
257
+ let rcc = & ( * RCC :: ptr ( ) ) ;
258
+ T :: enable ( rcc) ;
259
+ T :: reset ( rcc) ;
260
+ }
247
261
Self (
248
- StreamX { _dma : PhantomData } ,
249
- StreamX { _dma : PhantomData } ,
250
- StreamX { _dma : PhantomData } ,
251
- StreamX { _dma : PhantomData } ,
252
- StreamX { _dma : PhantomData } ,
253
- StreamX { _dma : PhantomData } ,
254
- StreamX { _dma : PhantomData } ,
255
- StreamX { _dma : PhantomData } ,
262
+ StreamX :: new ( ) ,
263
+ StreamX :: new ( ) ,
264
+ StreamX :: new ( ) ,
265
+ StreamX :: new ( ) ,
266
+ StreamX :: new ( ) ,
267
+ StreamX :: new ( ) ,
268
+ StreamX :: new ( ) ,
269
+ StreamX :: new ( ) ,
256
270
)
257
271
}
258
272
}
0 commit comments