[SX126x] Implemeted device type string check
This commit is contained in:
parent
547a522826
commit
bd258380c8
8 changed files with 81 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
|||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
|
||||
SX1261::SX1261(Module* mod): SX1262(mod) {
|
||||
|
||||
_chipType = RADIOLIB_SX1261_CHIP_TYPE;
|
||||
}
|
||||
|
||||
int16_t SX1261::setOutputPower(int8_t power) {
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
//RADIOLIB_SX126X_CMD_SET_PA_CONFIG
|
||||
#define RADIOLIB_SX126X_PA_CONFIG_SX1261 0x01
|
||||
|
||||
//RADIOLIB_SX126X_REG_VERSION_STRING
|
||||
#define RADIOLIB_SX1261_CHIP_TYPE 1
|
||||
|
||||
/*!
|
||||
\class SX1261
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
|
||||
SX1262::SX1262(Module* mod) : SX126x(mod) {
|
||||
|
||||
_chipType = RADIOLIB_SX1262_CHIP_TYPE;
|
||||
}
|
||||
|
||||
int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
|
@ -47,6 +47,18 @@ int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
|||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1262::beginLRFHSS(float freq, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
// execute common part
|
||||
int16_t state = SX126x::beginLRFHSS(tcxoVoltage, useRegulatorLDO);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1262::setFrequency(float freq) {
|
||||
return(setFrequency(freq, true));
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
//RADIOLIB_SX126X_CMD_SET_PA_CONFIG
|
||||
#define RADIOLIB_SX126X_PA_CONFIG_SX1262 0x00
|
||||
|
||||
//RADIOLIB_SX126X_REG_VERSION_STRING
|
||||
#define RADIOLIB_SX1262_CHIP_TYPE 2
|
||||
|
||||
/*!
|
||||
\class SX1262
|
||||
|
||||
|
@ -50,7 +53,7 @@ class SX1262: public SX126x {
|
|||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 0, bool useRegulatorLDO = false);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
|
@ -73,8 +76,10 @@ class SX1262: public SX126x {
|
|||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 0, bool useRegulatorLDO = false);
|
||||
|
||||
int16_t beginLRFHSS(float freq = 434.0, float tcxoVoltage = 0, bool useRegulatorLDO = false);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
|
||||
SX1268::SX1268(Module* mod) : SX126x(mod) {
|
||||
|
||||
_chipType = RADIOLIB_SX1268_CHIP_TYPE;
|
||||
}
|
||||
|
||||
int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
//RADIOLIB_SX126X_CMD_SET_PA_CONFIG
|
||||
#define RADIOLIB_SX126X_PA_CONFIG_SX1268 0x00
|
||||
|
||||
//RADIOLIB_SX126X_REG_VERSION_STRING
|
||||
#define RADIOLIB_SX1268_CHIP_TYPE 8
|
||||
|
||||
/*!
|
||||
\class SX1268
|
||||
|
||||
|
|
|
@ -20,6 +20,13 @@ int16_t SX126x::begin(uint8_t cr, uint8_t syncWord, uint16_t preambleLength, flo
|
|||
_mod->SPIstatusCommand = RADIOLIB_SX126X_CMD_GET_STATUS;
|
||||
_mod->SPIstreamType = true;
|
||||
_mod->SPIparseStatusCb = SPIparseStatus;
|
||||
|
||||
// try to find the SX126x chip
|
||||
if(!SX126x::findChip(_chipType)) {
|
||||
RADIOLIB_DEBUG_PRINTLN(F("No SX126x found!"));
|
||||
_mod->term();
|
||||
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSX126x"));
|
||||
|
||||
// BW in kHz and SF are required in order to calculate LDRO for setModulationParams
|
||||
|
@ -92,6 +99,13 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, uint16_t preambleL
|
|||
_mod->SPIstatusCommand = RADIOLIB_SX126X_CMD_GET_STATUS;
|
||||
_mod->SPIstreamType = true;
|
||||
_mod->SPIparseStatusCb = SPIparseStatus;
|
||||
|
||||
// try to find the SX126x chip
|
||||
if(!SX126x::findChip(_chipType)) {
|
||||
RADIOLIB_DEBUG_PRINTLN(F("No SX126x found!"));
|
||||
_mod->term();
|
||||
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSX126x"));
|
||||
|
||||
// initialize configuration variables (will be overwritten during public settings configuration)
|
||||
|
@ -950,9 +964,9 @@ int16_t SX126x::setRxBoostedGainMode(bool rxbgm, bool persist) {
|
|||
|
||||
// gain mode register value (SX1261/2 datasheet v2.1 section 9.6)
|
||||
if(rxbgm) {
|
||||
rxGain = 0x96; // Rx Boosted Gain
|
||||
rxGain = RADIOLIB_SX126X_RX_GAIN_BOOSTED;
|
||||
} else {
|
||||
rxGain = 0x94; // Rx Power Saving Gain
|
||||
rxGain = RADIOLIB_SX126X_RX_GAIN_POWER_SAVING;
|
||||
}
|
||||
|
||||
// update RX gain setting register
|
||||
|
@ -1795,4 +1809,39 @@ int16_t SX126x::SPIparseStatus(uint8_t in) {
|
|||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
bool SX126x::findChip(uint8_t ver) {
|
||||
uint8_t i = 0;
|
||||
bool flagFound = false;
|
||||
char versionBuff[16];
|
||||
sprintf(versionBuff, "SX126%d", ver);
|
||||
while((i < 10) && !flagFound) {
|
||||
// reset the module
|
||||
reset();
|
||||
|
||||
// read the version string
|
||||
char version[16];
|
||||
_mod->SPIreadRegisterBurst(RADIOLIB_SX126X_REG_VERSION_STRING, 16, (uint8_t*)version);
|
||||
|
||||
// check version register
|
||||
if(strncmp(versionBuff, version, 6) == 0) {
|
||||
RADIOLIB_DEBUG_PRINTLN(F("Found SX126x: RADIOLIB_SX126X_REG_VERSION_STRING:"));
|
||||
_mod->hexdump((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING);
|
||||
RADIOLIB_DEBUG_PRINTLN();
|
||||
flagFound = true;
|
||||
} else {
|
||||
#if defined(RADIOLIB_DEBUG)
|
||||
RADIOLIB_DEBUG_PRINT(F("SX126x not found! ("));
|
||||
RADIOLIB_DEBUG_PRINT(i + 1);
|
||||
RADIOLIB_DEBUG_PRINTLN(F(" of 10 tries) RADIOLIB_SX126X_REG_VERSION_STRING:"));
|
||||
_mod->hexdump((uint8_t*)version, 16, RADIOLIB_SX126X_REG_VERSION_STRING);
|
||||
RADIOLIB_DEBUG_PRINTLN();
|
||||
#endif
|
||||
_mod->delay(10);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return(flagFound);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1102,11 +1102,13 @@ class SX126x: public PhysicalLayer {
|
|||
uint32_t _tcxoDelay = 0;
|
||||
|
||||
size_t _implicitLen = 0;
|
||||
uint8_t _chipType = 0;
|
||||
|
||||
// Allow subclasses to define different TX modes
|
||||
uint8_t _tx_mode = Module::MODE_TX;
|
||||
|
||||
int16_t config(uint8_t modem);
|
||||
bool findChip(uint8_t type);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue