diff --git a/nrf52-code/loopback-fw/src/main.rs b/nrf52-code/loopback-fw/src/main.rs index c8f512f4..419296a6 100644 --- a/nrf52-code/loopback-fw/src/main.rs +++ b/nrf52-code/loopback-fw/src/main.rs @@ -51,8 +51,10 @@ mod app { msg_queue_out: heapless::spsc::Consumer<'static, Message, QUEUE_LEN>, /// A place to write to the message queue msg_queue_in: heapless::spsc::Producer<'static, Message, QUEUE_LEN>, - /// A status LED - led: dongle::Led, + /// The status LEDs + leds: dongle::Leds, + /// Handles the lower-level USB Device interface + usb_device: usb_device::device::UsbDevice<'static, dongle::UsbBus>, } #[derive(Debug, defmt::Format, Copy, Clone, PartialEq, Eq)] @@ -67,8 +69,6 @@ mod app { usb_serial: usbd_serial::SerialPort<'static, dongle::UsbBus>, /// Handles the USB HID interface usb_hid: usbd_hid::hid_class::HIDClass<'static, dongle::UsbBus>, - /// Handles the lower-level USB Device interface - usb_device: usb_device::device::UsbDevice<'static, dongle::UsbBus>, } #[init(local = [ @@ -154,7 +154,6 @@ mod app { let shared = MySharedResources { usb_serial, usb_hid, - usb_device, }; let local = MyLocalResources { radio: board.radio, @@ -165,7 +164,8 @@ mod app { err_count: 0, msg_queue_out, msg_queue_in, - led: board.leds.ld1, + leds: board.leds, + usb_device, }; defmt::debug!("Init Complete!"); @@ -173,7 +173,7 @@ mod app { (shared, local) } - #[idle(local = [radio, current_channel, packet, timer, rx_count, err_count, msg_queue_out, led], shared = [usb_serial])] + #[idle(local = [radio, current_channel, packet, timer, rx_count, err_count, msg_queue_out, leds], shared = [usb_serial])] fn idle(mut ctx: idle::Context) -> ! { use core::fmt::Write as _; let mut writer = Writer(|b: &[u8]| { @@ -189,6 +189,9 @@ mod app { ctx.local.current_channel ); + ctx.local.leds.ld1.on(); + ctx.local.leds.ld2_blue.on(); + loop { while let Some(msg) = ctx.local.msg_queue_out.dequeue() { match msg { @@ -299,12 +302,12 @@ mod app { defmt::debug!("Waiting for packet.."); match ctx.local.radio.recv_timeout( - &mut ctx.local.packet, - &mut ctx.local.timer, + ctx.local.packet, + ctx.local.timer, 1_000_000, ) { Ok(crc) => { - ctx.local.led.toggle(); + ctx.local.leds.ld1.toggle(); defmt::info!( "Received {=u8} bytes (CRC=0x{=u16:04x}, LQI={})", ctx.local.packet.len(), @@ -344,15 +347,11 @@ mod app { /// /// USB Device is set to fire this whenever there's a Start of Frame from /// the USB Host. - #[task(binds = USBD, local = [msg_queue_in], shared = [usb_serial, usb_hid, usb_device])] - fn usb_isr(mut ctx: usb_isr::Context) { - let mut all = ( - &mut ctx.shared.usb_serial, - &mut ctx.shared.usb_hid, - &mut ctx.shared.usb_device, - ); - all.lock(|usb_serial, usb_hid, usb_device| { - if usb_device.poll(&mut [usb_serial, usb_hid]) { + #[task(binds = USBD, local = [msg_queue_in, usb_device], shared = [usb_serial, usb_hid])] + fn usb_isr(ctx: usb_isr::Context) { + let mut all = (ctx.shared.usb_serial, ctx.shared.usb_hid); + all.lock(|usb_serial, usb_hid| { + if ctx.local.usb_device.poll(&mut [usb_serial, usb_hid]) { let mut buffer = [0u8; 64]; if let Ok(n) = usb_serial.read(&mut buffer) { if n > 0 { diff --git a/nrf52-code/puzzle-fw/src/main.rs b/nrf52-code/puzzle-fw/src/main.rs index 2bc3eed5..b15f82c1 100644 --- a/nrf52-code/puzzle-fw/src/main.rs +++ b/nrf52-code/puzzle-fw/src/main.rs @@ -68,6 +68,8 @@ mod app { msg_queue_in: heapless::spsc::Producer<'static, Message, QUEUE_LEN>, /// The status LEDs leds: dongle::Leds, + /// Handles the lower-level USB Device interface + usb_device: usb_device::device::UsbDevice<'static, dongle::UsbBus>, } #[derive(Debug, defmt::Format, Copy, Clone, PartialEq, Eq)] @@ -82,8 +84,6 @@ mod app { usb_serial: usbd_serial::SerialPort<'static, dongle::UsbBus>, /// Handles the USB HID interface usb_hid: usbd_hid::hid_class::HIDClass<'static, dongle::UsbBus>, - /// Handles the lower-level USB Device interface - usb_device: usb_device::device::UsbDevice<'static, dongle::UsbBus>, } #[init(local = [ @@ -169,7 +169,6 @@ mod app { let shared = MySharedResources { usb_serial, usb_hid, - usb_device, }; let local = MyLocalResources { radio: board.radio, @@ -181,6 +180,7 @@ mod app { msg_queue_out, msg_queue_in, leds: board.leds, + usb_device, }; defmt::debug!("Init Complete!"); @@ -427,15 +427,11 @@ mod app { /// /// USB Device is set to fire this whenever there's a Start of Frame from /// the USB Host. - #[task(binds = USBD, local = [msg_queue_in], shared = [usb_serial, usb_hid, usb_device])] - fn usb_isr(mut ctx: usb_isr::Context) { - let mut all = ( - &mut ctx.shared.usb_serial, - &mut ctx.shared.usb_hid, - &mut ctx.shared.usb_device, - ); - all.lock(|usb_serial, usb_hid, usb_device| { - if usb_device.poll(&mut [usb_serial, usb_hid]) { + #[task(binds = USBD, local = [msg_queue_in, usb_device], shared = [usb_serial, usb_hid])] + fn usb_isr(ctx: usb_isr::Context) { + let mut all = (ctx.shared.usb_serial, ctx.shared.usb_hid); + all.lock(|usb_serial, usb_hid| { + if ctx.local.usb_device.poll(&mut [usb_serial, usb_hid]) { let mut buffer = [0u8; 64]; if let Ok(n) = usb_serial.read(&mut buffer) { if n > 0 { @@ -472,7 +468,7 @@ mod app { dict: &heapless::LinearMap, ) -> Option { let payload = packet.get_mut(ADDR_BYTES..)?; - if payload.len() == 0 { + if payload.is_empty() { Some(Command::SendSecret) } else if payload.len() == 1 { // They give us plaintext, we give them ciphertext