From 7dc79c1a24e0a68086c0d5e4b4245f15d5f8561d Mon Sep 17 00:00:00 2001 From: Stephen Waits Date: Sun, 29 Mar 2026 16:57:37 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20clippy-clean=20=E2=80=94=20rename=20to?= =?UTF-8?q?=5Fbytes=E2=86=92write=5Fto,=20fix=20Justfile=20clippy=20args?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Justfile | 6 +++--- src/protocol.rs | 13 +++++++------ src/usb/task.rs | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Justfile b/Justfile index cdd019b6..e6842ca3 100644 --- a/Justfile +++ b/Justfile @@ -42,7 +42,7 @@ check board: # Run clippy on a single board clippy board: - @just _cargo {{board}} "clippy -- -D warnings" + @just _cargo {{board}} "clippy" "-- -D warnings" # Build release firmware and copy to firmware/ with a readable name build board profile="release": @@ -68,7 +68,7 @@ size board: # Run a cargo command for a board. # Xtensa: nightly cargo + esp rustc (via RUSTC override) + -Zbuild-std=core [private] -_cargo board cmd: +_cargo board cmd extra_args="": @read -r feat target chip <<< "$(just _info {{board}})"; \ env=""; extra=""; \ case "$target" in xtensa-*) \ @@ -76,7 +76,7 @@ _cargo board cmd: [ -f "$HOME/export-esp.sh" ] && . "$HOME/export-esp.sh"; \ env="RUSTC=$(rustup which rustc --toolchain esp)"; extra="+nightly";; \ esac; \ - eval $env cargo $extra {{cmd}} --target $target --features $feat + eval $env cargo $extra {{cmd}} --target "$target" --features "$feat" {{extra_args}} # Check if a board's toolchain is available (silent, for build-all/check-all skipping) [private] diff --git a/src/protocol.rs b/src/protocol.rs index 84e17b14..be8e660a 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -98,7 +98,7 @@ impl RadioConfig { } /// Serialize to fixed-size LE bytes. Returns number of bytes written (always 10). - pub fn to_bytes(&self, buf: &mut [u8]) -> usize { + pub fn write_to(self, buf: &mut [u8]) -> usize { buf[0..4].copy_from_slice(&self.freq_hz.to_le_bytes()); buf[4] = self.bw as u8; buf[5] = self.sf; @@ -159,7 +159,7 @@ impl Command { } let (config, pos) = if rest[0] == 0 { (None, 1) - } else if rest[0] == 1 && rest.len() >= 1 + RADIO_CONFIG_SIZE { + } else if rest[0] == 1 && rest.len() > RADIO_CONFIG_SIZE { (Some(RadioConfig::from_bytes(&rest[1..])?), 1 + RADIO_CONFIG_SIZE) } else { return None; @@ -201,7 +201,7 @@ pub enum Response { impl Response { /// Serialize to fixed-size LE bytes. Returns number of bytes written. - pub fn to_bytes(&self, buf: &mut [u8]) -> usize { + pub fn write_to(self, buf: &mut [u8]) -> usize { match self { Self::Pong => { buf[0] = 0; @@ -209,14 +209,14 @@ impl Response { } Self::Config(cfg) => { buf[0] = 1; - 1 + cfg.to_bytes(&mut buf[1..]) + 1 + cfg.write_to(&mut buf[1..]) } Self::RxPacket { rssi, snr, payload } => { buf[0] = 2; buf[1..3].copy_from_slice(&rssi.to_le_bytes()); buf[3..5].copy_from_slice(&snr.to_le_bytes()); buf[5..7].copy_from_slice(&(payload.len() as u16).to_le_bytes()); - buf[7..7 + payload.len()].copy_from_slice(payload); + buf[7..7 + payload.len()].copy_from_slice(&payload); 7 + payload.len() } Self::TxDone => { @@ -229,7 +229,7 @@ impl Response { } Self::Error(code) => { buf[0] = 5; - buf[1] = *code as u8; + buf[1] = code as u8; 2 } } @@ -239,6 +239,7 @@ impl Response { /// Error codes reported to the host. #[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)] #[repr(u8)] +#[allow(dead_code)] pub enum ErrorCode { InvalidConfig = 0, RadioBusy = 1, diff --git a/src/usb/task.rs b/src/usb/task.rs index 03c79321..b139f9d7 100644 --- a/src/usb/task.rs +++ b/src/usb/task.rs @@ -146,7 +146,7 @@ async fn protocol_loop<'d, D: embassy_usb_driver::Driver<'d>>( } Either3::Second(response) => { // Serialize response to fixed-size LE bytes, then COBS encode - let raw_len = response.to_bytes(&mut write_buf); + let raw_len = response.write_to(&mut write_buf); let encoded_len = cobs::encode(&write_buf[..raw_len], &mut cobs_encode_buf); // Append 0x00 sentinel if encoded_len < cobs_encode_buf.len() {