From 5f0cfa9bf62fb6d25ed61c2e54c2af3414847ac9 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sun, 2 Apr 2023 21:01:13 +0200 Subject: [PATCH] [SX126x] Improved RNG --- src/modules/SX126x/SX126x.cpp | 8 ++++++++ src/modules/SX126x/SX126x.h | 16 ++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 44f95a1a..e00bea5e 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -1391,6 +1391,10 @@ int16_t SX126x::autoLDRO() { } uint8_t SX126x::randomByte() { + // set some magic registers + _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_LNA, RADIOLIB_SX126X_LNA_RNG_ENABLED, 0, 0); + _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_MIXER, RADIOLIB_SX126X_MIXER_RNG_ENABLED, 0, 0); + // set mode to Rx setRx(RADIOLIB_SX126X_RX_TIMEOUT_INF); @@ -1408,6 +1412,10 @@ uint8_t SX126x::randomByte() { // set mode to standby standby(); + // restore the magic registers + _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_LNA, RADIOLIB_SX126X_LNA_RNG_DISABLED, 0, 0); + _mod->SPIsetRegValue(RADIOLIB_SX126X_REG_ANA_MIXER, RADIOLIB_SX126X_MIXER_RNG_DISABLED, 0, 0); + return(randByte); } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 2fb142bd..a19c7248 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -114,6 +114,7 @@ #define RADIOLIB_SX126X_REG_BROADCAST_ADDRESS 0x06CE #define RADIOLIB_SX126X_REG_PAYLOAD_LENGTH 0x0702 #define RADIOLIB_SX126X_REG_PACKET_PARAMS 0x0704 +#define RADIOLIB_SX126X_REG_LORA_SYNC_TIMEOUT 0x0706 #define RADIOLIB_SX126X_REG_IQ_CONFIG 0x0736 #define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_MSB 0x0740 #define RADIOLIB_SX126X_REG_LORA_SYNC_WORD_LSB 0x0741 @@ -132,8 +133,10 @@ #define RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW 0x089B #define RADIOLIB_SX126X_REG_RX_GAIN 0x08AC #define RADIOLIB_SX126X_REG_TX_CLAMP_CONFIG 0x08D8 +#define RADIOLIB_SX126X_REG_ANA_LNA 0x08E2 #define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_N 0x08E3 #define RADIOLIB_SX126X_REG_LNA_CAP_TUNE_P 0x08E4 +#define RADIOLIB_SX126X_REG_ANA_MIXER 0x08E5 #define RADIOLIB_SX126X_REG_OCP_CONFIGURATION 0x08E7 #define RADIOLIB_SX126X_REG_RTC_CTRL 0x0902 #define RADIOLIB_SX126X_REG_XTA_TRIM 0x0911 @@ -419,8 +422,17 @@ #define RADIOLIB_SX126X_SPECTRAL_SCAN_COMPLETED 0xFF // 7 0 completed // RADIOLIB_SX126X_REG_RSSI_AVG_WINDOW -#define RADIOLIB_SX126x_SPECTRAL_SCAN_WINDOW_DEFAULT (0x05 << 2) // 7 0 default RSSI average window +#define RADIOLIB_SX126X_SPECTRAL_SCAN_WINDOW_DEFAULT (0x05 << 2) // 7 0 default RSSI average window +// RADIOLIB_SX126X_REG_ANA_LNA +#define RADIOLIB_SX126X_LNA_RNG_DISABLED 0b00000001 // 0 0 random number: disabled +#define RADIOLIB_SX126X_LNA_RNG_ENABLED 0b00000000 // 0 0 enabled + +// RADIOLIB_SX126X_REG_ANA_MIXER +#define RADIOLIB_SX126X_MIXER_RNG_DISABLED 0b00000001 // 7 7 random number: disabled +#define RADIOLIB_SX126X_MIXER_RNG_ENABLED 0b00000000 // 7 7 enabled + +// size of the spectral scan result #define RADIOLIB_SX126X_SPECTRAL_SCAN_RES_SIZE (33) /*! @@ -1089,7 +1101,7 @@ class SX126x: public PhysicalLayer { \returns \ref status_codes */ - int16_t spectralScanStart(uint16_t numSamples, uint8_t window = RADIOLIB_SX126x_SPECTRAL_SCAN_WINDOW_DEFAULT, uint8_t interval = RADIOLIB_SX126X_SCAN_INTERVAL_8_20_US); + int16_t spectralScanStart(uint16_t numSamples, uint8_t window = RADIOLIB_SX126X_SPECTRAL_SCAN_WINDOW_DEFAULT, uint8_t interval = RADIOLIB_SX126X_SCAN_INTERVAL_8_20_US); /*! \brief Abort an ongoing spectral scan.