From 0dee956d2bd81f6b5e064d30788d4db2b3cc30b4 Mon Sep 17 00:00:00 2001 From: shakencodes Date: Mon, 25 Sep 2023 12:16:28 -0700 Subject: [PATCH 1/6] Add continuous_wave function --- src/lib.rs | 9 +++++++++ src/mod_traits.rs | 2 ++ src/sx1261_2/mod.rs | 5 +++++ src/sx1276_7_8_9/mod.rs | 11 +++++++++++ 4 files changed, 27 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 94f8d7c..43fa5c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -367,6 +367,15 @@ where } } } + + /// Place radio in continuous wave mode, generally for regulatory testing + /// + /// SemTech app note AN1200.26 “Semtech LoRa FCC 15.247 Guidance” covers usage. + /// + /// Presumes that init() and prepare_for_tx() are called before this function + pub async fn continuous_wave(&mut self) -> Result<(), RadioError> { + self.radio_kind.set_tx_continuous_wave_mode().await + } } impl AsyncRng for LoRa diff --git a/src/mod_traits.rs b/src/mod_traits.rs index 974945a..2fa8a73 100644 --- a/src/mod_traits.rs +++ b/src/mod_traits.rs @@ -126,6 +126,8 @@ pub trait RadioKind { polling_timeout_in_ms: Option, cad_activity_detected: Option<&mut bool>, ) -> Result<(), RadioError>; + /// Set the LoRa chip into the TxContinuousWave mode + async fn set_tx_continuous_wave_mode(&mut self) -> Result<(), RadioError>; } /// Internal trait for specifying that a [`RadioKind`] object has RNG capability. diff --git a/src/sx1261_2/mod.rs b/src/sx1261_2/mod.rs index b6dd360..6205679 100644 --- a/src/sx1261_2/mod.rs +++ b/src/sx1261_2/mod.rs @@ -947,6 +947,11 @@ where // if an interrupt occurred for other than an error or operation completion, loop to wait again } } + + async fn set_tx_continuous_wave_mode(&mut self) -> Result<(), RadioError> { + let op_code = [OpCode::SetTxContinuousWave.value()]; + self.intf.write(&[&op_code], false).await + } } impl crate::RngRadio for SX1261_2 diff --git a/src/sx1276_7_8_9/mod.rs b/src/sx1276_7_8_9/mod.rs index 401323c..7dc2137 100644 --- a/src/sx1276_7_8_9/mod.rs +++ b/src/sx1276_7_8_9/mod.rs @@ -606,4 +606,15 @@ where // if an interrupt occurred for other than an error or operation completion, loop to wait again } } + /// Set the LoRa chip into the TxContinuousWave mode + async fn set_tx_continuous_wave_mode(&mut self) -> Result<(), RadioError> { + let pa_config = self.read_register(Register::RegPaConfig).await?; + let new_pa_config = pa_config | 0b1000_0000; + self.write_register(Register::RegPaConfig, new_pa_config, false).await?; + self.write_register(Register::RegOpMode, 0b1100_0011, false).await?; + let modem_config = self.read_register(Register::RegModemConfig2).await?; + let new_modem_config = modem_config | 0b0000_1000; + self.write_register(Register::RegModemConfig2, new_modem_config, false) + .await + } } From 092a7cc29994ffed1d6f1c8be24a7041c6525e93 Mon Sep 17 00:00:00 2001 From: shakencodes Date: Mon, 25 Sep 2023 12:28:51 -0700 Subject: [PATCH 2/6] Make continous_wave set its own parameters --- src/lib.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 43fa5c3..92edd13 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -373,7 +373,32 @@ where /// SemTech app note AN1200.26 “Semtech LoRa FCC 15.247 Guidance” covers usage. /// /// Presumes that init() and prepare_for_tx() are called before this function - pub async fn continuous_wave(&mut self) -> Result<(), RadioError> { + pub async fn continuous_wave( + &mut self, + mdltn_params: &ModulationParams, + output_power: i32, + tx_boosted_if_possible: bool, + ) -> Result<(), RadioError> { + self.rx_continuous = false; + self.radio_kind.ensure_ready(self.radio_mode).await?; + if self.radio_mode != RadioMode::Standby { + self.radio_kind.set_standby().await?; + self.radio_mode = RadioMode::Standby; + } + if self.cold_start { + self.do_cold_start().await?; + } + if self.calibrate_image { + self.radio_kind.calibrate_image(mdltn_params.frequency_in_hz).await?; + self.calibrate_image = false; + } + self.radio_kind.set_modulation_params(mdltn_params).await?; + self.radio_kind + .set_tx_power_and_ramp_time(output_power, Some(mdltn_params), tx_boosted_if_possible, true) + .await?; + self.radio_kind.set_channel(mdltn_params.frequency_in_hz).await?; + // self.radio_mode = RadioMode::Transmit; + // self.radio_kind.set_irq_params(Some(self.radio_mode)).await?; self.radio_kind.set_tx_continuous_wave_mode().await } } From cf6c289fdcb10780a62c4fb9470372e46a44972b Mon Sep 17 00:00:00 2001 From: shakencodes Date: Wed, 27 Sep 2023 15:29:35 -0700 Subject: [PATCH 3/6] Corrects a documentation error --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 92edd13..d75e9ed 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -372,7 +372,7 @@ where /// /// SemTech app note AN1200.26 “Semtech LoRa FCC 15.247 Guidance” covers usage. /// - /// Presumes that init() and prepare_for_tx() are called before this function + /// Presumes that init() is called before this function pub async fn continuous_wave( &mut self, mdltn_params: &ModulationParams, From 19270e5487b003f04d7424f3f12871c2913098de Mon Sep 17 00:00:00 2001 From: shakencodes Date: Wed, 27 Sep 2023 15:29:52 -0700 Subject: [PATCH 4/6] Enables TX line in continuous wave mode --- src/sx1261_2/mod.rs | 2 ++ src/sx1276_7_8_9/mod.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/src/sx1261_2/mod.rs b/src/sx1261_2/mod.rs index 6205679..2c360b8 100644 --- a/src/sx1261_2/mod.rs +++ b/src/sx1261_2/mod.rs @@ -949,6 +949,8 @@ where } async fn set_tx_continuous_wave_mode(&mut self) -> Result<(), RadioError> { + self.intf.iv.enable_rf_switch_tx().await?; + let op_code = [OpCode::SetTxContinuousWave.value()]; self.intf.write(&[&op_code], false).await } diff --git a/src/sx1276_7_8_9/mod.rs b/src/sx1276_7_8_9/mod.rs index 7dc2137..ebc203d 100644 --- a/src/sx1276_7_8_9/mod.rs +++ b/src/sx1276_7_8_9/mod.rs @@ -608,6 +608,7 @@ where } /// Set the LoRa chip into the TxContinuousWave mode async fn set_tx_continuous_wave_mode(&mut self) -> Result<(), RadioError> { + self.intf.iv.enable_rf_switch_rx().await?; let pa_config = self.read_register(Register::RegPaConfig).await?; let new_pa_config = pa_config | 0b1000_0000; self.write_register(Register::RegPaConfig, new_pa_config, false).await?; From 31d95879d46c1a5ec5d924ade1c293ccb3238f2f Mon Sep 17 00:00:00 2001 From: shakencodes Date: Wed, 27 Sep 2023 16:55:23 -0700 Subject: [PATCH 5/6] Set mode to transmit during continuous wave --- src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d75e9ed..61422ff 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -396,9 +396,16 @@ where self.radio_kind .set_tx_power_and_ramp_time(output_power, Some(mdltn_params), tx_boosted_if_possible, true) .await?; + + self.rx_continuous = false; + self.radio_kind.ensure_ready(self.radio_mode).await?; + if self.radio_mode != RadioMode::Standby { + self.radio_kind.set_standby().await?; + self.radio_mode = RadioMode::Standby; + } self.radio_kind.set_channel(mdltn_params.frequency_in_hz).await?; - // self.radio_mode = RadioMode::Transmit; - // self.radio_kind.set_irq_params(Some(self.radio_mode)).await?; + self.radio_mode = RadioMode::Transmit; + self.radio_kind.set_irq_params(Some(self.radio_mode)).await?; self.radio_kind.set_tx_continuous_wave_mode().await } } From 96b11aa838279b2da64cf03c35b273dce2a6d2d9 Mon Sep 17 00:00:00 2001 From: shakencodes Date: Tue, 10 Oct 2023 11:22:40 -0700 Subject: [PATCH 6/6] Set packet length in continuous wave. --- src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 61422ff..59e24b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -392,6 +392,10 @@ where self.radio_kind.calibrate_image(mdltn_params.frequency_in_hz).await?; self.calibrate_image = false; } + let tx_pkt_params = self + .radio_kind + .create_packet_params(0, false, 16, false, false, mdltn_params)?; + self.radio_kind.set_packet_params(&tx_pkt_params).await?; self.radio_kind.set_modulation_params(mdltn_params).await?; self.radio_kind .set_tx_power_and_ramp_time(output_power, Some(mdltn_params), tx_boosted_if_possible, true)