Skip to content

Commit b9dd6ad

Browse files
authored
Merge pull request #757 from rust-embedded/optional-irq
reexport features
2 parents f8a5479 + 22e97d3 commit b9dd6ad

File tree

4 files changed

+58
-34
lines changed

4 files changed

+58
-34
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
- Add `reexport_core_peripherals` and `reexport_interrupt` features disabled by default
1011
- rename `const-generic` feature to `array_proxy`
1112
- `FieldWriter` takes offset as struct field instead of const generic.
1213
Improves SVD field array access

src/generate/device.rs

+39-34
Original file line numberDiff line numberDiff line change
@@ -103,46 +103,51 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke
103103

104104
let mut fields = TokenStream::new();
105105
let mut exprs = TokenStream::new();
106-
if config.target == Target::CortexM {
107-
out.extend(quote! {
108-
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
109-
#[cfg(feature = "rt")]
110-
pub use cortex_m_rt::interrupt;
111-
#[cfg(feature = "rt")]
112-
pub use self::Interrupt as interrupt;
113-
});
106+
match config.target {
107+
Target::CortexM => {
108+
if config.reexport_core_peripherals {
109+
let fpu = fpu_present.then(|| quote!(FPU,));
110+
out.extend(quote! {
111+
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
112+
pub use cortex_m::peripheral::{
113+
CBP, CPUID, DCB, DWT, FPB, #fpu ITM, MPU, NVIC, SCB, SYST, TPIU,
114+
};
115+
});
116+
}
114117

115-
if fpu_present {
116-
out.extend(quote! {
117-
pub use cortex_m::peripheral::{
118-
CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, SYST, TPIU,
119-
};
120-
});
121-
} else {
122-
out.extend(quote! {
123-
pub use cortex_m::peripheral::{
124-
CBP, CPUID, DCB, DWT, FPB, ITM, MPU, NVIC, SCB, SYST, TPIU,
125-
};
126-
});
118+
if config.reexport_interrupt {
119+
out.extend(quote! {
120+
#[cfg(feature = "rt")]
121+
pub use cortex_m_rt::interrupt;
122+
#[cfg(feature = "rt")]
123+
pub use self::Interrupt as interrupt;
124+
});
125+
}
127126
}
128-
}
129127

130-
if config.target == Target::Msp430 {
131-
out.extend(quote! {
128+
Target::Msp430 => {
132129
// XXX: Are there any core peripherals, really? Requires bump of msp430 crate.
133130
// pub use msp430::peripheral::Peripherals as CorePeripherals;
134-
#[cfg(feature = "rt")]
135-
pub use msp430_rt::interrupt;
136-
#[cfg(feature = "rt")]
137-
pub use self::Interrupt as interrupt;
138-
});
139-
}
131+
if config.reexport_interrupt {
132+
out.extend(quote! {
133+
#[cfg(feature = "rt")]
134+
pub use msp430_rt::interrupt;
135+
#[cfg(feature = "rt")]
136+
pub use self::Interrupt as interrupt;
137+
});
138+
}
139+
}
140140

141-
if config.target == Target::Mips {
142-
out.extend(quote! {
143-
#[cfg(feature = "rt")]
144-
pub use mips_rt::interrupt;
145-
});
141+
Target::Mips => {
142+
if config.reexport_interrupt {
143+
out.extend(quote! {
144+
#[cfg(feature = "rt")]
145+
pub use mips_rt::interrupt;
146+
});
147+
}
148+
}
149+
150+
_ => {}
146151
}
147152

148153
let generic_file = include_str!("generic.rs");

src/main.rs

+12
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ fn run() -> Result<()> {
163163
.long("source_type")
164164
.help("Specify file/stream format"),
165165
)
166+
.arg(
167+
Arg::new("reexport_core_peripherals")
168+
.long("reexport_core_peripherals")
169+
.action(ArgAction::SetTrue)
170+
.help("For Cortex-M target reexport peripherals from cortex-m crate"),
171+
)
172+
.arg(
173+
Arg::new("reexport_interrupt")
174+
.long("reexport_interrupt")
175+
.action(ArgAction::SetTrue)
176+
.help("Reexport interrupt macro from cortex-m-rt like crates"),
177+
)
166178
.arg(
167179
Arg::new("log_level")
168180
.long("log")

src/util.rs

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ pub struct Config {
6565
pub log_level: Option<String>,
6666
#[cfg_attr(feature = "serde", serde(default))]
6767
pub interrupt_link_section: Option<String>,
68+
#[cfg_attr(feature = "serde", serde(default))]
69+
pub reexport_core_peripherals: bool,
70+
#[cfg_attr(feature = "serde", serde(default))]
71+
pub reexport_interrupt: bool,
6872
}
6973

7074
#[derive(Clone, Debug, PartialEq, Eq)]
@@ -129,6 +133,8 @@ impl Default for Config {
129133
source_type: SourceType::default(),
130134
log_level: None,
131135
interrupt_link_section: None,
136+
reexport_core_peripherals: false,
137+
reexport_interrupt: false,
132138
}
133139
}
134140
}

0 commit comments

Comments
 (0)