Skip to content

Commit 694d3bd

Browse files
committed
rm rcc_enable
1 parent 3c5ebfe commit 694d3bd

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

src/dma/mod.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ use core::{
1717
};
1818
use embedded_dma::{StaticReadBuffer, StaticWriteBuffer};
1919

20+
use crate::pac::RCC;
21+
use crate::rcc;
22+
2023
pub mod traits;
2124
use traits::{
2225
sealed::{Bits, Sealed},
23-
Channel, DMASet, Direction, Instance, PeriAddress, RccEnable, Stream, StreamISR,
26+
Channel, DMASet, Direction, Instance, PeriAddress, Stream, StreamISR,
2427
};
2528

2629
/// Errors.
@@ -202,6 +205,12 @@ pub struct StreamX<DMA, const S: u8> {
202205
_dma: PhantomData<DMA>,
203206
}
204207

208+
impl<DMA, const S: u8> StreamX<DMA, S> {
209+
fn new() -> Self {
210+
Self { _dma: PhantomData }
211+
}
212+
}
213+
205214
/// Stream 0 on the DMA controller.
206215
pub type Stream0<DMA> = StreamX<DMA, 0>;
207216
/// Stream 1 on the DMA controller.
@@ -240,19 +249,24 @@ pub struct StreamsTuple<T>(
240249
pub StreamX<T, 7>,
241250
);
242251

243-
impl<T: RccEnable> StreamsTuple<T> {
252+
impl<T: rcc::Enable + rcc::Reset> StreamsTuple<T> {
244253
/// 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+
}
247261
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(),
256270
)
257271
}
258272
}

src/dma/traits.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use super::*;
22
use crate::{
33
adc::Adc,
4-
pac::{self, DMA1, DMA2, RCC},
5-
rcc::{Enable, Reset},
4+
pac::{self, DMA1, DMA2},
65
serial::{Rx, Tx},
76
};
87
use core::ops::Deref;
@@ -261,34 +260,6 @@ impl Instance for DMA2 {
261260
}
262261
}
263262

264-
/// Trait for peripheral's clock enabling.
265-
pub trait RccEnable: Sealed {
266-
/// Enable the peripheral's clock in the RCC.
267-
fn rcc_enable(&self);
268-
}
269-
270-
impl RccEnable for DMA1 {
271-
fn rcc_enable(&self) {
272-
unsafe {
273-
//NOTE(unsafe) this reference will only be used for atomic writes with no side effects
274-
let rcc = &(*RCC::ptr());
275-
DMA1::enable(rcc);
276-
DMA1::reset(rcc);
277-
}
278-
}
279-
}
280-
281-
impl RccEnable for DMA2 {
282-
fn rcc_enable(&self) {
283-
unsafe {
284-
//NOTE(unsafe) this reference will only be used for atomic writes with no side effects
285-
let rcc = &(*RCC::ptr());
286-
DMA2::enable(rcc);
287-
DMA2::reset(rcc);
288-
}
289-
}
290-
}
291-
292263
macro_rules! tim_channels {
293264
($($name:ident),+ $(,)*) => {
294265
$(

0 commit comments

Comments
 (0)