Run rustfmt.

This commit is contained in:
Dario Nieuwenhuis
2022-06-12 22:15:44 +02:00
parent 6199bdea71
commit a8703b7598
340 changed files with 1326 additions and 3020 deletions

View File

@ -43,19 +43,20 @@ mod value_error;
pub use bit_sync::BitSync;
pub use cad_params::{CadParams, ExitMode, NbCadSymbol};
pub use calibrate::{Calibrate, CalibrateImage};
use embassy_hal_common::ratio::Ratio;
pub use fallback_mode::FallbackMode;
pub use hse_trim::HseTrim;
pub use irq::{CfgIrq, Irq, IrqLine};
pub use lora_sync_word::LoRaSyncWord;
pub use mod_params::BpskModParams;
pub use mod_params::{CodingRate, LoRaBandwidth, LoRaModParams, SpreadingFactor};
pub use mod_params::{FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape};
pub use mod_params::{
BpskModParams, CodingRate, FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape, LoRaBandwidth,
LoRaModParams, SpreadingFactor,
};
pub use ocp::Ocp;
pub use op_error::OpError;
pub use pa_config::{PaConfig, PaSel};
pub use packet_params::{
AddrComp, BpskPacketParams, CrcType, GenericPacketParams, HeaderType, LoRaPacketParams,
PreambleDetection,
AddrComp, BpskPacketParams, CrcType, GenericPacketParams, HeaderType, LoRaPacketParams, PreambleDetection,
};
pub use packet_status::{FskPacketStatus, LoRaPacketStatus};
pub use packet_type::PacketType;
@ -75,17 +76,12 @@ pub use timeout::Timeout;
pub use tx_params::{RampTime, TxParams};
pub use value_error::ValueError;
use embassy_hal_common::ratio::Ratio;
use crate::Unborrow;
use crate::{
dma::NoDma,
pac,
peripherals::SUBGHZSPI,
rcc::sealed::RccPeripheral,
spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0},
time::Hertz,
};
use crate::dma::NoDma;
use crate::peripherals::SUBGHZSPI;
use crate::rcc::sealed::RccPeripheral;
use crate::spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0};
use crate::time::Hertz;
use crate::{pac, Unborrow};
/// Passthrough for SPI errors (for now)
pub type Error = crate::spi::Error;
@ -105,8 +101,7 @@ impl Nss {
fn clear() {
let pwr = pac::PWR;
unsafe {
pwr.subghzspicr()
.modify(|w| w.set_nss(pac::pwr::vals::Nss::LOW));
pwr.subghzspicr().modify(|w| w.set_nss(pac::pwr::vals::Nss::LOW));
}
}
@ -115,8 +110,7 @@ impl Nss {
fn set() {
let pwr = pac::PWR;
unsafe {
pwr.subghzspicr()
.modify(|w| w.set_nss(pac::pwr::vals::Nss::HIGH));
pwr.subghzspicr().modify(|w| w.set_nss(pac::pwr::vals::Nss::HIGH));
}
}
}
@ -286,8 +280,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
self.poll_not_busy();
{
let _nss: Nss = Nss::new();
self.spi
.blocking_write(&[OpCode::WriteBuffer as u8, offset])?;
self.spi.blocking_write(&[OpCode::WriteBuffer as u8, offset])?;
self.spi.blocking_write(data)?;
}
self.poll_not_busy();
@ -305,8 +298,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
self.poll_not_busy();
{
let _nss: Nss = Nss::new();
self.spi
.blocking_write(&[OpCode::ReadBuffer as u8, offset])?;
self.spi.blocking_write(&[OpCode::ReadBuffer as u8, offset])?;
self.spi.blocking_transfer_in_place(&mut status_buf)?;
self.spi.blocking_transfer_in_place(buf)?;
}
@ -678,10 +670,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
/// # Ok::<(), embassy_stm32::subghz::Error>(())
/// ```
pub fn set_rx_timeout_stop(&mut self, rx_timeout_stop: RxTimeoutStop) -> Result<(), Error> {
self.write(&[
OpCode::SetStopRxTimerOnPreamble.into(),
rx_timeout_stop.into(),
])
self.write(&[OpCode::SetStopRxTimerOnPreamble.into(), rx_timeout_stop.into()])
}
/// Put the radio in non-continuous RX mode.
@ -730,11 +719,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
/// [`RxDone`]: crate::subghz::Irq::RxDone
/// [`set_rf_frequency`]: crate::subghz::SubGhz::set_rf_frequency
/// [`set_standby`]: crate::subghz::SubGhz::set_standby
pub fn set_rx_duty_cycle(
&mut self,
rx_period: Timeout,
sleep_period: Timeout,
) -> Result<(), Error> {
pub fn set_rx_duty_cycle(&mut self, rx_period: Timeout, sleep_period: Timeout) -> Result<(), Error> {
let rx_period_bits: u32 = rx_period.into_bits();
let sleep_period_bits: u32 = sleep_period.into_bits();
self.write(&[
@ -1288,9 +1273,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
/// # Ok::<(), embassy_stm32::subghz::Error>(())
/// ```
pub fn lora_packet_status(&mut self) -> Result<LoRaPacketStatus, Error> {
Ok(LoRaPacketStatus::from(
self.read_n(OpCode::GetPacketStatus)?,
))
Ok(LoRaPacketStatus::from(self.read_n(OpCode::GetPacketStatus)?))
}
/// Get the instantaneous signal strength during packet reception.

View File

@ -13,58 +13,37 @@ impl PaConfig {
/// Optimal settings for +15dBm output power with the low-power PA.
///
/// This must be used with [`TxParams::LP_15`](super::TxParams::LP_15).
pub const LP_15: PaConfig = PaConfig::new()
.set_pa_duty_cycle(0x6)
.set_hp_max(0x0)
.set_pa(PaSel::Lp);
pub const LP_15: PaConfig = PaConfig::new().set_pa_duty_cycle(0x6).set_hp_max(0x0).set_pa(PaSel::Lp);
/// Optimal settings for +14dBm output power with the low-power PA.
///
/// This must be used with [`TxParams::LP_14`](super::TxParams::LP_14).
pub const LP_14: PaConfig = PaConfig::new()
.set_pa_duty_cycle(0x4)
.set_hp_max(0x0)
.set_pa(PaSel::Lp);
pub const LP_14: PaConfig = PaConfig::new().set_pa_duty_cycle(0x4).set_hp_max(0x0).set_pa(PaSel::Lp);
/// Optimal settings for +10dBm output power with the low-power PA.
///
/// This must be used with [`TxParams::LP_10`](super::TxParams::LP_10).
pub const LP_10: PaConfig = PaConfig::new()
.set_pa_duty_cycle(0x1)
.set_hp_max(0x0)
.set_pa(PaSel::Lp);
pub const LP_10: PaConfig = PaConfig::new().set_pa_duty_cycle(0x1).set_hp_max(0x0).set_pa(PaSel::Lp);
/// Optimal settings for +22dBm output power with the high-power PA.
///
/// This must be used with [`TxParams::HP`](super::TxParams::HP).
pub const HP_22: PaConfig = PaConfig::new()
.set_pa_duty_cycle(0x4)
.set_hp_max(0x7)
.set_pa(PaSel::Hp);
pub const HP_22: PaConfig = PaConfig::new().set_pa_duty_cycle(0x4).set_hp_max(0x7).set_pa(PaSel::Hp);
/// Optimal settings for +20dBm output power with the high-power PA.
///
/// This must be used with [`TxParams::HP`](super::TxParams::HP).
pub const HP_20: PaConfig = PaConfig::new()
.set_pa_duty_cycle(0x3)
.set_hp_max(0x5)
.set_pa(PaSel::Hp);
pub const HP_20: PaConfig = PaConfig::new().set_pa_duty_cycle(0x3).set_hp_max(0x5).set_pa(PaSel::Hp);
/// Optimal settings for +17dBm output power with the high-power PA.
///
/// This must be used with [`TxParams::HP`](super::TxParams::HP).
pub const HP_17: PaConfig = PaConfig::new()
.set_pa_duty_cycle(0x2)
.set_hp_max(0x3)
.set_pa(PaSel::Hp);
pub const HP_17: PaConfig = PaConfig::new().set_pa_duty_cycle(0x2).set_hp_max(0x3).set_pa(PaSel::Hp);
/// Optimal settings for +14dBm output power with the high-power PA.
///
/// This must be used with [`TxParams::HP`](super::TxParams::HP).
pub const HP_14: PaConfig = PaConfig::new()
.set_pa_duty_cycle(0x2)
.set_hp_max(0x2)
.set_pa(PaSel::Hp);
pub const HP_14: PaConfig = PaConfig::new().set_pa_duty_cycle(0x2).set_hp_max(0x2).set_pa(PaSel::Hp);
/// Create a new `PaConfig` struct.
///

View File

@ -147,10 +147,7 @@ impl GenericPacketParams {
/// # assert_eq!(PKT_PARAMS.as_slice()[3], 0x4);
/// ```
#[must_use = "set_preamble_detection returns a modified GenericPacketParams"]
pub const fn set_preamble_detection(
mut self,
pb_det: PreambleDetection,
) -> GenericPacketParams {
pub const fn set_preamble_detection(mut self, pb_det: PreambleDetection) -> GenericPacketParams {
self.buf[3] = pb_det as u8;
self
}

View File

@ -1,6 +1,4 @@
use super::Ratio;
use super::Status;
use super::{Ratio, Status};
/// (G)FSK packet status.
///

View File

@ -89,10 +89,7 @@ impl RfFreq {
// Get the frequency bit value.
const fn as_bits(&self) -> u32 {
((self.buf[1] as u32) << 24)
| ((self.buf[2] as u32) << 16)
| ((self.buf[3] as u32) << 8)
| (self.buf[4] as u32)
((self.buf[1] as u32) << 24) | ((self.buf[2] as u32) << 16) | ((self.buf[3] as u32) << 8) | (self.buf[4] as u32)
}
/// Get the actual frequency.

View File

@ -49,9 +49,7 @@ impl SleepCfg {
/// # assert_eq!(u8::from(SLEEP_CFG), 0b101);
/// ```
pub const fn new() -> SleepCfg {
SleepCfg(0)
.set_startup(Startup::Warm)
.set_rtc_wakeup_en(true)
SleepCfg(0).set_startup(Startup::Warm).set_rtc_wakeup_en(true)
}
/// Set the startup mode.

View File

@ -192,11 +192,6 @@ impl core::fmt::Display for Status {
#[cfg(feature = "defmt")]
impl defmt::Format for Status {
fn format(&self, fmt: defmt::Formatter) {
defmt::write!(
fmt,
"Status {{ mode: {}, cmd: {} }}",
self.mode(),
self.cmd()
)
defmt::write!(fmt, "Status {{ mode: {}, cmd: {} }}", self.mode(), self.cmd())
}
}

View File

@ -145,8 +145,7 @@ impl Timeout {
// `core::Duration` were not `const fn`, which leads to the hacks
// you see here.
let nanos: u128 = duration.as_nanos();
const UPPER_LIMIT: u128 =
Timeout::MAX.as_nanos() as u128 + (Timeout::RESOLUTION_NANOS as u128) / 2;
const UPPER_LIMIT: u128 = Timeout::MAX.as_nanos() as u128 + (Timeout::RESOLUTION_NANOS as u128) / 2;
const LOWER_LIMIT: u128 = (((Timeout::RESOLUTION_NANOS as u128) + 1) / 2) as u128;
if nanos > UPPER_LIMIT {
@ -420,15 +419,13 @@ impl From<Timeout> for embassy::time::Duration {
#[cfg(test)]
mod tests {
use super::{Timeout, ValueError};
use core::time::Duration;
use super::{Timeout, ValueError};
#[test]
fn saturate() {
assert_eq!(
Timeout::from_duration_sat(Duration::from_secs(u64::MAX)),
Timeout::MAX
);
assert_eq!(Timeout::from_duration_sat(Duration::from_secs(u64::MAX)), Timeout::MAX);
}
#[test]
@ -455,10 +452,7 @@ mod tests {
#[test]
fn upper_limit() {
let high: Duration = Timeout::MAX.as_duration() + Timeout::RESOLUTION / 2;
assert_eq!(
Timeout::from_duration(high),
Ok(Timeout::from_raw(0xFFFFFF))
);
assert_eq!(Timeout::from_duration(high), Ok(Timeout::from_raw(0xFFFFFF)));
let too_high: Duration = high + Duration::from_nanos(1);
assert_eq!(