diff options
| author | Daniel Bevenius <[email protected]> | 2022-06-15 14:53:07 +0200 |
|---|---|---|
| committer | Daniel Bevenius <[email protected]> | 2022-06-15 16:21:52 +0200 |
| commit | 06a76cd7ce2b0afbd35c822f9587fee7bca05590 (patch) | |
| tree | d55fd5138070cd708773d6470b8601f1fd652bf0 /embassy-lora/src | |
| parent | 03c20604c39d622b28c0070e5a95b9fbfb7a8f8a (diff) | |
Extract setting of lora modulation params
This commit suggests extracting the lora modulation parameters into a
separate function which can then be called from both the do_tx, and
the do_rx functions.
Diffstat (limited to 'embassy-lora/src')
| -rw-r--r-- | embassy-lora/src/stm32wl/mod.rs | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/embassy-lora/src/stm32wl/mod.rs b/embassy-lora/src/stm32wl/mod.rs index 5f3dc17a7..d7d399692 100644 --- a/embassy-lora/src/stm32wl/mod.rs +++ b/embassy-lora/src/stm32wl/mod.rs | |||
| @@ -8,9 +8,9 @@ use embassy_stm32::dma::NoDma; | |||
| 8 | use embassy_stm32::gpio::{AnyPin, Output}; | 8 | use embassy_stm32::gpio::{AnyPin, Output}; |
| 9 | use embassy_stm32::interrupt::{InterruptExt, SUBGHZ_RADIO}; | 9 | use embassy_stm32::interrupt::{InterruptExt, SUBGHZ_RADIO}; |
| 10 | use embassy_stm32::subghz::{ | 10 | use embassy_stm32::subghz::{ |
| 11 | CalibrateImage, CfgIrq, CodingRate, HeaderType, Irq, LoRaBandwidth, LoRaModParams, LoRaPacketParams, LoRaSyncWord, | 11 | CalibrateImage, CfgIrq, CodingRate, Error, HeaderType, Irq, LoRaBandwidth, LoRaModParams, LoRaPacketParams, |
| 12 | Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode, RfFreq, SpreadingFactor as SF, StandbyClk, Status, SubGhz, | 12 | LoRaSyncWord, Ocp, PaConfig, PaSel, PacketType, RampTime, RegMode, RfFreq, SpreadingFactor as SF, StandbyClk, |
| 13 | TcxoMode, TcxoTrim, Timeout, TxParams, | 13 | Status, SubGhz, TcxoMode, TcxoTrim, Timeout, TxParams, |
| 14 | }; | 14 | }; |
| 15 | use embassy_stm32::Unborrow; | 15 | use embassy_stm32::Unborrow; |
| 16 | use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; | 16 | use lorawan_device::async_device::radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig}; |
| @@ -128,12 +128,7 @@ impl<'a> StateInner<'a> { | |||
| 128 | self.radio | 128 | self.radio |
| 129 | .set_rf_frequency(&RfFreq::from_frequency(config.rf.frequency))?; | 129 | .set_rf_frequency(&RfFreq::from_frequency(config.rf.frequency))?; |
| 130 | 130 | ||
| 131 | let mod_params = LoRaModParams::new() | 131 | self.set_lora_mod_params(config.rf)?; |
| 132 | .set_sf(convert_spreading_factor(config.rf.spreading_factor)) | ||
| 133 | .set_bw(convert_bandwidth(config.rf.bandwidth)) | ||
| 134 | .set_cr(CodingRate::Cr45) | ||
| 135 | .set_ldro_en(true); | ||
| 136 | self.radio.set_lora_mod_params(&mod_params)?; | ||
| 137 | 132 | ||
| 138 | let packet_params = LoRaPacketParams::new() | 133 | let packet_params = LoRaPacketParams::new() |
| 139 | .set_preamble_len(8) | 134 | .set_preamble_len(8) |
| @@ -177,6 +172,15 @@ impl<'a> StateInner<'a> { | |||
| 177 | } | 172 | } |
| 178 | } | 173 | } |
| 179 | 174 | ||
| 175 | fn set_lora_mod_params(&mut self, config: RfConfig) -> Result<(), Error> { | ||
| 176 | let mod_params = LoRaModParams::new() | ||
| 177 | .set_sf(convert_spreading_factor(config.spreading_factor)) | ||
| 178 | .set_bw(convert_bandwidth(config.bandwidth)) | ||
| 179 | .set_cr(CodingRate::Cr45) | ||
| 180 | .set_ldro_en(true); | ||
| 181 | self.radio.set_lora_mod_params(&mod_params) | ||
| 182 | } | ||
| 183 | |||
| 180 | /// Perform a radio receive operation with the radio config and receive buffer. The receive buffer must | 184 | /// Perform a radio receive operation with the radio config and receive buffer. The receive buffer must |
| 181 | /// be able to hold a single LoRaWAN packet. | 185 | /// be able to hold a single LoRaWAN packet. |
| 182 | async fn do_rx(&mut self, config: RfConfig, buf: &mut [u8]) -> Result<(usize, RxQuality), RadioError> { | 186 | async fn do_rx(&mut self, config: RfConfig, buf: &mut [u8]) -> Result<(usize, RxQuality), RadioError> { |
| @@ -188,12 +192,7 @@ impl<'a> StateInner<'a> { | |||
| 188 | 192 | ||
| 189 | self.radio.set_rf_frequency(&RfFreq::from_frequency(config.frequency))?; | 193 | self.radio.set_rf_frequency(&RfFreq::from_frequency(config.frequency))?; |
| 190 | 194 | ||
| 191 | let mod_params = LoRaModParams::new() | 195 | self.set_lora_mod_params(config)?; |
| 192 | .set_sf(convert_spreading_factor(config.spreading_factor)) | ||
| 193 | .set_bw(convert_bandwidth(config.bandwidth)) | ||
| 194 | .set_cr(CodingRate::Cr45) | ||
| 195 | .set_ldro_en(true); | ||
| 196 | self.radio.set_lora_mod_params(&mod_params)?; | ||
| 197 | 196 | ||
| 198 | let packet_params = LoRaPacketParams::new() | 197 | let packet_params = LoRaPacketParams::new() |
| 199 | .set_preamble_len(8) | 198 | .set_preamble_len(8) |
