Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from Radiator-Labs/main
Browse files Browse the repository at this point in the history
Add support for Continuous Wave operation
  • Loading branch information
lucasgranberg authored Oct 16, 2023
2 parents fb96900 + 96b11aa commit 926b0e9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,51 @@ 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() is called before this function
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;
}
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)
.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_kind.set_tx_continuous_wave_mode().await
}
}

impl<RK, DLY> AsyncRng for LoRa<RK, DLY>
Expand Down
2 changes: 2 additions & 0 deletions src/mod_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub trait RadioKind {
polling_timeout_in_ms: Option<u32>,
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.
Expand Down
7 changes: 7 additions & 0 deletions src/sx1261_2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,13 @@ 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> {
self.intf.iv.enable_rf_switch_tx().await?;

let op_code = [OpCode::SetTxContinuousWave.value()];
self.intf.write(&[&op_code], false).await
}
}

impl<SPI, IV> crate::RngRadio for SX1261_2<SPI, IV>
Expand Down
12 changes: 12 additions & 0 deletions src/sx1276_7_8_9/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,4 +606,16 @@ 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> {
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?;
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
}
}

0 comments on commit 926b0e9

Please sign in to comment.