Skip to content

Commit 64b7beb

Browse files
Clippy fixes and clean ups.
The usb_device is only used in the ISR, so it can be a local. Saves us a lock.
1 parent f27c694 commit 64b7beb

File tree

2 files changed

+30
-35
lines changed

2 files changed

+30
-35
lines changed

nrf52-code/loopback-fw/src/main.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ mod app {
5151
msg_queue_out: heapless::spsc::Consumer<'static, Message, QUEUE_LEN>,
5252
/// A place to write to the message queue
5353
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>,
5658
}
5759

5860
#[derive(Debug, defmt::Format, Copy, Clone, PartialEq, Eq)]
@@ -67,8 +69,6 @@ mod app {
6769
usb_serial: usbd_serial::SerialPort<'static, dongle::UsbBus>,
6870
/// Handles the USB HID interface
6971
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>,
7272
}
7373

7474
#[init(local = [
@@ -154,7 +154,6 @@ mod app {
154154
let shared = MySharedResources {
155155
usb_serial,
156156
usb_hid,
157-
usb_device,
158157
};
159158
let local = MyLocalResources {
160159
radio: board.radio,
@@ -165,15 +164,16 @@ mod app {
165164
err_count: 0,
166165
msg_queue_out,
167166
msg_queue_in,
168-
led: board.leds.ld1,
167+
leds: board.leds,
168+
usb_device,
169169
};
170170

171171
defmt::debug!("Init Complete!");
172172

173173
(shared, local)
174174
}
175175

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])]
177177
fn idle(mut ctx: idle::Context) -> ! {
178178
use core::fmt::Write as _;
179179
let mut writer = Writer(|b: &[u8]| {
@@ -189,6 +189,9 @@ mod app {
189189
ctx.local.current_channel
190190
);
191191

192+
ctx.local.leds.ld1.on();
193+
ctx.local.leds.ld2_blue.on();
194+
192195
loop {
193196
while let Some(msg) = ctx.local.msg_queue_out.dequeue() {
194197
match msg {
@@ -298,13 +301,13 @@ mod app {
298301
}
299302

300303
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+
{
306309
Ok(crc) => {
307-
ctx.local.led.toggle();
310+
ctx.local.leds.ld1.toggle();
308311
defmt::info!(
309312
"Received {=u8} bytes (CRC=0x{=u16:04x}, LQI={})",
310313
ctx.local.packet.len(),
@@ -344,15 +347,11 @@ mod app {
344347
///
345348
/// USB Device is set to fire this whenever there's a Start of Frame from
346349
/// 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]) {
356355
let mut buffer = [0u8; 64];
357356
if let Ok(n) = usb_serial.read(&mut buffer) {
358357
if n > 0 {

nrf52-code/puzzle-fw/src/main.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ mod app {
6868
msg_queue_in: heapless::spsc::Producer<'static, Message, QUEUE_LEN>,
6969
/// The status LEDs
7070
leds: dongle::Leds,
71+
/// Handles the lower-level USB Device interface
72+
usb_device: usb_device::device::UsbDevice<'static, dongle::UsbBus>,
7173
}
7274

7375
#[derive(Debug, defmt::Format, Copy, Clone, PartialEq, Eq)]
@@ -82,8 +84,6 @@ mod app {
8284
usb_serial: usbd_serial::SerialPort<'static, dongle::UsbBus>,
8385
/// Handles the USB HID interface
8486
usb_hid: usbd_hid::hid_class::HIDClass<'static, dongle::UsbBus>,
85-
/// Handles the lower-level USB Device interface
86-
usb_device: usb_device::device::UsbDevice<'static, dongle::UsbBus>,
8787
}
8888

8989
#[init(local = [
@@ -169,7 +169,6 @@ mod app {
169169
let shared = MySharedResources {
170170
usb_serial,
171171
usb_hid,
172-
usb_device,
173172
};
174173
let local = MyLocalResources {
175174
radio: board.radio,
@@ -181,6 +180,7 @@ mod app {
181180
msg_queue_out,
182181
msg_queue_in,
183182
leds: board.leds,
183+
usb_device,
184184
};
185185

186186
defmt::debug!("Init Complete!");
@@ -427,15 +427,11 @@ mod app {
427427
///
428428
/// USB Device is set to fire this whenever there's a Start of Frame from
429429
/// the USB Host.
430-
#[task(binds = USBD, local = [msg_queue_in], shared = [usb_serial, usb_hid, usb_device])]
431-
fn usb_isr(mut ctx: usb_isr::Context) {
432-
let mut all = (
433-
&mut ctx.shared.usb_serial,
434-
&mut ctx.shared.usb_hid,
435-
&mut ctx.shared.usb_device,
436-
);
437-
all.lock(|usb_serial, usb_hid, usb_device| {
438-
if usb_device.poll(&mut [usb_serial, usb_hid]) {
430+
#[task(binds = USBD, local = [msg_queue_in, usb_device], shared = [usb_serial, usb_hid])]
431+
fn usb_isr(ctx: usb_isr::Context) {
432+
let mut all = (ctx.shared.usb_serial, ctx.shared.usb_hid);
433+
all.lock(|usb_serial, usb_hid| {
434+
if ctx.local.usb_device.poll(&mut [usb_serial, usb_hid]) {
439435
let mut buffer = [0u8; 64];
440436
if let Ok(n) = usb_serial.read(&mut buffer) {
441437
if n > 0 {
@@ -472,7 +468,7 @@ mod app {
472468
dict: &heapless::LinearMap<u8, u8, 128>,
473469
) -> Option<Command> {
474470
let payload = packet.get_mut(ADDR_BYTES..)?;
475-
if payload.len() == 0 {
471+
if payload.is_empty() {
476472
Some(Command::SendSecret)
477473
} else if payload.len() == 1 {
478474
// They give us plaintext, we give them ciphertext

0 commit comments

Comments
 (0)