Skip to content

Commit ab4c3b5

Browse files
committed
HRTIM: Capture interrupts and clippy
1 parent eb075b0 commit ab4c3b5

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

src/hrtim/capture.rs

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub struct HrCapt<TIM, PSCL, CH> {
99
_x: PhantomData<(TIM, PSCL, CH)>,
1010
}
1111

12+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
13+
#[derive(Copy, Clone, Debug)]
1214
pub enum CountingDirection {
1315
Up = 0,
1416
Down = 1,
@@ -23,7 +25,7 @@ pub trait CaptureEvent<TIM, PSCL> {
2325
const BITS: u32;
2426
}
2527

26-
trait HrCapture {
28+
pub trait HrCapture {
2729
fn get(&self) -> (u16, CountingDirection);
2830

2931
/// Get number of ticks relative to beginning of upcounting
@@ -43,10 +45,14 @@ trait HrCapture {
4345
let dir_bit = dir as u32;
4446
dir_bit << 16 | u32::from(value)
4547
}
48+
49+
fn clear_interrupt(&mut self);
50+
51+
fn is_pending(&self) -> bool;
4652
}
4753

4854
macro_rules! impl_capture {
49-
($($TIMX:ident: $CH:ident, $cptXYr:ident, $cptXYcr:ident, $cptXx:ident),+) => {
55+
($($TIMX:ident: $CH:ident, $cptXYr:ident, $cptXYcr:ident, $cptXx:ident, $dier:ident, $icr:ident, $isr:ident, $cptXie:ident, $cptXc:ident, $cptX:ident),+) => {
5056
$(impl<PSCL> HrCapt<$TIMX, PSCL, $CH> {
5157
/// Add event to capture
5258
///
@@ -78,6 +84,15 @@ macro_rules! impl_capture {
7884

7985
tim.$cptXYcr.modify(|_, w| w.swcpt().set_bit());
8086
}
87+
88+
// TODO: It would be sufficient to instead of hr_control only require exclusive access to the owning timer
89+
// however that would be hard to do since typically the capture device is a field of that same timer.
90+
// Would it make more sense to have this method direcly on HrTim instead?
91+
pub fn enable_interrupt(&mut self, enable: bool, _hr_control: &mut super::HrPwmControl) {
92+
let tim = unsafe { &*$TIMX::ptr() };
93+
94+
tim.$dier.modify(|_r, w| w.$cptXie().bit(enable));
95+
}
8196
}
8297

8398
impl<PSCL> HrCapture for HrCapt<$TIMX, PSCL, $CH> {
@@ -92,26 +107,40 @@ macro_rules! impl_capture {
92107

93108
(value, dir)
94109
}
110+
111+
fn clear_interrupt(&mut self) {
112+
let tim = unsafe { &*$TIMX::ptr() };
113+
114+
// No need for exclusive access since this is a write only register
115+
tim.$icr.write(|w| w.$cptXc().set_bit());
116+
}
117+
118+
fn is_pending(&self) -> bool {
119+
let tim = unsafe { &*$TIMX::ptr() };
120+
121+
// No need for exclusive access since this is a read only register
122+
tim.$isr.read().$cptX().bit()
123+
}
95124
})+
96125
};
97126
}
98127

99128
impl_capture! {
100-
HRTIM_TIMA: Ch1, cpt1ar, cpt1acr, cpt1x,
101-
HRTIM_TIMA: Ch2, cpt2ar, cpt2acr, cpt2x,
129+
HRTIM_TIMA: Ch1, cpt1ar, cpt1acr, cpt1x, timadier, timaicr, timaisr, cpt1ie, cpt1c, cpt1,
130+
HRTIM_TIMA: Ch2, cpt2ar, cpt2acr, cpt2x, timadier, timaicr, timaisr, cpt2ie, cpt2c, cpt2,
102131

103-
HRTIM_TIMB: Ch1, cpt1br, cpt1bcr, cpt1x,
104-
HRTIM_TIMB: Ch2, cpt2br, cpt2bcr, cpt2x,
132+
HRTIM_TIMB: Ch1, cpt1br, cpt1bcr, cpt1x, timbdier, timbicr, timbisr, cpt1ie, cpt1c, cpt1,
133+
HRTIM_TIMB: Ch2, cpt2br, cpt2bcr, cpt2x, timbdier, timbicr, timbisr, cpt2ie, cpt2c, cpt2,
105134

106-
HRTIM_TIMC: Ch1, cpt1cr, cpt1ccr, cpt1x,
107-
HRTIM_TIMC: Ch2, cpt2cr, cpt2ccr, cpt2x,
135+
HRTIM_TIMC: Ch1, cpt1cr, cpt1ccr, cpt1x, timcdier, timcicr, timcisr, cpt1ie, cpt1c, cpt1,
136+
HRTIM_TIMC: Ch2, cpt2cr, cpt2ccr, cpt2x, timcdier, timcicr, timcisr, cpt2ie, cpt2c, cpt2,
108137

109-
HRTIM_TIMD: Ch1, cpt1dr, cpt1dcr, cpt1x,
110-
HRTIM_TIMD: Ch2, cpt2dr, cpt2dcr, cpt2x,
138+
HRTIM_TIMD: Ch1, cpt1dr, cpt1dcr, cpt1x, timddier, timdicr, timdisr, cpt1ie, cpt1c, cpt1,
139+
HRTIM_TIMD: Ch2, cpt2dr, cpt2dcr, cpt2x, timddier, timdicr, timdisr, cpt2ie, cpt2c, cpt2,
111140

112-
HRTIM_TIME: Ch1, cpt1er, cpt1ecr, cpt1x,
113-
HRTIM_TIME: Ch2, cpt2er, cpt2ecr, cpt2x,
141+
HRTIM_TIME: Ch1, cpt1er, cpt1ecr, cpt1x, timedier, timeicr, timeisr, cpt1ie, cpt1c, cpt1,
142+
HRTIM_TIME: Ch2, cpt2er, cpt2ecr, cpt2x, timedier, timeicr, timeisr, cpt2ie, cpt2c, cpt2,
114143

115-
HRTIM_TIMF: Ch1, cpt1fr, cpt1fcr, cpt1x,
116-
HRTIM_TIMF: Ch2, cpt2fr, cpt2fcr, cpt2x
144+
HRTIM_TIMF: Ch1, cpt1fr, cpt1fcr, cpt1x, timfdier, timficr, timfisr, cpt1ie, cpt1c, cpt1,
145+
HRTIM_TIMF: Ch2, cpt2fr, cpt2fcr, cpt2x, timfdier, timficr, timfisr, cpt2ie, cpt2c, cpt2
117146
}

src/hrtim/control.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,14 @@ macro_rules! impl_adc1234_trigger {
247247
}
248248
}
249249

250-
$(impl Into<crate::adc::config::ExternalTrigger12> for &$t {
251-
fn into(self) -> crate::adc::config::ExternalTrigger12 {
250+
$(impl From<&$t> for crate::adc::config::ExternalTrigger12 {
251+
fn from(_val: &$t) -> Self {
252252
crate::adc::config::ExternalTrigger12::$variant12
253253
}
254254
})*
255255

256-
impl Into<crate::adc::config::ExternalTrigger345> for &$t {
257-
fn into(self) -> crate::adc::config::ExternalTrigger345 {
256+
impl From<&$t> for crate::adc::config::ExternalTrigger345 {
257+
fn from(_val: &$t) -> Self {
258258
crate::adc::config::ExternalTrigger345::$variant345
259259
}
260260
}
@@ -276,14 +276,14 @@ macro_rules! impl_adc5678910_trigger {
276276
}
277277
}
278278

279-
impl Into<crate::adc::config::ExternalTrigger12> for &$t {
280-
fn into(self) -> crate::adc::config::ExternalTrigger12 {
279+
impl From<&$t> for crate::adc::config::ExternalTrigger12 {
280+
fn from(_val: &$t) -> Self {
281281
crate::adc::config::ExternalTrigger12::$variant12
282282
}
283283
}
284284

285-
impl Into<crate::adc::config::ExternalTrigger345> for &$t {
286-
fn into(self) -> crate::adc::config::ExternalTrigger345 {
285+
impl From<&$t> for crate::adc::config::ExternalTrigger345 {
286+
fn from(_val: &$t) -> Self {
287287
crate::adc::config::ExternalTrigger345::$variant345
288288
}
289289
}

src/hrtim/output.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::stm32::{
2-
HRTIM_MASTER, HRTIM_TIMA, HRTIM_TIMB, HRTIM_TIMC, HRTIM_TIMD, HRTIM_TIME, HRTIM_TIMF,
2+
HRTIM_TIMA, HRTIM_TIMB, HRTIM_TIMC, HRTIM_TIMD, HRTIM_TIME, HRTIM_TIMF,
33
};
44
use core::marker::PhantomData;
55

@@ -179,7 +179,7 @@ pins! {
179179
HRTIM_TIMF: CH1: PC6<Alternate<AF13>>, CH2: PC7<Alternate<AF13>>
180180
}
181181

182-
impl Pins<HRTIM_MASTER, (), ComplementaryImpossible> for () {
182+
impl<T> Pins<T, (), ComplementaryImpossible> for () {
183183
type Channel = ();
184184
}
185185

0 commit comments

Comments
 (0)