2 Commits

Author SHA1 Message Date
d82b8e4d07 cleaned up dependencies 2025-04-24 15:36:19 +02:00
64a7cef47a 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.
2025-04-24 15:06:52 +02:00
9 changed files with 87 additions and 60 deletions

View File

@@ -6,13 +6,14 @@ edition = "2021"
[dependencies]
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
defmt = "1"
defmt-rtt = "0.4"
panic-probe = { version = "0.3", features = ["print-defmt"] }
panic-halt = "1"
rtt-target = "0.6"
panic-rtt-target = "0.2"
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,21 +7,18 @@
use cortex_m_rt::entry;
use embedded_hal::delay::DelayNs;
// Logging provider
use defmt_rtt as _;
// Panic provider
use panic_probe as _;
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
use va108xx_hal::{
gpio::{regs::Gpio, Input, Output, PinState, Pull},
pac,
pins::{PinsA, PinsB, Port},
gpio::{PinState, PinsA, PinsB},
pac::{self, interrupt},
prelude::*,
time::Hertz,
timer::CountdownTimer,
timer::{default_ms_irq_handler, set_up_ms_tick, CountdownTimer, InterruptConfig},
};
#[allow(dead_code)]
#[derive(Debug, defmt::Format)]
#[derive(Debug)]
enum TestCase {
// Tie PORTA[0] to PORTA[1] for these tests!
TestBasic,
@@ -40,12 +37,13 @@ enum TestCase {
#[entry]
fn main() -> ! {
defmt::println!("-- VA108xx Test Application --");
let dp = pac::Peripherals::take().unwrap();
rtt_init_print!();
rprintln!("-- VA108xx Test Application --");
let mut dp = pac::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();
let pinsa = PinsA::new(dp.porta);
let pinsb = PinsB::new(dp.portb);
let mut led1 = Output::new(pinsa.pa10, PinState::Low);
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 test_case = TestCase::DelayMs;
match test_case {
@@ -53,20 +51,20 @@ fn main() -> ! {
| TestCase::TestPulldown
| TestCase::TestPullup
| TestCase::TestMask => {
defmt::info!(
rprintln!(
"Test case {:?}. Make sure to tie PORTA[0] to PORTA[1]",
test_case
);
}
_ => {
defmt::info!("Test case {:?}", test_case);
rprintln!("Test case {:?}", test_case);
}
}
match test_case {
TestCase::TestBasic => {
// Tie PORTA[0] to PORTA[1] for these tests!
let mut out = Output::new(pinsa.pa0, PinState::Low);
let input = Input::new_floating(pinsa.pa1);
let mut out = pinsa.pa0.into_readable_push_pull_output();
let input = pinsa.pa1.into_floating_input();
out.set_high();
assert!(input.is_high());
out.set_low();
@@ -74,58 +72,55 @@ fn main() -> ! {
}
TestCase::TestPullup => {
// Tie PORTA[0] to PORTA[1] for these tests!
let input = Input::new_with_pull(pinsa.pa1, Pull::Up);
let input = pinsa.pa1.into_pull_up_input();
assert!(input.is_high());
let mut out = Output::new(pinsa.pa0, PinState::Low);
let mut out = pinsa.pa0.into_readable_push_pull_output();
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 = Input::new_with_pull(pinsa.pa1, Pull::Down);
let input = pinsa.pa1.into_pull_down_input();
assert!(input.is_low());
let mut out = Output::new(pinsa.pa0, PinState::Low);
let mut out = pinsa.pa0.into_push_pull_output();
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!
// Need to test this low-level..
/*
let mut input = Input::new_with_pull(pinsa.pa1, Pull::Down);
let mut input = pinsa.pa1.into_pull_down_input();
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 = Output::new(pinsb.pb22, PinState::Low);
let input = Input::new_floating(pinsb.pb23);
let mut out = pinsb.pb22.into_readable_push_pull_output();
let input = pinsb.pb23.into_floating_input();
out.set_high();
assert!(input.is_high());
out.set_low();
assert!(input.is_low());
}
TestCase::Perid => {
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);
assert_eq!(PinsA::get_perid(), 0x004007e1);
assert_eq!(PinsB::get_perid(), 0x004007e1);
}
TestCase::Pulse => {
// TODO: Fix
/*
let mut output_pulsed = Output::new(pinsa.pa0, PinState::Low);
let mut output_pulsed = pinsa.pa0.into_push_pull_output();
output_pulsed.configure_pulse_mode(true, PinState::Low);
defmt::info!("Pulsing high 10 times..");
rprintln!("Pulsing high 10 times..");
output_pulsed.set_low();
for _ in 0..10 {
output_pulsed.set_high();
@@ -137,11 +132,8 @@ fn main() -> ! {
output_pulsed.set_low();
cortex_m::asm::delay(25_000_000);
}
*/
}
TestCase::DelayGpio => {
// TODO: Fix
/*
let mut out_0 = pinsa.pa0.into_readable_push_pull_output();
out_0.configure_delay(true, false);
let mut out_1 = pinsa.pa1.into_readable_push_pull_output();
@@ -154,11 +146,24 @@ fn main() -> ! {
out_2.toggle();
cortex_m::asm::delay(25_000_000);
}
*/
}
TestCase::DelayMs => {
let mut delay_timer = CountdownTimer::new(dp.tim1, 50.MHz());
let mut pa0 = Output::new(pinsa.pa0, PinState::Low);
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();
for _ in 0..5 {
led1.toggle();
delay_timer.delay_ms(500);
@@ -182,9 +187,15 @@ fn main() -> ! {
}
}
defmt::info!("Test success");
rprintln!("Test success");
loop {
led1.toggle();
cortex_m::asm::delay(25_000_000);
}
}
#[interrupt]
#[allow(non_snake_case)]
fn OC0() {
default_ms_irq_handler()
}

View File

@@ -5,9 +5,9 @@ edition = "2021"
[dependencies]
cfg-if = "1"
# cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
# embedded-hal = "1"
embedded-hal = "1"
embedded-hal-async = "1"
embedded-io = "0.6"
embedded-io-async = "0.6"
@@ -19,7 +19,7 @@ defmt-rtt = "0.4"
panic-probe = { version = "0.3", features = ["print-defmt"] }
critical-section = "1"
# portable-atomic = { version = "1", features = ["unsafe-assume-single-core"]}
portable-atomic = { version = "1", features = ["unsafe-assume-single-core"]}
embassy-sync = "0.6"
embassy-time = "0.4"
@@ -37,6 +37,3 @@ default = ["ticks-hz-1_000", "va108xx-embassy/irq-oc30-oc31"]
custom-irqs = []
ticks-hz-1_000 = ["embassy-time/tick-hz-1_000"]
ticks-hz-32_768 = ["embassy-time/tick-hz-32_768"]
[package.metadata.cargo-machete]
ignored = ["cortex-m-rt"]

View File

@@ -5,12 +5,22 @@ edition = "2021"
[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
embedded-hal = "1"
embedded-io = "0.6"
defmt-rtt = "0.4"
defmt = "1"
panic-probe = { version = "1", features = ["defmt"] }
# Even though we do not use this directly, we need to activate this feature explicitely
# so that RTIC compiles because thumv6 does not have CAS operations natively.
portable-atomic = { version = "1", features = ["unsafe-assume-single-core"]}
rtic = { version = "2", features = ["thumbv6-backend"] }
rtic-monotonics = { version = "2", features = ["cortex-m-systick"] }
rtic-sync = { version = "1.3", features = ["defmt-03"] }
once_cell = {version = "1", default-features = false, features = ["critical-section"]}
ringbuf = { version = "0.4.7", default-features = false, features = ["portable-atomic"] }
va108xx-hal = { version = "0.11", path = "../../va108xx-hal" }

View File

@@ -7,15 +7,21 @@ edition = "2021"
cortex-m = {version = "0.7", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7"
panic-halt = "1"
critical-section = "1"
defmt-rtt = "0.4"
defmt = "1"
panic-probe = { version = "1", features = ["defmt"] }
embedded-hal = "1"
embedded-hal-nb = "1"
embedded-io = "0.6"
cortex-m-semihosting = "0.5.0"
portable-atomic = { version = "1", features = ["unsafe-assume-single-core"] }
[dependencies.va108xx-hal]
version = "0.11"
path = "../../va108xx-hal"
features = ["defmt"]
[dependencies.vorago-reb1]
path = "../../vorago-reb1"
version = "0.8"

View File

@@ -4,16 +4,20 @@ version = "0.1.0"
edition = "2021"
[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"]}
cortex-m = "0.7"
cortex-m-rt = "0.7"
embedded-hal = "1"
embedded-hal-nb = "1"
embedded-io = "0.6"
defmt = "1"
defmt-rtt = { version = "0.4" }
panic-probe = { version = "0.3", features = ["print-defmt"] }
num_enum = { version = "0.7", default-features = false }
crc = "3"
cobs = { version = "0.3", default-features = false }
satrs = { version = "0.2", default-features = false }
ringbuf = { version = "0.4.7", default-features = false, features = ["portable-atomic"] }
once_cell = { version = "1", default-features = false, features = ["critical-section"] }
spacepackets = { version = "0.11", default-features = false, features = ["defmt"] }
# Even though we do not use this directly, we need to activate this feature explicitely
# so that RTIC compiles because thumv6 does not have CAS operations natively.
@@ -21,6 +25,7 @@ portable-atomic = {version = "1", features = ["unsafe-assume-single-core"]}
rtic = { version = "2", features = ["thumbv6-backend"] }
rtic-monotonics = { version = "2", features = ["cortex-m-systick"] }
rtic-sync = {version = "1", features = ["defmt-03"]}
[dependencies.va108xx-hal]
version = "0.11"
@@ -29,6 +34,3 @@ features = ["defmt"]
[dependencies.vorago-reb1]
version = "0.8"
[package.metadata.cargo-machete]
ignored = ["portable-atomic", "cortex-m-rt"]

View File

@@ -9,6 +9,7 @@ edition = "2021"
cortex-m-rt = "0.7"
panic-rtt-target = { version = "0.1.3" }
rtt-target = { version = "0.5" }
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
embedded-hal = "1"
va108xx-hal = { version = "0.10.0" }

View File

@@ -9,6 +9,7 @@ edition = "2021"
cortex-m-rt = "0.7"
panic-rtt-target = { version = "0.1.3" }
rtt-target = { version = "0.5" }
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
embedded-hal = "1"
va108xx-hal = { version = "0.10.0" }

View File

@@ -12,6 +12,7 @@ categories = ["aerospace", "embedded", "no-std", "hardware-support"]
[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"]}
cortex-m-rt = "0.7"
vorago-shared-periphs = { path = "../../vorago-shared-periphs", features = ["vor1x"] }
fugit = "0.3"
thiserror = { version = "2", default-features = false }
@@ -31,6 +32,3 @@ defmt = ["dep:defmt", "vorago-shared-periphs/defmt"]
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--generate-link-to-definition"]
[package.metadata.cargo-machete]
ignored = ["cortex-m"]