Skip to content

Commit 8d4c36e

Browse files
committed
more accessors
1 parent 213cc35 commit 8d4c36e

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

src/generate/peripheral.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
10151015
})
10161016
}
10171017
Cluster::Array(info, array_info) => {
1018+
let ends_with_index = info.name.ends_with("[%s]") || info.name.ends_with("%s");
10181019
let increment_bits = array_info.dim_increment * BITS_PER_BYTE;
10191020
if cluster_size > increment_bits {
10201021
let cname = &cluster.name;
@@ -1074,7 +1075,7 @@ fn expand_cluster(cluster: &Cluster, config: &Config) -> Result<Vec<RegisterBloc
10741075
}
10751076
.into()
10761077
});
1077-
if !sequential_indexes_from0 {
1078+
if !sequential_indexes_from0 || !ends_with_index {
10781079
for (i, ci) in svd::cluster::expand(info, array_info).enumerate() {
10791080
let idx_name = ci.name.to_snake_case_ident(span);
10801081
let doc = make_comment(
@@ -1184,6 +1185,7 @@ fn expand_register(
11841185
})
11851186
}
11861187
Register::Array(info, array_info) => {
1188+
let ends_with_index = info.name.ends_with("[%s]") || info.name.ends_with("%s");
11871189
let sequential_addresses = (array_info.dim == 1)
11881190
|| (register_size == array_info.dim_increment * BITS_PER_BYTE);
11891191
let disjoint_sequential_addresses = (array_info.dim == 1)
@@ -1258,7 +1260,7 @@ fn expand_register(
12581260
}
12591261
.into()
12601262
});
1261-
if !sequential_indexes_from0 {
1263+
if !sequential_indexes_from0 || !ends_with_index {
12621264
for (i, ri) in svd::register::expand(info, array_info).enumerate() {
12631265
let idx_name =
12641266
util::fullname(&ri.name, &info.alternate_group, config.ignore_groups)

src/lib.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
//!
172172
//! ```ignore
173173
//! let mut peripherals = stm32f30x::Peripherals::take().unwrap();
174-
//! peripherals.GPIOA.odr.write(|w| w.bits(1));
174+
//! peripherals.GPIOA.odr().write(|w| w.bits(1));
175175
//! ```
176176
//!
177177
//! This method can only be successfully called *once* -- that's why the method returns an `Option`.
@@ -195,7 +195,7 @@
195195
//! impl PA0 {
196196
//! fn is_high(&self) -> bool {
197197
//! // NOTE(unsafe) actually safe because this is an atomic read with no side effects
198-
//! unsafe { (*GPIOA::ptr()).idr.read().bits() & 1 != 0 }
198+
//! unsafe { (*GPIOA::ptr()).idr().read().bits() & 1 != 0 }
199199
//! }
200200
//!
201201
//! fn is_low(&self) -> bool {
@@ -315,7 +315,7 @@
315315
//!
316316
//! ```ignore
317317
//! // is the SADD0 bit of the CR2 register set?
318-
//! if i2c1.c2r.read().sadd0().bit() {
318+
//! if i2c1.c2r().read().sadd0().bit() {
319319
//! // yes
320320
//! } else {
321321
//! // no
@@ -330,7 +330,7 @@
330330
//! Usage looks like this:
331331
//!
332332
//! ```ignore
333-
//! if i2c1.c2r.write().reset()
333+
//! if i2c1.c2r().write().reset()
334334
//! ```
335335
//!
336336
//! ## `write`
@@ -360,7 +360,7 @@
360360
//! // Starting from the reset value, `0x0000_0000`, change the bitfields SADD0
361361
//! // and SADD1 to `1` and `0b0011110` respectively and write that to the
362362
//! // register CR2.
363-
//! i2c1.cr2.write(|w| unsafe { w.sadd0().bit(true).sadd1().bits(0b0011110) });
363+
//! i2c1.cr2().write(|w| unsafe { w.sadd0().bit(true).sadd1().bits(0b0011110) });
364364
//! // NOTE ^ unsafe because you could be writing a reserved bit pattern into
365365
//! // the register. In this case, the SVD doesn't provide enough information to
366366
//! // check whether that's the case.
@@ -383,10 +383,10 @@
383383
//!
384384
//! ```ignore
385385
//! // Set the START bit to 1 while KEEPING the state of the other bits intact
386-
//! i2c1.cr2.modify(|_, w| unsafe { w.start().bit(true) });
386+
//! i2c1.cr2().modify(|_, w| unsafe { w.start().bit(true) });
387387
//!
388388
//! // TOGGLE the STOP bit, all the other bits will remain untouched
389-
//! i2c1.cr2.modify(|r, w| w.stop().bit(!r.stop().bit()));
389+
//! i2c1.cr2().modify(|r, w| w.stop().bit(!r.stop().bit()));
390390
//! ```
391391
//!
392392
//! # enumeratedValues
@@ -399,7 +399,7 @@
399399
//! The new `read` API returns an enum that you can match:
400400
//!
401401
//! ```ignore
402-
//! match gpioa.dir.read().pin0().variant() {
402+
//! match gpioa.dir().read().pin0().variant() {
403403
//! gpioa::dir::PIN0_A::Input => { .. },
404404
//! gpioa::dir::PIN0_A::Output => { .. },
405405
//! }
@@ -408,7 +408,7 @@
408408
//! or test for equality
409409
//!
410410
//! ```ignore
411-
//! if gpioa.dir.read().pin0().variant() == gpio::dir::PIN0_A::Input {
411+
//! if gpioa.dir().read().pin0().variant() == gpio::dir::PIN0_A::Input {
412412
//! ..
413413
//! }
414414
//! ```
@@ -417,19 +417,19 @@
417417
//! having to import the enum:
418418
//!
419419
//! ```ignore
420-
//! if gpioa.dir.read().pin0().is_input() {
420+
//! if gpioa.dir().read().pin0().is_input() {
421421
//! ..
422422
//! }
423423
//!
424-
//! if gpioa.dir.read().pin0().is_output() {
424+
//! if gpioa.dir().read().pin0().is_output() {
425425
//! ..
426426
//! }
427427
//! ```
428428
//!
429429
//! The original `bits` method is available as well:
430430
//!
431431
//! ```ignore
432-
//! if gpioa.dir.read().pin0().bits() == 0 {
432+
//! if gpioa.dir().read().pin0().bits() == 0 {
433433
//! ..
434434
//! }
435435
//! ```
@@ -439,22 +439,22 @@
439439
//!
440440
//! ```ignore
441441
//! // enum PIN0_A { Input, Output }
442-
//! gpioa.dir.write(|w| w.pin0().variant(gpio::dir::PIN0_A::Output));
442+
//! gpioa.dir().write(|w| w.pin0().variant(gpio::dir::PIN0_A::Output));
443443
//! ```
444444
//!
445445
//! There are convenience methods to pick one of the variants without having to
446446
//! import the enum:
447447
//!
448448
//! ```ignore
449-
//! gpioa.dir.write(|w| w.pin0().output());
449+
//! gpioa.dir().write(|w| w.pin0().output());
450450
//! ```
451451
//!
452452
//! The `bits` (or `bit`) method is still available but will become safe if it's
453453
//! impossible to write a reserved bit pattern into the register:
454454
//!
455455
//! ```ignore
456456
//! // safe because there are only two options: `0` or `1`
457-
//! gpioa.dir.write(|w| w.pin0().bit(true));
457+
//! gpioa.dir().write(|w| w.pin0().bit(true));
458458
//! ```
459459
//!
460460
//! # Interrupt API
@@ -513,9 +513,9 @@
513513
//!
514514
//! ```ignore
515515
//! // These can be called from different contexts even though they are modifying the same register
516-
//! P1.p1out.set_bits(|w| unsafe { w.bits(1 << 1) });
517-
//! P1.p1out.clear_bits(|w| unsafe { w.bits(!(1 << 2)) });
518-
//! P1.p1out.toggle_bits(|w| unsafe { w.bits(1 << 4) });
516+
//! P1.p1out().set_bits(|w| unsafe { w.bits(1 << 1) });
517+
//! P1.p1out().clear_bits(|w| unsafe { w.bits(!(1 << 2)) });
518+
//! P1.p1out().toggle_bits(|w| unsafe { w.bits(1 << 4) });
519519
//! // if impl_debug was used one can print Registers or RegisterBlocks
520520
//! // print single register
521521
//! println!("RTC_CNT {:#?}", unsafe { &*esp32s3::RTC_CNTL::ptr() }.options0);

0 commit comments

Comments
 (0)