Skip to content

Commit 45ee5ad

Browse files
committed
Merge pull request 'prep embassy v0.2.0' (#67) from prep-embassy-v0.2.0 into main
Reviewed-on: https://egit.irs.uni-stuttgart.de/rust/va108xx-rs/pulls/67
2 parents 9ccd147 + 1659134 commit 45ee5ad

File tree

8 files changed

+105
-128
lines changed

8 files changed

+105
-128
lines changed

examples/embassy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ embassy-executor = { version = "0.7", features = [
2828
]}
2929

3030
va108xx-hal = { version = "0.10" }
31-
va108xx-embassy = { version = "0.1", path = "../../va108xx-embassy" }
31+
va108xx-embassy = { version = "0.2", path = "../../va108xx-embassy" }
3232

3333
[features]
3434
default = ["ticks-hz-1_000", "va108xx-embassy/irq-oc30-oc31"]

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use embassy_time::{Duration, Instant, Timer};
1212
use embedded_hal_async::digital::Wait;
1313
use panic_rtt_target as _;
1414
use rtt_target::{rprintln, rtt_init_print};
15-
use va108xx_embassy::embassy;
1615
use va108xx_hal::gpio::{
1716
on_interrupt_for_async_gpio_for_port, InputDynPinAsync, InputPinAsync, PinsB, Port,
1817
};
@@ -65,15 +64,13 @@ async fn main(spawner: Spawner) {
6564
let mut dp = pac::Peripherals::take().unwrap();
6665

6766
// Safety: Only called once here.
68-
unsafe {
69-
embassy::init(
70-
&mut dp.sysconfig,
71-
&dp.irqsel,
72-
SYSCLK_FREQ,
73-
dp.tim23,
74-
dp.tim22,
75-
)
76-
};
67+
va108xx_embassy::init(
68+
&mut dp.sysconfig,
69+
&dp.irqsel,
70+
SYSCLK_FREQ,
71+
dp.tim23,
72+
dp.tim22,
73+
);
7774

7875
let porta = PinsA::new(&mut dp.sysconfig, dp.porta);
7976
let portb = PinsB::new(&mut dp.sysconfig, dp.portb);

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use embedded_io_async::Read;
2323
use heapless::spsc::{Consumer, Producer, Queue};
2424
use panic_rtt_target as _;
2525
use rtt_target::{rprintln, rtt_init_print};
26-
use va108xx_embassy::embassy;
2726
use va108xx_hal::{
2827
gpio::PinsA,
2928
pac::{self, interrupt},
@@ -56,15 +55,13 @@ async fn main(spawner: Spawner) {
5655
let mut dp = pac::Peripherals::take().unwrap();
5756

5857
// Safety: Only called once here.
59-
unsafe {
60-
embassy::init(
61-
&mut dp.sysconfig,
62-
&dp.irqsel,
63-
SYSCLK_FREQ,
64-
dp.tim23,
65-
dp.tim22,
66-
);
67-
}
58+
va108xx_embassy::init(
59+
&mut dp.sysconfig,
60+
&dp.irqsel,
61+
SYSCLK_FREQ,
62+
dp.tim23,
63+
dp.tim22,
64+
);
6865

6966
let porta = PinsA::new(&mut dp.sysconfig, dp.porta);
7067
let mut led0 = porta.pa10.into_readable_push_pull_output();

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

+7-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use embassy_time::{Duration, Instant, Ticker};
1515
use embedded_io_async::Write;
1616
use panic_rtt_target as _;
1717
use rtt_target::{rprintln, rtt_init_print};
18-
use va108xx_embassy::embassy;
1918
use va108xx_hal::{
2019
gpio::PinsA,
2120
pac::{self, interrupt},
@@ -42,15 +41,13 @@ async fn main(_spawner: Spawner) {
4241
let mut dp = pac::Peripherals::take().unwrap();
4342

4443
// Safety: Only called once here.
45-
unsafe {
46-
embassy::init(
47-
&mut dp.sysconfig,
48-
&dp.irqsel,
49-
SYSCLK_FREQ,
50-
dp.tim23,
51-
dp.tim22,
52-
);
53-
}
44+
va108xx_embassy::init(
45+
&mut dp.sysconfig,
46+
&dp.irqsel,
47+
SYSCLK_FREQ,
48+
dp.tim23,
49+
dp.tim22,
50+
);
5451

5552
let porta = PinsA::new(&mut dp.sysconfig, dp.porta);
5653
let mut led0 = porta.pa10.into_readable_push_pull_output();

examples/embassy/src/main.rs

+19-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use embassy_executor::Spawner;
44
use embassy_time::{Duration, Instant, Ticker};
55
use panic_rtt_target as _;
66
use rtt_target::{rprintln, rtt_init_print};
7-
use va108xx_embassy::embassy;
87

98
cfg_if::cfg_if! {
109
if #[cfg(feature = "custom-irqs")] {
@@ -27,27 +26,25 @@ async fn main(_spawner: Spawner) {
2726
let mut dp = pac::Peripherals::take().unwrap();
2827

2928
// Safety: Only called once here.
30-
unsafe {
31-
cfg_if::cfg_if! {
32-
if #[cfg(not(feature = "custom-irqs"))] {
33-
embassy::init(
34-
&mut dp.sysconfig,
35-
&dp.irqsel,
36-
SYSCLK_FREQ,
37-
dp.tim23,
38-
dp.tim22,
39-
);
40-
} else {
41-
embassy::init_with_custom_irqs(
42-
&mut dp.sysconfig,
43-
&dp.irqsel,
44-
SYSCLK_FREQ,
45-
dp.tim23,
46-
dp.tim22,
47-
pac::Interrupt::OC23,
48-
pac::Interrupt::OC24,
49-
);
50-
}
29+
cfg_if::cfg_if! {
30+
if #[cfg(not(feature = "custom-irqs"))] {
31+
va108xx_embassy::init(
32+
&mut dp.sysconfig,
33+
&dp.irqsel,
34+
SYSCLK_FREQ,
35+
dp.tim23,
36+
dp.tim22,
37+
);
38+
} else {
39+
va108xx_embassy::init_with_custom_irqs(
40+
&mut dp.sysconfig,
41+
&dp.irqsel,
42+
SYSCLK_FREQ,
43+
dp.tim23,
44+
dp.tim22,
45+
pac::Interrupt::OC23,
46+
pac::Interrupt::OC24,
47+
);
5148
}
5249
}
5350

va108xx-embassy/CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88

99
## [unreleased]
1010

11-
## [v0.1.3] 2025-02-17
11+
## [v0.2.0] 2025-02-17
12+
13+
- Bumped va108xx-hal to v0.10.0
14+
- Remove `embassy` module, expose public functions in library root directly
1215

13-
Bumped va108xx-hal to v0.10.0
1416

1517
## [v0.1.2] and [v0.1.1] 2025-02-13
1618

va108xx-embassy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "va108xx-embassy"
3-
version = "0.1.3"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["Robin Mueller <[email protected]>"]
66
description = "Embassy-rs support for the Vorago VA108xx family of microcontrollers"

va108xx-embassy/src/lib.rs

+59-72
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//! # Embassy-rs support for the Vorago VA108xx MCU family
22
//!
3-
//! This repository contains the [embassy-rs](https://github.com/embassy-rs/embassy) support for the
4-
//! VA108xx family. Currently, it contains the time driver to allow using embassy-rs. It uses the TIM
5-
//! peripherals provided by the VA108xx family for this purpose.
3+
//! This repository contains the [embassy-rs](https://github.com/embassy-rs/embassy) support for
4+
//! the VA108xx family. Currently, it contains the time driver to allow using embassy-rs. It uses
5+
//! the TIM peripherals provided by the VA108xx family for this purpose.
66
//!
77
//! ## Usage
88
//!
9-
//! This library only exposes the [embassy::init] method which sets up the time driver. This
10-
//! function must be called once at the start of the application.
9+
//! This library exposes the [init] or the [init_with_custom_irqs] functions which set up the time
10+
//! driver. This function must be called once at the start of the application.
1111
//!
1212
//! This implementation requires two TIM peripherals provided by the VA108xx device.
1313
//! The user can freely specify the two used TIM peripheral by passing the concrete TIM instances
14-
//! into the [embassy::init_with_custom_irqs] and [embassy::init] method.
14+
//! into the [init_with_custom_irqs] and [init] method.
1515
//!
1616
//! The application also requires two interrupt handlers to handle the timekeeper and alarm
1717
//! interrupts. By default, this library will define the interrupt handler inside the library
@@ -24,7 +24,7 @@
2424
//! You can disable the default features and then specify one of the features above to use the
2525
//! documented combination of IRQs. It is also possible to specify custom IRQs by importing and
2626
//! using the [embassy_time_driver_irqs] macro to declare the IRQ handlers in the
27-
//! application code. If this is done, [embassy::init_with_custom_irqs] must be used
27+
//! application code. If this is done, [init_with_custom_irqs] must be used
2828
//! method to pass the IRQ numbers to the library.
2929
//!
3030
//! ## Examples
@@ -76,7 +76,7 @@ macro_rules! embassy_time_driver_irqs {
7676
#[allow(non_snake_case)]
7777
fn $timekeeper_irq() {
7878
// Safety: We call it once here.
79-
unsafe { $crate::embassy::time_driver().on_interrupt_timekeeping() }
79+
unsafe { $crate::time_driver().on_interrupt_timekeeping() }
8080
}
8181

8282
const ALARM_IRQ: pac::Interrupt = pac::Interrupt::$alarm_irq;
@@ -85,7 +85,7 @@ macro_rules! embassy_time_driver_irqs {
8585
#[allow(non_snake_case)]
8686
fn $alarm_irq() {
8787
// Safety: We call it once here.
88-
unsafe { $crate::embassy::time_driver().on_interrupt_alarm() }
88+
unsafe { $crate::time_driver().on_interrupt_alarm() }
8989
}
9090
};
9191
}
@@ -99,71 +99,58 @@ embassy_time_driver_irqs!(timekeeper_irq = OC30, alarm_irq = OC29);
9999
#[cfg(feature = "irq-oc28-oc29")]
100100
embassy_time_driver_irqs!(timekeeper_irq = OC29, alarm_irq = OC28);
101101

102-
pub mod embassy {
103-
use super::*;
104-
use va108xx_hal::{pac, timer::TimRegInterface};
105-
106-
/// Expose the time driver so the user can specify the IRQ handlers themselves.
107-
pub fn time_driver() -> &'static TimerDriver {
108-
&TIME_DRIVER
109-
}
102+
/// Expose the time driver so the user can specify the IRQ handlers themselves.
103+
pub fn time_driver() -> &'static TimerDriver {
104+
&TIME_DRIVER
105+
}
110106

111-
/// Initialization method for embassy
112-
///
113-
/// # Safety
114-
///
115-
/// This has to be called once at initialization time to initiate the time driver for
116-
/// embassy.
117-
#[cfg(feature = "irqs-in-lib")]
118-
pub unsafe fn init<
119-
TimekeeperTim: TimRegInterface + ValidTim,
120-
AlarmTim: TimRegInterface + ValidTim,
121-
>(
122-
syscfg: &mut pac::Sysconfig,
123-
irqsel: &pac::Irqsel,
124-
sysclk: impl Into<Hertz>,
125-
timekeeper_tim: TimekeeperTim,
126-
alarm_tim: AlarmTim,
127-
) {
128-
TIME_DRIVER.init(
129-
syscfg,
130-
irqsel,
131-
sysclk,
132-
timekeeper_tim,
133-
alarm_tim,
134-
TIMEKEEPER_IRQ,
135-
ALARM_IRQ,
136-
)
137-
}
107+
/// Initialization method for embassy.
108+
///
109+
/// This should be used if the interrupt handler is provided by the library, which is the
110+
/// default case.
111+
#[cfg(feature = "irqs-in-lib")]
112+
pub fn init<TimekeeperTim: TimRegInterface + ValidTim, AlarmTim: TimRegInterface + ValidTim>(
113+
syscfg: &mut pac::Sysconfig,
114+
irqsel: &pac::Irqsel,
115+
sysclk: impl Into<Hertz>,
116+
timekeeper_tim: TimekeeperTim,
117+
alarm_tim: AlarmTim,
118+
) {
119+
TIME_DRIVER.init(
120+
syscfg,
121+
irqsel,
122+
sysclk,
123+
timekeeper_tim,
124+
alarm_tim,
125+
TIMEKEEPER_IRQ,
126+
ALARM_IRQ,
127+
)
128+
}
138129

139-
/// Initialization method for embassy
140-
///
141-
/// # Safety
142-
///
143-
/// This has to be called once at initialization time to initiate the time driver for
144-
/// embassy.
145-
pub unsafe fn init_with_custom_irqs<
146-
TimekeeperTim: TimRegInterface + ValidTim,
147-
AlarmTim: TimRegInterface + ValidTim,
148-
>(
149-
syscfg: &mut pac::Sysconfig,
150-
irqsel: &pac::Irqsel,
151-
sysclk: impl Into<Hertz>,
152-
timekeeper_tim: TimekeeperTim,
153-
alarm_tim: AlarmTim,
154-
timekeeper_irq: pac::Interrupt,
155-
alarm_irq: pac::Interrupt,
156-
) {
157-
TIME_DRIVER.init(
158-
syscfg,
159-
irqsel,
160-
sysclk,
161-
timekeeper_tim,
162-
alarm_tim,
163-
timekeeper_irq,
164-
alarm_irq,
165-
)
166-
}
130+
/// Initialization method for embassy when using custom IRQ handlers.
131+
///
132+
/// Requires an explicit [pac::Interrupt] argument for the timekeeper and alarm IRQs.
133+
pub fn init_with_custom_irqs<
134+
TimekeeperTim: TimRegInterface + ValidTim,
135+
AlarmTim: TimRegInterface + ValidTim,
136+
>(
137+
syscfg: &mut pac::Sysconfig,
138+
irqsel: &pac::Irqsel,
139+
sysclk: impl Into<Hertz>,
140+
timekeeper_tim: TimekeeperTim,
141+
alarm_tim: AlarmTim,
142+
timekeeper_irq: pac::Interrupt,
143+
alarm_irq: pac::Interrupt,
144+
) {
145+
TIME_DRIVER.init(
146+
syscfg,
147+
irqsel,
148+
sysclk,
149+
timekeeper_tim,
150+
alarm_tim,
151+
timekeeper_irq,
152+
alarm_irq,
153+
)
167154
}
168155

169156
struct AlarmState {

0 commit comments

Comments
 (0)