Skip to content

Commit

Permalink
Added method to change FSK encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Nov 5, 2019
1 parent 2c1b863 commit 5dc5ead
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ setOOK KEYWORD2
setDataShapingOOK KEYWORD2
setCRC KEYWORD2
setRSSIConfig KEYWORD2
setEncoding KEYWORD2

#######################################
# Constants (LITERAL1)
Expand Down Expand Up @@ -99,3 +100,4 @@ ERR_INVALID_MODULATION LITERAL1
ERR_MEMORY_ALLOCATION_FAILED LITERAL1
ERR_INVALID_NUM_SAMPLES LITERAL1
ERR_INVALID_RSSI_OFFSET LITERAL1
ERR_INVALID_ENCODING LITERAL1
5 changes: 5 additions & 0 deletions src/TypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
*/
#define ERR_INVALID_RSSI_OFFSET -28

/*!
\brief The supplied encoding is invalid.
*/
#define ERR_INVALID_ENCODING -29

/*!
\}
*/
Expand Down
25 changes: 25 additions & 0 deletions src/modules/SX127x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB

// set default RSSI measurement config
state = setRSSIConfig(2);
if(state != ERR_NONE) {
return(state);
}

// set default encoding
state = setEncoding(0);

return(state);
}
Expand Down Expand Up @@ -926,6 +932,25 @@ int16_t SX127x::setRSSIConfig(uint8_t smoothingSamples, int8_t offset) {
return(state);
}

int16_t SX127x::setEncoding(uint8_t encoding) {
// check active modem
if(getActiveModem() != SX127X_FSK_OOK) {
return(ERR_WRONG_MODEM);
}

// set encoding
switch(encoding) {
case 0:
return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_DC_FREE_NONE, 6, 5));
case 1:
return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_DC_FREE_NONE, 6, 5));
case 2:
return(_mod->SPIsetRegValue(SX127X_REG_PACKET_CONFIG_1, SX127X_DC_FREE_NONE, 6, 5));
default:
return(ERR_INVALID_ENCODING);
}
}

int16_t SX127x::config() {
// turn off frequency hopping
int16_t state = _mod->SPIsetRegValue(SX127X_REG_HOP_PERIOD, SX127X_HOP_PERIOD_OFF);
Expand Down
9 changes: 9 additions & 0 deletions src/modules/SX127x.h
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,15 @@ class SX127x: public PhysicalLayer {
*/
int16_t setRSSIConfig(uint8_t smoothingSamples, int8_t offset = 0);

/*!
\brief Sets transmission encoding. Only available in FSK mode.
\param encoding Encoding to be used. Set to 0 for NRZ, 1 for Manchester and 2 for whitening.
\returns \ref status_codes
*/
int16_t setEncoding(uint8_t encoding);

#ifdef RADIOLIB_DEBUG
void regDump();
#endif
Expand Down

0 comments on commit 5dc5ead

Please sign in to comment.