Struct stm32wlxx_hal::subghz::FskModParams
source · pub struct FskModParams { /* private fields */ }
Expand description
(G)FSK modulation parameters.
Implementations§
source§impl FskModParams
impl FskModParams
sourcepub const fn new() -> FskModParams
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();
sourcepub const fn bitrate(&self) -> FskBitrate
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);
sourcepub const fn set_bitrate(self, bitrate: FskBitrate) -> FskModParams
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);
sourcepub const fn set_pulse_shape(self, shape: FskPulseShape) -> FskModParams
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);
sourcepub const fn bandwidth(&self) -> Result<FskBandwidth, u8>
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));
sourcepub const fn set_bandwidth(self, bw: FskBandwidth) -> FskModParams
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);
sourcepub const fn fdev(&self) -> FskFdev
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);
sourcepub const fn set_fdev(self, fdev: FskFdev) -> FskModParams
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);
sourcepub const fn is_valid(&self, ppm: u8) -> bool
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));
sourcepub const fn is_valid_worst_case(&self) -> bool
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.
sourcepub const fn as_slice(&self) -> &[u8]
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
impl Clone for FskModParams
source§fn clone(&self) -> FskModParams
fn clone(&self) -> FskModParams
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for FskModParams
impl Debug for FskModParams
source§impl Default for FskModParams
impl Default for FskModParams
source§impl PartialEq for FskModParams
impl PartialEq for FskModParams
source§fn eq(&self, other: &FskModParams) -> bool
fn eq(&self, other: &FskModParams) -> bool
self
and other
values to be equal, and is used
by ==
.