Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions hal/src/subghz/mod_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Ord for FskBandwidth {

impl PartialOrd for FskBandwidth {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.hertz().cmp(&other.hertz()))
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -278,7 +278,7 @@ impl Ord for FskBitrate {

impl PartialOrd for FskBitrate {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.as_bps().cmp(&other.as_bps()))
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -711,7 +711,7 @@ impl Ord for LoRaBandwidth {

impl PartialOrd for LoRaBandwidth {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.hertz().cmp(&other.hertz()))
Some(self.cmp(other))
}
}

Expand Down Expand Up @@ -752,7 +752,6 @@ pub enum CodingRate {
/// LoRa modulation parameters.
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]

pub struct LoRaModParams {
buf: [u8; 5],
}
Expand Down
12 changes: 4 additions & 8 deletions hal/src/subghz/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ use core::time::Duration;

use super::ValueError;

const fn abs_diff(a: u64, b: u64) -> u64 {
if a > b { a - b } else { b - a }
}

/// Timeout argument.
///
/// This is used by:
Expand Down Expand Up @@ -159,8 +155,8 @@ impl Timeout {
let timeout_ceil: Timeout = Timeout::from_raw(div_ceil as u32);
let timeout_floor: Timeout = Timeout::from_raw(div_floor as u32);

let error_ceil: u64 = abs_diff(timeout_ceil.as_nanos(), duration_nanos);
let error_floor: u64 = abs_diff(timeout_floor.as_nanos(), duration_nanos);
let error_ceil: u64 = timeout_ceil.as_nanos().abs_diff(duration_nanos);
let error_floor: u64 = timeout_floor.as_nanos().abs_diff(duration_nanos);

if error_ceil < error_floor {
Ok(timeout_ceil)
Expand Down Expand Up @@ -221,8 +217,8 @@ impl Timeout {
let timeout_ceil: Timeout = Timeout::from_raw(div_ceil as u32);
let timeout_floor: Timeout = Timeout::from_raw(div_floor as u32);

let error_ceil: u64 = abs_diff(timeout_ceil.as_nanos(), duration_nanos);
let error_floor: u64 = abs_diff(timeout_floor.as_nanos(), duration_nanos);
let error_ceil: u64 = timeout_ceil.as_nanos().abs_diff(duration_nanos);
let error_floor: u64 = timeout_floor.as_nanos().abs_diff(duration_nanos);

if error_ceil < error_floor {
timeout_ceil
Expand Down