Skip to content

Commit 2cdf58e

Browse files
committed
DMA transfer for PwmChannel and PwmManager
1 parent c4171fb commit 2cdf58e

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/timer.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,14 @@ macro_rules! hal {
753753
self.0.ccr(C as usize).as_ptr() as u32
754754
}
755755

756+
type MemSize = $bits;
757+
}
758+
unsafe impl<const C: u8, const COMP: bool, Otype> PeriAddress for PwmChannel<$TIM, C, COMP, Otype> where $TIM: CPin<C> {
759+
#[inline(always)]
760+
fn address(&self) -> u32 {
761+
self.tim.ccr(C as usize).as_ptr() as u32
762+
}
763+
756764
type MemSize = $bits;
757765
}
758766
)?
@@ -775,6 +783,14 @@ macro_rules! with_dmar {
775783
self.0.dmar().as_ptr() as u32
776784
}
777785

786+
type MemSize = $memsize;
787+
}
788+
unsafe impl<const FREQ: u32> PeriAddress for PwmManager<$TIM, FREQ> {
789+
#[inline(always)]
790+
fn address(&self) -> u32 {
791+
self.tim.dmar().as_ptr() as u32
792+
}
793+
778794
type MemSize = $memsize;
779795
}
780796
};

src/timer/pwm.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use super::{
4141
Polarity, Timer, WithPwm,
4242
};
4343
pub use super::{Ch, C1, C2, C3, C4};
44+
use crate::dma::traits::DMASet;
4445
use crate::gpio::{OpenDrain, PushPull};
4546
use crate::rcc::Rcc;
4647
use core::ops::{Deref, DerefMut};
@@ -183,6 +184,14 @@ pub struct PwmChannel<TIM: CPin<C>, const C: u8, const COMP: bool = false, Otype
183184
// TODO: add complementary pins
184185
}
185186

187+
unsafe impl<TIM, const C: u8, const COMP: bool, Otype, STREAM, const CHANNEL: u8, DIRECTION>
188+
DMASet<STREAM, CHANNEL, DIRECTION> for PwmChannel<TIM, C, COMP, Otype>
189+
where
190+
TIM: CPin<C>,
191+
super::CCR<TIM, C>: DMASet<STREAM, CHANNEL, DIRECTION>,
192+
{
193+
}
194+
186195
impl<TIM: Instance + WithPwm + CPin<C>, const C: u8, const COMP: bool, Otype>
187196
PwmChannel<TIM, C, COMP, Otype>
188197
{
@@ -339,6 +348,14 @@ where
339348
pub(super) timer: FTimer<TIM, FREQ>,
340349
}
341350

351+
unsafe impl<TIM, const FREQ: u32, STREAM, const CHANNEL: u8, DIRECTION>
352+
DMASet<STREAM, CHANNEL, DIRECTION> for PwmManager<TIM, FREQ>
353+
where
354+
TIM: Instance + WithPwm,
355+
super::DMAR<TIM>: DMASet<STREAM, CHANNEL, DIRECTION>,
356+
{
357+
}
358+
342359
impl<TIM, const FREQ: u32> PwmManager<TIM, FREQ>
343360
where
344361
TIM: Instance + WithPwm + Split,

0 commit comments

Comments
 (0)