Skip to content

Commit 5205d8e

Browse files
bors[bot]burrbull
andauthored
Merge #588
588: v0.22 r=Emilgardis a=burrbull Co-authored-by: Andrey Zgarbul <zgarbul.andrey@gmail.com>
2 parents a3c3df5 + e49e8a8 commit 5205d8e

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [v0.22.0] - 2022-04-05
11+
1012
### Added
1113

1214
- added `dyn` keyword to sanatizer.
15+
1316
### Changed
1417

1518
- Generate Rust arrays for all register & cluster arrays with sequential_addresses.
@@ -670,7 +673,8 @@ peripheral.register.write(|w| w.field().set());
670673

671674
- Initial version of the `svd2rust` tool
672675

673-
[Unreleased]: https://github.com/rust-embedded/svd2rust/compare/v0.21.0...HEAD
676+
[Unreleased]: https://github.com/rust-embedded/svd2rust/compare/v0.22.0...HEAD
677+
[v0.22.0]: https://github.com/rust-embedded/svd2rust/compare/v0.21.0...v0.22.0
674678
[v0.21.0]: https://github.com/rust-embedded/svd2rust/compare/v0.20.0...v0.21.0
675679
[v0.20.0]: https://github.com/rust-embedded/svd2rust/compare/v0.19.0...v0.20.0
676680
[v0.19.0]: https://github.com/rust-embedded/svd2rust/compare/v0.18.0...v0.19.0

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ keywords = [
2323
license = "MIT OR Apache-2.0"
2424
name = "svd2rust"
2525
repository = "https://github.com/rust-embedded/svd2rust/"
26-
version = "0.21.0"
26+
version = "0.22.0"
2727
readme = "README.md"
2828

2929
[package.metadata.deb]
@@ -54,7 +54,7 @@ version = "0.13.1"
5454

5555
[dependencies.svd-rs]
5656
features = ["serde"]
57-
version = "0.13.0"
57+
version = "0.13.1"
5858

5959
[dependencies.syn]
6060
version = "1.0"

src/generate/register.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub fn fields(
318318
let can_write = can_write && (f.access != Some(Access::ReadOnly));
319319

320320
let mask = u64::MAX >> (64 - width);
321-
let hexmask = &util::hex(mask);
321+
let hexmask = &util::digit_or_hex(mask);
322322
let offset = u64::from(offset);
323323
let rv = properties.reset_value.map(|rv| (rv >> offset) & mask);
324324
let fty = width.to_ty()?;
@@ -348,7 +348,7 @@ pub fn fields(
348348

349349
let field_dim = match f {
350350
Field::Array(_, de) => {
351-
let (first, index) = if let Some(dim_index) = &de.dim_index {
351+
let first = if let Some(dim_index) = &de.dim_index {
352352
if let Ok(first) = dim_index[0].parse::<u32>() {
353353
let sequential_indexes = dim_index
354354
.iter()
@@ -357,17 +357,14 @@ pub fn fields(
357357
if !sequential_indexes {
358358
return Err(anyhow!("unsupported array indexes in {}", f.name));
359359
}
360-
(first, None)
360+
first
361361
} else {
362-
(0, de.dim_index.clone())
362+
0
363363
}
364364
} else {
365-
(0, None)
366-
};
367-
let suffixes: Vec<_> = match index {
368-
Some(ix) => ix,
369-
None => (0..de.dim).map(|i| (first + i).to_string()).collect(),
365+
0
370366
};
367+
let suffixes: Vec<_> = de.indexes().collect();
371368
let suffixes_str = format!("({}-{})", first, first + de.dim - 1);
372369
Some((first, de.dim, de.dim_increment, suffixes, suffixes_str))
373370
}

src/util.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,14 @@ pub fn access_of(properties: &RegisterProperties, fields: Option<&[Field]>) -> A
260260
})
261261
}
262262

263+
pub fn digit_or_hex(n: u64) -> TokenStream {
264+
if n < 10 {
265+
unsuffixed(n)
266+
} else {
267+
hex(n)
268+
}
269+
}
270+
263271
/// Turns `n` into an unsuffixed separated hex token
264272
pub fn hex(n: u64) -> TokenStream {
265273
let (h4, h3, h2, h1) = (

0 commit comments

Comments
 (0)