[SX128x] Minor formatting update

This commit is contained in:
jgromes 2022-02-28 18:47:55 +01:00
parent 84c086eeac
commit 64817ed4be
2 changed files with 74 additions and 69 deletions

View file

@ -1021,22 +1021,24 @@ int16_t SX128x::setAccessAddress(uint32_t addr) {
}
int16_t SX128x::setHighSensitivityMode(bool hsm) {
// update register
// read the current registers
uint8_t RxGain = 0;
int16_t state = readRegister(RADIOLIB_SX128X_REG_GAIN_MODE, &RxGain, 1);
RADIOLIB_ASSERT(state);
if(hsm) {
RxGain |= 0xC0; // Set bits 6 and 7
} else {
RxGain &= ~0xC0; // Unset bits 6 and 7
}
// update all values
state = writeRegister(RADIOLIB_SX128X_REG_GAIN_MODE, &RxGain, 1);
RADIOLIB_ASSERT(state);
return(0);
return(state);
}
int16_t SX128x::setGainControl(uint8_t gain) {
// update registers
// read the current registers
uint8_t ManualGainSetting = 0;
int16_t state = readRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2, &ManualGainSetting, 1);
RADIOLIB_ASSERT(state);
@ -1046,6 +1048,8 @@ int16_t SX128x::setGainControl(uint8_t gain) {
uint8_t LNAGainControl = 0;
state = readRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_1, &LNAGainControl, 1);
RADIOLIB_ASSERT(state);
// set the gain
if (gain > 0 && gain < 14) {
// Set manual gain
ManualGainSetting &= ~0x01; // Set bit 0 to 0 (Enable Manual Gain Control)
@ -1059,13 +1063,14 @@ int16_t SX128x::setGainControl(uint8_t gain) {
LNAGainValue |= 0x0A; // Set bits 0, 1, 2 and 3 to Manual Gain Setting (1-13)
LNAGainControl &= ~0x80; // Set bit 7 to 0 (Enable Automatic Gain Control)
}
// update all values
state = writeRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2, &ManualGainSetting, 1);
RADIOLIB_ASSERT(state);
state = writeRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_SETTING, &LNAGainValue, 1);
RADIOLIB_ASSERT(state);
state = writeRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_1, &LNAGainControl, 1);
RADIOLIB_ASSERT(state);
return(0);
return(state);
}
float SX128x::getRSSI() {
@ -1119,8 +1124,8 @@ float SX128x::getFrequencyError() {
return(0.0);
}
uint8_t efeRaw[3] = {0};
// read the raw frequency error register values
uint8_t efeRaw[3] = {0};
int16_t state = readRegister(RADIOLIB_SX128X_REG_FEI_MSB, &efeRaw[0], 1);
RADIOLIB_ASSERT(state);
state = readRegister(RADIOLIB_SX128X_REG_FEI_MID, &efeRaw[1], 1);
@ -1130,7 +1135,7 @@ float SX128x::getFrequencyError() {
uint32_t efe = ((uint32_t) efeRaw[0] << 16) | ((uint32_t) efeRaw[1] << 8) | efeRaw[2];
efe &= 0x0FFFFF;
float error;
float error = 0;
// check the first bit
if (efe & 0x80000) {

View file

@ -725,7 +725,7 @@ class SX128x: public PhysicalLayer {
/*!
\brief Enables or disables receiver manual gain control.
\param Gain 0 automatic gain; 1 minimum gain to 13 maximum gain.
\param gain Use 0 for automatic gain, 1 for minimum gain and up to 13 for maximum gain.
\returns 0
*/