[SX128x] Minor formatting update
This commit is contained in:
parent
84c086eeac
commit
64817ed4be
2 changed files with 74 additions and 69 deletions
|
@ -1021,51 +1021,56 @@ int16_t SX128x::setAccessAddress(uint32_t addr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t SX128x::setHighSensitivityMode(bool hsm) {
|
int16_t SX128x::setHighSensitivityMode(bool hsm) {
|
||||||
// update register
|
// read the current registers
|
||||||
uint8_t RxGain = 0;
|
uint8_t RxGain = 0;
|
||||||
int16_t state = readRegister(RADIOLIB_SX128X_REG_GAIN_MODE, &RxGain, 1);
|
int16_t state = readRegister(RADIOLIB_SX128X_REG_GAIN_MODE, &RxGain, 1);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
if (hsm) {
|
|
||||||
RxGain |= 0xC0; // Set bits 6 and 7
|
if(hsm) {
|
||||||
} else {
|
RxGain |= 0xC0; // Set bits 6 and 7
|
||||||
RxGain &= ~0xC0; // Unset bits 6 and 7
|
} else {
|
||||||
}
|
RxGain &= ~0xC0; // Unset bits 6 and 7
|
||||||
state = writeRegister(RADIOLIB_SX128X_REG_GAIN_MODE, &RxGain, 1);
|
}
|
||||||
RADIOLIB_ASSERT(state);
|
|
||||||
return(0);
|
// update all values
|
||||||
|
state = writeRegister(RADIOLIB_SX128X_REG_GAIN_MODE, &RxGain, 1);
|
||||||
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t SX128x::setGainControl(uint8_t gain) {
|
int16_t SX128x::setGainControl(uint8_t gain) {
|
||||||
// update registers
|
// read the current registers
|
||||||
uint8_t ManualGainSetting = 0;
|
uint8_t ManualGainSetting = 0;
|
||||||
int16_t state = readRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2, &ManualGainSetting, 1);
|
int16_t state = readRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2, &ManualGainSetting, 1);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
uint8_t LNAGainValue = 0;
|
uint8_t LNAGainValue = 0;
|
||||||
state = readRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_SETTING, &LNAGainValue, 1);
|
state = readRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_SETTING, &LNAGainValue, 1);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
uint8_t LNAGainControl = 0;
|
uint8_t LNAGainControl = 0;
|
||||||
state = readRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_1, &LNAGainControl, 1);
|
state = readRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_1, &LNAGainControl, 1);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
if (gain > 0 && gain < 14) {
|
|
||||||
// Set manual gain
|
// set the gain
|
||||||
ManualGainSetting &= ~0x01; // Set bit 0 to 0 (Enable Manual Gain Control)
|
if (gain > 0 && gain < 14) {
|
||||||
LNAGainValue &= 0xF0; // Bits 0, 1, 2 and 3 to 0
|
// Set manual gain
|
||||||
LNAGainValue |= gain; // Set bits 0, 1, 2 and 3 to Manual Gain Setting (1-13)
|
ManualGainSetting &= ~0x01; // Set bit 0 to 0 (Enable Manual Gain Control)
|
||||||
LNAGainControl |= 0x80; // Set bit 7 to 1 (Enable Manual Gain Control)
|
LNAGainValue &= 0xF0; // Bits 0, 1, 2 and 3 to 0
|
||||||
} else {
|
LNAGainValue |= gain; // Set bits 0, 1, 2 and 3 to Manual Gain Setting (1-13)
|
||||||
// Set automatic gain if 0 or out of range
|
LNAGainControl |= 0x80; // Set bit 7 to 1 (Enable Manual Gain Control)
|
||||||
ManualGainSetting |= 0x01; // Set bit 0 to 1 (Enable Automatic Gain Control)
|
} else {
|
||||||
LNAGainValue &= 0xF0; // Bits 0, 1, 2 and 3 to 0
|
// Set automatic gain if 0 or out of range
|
||||||
LNAGainValue |= 0x0A; // Set bits 0, 1, 2 and 3 to Manual Gain Setting (1-13)
|
ManualGainSetting |= 0x01; // Set bit 0 to 1 (Enable Automatic Gain Control)
|
||||||
LNAGainControl &= ~0x80; // Set bit 7 to 0 (Enable Automatic Gain Control)
|
LNAGainValue &= 0xF0; // Bits 0, 1, 2 and 3 to 0
|
||||||
}
|
LNAGainValue |= 0x0A; // Set bits 0, 1, 2 and 3 to Manual Gain Setting (1-13)
|
||||||
state = writeRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2, &ManualGainSetting, 1);
|
LNAGainControl &= ~0x80; // Set bit 7 to 0 (Enable Automatic Gain Control)
|
||||||
RADIOLIB_ASSERT(state);
|
}
|
||||||
state = writeRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_SETTING, &LNAGainValue, 1);
|
|
||||||
RADIOLIB_ASSERT(state);
|
// update all values
|
||||||
state = writeRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_1, &LNAGainControl, 1);
|
state = writeRegister(RADIOLIB_SX128X_REG_MANUAL_GAIN_CONTROL_ENABLE_2, &ManualGainSetting, 1);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
return(0);
|
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);
|
||||||
|
return(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
float SX128x::getRSSI() {
|
float SX128x::getRSSI() {
|
||||||
|
@ -1113,36 +1118,36 @@ float SX128x::getSNR() {
|
||||||
}
|
}
|
||||||
|
|
||||||
float SX128x::getFrequencyError() {
|
float SX128x::getFrequencyError() {
|
||||||
// check active modem
|
// check active modem
|
||||||
uint8_t modem = getPacketType();
|
uint8_t modem = getPacketType();
|
||||||
if (!((modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) || (modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING))) {
|
if(!((modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) || (modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING))) {
|
||||||
return (0.0);
|
return(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t efeRaw[3] = {0};
|
// read the raw frequency error register values
|
||||||
// read the raw frequency error register values
|
uint8_t efeRaw[3] = {0};
|
||||||
int16_t state = readRegister(RADIOLIB_SX128X_REG_FEI_MSB, &efeRaw[0], 1);
|
int16_t state = readRegister(RADIOLIB_SX128X_REG_FEI_MSB, &efeRaw[0], 1);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
state = readRegister(RADIOLIB_SX128X_REG_FEI_MID, &efeRaw[1], 1);
|
state = readRegister(RADIOLIB_SX128X_REG_FEI_MID, &efeRaw[1], 1);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
state = readRegister(RADIOLIB_SX128X_REG_FEI_LSB, &efeRaw[2], 1);
|
state = readRegister(RADIOLIB_SX128X_REG_FEI_LSB, &efeRaw[2], 1);
|
||||||
RADIOLIB_ASSERT(state);
|
RADIOLIB_ASSERT(state);
|
||||||
uint32_t efe = ((uint32_t) efeRaw[0] << 16) | ((uint32_t) efeRaw[1] << 8) | efeRaw[2];
|
uint32_t efe = ((uint32_t) efeRaw[0] << 16) | ((uint32_t) efeRaw[1] << 8) | efeRaw[2];
|
||||||
efe &= 0x0FFFFF;
|
efe &= 0x0FFFFF;
|
||||||
|
|
||||||
float error;
|
float error = 0;
|
||||||
|
|
||||||
// check the first bit
|
// check the first bit
|
||||||
if (efe & 0x80000) {
|
if (efe & 0x80000) {
|
||||||
// frequency error is negative
|
// frequency error is negative
|
||||||
efe |= (uint32_t) 0xFFF00000;
|
efe |= (uint32_t) 0xFFF00000;
|
||||||
efe = ~efe + 1;
|
efe = ~efe + 1;
|
||||||
error = 1.55 * (float) efe / (1600.0 / (float) _bwKhz) * -1.0;
|
error = 1.55 * (float) efe / (1600.0 / (float) _bwKhz) * -1.0;
|
||||||
} else {
|
} else {
|
||||||
error = 1.55 * (float) efe / (1600.0 / (float) _bwKhz);
|
error = 1.55 * (float) efe / (1600.0 / (float) _bwKhz);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (error);
|
return(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t SX128x::getPacketLength(bool update) {
|
size_t SX128x::getPacketLength(bool update) {
|
||||||
|
|
|
@ -725,7 +725,7 @@ class SX128x: public PhysicalLayer {
|
||||||
/*!
|
/*!
|
||||||
\brief Enables or disables receiver manual gain control.
|
\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
|
\returns 0
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue