From 3478d908196469ee34461365e2f5c107651e8dae Mon Sep 17 00:00:00 2001 From: jgromes Date: Thu, 4 Jan 2024 18:21:35 +0100 Subject: [PATCH] [SX126x] Improved image calibration --- src/modules/SX126x/SX1262.cpp | 21 ++------------------- src/modules/SX126x/SX1268.cpp | 15 ++------------- src/modules/SX126x/SX126x.h | 14 +------------- 3 files changed, 5 insertions(+), 45 deletions(-) diff --git a/src/modules/SX126x/SX1262.cpp b/src/modules/SX126x/SX1262.cpp index d24e0f43..b6f68cb4 100644 --- a/src/modules/SX126x/SX1262.cpp +++ b/src/modules/SX126x/SX1262.cpp @@ -54,26 +54,9 @@ int16_t SX1262::setFrequency(float freq) { int16_t SX1262::setFrequency(float freq, bool calibrate) { RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, RADIOLIB_ERR_INVALID_FREQUENCY); - // calibrate image + // calibrate image rejection - assume band to be the selected frequency +- 4 MHz if(calibrate) { - uint8_t data[2]; - if(freq > 900.0) { - data[0] = RADIOLIB_SX126X_CAL_IMG_902_MHZ_1; - data[1] = RADIOLIB_SX126X_CAL_IMG_902_MHZ_2; - } else if(freq > 850.0) { - data[0] = RADIOLIB_SX126X_CAL_IMG_863_MHZ_1; - data[1] = RADIOLIB_SX126X_CAL_IMG_863_MHZ_2; - } else if(freq > 770.0) { - data[0] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_1; - data[1] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_2; - } else if(freq > 460.0) { - data[0] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_1; - data[1] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_2; - } else { - data[0] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_1; - data[1] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_2; - } - int16_t state = SX126x::calibrateImage(data); + int16_t state = SX126x::calibrateImage(freq - 4, freq + 4); RADIOLIB_ASSERT(state); } diff --git a/src/modules/SX126x/SX1268.cpp b/src/modules/SX126x/SX1268.cpp index 596ce7e4..8aad25b7 100644 --- a/src/modules/SX126x/SX1268.cpp +++ b/src/modules/SX126x/SX1268.cpp @@ -55,20 +55,9 @@ int16_t SX1268::setFrequency(float freq) { int16_t SX1268::setFrequency(float freq, bool calibrate) { RADIOLIB_CHECK_RANGE(freq, 410.0, 810.0, RADIOLIB_ERR_INVALID_FREQUENCY); - // calibrate image + // calibrate image rejection - assume band to be the selected frequency +- 4 MHz if(calibrate) { - uint8_t data[2]; - if(freq > 770.0) { - data[0] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_1; - data[1] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_2; - } else if(freq > 460.0) { - data[0] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_1; - data[1] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_2; - } else { - data[0] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_1; - data[1] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_2; - } - int16_t state = SX126x::calibrateImage(data); + int16_t state = SX126x::calibrateImage(freq - 4, freq + 4); RADIOLIB_ASSERT(state); } diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 5e8c03b6..2fb3fdb4 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -188,18 +188,6 @@ #define RADIOLIB_SX126X_CALIBRATE_RC64K_ON 0b00000001 // 0 0 enabled #define RADIOLIB_SX126X_CALIBRATE_ALL 0b01111111 // 6 0 calibrate all blocks -//RADIOLIB_SX126X_CMD_CALIBRATE_IMAGE -#define RADIOLIB_SX126X_CAL_IMG_430_MHZ_1 0x6B -#define RADIOLIB_SX126X_CAL_IMG_430_MHZ_2 0x6F -#define RADIOLIB_SX126X_CAL_IMG_470_MHZ_1 0x75 -#define RADIOLIB_SX126X_CAL_IMG_470_MHZ_2 0x81 -#define RADIOLIB_SX126X_CAL_IMG_779_MHZ_1 0xC1 -#define RADIOLIB_SX126X_CAL_IMG_779_MHZ_2 0xC5 -#define RADIOLIB_SX126X_CAL_IMG_863_MHZ_1 0xD7 -#define RADIOLIB_SX126X_CAL_IMG_863_MHZ_2 0xDB -#define RADIOLIB_SX126X_CAL_IMG_902_MHZ_1 0xE1 -#define RADIOLIB_SX126X_CAL_IMG_902_MHZ_2 0xE9 - //RADIOLIB_SX126X_CMD_SET_PA_CONFIG #define RADIOLIB_SX126X_PA_CONFIG_HP_MAX 0x07 #define RADIOLIB_SX126X_PA_CONFIG_PA_LUT 0x01 @@ -1119,7 +1107,7 @@ class SX126x: public PhysicalLayer { int16_t setDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask = RADIOLIB_SX126X_IRQ_NONE, uint16_t dio3Mask = RADIOLIB_SX126X_IRQ_NONE); virtual int16_t clearIrqStatus(uint16_t clearIrqParams = RADIOLIB_SX126X_IRQ_ALL); int16_t setRfFrequency(uint32_t frf); - int16_t calibrateImage(uint8_t* data); + int16_t calibrateImage(float freqMin, float freqMax); uint8_t getPacketType(); int16_t setTxParams(uint8_t power, uint8_t rampTime = RADIOLIB_SX126X_PA_RAMP_200U); int16_t setModulationParams(uint8_t sf, uint8_t bw, uint8_t cr, uint8_t ldro);