From 811e1054c63f23583a09c9bb758324a06470af93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Papierski?= Date: Fri, 29 Aug 2025 15:21:21 +0200 Subject: [PATCH] More extensive sync modes. This commit adds more SyncMode options for enabling no preamble/sync with carrier-sense above threshold. Additionally within the same register, this commit adds an option to enable manchester encoding. There are some small changes for method names that deal with units (i.e. set_channel_bandwidth(bandwidth_hz) instead of setchanbw(bandwidth)) --- src/lib.rs | 25 +++++++++++++++++++------ src/types.rs | 22 +++++++++++++++------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e23c729..4db9ba0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -309,7 +309,7 @@ where } /// Set Modem deviation setting. - pub fn set_deviation(&mut self, deviation: u64) -> Result<(), Error> { + pub fn set_deviation_hz(&mut self, deviation: u64) -> Result<(), Error> { let (mantissa, exponent) = from_deviation(deviation); self.0.write_register( Config::DEVIATN, @@ -352,8 +352,8 @@ where } /// Sets the channel bandwidth (in Hertz). - pub fn set_chanbw(&mut self, bandwidth: u64) -> Result<(), Error> { - let (mantissa, exponent) = from_chanbw(bandwidth); + pub fn set_channel_bandwidth(&mut self, bandwidth_hz: u64) -> Result<(), Error> { + let (mantissa, exponent) = from_chanbw(bandwidth_hz); self.0.modify_register(Config::MDMCFG4, |r| { MDMCFG4(r).modify().chanbw_m(mantissa).chanbw_e(exponent).bits() })?; @@ -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() })?; @@ -378,6 +383,14 @@ where Ok(()) } + /// Sets the Manchester encoding mode. + pub fn set_manchester_encoding(&mut self, enable: bool) -> Result<(), Error> { + 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, diff --git a/src/types.rs b/src/types.rs index fdb3bb9..a3766db 100644 --- a/src/types.rs +++ b/src/types.rs @@ -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), }