Skip to content
Open
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
25 changes: 19 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ where
}

/// Set Modem deviation setting.
pub fn set_deviation(&mut self, deviation: u64) -> Result<(), Error<SpiE>> {
pub fn set_deviation_hz(&mut self, deviation: u64) -> Result<(), Error<SpiE>> {
let (mantissa, exponent) = from_deviation(deviation);
self.0.write_register(
Config::DEVIATN,
Expand Down Expand Up @@ -352,8 +352,8 @@ where
}

/// Sets the channel bandwidth (in Hertz).
pub fn set_chanbw(&mut self, bandwidth: u64) -> Result<(), Error<SpiE>> {
let (mantissa, exponent) = from_chanbw(bandwidth);
pub fn set_channel_bandwidth(&mut self, bandwidth_hz: u64) -> Result<(), Error<SpiE>> {
let (mantissa, exponent) = from_chanbw(bandwidth_hz);
self.0.modify_register(Config::MDMCFG4, |r| {
MDMCFG4(r).modify().chanbw_m(mantissa).chanbw_e(exponent).bits()
})?;
Expand All @@ -366,10 +366,15 @@ where

let (mode, word) = match sync_mode {
SyncMode::Disabled => (SyncCheck::DISABLED, reset),
SyncMode::MatchPartial(word) => (SyncCheck::CHECK_15_16, word),
SyncMode::MatchPartialRepeated(word) => (SyncCheck::CHECK_30_32, word),
SyncMode::MatchFull(word) => (SyncCheck::CHECK_16_16, word),
SyncMode::Match15of16(w) => (SyncCheck::CHECK_15_16, w),
SyncMode::Match16of16(w) => (SyncCheck::CHECK_16_16, w),
SyncMode::Match30of32(w) => (SyncCheck::CHECK_30_32, w),
SyncMode::CarrierSenseOnly => (SyncCheck::CHECK_0_0_CS, reset),
SyncMode::Match15of16Cs(w) => (SyncCheck::CHECK_15_16_CS, w),
SyncMode::Match16of16Cs(w) => (SyncCheck::CHECK_16_16_CS, w),
SyncMode::Match30of32Cs(w) => (SyncCheck::CHECK_30_32_CS, w),
};

self.0.modify_register(Config::MDMCFG2, |r| {
MDMCFG2(r).modify().sync_mode(mode.into()).bits()
})?;
Expand All @@ -378,6 +383,14 @@ where
Ok(())
}

/// Sets the Manchester encoding mode.
pub fn set_manchester_encoding(&mut self, enable: bool) -> Result<(), Error<SpiE>> {
self.0.modify_register(Config::MDMCFG2, |r| {
MDMCFG2(r).modify().manchester_en(enable as u8).bits()
})?;
Ok(())
}

/// Set the modulation format of the radio signal.
pub fn set_modulation_format(
&mut self,
Expand Down
22 changes: 15 additions & 7 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ pub enum AddressFilter {
/// Sync word configuration.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum SyncMode {
/// No sync word.
/// No sync word, no carrier sense.
Disabled,
/// Match 15 of 16 bits of given sync word.
MatchPartial(u16),
/// Match 30 of 32 bits of a repetition of given sync word.
MatchPartialRepeated(u16),
/// Match 16 of 16 bits of given sync word.
MatchFull(u16),
/// Require 15 of 16 sync bits to match.
Match15of16(u16),
/// Require all 16 sync bits to match.
Match16of16(u16),
/// Require 30 of 32 sync bits (two repeated sync words).
Match30of32(u16),
/// No sync, but require carrier sense above threshold.
CarrierSenseOnly,
/// 15 of 16 sync bits + carrier sense.
Match15of16Cs(u16),
/// 16 of 16 sync bits + carrier sense.
Match16of16Cs(u16),
/// 30 of 32 sync bits + carrier sense.
Match30of32Cs(u16),
}