Skip to content

Commit

Permalink
ran cargo clippy and cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Aug 1, 2024
1 parent 8cf3280 commit 14c41ee
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/radio/rf24/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ where
/// See also [`RF24::set_channel()`].
fn get_channel(&mut self) -> Result<u8, Self::ChannelErrorType> {
self.spi_read(1, registers::RF_CH)?;
Ok(self._buf[1].clone())
Ok(self._buf[1])
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/radio/rf24/crc_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ where
fn set_crc_length(&mut self, data_rate: CrcLength) -> Result<(), Self::CrcLengthErrorType> {
let crc_bin = {
match data_rate {
CrcLength::DISABLED => 0 as u8,
CrcLength::BIT8 => 2 as u8,
CrcLength::BIT16 => 3 as u8,
CrcLength::DISABLED => 0u8,
CrcLength::BIT8 => 2u8,
CrcLength::BIT16 => 3u8,
}
} << 2;
self.spi_read(1, registers::CONFIG)?;
Expand Down
6 changes: 3 additions & 3 deletions src/radio/rf24/data_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ where
match data_rate {
DataRate::Mbps1 => {
self._tx_delay = 280;
0 as u8
0u8
}
DataRate::Mbps2 => {
self._tx_delay = 240;
1 as u8
1u8
}
DataRate::Kbps250 => {
self._tx_delay = 505;
4 as u8
4u8
}
}
} << 3;
Expand Down
6 changes: 2 additions & 4 deletions src/radio/rf24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ where
_status: 0,
_ce_pin: ce_pin,
_spi: spi,
_buf: [0 as u8; 33],
_buf: [0u8; 33],
_is_plus_variant: true,
_ack_payloads_enabled: false,
_dynamic_payloads_enabled: false,
Expand Down Expand Up @@ -110,9 +110,7 @@ where
) -> Result<(), Nrf24Error<SPI::Error, DO::Error>> {
self._buf[0] = command | commands::W_REGISTER;
let buf_len = buf.len();
for i in 0..buf_len {
self._buf[i + 1] = buf[i];
}
self._buf[1..(buf_len + 1)].copy_from_slice(&buf[..buf_len]);
self.spi_transfer(buf_len as u8 + 1)
}

Expand Down
8 changes: 4 additions & 4 deletions src/radio/rf24/pa_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ where
let pa_bin = 1
| ({
match pa_level {
PaLevel::MIN => 0 as u8,
PaLevel::LOW => 1 as u8,
PaLevel::HIGH => 2 as u8,
PaLevel::MAX => 3 as u8,
PaLevel::MIN => 0u8,
PaLevel::LOW => 1u8,
PaLevel::HIGH => 2u8,
PaLevel::MAX => 3u8,
}
} << 1);
self.spi_read(1, registers::RF_SETUP)?;
Expand Down
4 changes: 1 addition & 3 deletions src/radio/rf24/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ where
// start_listening() will have to restore it.
if pipe == 0 {
let mut cached_addr = self._pipe0_rx_addr.unwrap_or_default();
for i in 0..width {
cached_addr[i] = address[i];
}
cached_addr[..width].copy_from_slice(&address[..width]);
self._pipe0_rx_addr = Some(cached_addr);
}
self.spi_write_buf(registers::RX_ADDR_P0 + pipe, &address[..width])?;
Expand Down
2 changes: 1 addition & 1 deletion src/radio/rf24/power.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where
// There must be a delay of Tpd2stby (see Table 16.) after the nRF24L01+ leaves power down mode before
// the CEis set high. - Tpd2stby can be up to 5ms per the 1.0 datasheet
if delay.is_some_and(|val| val > 0) || delay.is_none() {
self._delay_impl.delay_ns(delay.unwrap_or_else(|| 5000000));
self._delay_impl.delay_ns(delay.unwrap_or(5000000));
}
Ok(())
}
Expand Down
8 changes: 3 additions & 5 deletions src/radio/rf24/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ where

// if config is not set correctly then there was a bad response from module
self.spi_read(1, registers::CONFIG)?;
return if self._buf[1] == self._config_reg {
if self._buf[1] == self._config_reg {
Ok(())
} else {
Err(Nrf24Error::BinaryCorruption)
};
}
}

fn start_listening(&mut self) -> Result<(), Self::RadioErrorType> {
Expand Down Expand Up @@ -178,9 +178,7 @@ where
};
// to avoid resizing the given buf, we'll have to use self._buf directly
self._buf[0] = commands::W_TX_PAYLOAD | ((ask_no_ack as u8) << 4);
for i in 0..buf_len {
self._buf[i + 1] = buf[i];
}
self._buf[1..(buf_len + 1)].copy_from_slice(&buf[..buf_len]);
// ensure payload_length setting is respected
if !self._dynamic_payloads_enabled && buf_len < self._payload_length as usize {
// pad buf with zeros
Expand Down
3 changes: 1 addition & 2 deletions src/radio/rf24/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ where
tx_ds: bool,
tx_df: bool,
) -> Result<(), Self::StatusErrorType> {
let new_config = 0
| (mnemonics::MASK_RX_DR * rx_dr as u8)
let new_config = (mnemonics::MASK_RX_DR * rx_dr as u8)
| (mnemonics::MASK_TX_DS * tx_ds as u8)
| (mnemonics::MASK_MAX_RT * tx_df as u8);
self.spi_write_byte(registers::STATUS, new_config)
Expand Down

0 comments on commit 14c41ee

Please sign in to comment.