Skip to content

Commit 6fac3ff

Browse files
committed
expose inner Input for InputPinAsync
1 parent 21e1a79 commit 6fac3ff

File tree

3 files changed

+67
-7
lines changed

3 files changed

+67
-7
lines changed

justfile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
all: check-all \
2-
build-all \
3-
check-fmt-all \
1+
all: check \
2+
build \
3+
check-fmt \
44
clippy-all \
55
docs-all
66

7-
check-all: check-va108xx check-va416xx
8-
build-all: build-va108xx build-va416xx
9-
check-fmt-all: check-fmt-va108xx check-fmt-va416xx
10-
fmt-all: fmt-va108xx fmt-va416xx fmt-shared-hal
7+
check: check-va108xx check-va416xx
8+
build: build-va108xx build-va416xx
9+
check-fmt: check-fmt-va108xx check-fmt-va416xx
10+
fmt: fmt-va108xx fmt-va416xx fmt-shared-hal
1111
clippy-all: clippy-va108xx clippy-va416xx clippy-shared-hal
1212
docs-all: docs-va108xx docs-va416xx docs-shared-hal
1313
clean-all: clean-va108xx clean-va416xx

vorago-shared-hal/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010

1111
### Added
1212

13+
- Add `is_high` and `is_low` for `InputPinAsync`.
14+
- Add `InputPin` impl for `InputPinAsync`.
15+
1316
### Changed
1417

1518
- Added `RxWithInterrupt::steal`.
@@ -19,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1922

2023
- Removed HW CS pin provider implementation for PA23, PA22 and PA21, which are multi HW CS pins.
2124
- Added missing `AnyPin` trait impl for Multi HW CS pins.
25+
- Expose inner `Input` pin for `InputPinAsync`.
2226

2327
## [v0.2.0] 2025-09-03
2428

vorago-shared-hal/src/gpio/asynch.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! which must be provided for async support to work. However, it provides the
77
//! [on_interrupt_for_async_gpio_for_port] generic interrupt handler. This should be called in all
88
//! IRQ functions which handle any GPIO interrupts with the corresponding [Port] argument.
9+
#![deny(missing_docs)]
910
use core::future::Future;
1011

1112
use embassy_sync::waitqueue::AtomicWaker;
@@ -97,6 +98,14 @@ fn pin_group_to_waker_and_edge_detection_group(
9798
pub fn on_interrupt_for_async_gpio_for_port(port: Port) {
9899
on_interrupt_for_async_gpio_for_port_generic(port);
99100
}
101+
102+
/// Generic interrupt handler for GPIO interrupts on a specific port to support async functionalities
103+
///
104+
/// This function should be called in all interrupt handlers which handle any GPIO interrupts
105+
/// matching the [Port] argument.
106+
/// The handler will wake the corresponding wakers for the pins that triggered an interrupts
107+
/// as well as update the static edge detection structures. This allows the pin future to complete
108+
/// complete async operations.
100109
#[cfg(feature = "vor4x")]
101110
pub fn on_interrupt_for_async_gpio_for_port(
102111
port: Port,
@@ -152,6 +161,7 @@ pub struct InputPinFuture {
152161
}
153162

154163
impl InputPinFuture {
164+
/// Create a new input pin future from mutable reference to an [Input] pin.
155165
#[cfg(feature = "vor1x")]
156166
pub fn new_with_input_pin(pin: &mut Input, irq: pac::Interrupt, edge: InterruptEdge) -> Self {
157167
let (waker_group, edge_detection_group) =
@@ -166,6 +176,8 @@ impl InputPinFuture {
166176
edge_detection_group,
167177
}
168178
}
179+
180+
/// Create a new input pin future from mutable reference to an [Input] pin.
169181
#[cfg(feature = "vor4x")]
170182
pub fn new_with_input_pin(
171183
pin: &mut Input,
@@ -208,6 +220,7 @@ impl Future for InputPinFuture {
208220
}
209221
}
210222

223+
/// Input pin which has additional asynchronous support.
211224
pub struct InputPinAsync {
212225
pin: Input,
213226
#[cfg(feature = "vor1x")]
@@ -225,6 +238,13 @@ impl InputPinAsync {
225238
pub fn new(pin: Input, irq: va108xx::Interrupt) -> Self {
226239
Self { pin, irq }
227240
}
241+
242+
/// Create a new asynchronous input pin from an [Input] pin. The interrupt ID to be used must be
243+
/// passed as well and is used to route and enable the interrupt.
244+
///
245+
/// Please note that the interrupt handler itself must be provided by the user and the
246+
/// generic [on_interrupt_for_async_gpio_for_port] function must be called inside that function
247+
/// for the asynchronous functionality to work.
228248
#[cfg(feature = "vor4x")]
229249
pub fn new(pin: Input) -> Result<Self, PortDoesNotSupportInterrupts> {
230250
if pin.id().port() == Port::G {
@@ -250,6 +270,30 @@ impl InputPinAsync {
250270
fut.await;
251271
}
252272

273+
/// Check whether pin is high.
274+
#[inline]
275+
pub fn is_high(&self) -> bool {
276+
self.pin.is_high()
277+
}
278+
279+
/// Check whether pin is low.
280+
#[inline]
281+
pub fn is_low(&self) -> bool {
282+
self.pin.is_low()
283+
}
284+
285+
/// Shared access to [Input] pin.
286+
#[inline]
287+
pub fn inner(&self) -> &Input {
288+
&self.pin
289+
}
290+
291+
/// Mutable access to [Input] pin.
292+
#[inline]
293+
pub fn inner_mut(&mut self) -> &mut Input {
294+
&mut self.pin
295+
}
296+
253297
/// Asynchronously wait until the pin is low.
254298
///
255299
/// This returns immediately if the pin is already high.
@@ -296,6 +340,8 @@ impl InputPinAsync {
296340
.await;
297341
}
298342

343+
/// Release the contained [Input] pin.
344+
#[inline]
299345
pub fn release(self) -> Input {
300346
self.pin
301347
}
@@ -331,3 +377,13 @@ impl Wait for InputPinAsync {
331377
Ok(())
332378
}
333379
}
380+
381+
impl embedded_hal::digital::InputPin for InputPinAsync {
382+
fn is_low(&mut self) -> Result<bool, Self::Error> {
383+
Ok(self.inner().is_low())
384+
}
385+
386+
fn is_high(&mut self) -> Result<bool, Self::Error> {
387+
Ok(self.inner().is_high())
388+
}
389+
}

0 commit comments

Comments
 (0)