From d90b0d3197a2eeee9964dc421bd4f1e6898aa729 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Thu, 5 Oct 2023 12:03:22 +0300 Subject: [PATCH] sx127x: Implement Tcxo configuration --- src/sx1276_7_8_9/mod.rs | 13 ++++++++++++- src/sx1276_7_8_9/radio_kind_params.rs | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/sx1276_7_8_9/mod.rs b/src/sx1276_7_8_9/mod.rs index 278c178..454f769 100644 --- a/src/sx1276_7_8_9/mod.rs +++ b/src/sx1276_7_8_9/mod.rs @@ -32,6 +32,8 @@ pub enum Sx127xVariant { pub struct Config { /// LoRa chip used on specific board pub chip: Sx127xVariant, + /// Whether board is using crystal oscillator or external clock + pub tcxo_used: bool, } /// Base for the RadioKind implementation for the LoRa chip kind and board type @@ -277,7 +279,16 @@ where } async fn set_oscillator(&mut self) -> Result<(), RadioError> { - self.write_register(Register::RegTcxo, TCXO_FOR_OSCILLATOR, false).await + if !self.config.tcxo_used { + return Ok(()); + } + + // Configure Tcxo as input + let reg = match self.config.chip { + Sx127xVariant::Sx1272 => Register::RegTcxoSX1272, + Sx127xVariant::Sx1276_7_8_9 => Register::RegTcxoSX1276, + }; + self.write_register(reg, TCXO_FOR_OSCILLATOR, false).await } async fn set_regulator_mode(&mut self) -> Result<(), RadioError> { diff --git a/src/sx1276_7_8_9/radio_kind_params.rs b/src/sx1276_7_8_9/radio_kind_params.rs index 9346445..c61ed0d 100644 --- a/src/sx1276_7_8_9/radio_kind_params.rs +++ b/src/sx1276_7_8_9/radio_kind_params.rs @@ -101,9 +101,10 @@ pub enum Register { RegInvertiq2 = 0x3b, RegDioMapping1 = 0x40, RegVersion = 0x42, - RegTcxo = 0x4b, RegPaDacSX1272 = 0x5a, RegPaDacSX1276 = 0x4d, + RegTcxoSX1276 = 0x4b, + RegTcxoSX1272 = 0x58, } impl Register {