@@ -51,8 +51,10 @@ mod app {
51
51
msg_queue_out : heapless:: spsc:: Consumer < ' static , Message , QUEUE_LEN > ,
52
52
/// A place to write to the message queue
53
53
msg_queue_in : heapless:: spsc:: Producer < ' static , Message , QUEUE_LEN > ,
54
- /// A status LED
55
- led : dongle:: Led ,
54
+ /// The status LEDs
55
+ leds : dongle:: Leds ,
56
+ /// Handles the lower-level USB Device interface
57
+ usb_device : usb_device:: device:: UsbDevice < ' static , dongle:: UsbBus > ,
56
58
}
57
59
58
60
#[ derive( Debug , defmt:: Format , Copy , Clone , PartialEq , Eq ) ]
@@ -67,8 +69,6 @@ mod app {
67
69
usb_serial : usbd_serial:: SerialPort < ' static , dongle:: UsbBus > ,
68
70
/// Handles the USB HID interface
69
71
usb_hid : usbd_hid:: hid_class:: HIDClass < ' static , dongle:: UsbBus > ,
70
- /// Handles the lower-level USB Device interface
71
- usb_device : usb_device:: device:: UsbDevice < ' static , dongle:: UsbBus > ,
72
72
}
73
73
74
74
#[ init( local = [
@@ -154,7 +154,6 @@ mod app {
154
154
let shared = MySharedResources {
155
155
usb_serial,
156
156
usb_hid,
157
- usb_device,
158
157
} ;
159
158
let local = MyLocalResources {
160
159
radio : board. radio ,
@@ -165,15 +164,16 @@ mod app {
165
164
err_count : 0 ,
166
165
msg_queue_out,
167
166
msg_queue_in,
168
- led : board. leds . ld1 ,
167
+ leds : board. leds ,
168
+ usb_device,
169
169
} ;
170
170
171
171
defmt:: debug!( "Init Complete!" ) ;
172
172
173
173
( shared, local)
174
174
}
175
175
176
- #[ idle( local = [ radio, current_channel, packet, timer, rx_count, err_count, msg_queue_out, led ] , shared = [ usb_serial] ) ]
176
+ #[ idle( local = [ radio, current_channel, packet, timer, rx_count, err_count, msg_queue_out, leds ] , shared = [ usb_serial] ) ]
177
177
fn idle ( mut ctx : idle:: Context ) -> ! {
178
178
use core:: fmt:: Write as _;
179
179
let mut writer = Writer ( |b : & [ u8 ] | {
@@ -189,6 +189,9 @@ mod app {
189
189
ctx. local. current_channel
190
190
) ;
191
191
192
+ ctx. local . leds . ld1 . on ( ) ;
193
+ ctx. local . leds . ld2_blue . on ( ) ;
194
+
192
195
loop {
193
196
while let Some ( msg) = ctx. local . msg_queue_out . dequeue ( ) {
194
197
match msg {
@@ -298,13 +301,13 @@ mod app {
298
301
}
299
302
300
303
defmt:: debug!( "Waiting for packet.." ) ;
301
- match ctx. local . radio . recv_timeout (
302
- & mut ctx . local . packet ,
303
- & mut ctx . local . timer ,
304
- 1_000_000 ,
305
- ) {
304
+ match ctx
305
+ . local
306
+ . radio
307
+ . recv_timeout ( ctx . local . packet , ctx . local . timer , 1_000_000 )
308
+ {
306
309
Ok ( crc) => {
307
- ctx. local . led . toggle ( ) ;
310
+ ctx. local . leds . ld1 . toggle ( ) ;
308
311
defmt:: info!(
309
312
"Received {=u8} bytes (CRC=0x{=u16:04x}, LQI={})" ,
310
313
ctx. local. packet. len( ) ,
@@ -344,15 +347,11 @@ mod app {
344
347
///
345
348
/// USB Device is set to fire this whenever there's a Start of Frame from
346
349
/// the USB Host.
347
- #[ task( binds = USBD , local = [ msg_queue_in] , shared = [ usb_serial, usb_hid, usb_device] ) ]
348
- fn usb_isr ( mut ctx : usb_isr:: Context ) {
349
- let mut all = (
350
- & mut ctx. shared . usb_serial ,
351
- & mut ctx. shared . usb_hid ,
352
- & mut ctx. shared . usb_device ,
353
- ) ;
354
- all. lock ( |usb_serial, usb_hid, usb_device| {
355
- if usb_device. poll ( & mut [ usb_serial, usb_hid] ) {
350
+ #[ task( binds = USBD , local = [ msg_queue_in, usb_device] , shared = [ usb_serial, usb_hid] ) ]
351
+ fn usb_isr ( ctx : usb_isr:: Context ) {
352
+ let mut all = ( ctx. shared . usb_serial , ctx. shared . usb_hid ) ;
353
+ all. lock ( |usb_serial, usb_hid| {
354
+ if ctx. local . usb_device . poll ( & mut [ usb_serial, usb_hid] ) {
356
355
let mut buffer = [ 0u8 ; 64 ] ;
357
356
if let Ok ( n) = usb_serial. read ( & mut buffer) {
358
357
if n > 0 {
0 commit comments