Skip to content

Commit 6914112

Browse files
committed
s/local/locals/g, make Peripherals fields uppercase, update docs
1 parent 9266b73 commit 6914112

File tree

3 files changed

+42
-24
lines changed

3 files changed

+42
-24
lines changed

ci/script.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ main() {
3535
# test crate
3636
cargo init --name foo $td
3737
echo 'bare-metal = "0.1.0"' >> $td/Cargo.toml
38-
echo 'cortex-m = { git = "https://github.com/japaric/cortex-m" }' >> $td/Cargo.toml
39-
echo 'cortex-m-rt = { git = "https://github.com/japaric/cortex-m-rt" }' >> $td/Cargo.toml
38+
echo 'cortex-m = "0.3.0"' >> $td/Cargo.toml
39+
echo 'cortex-m-rt = "0.3.0"' >> $td/Cargo.toml
4040
echo 'vcell = "0.1.0"' >> $td/Cargo.toml
4141

4242
case $VENDOR in

src/generate.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn device(
133133
}
134134

135135
::generate::peripheral(p, &d.peripherals, items, &d.defaults)?;
136-
let p = &*p.name;
136+
let p = p.name.to_sanitized_upper_case();
137137
let id = Ident::new(&*p);
138138
fields.push(quote! {
139139
#[doc = #p]
@@ -305,12 +305,12 @@ pub fn interrupt(
305305
#[cfg(feature = "rt")]
306306
#[macro_export]
307307
macro_rules! interrupt {
308-
($NAME:ident, $f:ident, local: {
308+
($NAME:ident, $path:path, locals: {
309309
$($lvar:ident:$lty:ident = $lval:expr;)*
310310
}) => {
311311
#[allow(non_snake_case)]
312312
mod $NAME {
313-
pub struct Local {
313+
pub struct Locals {
314314
$(
315315
pub $lvar: $lty,
316316
)*
@@ -323,27 +323,27 @@ pub fn interrupt(
323323
// check that the handler exists
324324
let _ = $crate::interrupt::Interrupt::$NAME;
325325

326-
static mut LOCAL: self::$NAME::Local =
327-
self::$NAME::Local {
326+
static mut LOCALS: self::$NAME::Locals =
327+
self::$NAME::Locals {
328328
$(
329329
$lvar: $lval,
330330
)*
331331
};
332332

333333
// type checking
334-
let f: fn(&mut self::$NAME::Local) = $f;
335-
f(unsafe { &mut LOCAL });
334+
let f: fn(&mut self::$NAME::Locals) = $path;
335+
f(unsafe { &mut LOCALS });
336336
}
337337
};
338-
($NAME:ident, $f:ident) => {
338+
($NAME:ident, $path:path) => {
339339
#[allow(non_snake_case)]
340340
#[no_mangle]
341341
pub extern "C" fn $NAME() {
342342
// check that the handler exists
343343
let _ = $crate::interrupt::Interrupt::$NAME;
344344

345345
// type checking
346-
let f: fn() = $f;
346+
let f: fn() = $path;
347347
f();
348348
}
349349
}

src/lib.rs

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,20 @@
1818
//!
1919
//! # Usage
2020
//!
21+
//! `svd2rust` supports Cortex-M and MSP430 microcontrollers. The generated
22+
//! crate can be tailored for either architecture using the `--target` flag. The
23+
//! flag accepts "cortex-m", "msp430" and "none" as values. "none" can be used
24+
//! to generate a crate that's architecture agnostic and that should work for
25+
//! architectures that `svd2rust` doesn't currently know about like the Cortex-A
26+
//! architecture.
27+
//!
28+
//! If the `--target` flag is omitted `svd2rust` assumes the target is the
29+
//! Cortex-M architecture.
30+
//!
2131
//! ```
2232
//! $ svd2rust -i STM32F30x.svd | rustfmt | tee src/lib.rs
23-
//! //! Peripheral access API for STM32F30X microcontrollers (generated using svd2rust v0.11.0)
33+
//! //! Peripheral access API for STM32F30X microcontrollers
34+
//! //! (generated using svd2rust v0.11.0)
2435
//!
2536
//! #![deny(missing_docs)]
2637
//! #![deny(warnings)]
@@ -79,9 +90,16 @@
7990
//!
8091
//! The generated crate depends on:
8192
//!
82-
//! - [`cortex-m-rt`](https://crates.io/crates/cortex-m-rt) v0.3.x
83-
//! - [`cortex-m`](https://crates.io/crates/cortex-m) v0.3.x
93+
//! - [`bare-metal`](https://crates.io/crates/bare-metal) v0.1.x
8494
//! - [`vcell`](https://crates.io/crates/vcell) v0.1.x
95+
//! - [`cortex-m-rt`](https://crates.io/crates/cortex-m-rt) v0.3.x if targeting
96+
//! the Cortex-M architecture.
97+
//! - [`cortex-m`](https://crates.io/crates/cortex-m) v0.3.x if targeting the
98+
//! Cortex-M architecture.
99+
//! - [`msp430`](https://crates.io/crates/msp430) v0.1.x if targeting the MSP430
100+
//! architecture.
101+
//! - [`msp430-rt`](https://crates.io/crates/msp430-rt) v0.1.x if targeting the
102+
//! MSP430 architecture.
85103
//!
86104
//! # Peripheral API
87105
//!
@@ -365,10 +383,10 @@
365383
/// must have signature `fn()`.
366384
///
367385
/// Optionally, a third argument may be used to declare interrupt local data.
368-
/// The handler will have exclusive access to this data on each invocation. If
369-
/// the third argument is used then the signature of the handler function must
370-
/// be `fn(&mut $NAME::Local)` where `$NAME` is the first argument passed to the
371-
/// macro.
386+
/// The handler will have exclusive access to these *local* variables on each
387+
/// invocation. If the third argument is used then the signature of the handler
388+
/// function must be `fn(&mut $NAME::Locals)` where `$NAME` is the first argument
389+
/// passed to the macro.
372390
///
373391
/// # Example
374392
///
@@ -379,14 +397,14 @@
379397
/// print!(".");
380398
/// }
381399
///
382-
/// interrupt!(TIM3, tick, local: {
400+
/// interrupt!(TIM3, tick, locals: {
383401
/// tick: bool = false;
384402
/// });
385403
///
386-
/// fn tick(local: &mut TIM3::Local) {
387-
/// local.tick = !local.tick;
404+
/// fn tick(locals: &mut TIM3::Locals) {
405+
/// locals.tick = !locals.tick;
388406
///
389-
/// if local.tick {
407+
/// if locals.tick {
390408
/// println!("Tick");
391409
/// } else {
392410
/// println!("Tock");
@@ -395,8 +413,8 @@
395413
/// ```
396414
#[macro_export]
397415
macro_rules! interrupt {
398-
($NAME:ident, $body:path) => {};
399-
($NAME:ident, $body:path, local: {
416+
($NAME:ident, $path:path) => {};
417+
($NAME:ident, $path:path, locals: {
400418
$($lvar:ident: $lty:ty = $lval:expr;)+
401419
}) => {};
402420
}

0 commit comments

Comments
 (0)