Rework library structure

Changed:

- Move most library components to new [`vorago-shared-periphs`](https://egit.irs.uni-stuttgart.de/rust/vorago-shared-periphs)
  which is mostly re-exported in this crate.
- All HAL API constructors now have a more consistent argument order: PAC structures and resource
  management structures first, then clock configuration, then any other configuration.
- Overhaul and simplification of several HAL APIs. The system configuration and IRQ router
  peripheral instance generally does not need to be passed to HAL API anymore.
- All HAL drivers are now type erased. The constructors will still expect and consume the PAC
  singleton component for resource management purposes, but are not cached anymore.
- Refactoring of GPIO library to be more inline with embassy GPIO API.

Added:

- I2C clock timeout feature support.
This commit is contained in:
2025-04-12 17:01:53 +02:00
parent 5b2ded51f9
commit fc0775ddb4
67 changed files with 774 additions and 9246 deletions

View File

@ -6,14 +6,13 @@ edition = "2021"
[dependencies]
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
panic-halt = "1"
rtt-target = "0.6"
panic-rtt-target = "0.2"
defmt = "1"
defmt-rtt = "0.4"
panic-probe = { version = "0.3", features = ["print-defmt"] }
embedded-hal = "1"
embedded-hal-nb = "1"
embedded-io = "0.6"
[dependencies.va108xx-hal]
version = "0.11"
features = ["rt"]
path = "../va108xx-hal"

View File

@ -7,18 +7,21 @@
use cortex_m_rt::entry;
use embedded_hal::delay::DelayNs;
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
// Logging provider
use defmt_rtt as _;
// Panic provider
use panic_probe as _;
use va108xx_hal::{
gpio::{PinState, PinsA, PinsB},
pac::{self, interrupt},
gpio::{regs::Gpio, Input, Output, PinState, Pull},
pac,
pins::{PinsA, PinsB, Port},
prelude::*,
time::Hertz,
timer::{default_ms_irq_handler, set_up_ms_tick, CountdownTimer, InterruptConfig},
timer::CountdownTimer,
};
#[allow(dead_code)]
#[derive(Debug)]
#[derive(Debug, defmt::Format)]
enum TestCase {
// Tie PORTA[0] to PORTA[1] for these tests!
TestBasic,
@ -37,13 +40,12 @@ enum TestCase {
#[entry]
fn main() -> ! {
rtt_init_print!();
rprintln!("-- VA108xx Test Application --");
let mut dp = pac::Peripherals::take().unwrap();
defmt::println!("-- VA108xx Test Application --");
let dp = pac::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();
let pinsa = PinsA::new(&mut dp.sysconfig, dp.porta);
let pinsb = PinsB::new(&mut dp.sysconfig, dp.portb);
let mut led1 = pinsa.pa10.into_readable_push_pull_output();
let pinsa = PinsA::new(dp.porta);
let pinsb = PinsB::new(dp.portb);
let mut led1 = Output::new(pinsa.pa10, PinState::Low);
let test_case = TestCase::DelayMs;
match test_case {
@ -51,20 +53,20 @@ fn main() -> ! {
| TestCase::TestPulldown
| TestCase::TestPullup
| TestCase::TestMask => {
rprintln!(
defmt::info!(
"Test case {:?}. Make sure to tie PORTA[0] to PORTA[1]",
test_case
);
}
_ => {
rprintln!("Test case {:?}", test_case);
defmt::info!("Test case {:?}", test_case);
}
}
match test_case {
TestCase::TestBasic => {
// Tie PORTA[0] to PORTA[1] for these tests!
let mut out = pinsa.pa0.into_readable_push_pull_output();
let input = pinsa.pa1.into_floating_input();
let mut out = Output::new(pinsa.pa0, PinState::Low);
let input = Input::new_floating(pinsa.pa1);
out.set_high();
assert!(input.is_high());
out.set_low();
@ -72,73 +74,75 @@ fn main() -> ! {
}
TestCase::TestPullup => {
// Tie PORTA[0] to PORTA[1] for these tests!
let input = pinsa.pa1.into_pull_up_input();
let input = Input::new_with_pull(pinsa.pa1, Pull::Up);
assert!(input.is_high());
let mut out = pinsa.pa0.into_readable_push_pull_output();
let mut out = Output::new(pinsa.pa0, PinState::Low);
out.set_low();
assert!(input.is_low());
out.set_high();
assert!(input.is_high());
out.into_floating_input();
assert!(input.is_high());
}
TestCase::TestPulldown => {
// Tie PORTA[0] to PORTA[1] for these tests!
let input = pinsa.pa1.into_pull_down_input();
let input = Input::new_with_pull(pinsa.pa1, Pull::Down);
assert!(input.is_low());
let mut out = pinsa.pa0.into_push_pull_output();
let mut out = Output::new(pinsa.pa0, PinState::Low);
out.set_low();
assert!(input.is_low());
out.set_high();
assert!(input.is_high());
out.into_floating_input();
assert!(input.is_low());
}
TestCase::TestMask => {
// Tie PORTA[0] to PORTA[1] for these tests!
let mut input = pinsa.pa1.into_pull_down_input();
// Need to test this low-level..
/*
let mut input = Input::new_with_pull(pinsa.pa1, Pull::Down);
input.clear_datamask();
assert!(!input.datamask());
let mut out = pinsa.pa0.into_push_pull_output();
out.clear_datamask();
assert!(input.is_low_masked().is_err());
assert!(out.set_high_masked().is_err());
*/
}
TestCase::PortB => {
// Tie PORTB[22] to PORTB[23] for these tests!
let mut out = pinsb.pb22.into_readable_push_pull_output();
let input = pinsb.pb23.into_floating_input();
let mut out = Output::new(pinsb.pb22, PinState::Low);
let input = Input::new_floating(pinsb.pb23);
out.set_high();
assert!(input.is_high());
out.set_low();
assert!(input.is_low());
}
TestCase::Perid => {
assert_eq!(PinsA::get_perid(), 0x004007e1);
assert_eq!(PinsB::get_perid(), 0x004007e1);
let mmio_porta = Gpio::new_mmio(Port::A);
assert_eq!(mmio_porta.read_perid(), 0x004007e1);
let mmio_porta = Gpio::new_mmio(Port::B);
assert_eq!(mmio_porta.read_perid(), 0x004007e1);
}
TestCase::Pulse => {
let mut output_pulsed = pinsa.pa0.into_push_pull_output();
// TODO: Fix
let mut output_pulsed = Output::new(pinsa.pa0, PinState::Low);
output_pulsed.configure_pulse_mode(true, PinState::Low);
rprintln!("Pulsing high 10 times..");
defmt::info!("Pulsing high 10 times..");
output_pulsed.set_low();
for _ in 0..10 {
output_pulsed.set_high();
cortex_m::asm::delay(25_000_000);
}
output_pulsed.configure_pulse_mode(true, PinState::High);
rprintln!("Pulsing low 10 times..");
defmt::info!("Pulsing low 10 times..");
for _ in 0..10 {
output_pulsed.set_low();
cortex_m::asm::delay(25_000_000);
}
}
TestCase::DelayGpio => {
let mut out_0 = pinsa.pa0.into_readable_push_pull_output();
let mut out_0 = Output::new(pinsa.pa0, PinState::Low);
out_0.configure_delay(true, false);
let mut out_1 = pinsa.pa1.into_readable_push_pull_output();
let mut out_1 = Output::new(pinsa.pa1, PinState::Low);
out_1.configure_delay(false, true);
let mut out_2 = pinsa.pa3.into_readable_push_pull_output();
let mut out_2 = Output::new(pinsa.pa3, PinState::Low);
out_2.configure_delay(true, true);
for _ in 0..20 {
out_0.toggle();
@ -148,22 +152,8 @@ fn main() -> ! {
}
}
TestCase::DelayMs => {
let mut ms_timer = set_up_ms_tick(
InterruptConfig::new(pac::Interrupt::OC0, true, true),
&mut dp.sysconfig,
Some(&mut dp.irqsel),
50.MHz(),
dp.tim0,
);
for _ in 0..5 {
led1.toggle();
ms_timer.delay_ms(500);
led1.toggle();
ms_timer.delay_ms(500);
}
let mut delay_timer = CountdownTimer::new(&mut dp.sysconfig, 50.MHz(), dp.tim1);
let mut pa0 = pinsa.pa0.into_readable_push_pull_output();
let mut delay_timer = CountdownTimer::new(dp.tim1, 50.MHz());
let mut pa0 = Output::new(pinsa.pa0, PinState::Low);
for _ in 0..5 {
led1.toggle();
delay_timer.delay_ms(500);
@ -187,15 +177,9 @@ fn main() -> ! {
}
}
rprintln!("Test success");
defmt::info!("Test success");
loop {
led1.toggle();
cortex_m::asm::delay(25_000_000);
}
}
#[interrupt]
#[allow(non_snake_case)]
fn OC0() {
default_ms_irq_handler()
}