Skip to content

Commit beada27

Browse files
committed
Add warning about indexing register arrays
1 parent c13b87d commit beada27

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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 warning about indexing register arrays
1011
- Skip generating `.add(0)` and `1 *` in accessors
1112
- Bump MSRV of generated code to 1.76
1213
- move `must_use` from methods to generic type

src/generate/peripheral.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,10 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
10521052
&description,
10531053
);
10541054
let mut accessors = Vec::with_capacity((array_info.dim + 1) as _);
1055+
let first_name = svd::array::names(info, array_info).next().unwrap();
1056+
let note = (array_info.indexes().next().unwrap() != "0").then(||
1057+
format!("<div class=\"warning\">`n` is number of {0} in array. `n == 0` corresponds to `{first_name}` {0}.</div>", "cluster")
1058+
);
10551059
accessors.push(
10561060
Accessor::Array(ArrayAccessor {
10571061
doc,
@@ -1060,6 +1064,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
10601064
offset: info.address_offset,
10611065
dim: array_info.dim,
10621066
increment: array_info.dim_increment,
1067+
note,
10631068
})
10641069
.raw_if(!array_convertible),
10651070
);
@@ -1234,6 +1239,10 @@ fn expand_register(
12341239
&description,
12351240
);
12361241
let mut accessors = Vec::with_capacity((array_info.dim + 1) as _);
1242+
let first_name = svd::array::names(info, array_info).next().unwrap();
1243+
let note = (array_info.indexes().next().unwrap() != "0").then(||
1244+
format!("<div class=\"warning\">`n` is number of {0} in array. `n == 0` corresponds to `{first_name}` {0}.</div>", "register")
1245+
);
12371246
accessors.push(
12381247
Accessor::Array(ArrayAccessor {
12391248
doc,
@@ -1242,6 +1251,7 @@ fn expand_register(
12421251
offset: info.address_offset,
12431252
dim: array_info.dim,
12441253
increment: array_info.dim_increment,
1254+
note,
12451255
})
12461256
.raw_if(!array_convertible),
12471257
);

src/generate/peripheral/accessor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub struct ArrayAccessor {
145145
pub offset: u32,
146146
pub dim: u32,
147147
pub increment: u32,
148+
pub note: Option<String>,
148149
}
149150

150151
#[derive(Clone, Debug)]

0 commit comments

Comments
 (0)