Skip to content

Commit 70039a9

Browse files
authored
Merge branch 'master' into features/edition-2018
2 parents ee7cddd + 116a125 commit 70039a9

File tree

8 files changed

+206
-196
lines changed

8 files changed

+206
-196
lines changed

ci/script.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ test_svd() {
2020
}
2121

2222
main() {
23+
# Ensure that `cargo test` works to avoid surprising people, though it
24+
# doesn't help with our actual coverage.
25+
cargo test
26+
2327
if [ $TRAVIS_OS_NAME = windows ]; then
2428
cargo check --target $TARGET
2529
return

src/generate/device.rs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ use crate::Target;
99
use crate::generate::{interrupt, peripheral};
1010

1111
/// Whole device generation
12-
pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String) -> Result<Vec<Tokens>> {
12+
pub fn render(
13+
d: &Device,
14+
target: Target,
15+
nightly: bool,
16+
device_x: &mut String,
17+
) -> Result<Vec<Tokens>> {
1318
let mut out = vec![];
1419

1520
let doc = format!(
@@ -21,13 +26,13 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
2126
env!("CARGO_PKG_VERSION")
2227
);
2328

24-
if *target == Target::Msp430 {
29+
if target == Target::Msp430 {
2530
out.push(quote! {
2631
#![feature(abi_msp430_interrupt)]
2732
});
2833
}
2934

30-
if *target != Target::None && *target != Target::CortexM && *target != Target::RISCV {
35+
if target != Target::None && target != Target::CortexM && target != Target::RISCV {
3136
out.push(quote! {
3237
#![cfg_attr(feature = "rt", feature(global_asm))]
3338
#![cfg_attr(feature = "rt", feature(use_extern_macros))]
@@ -49,7 +54,7 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
4954
});
5055
}
5156

52-
match *target {
57+
match target {
5358
Target::CortexM => {
5459
out.push(quote! {
5560
extern crate cortex_m;
@@ -88,7 +93,7 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
8893
let mut fpu_present = true;
8994

9095
if let Some(cpu) = d.cpu.as_ref() {
91-
let bits = util::unsuffixed(cpu.nvic_priority_bits as u64);
96+
let bits = util::unsuffixed(u64::from(cpu.nvic_priority_bits));
9297

9398
out.push(quote! {
9499
/// Number available in the NVIC for configuring priority
@@ -100,21 +105,20 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
100105

101106
out.extend(interrupt::render(target, &d.peripherals, device_x)?);
102107

103-
let core_peripherals: &[&str];
104-
105-
if fpu_present {
106-
core_peripherals = &[
107-
"CBP", "CPUID", "DCB", "DWT", "FPB", "FPU", "ITM", "MPU", "NVIC", "SCB", "SYST", "TPIU"
108-
];
108+
let core_peripherals: &[_] = if fpu_present {
109+
&[
110+
"CBP", "CPUID", "DCB", "DWT", "FPB", "FPU", "ITM", "MPU", "NVIC", "SCB", "SYST",
111+
"TPIU",
112+
]
109113
} else {
110-
core_peripherals = &[
111-
"CBP", "CPUID", "DCB", "DWT", "FPB", "ITM", "MPU", "NVIC", "SCB", "SYST", "TPIU"
112-
];
113-
}
114+
&[
115+
"CBP", "CPUID", "DCB", "DWT", "FPB", "ITM", "MPU", "NVIC", "SCB", "SYST", "TPIU",
116+
]
117+
};
114118

115119
let mut fields = vec![];
116120
let mut exprs = vec![];
117-
if *target == Target::CortexM {
121+
if target == Target::CortexM {
118122
out.push(quote! {
119123
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
120124
#[cfg(feature = "rt")]
@@ -139,7 +143,7 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
139143
}
140144

141145
for p in &d.peripherals {
142-
if *target == Target::CortexM && core_peripherals.contains(&&*p.name.to_uppercase()) {
146+
if target == Target::CortexM && core_peripherals.contains(&&*p.name.to_uppercase()) {
143147
// Core peripherals are handled above
144148
continue;
145149
}
@@ -150,7 +154,8 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
150154
.as_ref()
151155
.map(|v| &v[..])
152156
.unwrap_or(&[])
153-
.is_empty() && p.derived_from.is_none()
157+
.is_empty()
158+
&& p.derived_from.is_none()
154159
{
155160
// No register block will be generated so don't put this peripheral
156161
// in the `Peripherals` struct
@@ -166,12 +171,13 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
166171
exprs.push(quote!(#id: #id { _marker: PhantomData }));
167172
}
168173

169-
let take = match *target {
174+
let take = match target {
170175
Target::CortexM => Some(Ident::new("cortex_m")),
171176
Target::Msp430 => Some(Ident::new("msp430")),
172177
Target::RISCV => Some(Ident::new("riscv")),
173178
Target::None => None,
174-
}.map(|krate| {
179+
}
180+
.map(|krate| {
175181
quote! {
176182
/// Returns all the peripherals *once*
177183
#[inline]

src/generate/interrupt.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::Target;
1212

1313
/// Generates code for `src/interrupt.rs`
1414
pub fn render(
15-
target: &Target,
15+
target: Target,
1616
peripherals: &[Peripheral],
1717
device_x: &mut String,
1818
) -> Result<Vec<Tokens>> {
@@ -75,10 +75,10 @@ pub fn render(
7575
}
7676

7777
let n = util::unsuffixed(u64(pos));
78-
match *target {
78+
match target {
7979
Target::CortexM => {
8080
for name in &names {
81-
writeln!(device_x, "PROVIDE({} = DefaultHandler);" ,name).unwrap();
81+
writeln!(device_x, "PROVIDE({} = DefaultHandler);", name).unwrap();
8282
}
8383

8484
root.push(quote! {
@@ -169,7 +169,7 @@ pub fn render(
169169
}
170170
};
171171

172-
if *target == Target::CortexM {
172+
if target == Target::CortexM {
173173
root.push(interrupt_enum);
174174
} else {
175175
mod_items.push(quote! {
@@ -190,13 +190,13 @@ pub fn render(
190190
});
191191
}
192192

193-
if *target != Target::None {
194-
let abi = match *target {
193+
if target != Target::None {
194+
let abi = match target {
195195
Target::Msp430 => "msp430-interrupt",
196196
_ => "C",
197197
};
198198

199-
if *target != Target::CortexM {
199+
if target != Target::CortexM {
200200
mod_items.push(quote! {
201201
#[cfg(feature = "rt")]
202202
#[macro_export]
@@ -248,19 +248,17 @@ pub fn render(
248248
}
249249
}
250250

251-
if !interrupts.is_empty() {
252-
if *target != Target::CortexM {
253-
root.push(quote! {
254-
#[doc(hidden)]
255-
pub mod interrupt {
256-
#(#mod_items)*
257-
}
258-
});
251+
if !interrupts.is_empty() && target != Target::CortexM {
252+
root.push(quote! {
253+
#[doc(hidden)]
254+
pub mod interrupt {
255+
#(#mod_items)*
256+
}
257+
});
259258

260-
root.push(quote! {
261-
pub use self::interrupt::Interrupt;
262-
});
263-
}
259+
root.push(quote! {
260+
pub use self::interrupt::Interrupt;
261+
});
264262
}
265263

266264
Ok(root)

0 commit comments

Comments
 (0)