[SX127x] disable syncword generation & detection, add method to set preamble polarity (#834)
* allow syncword to be disabled if length is 0 * add method to change preamble polarity in FSK mode * add new method 'setPreamblePolarity' * move RADIOLIB_SX127X_PREAMBLE_POLARITY_55 from ::config to ::begin & ::beginFSK * [SX127x] Remove FSK preamble config from LoRa init method * [SX127x] Rename preamble inversion method --------- Co-authored-by: BayCom GmbH <software@baycom.de> Co-authored-by: jgromes <jan.gromes@gmail.com>
This commit is contained in:
parent
44bdf0dba4
commit
d329c60906
3 changed files with 38 additions and 4 deletions
|
@ -124,6 +124,7 @@ setSyncWord KEYWORD2
|
|||
setOutputPower KEYWORD2
|
||||
setCurrentLimit KEYWORD2
|
||||
setPreambleLength KEYWORD2
|
||||
invertPreamble KEYWORD2
|
||||
setGain KEYWORD2
|
||||
getFrequencyError KEYWORD2
|
||||
getRSSI KEYWORD2
|
||||
|
|
|
@ -118,6 +118,10 @@ int16_t SX127x::beginFSK(uint8_t* chipVersions, uint8_t numVersions, float freqD
|
|||
state = SX127x::setPreambleLength(preambleLength);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set preamble polarity
|
||||
state = invertPreamble(false);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set default sync word
|
||||
uint8_t syncWord[] = {0x12, 0xAD};
|
||||
state = setSyncWord(syncWord, 2);
|
||||
|
@ -782,6 +786,25 @@ int16_t SX127x::setPreambleLength(size_t preambleLength) {
|
|||
return(RADIOLIB_ERR_UNKNOWN);
|
||||
}
|
||||
|
||||
int16_t SX127x::invertPreamble(bool enable) {
|
||||
// set mode to standby
|
||||
int16_t state = setMode(RADIOLIB_SX127X_STANDBY);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// check active modem
|
||||
uint8_t modem = getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_LORA) {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
// set preamble polarity
|
||||
uint8_t polarity = enable ? RADIOLIB_SX127X_PREAMBLE_POLARITY_AA : RADIOLIB_SX127X_PREAMBLE_POLARITY_55;
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, polarity, 5, 5);
|
||||
return(state);
|
||||
}
|
||||
|
||||
return(RADIOLIB_ERR_UNKNOWN);
|
||||
}
|
||||
|
||||
float SX127x::getFrequencyError(bool autoCorrect) {
|
||||
int16_t modem = getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_LORA) {
|
||||
|
@ -999,6 +1022,13 @@ int16_t SX127x::setSyncWord(uint8_t* syncWord, size_t len) {
|
|||
// check active modem
|
||||
uint8_t modem = getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
|
||||
// disable sync word in case len is 0
|
||||
if(len == 0) {
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, RADIOLIB_SX127X_SYNC_OFF, 4, 4);
|
||||
return(state);
|
||||
}
|
||||
|
||||
RADIOLIB_CHECK_RANGE(len, 1, 8, RADIOLIB_ERR_INVALID_SYNC_WORD);
|
||||
|
||||
// sync word must not contain value 0x00
|
||||
|
@ -1428,10 +1458,6 @@ int16_t SX127x::configFSK() {
|
|||
state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_2, RADIOLIB_SX127X_DATA_MODE_PACKET | RADIOLIB_SX127X_IO_HOME_OFF, 6, 5);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set preamble polarity
|
||||
state =this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_SYNC_CONFIG, RADIOLIB_SX127X_PREAMBLE_POLARITY_55, 5, 5);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set FIFO threshold
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_TX_START_FIFO_NOT_EMPTY, 7, 7);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_SX127X_REG_FIFO_THRESH, RADIOLIB_SX127X_FIFO_THRESH, 5, 0);
|
||||
|
|
|
@ -878,6 +878,13 @@ class SX127x: public PhysicalLayer {
|
|||
*/
|
||||
int16_t setPreambleLength(size_t preambleLength) override;
|
||||
|
||||
/*!
|
||||
\brief Invert FSK preamble polarity. The default (non-inverted) is 0x55, the inverted is 0xAA.
|
||||
\param enable Preamble polarity in FSK mode - 0xAA when true, 0x55 when false.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t invertPreamble(bool enable);
|
||||
|
||||
/*!
|
||||
\brief Gets frequency error of the latest received packet.
|
||||
\param autoCorrect When set to true, frequency will be automatically corrected.
|
||||
|
|
Loading…
Add table
Reference in a new issue