[RF69] General reformatting

This commit is contained in:
jgromes 2023-04-23 19:43:48 +02:00
parent c62bb74f9d
commit 9be1cdfa41
2 changed files with 652 additions and 761 deletions

View file

@ -3,17 +3,17 @@
#if !defined(RADIOLIB_EXCLUDE_RF69) #if !defined(RADIOLIB_EXCLUDE_RF69)
RF69::RF69(Module* module) : PhysicalLayer(RADIOLIB_RF69_FREQUENCY_STEP_SIZE, RADIOLIB_RF69_MAX_PACKET_LENGTH) { RF69::RF69(Module* module) : PhysicalLayer(RADIOLIB_RF69_FREQUENCY_STEP_SIZE, RADIOLIB_RF69_MAX_PACKET_LENGTH) {
_mod = module; this->mod = module;
} }
Module* RF69::getMod() { Module* RF69::getMod() {
return(_mod); return(this->mod);
} }
int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) { int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) {
// set module properties // set module properties
_mod->init(); this->mod->init();
_mod->hal->pinMode(_mod->getIrq(), _mod->hal->GpioModeInput); this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
// try to find the RF69 chip // try to find the RF69 chip
uint8_t i = 0; uint8_t i = 0;
@ -28,14 +28,14 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe
flagFound = true; flagFound = true;
} else { } else {
RADIOLIB_DEBUG_PRINTLN("RF69 not found! (%d of 10 tries) RADIOLIB_RF69_REG_VERSION == 0x%04X, expected 0x0024", i + 1, version); RADIOLIB_DEBUG_PRINTLN("RF69 not found! (%d of 10 tries) RADIOLIB_RF69_REG_VERSION == 0x%04X, expected 0x0024", i + 1, version);
_mod->hal->delay(10); this->mod->hal->delay(10);
i++; i++;
} }
} }
if(!flagFound) { if(!flagFound) {
RADIOLIB_DEBUG_PRINTLN("No RF69 found!"); RADIOLIB_DEBUG_PRINTLN("No RF69 found!");
_mod->term(); this->mod->term();
return(RADIOLIB_ERR_CHIP_NOT_FOUND); return(RADIOLIB_ERR_CHIP_NOT_FOUND);
} else { } else {
RADIOLIB_DEBUG_PRINTLN("M\tRF69"); RADIOLIB_DEBUG_PRINTLN("M\tRF69");
@ -50,7 +50,7 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// configure bitrate // configure bitrate
_rxBw = rxBw; this->rxBandwidth = rxBw;
state = setBitRate(br); state = setBitRate(br);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
@ -95,27 +95,27 @@ int16_t RF69::begin(float freq, float br, float freqDev, float rxBw, int8_t powe
} }
void RF69::reset() { void RF69::reset() {
_mod->hal->pinMode(_mod->getRst(), _mod->hal->GpioModeOutput); this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
_mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelHigh); this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
_mod->hal->delay(1); this->mod->hal->delay(1);
_mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelLow); this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
_mod->hal->delay(10); this->mod->hal->delay(10);
} }
int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) { int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
// calculate timeout (5ms + 500 % of expected time-on-air) // calculate timeout (5ms + 500 % of expected time-on-air)
uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 5000000.0); uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (this->bitRate * 1000.0)) * 5000000.0);
// start transmission // start transmission
int16_t state = startTransmit(data, len, addr); int16_t state = startTransmit(data, len, addr);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// wait for transmission end or timeout // wait for transmission end or timeout
uint32_t start = _mod->hal->micros(); uint32_t start = this->mod->hal->micros();
while(!_mod->hal->digitalRead(_mod->getIrq())) { while(!this->mod->hal->digitalRead(this->mod->getIrq())) {
_mod->hal->yield(); this->mod->hal->yield();
if(_mod->hal->micros() - start > timeout) { if(this->mod->hal->micros() - start > timeout) {
finishTransmit(); finishTransmit();
return(RADIOLIB_ERR_TX_TIMEOUT); return(RADIOLIB_ERR_TX_TIMEOUT);
} }
@ -126,18 +126,18 @@ int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
int16_t RF69::receive(uint8_t* data, size_t len) { int16_t RF69::receive(uint8_t* data, size_t len) {
// calculate timeout (500 ms + 400 full 64-byte packets at current bit rate) // calculate timeout (500 ms + 400 full 64-byte packets at current bit rate)
uint32_t timeout = 500000 + (1.0/(_br*1000.0))*(RADIOLIB_RF69_MAX_PACKET_LENGTH*400.0); uint32_t timeout = 500000 + (1.0/(this->bitRate*1000.0))*(RADIOLIB_RF69_MAX_PACKET_LENGTH*400.0);
// start reception // start reception
int16_t state = startReceive(); int16_t state = startReceive();
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// wait for packet reception or timeout // wait for packet reception or timeout
uint32_t start = _mod->hal->micros(); uint32_t start = this->mod->hal->micros();
while(!_mod->hal->digitalRead(_mod->getIrq())) { while(!this->mod->hal->digitalRead(this->mod->getIrq())) {
_mod->hal->yield(); this->mod->hal->yield();
if(_mod->hal->micros() - start > timeout) { if(this->mod->hal->micros() - start > timeout) {
standby(); standby();
clearIRQFlags(); clearIRQFlags();
return(RADIOLIB_ERR_RX_TIMEOUT); return(RADIOLIB_ERR_RX_TIMEOUT);
@ -150,7 +150,7 @@ int16_t RF69::receive(uint8_t* data, size_t len) {
int16_t RF69::sleep() { int16_t RF69::sleep() {
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_IDLE); this->mod->setRfSwitchState(Module::MODE_IDLE);
// set module to sleep // set module to sleep
return(setMode(RADIOLIB_RF69_SLEEP)); return(setMode(RADIOLIB_RF69_SLEEP));
@ -158,7 +158,7 @@ int16_t RF69::sleep() {
int16_t RF69::standby() { int16_t RF69::standby() {
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_IDLE); this->mod->setRfSwitchState(Module::MODE_IDLE);
// set module to standby // set module to standby
return(setMode(RADIOLIB_RF69_STANDBY)); return(setMode(RADIOLIB_RF69_STANDBY));
@ -171,13 +171,13 @@ int16_t RF69::standby(uint8_t mode) {
int16_t RF69::transmitDirect(uint32_t frf) { int16_t RF69::transmitDirect(uint32_t frf) {
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_TX); this->mod->setRfSwitchState(Module::MODE_TX);
// user requested to start transmitting immediately (required for RTTY) // user requested to start transmitting immediately (required for RTTY)
if(frf != 0) { if(frf != 0) {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MSB, (frf & 0xFF0000) >> 16); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MSB, (frf & 0xFF0000) >> 16);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MID, (frf & 0x00FF00) >> 8); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MID, (frf & 0x00FF00) >> 8);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_LSB, frf & 0x0000FF); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_LSB, frf & 0x0000FF);
return(setMode(RADIOLIB_RF69_TX)); return(setMode(RADIOLIB_RF69_TX));
} }
@ -192,7 +192,7 @@ int16_t RF69::transmitDirect(uint32_t frf) {
int16_t RF69::receiveDirect() { int16_t RF69::receiveDirect() {
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_RX); this->mod->setRfSwitchState(Module::MODE_RX);
// activate direct mode // activate direct mode
int16_t state = directMode(); int16_t state = directMode();
@ -208,31 +208,31 @@ int16_t RF69::directMode() {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set DIO mapping // set DIO mapping
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO1_CONT_DCLK | RADIOLIB_RF69_DIO2_CONT_DATA, 5, 2); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO1_CONT_DCLK | RADIOLIB_RF69_DIO2_CONT_DATA, 5, 2);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set continuous mode // set continuous mode
if(_bitSync) { if(this->bitSync) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE_WITH_SYNC, 6, 5)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE_WITH_SYNC, 6, 5));
} else { } else {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE, 6, 5)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE, 6, 5));
} }
} }
int16_t RF69::packetMode() { int16_t RF69::packetMode() {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_PACKET_MODE, 6, 5)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_PACKET_MODE, 6, 5));
} }
void RF69::setAESKey(uint8_t* key) { void RF69::setAESKey(uint8_t* key) {
_mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_AES_KEY_1, key, 16); this->mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_AES_KEY_1, key, 16);
} }
int16_t RF69::enableAES() { int16_t RF69::enableAES() {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_AES_ON, 0, 0)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_AES_ON, 0, 0));
} }
int16_t RF69::disableAES() { int16_t RF69::disableAES() {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_AES_OFF, 0, 0)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_AES_OFF, 0, 0));
} }
int16_t RF69::startReceive() { int16_t RF69::startReceive() {
@ -241,21 +241,21 @@ int16_t RF69::startReceive() {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set RX timeouts and DIO pin mapping // set RX timeouts and DIO pin mapping
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO0_PACK_PAYLOAD_READY, 7, 4); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO0_PACK_PAYLOAD_READY, 7, 4);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_1, RADIOLIB_RF69_TIMEOUT_RX_START); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_1, RADIOLIB_RF69_TIMEOUT_RX_START);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_2, RADIOLIB_RF69_TIMEOUT_RSSI_THRESH); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_2, RADIOLIB_RF69_TIMEOUT_RSSI_THRESH);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// clear interrupt flags // clear interrupt flags
clearIRQFlags(); clearIRQFlags();
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_RX); this->mod->setRfSwitchState(Module::MODE_RX);
// set mode to receive // set mode to receive
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA1, RADIOLIB_RF69_PA1_NORMAL); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA1, RADIOLIB_RF69_PA1_NORMAL);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA2, RADIOLIB_RF69_PA2_NORMAL); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA2, RADIOLIB_RF69_PA2_NORMAL);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
state = setMode(RADIOLIB_RF69_RX); state = setMode(RADIOLIB_RF69_RX);
@ -272,37 +272,37 @@ int16_t RF69::startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMask
} }
void RF69::setDio0Action(void (*func)(void)) { void RF69::setDio0Action(void (*func)(void)) {
_mod->hal->attachInterrupt(_mod->hal->pinToInterrupt(_mod->getIrq()), func, _mod->hal->GpioInterruptRising); this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, this->mod->hal->GpioInterruptRising);
} }
void RF69::clearDio0Action() { void RF69::clearDio0Action() {
_mod->hal->detachInterrupt(_mod->hal->pinToInterrupt(_mod->getIrq())); this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()));
} }
void RF69::setDio1Action(void (*func)(void)) { void RF69::setDio1Action(void (*func)(void)) {
if(_mod->getGpio() == RADIOLIB_NC) { if(this->mod->getGpio() == RADIOLIB_NC) {
return; return;
} }
_mod->hal->pinMode(_mod->getGpio(), _mod->hal->GpioModeInput); this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput);
_mod->hal->attachInterrupt(_mod->hal->pinToInterrupt(_mod->getGpio()), func, _mod->hal->GpioInterruptRising); this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getGpio()), func, this->mod->hal->GpioInterruptRising);
} }
void RF69::clearDio1Action() { void RF69::clearDio1Action() {
if(_mod->getGpio() == RADIOLIB_NC) { if(this->mod->getGpio() == RADIOLIB_NC) {
return; return;
} }
_mod->hal->detachInterrupt(_mod->hal->pinToInterrupt(_mod->getGpio())); this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getGpio()));
} }
void RF69::setFifoEmptyAction(void (*func)(void)) { void RF69::setFifoEmptyAction(void (*func)(void)) {
// set DIO1 to the FIFO empty event (the register setting is done in startTransmit) // set DIO1 to the FIFO empty event (the register setting is done in startTransmit)
if(_mod->getGpio() == RADIOLIB_NC) { if(this->mod->getGpio() == RADIOLIB_NC) {
return; return;
} }
_mod->hal->pinMode(_mod->getGpio(), _mod->hal->GpioModeInput); this->mod->hal->pinMode(this->mod->getGpio(), this->mod->hal->GpioModeInput);
// we need to invert the logic here (as compared to setDio1Action), since we are using the "FIFO not empty interrupt" // we need to invert the logic here (as compared to setDio1Action), since we are using the "FIFO not empty interrupt"
_mod->hal->attachInterrupt(_mod->hal->pinToInterrupt(_mod->getGpio()), func, _mod->hal->GpioInterruptFalling); this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getGpio()), func, this->mod->hal->GpioInterruptFalling);
} }
void RF69::clearFifoEmptyAction() { void RF69::clearFifoEmptyAction() {
@ -311,8 +311,8 @@ void RF69::clearFifoEmptyAction() {
void RF69::setFifoFullAction(void (*func)(void)) { void RF69::setFifoFullAction(void (*func)(void)) {
// set the interrupt // set the interrupt
_mod->SPIsetRegValue(RADIOLIB_RF69_REG_FIFO_THRESH, RADIOLIB_RF69_FIFO_THRESH, 6, 0); this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_FIFO_THRESH, RADIOLIB_RF69_FIFO_THRESH, 6, 0);
_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO1_PACK_FIFO_LEVEL, 5, 4); this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO1_PACK_FIFO_LEVEL, 5, 4);
// set DIO1 to the FIFO full event // set DIO1 to the FIFO full event
setDio1Action(func); setDio1Action(func);
@ -320,7 +320,7 @@ void RF69::setFifoFullAction(void (*func)(void)) {
void RF69::clearFifoFullAction() { void RF69::clearFifoFullAction() {
clearDio1Action(); clearDio1Action();
_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, 0x00, 5, 4); this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, 0x00, 5, 4);
} }
bool RF69::fifoAdd(uint8_t* data, int totalLen, int* remLen) { bool RF69::fifoAdd(uint8_t* data, int totalLen, int* remLen) {
@ -340,7 +340,7 @@ bool RF69::fifoAdd(uint8_t* data, int totalLen, int* remLen) {
} }
// copy the bytes to the FIFO // copy the bytes to the FIFO
_mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_FIFO, &data[totalLen - *remLen], len); this->mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_FIFO, &data[totalLen - *remLen], len);
// we're not done yet // we're not done yet
return(false); return(false);
@ -358,7 +358,7 @@ bool RF69::fifoGet(volatile uint8_t* data, int totalLen, volatile int* rcvLen) {
} }
// get the data // get the data
_mod->SPIreadRegisterBurst(RADIOLIB_RF69_REG_FIFO, len, dataPtr); this->mod->SPIreadRegisterBurst(RADIOLIB_RF69_REG_FIFO, len, dataPtr);
(*rcvLen) += (len); (*rcvLen) += (len);
// check if we're done // check if we're done
@ -378,47 +378,47 @@ int16_t RF69::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
// set DIO mapping // set DIO mapping
if(len > RADIOLIB_RF69_MAX_PACKET_LENGTH) { if(len > RADIOLIB_RF69_MAX_PACKET_LENGTH) {
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO1_PACK_FIFO_NOT_EMPTY, 5, 4); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO1_PACK_FIFO_NOT_EMPTY, 5, 4);
} else { } else {
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO0_PACK_PACKET_SENT, 7, 6); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, RADIOLIB_RF69_DIO0_PACK_PACKET_SENT, 7, 6);
} }
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// optionally write packet length // optionally write packet length
if (_packetLengthConfig == RADIOLIB_RF69_PACKET_FORMAT_VARIABLE) { if (this->packetLengthConfig == RADIOLIB_RF69_PACKET_FORMAT_VARIABLE) {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FIFO, len); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_FIFO, len);
} }
// check address filtering // check address filtering
uint8_t filter = _mod->SPIgetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, 2, 1); uint8_t filter = this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, 2, 1);
if((filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST)) { if((filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST)) {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FIFO, addr); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_FIFO, addr);
} }
// write packet to FIFO // write packet to FIFO
size_t packetLen = len; size_t packetLen = len;
if(len > RADIOLIB_RF69_MAX_PACKET_LENGTH) { if(len > RADIOLIB_RF69_MAX_PACKET_LENGTH) {
packetLen = RADIOLIB_RF69_FIFO_THRESH - 1; packetLen = RADIOLIB_RF69_FIFO_THRESH - 1;
_mod->SPIsetRegValue(RADIOLIB_RF69_REG_FIFO_THRESH, RADIOLIB_RF69_TX_START_CONDITION_FIFO_NOT_EMPTY, 7, 7); this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_FIFO_THRESH, RADIOLIB_RF69_TX_START_CONDITION_FIFO_NOT_EMPTY, 7, 7);
} }
_mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_FIFO, data, packetLen); this->mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_FIFO, data, packetLen);
// this is a hack, but it seems than in Stream mode, Rx FIFO level is getting triggered 1 byte before it should // this is a hack, but it seems than in Stream mode, Rx FIFO level is getting triggered 1 byte before it should
// just add a padding byte that can be dropped without consequence // just add a padding byte that can be dropped without consequence
if(len > RADIOLIB_RF69_MAX_PACKET_LENGTH) { if(len > RADIOLIB_RF69_MAX_PACKET_LENGTH) {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FIFO, '/'); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_FIFO, '/');
} }
// enable +20 dBm operation // enable +20 dBm operation
if(_power > 17) { if(this->power > 17) {
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_OFF | 0x0F); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_OFF | 0x0F);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA1, RADIOLIB_RF69_PA1_20_DBM); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA1, RADIOLIB_RF69_PA1_20_DBM);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA2, RADIOLIB_RF69_PA2_20_DBM); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_PA2, RADIOLIB_RF69_PA2_20_DBM);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
} }
// set RF switch (if present) // set RF switch (if present)
_mod->setRfSwitchState(Module::MODE_TX); this->mod->setRfSwitchState(Module::MODE_TX);
// set mode to transmit // set mode to transmit
state = setMode(RADIOLIB_RF69_TX); state = setMode(RADIOLIB_RF69_TX);
@ -449,13 +449,13 @@ int16_t RF69::readData(uint8_t* data, size_t len) {
} }
// check address filtering // check address filtering
uint8_t filter = _mod->SPIgetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, 2, 1); uint8_t filter = this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, 2, 1);
if((filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST)) { if((filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE) || (filter == RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST)) {
_mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO); this->mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO);
} }
// read packet data // read packet data
_mod->SPIreadRegisterBurst(RADIOLIB_RF69_REG_FIFO, length, data); this->mod->SPIreadRegisterBurst(RADIOLIB_RF69_REG_FIFO, length, data);
// dump the bytes that weren't requested // dump the bytes that weren't requested
if(dumpLen != 0) { if(dumpLen != 0) {
@ -463,7 +463,7 @@ int16_t RF69::readData(uint8_t* data, size_t len) {
} }
// clear internal flag so getPacketLength can return the new packet length // clear internal flag so getPacketLength can return the new packet length
_packetLengthQueried = false; this->packetLengthQueried = false;
// clear interrupt flags // clear interrupt flags
clearIRQFlags(); clearIRQFlags();
@ -471,21 +471,21 @@ int16_t RF69::readData(uint8_t* data, size_t len) {
return(RADIOLIB_ERR_NONE); return(RADIOLIB_ERR_NONE);
} }
int16_t RF69::setOOK(bool enableOOK) { int16_t RF69::setOOK(bool enable) {
// set OOK and if successful, save the new setting // set OOK and if successful, save the new setting
int16_t state = RADIOLIB_ERR_NONE; int16_t state = RADIOLIB_ERR_NONE;
if(enableOOK) { if(enable) {
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_OOK, 4, 3, 5); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_OOK, 4, 3, 5);
} else { } else {
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK, 4, 3, 5); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK, 4, 3, 5);
} }
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_ook = enableOOK; this->ookEnabled = enable;
} }
// call setRxBandwidth again, since register values differ based on OOK mode being enabled // call setRxBandwidth again, since register values differ based on OOK mode being enabled
state |= setRxBandwidth(_rxBw); state |= setRxBandwidth(this->rxBandwidth);
return(state); return(state);
} }
@ -494,15 +494,15 @@ int16_t RF69::setOokThresholdType(uint8_t type) {
if((type != RADIOLIB_RF69_OOK_THRESH_FIXED) && (type != RADIOLIB_RF69_OOK_THRESH_PEAK) && (type != RADIOLIB_RF69_OOK_THRESH_AVERAGE)) { if((type != RADIOLIB_RF69_OOK_THRESH_FIXED) && (type != RADIOLIB_RF69_OOK_THRESH_PEAK) && (type != RADIOLIB_RF69_OOK_THRESH_AVERAGE)) {
return(RADIOLIB_ERR_INVALID_OOK_RSSI_PEAK_TYPE); return(RADIOLIB_ERR_INVALID_OOK_RSSI_PEAK_TYPE);
} }
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_OOK_PEAK, type, 7, 3, 5)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OOK_PEAK, type, 7, 3, 5));
} }
int16_t RF69::setOokFixedThreshold(uint8_t value) { int16_t RF69::setOokFixedThreshold(uint8_t value) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_OOK_FIX, value, 7, 0, 5)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OOK_FIX, value, 7, 0, 5));
} }
int16_t RF69::setOokPeakThresholdDecrement(uint8_t value) { int16_t RF69::setOokPeakThresholdDecrement(uint8_t value) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_OOK_PEAK, value, 2, 0, 5)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OOK_PEAK, value, 2, 0, 5));
} }
int16_t RF69::setFrequency(float freq) { int16_t RF69::setFrequency(float freq) {
@ -519,9 +519,9 @@ int16_t RF69::setFrequency(float freq) {
//set carrier frequency //set carrier frequency
//FRF(23:0) = freq / Fstep = freq * (1 / Fstep) = freq * (2^19 / 32.0) (pag. 17 of datasheet) //FRF(23:0) = freq / Fstep = freq * (1 / Fstep) = freq * (2^19 / 32.0) (pag. 17 of datasheet)
uint32_t FRF = (freq * (uint32_t(1) << RADIOLIB_RF69_DIV_EXPONENT)) / RADIOLIB_RF69_CRYSTAL_FREQ; uint32_t FRF = (freq * (uint32_t(1) << RADIOLIB_RF69_DIV_EXPONENT)) / RADIOLIB_RF69_CRYSTAL_FREQ;
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MSB, (FRF & 0xFF0000) >> 16); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MSB, (FRF & 0xFF0000) >> 16);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MID, (FRF & 0x00FF00) >> 8); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_MID, (FRF & 0x00FF00) >> 8);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_LSB, FRF & 0x0000FF); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_FRF_LSB, FRF & 0x0000FF);
return(RADIOLIB_ERR_NONE); return(RADIOLIB_ERR_NONE);
} }
@ -531,9 +531,9 @@ int16_t RF69::getFrequency(float *freq) {
//FRF(23:0) = [ [FRF_MSB]|[FRF_MID]|[FRF_LSB]] //FRF(23:0) = [ [FRF_MSB]|[FRF_MID]|[FRF_LSB]]
//FRF(32:0) = [0x00|[FRF_MSB]|[FRF_MID]|[FRF_LSB]] //FRF(32:0) = [0x00|[FRF_MSB]|[FRF_MID]|[FRF_LSB]]
FRF |= (((uint32_t)(_mod->SPIgetRegValue(RADIOLIB_RF69_REG_FRF_MSB, 7, 0)) << 16) & 0x00FF0000); FRF |= (((uint32_t)(this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_FRF_MSB, 7, 0)) << 16) & 0x00FF0000);
FRF |= (((uint32_t)(_mod->SPIgetRegValue(RADIOLIB_RF69_REG_FRF_MID, 7, 0)) << 8) & 0x0000FF00); FRF |= (((uint32_t)(this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_FRF_MID, 7, 0)) << 8) & 0x0000FF00);
FRF |= (((uint32_t)(_mod->SPIgetRegValue(RADIOLIB_RF69_REG_FRF_LSB, 7, 0)) << 0) & 0x000000FF); FRF |= (((uint32_t)(this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_FRF_LSB, 7, 0)) << 0) & 0x000000FF);
//freq = Fstep * FRF(23:0) = (32.0 / 2^19) * FRF(23:0) (pag. 17 of datasheet) //freq = Fstep * FRF(23:0) = (32.0 / 2^19) * FRF(23:0) (pag. 17 of datasheet)
*freq = FRF * ( RADIOLIB_RF69_CRYSTAL_FREQ / (uint32_t(1) << RADIOLIB_RF69_DIV_EXPONENT) ); *freq = FRF * ( RADIOLIB_RF69_CRYSTAL_FREQ / (uint32_t(1) << RADIOLIB_RF69_DIV_EXPONENT) );
@ -546,7 +546,7 @@ int16_t RF69::setBitRate(float br) {
RADIOLIB_CHECK_RANGE(br, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE); RADIOLIB_CHECK_RANGE(br, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
// check bitrate-bandwidth ratio // check bitrate-bandwidth ratio
if(!(br < 2000 * _rxBw)) { if(!(br < 2000 * this->rxBandwidth)) {
return(RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO); return(RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO);
} }
@ -555,17 +555,17 @@ int16_t RF69::setBitRate(float br) {
// set bit rate // set bit rate
uint16_t bitRate = 32000 / br; uint16_t bitRate = 32000 / br;
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0); int16_t state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0);
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_br = br; this->bitRate = br;
} }
return(state); return(state);
} }
int16_t RF69::setRxBandwidth(float rxBw) { int16_t RF69::setRxBandwidth(float rxBw) {
// check bitrate-bandwidth ratio // check bitrate-bandwidth ratio
if(!(_br < 2000 * rxBw)) { if(!(this->bitRate < 2000 * rxBw)) {
return(RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO); return(RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO);
} }
@ -576,12 +576,12 @@ int16_t RF69::setRxBandwidth(float rxBw) {
// calculate exponent and mantissa values for receiver bandwidth // calculate exponent and mantissa values for receiver bandwidth
for(int8_t e = 7; e >= 0; e--) { for(int8_t e = 7; e >= 0; e--) {
for(int8_t m = 2; m >= 0; m--) { for(int8_t m = 2; m >= 0; m--) {
float point = (RADIOLIB_RF69_CRYSTAL_FREQ * 1000000.0)/(((4 * m) + 16) * ((uint32_t)1 << (e + (_ook ? 3 : 2)))); float point = (RADIOLIB_RF69_CRYSTAL_FREQ * 1000000.0)/(((4 * m) + 16) * ((uint32_t)1 << (e + (this->ookEnabled ? 3 : 2))));
if(fabs(rxBw - (point / 1000.0)) <= 0.1) { if(fabs(rxBw - (point / 1000.0)) <= 0.1) {
// set Rx bandwidth // set Rx bandwidth
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_BW, (m << 3) | e, 4, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_BW, (m << 3) | e, 4, 0);
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_rxBw = rxBw; this->rxBandwidth = rxBw;
} }
return(state); return(state);
} }
@ -599,7 +599,7 @@ int16_t RF69::setFrequencyDeviation(float freqDev) {
} }
// check frequency deviation range // check frequency deviation range
if(!((newFreqDev + _br/2 <= 500))) { if(!((newFreqDev + this->bitRate/2 <= 500))) {
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION); return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
} }
@ -608,18 +608,18 @@ int16_t RF69::setFrequencyDeviation(float freqDev) {
// set frequency deviation from carrier frequency // set frequency deviation from carrier frequency
uint32_t fdev = (newFreqDev * (uint32_t(1) << RADIOLIB_RF69_DIV_EXPONENT)) / 32000; uint32_t fdev = (newFreqDev * (uint32_t(1) << RADIOLIB_RF69_DIV_EXPONENT)) / 32000;
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_MSB, (fdev & 0xFF00) >> 8, 5, 0); int16_t state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_MSB, (fdev & 0xFF00) >> 8, 5, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_LSB, fdev & 0x00FF, 7, 0); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_FDEV_LSB, fdev & 0x00FF, 7, 0);
return(state); return(state);
} }
int16_t RF69::getFrequencyDeviation(float *freqDev) { int16_t RF69::getFrequencyDeviation(float *freqDev) {
if (freqDev == NULL) { if(freqDev == NULL) {
return(RADIOLIB_ERR_NULL_POINTER); return(RADIOLIB_ERR_NULL_POINTER);
} }
if (RF69::_ook) { if(this->ookEnabled) {
*freqDev = 0.0; *freqDev = 0.0;
return(RADIOLIB_ERR_NONE); return(RADIOLIB_ERR_NONE);
@ -627,8 +627,8 @@ int16_t RF69::getFrequencyDeviation(float *freqDev) {
// get raw value from register // get raw value from register
uint32_t fdev = 0; uint32_t fdev = 0;
fdev |= (uint32_t)((_mod->SPIgetRegValue(RADIOLIB_RF69_REG_FDEV_MSB, 5, 0) << 8) & 0x0000FF00); fdev |= (uint32_t)((this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_FDEV_MSB, 5, 0) << 8) & 0x0000FF00);
fdev |= (uint32_t)((_mod->SPIgetRegValue(RADIOLIB_RF69_REG_FDEV_LSB, 7, 0) << 0) & 0x000000FF); fdev |= (uint32_t)((this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_FDEV_LSB, 7, 0) << 0) & 0x000000FF);
// calculate frequency deviation from raw value obtained from register // calculate frequency deviation from raw value obtained from register
// Fdev = Fstep * Fdev(13:0) (pag. 20 of datasheet) // Fdev = Fstep * Fdev(13:0) (pag. 20 of datasheet)
@ -638,11 +638,11 @@ int16_t RF69::getFrequencyDeviation(float *freqDev) {
return(RADIOLIB_ERR_NONE); return(RADIOLIB_ERR_NONE);
} }
int16_t RF69::setOutputPower(int8_t power, bool highPower) { int16_t RF69::setOutputPower(int8_t pwr, bool highPower) {
if(highPower) { if(highPower) {
RADIOLIB_CHECK_RANGE(power, -2, 20, RADIOLIB_ERR_INVALID_OUTPUT_POWER); RADIOLIB_CHECK_RANGE(pwr, -2, 20, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
} else { } else {
RADIOLIB_CHECK_RANGE(power, -18, 13, RADIOLIB_ERR_INVALID_OUTPUT_POWER); RADIOLIB_CHECK_RANGE(pwr, -18, 13, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
} }
// set mode to standby // set mode to standby
@ -652,25 +652,25 @@ int16_t RF69::setOutputPower(int8_t power, bool highPower) {
int16_t state; int16_t state;
if(highPower) { if(highPower) {
// check if both PA1 and PA2 are needed // check if both PA1 and PA2 are needed
if(power <= 10) { if(pwr <= 10) {
// -2 to 13 dBm, PA1 is enough // -2 to 13 dBm, PA1 is enough
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_OFF | RADIOLIB_RF69_PA1_ON | RADIOLIB_RF69_PA2_OFF | (power + 18), 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_OFF | RADIOLIB_RF69_PA1_ON | RADIOLIB_RF69_PA2_OFF | (power + 18), 7, 0);
} else if(power <= 17) { } else if(pwr <= 17) {
// 13 to 17 dBm, both PAs required // 13 to 17 dBm, both PAs required
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_OFF | RADIOLIB_RF69_PA1_ON | RADIOLIB_RF69_PA2_ON | (power + 14), 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_OFF | RADIOLIB_RF69_PA1_ON | RADIOLIB_RF69_PA2_ON | (power + 14), 7, 0);
} else { } else {
// 18 - 20 dBm, both PAs and hig power settings required // 18 - 20 dBm, both PAs and hig power settings required
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_OFF | RADIOLIB_RF69_PA1_ON | RADIOLIB_RF69_PA2_ON | (power + 11), 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_OFF | RADIOLIB_RF69_PA1_ON | RADIOLIB_RF69_PA2_ON | (power + 11), 7, 0);
} }
} else { } else {
// low power module, use only PA0 // low power module, use only PA0
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_ON | RADIOLIB_RF69_PA1_OFF | RADIOLIB_RF69_PA2_OFF | (power + 18), 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PA_LEVEL, RADIOLIB_RF69_PA0_ON | RADIOLIB_RF69_PA1_OFF | RADIOLIB_RF69_PA2_OFF | (power + 18), 7, 0);
} }
// cache the power value // cache the power value
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_power = power; this->power = pwr;
} }
return(state); return(state);
@ -693,10 +693,10 @@ int16_t RF69::setSyncWord(uint8_t* syncWord, size_t len, uint8_t maxErrBits) {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set sync word register // set sync word register
_mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_SYNC_VALUE_1, syncWord, len); this->mod->SPIwriteRegisterBurst(RADIOLIB_RF69_REG_SYNC_VALUE_1, syncWord, len);
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_syncWordLength = len; this->syncWordLength = len;
} }
return(state); return(state);
@ -709,44 +709,44 @@ int16_t RF69::setPreambleLength(uint8_t preambleLen) {
} }
uint8_t preLenBytes = preambleLen / 8; uint8_t preLenBytes = preambleLen / 8;
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_PREAMBLE_MSB, 0x00); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_PREAMBLE_MSB, 0x00);
return (_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PREAMBLE_LSB, preLenBytes)); return (this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PREAMBLE_LSB, preLenBytes));
} }
int16_t RF69::setNodeAddress(uint8_t nodeAddr) { int16_t RF69::setNodeAddress(uint8_t nodeAddr) {
// enable address filtering (node only) // enable address filtering (node only)
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_ADDRESS_FILTERING_NODE, 2, 1); int16_t state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_ADDRESS_FILTERING_NODE, 2, 1);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set node address // set node address
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_NODE_ADRS, nodeAddr)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_NODE_ADRS, nodeAddr));
} }
int16_t RF69::setBroadcastAddress(uint8_t broadAddr) { int16_t RF69::setBroadcastAddress(uint8_t broadAddr) {
// enable address filtering (node + broadcast) // enable address filtering (node + broadcast)
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST, 2, 1); int16_t state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_ADDRESS_FILTERING_NODE_BROADCAST, 2, 1);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set broadcast address // set broadcast address
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_BROADCAST_ADRS, broadAddr)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_BROADCAST_ADRS, broadAddr));
} }
int16_t RF69::disableAddressFiltering() { int16_t RF69::disableAddressFiltering() {
// disable address filtering // disable address filtering
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_ADDRESS_FILTERING_OFF, 2, 1); int16_t state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_ADDRESS_FILTERING_OFF, 2, 1);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set node address to default (0x00) // set node address to default (0x00)
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_NODE_ADRS, 0x00); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_NODE_ADRS, 0x00);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set broadcast address to default (0x00) // set broadcast address to default (0x00)
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_BROADCAST_ADRS, 0x00)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_BROADCAST_ADRS, 0x00));
} }
void RF69::setAmbientTemperature(int16_t tempAmbient) { void RF69::setAmbientTemperature(int16_t tempAmbient) {
_tempOffset = getTemperature() - tempAmbient; this->tempOffset = getTemperature() - tempAmbient;
} }
int16_t RF69::getTemperature() { int16_t RF69::getTemperature() {
@ -754,29 +754,29 @@ int16_t RF69::getTemperature() {
setMode(RADIOLIB_RF69_STANDBY); setMode(RADIOLIB_RF69_STANDBY);
// start temperature measurement // start temperature measurement
_mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEMP_1, RADIOLIB_RF69_TEMP_MEAS_START, 3, 3); this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEMP_1, RADIOLIB_RF69_TEMP_MEAS_START, 3, 3);
// wait until measurement is finished // wait until measurement is finished
while(_mod->SPIgetRegValue(RADIOLIB_RF69_REG_TEMP_1, 2, 2) == RADIOLIB_RF69_TEMP_MEAS_RUNNING) { while(this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_TEMP_1, 2, 2) == RADIOLIB_RF69_TEMP_MEAS_RUNNING) {
// check every 10 us // check every 10 us
_mod->hal->delay(10); this->mod->hal->delay(10);
} }
int8_t rawTemp = _mod->SPIgetRegValue(RADIOLIB_RF69_REG_TEMP_2); int8_t rawTemp = this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_TEMP_2);
return(0 - (rawTemp + _tempOffset)); return(0 - (rawTemp + this->tempOffset));
} }
size_t RF69::getPacketLength(bool update) { size_t RF69::getPacketLength(bool update) {
if(!_packetLengthQueried && update) { if(!this->packetLengthQueried && update) {
if (_packetLengthConfig == RADIOLIB_RF69_PACKET_FORMAT_VARIABLE) { if (this->packetLengthConfig == RADIOLIB_RF69_PACKET_FORMAT_VARIABLE) {
_packetLength = _mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO); this->packetLength = this->mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO);
} else { } else {
_packetLength = _mod->SPIreadRegister(RADIOLIB_RF69_REG_PAYLOAD_LENGTH); this->packetLength = this->mod->SPIreadRegister(RADIOLIB_RF69_REG_PAYLOAD_LENGTH);
} }
_packetLengthQueried = true; this->packetLengthQueried = true;
} }
return(_packetLength); return(this->packetLength);
} }
int16_t RF69::fixedPacketLengthMode(uint8_t len) { int16_t RF69::fixedPacketLengthMode(uint8_t len) {
@ -789,27 +789,27 @@ int16_t RF69::variablePacketLengthMode(uint8_t maxLen) {
int16_t RF69::enableSyncWordFiltering(uint8_t maxErrBits) { int16_t RF69::enableSyncWordFiltering(uint8_t maxErrBits) {
// enable sync word recognition // enable sync word recognition
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_SYNC_CONFIG, RADIOLIB_RF69_SYNC_ON | RADIOLIB_RF69_FIFO_FILL_CONDITION_SYNC | (_syncWordLength - 1) << 3 | maxErrBits, 7, 0)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_SYNC_CONFIG, RADIOLIB_RF69_SYNC_ON | RADIOLIB_RF69_FIFO_FILL_CONDITION_SYNC | (this->syncWordLength - 1) << 3 | maxErrBits, 7, 0));
} }
int16_t RF69::disableSyncWordFiltering() { int16_t RF69::disableSyncWordFiltering() {
// disable sync word detection and generation // disable sync word detection and generation
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_SYNC_CONFIG, RADIOLIB_RF69_SYNC_OFF | RADIOLIB_RF69_FIFO_FILL_CONDITION, 7, 6)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_SYNC_CONFIG, RADIOLIB_RF69_SYNC_OFF | RADIOLIB_RF69_FIFO_FILL_CONDITION, 7, 6));
} }
int16_t RF69::enableContinuousModeBitSync() { int16_t RF69::enableContinuousModeBitSync() {
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE_WITH_SYNC, 6, 5); int16_t state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE_WITH_SYNC, 6, 5);
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_bitSync = true; this->bitSync = true;
} }
return(state); return(state);
} }
int16_t RF69::disableContinuousModeBitSync() { int16_t RF69::disableContinuousModeBitSync() {
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE, 6, 5); int16_t state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_CONTINUOUS_MODE, 6, 5);
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_bitSync = false; this->bitSync = false;
} }
return(state); return(state);
@ -817,20 +817,20 @@ int16_t RF69::disableContinuousModeBitSync() {
int16_t RF69::setCrcFiltering(bool crcOn) { int16_t RF69::setCrcFiltering(bool crcOn) {
if (crcOn == true) { if (crcOn == true) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_CRC_ON, 4, 4)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_CRC_ON, 4, 4));
} else { } else {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_CRC_OFF, 4, 4)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_CRC_OFF, 4, 4));
} }
} }
int16_t RF69::setPromiscuousMode(bool promiscuous) { int16_t RF69::setPromiscuousMode(bool enable) {
int16_t state = RADIOLIB_ERR_NONE; int16_t state = RADIOLIB_ERR_NONE;
if (_promiscuous == promiscuous) { if (this->promiscuous == enable) {
return(state); return(state);
} }
if (promiscuous == true) { if (enable == true) {
// disable preamble detection and generation // disable preamble detection and generation
state = setPreambleLength(0); state = setPreambleLength(0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
@ -854,7 +854,7 @@ int16_t RF69::setPromiscuousMode(bool promiscuous) {
state = setCrcFiltering(true); state = setCrcFiltering(true);
} }
if(state == RADIOLIB_ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
_promiscuous = promiscuous; this->promiscuous = enable;
} }
@ -869,13 +869,13 @@ int16_t RF69::setDataShaping(uint8_t sh) {
// set data shaping // set data shaping
switch(sh) { switch(sh) {
case RADIOLIB_SHAPING_NONE: case RADIOLIB_SHAPING_NONE:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_NO_SHAPING, 1, 0)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_NO_SHAPING, 1, 0));
case RADIOLIB_SHAPING_0_3: case RADIOLIB_SHAPING_0_3:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_0_3, 1, 0)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_0_3, 1, 0));
case RADIOLIB_SHAPING_0_5: case RADIOLIB_SHAPING_0_5:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_0_5, 1, 0)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_0_5, 1, 0));
case RADIOLIB_SHAPING_1_0: case RADIOLIB_SHAPING_1_0:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_1_0, 1, 0)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_1_0, 1, 0));
default: default:
return(RADIOLIB_ERR_INVALID_DATA_SHAPING); return(RADIOLIB_ERR_INVALID_DATA_SHAPING);
} }
@ -889,11 +889,11 @@ int16_t RF69::setEncoding(uint8_t encoding) {
// set encoding // set encoding
switch(encoding) { switch(encoding) {
case RADIOLIB_ENCODING_NRZ: case RADIOLIB_ENCODING_NRZ:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_DC_FREE_NONE, 6, 5)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_DC_FREE_NONE, 6, 5));
case RADIOLIB_ENCODING_MANCHESTER: case RADIOLIB_ENCODING_MANCHESTER:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_DC_FREE_MANCHESTER, 6, 5)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_DC_FREE_MANCHESTER, 6, 5));
case RADIOLIB_ENCODING_WHITENING: case RADIOLIB_ENCODING_WHITENING:
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_DC_FREE_WHITENING, 6, 5)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_DC_FREE_WHITENING, 6, 5));
default: default:
return(RADIOLIB_ERR_INVALID_ENCODING); return(RADIOLIB_ERR_INVALID_ENCODING);
} }
@ -901,28 +901,28 @@ int16_t RF69::setEncoding(uint8_t encoding) {
int16_t RF69::setLnaTestBoost(bool value) { int16_t RF69::setLnaTestBoost(bool value) {
if(value) { if(value) {
return (_mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_LNA, RADIOLIB_RF69_TEST_LNA_BOOST_HIGH, 7, 0)); return (this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_LNA, RADIOLIB_RF69_TEST_LNA_BOOST_HIGH, 7, 0));
} }
return(_mod->SPIsetRegValue(RADIOLIB_RF69_TEST_LNA_BOOST_NORMAL, RADIOLIB_RF69_TEST_LNA_BOOST_HIGH, 7, 0)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_TEST_LNA_BOOST_NORMAL, RADIOLIB_RF69_TEST_LNA_BOOST_HIGH, 7, 0));
} }
float RF69::getRSSI() { float RF69::getRSSI() {
return(-1.0 * (_mod->SPIgetRegValue(RADIOLIB_RF69_REG_RSSI_VALUE)/2.0)); return(-1.0 * (this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_RSSI_VALUE)/2.0));
} }
int16_t RF69::setRSSIThreshold(float dbm) { int16_t RF69::setRSSIThreshold(float dbm) {
RADIOLIB_CHECK_RANGE(dbm, -127.5, 0, RADIOLIB_ERR_INVALID_RSSI_THRESHOLD); RADIOLIB_CHECK_RANGE(dbm, -127.5, 0, RADIOLIB_ERR_INVALID_RSSI_THRESHOLD);
return _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RSSI_THRESH, (uint8_t)(-2.0 * dbm), 7, 0); return this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_RSSI_THRESH, (uint8_t)(-2.0 * dbm), 7, 0);
} }
void RF69::setRfSwitchPins(uint32_t rxEn, uint32_t txEn) { void RF69::setRfSwitchPins(uint32_t rxEn, uint32_t txEn) {
_mod->setRfSwitchPins(rxEn, txEn); this->mod->setRfSwitchPins(rxEn, txEn);
} }
void RF69::setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]) { void RF69::setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]) {
_mod->setRfSwitchTable(pins, table); this->mod->setRfSwitchTable(pins, table);
} }
uint8_t RF69::randomByte() { uint8_t RF69::randomByte() {
@ -930,12 +930,12 @@ uint8_t RF69::randomByte() {
setMode(RADIOLIB_RF69_RX); setMode(RADIOLIB_RF69_RX);
// wait a bit for the RSSI reading to stabilise // wait a bit for the RSSI reading to stabilise
_mod->hal->delay(10); this->mod->hal->delay(10);
// read RSSI value 8 times, always keep just the least significant bit // read RSSI value 8 times, always keep just the least significant bit
uint8_t randByte = 0x00; uint8_t randByte = 0x00;
for(uint8_t i = 0; i < 8; i++) { for(uint8_t i = 0; i < 8; i++) {
randByte |= ((_mod->SPIreadRegister(RADIOLIB_RF69_REG_RSSI_VALUE) & 0x01) << i); randByte |= ((this->mod->SPIreadRegister(RADIOLIB_RF69_REG_RSSI_VALUE) & 0x01) << i);
} }
// set mode to standby // set mode to standby
@ -950,7 +950,7 @@ void RF69::setDirectAction(void (*func)(void)) {
} }
void RF69::readBit(uint32_t pin) { void RF69::readBit(uint32_t pin) {
updateDirectBuffer((uint8_t)_mod->hal->digitalRead(pin)); updateDirectBuffer((uint8_t)this->mod->hal->digitalRead(pin));
} }
#endif #endif
@ -960,14 +960,14 @@ int16_t RF69::setDIOMapping(uint32_t pin, uint32_t value) {
} }
if(pin < 4) { if(pin < 4) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, value, 7 - 2 * pin, 6 - 2 * pin)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_1, value, 7 - 2 * pin, 6 - 2 * pin));
} }
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_2, value, 15 - 2 * pin, 14 - 2 * pin)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_2, value, 15 - 2 * pin, 14 - 2 * pin));
} }
int16_t RF69::getChipVersion() { int16_t RF69::getChipVersion() {
return(_mod->SPIgetRegValue(RADIOLIB_RF69_REG_VERSION)); return(this->mod->SPIgetRegValue(RADIOLIB_RF69_REG_VERSION));
} }
int16_t RF69::config() { int16_t RF69::config() {
@ -978,50 +978,50 @@ int16_t RF69::config() {
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set operation modes // set operation modes
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OP_MODE, RADIOLIB_RF69_SEQUENCER_ON | RADIOLIB_RF69_LISTEN_OFF, 7, 6); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OP_MODE, RADIOLIB_RF69_SEQUENCER_ON | RADIOLIB_RF69_LISTEN_OFF, 7, 6);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// enable over-current protection // enable over-current protection
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON, 4, 4); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON, 4, 4);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set data mode, modulation type and shaping // set data mode, modulation type and shaping
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_PACKET_MODE | RADIOLIB_RF69_FSK, 6, 3); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_PACKET_MODE | RADIOLIB_RF69_FSK, 6, 3);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_0_3, 1, 0); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DATA_MODUL, RADIOLIB_RF69_FSK_GAUSSIAN_0_3, 1, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set RSSI threshold // set RSSI threshold
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RSSI_THRESH, RADIOLIB_RF69_RSSI_THRESHOLD, 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_RSSI_THRESH, RADIOLIB_RF69_RSSI_THRESHOLD, 7, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// reset FIFO flag // reset FIFO flag
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_2, RADIOLIB_RF69_IRQ_FIFO_OVERRUN); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_2, RADIOLIB_RF69_IRQ_FIFO_OVERRUN);
// disable ClkOut on DIO5 // disable ClkOut on DIO5
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_2, RADIOLIB_RF69_CLK_OUT_OFF, 2, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_DIO_MAPPING_2, RADIOLIB_RF69_CLK_OUT_OFF, 2, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set packet configuration and disable encryption // set packet configuration and disable encryption
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_PACKET_FORMAT_VARIABLE | RADIOLIB_RF69_DC_FREE_NONE | RADIOLIB_RF69_CRC_ON | RADIOLIB_RF69_CRC_AUTOCLEAR_ON | RADIOLIB_RF69_ADDRESS_FILTERING_OFF, 7, 1); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, RADIOLIB_RF69_PACKET_FORMAT_VARIABLE | RADIOLIB_RF69_DC_FREE_NONE | RADIOLIB_RF69_CRC_ON | RADIOLIB_RF69_CRC_AUTOCLEAR_ON | RADIOLIB_RF69_ADDRESS_FILTERING_OFF, 7, 1);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_INTER_PACKET_RX_DELAY, 7, 4); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_INTER_PACKET_RX_DELAY, 7, 4);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_AUTO_RX_RESTART_ON | RADIOLIB_RF69_AES_OFF, 1, 0); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_2, RADIOLIB_RF69_AUTO_RX_RESTART_ON | RADIOLIB_RF69_AES_OFF, 1, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set payload length // set payload length
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PAYLOAD_LENGTH, RADIOLIB_RF69_PAYLOAD_LENGTH, 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PAYLOAD_LENGTH, RADIOLIB_RF69_PAYLOAD_LENGTH, 7, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set FIFO threshold // set FIFO threshold
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_FIFO_THRESH, RADIOLIB_RF69_TX_START_CONDITION_FIFO_NOT_EMPTY | RADIOLIB_RF69_FIFO_THRESH, 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_FIFO_THRESH, RADIOLIB_RF69_TX_START_CONDITION_FIFO_NOT_EMPTY | RADIOLIB_RF69_FIFO_THRESH, 7, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set Rx timeouts // set Rx timeouts
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_1, RADIOLIB_RF69_TIMEOUT_RX_START, 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_1, RADIOLIB_RF69_TIMEOUT_RX_START, 7, 0);
state |= _mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_2, RADIOLIB_RF69_TIMEOUT_RSSI_THRESH, 7, 0); state |= this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_RX_TIMEOUT_2, RADIOLIB_RF69_TIMEOUT_RSSI_THRESH, 7, 0);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// enable improved fading margin // enable improved fading margin
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_DAGC, RADIOLIB_RF69_CONTINUOUS_DAGC_LOW_BETA_OFF, 7, 0); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_TEST_DAGC, RADIOLIB_RF69_CONTINUOUS_DAGC_LOW_BETA_OFF, 7, 0);
return(state); return(state);
} }
@ -1033,30 +1033,30 @@ int16_t RF69::setPacketMode(uint8_t mode, uint8_t len) {
} }
// set to fixed packet length // set to fixed packet length
int16_t state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, mode, 7, 7); int16_t state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PACKET_CONFIG_1, mode, 7, 7);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// set length to register // set length to register
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_PAYLOAD_LENGTH, len); state = this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_PAYLOAD_LENGTH, len);
RADIOLIB_ASSERT(state); RADIOLIB_ASSERT(state);
// update the cached value // update the cached value
_packetLengthConfig = mode; this->packetLengthConfig = mode;
return(state); return(state);
} }
int16_t RF69::setMode(uint8_t mode) { int16_t RF69::setMode(uint8_t mode) {
return(_mod->SPIsetRegValue(RADIOLIB_RF69_REG_OP_MODE, mode, 4, 2)); return(this->mod->SPIsetRegValue(RADIOLIB_RF69_REG_OP_MODE, mode, 4, 2));
} }
void RF69::clearIRQFlags() { void RF69::clearIRQFlags() {
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_1, 0b11111111); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_1, 0b11111111);
_mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_2, 0b11111111); this->mod->SPIwriteRegister(RADIOLIB_RF69_REG_IRQ_FLAGS_2, 0b11111111);
} }
void RF69::clearFIFO(size_t count) { void RF69::clearFIFO(size_t count) {
while(count) { while(count) {
_mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO); this->mod->SPIreadRegister(RADIOLIB_RF69_REG_FIFO);
count--; count--;
} }
} }

File diff suppressed because it is too large Load diff