Skip to content

Commit e5e010a

Browse files
committed
Merge pull request 'larger GPIO refactoring and Async UART update' (#62) from uart-gpio-update into main
Reviewed-on: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/pulls/62
2 parents 31b25b0 + caf54e5 commit e5e010a

File tree

27 files changed

+909
-1154
lines changed

27 files changed

+909
-1154
lines changed

board-tests/src/main.rs

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
#![no_std]
77

88
use cortex_m_rt::entry;
9-
use embedded_hal::{
10-
delay::DelayNs,
11-
digital::{InputPin, OutputPin, StatefulOutputPin},
12-
};
9+
use embedded_hal::delay::DelayNs;
1310
use panic_rtt_target as _;
1411
use rtt_target::{rprintln, rtt_init_print};
1512
use va108xx_hal::{
@@ -67,35 +64,35 @@ fn main() -> ! {
6764
TestCase::TestBasic => {
6865
// Tie PORTA[0] to PORTA[1] for these tests!
6966
let mut out = pinsa.pa0.into_readable_push_pull_output();
70-
let mut input = pinsa.pa1.into_floating_input();
71-
out.set_high().unwrap();
72-
assert!(input.is_high().unwrap());
73-
out.set_low().unwrap();
74-
assert!(input.is_low().unwrap());
67+
let input = pinsa.pa1.into_floating_input();
68+
out.set_high();
69+
assert!(input.is_high());
70+
out.set_low();
71+
assert!(input.is_low());
7572
}
7673
TestCase::TestPullup => {
7774
// Tie PORTA[0] to PORTA[1] for these tests!
78-
let mut input = pinsa.pa1.into_pull_up_input();
79-
assert!(input.is_high().unwrap());
75+
let input = pinsa.pa1.into_pull_up_input();
76+
assert!(input.is_high());
8077
let mut out = pinsa.pa0.into_readable_push_pull_output();
81-
out.set_low().unwrap();
82-
assert!(input.is_low().unwrap());
83-
out.set_high().unwrap();
84-
assert!(input.is_high().unwrap());
78+
out.set_low();
79+
assert!(input.is_low());
80+
out.set_high();
81+
assert!(input.is_high());
8582
out.into_floating_input();
86-
assert!(input.is_high().unwrap());
83+
assert!(input.is_high());
8784
}
8885
TestCase::TestPulldown => {
8986
// Tie PORTA[0] to PORTA[1] for these tests!
90-
let mut input = pinsa.pa1.into_pull_down_input();
91-
assert!(input.is_low().unwrap());
87+
let input = pinsa.pa1.into_pull_down_input();
88+
assert!(input.is_low());
9289
let mut out = pinsa.pa0.into_push_pull_output();
93-
out.set_low().unwrap();
94-
assert!(input.is_low().unwrap());
95-
out.set_high().unwrap();
96-
assert!(input.is_high().unwrap());
90+
out.set_low();
91+
assert!(input.is_low());
92+
out.set_high();
93+
assert!(input.is_high());
9794
out.into_floating_input();
98-
assert!(input.is_low().unwrap());
95+
assert!(input.is_low());
9996
}
10097
TestCase::TestMask => {
10198
// Tie PORTA[0] to PORTA[1] for these tests!
@@ -110,11 +107,11 @@ fn main() -> ! {
110107
TestCase::PortB => {
111108
// Tie PORTB[22] to PORTB[23] for these tests!
112109
let mut out = pinsb.pb22.into_readable_push_pull_output();
113-
let mut input = pinsb.pb23.into_floating_input();
114-
out.set_high().unwrap();
115-
assert!(input.is_high().unwrap());
116-
out.set_low().unwrap();
117-
assert!(input.is_low().unwrap());
110+
let input = pinsb.pb23.into_floating_input();
111+
out.set_high();
112+
assert!(input.is_high());
113+
out.set_low();
114+
assert!(input.is_low());
118115
}
119116
TestCase::Perid => {
120117
assert_eq!(PinsA::get_perid(), 0x004007e1);
@@ -124,15 +121,15 @@ fn main() -> ! {
124121
let mut output_pulsed = pinsa.pa0.into_push_pull_output();
125122
output_pulsed.configure_pulse_mode(true, PinState::Low);
126123
rprintln!("Pulsing high 10 times..");
127-
output_pulsed.set_low().unwrap();
124+
output_pulsed.set_low();
128125
for _ in 0..10 {
129-
output_pulsed.set_high().unwrap();
126+
output_pulsed.set_high();
130127
cortex_m::asm::delay(25_000_000);
131128
}
132129
output_pulsed.configure_pulse_mode(true, PinState::High);
133130
rprintln!("Pulsing low 10 times..");
134131
for _ in 0..10 {
135-
output_pulsed.set_low().unwrap();
132+
output_pulsed.set_low();
136133
cortex_m::asm::delay(25_000_000);
137134
}
138135
}
@@ -144,9 +141,9 @@ fn main() -> ! {
144141
let mut out_2 = pinsa.pa3.into_readable_push_pull_output();
145142
out_2.configure_delay(true, true);
146143
for _ in 0..20 {
147-
out_0.toggle().unwrap();
148-
out_1.toggle().unwrap();
149-
out_2.toggle().unwrap();
144+
out_0.toggle();
145+
out_1.toggle();
146+
out_2.toggle();
150147
cortex_m::asm::delay(25_000_000);
151148
}
152149
}
@@ -159,40 +156,40 @@ fn main() -> ! {
159156
dp.tim0,
160157
);
161158
for _ in 0..5 {
162-
led1.toggle().ok();
159+
led1.toggle();
163160
ms_timer.delay_ms(500);
164-
led1.toggle().ok();
161+
led1.toggle();
165162
ms_timer.delay_ms(500);
166163
}
167164

168165
let mut delay_timer = CountdownTimer::new(&mut dp.sysconfig, 50.MHz(), dp.tim1);
169166
let mut pa0 = pinsa.pa0.into_readable_push_pull_output();
170167
for _ in 0..5 {
171-
led1.toggle().ok();
168+
led1.toggle();
172169
delay_timer.delay_ms(500);
173-
led1.toggle().ok();
170+
led1.toggle();
174171
delay_timer.delay_ms(500);
175172
}
176173
let ahb_freq: Hertz = 50.MHz();
177174
let mut syst_delay = cortex_m::delay::Delay::new(cp.SYST, ahb_freq.raw());
178175
// Test usecond delay using both TIM peripheral and SYST. Use the release image if you
179176
// want to verify the timings!
180177
loop {
181-
pa0.toggle().ok();
178+
pa0.toggle();
182179
delay_timer.delay_us(50);
183-
pa0.toggle().ok();
180+
pa0.toggle();
184181
delay_timer.delay_us(50);
185-
pa0.toggle_with_toggle_reg();
182+
pa0.toggle();
186183
syst_delay.delay_us(50);
187-
pa0.toggle_with_toggle_reg();
184+
pa0.toggle();
188185
syst_delay.delay_us(50);
189186
}
190187
}
191188
}
192189

193190
rprintln!("Test success");
194191
loop {
195-
led1.toggle().ok();
192+
led1.toggle();
196193
cortex_m::asm::delay(25_000_000);
197194
}
198195
}

examples/embassy/src/bin/async-gpio.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use embassy_executor::Spawner;
99
use embassy_sync::channel::{Receiver, Sender};
1010
use embassy_sync::{blocking_mutex::raw::ThreadModeRawMutex, channel::Channel};
1111
use embassy_time::{Duration, Instant, Timer};
12-
use embedded_hal::digital::{InputPin, OutputPin, StatefulOutputPin};
1312
use embedded_hal_async::digital::Wait;
1413
use panic_rtt_target as _;
1514
use rtt_target::{rprintln, rtt_init_print};
@@ -116,7 +115,7 @@ async fn main(spawner: Spawner) {
116115

117116
rprintln!("Example done, toggling LED0");
118117
loop {
119-
led0.toggle().unwrap();
118+
led0.toggle();
120119
Timer::after(Duration::from_millis(500)).await;
121120
}
122121
}

examples/embassy/src/bin/async-uart-rx.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use core::cell::RefCell;
1818
use critical_section::Mutex;
1919
use embassy_executor::Spawner;
2020
use embassy_time::Instant;
21-
use embedded_hal::digital::StatefulOutputPin;
2221
use embedded_io::Write;
2322
use embedded_io_async::Read;
2423
use heapless::spsc::{Consumer, Producer, Queue};
@@ -30,9 +29,9 @@ use va108xx_hal::{
3029
pac::{self, interrupt},
3130
prelude::*,
3231
uart::{
33-
self, on_interrupt_uart_b_overwriting,
34-
rx_asynch::{on_interrupt_uart_a, RxAsync},
35-
RxAsyncSharedConsumer, Tx,
32+
self, on_interrupt_rx_overwriting,
33+
rx_asynch::{on_interrupt_rx, RxAsync},
34+
Bank, RxAsyncOverwriting, Tx,
3635
},
3736
InterruptConfig,
3837
};
@@ -106,16 +105,16 @@ async fn main(spawner: Spawner) {
106105
*CONSUMER_UART_B.borrow(cs).borrow_mut() = Some(cons_uart_b);
107106
});
108107
let mut async_rx_uart_a = RxAsync::new(rx_uart_a, cons_uart_a);
109-
let async_rx_uart_b = RxAsyncSharedConsumer::new(rx_uart_b, &CONSUMER_UART_B);
108+
let async_rx_uart_b = RxAsyncOverwriting::new(rx_uart_b, &CONSUMER_UART_B);
110109
spawner
111110
.spawn(uart_b_task(async_rx_uart_b, tx_uart_b))
112111
.unwrap();
113112
let mut buf = [0u8; 256];
114113
loop {
115114
rprintln!("Current time UART A: {}", Instant::now().as_secs());
116-
led0.toggle().ok();
117-
led1.toggle().ok();
118-
led2.toggle().ok();
115+
led0.toggle();
116+
led1.toggle();
117+
led2.toggle();
119118
let read_bytes = async_rx_uart_a.read(&mut buf).await.unwrap();
120119
let read_str = core::str::from_utf8(&buf[..read_bytes]).unwrap();
121120
rprintln!(
@@ -128,7 +127,7 @@ async fn main(spawner: Spawner) {
128127
}
129128

130129
#[embassy_executor::task]
131-
async fn uart_b_task(mut async_rx: RxAsyncSharedConsumer<pac::Uartb, 256>, mut tx: Tx<pac::Uartb>) {
130+
async fn uart_b_task(mut async_rx: RxAsyncOverwriting<pac::Uartb, 256>, mut tx: Tx<pac::Uartb>) {
132131
let mut buf = [0u8; 256];
133132
loop {
134133
rprintln!("Current time UART B: {}", Instant::now().as_secs());
@@ -149,7 +148,7 @@ async fn uart_b_task(mut async_rx: RxAsyncSharedConsumer<pac::Uartb, 256>, mut t
149148
fn OC2() {
150149
let mut prod =
151150
critical_section::with(|cs| PRODUCER_UART_A.borrow(cs).borrow_mut().take().unwrap());
152-
let errors = on_interrupt_uart_a(&mut prod);
151+
let errors = on_interrupt_rx(Bank::A, &mut prod);
153152
critical_section::with(|cs| *PRODUCER_UART_A.borrow(cs).borrow_mut() = Some(prod));
154153
// In a production app, we could use a channel to send the errors to the main task.
155154
if let Err(errors) = errors {
@@ -162,7 +161,7 @@ fn OC2() {
162161
fn OC3() {
163162
let mut prod =
164163
critical_section::with(|cs| PRODUCER_UART_B.borrow(cs).borrow_mut().take().unwrap());
165-
let errors = on_interrupt_uart_b_overwriting(&mut prod, &CONSUMER_UART_B);
164+
let errors = on_interrupt_rx_overwriting(Bank::B, &mut prod, &CONSUMER_UART_B);
166165
critical_section::with(|cs| *PRODUCER_UART_B.borrow(cs).borrow_mut() = Some(prod));
167166
// In a production app, we could use a channel to send the errors to the main task.
168167
if let Err(errors) = errors {

examples/embassy/src/bin/async-uart-tx.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![no_main]
1313
use embassy_executor::Spawner;
1414
use embassy_time::{Duration, Instant, Ticker};
15-
use embedded_hal::digital::StatefulOutputPin;
1615
use embedded_io_async::Write;
1716
use panic_rtt_target as _;
1817
use rtt_target::{rprintln, rtt_init_print};
@@ -21,7 +20,7 @@ use va108xx_hal::{
2120
gpio::PinsA,
2221
pac::{self, interrupt},
2322
prelude::*,
24-
uart::{self, on_interrupt_uart_a_tx, TxAsync},
23+
uart::{self, on_interrupt_tx, Bank, TxAsync},
2524
InterruptConfig,
2625
};
2726

@@ -75,9 +74,9 @@ async fn main(_spawner: Spawner) {
7574
let mut idx = 0;
7675
loop {
7776
rprintln!("Current time: {}", Instant::now().as_secs());
78-
led0.toggle().ok();
79-
led1.toggle().ok();
80-
led2.toggle().ok();
77+
led0.toggle();
78+
led1.toggle();
79+
led2.toggle();
8180
let _written = async_tx
8281
.write(STR_LIST[idx].as_bytes())
8382
.await
@@ -93,5 +92,5 @@ async fn main(_spawner: Spawner) {
9392
#[interrupt]
9493
#[allow(non_snake_case)]
9594
fn OC2() {
96-
on_interrupt_uart_a_tx();
95+
on_interrupt_tx(Bank::A);
9796
}

examples/embassy/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![no_main]
33
use embassy_executor::Spawner;
44
use embassy_time::{Duration, Instant, Ticker};
5-
use embedded_hal::digital::StatefulOutputPin;
65
use panic_rtt_target as _;
76
use rtt_target::{rprintln, rtt_init_print};
87
use va108xx_embassy::embassy;
@@ -60,8 +59,8 @@ async fn main(_spawner: Spawner) {
6059
loop {
6160
ticker.next().await;
6261
rprintln!("Current time: {}", Instant::now().as_secs());
63-
led0.toggle().ok();
64-
led1.toggle().ok();
65-
led2.toggle().ok();
62+
led0.toggle();
63+
led1.toggle();
64+
led2.toggle();
6665
}
6766
}

examples/rtic/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ rtic-sync = { version = "1.3", features = ["defmt-03"] }
2222
once_cell = {version = "1", default-features = false, features = ["critical-section"]}
2323
ringbuf = { version = "0.4.7", default-features = false, features = ["portable-atomic"] }
2424

25-
va108xx-hal = "0.9"
26-
vorago-reb1 = "0.7"
25+
va108xx-hal = { version = "0.9", path = "../../va108xx-hal" }
26+
vorago-reb1 = { version = "0.7", path = "../../vorago-reb1" }

examples/rtic/src/bin/blinky-button-rtic.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,16 @@ mod app {
6969

7070
// Configure an edge interrupt on the button and route it to interrupt vector 15
7171
let mut button = Button::new(pinsa.pa11.into_floating_input());
72-
button.configure_edge_interrupt(
73-
edge_irq,
74-
InterruptConfig::new(pac::interrupt::OC15, true, true),
75-
Some(&mut dp.sysconfig),
76-
Some(&mut dp.irqsel),
77-
);
7872

7973
if mode == PressMode::Toggle {
8074
// This filter debounces the switch for edge based interrupts
8175
button.configure_filter_type(FilterType::FilterFourClockCycles, FilterClkSel::Clk1);
8276
set_clk_div_register(&mut dp.sysconfig, FilterClkSel::Clk1, 50_000);
8377
}
78+
button.configure_and_enable_edge_interrupt(
79+
edge_irq,
80+
InterruptConfig::new(pac::interrupt::OC15, true, true),
81+
);
8482
let mut leds = Leds::new(
8583
pinsa.pa10.into_push_pull_output(),
8684
pinsa.pa7.into_push_pull_output(),

examples/rtic/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#[rtic::app(device = pac, dispatchers = [OC31, OC30, OC29])]
66
mod app {
77
use cortex_m::asm;
8-
use embedded_hal::digital::StatefulOutputPin;
98
use panic_rtt_target as _;
109
use rtic_example::SYSCLK_FREQ;
1110
use rtic_monotonics::systick::prelude::*;
@@ -58,9 +57,9 @@ mod app {
5857
async fn blinky(cx: blinky::Context) {
5958
loop {
6059
rprintln!("toggling LEDs");
61-
cx.local.led0.toggle().ok();
62-
cx.local.led1.toggle().ok();
63-
cx.local.led2.toggle().ok();
60+
cx.local.led0.toggle();
61+
cx.local.led1.toggle();
62+
cx.local.led2.toggle();
6463
Mono::delay(1000.millis()).await;
6564
}
6665
}

examples/simple/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ embedded-io = "0.6"
1616
cortex-m-semihosting = "0.5.0"
1717

1818
[dependencies.va108xx-hal]
19+
path = "../../va108xx-hal"
1920
version = "0.9"
2021
features = ["rt", "defmt"]
2122

2223
[dependencies.vorago-reb1]
24+
path = "../../vorago-reb1"
2325
version = "0.7"

0 commit comments

Comments
 (0)