Skip to content

Commit 43b9383

Browse files
bors[bot]adamgreig
andauthored
Merge #266
266: Implement InterruptNumber for bare_metal::Nr r=therealprof a=adamgreig This PR aims to help backwards compatibility by implementing the new `InterruptNumber` trait (coming in cortex-m 0.7) for the old `bare_metal::Nr` trait. With this included in cortex-m 0.7, existing PACs generated from the current svd2rust (0.17) will work with cortex-m 0.7, and new PACs generated from a to-be-released svd2rust which uses `InterruptNumber directly will also work. We can then remove this implementation in cortex-m 0.8 and upgrade cortex-m to depend on bare-metal 1.0 (or not depend on it at all) at that time. With this PR in place, the upgrade path looks like: * We release cortex-m 0.7, which users can upgrade to without needing a new PAC * We release svd2rust 0.18, which will generate new PACs * PACs update, now requiring cortex-m 0.7 * Users can update their PAC so long as they've already upgraded to cortex-m 0.7 * For cortex-m 0.8, we drop this impl and move off bare-metal 0.2, and a new PAC is required to use 0.8 onwards Co-authored-by: Adam Greig <[email protected]>
2 parents aa77c89 + b7541dd commit 43b9383

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- New `InterruptNumber` trait is now required on interrupt arguments to the
1313
various NVIC functions, replacing the previous use of `Nr` from bare-metal.
14+
For backwards compatibility, `InterruptNumber` is implemented for types
15+
which are `Nr + Copy`, but this will be removed in a future version.
1416
- Associated const `PTR` is introduced to Core Peripherals to
1517
eventually replace the existing `ptr()` API.
1618
- A delay driver based on SysTick.

src/interrupt.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Interrupts
22
3-
pub use bare_metal::{CriticalSection, Mutex};
3+
pub use bare_metal::{CriticalSection, Mutex, Nr};
44

55
/// Trait for enums of external interrupt numbers.
66
///
@@ -23,6 +23,15 @@ pub unsafe trait InterruptNumber: Copy {
2323
fn number(self) -> u16;
2424
}
2525

26+
/// Implement InterruptNumber for the old bare_metal::Nr trait.
27+
/// This implementation is for backwards compatibility only and will be removed in cortex-m 0.8.
28+
#[deprecated(since="0.7.0", note="Please update your PAC to one using the latest svd2rust")]
29+
unsafe impl<T: Nr + Copy> InterruptNumber for T {
30+
fn number(self) -> u16 {
31+
self.nr() as u16
32+
}
33+
}
34+
2635
/// Disables all interrupts
2736
#[inline]
2837
pub fn disable() {

0 commit comments

Comments
 (0)