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) ]
910use core:: future:: Future ;
1011
1112use embassy_sync:: waitqueue:: AtomicWaker ;
@@ -97,6 +98,14 @@ fn pin_group_to_waker_and_edge_detection_group(
9798pub 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" ) ]
101110pub fn on_interrupt_for_async_gpio_for_port (
102111 port : Port ,
@@ -152,6 +161,7 @@ pub struct InputPinFuture {
152161}
153162
154163impl 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.
211224pub 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