pub struct FskModParams { /* private fields */ }
Expand description

(G)FSK modulation parameters.

Implementations§

source§

impl FskModParams

source

pub const fn new() -> FskModParams

Create a new FskModParams struct.

This is the same as default, but in a const function.

Example
use stm32wlxx_hal::subghz::FskModParams;

const MOD_PARAMS: FskModParams = FskModParams::new();
source

pub const fn bitrate(&self) -> FskBitrate

Get the bitrate.

Example

Setting the bitrate to 32,000 bits per second.

use stm32wlxx_hal::subghz::{FskBitrate, FskModParams};

const BITRATE: FskBitrate = FskBitrate::from_bps(32_000);
const MOD_PARAMS: FskModParams = FskModParams::new().set_bitrate(BITRATE);
assert_eq!(MOD_PARAMS.bitrate(), BITRATE);
source

pub const fn set_bitrate(self, bitrate: FskBitrate) -> FskModParams

Set the bitrate.

Example

Setting the bitrate to 32,000 bits per second.

use stm32wlxx_hal::subghz::{FskBitrate, FskModParams};

const BITRATE: FskBitrate = FskBitrate::from_bps(32_000);
const MOD_PARAMS: FskModParams = FskModParams::new().set_bitrate(BITRATE);
source

pub const fn set_pulse_shape(self, shape: FskPulseShape) -> FskModParams

Set the pulse shaping.

Example
use stm32wlxx_hal::subghz::{FskModParams, FskPulseShape};

const MOD_PARAMS: FskModParams = FskModParams::new().set_pulse_shape(FskPulseShape::Bt03);
source

pub const fn bandwidth(&self) -> Result<FskBandwidth, u8>

Get the bandwidth.

Values that do not correspond to a valid FskBandwidth will be returned in the Err variant of the result.

Example
use stm32wlxx_hal::subghz::{FskBandwidth, FskModParams};

const MOD_PARAMS: FskModParams = FskModParams::new().set_bandwidth(FskBandwidth::Bw9);
assert_eq!(MOD_PARAMS.bandwidth(), Ok(FskBandwidth::Bw9));
source

pub const fn set_bandwidth(self, bw: FskBandwidth) -> FskModParams

Set the bandwidth.

Example
use stm32wlxx_hal::subghz::{FskBandwidth, FskModParams};

const MOD_PARAMS: FskModParams = FskModParams::new().set_bandwidth(FskBandwidth::Bw9);
source

pub const fn fdev(&self) -> FskFdev

Get the frequency deviation.

Example
use stm32wlxx_hal::subghz::{FskFdev, FskModParams};

const FDEV: FskFdev = FskFdev::from_hertz(31_250);
const MOD_PARAMS: FskModParams = FskModParams::new().set_fdev(FDEV);
assert_eq!(MOD_PARAMS.fdev(), FDEV);
source

pub const fn set_fdev(self, fdev: FskFdev) -> FskModParams

Set the frequency deviation.

Example
use stm32wlxx_hal::subghz::{FskFdev, FskModParams};

const FDEV: FskFdev = FskFdev::from_hertz(31_250);
const MOD_PARAMS: FskModParams = FskModParams::new().set_fdev(FDEV);
source

pub const fn is_valid(&self, ppm: u8) -> bool

Returns true if the modulation parameters are valid.

The bandwidth must be chosen so that:

FskBandwidth > FskBitrate + 2 × FskFdev + frequency error

Where frequency error = 2 × HSE32FREQ error.

The datasheet (DS13293 Rev 1) gives these requirements for the HSE32 frequency tolerance:

  • Initial: ±10 ppm
  • Over temperature (-20 to 70 °C): ±10 ppm
  • Aging over 10 years: ±10 ppm
Example

Checking valid parameters at compile-time

extern crate static_assertions as sa;
use stm32wlxx_hal::subghz::{FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape};

const MOD_PARAMS: FskModParams = FskModParams::new()
    .set_bitrate(FskBitrate::from_bps(20_000))
    .set_pulse_shape(FskPulseShape::Bt03)
    .set_bandwidth(FskBandwidth::Bw58)
    .set_fdev(FskFdev::from_hertz(10_000));

// 30 PPM is worst case (if the HSE32 crystal meets requirements)
sa::const_assert!(MOD_PARAMS.is_valid(30));
source

pub const fn is_valid_worst_case(&self) -> bool

Returns true if the modulation parameters are valid for a worst-case crystal tolerance.

This is equivalent to is_valid with a ppm argument of 30.

source

pub const fn as_slice(&self) -> &[u8]

Extracts a slice containing the packet.

Example
use stm32wlxx_hal::subghz::{FskBandwidth, FskBitrate, FskFdev, FskModParams, FskPulseShape};

const BITRATE: FskBitrate = FskBitrate::from_bps(20_000);
const PULSE_SHAPE: FskPulseShape = FskPulseShape::Bt03;
const BW: FskBandwidth = FskBandwidth::Bw58;
const FDEV: FskFdev = FskFdev::from_hertz(10_000);

const MOD_PARAMS: FskModParams = FskModParams::new()
    .set_bitrate(BITRATE)
    .set_pulse_shape(PULSE_SHAPE)
    .set_bandwidth(BW)
    .set_fdev(FDEV);

assert_eq!(
    MOD_PARAMS.as_slice(),
    &[0x8B, 0x00, 0xC8, 0x00, 0x08, 0x0C, 0x00, 0x28, 0xF5]
);

Trait Implementations§

source§

impl Clone for FskModParams

source§

fn clone(&self) -> FskModParams

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for FskModParams

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for FskModParams

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl PartialEq for FskModParams

source§

fn eq(&self, other: &FskModParams) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for FskModParams

source§

impl Eq for FskModParams

source§

impl StructuralEq for FskModParams

source§

impl StructuralPartialEq for FskModParams

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.