Skip to content

Commit

Permalink
Sync with new RadioLib debug macros
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Sep 29, 2019
1 parent 626ca7c commit a3637b5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 53 deletions.
66 changes: 33 additions & 33 deletions src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Module::init(uint8_t interface, uint8_t gpio) {
case USE_I2C:
break;
}

// select GPIO
switch(gpio) {
case INT_NONE:
Expand Down Expand Up @@ -49,10 +49,10 @@ int16_t Module::SPIgetRegValue(uint8_t reg, uint8_t msb, uint8_t lsb) {
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
return(ERR_INVALID_BIT_RANGE);
}

// get current register value
uint8_t rawValue = SPIreadRegister(reg);

// mask the register value
uint8_t maskedValue = rawValue & ((0b11111111 << lsb) & (0b11111111 >> (7 - msb)));
return(maskedValue);
Expand All @@ -63,19 +63,19 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
if((msb > 7) || (lsb > 7) || (lsb > msb)) {
return(ERR_INVALID_BIT_RANGE);
}

// get current raw register value
uint8_t currentValue = SPIreadRegister(reg);

// mask the bits that should be kept
uint8_t mask = ~((0b11111111 << (msb + 1)) | (0b11111111 >> (8 - lsb)));

// calculate the new raw register value
uint8_t newValue = (currentValue & ~mask) | (value & mask);

// write the new raw value into register
SPIwriteRegister(reg, newValue);

// check register value each millisecond until check interval is reached
// some registers need a bit of time to process the change (e.g. SX127X_REG_OP_MODE)
uint32_t start = micros();
Expand All @@ -87,27 +87,27 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
return(ERR_NONE);
}
}

// check failed, print debug info
DEBUG_PRINTLN();
DEBUG_PRINT(F("address:\t0x"));
DEBUG_PRINTLN(reg, HEX);
DEBUG_PRINT(F("bits:\t\t"));
DEBUG_PRINT(msb);
DEBUG_PRINT(' ');
DEBUG_PRINTLN(lsb);
DEBUG_PRINT(F("value:\t\t0b"));
DEBUG_PRINTLN(value, BIN);
DEBUG_PRINT(F("current:\t0b"));
DEBUG_PRINTLN(currentValue, BIN);
DEBUG_PRINT(F("mask:\t\t0b"));
DEBUG_PRINTLN(mask, BIN);
DEBUG_PRINT(F("new:\t\t0b"));
DEBUG_PRINTLN(newValue, BIN);
DEBUG_PRINT(F("read:\t\t0b"));
DEBUG_PRINTLN(readValue, BIN);
DEBUG_PRINTLN();
RADIOLIB_DEBUG_PRINTLN();
RADIOLIB_DEBUG_PRINT(F("address:\t0x"));
RADIOLIB_DEBUG_PRINTLN(reg, HEX);
RADIOLIB_DEBUG_PRINT(F("bits:\t\t"));
RADIOLIB_DEBUG_PRINT(msb);
RADIOLIB_DEBUG_PRINT(' ');
RADIOLIB_DEBUG_PRINTLN(lsb);
RADIOLIB_DEBUG_PRINT(F("value:\t\t0b"));
RADIOLIB_DEBUG_PRINTLN(value, BIN);
RADIOLIB_DEBUG_PRINT(F("current:\t0b"));
RADIOLIB_DEBUG_PRINTLN(currentValue, BIN);
RADIOLIB_DEBUG_PRINT(F("mask:\t\t0b"));
RADIOLIB_DEBUG_PRINTLN(mask, BIN);
RADIOLIB_DEBUG_PRINT(F("new:\t\t0b"));
RADIOLIB_DEBUG_PRINTLN(newValue, BIN);
RADIOLIB_DEBUG_PRINT(F("read:\t\t0b"));
RADIOLIB_DEBUG_PRINTLN(readValue, BIN);
RADIOLIB_DEBUG_PRINTLN();

return(ERR_SPI_WRITE_FAILED);
}

Expand All @@ -132,13 +132,13 @@ void Module::SPIwriteRegister(uint8_t reg, uint8_t data) {
void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes) {
// start SPI transaction
_spi->beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));

// pull CS low
digitalWrite(_cs, LOW);

// send SPI register address with access command
_spi->transfer(reg | cmd);

// send data or get response
switch(cmd) {
case SPI_WRITE:
Expand All @@ -154,10 +154,10 @@ void Module::SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* da
default:
break;
}

// release CS
digitalWrite(_cs, HIGH);

// end SPI transaction
_spi->endTransaction();
}
8 changes: 4 additions & 4 deletions src/TypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
//#define RADIOLIB_DEBUG

#ifdef RADIOLIB_DEBUG
#define DEBUG_PRINT(...) { Serial.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...) { Serial.println(__VA_ARGS__); }
#define RADIOLIB_DEBUG_PRINT(...) { Serial.print(__VA_ARGS__); }
#define RADIOLIB_DEBUG_PRINTLN(...) { Serial.println(__VA_ARGS__); }
#else
#define DEBUG_PRINT(...) {}
#define DEBUG_PRINTLN(...) {}
#define RADIOLIB_DEBUG_PRINT(...) {}
#define RADIOLIB_DEBUG_PRINTLN(...) {}
#endif

// Shield configuration
Expand Down
12 changes: 6 additions & 6 deletions src/modules/SX1272.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ int16_t SX1272::setBandwidth(float bw) {

// calculate symbol length and set low data rate optimization, if needed
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
DEBUG_PRINT("Symbol length: ");
DEBUG_PRINT(symbolLength);
DEBUG_PRINTLN(" ms");
RADIOLIB_DEBUG_PRINT("Symbol length: ");
RADIOLIB_DEBUG_PRINT(symbolLength);
RADIOLIB_DEBUG_PRINTLN(" ms");
if(symbolLength >= 16.0) {
state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
} else {
Expand Down Expand Up @@ -179,9 +179,9 @@ int16_t SX1272::setSpreadingFactor(uint8_t sf) {

// calculate symbol length and set low data rate optimization, if needed
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
DEBUG_PRINT("Symbol length: ");
DEBUG_PRINT(symbolLength);
DEBUG_PRINTLN(" ms");
RADIOLIB_DEBUG_PRINT("Symbol length: ");
RADIOLIB_DEBUG_PRINT(symbolLength);
RADIOLIB_DEBUG_PRINTLN(" ms");
if(symbolLength >= 16.0) {
state = _mod->SPIsetRegValue(SX127X_REG_MODEM_CONFIG_1, SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/modules/SX1278.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ int16_t SX1278::setBandwidth(float bw) {

// calculate symbol length and set low data rate optimization, if needed
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
DEBUG_PRINT("Symbol length: ");
DEBUG_PRINT(symbolLength);
DEBUG_PRINTLN(" ms");
RADIOLIB_DEBUG_PRINT("Symbol length: ");
RADIOLIB_DEBUG_PRINT(symbolLength);
RADIOLIB_DEBUG_PRINTLN(" ms");
if(symbolLength >= 16.0) {
state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
} else {
Expand Down Expand Up @@ -249,9 +249,9 @@ int16_t SX1278::setSpreadingFactor(uint8_t sf) {

// calculate symbol length and set low data rate optimization, if needed
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
DEBUG_PRINT("Symbol length: ");
DEBUG_PRINT(symbolLength);
DEBUG_PRINTLN(" ms");
RADIOLIB_DEBUG_PRINT("Symbol length: ");
RADIOLIB_DEBUG_PRINT(symbolLength);
RADIOLIB_DEBUG_PRINTLN(" ms");
if(symbolLength >= 16.0) {
state = _mod->SPIsetRegValue(SX1278_REG_MODEM_CONFIG_3, SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/modules/SX127x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ int16_t SX127x::begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimi

// try to find the SX127x chip
if(!SX127x::findChip(chipVersion)) {
DEBUG_PRINTLN(F("No SX127x found!"));
RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!"));
_mod->term();
return(ERR_CHIP_NOT_FOUND);
} else {
DEBUG_PRINTLN(F("Found SX127x!"));
RADIOLIB_DEBUG_PRINTLN(F("Found SX127x!"));
}

// check active modem
Expand Down Expand Up @@ -55,11 +55,11 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB

// try to find the SX127x chip
if(!SX127x::findChip(chipVersion)) {
DEBUG_PRINTLN(F("No SX127x found!"));
RADIOLIB_DEBUG_PRINTLN(F("No SX127x found!"));
_mod->term();
return(ERR_CHIP_NOT_FOUND);
} else {
DEBUG_PRINTLN(F("Found SX127x!"));
RADIOLIB_DEBUG_PRINTLN(F("Found SX127x!"));
}

// check currently active modem
Expand Down

0 comments on commit a3637b5

Please sign in to comment.