fix: clippy-clean — rename to_bytes→write_to, fix Justfile clippy args

This commit is contained in:
swaits committed 2026-03-29 20:42:59 -06:00
1 parent fd360e0cfe
commit 7dc79c1a24
3 files changed
+11 -10

No files matched your search

+3 -3
View File
@@ -42,7 +42,7 @@ check board:
# Run clippy on a single board # Run clippy on a single board
clippy 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 release firmware and copy to firmware/ with a readable name
build board profile="release": build board profile="release":
@@ -68,7 +68,7 @@ size board:
# Run a cargo command for a board. # Run a cargo command for a board.
# Xtensa: nightly cargo + esp rustc (via RUSTC override) + -Zbuild-std=core # Xtensa: nightly cargo + esp rustc (via RUSTC override) + -Zbuild-std=core
[private] [private]
_cargo board cmd: _cargo board cmd extra_args="":
@read -r feat target chip <<< "$(just _info {{board}})"; \ @read -r feat target chip <<< "$(just _info {{board}})"; \
env=""; extra=""; \ env=""; extra=""; \
case "$target" in xtensa-*) \ case "$target" in xtensa-*) \
@@ -76,7 +76,7 @@ _cargo board cmd:
[ -f "$HOME/export-esp.sh" ] && . "$HOME/export-esp.sh"; \ [ -f "$HOME/export-esp.sh" ] && . "$HOME/export-esp.sh"; \
env="RUSTC=$(rustup which rustc --toolchain esp)"; extra="+nightly";; \ env="RUSTC=$(rustup which rustc --toolchain esp)"; extra="+nightly";; \
esac; \ 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) # Check if a board's toolchain is available (silent, for build-all/check-all skipping)
[private] [private]
+7 -6
View File
@@ -98,7 +98,7 @@ impl RadioConfig {
} }
/// Serialize to fixed-size LE bytes. Returns number of bytes written (always 10). /// 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[0..4].copy_from_slice(&self.freq_hz.to_le_bytes());
buf[4] = self.bw as u8; buf[4] = self.bw as u8;
buf[5] = self.sf; buf[5] = self.sf;
@@ -159,7 +159,7 @@ impl Command {
} }
let (config, pos) = if rest[0] == 0 { let (config, pos) = if rest[0] == 0 {
(None, 1) (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) (Some(RadioConfig::from_bytes(&rest[1..])?), 1 + RADIO_CONFIG_SIZE)
} else { } else {
return None; return None;
@@ -201,7 +201,7 @@ pub enum Response {
impl Response { impl Response {
/// Serialize to fixed-size LE bytes. Returns number of bytes written. /// 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 { match self {
Self::Pong => { Self::Pong => {
buf[0] = 0; buf[0] = 0;
@@ -209,14 +209,14 @@ impl Response {
} }
Self::Config(cfg) => { Self::Config(cfg) => {
buf[0] = 1; buf[0] = 1;
1 + cfg.to_bytes(&mut buf[1..]) 1 + cfg.write_to(&mut buf[1..])
} }
Self::RxPacket { rssi, snr, payload } => { Self::RxPacket { rssi, snr, payload } => {
buf[0] = 2; buf[0] = 2;
buf[1..3].copy_from_slice(&rssi.to_le_bytes()); buf[1..3].copy_from_slice(&rssi.to_le_bytes());
buf[3..5].copy_from_slice(&snr.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[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() 7 + payload.len()
} }
Self::TxDone => { Self::TxDone => {
@@ -229,7 +229,7 @@ impl Response {
} }
Self::Error(code) => { Self::Error(code) => {
buf[0] = 5; buf[0] = 5;
buf[1] = *code as u8; buf[1] = code as u8;
2 2
} }
} }
@@ -239,6 +239,7 @@ impl Response {
/// Error codes reported to the host. /// Error codes reported to the host.
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)] #[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
#[repr(u8)] #[repr(u8)]
#[allow(dead_code)]
pub enum ErrorCode { pub enum ErrorCode {
InvalidConfig = 0, InvalidConfig = 0,
RadioBusy = 1, RadioBusy = 1,
+1 -1
View File
@@ -146,7 +146,7 @@ async fn protocol_loop<'d, D: embassy_usb_driver::Driver<'d>>(
} }
Either3::Second(response) => { Either3::Second(response) => {
// Serialize response to fixed-size LE bytes, then COBS encode // 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); let encoded_len = cobs::encode(&write_buf[..raw_len], &mut cobs_encode_buf);
// Append 0x00 sentinel // Append 0x00 sentinel
if encoded_len < cobs_encode_buf.len() { if encoded_len < cobs_encode_buf.len() {