Skip to content

Commit a2747b1

Browse files
committed
timer: Interrupt API Do not have nvic as an assocated function
This is to improve ergonimics. The associated function is not really needed, when an assocated const already exists
1 parent 723dce4 commit a2747b1

File tree

5 files changed

+18
-51
lines changed

5 files changed

+18
-51
lines changed

src/serial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ where
741741
///
742742
/// though this function can not be used in a const context.
743743
#[doc(alias = "unmask")]
744-
pub fn nvic() -> Interrupt {
744+
pub fn nvic(&self) -> Interrupt {
745745
<Usart as Instance>::INTERRUPT
746746
}
747747

src/timer.rs

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::pac::{Interrupt, RCC};
1818
use crate::rcc::{Clocks, APB1, APB2};
1919
use crate::time::rate::*;
2020

21-
mod interrupts;
21+
pub mod interrupts;
2222

2323
/// A monotonic nondecreasing timer.
2424
#[derive(Debug, Clone, Copy)]
@@ -65,33 +65,6 @@ impl MonoTimer {
6565
}
6666
}
6767

68-
// #[non_exhaustive]
69-
// // TODO: ...
70-
// pub struct CommonRegisterBlock {
71-
// cr1: i32,
72-
// // ...
73-
// }
74-
75-
/// Wrapper around interrupt types for the timers.
76-
#[derive(Copy, Clone, Debug)]
77-
// FIXME: Interrupt is not formattable?
78-
// #[cfg_attr(feature = "defmt", derive(defmt::Format))]
79-
// TODO: Does it make sense to introduce an enum for that?
80-
// enum ItrTypes {Global, Break, Update, Trigger, CaptureCompare}
81-
#[non_exhaustive] // To make the type non-creatable but still accessable.
82-
pub struct InterruptTypes {
83-
/// Global Interrupt
84-
global: Option<Interrupt>,
85-
/// Break Interrupt
86-
r#break: Option<Interrupt>,
87-
/// Update Interrupt
88-
update: Option<Interrupt>,
89-
/// Trigger and communication Interrupt
90-
trigger: Option<Interrupt>,
91-
/// Capture and compare interupt
92-
capture_compare: Option<Interrupt>,
93-
}
94-
9568
/// A measurement of a monotonically nondecreasing clock
9669
#[derive(Debug, Clone, Copy)]
9770
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -181,9 +154,7 @@ where
181154
/// ```
182155
///
183156
/// though this function can not be used in a const context.
184-
// TODO: Maybe this function should be implemented as a trait:
185-
// Like extended timer and normal / simple timer?
186-
pub fn nvic() -> <TIM as self::interrupts::InterruptNumber>::Interrupt {
157+
pub fn nvic(&self) -> <TIM as self::interrupts::InterruptNumber>::Interrupt {
187158
<TIM as self::interrupts::InterruptNumber>::INTERRUPT
188159
}
189160

@@ -344,11 +315,6 @@ pub trait Instance:
344315
/// Peripheral bus instance which is responsible for the peripheral
345316
type APB;
346317

347-
/// The associated interrupt number, used to unmask / enable the interrupt
348-
/// with [`cortex_m::peripheral::NVIC::unmask()`]
349-
// const INTERRUPT: InterruptTypes;
350-
const INTERRUPT: Interrupt = Interrupt::TIM2;
351-
352318
#[doc(hidden)]
353319
fn enable_clock(apb: &mut Self::APB);
354320
#[doc(hidden)]
@@ -425,8 +391,6 @@ macro_rules! timer {
425391
impl crate::private::Sealed for crate::pac::$TIMX {}
426392
impl Instance for crate::pac::$TIMX {
427393
type APB = $APB;
428-
// TODO: This has to be variable.
429-
const INTERRUPT: Interrupt = Interrupt::TIM2;
430394

431395
#[inline]
432396
fn enable_clock(apb: &mut Self::APB) {

src/timer/interrupts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct InterruptTypes {
2121
// FIXME: This super-trait constrained makes it difficult to use this trait
2222
// without cfg(feature...)
2323
// pub trait InterruptNumber: crate::private::Sealed {
24+
// TODO: Rename, because in conflict with: use cortex_m::interrupt::InterruptNumber;
2425
pub trait InterruptNumber {
2526
type Interrupt;
2627
const INTERRUPT: Self::Interrupt;

testsuite/tests/timer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
use core::sync::atomic::{AtomicBool, Ordering};
55

6+
use cortex_m::interrupt::InterruptNumber;
67
use defmt_rtt as _;
78
use panic_probe as _;
89

910
use stm32f3xx_hal as hal;
1011

1112
use hal::rcc::{Clocks, APB1};
12-
use hal::timer::{Event, Instance, MonoTimer, Timer};
13+
use hal::timer::{self, Event, Instance, MonoTimer, Timer};
1314
use hal::{interrupt, pac, prelude::*};
1415

1516
use pac::TIM2;
@@ -118,7 +119,6 @@ fn TIM2() {
118119
//
119120
// This is all needed, to clear the fired interrupt.
120121
assert!(cortex_m::peripheral::NVIC::is_active(
121-
<pac::TIM2 as Instance>::INTERRUPT
122+
<pac::TIM2 as timer::interrupts::InterruptNumber>::INTERRUPT
122123
));
123-
cortex_m::peripheral::NVIC::mask(<pac::TIM2 as Instance>::INTERRUPT);
124-
}
124+
cortex_m::peripheral::NVIC::mask(<pac::TIM2 as timer::interrupts::InterruptNumber>::INTERRUPT); }

testsuite/tests/uart.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,18 @@ mod tests {
142142
.into_af7_open_drain(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl),
143143
};
144144

145-
unsafe { cortex_m::peripheral::NVIC::unmask(<pac::USART1 as Instance>::INTERRUPT) }
145+
let serial1 = Serial::new(
146+
dp.USART1,
147+
(serial_pair.0, serial_pair.1),
148+
9600.Bd(),
149+
clocks,
150+
&mut rcc.apb2,
151+
);
152+
153+
unsafe { cortex_m::peripheral::NVIC::unmask(serial1.nvic()) }
146154

147155
super::State {
148-
serial1: Some(Serial::new(
149-
dp.USART1,
150-
(serial_pair.0, serial_pair.1),
151-
9600.Bd(),
152-
clocks,
153-
&mut rcc.apb2,
154-
)),
156+
serial1: Some(serial1),
155157
serial_slow: Some(Serial::new(
156158
dp.USART2,
157159
(cs_pair_1.0, cs_pair_2.1),

0 commit comments

Comments
 (0)