@@ -20,11 +20,22 @@ mod async_io {
20
20
//! the largest number currently used, although this might change with 64-bit targest in the
21
21
//! future.
22
22
23
- use core:: { cell:: UnsafeCell , ffi:: c_int, future:: Future , mem, sync:: atomic:: Ordering , task:: { Poll , Waker } } ;
23
+ use core:: {
24
+ cell:: UnsafeCell ,
25
+ ffi:: c_int,
26
+ future:: Future ,
27
+ mem,
28
+ sync:: atomic:: Ordering ,
29
+ task:: { Poll , Waker } ,
30
+ } ;
24
31
25
32
use embassy_sync:: waitqueue:: AtomicWaker ;
26
33
use portable_atomic:: AtomicBool ;
27
- use zephyr_sys:: { device, gpio_add_callback, gpio_callback, gpio_init_callback, gpio_pin_get, gpio_pin_interrupt_configure, gpio_pin_interrupt_configure_dt, gpio_port_pins_t, GPIO_INT_LEVEL_HIGH , GPIO_INT_LEVEL_LOW , ZR_GPIO_INT_MODE_DISABLE_ONLY } ;
34
+ use zephyr_sys:: {
35
+ device, gpio_add_callback, gpio_callback, gpio_init_callback, gpio_pin_get,
36
+ gpio_pin_interrupt_configure, gpio_pin_interrupt_configure_dt, gpio_port_pins_t,
37
+ GPIO_INT_LEVEL_HIGH , GPIO_INT_LEVEL_LOW , ZR_GPIO_INT_MODE_DISABLE_ONLY ,
38
+ } ;
28
39
29
40
use crate :: printkln;
30
41
@@ -94,11 +105,15 @@ mod async_io {
94
105
}
95
106
}
96
107
97
- extern "C" fn callback_handler ( port : * const device , cb : * mut gpio_callback , mut pins : gpio_port_pins_t ) {
98
- let data = unsafe { cb
99
- . cast :: < u8 > ( )
100
- . sub ( mem:: offset_of!( Self , callback) )
101
- . cast :: < Self > ( )
108
+ extern "C" fn callback_handler (
109
+ port : * const device ,
110
+ cb : * mut gpio_callback ,
111
+ mut pins : gpio_port_pins_t ,
112
+ ) {
113
+ let data = unsafe {
114
+ cb. cast :: < u8 > ( )
115
+ . sub ( mem:: offset_of!( Self , callback) )
116
+ . cast :: < Self > ( )
102
117
} ;
103
118
104
119
// printkln!("CB called: pins: {pins:#x}");
@@ -136,7 +151,10 @@ mod async_io {
136
151
/// The `_token` enforces single use of gpios. Note that this makes it impossible to wait for
137
152
/// more than one GPIO.
138
153
///
139
- pub unsafe fn wait_for_high ( & mut self , _token : & mut GpioToken ) -> impl Future < Output = ( ) > + use < ' _ > {
154
+ pub unsafe fn wait_for_high (
155
+ & mut self ,
156
+ _token : & mut GpioToken ,
157
+ ) -> impl Future < Output = ( ) > + use < ' _ > {
140
158
GpioWait :: new ( self , 1 )
141
159
}
142
160
@@ -146,7 +164,10 @@ mod async_io {
146
164
///
147
165
/// The `_token` enforces single use of gpios. Note that this makes it impossible to wait
148
166
/// for more than one GPIO.
149
- pub unsafe fn wait_for_low ( & mut self , _token : & mut GpioToken ) -> impl Future < Output = ( ) > + use < ' _ > {
167
+ pub unsafe fn wait_for_low (
168
+ & mut self ,
169
+ _token : & mut GpioToken ,
170
+ ) -> impl Future < Output = ( ) > + use < ' _ > {
150
171
GpioWait :: new ( self , 0 )
151
172
}
152
173
}
@@ -159,17 +180,17 @@ mod async_io {
159
180
160
181
impl < ' a > GpioWait < ' a > {
161
182
fn new ( pin : & ' a mut GpioPin , level : u8 ) -> Self {
162
- Self {
163
- pin,
164
- level,
165
- }
183
+ Self { pin, level }
166
184
}
167
185
}
168
186
169
187
impl < ' a > Future for GpioWait < ' a > {
170
188
type Output = ( ) ;
171
189
172
- fn poll ( self : core:: pin:: Pin < & mut Self > , cx : & mut core:: task:: Context < ' _ > ) -> core:: task:: Poll < Self :: Output > {
190
+ fn poll (
191
+ self : core:: pin:: Pin < & mut Self > ,
192
+ cx : & mut core:: task:: Context < ' _ > ,
193
+ ) -> core:: task:: Poll < Self :: Output > {
173
194
self . pin . data . fast_install ( self . pin . pin . port ) ;
174
195
175
196
self . pin . data . register ( self . pin . pin . pin , cx. waker ( ) ) ;
@@ -256,7 +277,11 @@ impl Gpio {
256
277
///
257
278
/// TODO: Guarantee single instancing.
258
279
#[ allow( dead_code) ]
259
- pub ( crate ) unsafe fn new ( unique : & Unique , data : & ' static GpioStatic , device : * const raw:: device ) -> Option < Gpio > {
280
+ pub ( crate ) unsafe fn new (
281
+ unique : & Unique ,
282
+ data : & ' static GpioStatic ,
283
+ device : * const raw:: device ,
284
+ ) -> Option < Gpio > {
260
285
if !unique. once ( ) {
261
286
return None ;
262
287
}
0 commit comments