prep embassy v0.2.0

This commit is contained in:
Robin Müller 2025-02-17 23:52:26 +01:00
parent 9ccd147ff6
commit 16591346e5
8 changed files with 105 additions and 128 deletions

View File

@ -28,7 +28,7 @@ embassy-executor = { version = "0.7", features = [
]} ]}
va108xx-hal = { version = "0.10" } va108xx-hal = { version = "0.10" }
va108xx-embassy = { version = "0.1", path = "../../va108xx-embassy" } va108xx-embassy = { version = "0.2", path = "../../va108xx-embassy" }
[features] [features]
default = ["ticks-hz-1_000", "va108xx-embassy/irq-oc30-oc31"] default = ["ticks-hz-1_000", "va108xx-embassy/irq-oc30-oc31"]

View File

@ -12,7 +12,6 @@ use embassy_time::{Duration, Instant, Timer};
use embedded_hal_async::digital::Wait; use embedded_hal_async::digital::Wait;
use panic_rtt_target as _; use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use va108xx_embassy::embassy;
use va108xx_hal::gpio::{ use va108xx_hal::gpio::{
on_interrupt_for_async_gpio_for_port, InputDynPinAsync, InputPinAsync, PinsB, Port, on_interrupt_for_async_gpio_for_port, InputDynPinAsync, InputPinAsync, PinsB, Port,
}; };
@ -65,15 +64,13 @@ async fn main(spawner: Spawner) {
let mut dp = pac::Peripherals::take().unwrap(); let mut dp = pac::Peripherals::take().unwrap();
// Safety: Only called once here. // Safety: Only called once here.
unsafe { va108xx_embassy::init(
embassy::init(
&mut dp.sysconfig, &mut dp.sysconfig,
&dp.irqsel, &dp.irqsel,
SYSCLK_FREQ, SYSCLK_FREQ,
dp.tim23, dp.tim23,
dp.tim22, dp.tim22,
) );
};
let porta = PinsA::new(&mut dp.sysconfig, dp.porta); let porta = PinsA::new(&mut dp.sysconfig, dp.porta);
let portb = PinsB::new(&mut dp.sysconfig, dp.portb); let portb = PinsB::new(&mut dp.sysconfig, dp.portb);

View File

@ -23,7 +23,6 @@ use embedded_io_async::Read;
use heapless::spsc::{Consumer, Producer, Queue}; use heapless::spsc::{Consumer, Producer, Queue};
use panic_rtt_target as _; use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use va108xx_embassy::embassy;
use va108xx_hal::{ use va108xx_hal::{
gpio::PinsA, gpio::PinsA,
pac::{self, interrupt}, pac::{self, interrupt},
@ -56,15 +55,13 @@ async fn main(spawner: Spawner) {
let mut dp = pac::Peripherals::take().unwrap(); let mut dp = pac::Peripherals::take().unwrap();
// Safety: Only called once here. // Safety: Only called once here.
unsafe { va108xx_embassy::init(
embassy::init(
&mut dp.sysconfig, &mut dp.sysconfig,
&dp.irqsel, &dp.irqsel,
SYSCLK_FREQ, SYSCLK_FREQ,
dp.tim23, dp.tim23,
dp.tim22, dp.tim22,
); );
}
let porta = PinsA::new(&mut dp.sysconfig, dp.porta); let porta = PinsA::new(&mut dp.sysconfig, dp.porta);
let mut led0 = porta.pa10.into_readable_push_pull_output(); let mut led0 = porta.pa10.into_readable_push_pull_output();

View File

@ -15,7 +15,6 @@ use embassy_time::{Duration, Instant, Ticker};
use embedded_io_async::Write; use embedded_io_async::Write;
use panic_rtt_target as _; use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use va108xx_embassy::embassy;
use va108xx_hal::{ use va108xx_hal::{
gpio::PinsA, gpio::PinsA,
pac::{self, interrupt}, pac::{self, interrupt},
@ -42,15 +41,13 @@ async fn main(_spawner: Spawner) {
let mut dp = pac::Peripherals::take().unwrap(); let mut dp = pac::Peripherals::take().unwrap();
// Safety: Only called once here. // Safety: Only called once here.
unsafe { va108xx_embassy::init(
embassy::init(
&mut dp.sysconfig, &mut dp.sysconfig,
&dp.irqsel, &dp.irqsel,
SYSCLK_FREQ, SYSCLK_FREQ,
dp.tim23, dp.tim23,
dp.tim22, dp.tim22,
); );
}
let porta = PinsA::new(&mut dp.sysconfig, dp.porta); let porta = PinsA::new(&mut dp.sysconfig, dp.porta);
let mut led0 = porta.pa10.into_readable_push_pull_output(); let mut led0 = porta.pa10.into_readable_push_pull_output();

View File

@ -4,7 +4,6 @@ use embassy_executor::Spawner;
use embassy_time::{Duration, Instant, Ticker}; use embassy_time::{Duration, Instant, Ticker};
use panic_rtt_target as _; use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print}; use rtt_target::{rprintln, rtt_init_print};
use va108xx_embassy::embassy;
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(feature = "custom-irqs")] { if #[cfg(feature = "custom-irqs")] {
@ -27,10 +26,9 @@ async fn main(_spawner: Spawner) {
let mut dp = pac::Peripherals::take().unwrap(); let mut dp = pac::Peripherals::take().unwrap();
// Safety: Only called once here. // Safety: Only called once here.
unsafe {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(not(feature = "custom-irqs"))] { if #[cfg(not(feature = "custom-irqs"))] {
embassy::init( va108xx_embassy::init(
&mut dp.sysconfig, &mut dp.sysconfig,
&dp.irqsel, &dp.irqsel,
SYSCLK_FREQ, SYSCLK_FREQ,
@ -38,7 +36,7 @@ async fn main(_spawner: Spawner) {
dp.tim22, dp.tim22,
); );
} else { } else {
embassy::init_with_custom_irqs( va108xx_embassy::init_with_custom_irqs(
&mut dp.sysconfig, &mut dp.sysconfig,
&dp.irqsel, &dp.irqsel,
SYSCLK_FREQ, SYSCLK_FREQ,
@ -49,7 +47,6 @@ async fn main(_spawner: Spawner) {
); );
} }
} }
}
let porta = PinsA::new(&mut dp.sysconfig, dp.porta); let porta = PinsA::new(&mut dp.sysconfig, dp.porta);
let mut led0 = porta.pa10.into_readable_push_pull_output(); let mut led0 = porta.pa10.into_readable_push_pull_output();

View File

@ -8,9 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [unreleased] ## [unreleased]
## [v0.1.3] 2025-02-17 ## [v0.2.0] 2025-02-17
- Bumped va108xx-hal to v0.10.0
- Remove `embassy` module, expose public functions in library root directly
Bumped va108xx-hal to v0.10.0
## [v0.1.2] and [v0.1.1] 2025-02-13 ## [v0.1.2] and [v0.1.1] 2025-02-13

View File

@ -1,6 +1,6 @@
[package] [package]
name = "va108xx-embassy" name = "va108xx-embassy"
version = "0.1.3" version = "0.2.0"
edition = "2021" edition = "2021"
authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"] authors = ["Robin Mueller <muellerr@irs.uni-stuttgart.de>"]
description = "Embassy-rs support for the Vorago VA108xx family of microcontrollers" description = "Embassy-rs support for the Vorago VA108xx family of microcontrollers"

View File

@ -1,17 +1,17 @@
//! # Embassy-rs support for the Vorago VA108xx MCU family //! # Embassy-rs support for the Vorago VA108xx MCU family
//! //!
//! This repository contains the [embassy-rs](https://github.com/embassy-rs/embassy) support for the //! This repository contains the [embassy-rs](https://github.com/embassy-rs/embassy) support for
//! VA108xx family. Currently, it contains the time driver to allow using embassy-rs. It uses the TIM //! the VA108xx family. Currently, it contains the time driver to allow using embassy-rs. It uses
//! peripherals provided by the VA108xx family for this purpose. //! the TIM peripherals provided by the VA108xx family for this purpose.
//! //!
//! ## Usage //! ## Usage
//! //!
//! This library only exposes the [embassy::init] method which sets up the time driver. This //! This library exposes the [init] or the [init_with_custom_irqs] functions which set up the time
//! function must be called once at the start of the application. //! driver. This function must be called once at the start of the application.
//! //!
//! This implementation requires two TIM peripherals provided by the VA108xx device. //! This implementation requires two TIM peripherals provided by the VA108xx device.
//! The user can freely specify the two used TIM peripheral by passing the concrete TIM instances //! The user can freely specify the two used TIM peripheral by passing the concrete TIM instances
//! into the [embassy::init_with_custom_irqs] and [embassy::init] method. //! into the [init_with_custom_irqs] and [init] method.
//! //!
//! The application also requires two interrupt handlers to handle the timekeeper and alarm //! The application also requires two interrupt handlers to handle the timekeeper and alarm
//! interrupts. By default, this library will define the interrupt handler inside the library //! interrupts. By default, this library will define the interrupt handler inside the library
@ -24,7 +24,7 @@
//! You can disable the default features and then specify one of the features above to use the //! You can disable the default features and then specify one of the features above to use the
//! documented combination of IRQs. It is also possible to specify custom IRQs by importing and //! documented combination of IRQs. It is also possible to specify custom IRQs by importing and
//! using the [embassy_time_driver_irqs] macro to declare the IRQ handlers in the //! using the [embassy_time_driver_irqs] macro to declare the IRQ handlers in the
//! application code. If this is done, [embassy::init_with_custom_irqs] must be used //! application code. If this is done, [init_with_custom_irqs] must be used
//! method to pass the IRQ numbers to the library. //! method to pass the IRQ numbers to the library.
//! //!
//! ## Examples //! ## Examples
@ -76,7 +76,7 @@ macro_rules! embassy_time_driver_irqs {
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn $timekeeper_irq() { fn $timekeeper_irq() {
// Safety: We call it once here. // Safety: We call it once here.
unsafe { $crate::embassy::time_driver().on_interrupt_timekeeping() } unsafe { $crate::time_driver().on_interrupt_timekeeping() }
} }
const ALARM_IRQ: pac::Interrupt = pac::Interrupt::$alarm_irq; const ALARM_IRQ: pac::Interrupt = pac::Interrupt::$alarm_irq;
@ -85,7 +85,7 @@ macro_rules! embassy_time_driver_irqs {
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn $alarm_irq() { fn $alarm_irq() {
// Safety: We call it once here. // Safety: We call it once here.
unsafe { $crate::embassy::time_driver().on_interrupt_alarm() } unsafe { $crate::time_driver().on_interrupt_alarm() }
} }
}; };
} }
@ -99,26 +99,17 @@ embassy_time_driver_irqs!(timekeeper_irq = OC30, alarm_irq = OC29);
#[cfg(feature = "irq-oc28-oc29")] #[cfg(feature = "irq-oc28-oc29")]
embassy_time_driver_irqs!(timekeeper_irq = OC29, alarm_irq = OC28); embassy_time_driver_irqs!(timekeeper_irq = OC29, alarm_irq = OC28);
pub mod embassy {
use super::*;
use va108xx_hal::{pac, timer::TimRegInterface};
/// Expose the time driver so the user can specify the IRQ handlers themselves. /// Expose the time driver so the user can specify the IRQ handlers themselves.
pub fn time_driver() -> &'static TimerDriver { pub fn time_driver() -> &'static TimerDriver {
&TIME_DRIVER &TIME_DRIVER
} }
/// Initialization method for embassy /// Initialization method for embassy.
/// ///
/// # Safety /// This should be used if the interrupt handler is provided by the library, which is the
/// /// default case.
/// This has to be called once at initialization time to initiate the time driver for
/// embassy.
#[cfg(feature = "irqs-in-lib")] #[cfg(feature = "irqs-in-lib")]
pub unsafe fn init< pub fn init<TimekeeperTim: TimRegInterface + ValidTim, AlarmTim: TimRegInterface + ValidTim>(
TimekeeperTim: TimRegInterface + ValidTim,
AlarmTim: TimRegInterface + ValidTim,
>(
syscfg: &mut pac::Sysconfig, syscfg: &mut pac::Sysconfig,
irqsel: &pac::Irqsel, irqsel: &pac::Irqsel,
sysclk: impl Into<Hertz>, sysclk: impl Into<Hertz>,
@ -136,13 +127,10 @@ pub mod embassy {
) )
} }
/// Initialization method for embassy /// Initialization method for embassy when using custom IRQ handlers.
/// ///
/// # Safety /// Requires an explicit [pac::Interrupt] argument for the timekeeper and alarm IRQs.
/// pub fn init_with_custom_irqs<
/// This has to be called once at initialization time to initiate the time driver for
/// embassy.
pub unsafe fn init_with_custom_irqs<
TimekeeperTim: TimRegInterface + ValidTim, TimekeeperTim: TimRegInterface + ValidTim,
AlarmTim: TimRegInterface + ValidTim, AlarmTim: TimRegInterface + ValidTim,
>( >(
@ -164,7 +152,6 @@ pub mod embassy {
alarm_irq, alarm_irq,
) )
} }
}
struct AlarmState { struct AlarmState {
timestamp: Cell<u64>, timestamp: Cell<u64>,