From 1512a6f67bc0c91c86e28219febce3927f5cffaf Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Wed, 5 Aug 2020 22:35:49 +0200 Subject: [PATCH] Rework `Interrupt` enum for MSP430 This also removes the `bare-metal` dependency from PACs created for MSP430, as requested in https://github.com/rust-embedded/svd2rust/pull/455#issuecomment-665214017 Signed-off-by: Daniel Egger --- CHANGELOG.md | 3 ++ ci/script.sh | 3 -- src/generate/interrupt.rs | 71 +++++++++++++++++++++++---------------- src/lib.rs | 3 +- 4 files changed, 46 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb784a04..1e9893d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/). use the `msp430_rt::interrupt` attribute macro and `device.x` for interrupt support. The `INTERRUPT` array has been renamed `__INTERRUPT`. +- Documented the nature of the `Interrupt` enum on MSP430 and consequently + removed all use of `bare-metal` from that architecture + - Don't generate pre Edition 2018 `extern crate` statements anymore ## [v0.17.0] - 2019-12-31 diff --git a/ci/script.sh b/ci/script.sh index 575dfe00..4d5f91c5 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -493,9 +493,6 @@ main() { # test other targets (architectures) OTHER) - echo '[dependencies.bare-metal]' >> $td/Cargo.toml - echo 'version = "0.1.0"' >> $td/Cargo.toml - echo '[dependencies.msp430]' >> $td/Cargo.toml echo 'version = "0.2.2"' >> $td/Cargo.toml diff --git a/src/generate/interrupt.rs b/src/generate/interrupt.rs index a89de391..ae378849 100644 --- a/src/generate/interrupt.rs +++ b/src/generate/interrupt.rs @@ -160,41 +160,54 @@ pub fn render( (quote!(#[repr(u8)]), quote!(*#self_token as u8)) }; - let interrupt_enum = quote! { - ///Enumeration of all the interrupts - #[derive(Copy, Clone, Debug, PartialEq, Eq)] - #enum_repr - pub enum Interrupt { - #variants - } - - unsafe impl bare_metal::Nr for Interrupt { - #[inline(always)] - fn nr(&#self_token) -> u8 { - #nr_expr + if target == Target::Msp430 { + let interrupt_enum = quote! { + ///Enumeration of all the interrupts. This enum is seldom used in application or library crates. It is present primarily for documenting the device's implemented interrupts. + #[derive(Copy, Clone, Debug, PartialEq, Eq)] + #enum_repr + pub enum Interrupt { + #variants } - } - }; + }; - if target == Target::CortexM || target == Target::Msp430 { root.extend(interrupt_enum); } else { - mod_items.extend(quote! { - #interrupt_enum - - #[derive(Debug, Copy, Clone)] - pub struct TryFromInterruptError(()); - - impl Interrupt { - #[inline] - pub fn try_from(value: u8) -> Result { - match value { - #from_arms - _ => Err(TryFromInterruptError(())), - } + let interrupt_enum = quote! { + ///Enumeration of all the interrupts + #[derive(Copy, Clone, Debug, PartialEq, Eq)] + #enum_repr + pub enum Interrupt { + #variants + } + + unsafe impl bare_metal::Nr for Interrupt { + #[inline(always)] + fn nr(&#self_token) -> u8 { + #nr_expr } } - }); + }; + + if target == Target::CortexM { + root.extend(interrupt_enum); + } else { + mod_items.extend(quote! { + #interrupt_enum + + #[derive(Debug, Copy, Clone)] + pub struct TryFromInterruptError(()); + + impl Interrupt { + #[inline] + pub fn try_from(value: u8) -> Result { + match value { + #from_arms + _ => Err(TryFromInterruptError(())), + } + } + } + }); + } } if target != Target::None { diff --git a/src/lib.rs b/src/lib.rs index c4d98103..210cdb72 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -106,13 +106,12 @@ //! ``` //! //! The resulting crate must provide an opt-in "rt" feature and depend on these crates: -//! `bare-metal` v0.2.x, `msp430` v0.2.x, `msp430-rt` v0.2.x and `vcell` v0.1.x. Furthermore +//! `msp430` v0.2.x, `msp430-rt` v0.2.x and `vcell` v0.1.x. Furthermore //! the "device" feature of `msp430-rt` must be enabled when the "rt" feature is enabled. The //! `Cargo.toml` of the device crate will look like this: //! //! ``` toml //! [dependencies] -//! bare-metal = "0.2.0" //! msp430 = "0.2.0" //! vcell = "0.1.0" //!