Skip to content

Commit c682d43

Browse files
committed
HAL update
1 parent 1a83f93 commit c682d43

File tree

10 files changed

+102
-322
lines changed

10 files changed

+102
-322
lines changed

board-tests/src/main.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,27 @@ fn main() -> ! {
122122
}
123123
TestCase::Pulse => {
124124
let mut output_pulsed = pinsa.pa0.into_push_pull_output();
125-
output_pulsed.pulse_mode(true, PinState::Low);
125+
output_pulsed.configure_pulse_mode(true, PinState::Low);
126126
rprintln!("Pulsing high 10 times..");
127127
output_pulsed.set_low().unwrap();
128128
for _ in 0..10 {
129129
output_pulsed.set_high().unwrap();
130130
cortex_m::asm::delay(25_000_000);
131131
}
132-
output_pulsed.pulse_mode(true, PinState::High);
132+
output_pulsed.configure_pulse_mode(true, PinState::High);
133133
rprintln!("Pulsing low 10 times..");
134134
for _ in 0..10 {
135135
output_pulsed.set_low().unwrap();
136136
cortex_m::asm::delay(25_000_000);
137137
}
138138
}
139139
TestCase::DelayGpio => {
140-
let mut out_0 = pinsa
141-
.pa0
142-
.into_readable_push_pull_output()
143-
.delay(true, false);
144-
let mut out_1 = pinsa
145-
.pa1
146-
.into_readable_push_pull_output()
147-
.delay(false, true);
148-
let mut out_2 = pinsa.pa3.into_readable_push_pull_output().delay(true, true);
140+
let mut out_0 = pinsa.pa0.into_readable_push_pull_output();
141+
out_0.configure_delay(true, false);
142+
let mut out_1 = pinsa.pa1.into_readable_push_pull_output();
143+
out_1.configure_delay(false, true);
144+
let mut out_2 = pinsa.pa3.into_readable_push_pull_output();
145+
out_2.configure_delay(true, true);
149146
for _ in 0..20 {
150147
out_0.toggle().unwrap();
151148
out_1.toggle().unwrap();

va108xx-hal/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
## [unreleased]
1010

11+
## [v0.10.0]
12+
13+
## Added
14+
15+
- A lot of missing `defmt::Format` implementations.
16+
17+
## Changed
18+
19+
- Missing GPIO API replacements from `x` to `configure_x`
20+
1121
## [v0.9.0]
1222

1323
## Fixed

va108xx-hal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ portable-atomic = "1"
4242
[features]
4343
default = ["rt"]
4444
rt = ["va108xx/rt"]
45-
defmt = ["dep:defmt", "fugit/defmt"]
45+
defmt = ["dep:defmt", "fugit/defmt", "embedded-hal/defmt-03"]
4646

4747
[package.metadata.docs.rs]
4848
all-features = true

va108xx-hal/src/gpio/asynch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl InputPinFuture {
115115

116116
EDGE_DETECTION[pin_id_to_offset(pin.id())]
117117
.store(false, core::sync::atomic::Ordering::Relaxed);
118-
pin.interrupt_edge(
118+
pin.configure_edge_interrupt(
119119
edge,
120120
InterruptConfig::new(irq, true, true),
121121
Some(sys_cfg),

va108xx-hal/src/gpio/dynpin.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ pub struct DynPinId {
181181
/// This `struct` takes ownership of a [`DynPinId`] and provides an API to
182182
/// access the corresponding regsiters.
183183
#[derive(Debug)]
184+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
184185
pub(crate) struct DynRegisters(DynPinId);
185186

186187
// [`DynRegisters`] takes ownership of the [`DynPinId`], and [`DynPin`]
@@ -392,11 +393,15 @@ impl DynPin {
392393
/// - Delay 2: 2
393394
/// - Delay 1 + Delay 2: 3
394395
#[inline]
395-
pub fn delay(self, delay_1: bool, delay_2: bool) -> Result<Self, InvalidPinTypeError> {
396+
pub fn configure_delay(
397+
&mut self,
398+
delay_1: bool,
399+
delay_2: bool,
400+
) -> Result<(), InvalidPinTypeError> {
396401
match self.mode {
397402
DynPinMode::Output(_) => {
398-
self.regs.delay(delay_1, delay_2);
399-
Ok(self)
403+
self.regs.configure_delay(delay_1, delay_2);
404+
Ok(())
400405
}
401406
_ => Err(InvalidPinTypeError(self.mode)),
402407
}
@@ -406,7 +411,7 @@ impl DynPin {
406411
/// When configured for pulse mode, a given pin will set the non-default state for exactly
407412
/// one clock cycle before returning to the configured default state
408413
#[inline]
409-
pub fn pulse_mode(
414+
pub fn configure_pulse_mode(
410415
&mut self,
411416
enable: bool,
412417
default_state: PinState,
@@ -422,22 +427,22 @@ impl DynPin {
422427

423428
/// See p.37 and p.38 of the programmers guide for more information.
424429
#[inline]
425-
pub fn filter_type(
430+
pub fn configure_filter_type(
426431
&mut self,
427432
filter: FilterType,
428433
clksel: FilterClkSel,
429434
) -> Result<(), InvalidPinTypeError> {
430435
match self.mode {
431436
DynPinMode::Input(_) => {
432-
self.regs.filter_type(filter, clksel);
437+
self.regs.configure_filter_type(filter, clksel);
433438
Ok(())
434439
}
435440
_ => Err(InvalidPinTypeError(self.mode)),
436441
}
437442
}
438443

439444
#[inline]
440-
pub fn interrupt_edge(
445+
pub fn configure_edge_interrupt(
441446
&mut self,
442447
edge_type: InterruptEdge,
443448
irq_cfg: InterruptConfig,
@@ -446,7 +451,7 @@ impl DynPin {
446451
) -> Result<(), InvalidPinTypeError> {
447452
match self.mode {
448453
DynPinMode::Input(_) | DynPinMode::Output(_) => {
449-
self.regs.interrupt_edge(edge_type);
454+
self.regs.configure_edge_interrupt(edge_type);
450455
self.irq_enb(irq_cfg, syscfg, irqsel);
451456
Ok(())
452457
}
@@ -455,7 +460,7 @@ impl DynPin {
455460
}
456461

457462
#[inline]
458-
pub fn interrupt_level(
463+
pub fn configure_level_interrupt(
459464
&mut self,
460465
level_type: InterruptLevel,
461466
irq_cfg: InterruptConfig,
@@ -464,7 +469,7 @@ impl DynPin {
464469
) -> Result<(), InvalidPinTypeError> {
465470
match self.mode {
466471
DynPinMode::Input(_) | DynPinMode::Output(_) => {
467-
self.regs.interrupt_level(level_type);
472+
self.regs.configure_level_interrupt(level_type);
468473
self.irq_enb(irq_cfg, syscfg, irqsel);
469474
Ok(())
470475
}

va108xx-hal/src/gpio/pin.rs

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,22 @@ use paste::paste;
8989
//==================================================================================================
9090

9191
#[derive(Debug, PartialEq, Eq)]
92+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
9293
pub enum InterruptEdge {
9394
HighToLow,
9495
LowToHigh,
9596
BothEdges,
9697
}
9798

9899
#[derive(Debug, PartialEq, Eq)]
100+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
99101
pub enum InterruptLevel {
100102
Low = 0,
101103
High = 1,
102104
}
103105

104106
#[derive(Debug, PartialEq, Eq)]
107+
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
105108
pub enum PinState {
106109
Low = 0,
107110
High = 1,
@@ -353,6 +356,7 @@ impl<I: PinId, M: PinMode> Pin<I, M> {
353356
}
354357
}
355358

359+
#[inline]
356360
pub fn id(&self) -> DynPinId {
357361
self.inner.id()
358362
}
@@ -482,11 +486,6 @@ impl<I: PinId, M: PinMode> Pin<I, M> {
482486
self.inner.regs.write_pin(false)
483487
}
484488

485-
#[inline]
486-
pub(crate) fn _toggle_with_toggle_reg(&mut self) {
487-
self.inner.regs.toggle();
488-
}
489-
490489
#[inline]
491490
pub(crate) fn _is_low(&self) -> bool {
492491
!self.inner.regs.read_pin()
@@ -599,7 +598,7 @@ impl<I: PinId, C: InputConfig> Pin<I, Input<C>> {
599598
syscfg: Option<&mut Sysconfig>,
600599
irqsel: Option<&mut Irqsel>,
601600
) {
602-
self.inner.regs.interrupt_edge(edge_type);
601+
self.inner.regs.configure_edge_interrupt(edge_type);
603602
self.irq_enb(irq_cfg, syscfg, irqsel);
604603
}
605604

@@ -610,7 +609,7 @@ impl<I: PinId, C: InputConfig> Pin<I, Input<C>> {
610609
syscfg: Option<&mut Sysconfig>,
611610
irqsel: Option<&mut Irqsel>,
612611
) {
613-
self.inner.regs.interrupt_level(level_type);
612+
self.inner.regs.configure_level_interrupt(level_type);
614613
self.irq_enb(irq_cfg, syscfg, irqsel);
615614
}
616615
}
@@ -622,42 +621,78 @@ impl<I: PinId, C: OutputConfig> Pin<I, Output<C>> {
622621
/// - Delay 2: 2
623622
/// - Delay 1 + Delay 2: 3
624623
#[inline]
625-
pub fn delay(self, delay_1: bool, delay_2: bool) -> Self {
626-
self.inner.regs.delay(delay_1, delay_2);
627-
self
624+
pub fn configure_delay(&mut self, delay_1: bool, delay_2: bool) {
625+
self.inner.regs.configure_delay(delay_1, delay_2);
628626
}
629627

630628
#[inline]
631629
pub fn toggle_with_toggle_reg(&mut self) {
632-
self._toggle_with_toggle_reg()
630+
self.inner.regs.toggle()
631+
}
632+
633+
#[deprecated(
634+
since = "0.9.0",
635+
note = "Please use the `configure_pulse_mode` method instead"
636+
)]
637+
pub fn pulse_mode(&mut self, enable: bool, default_state: PinState) {
638+
self.configure_pulse_mode(enable, default_state);
633639
}
634640

635641
/// See p.52 of the programmers guide for more information.
636642
/// When configured for pulse mode, a given pin will set the non-default state for exactly
637643
/// one clock cycle before returning to the configured default state
638-
pub fn pulse_mode(&mut self, enable: bool, default_state: PinState) {
644+
pub fn configure_pulse_mode(&mut self, enable: bool, default_state: PinState) {
639645
self.inner.regs.pulse_mode(enable, default_state);
640646
}
641647

648+
#[deprecated(
649+
since = "0.9.0",
650+
note = "Please use the `configure_edge_interrupt` method instead"
651+
)]
642652
pub fn interrupt_edge(
643653
&mut self,
644654
edge_type: InterruptEdge,
645655
irq_cfg: InterruptConfig,
646656
syscfg: Option<&mut Sysconfig>,
647657
irqsel: Option<&mut Irqsel>,
648658
) {
649-
self.inner.regs.interrupt_edge(edge_type);
659+
self.inner.regs.configure_edge_interrupt(edge_type);
650660
self.irq_enb(irq_cfg, syscfg, irqsel);
651661
}
652662

653-
pub fn interrupt_level(
663+
pub fn configure_edge_interrupt(
664+
&mut self,
665+
edge_type: InterruptEdge,
666+
irq_cfg: InterruptConfig,
667+
syscfg: Option<&mut Sysconfig>,
668+
irqsel: Option<&mut Irqsel>,
669+
) {
670+
self.inner.regs.configure_edge_interrupt(edge_type);
671+
self.irq_enb(irq_cfg, syscfg, irqsel);
672+
}
673+
674+
#[deprecated(
675+
since = "0.9.0",
676+
note = "Please use the `configure_level_interrupt` method instead"
677+
)]
678+
pub fn level_interrupt(
679+
&mut self,
680+
level_type: InterruptLevel,
681+
irq_cfg: InterruptConfig,
682+
syscfg: Option<&mut Sysconfig>,
683+
irqsel: Option<&mut Irqsel>,
684+
) {
685+
self.configure_level_interrupt(level_type, irq_cfg, syscfg, irqsel);
686+
}
687+
688+
pub fn configure_level_interrupt(
654689
&mut self,
655690
level_type: InterruptLevel,
656691
irq_cfg: InterruptConfig,
657692
syscfg: Option<&mut Sysconfig>,
658693
irqsel: Option<&mut Irqsel>,
659694
) {
660-
self.inner.regs.interrupt_level(level_type);
695+
self.inner.regs.configure_level_interrupt(level_type);
661696
self.irq_enb(irq_cfg, syscfg, irqsel);
662697
}
663698
}
@@ -666,7 +701,7 @@ impl<I: PinId, C: InputConfig> Pin<I, Input<C>> {
666701
/// See p.37 and p.38 of the programmers guide for more information.
667702
#[inline]
668703
pub fn configure_filter_type(&mut self, filter: FilterType, clksel: FilterClkSel) {
669-
self.inner.regs.filter_type(filter, clksel);
704+
self.inner.regs.configure_filter_type(filter, clksel);
670705
}
671706
}
672707

va108xx-hal/src/gpio/reg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ pub(super) unsafe trait RegisterInterface {
240240
/// Only useful for interrupt pins. Configure whether to use edges or level as interrupt soure
241241
/// When using edge mode, it is possible to generate interrupts on both edges as well
242242
#[inline]
243-
fn interrupt_edge(&mut self, edge_type: InterruptEdge) {
243+
fn configure_edge_interrupt(&mut self, edge_type: InterruptEdge) {
244244
unsafe {
245245
self.port_reg()
246246
.irq_sen()
@@ -267,7 +267,7 @@ pub(super) unsafe trait RegisterInterface {
267267

268268
/// Configure which edge or level type triggers an interrupt
269269
#[inline]
270-
fn interrupt_level(&mut self, level: InterruptLevel) {
270+
fn configure_level_interrupt(&mut self, level: InterruptLevel) {
271271
unsafe {
272272
self.port_reg()
273273
.irq_sen()
@@ -286,7 +286,7 @@ pub(super) unsafe trait RegisterInterface {
286286

287287
/// Only useful for input pins
288288
#[inline]
289-
fn filter_type(&mut self, filter: FilterType, clksel: FilterClkSel) {
289+
fn configure_filter_type(&mut self, filter: FilterType, clksel: FilterClkSel) {
290290
self.iocfg_port().modify(|_, w| {
291291
// Safety: Only write to register for this Pin ID
292292
unsafe {
@@ -349,7 +349,7 @@ pub(super) unsafe trait RegisterInterface {
349349
}
350350

351351
/// Only useful for output pins
352-
fn delay(&self, delay_1: bool, delay_2: bool) {
352+
fn configure_delay(&mut self, delay_1: bool, delay_2: bool) {
353353
let portreg = self.port_reg();
354354
unsafe {
355355
if delay_1 {

0 commit comments

Comments
 (0)