[nRF24] General reformatting
This commit is contained in:
parent
a015e541f6
commit
bba644377a
2 changed files with 274 additions and 387 deletions
|
@ -3,32 +3,32 @@
|
|||
#if !defined(RADIOLIB_EXCLUDE_NRF24)
|
||||
|
||||
nRF24::nRF24(Module* mod) : PhysicalLayer(RADIOLIB_NRF24_FREQUENCY_STEP_SIZE, RADIOLIB_NRF24_MAX_PACKET_LENGTH) {
|
||||
_mod = mod;
|
||||
this->mod = mod;
|
||||
}
|
||||
|
||||
Module* nRF24::getMod() {
|
||||
return(_mod);
|
||||
return(this->mod);
|
||||
}
|
||||
|
||||
int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrWidth) {
|
||||
int16_t nRF24::begin(int16_t freq, int16_t dr, int8_t pwr, uint8_t addrWidth) {
|
||||
// set module properties
|
||||
_mod->SPIreadCommand = RADIOLIB_NRF24_CMD_READ;
|
||||
_mod->SPIwriteCommand = RADIOLIB_NRF24_CMD_WRITE;
|
||||
_mod->init();
|
||||
_mod->hal->pinMode(_mod->getIrq(), _mod->hal->GpioModeInput);
|
||||
this->mod->SPIreadCommand = RADIOLIB_NRF24_CMD_READ;
|
||||
this->mod->SPIwriteCommand = RADIOLIB_NRF24_CMD_WRITE;
|
||||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
|
||||
// set pin mode on RST (connected to nRF24 CE pin)
|
||||
_mod->hal->pinMode(_mod->getRst(), _mod->hal->GpioModeOutput);
|
||||
_mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelLow);
|
||||
this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
|
||||
|
||||
// wait for minimum power-on reset duration
|
||||
_mod->hal->delay(100);
|
||||
this->mod->hal->delay(100);
|
||||
|
||||
// check SPI connection
|
||||
int16_t val = _mod->SPIgetRegValue(RADIOLIB_NRF24_REG_SETUP_AW);
|
||||
int16_t val = this->mod->SPIgetRegValue(RADIOLIB_NRF24_REG_SETUP_AW);
|
||||
if(!((val >= 0) && (val <= 3))) {
|
||||
RADIOLIB_DEBUG_PRINTLN("No nRF24 found!");
|
||||
_mod->term();
|
||||
this->mod->term();
|
||||
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN("M\tnRF24");
|
||||
|
@ -46,11 +46,11 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW
|
|||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set data rate
|
||||
state = setBitRate(dataRate);
|
||||
state = setBitRate(dr);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set output power
|
||||
state = setOutputPower(power);
|
||||
state = setOutputPower(pwr);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set address width
|
||||
|
@ -69,7 +69,7 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW
|
|||
}
|
||||
|
||||
int16_t nRF24::sleep() {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_DOWN, 1, 1));
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_DOWN, 1, 1));
|
||||
}
|
||||
|
||||
int16_t nRF24::standby() {
|
||||
|
@ -78,12 +78,12 @@ int16_t nRF24::standby() {
|
|||
|
||||
int16_t nRF24::standby(uint8_t mode) {
|
||||
// make sure carrier output is disabled
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_OFF, 7, 7);
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_OFF, 4, 4);
|
||||
_mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelLow);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_OFF, 7, 7);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_OFF, 4, 4);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
|
||||
|
||||
// use standby-1 mode
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, mode, 1, 1));
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, mode, 1, 1));
|
||||
}
|
||||
|
||||
int16_t nRF24::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
|
@ -92,9 +92,9 @@ int16_t nRF24::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// wait until transmission is finished
|
||||
uint32_t start = _mod->hal->micros();
|
||||
while(_mod->hal->digitalRead(_mod->getIrq())) {
|
||||
_mod->hal->yield();
|
||||
uint32_t start = this->mod->hal->micros();
|
||||
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
|
||||
this->mod->hal->yield();
|
||||
|
||||
// check maximum number of retransmits
|
||||
if(getStatus(RADIOLIB_NRF24_MAX_RT)) {
|
||||
|
@ -103,7 +103,7 @@ int16_t nRF24::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
}
|
||||
|
||||
// check timeout: 15 retries * 4ms (max Tx time as per datasheet)
|
||||
if(_mod->hal->micros() - start >= 60000) {
|
||||
if(this->mod->hal->micros() - start >= 60000) {
|
||||
finishTransmit();
|
||||
return(RADIOLIB_ERR_TX_TIMEOUT);
|
||||
}
|
||||
|
@ -118,12 +118,12 @@ int16_t nRF24::receive(uint8_t* data, size_t len) {
|
|||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// wait for Rx_DataReady or timeout
|
||||
uint32_t start = _mod->hal->micros();
|
||||
while(_mod->hal->digitalRead(_mod->getIrq())) {
|
||||
_mod->hal->yield();
|
||||
uint32_t start = this->mod->hal->micros();
|
||||
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
|
||||
this->mod->hal->yield();
|
||||
|
||||
// check timeout: 15 retries * 4ms (max Tx time as per datasheet)
|
||||
if(_mod->hal->micros() - start >= 60000) {
|
||||
if(this->mod->hal->micros() - start >= 60000) {
|
||||
standby();
|
||||
clearIRQ();
|
||||
return(RADIOLIB_ERR_RX_TIMEOUT);
|
||||
|
@ -138,14 +138,14 @@ int16_t nRF24::transmitDirect(uint32_t frf) {
|
|||
// set raw frequency value
|
||||
if(frf != 0) {
|
||||
uint8_t freqRaw = frf - 2400;
|
||||
_mod->SPIwriteRegister(RADIOLIB_NRF24_REG_RF_CH, freqRaw & 0b01111111);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_NRF24_REG_RF_CH, freqRaw & 0b01111111);
|
||||
}
|
||||
|
||||
// output carrier
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_ON, 7, 7);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_ON, 4, 4);
|
||||
_mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelHigh);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_ON, 7, 7);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_ON, 4, 4);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
|
||||
return(state);
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ int16_t nRF24::receiveDirect() {
|
|||
}
|
||||
|
||||
void nRF24::setIrqAction(void (*func)(void)) {
|
||||
_mod->hal->attachInterrupt(_mod->hal->pinToInterrupt(_mod->getIrq()), func, _mod->hal->GpioInterruptFalling);
|
||||
this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, this->mod->hal->GpioInterruptFalling);
|
||||
}
|
||||
|
||||
int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
|
@ -173,13 +173,13 @@ int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable primary Tx mode
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
|
||||
|
||||
// clear interrupts
|
||||
clearIRQ();
|
||||
|
||||
// enable Tx_DataSent interrupt
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON, 5, 5);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON, 5, 5);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// flush Tx FIFO
|
||||
|
@ -192,9 +192,9 @@ int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
SPIwriteTxPayload(data, len);
|
||||
|
||||
// CE high to start transmitting
|
||||
_mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelHigh);
|
||||
_mod->hal->delay(1);
|
||||
_mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelLow);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
|
||||
this->mod->hal->delay(1);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
@ -213,22 +213,22 @@ int16_t nRF24::startReceive() {
|
|||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable primary Rx mode
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PRX, 0, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PRX, 0, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable Rx_DataReady interrupt
|
||||
clearIRQ();
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON, 6, 6);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON, 6, 6);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// flush Rx FIFO
|
||||
SPItransfer(RADIOLIB_NRF24_CMD_FLUSH_RX);
|
||||
|
||||
// CE high to start receiving
|
||||
_mod->hal->digitalWrite(_mod->getRst(), _mod->hal->GpioLevelHigh);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
|
||||
|
||||
// wait to enter Rx state
|
||||
_mod->hal->delay(1);
|
||||
this->mod->hal->delay(1);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
@ -267,10 +267,10 @@ int16_t nRF24::setFrequency(float freq) {
|
|||
|
||||
// set frequency
|
||||
uint8_t freqRaw = (uint16_t)freq - 2400;
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0);
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
_freq = freq;
|
||||
this->frequency = freq;
|
||||
}
|
||||
|
||||
return(state);
|
||||
|
@ -284,20 +284,20 @@ int16_t nRF24::setBitRate(float br) {
|
|||
// set data rate
|
||||
uint16_t dataRate = (uint16_t)br;
|
||||
if(dataRate == 250) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 5, 5);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 3, 3);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 5, 5);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 3, 3);
|
||||
} else if(dataRate == 1000) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 5, 5);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 3, 3);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 5, 5);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 3, 3);
|
||||
} else if(dataRate == 2000) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 5, 5);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 3, 3);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 5, 5);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 3, 3);
|
||||
} else {
|
||||
return(RADIOLIB_ERR_INVALID_DATA_RATE);
|
||||
}
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
_dataRate = dataRate;
|
||||
this->dataRate = dataRate;
|
||||
}
|
||||
|
||||
|
||||
|
@ -329,10 +329,10 @@ int16_t nRF24::setOutputPower(int8_t power) {
|
|||
}
|
||||
|
||||
// write new register value
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, powerRaw, 2, 1);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, powerRaw, 2, 1);
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
_power = power;
|
||||
this->power = power;
|
||||
}
|
||||
|
||||
|
||||
|
@ -349,16 +349,16 @@ int16_t nRF24::setAddressWidth(uint8_t addrWidth) {
|
|||
case 2:
|
||||
// Even if marked as 'Illegal' on the datasheet this will work:
|
||||
// http://travisgoodspeed.blogspot.com/2011/02/promiscuity-is-nrf24l01s-duty.html
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_2_BYTES, 1, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_2_BYTES, 1, 0);
|
||||
break;
|
||||
case 3:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_3_BYTES, 1, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_3_BYTES, 1, 0);
|
||||
break;
|
||||
case 4:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_4_BYTES, 1, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_4_BYTES, 1, 0);
|
||||
break;
|
||||
case 5:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_5_BYTES, 1, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_5_BYTES, 1, 0);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_ADDRESS_WIDTH);
|
||||
|
@ -366,7 +366,7 @@ int16_t nRF24::setAddressWidth(uint8_t addrWidth) {
|
|||
|
||||
// save address width
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
_addrWidth = addrWidth;
|
||||
this->addressWidth = addrWidth;
|
||||
}
|
||||
|
||||
return(state);
|
||||
|
@ -378,11 +378,11 @@ int16_t nRF24::setTransmitPipe(uint8_t* addr) {
|
|||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set transmit address
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_TX_ADDR, addr, _addrWidth);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_TX_ADDR, addr, this->addressWidth);
|
||||
|
||||
// set Rx pipe 0 address (for ACK)
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, _addrWidth);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, this->addressWidth);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
@ -395,12 +395,12 @@ int16_t nRF24::setReceivePipe(uint8_t pipeNum, uint8_t* addr) {
|
|||
// write full pipe 0 - 1 address and enable the pipe
|
||||
switch(pipeNum) {
|
||||
case 0:
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, _addrWidth);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, this->addressWidth);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
|
||||
break;
|
||||
case 1:
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P1, addr, _addrWidth);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_ON, 1, 1);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P1, addr, this->addressWidth);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_ON, 1, 1);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_PIPE_NUMBER);
|
||||
|
@ -417,20 +417,20 @@ int16_t nRF24::setReceivePipe(uint8_t pipeNum, uint8_t addrByte) {
|
|||
// write unique pipe 2 - 5 address and enable the pipe
|
||||
switch(pipeNum) {
|
||||
case 2:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P2, addrByte);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_ON, 2, 2);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P2, addrByte);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_ON, 2, 2);
|
||||
break;
|
||||
case 3:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P3, addrByte);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_ON, 3, 3);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P3, addrByte);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_ON, 3, 3);
|
||||
break;
|
||||
case 4:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P4, addrByte);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_ON, 4, 4);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P4, addrByte);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_ON, 4, 4);
|
||||
break;
|
||||
case 5:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P5, addrByte);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_ON, 5, 5);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P5, addrByte);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_ON, 5, 5);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_PIPE_NUMBER);
|
||||
|
@ -446,22 +446,22 @@ int16_t nRF24::disablePipe(uint8_t pipeNum) {
|
|||
|
||||
switch(pipeNum) {
|
||||
case 0:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_OFF, 0, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_OFF, 0, 0);
|
||||
break;
|
||||
case 1:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_OFF, 1, 1);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_OFF, 1, 1);
|
||||
break;
|
||||
case 2:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_OFF, 2, 2);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_OFF, 2, 2);
|
||||
break;
|
||||
case 3:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_OFF, 3, 3);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_OFF, 3, 3);
|
||||
break;
|
||||
case 4:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_OFF, 4, 4);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_OFF, 4, 4);
|
||||
break;
|
||||
case 5:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_OFF, 5, 5);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_OFF, 5, 5);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_PIPE_NUMBER);
|
||||
|
@ -471,11 +471,11 @@ int16_t nRF24::disablePipe(uint8_t pipeNum) {
|
|||
}
|
||||
|
||||
int16_t nRF24::getStatus(uint8_t mask) {
|
||||
return(_mod->SPIgetRegValue(RADIOLIB_NRF24_REG_STATUS) & mask);
|
||||
return(this->mod->SPIgetRegValue(RADIOLIB_NRF24_REG_STATUS) & mask);
|
||||
}
|
||||
|
||||
bool nRF24::isCarrierDetected() {
|
||||
return(_mod->SPIgetRegValue(RADIOLIB_NRF24_REG_RPD, 0, 0) == 1);
|
||||
return(this->mod->SPIgetRegValue(RADIOLIB_NRF24_REG_RPD, 0, 0) == 1);
|
||||
}
|
||||
|
||||
int16_t nRF24::setFrequencyDeviation(float freqDev) {
|
||||
|
@ -500,32 +500,32 @@ int16_t nRF24::setCrcFiltering(bool crcOn) {
|
|||
}
|
||||
|
||||
// Disable CRC
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, (crcOn ? RADIOLIB_NRF24_CRC_ON : RADIOLIB_NRF24_CRC_OFF), 3, 3);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, (crcOn ? RADIOLIB_NRF24_CRC_ON : RADIOLIB_NRF24_CRC_OFF), 3, 3);
|
||||
}
|
||||
|
||||
int16_t nRF24::setAutoAck(bool autoAckOn){
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_ALL_ON : RADIOLIB_NRF24_AA_ALL_OFF), 5, 0);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_ALL_ON : RADIOLIB_NRF24_AA_ALL_OFF), 5, 0);
|
||||
}
|
||||
|
||||
int16_t nRF24::setAutoAck(uint8_t pipeNum, bool autoAckOn){
|
||||
switch(pipeNum) {
|
||||
case 0:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P0_ON : RADIOLIB_NRF24_AA_P0_OFF), 0, 0);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P0_ON : RADIOLIB_NRF24_AA_P0_OFF), 0, 0);
|
||||
break;
|
||||
case 1:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P1_ON : RADIOLIB_NRF24_AA_P1_OFF), 1, 1);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P1_ON : RADIOLIB_NRF24_AA_P1_OFF), 1, 1);
|
||||
break;
|
||||
case 2:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P2_ON : RADIOLIB_NRF24_AA_P2_OFF), 2, 2);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P2_ON : RADIOLIB_NRF24_AA_P2_OFF), 2, 2);
|
||||
break;
|
||||
case 3:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P3_ON : RADIOLIB_NRF24_AA_P3_OFF), 3, 3);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P3_ON : RADIOLIB_NRF24_AA_P3_OFF), 3, 3);
|
||||
break;
|
||||
case 4:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P4_ON : RADIOLIB_NRF24_AA_P4_OFF), 4, 4);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P4_ON : RADIOLIB_NRF24_AA_P4_OFF), 4, 4);
|
||||
break;
|
||||
case 5:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P5_ON : RADIOLIB_NRF24_AA_P5_OFF), 5, 5);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P5_ON : RADIOLIB_NRF24_AA_P5_OFF), 5, 5);
|
||||
break;
|
||||
default:
|
||||
return (RADIOLIB_ERR_INVALID_PIPE_NUMBER);
|
||||
|
@ -546,63 +546,43 @@ int16_t nRF24::setEncoding(uint8_t encoding) {
|
|||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
uint8_t nRF24::randomByte() {
|
||||
// nRF24 is unable to measure RSSI, hence no TRNG
|
||||
// this method is implemented only for PhysicalLayer compatibility
|
||||
return(0);
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
void nRF24::setDirectAction(void (*func)(void)) {
|
||||
// nRF24 is unable to perform direct mode actions
|
||||
// this method is implemented only for PhysicalLayer compatibility
|
||||
(void)func;
|
||||
}
|
||||
|
||||
void nRF24::readBit(uint32_t pin) {
|
||||
// nRF24 is unable to perform direct mode actions
|
||||
// this method is implemented only for PhysicalLayer compatibility
|
||||
(void)pin;
|
||||
}
|
||||
#endif
|
||||
|
||||
void nRF24::clearIRQ() {
|
||||
// clear status bits
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
|
||||
|
||||
// disable interrupts
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF | RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF | RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF, 6, 4);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF | RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF | RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF, 6, 4);
|
||||
}
|
||||
|
||||
int16_t nRF24::config() {
|
||||
// enable 16-bit CRC
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_CRC_ON | RADIOLIB_NRF24_CRC_16, 3, 2);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_CRC_ON | RADIOLIB_NRF24_CRC_16, 3, 2);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set 15 retries and delay 1500 (5*250) us
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_RETR, (5 << 4) | 5);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_RETR, (5 << 4) | 5);
|
||||
|
||||
// set features: dynamic payload on, payload with ACK packets off, dynamic ACK off
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_FEATURE, RADIOLIB_NRF24_DPL_ON | RADIOLIB_NRF24_ACK_PAY_OFF | RADIOLIB_NRF24_DYN_ACK_OFF, 2, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_FEATURE, RADIOLIB_NRF24_DPL_ON | RADIOLIB_NRF24_ACK_PAY_OFF | RADIOLIB_NRF24_DYN_ACK_OFF, 2, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable dynamic payloads
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_DYNPD, RADIOLIB_NRF24_DPL_ALL_ON, 5, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_DYNPD, RADIOLIB_NRF24_DPL_ALL_ON, 5, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// reset IRQ
|
||||
clearIRQ();
|
||||
|
||||
// clear status
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
|
||||
|
||||
// flush FIFOs
|
||||
SPItransfer(RADIOLIB_NRF24_CMD_FLUSH_TX);
|
||||
SPItransfer(RADIOLIB_NRF24_CMD_FLUSH_RX);
|
||||
|
||||
// power up
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_UP, 1, 1);
|
||||
_mod->hal->delay(5);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_UP, 1, 1);
|
||||
this->mod->hal->delay(5);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
@ -617,26 +597,26 @@ void nRF24::SPIwriteTxPayload(uint8_t* data, uint8_t numBytes) {
|
|||
|
||||
void nRF24::SPItransfer(uint8_t cmd, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes) {
|
||||
// start transfer
|
||||
_mod->hal->digitalWrite(_mod->getCs(), _mod->hal->GpioLevelLow);
|
||||
_mod->hal->spiBeginTransaction();
|
||||
this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelLow);
|
||||
this->mod->hal->spiBeginTransaction();
|
||||
|
||||
// send command
|
||||
_mod->hal->spiTransfer(cmd);
|
||||
this->mod->hal->spiTransfer(cmd);
|
||||
|
||||
// send data
|
||||
if(write) {
|
||||
for(uint8_t i = 0; i < numBytes; i++) {
|
||||
_mod->hal->spiTransfer(dataOut[i]);
|
||||
this->mod->hal->spiTransfer(dataOut[i]);
|
||||
}
|
||||
} else {
|
||||
for(uint8_t i = 0; i < numBytes; i++) {
|
||||
dataIn[i] = _mod->hal->spiTransfer(0x00);
|
||||
dataIn[i] = this->mod->hal->spiTransfer(0x00);
|
||||
}
|
||||
}
|
||||
|
||||
// stop transfer
|
||||
_mod->hal->spiEndTransaction();
|
||||
_mod->hal->digitalWrite(_mod->getCs(), _mod->hal->GpioLevelHigh);
|
||||
this->mod->hal->spiEndTransaction();
|
||||
this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelHigh);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,180 +7,178 @@
|
|||
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
||||
|
||||
// nRF24 physical layer properties
|
||||
#define RADIOLIB_NRF24_FREQUENCY_STEP_SIZE 1000000.0
|
||||
#define RADIOLIB_NRF24_MAX_PACKET_LENGTH 32
|
||||
#define RADIOLIB_NRF24_FREQUENCY_STEP_SIZE 1000000.0
|
||||
#define RADIOLIB_NRF24_MAX_PACKET_LENGTH 32
|
||||
|
||||
// nRF24 SPI commands
|
||||
#define RADIOLIB_NRF24_CMD_READ 0b00000000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE 0b00100000
|
||||
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD 0b01100001
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD 0b10100000
|
||||
#define RADIOLIB_NRF24_CMD_FLUSH_TX 0b11100001
|
||||
#define RADIOLIB_NRF24_CMD_FLUSH_RX 0b11100010
|
||||
#define RADIOLIB_NRF24_CMD_REUSE_TX_PAXLOAD 0b11100011
|
||||
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD_WIDTH 0b01100000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_ACK_PAYLOAD 0b10101000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD_NOACK 0b10110000
|
||||
#define RADIOLIB_NRF24_CMD_NOP 0b11111111
|
||||
#define RADIOLIB_NRF24_CMD_READ 0b00000000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE 0b00100000
|
||||
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD 0b01100001
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD 0b10100000
|
||||
#define RADIOLIB_NRF24_CMD_FLUSH_TX 0b11100001
|
||||
#define RADIOLIB_NRF24_CMD_FLUSH_RX 0b11100010
|
||||
#define RADIOLIB_NRF24_CMD_REUSE_TX_PAXLOAD 0b11100011
|
||||
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD_WIDTH 0b01100000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_ACK_PAYLOAD 0b10101000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD_NOACK 0b10110000
|
||||
#define RADIOLIB_NRF24_CMD_NOP 0b11111111
|
||||
|
||||
// nRF24 register map
|
||||
#define RADIOLIB_NRF24_REG_CONFIG 0x00
|
||||
#define RADIOLIB_NRF24_REG_EN_AA 0x01
|
||||
#define RADIOLIB_NRF24_REG_EN_RXADDR 0x02
|
||||
#define RADIOLIB_NRF24_REG_SETUP_AW 0x03
|
||||
#define RADIOLIB_NRF24_REG_SETUP_RETR 0x04
|
||||
#define RADIOLIB_NRF24_REG_RF_CH 0x05
|
||||
#define RADIOLIB_NRF24_REG_RF_SETUP 0x06
|
||||
#define RADIOLIB_NRF24_REG_STATUS 0x07
|
||||
#define RADIOLIB_NRF24_REG_OBSERVE_TX 0x08
|
||||
#define RADIOLIB_NRF24_REG_RPD 0x09
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P0 0x0A
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P1 0x0B
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P2 0x0C
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P3 0x0D
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P4 0x0E
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P5 0x0F
|
||||
#define RADIOLIB_NRF24_REG_TX_ADDR 0x10
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P0 0x11
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P1 0x12
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P2 0x13
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P3 0x14
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P4 0x15
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P5 0x16
|
||||
#define RADIOLIB_NRF24_REG_FIFO_STATUS 0x17
|
||||
#define RADIOLIB_NRF24_REG_DYNPD 0x1C
|
||||
#define RADIOLIB_NRF24_REG_FEATURE 0x1D
|
||||
#define RADIOLIB_NRF24_REG_CONFIG 0x00
|
||||
#define RADIOLIB_NRF24_REG_EN_AA 0x01
|
||||
#define RADIOLIB_NRF24_REG_EN_RXADDR 0x02
|
||||
#define RADIOLIB_NRF24_REG_SETUP_AW 0x03
|
||||
#define RADIOLIB_NRF24_REG_SETUP_RETR 0x04
|
||||
#define RADIOLIB_NRF24_REG_RF_CH 0x05
|
||||
#define RADIOLIB_NRF24_REG_RF_SETUP 0x06
|
||||
#define RADIOLIB_NRF24_REG_STATUS 0x07
|
||||
#define RADIOLIB_NRF24_REG_OBSERVE_TX 0x08
|
||||
#define RADIOLIB_NRF24_REG_RPD 0x09
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P0 0x0A
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P1 0x0B
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P2 0x0C
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P3 0x0D
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P4 0x0E
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P5 0x0F
|
||||
#define RADIOLIB_NRF24_REG_TX_ADDR 0x10
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P0 0x11
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P1 0x12
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P2 0x13
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P3 0x14
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P4 0x15
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P5 0x16
|
||||
#define RADIOLIB_NRF24_REG_FIFO_STATUS 0x17
|
||||
#define RADIOLIB_NRF24_REG_DYNPD 0x1C
|
||||
#define RADIOLIB_NRF24_REG_FEATURE 0x1D
|
||||
|
||||
// NRF24_REG_CONFIG MSB LSB DESCRIPTION
|
||||
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF 0b01000000 // 6 6 RX_DR will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON 0b00000000 // 6 6 RX_DR will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF 0b00100000 // 5 5 TX_DS will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON 0b00000000 // 5 5 TX_DS will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF 0b00010000 // 4 4 MAX_RT will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_ON 0b00000000 // 4 4 MAX_RT will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_CRC_OFF 0b00000000 // 3 3 CRC calculation: disabled
|
||||
#define RADIOLIB_NRF24_CRC_ON 0b00001000 // 3 3 enabled (default)
|
||||
#define RADIOLIB_NRF24_CRC_8 0b00000000 // 2 2 CRC scheme: CRC8 (default)
|
||||
#define RADIOLIB_NRF24_CRC_16 0b00000100 // 2 2 CRC16
|
||||
#define RADIOLIB_NRF24_POWER_UP 0b00000010 // 1 1 power up
|
||||
#define RADIOLIB_NRF24_POWER_DOWN 0b00000000 // 1 1 power down
|
||||
#define RADIOLIB_NRF24_PTX 0b00000000 // 0 0 enable primary Tx
|
||||
#define RADIOLIB_NRF24_PRX 0b00000001 // 0 0 enable primary Rx
|
||||
// RADIOLIB_NRF24_REG_CONFIG MSB LSB DESCRIPTION
|
||||
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF 0b01000000 // 6 6 RX_DR will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON 0b00000000 // 6 6 RX_DR will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF 0b00100000 // 5 5 TX_DS will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON 0b00000000 // 5 5 TX_DS will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF 0b00010000 // 4 4 MAX_RT will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_ON 0b00000000 // 4 4 MAX_RT will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_CRC_OFF 0b00000000 // 3 3 CRC calculation: disabled
|
||||
#define RADIOLIB_NRF24_CRC_ON 0b00001000 // 3 3 enabled (default)
|
||||
#define RADIOLIB_NRF24_CRC_8 0b00000000 // 2 2 CRC scheme: CRC8 (default)
|
||||
#define RADIOLIB_NRF24_CRC_16 0b00000100 // 2 2 CRC16
|
||||
#define RADIOLIB_NRF24_POWER_UP 0b00000010 // 1 1 power up
|
||||
#define RADIOLIB_NRF24_POWER_DOWN 0b00000000 // 1 1 power down
|
||||
#define RADIOLIB_NRF24_PTX 0b00000000 // 0 0 enable primary Tx
|
||||
#define RADIOLIB_NRF24_PRX 0b00000001 // 0 0 enable primary Rx
|
||||
|
||||
// NRF24_REG_EN_AA
|
||||
#define RADIOLIB_NRF24_AA_ALL_OFF 0b00000000 // 5 0 auto-ACK on all pipes: disabled
|
||||
#define RADIOLIB_NRF24_AA_ALL_ON 0b00111111 // 5 0 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P5_OFF 0b00000000 // 5 5 auto-ACK on pipe 5: disabled
|
||||
#define RADIOLIB_NRF24_AA_P5_ON 0b00100000 // 5 5 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P4_OFF 0b00000000 // 4 4 auto-ACK on pipe 4: disabled
|
||||
#define RADIOLIB_NRF24_AA_P4_ON 0b00010000 // 4 4 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P3_OFF 0b00000000 // 3 3 auto-ACK on pipe 3: disabled
|
||||
#define RADIOLIB_NRF24_AA_P3_ON 0b00001000 // 3 3 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P2_OFF 0b00000000 // 2 2 auto-ACK on pipe 2: disabled
|
||||
#define RADIOLIB_NRF24_AA_P2_ON 0b00000100 // 2 2 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P1_OFF 0b00000000 // 1 1 auto-ACK on pipe 1: disabled
|
||||
#define RADIOLIB_NRF24_AA_P1_ON 0b00000010 // 1 1 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P0_OFF 0b00000000 // 0 0 auto-ACK on pipe 0: disabled
|
||||
#define RADIOLIB_NRF24_AA_P0_ON 0b00000001 // 0 0 enabled (default)
|
||||
// RADIOLIB_NRF24_REG_EN_AA
|
||||
#define RADIOLIB_NRF24_AA_ALL_OFF 0b00000000 // 5 0 auto-ACK on all pipes: disabled
|
||||
#define RADIOLIB_NRF24_AA_ALL_ON 0b00111111 // 5 0 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P5_OFF 0b00000000 // 5 5 auto-ACK on pipe 5: disabled
|
||||
#define RADIOLIB_NRF24_AA_P5_ON 0b00100000 // 5 5 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P4_OFF 0b00000000 // 4 4 auto-ACK on pipe 4: disabled
|
||||
#define RADIOLIB_NRF24_AA_P4_ON 0b00010000 // 4 4 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P3_OFF 0b00000000 // 3 3 auto-ACK on pipe 3: disabled
|
||||
#define RADIOLIB_NRF24_AA_P3_ON 0b00001000 // 3 3 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P2_OFF 0b00000000 // 2 2 auto-ACK on pipe 2: disabled
|
||||
#define RADIOLIB_NRF24_AA_P2_ON 0b00000100 // 2 2 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P1_OFF 0b00000000 // 1 1 auto-ACK on pipe 1: disabled
|
||||
#define RADIOLIB_NRF24_AA_P1_ON 0b00000010 // 1 1 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P0_OFF 0b00000000 // 0 0 auto-ACK on pipe 0: disabled
|
||||
#define RADIOLIB_NRF24_AA_P0_ON 0b00000001 // 0 0 enabled (default)
|
||||
|
||||
// NRF24_REG_EN_RXADDR
|
||||
#define RADIOLIB_NRF24_P5_OFF 0b00000000 // 5 5 receive pipe 5: disabled (default)
|
||||
#define RADIOLIB_NRF24_P5_ON 0b00100000 // 5 5 enabled
|
||||
#define RADIOLIB_NRF24_P4_OFF 0b00000000 // 4 4 receive pipe 4: disabled (default)
|
||||
#define RADIOLIB_NRF24_P4_ON 0b00010000 // 4 4 enabled
|
||||
#define RADIOLIB_NRF24_P3_OFF 0b00000000 // 3 3 receive pipe 3: disabled (default)
|
||||
#define RADIOLIB_NRF24_P3_ON 0b00001000 // 3 3 enabled
|
||||
#define RADIOLIB_NRF24_P2_OFF 0b00000000 // 2 2 receive pipe 2: disabled (default)
|
||||
#define RADIOLIB_NRF24_P2_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_P1_OFF 0b00000000 // 1 1 receive pipe 1: disabled
|
||||
#define RADIOLIB_NRF24_P1_ON 0b00000010 // 1 1 enabled (default)
|
||||
#define RADIOLIB_NRF24_P0_OFF 0b00000000 // 0 0 receive pipe 0: disabled
|
||||
#define RADIOLIB_NRF24_P0_ON 0b00000001 // 0 0 enabled (default)
|
||||
// RADIOLIB_NRF24_REG_EN_RXADDR
|
||||
#define RADIOLIB_NRF24_P5_OFF 0b00000000 // 5 5 receive pipe 5: disabled (default)
|
||||
#define RADIOLIB_NRF24_P5_ON 0b00100000 // 5 5 enabled
|
||||
#define RADIOLIB_NRF24_P4_OFF 0b00000000 // 4 4 receive pipe 4: disabled (default)
|
||||
#define RADIOLIB_NRF24_P4_ON 0b00010000 // 4 4 enabled
|
||||
#define RADIOLIB_NRF24_P3_OFF 0b00000000 // 3 3 receive pipe 3: disabled (default)
|
||||
#define RADIOLIB_NRF24_P3_ON 0b00001000 // 3 3 enabled
|
||||
#define RADIOLIB_NRF24_P2_OFF 0b00000000 // 2 2 receive pipe 2: disabled (default)
|
||||
#define RADIOLIB_NRF24_P2_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_P1_OFF 0b00000000 // 1 1 receive pipe 1: disabled
|
||||
#define RADIOLIB_NRF24_P1_ON 0b00000010 // 1 1 enabled (default)
|
||||
#define RADIOLIB_NRF24_P0_OFF 0b00000000 // 0 0 receive pipe 0: disabled
|
||||
#define RADIOLIB_NRF24_P0_ON 0b00000001 // 0 0 enabled (default)
|
||||
|
||||
// NRF24_REG_SETUP_AW
|
||||
#define RADIOLIB_NRF24_ADDRESS_2_BYTES 0b00000000 // 1 0 address width: 2 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_3_BYTES 0b00000001 // 1 0 3 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_4_BYTES 0b00000010 // 1 0 4 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_5_BYTES 0b00000011 // 1 0 5 bytes (default)
|
||||
// RADIOLIB_NRF24_REG_SETUP_AW
|
||||
#define RADIOLIB_NRF24_ADDRESS_2_BYTES 0b00000000 // 1 0 address width: 2 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_3_BYTES 0b00000001 // 1 0 3 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_4_BYTES 0b00000010 // 1 0 4 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_5_BYTES 0b00000011 // 1 0 5 bytes (default)
|
||||
|
||||
// NRF24_REG_SETUP_RETR
|
||||
#define RADIOLIB_NRF24_ARD 0b00000000 // 7 4 auto retransmit delay: t[us] = (NRF24_ARD + 1) * 250 us
|
||||
#define RADIOLIB_NRF24_ARC_OFF 0b00000000 // 3 0 auto retransmit count: auto retransmit disabled
|
||||
#define RADIOLIB_NRF24_ARC 0b00000011 // 3 0 up to 3 retransmits on AA fail (default)
|
||||
// RADIOLIB_NRF24_REG_SETUP_RETR
|
||||
#define RADIOLIB_NRF24_ARD 0b00000000 // 7 4 auto retransmit delay: t[us] = (NRF24_ARD + 1) * 250 us
|
||||
#define RADIOLIB_NRF24_ARC_OFF 0b00000000 // 3 0 auto retransmit count: auto retransmit disabled
|
||||
#define RADIOLIB_NRF24_ARC 0b00000011 // 3 0 up to 3 retransmits on AA fail (default)
|
||||
|
||||
// NRF24_REG_RF_CH
|
||||
#define RADIOLIB_NRF24_RF_CH 0b00000010 // 6 0 RF channel: f_CH[MHz] = 2400 MHz + NRF24_RF_CH
|
||||
// RADIOLIB_NRF24_REG_RF_CH
|
||||
#define RADIOLIB_NRF24_RF_CH 0b00000010 // 6 0 RF channel: f_CH[MHz] = 2400 MHz + NRF24_RF_CH
|
||||
|
||||
// NRF24_REG_RF_SETUP
|
||||
#define RADIOLIB_NRF24_CONT_WAVE_OFF 0b00000000 // 7 7 continuous carrier transmit: disabled (default)
|
||||
#define RADIOLIB_NRF24_CONT_WAVE_ON 0b10000000 // 7 7 enabled
|
||||
#define RADIOLIB_NRF24_DR_250_KBPS 0b00100000 // 5 5 data rate: 250 kbps
|
||||
#define RADIOLIB_NRF24_DR_1_MBPS 0b00000000 // 3 3 1 Mbps (default)
|
||||
#define RADIOLIB_NRF24_DR_2_MBPS 0b00001000 // 3 3 2 Mbps
|
||||
#define RADIOLIB_NRF24_PLL_LOCK_ON 0b00010000 // 4 4 force PLL lock: enabled
|
||||
#define RADIOLIB_NRF24_PLL_LOCK_OFF 0b00000000 // 4 4 disabled (default)
|
||||
#define RADIOLIB_NRF24_RF_PWR_18_DBM 0b00000000 // 2 1 output power: -18 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_12_DBM 0b00000010 // 2 1 -12 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_6_DBM 0b00000100 // 2 1 -6 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_0_DBM 0b00000110 // 2 1 0 dBm (default)
|
||||
// RADIOLIB_NRF24_REG_RF_SETUP
|
||||
#define RADIOLIB_NRF24_CONT_WAVE_OFF 0b00000000 // 7 7 continuous carrier transmit: disabled (default)
|
||||
#define RADIOLIB_NRF24_CONT_WAVE_ON 0b10000000 // 7 7 enabled
|
||||
#define RADIOLIB_NRF24_DR_250_KBPS 0b00100000 // 5 5 data rate: 250 kbps
|
||||
#define RADIOLIB_NRF24_DR_1_MBPS 0b00000000 // 3 3 1 Mbps (default)
|
||||
#define RADIOLIB_NRF24_DR_2_MBPS 0b00001000 // 3 3 2 Mbps
|
||||
#define RADIOLIB_NRF24_PLL_LOCK_ON 0b00010000 // 4 4 force PLL lock: enabled
|
||||
#define RADIOLIB_NRF24_PLL_LOCK_OFF 0b00000000 // 4 4 disabled (default)
|
||||
#define RADIOLIB_NRF24_RF_PWR_18_DBM 0b00000000 // 2 1 output power: -18 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_12_DBM 0b00000010 // 2 1 -12 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_6_DBM 0b00000100 // 2 1 -6 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_0_DBM 0b00000110 // 2 1 0 dBm (default)
|
||||
|
||||
// NRF24_REG_STATUS
|
||||
#define RADIOLIB_NRF24_RX_DR 0b01000000 // 6 6 Rx data ready
|
||||
#define RADIOLIB_NRF24_TX_DS 0b00100000 // 5 5 Tx data sent
|
||||
#define RADIOLIB_NRF24_MAX_RT 0b00010000 // 4 4 maximum number of retransmits reached (must be cleared to continue)
|
||||
#define RADIOLIB_NRF24_RX_FIFO_EMPTY 0b00001110 // 3 1 Rx FIFO is empty
|
||||
#define RADIOLIB_NRF24_RX_P_NO 0b00000000 // 3 1 number of data pipe that received data
|
||||
#define RADIOLIB_NRF24_TX_FIFO_FULL 0b00000001 // 0 0 Tx FIFO is full
|
||||
// RADIOLIB_NRF24_REG_STATUS
|
||||
#define RADIOLIB_NRF24_RX_DR 0b01000000 // 6 6 Rx data ready
|
||||
#define RADIOLIB_NRF24_TX_DS 0b00100000 // 5 5 Tx data sent
|
||||
#define RADIOLIB_NRF24_MAX_RT 0b00010000 // 4 4 maximum number of retransmits reached (must be cleared to continue)
|
||||
#define RADIOLIB_NRF24_RX_FIFO_EMPTY 0b00001110 // 3 1 Rx FIFO is empty
|
||||
#define RADIOLIB_NRF24_RX_P_NO 0b00000000 // 3 1 number of data pipe that received data
|
||||
#define RADIOLIB_NRF24_TX_FIFO_FULL 0b00000001 // 0 0 Tx FIFO is full
|
||||
|
||||
// NRF24_REG_OBSERVE_TX
|
||||
#define RADIOLIB_NRF24_PLOS_CNT 0b00000000 // 7 4 number of lost packets
|
||||
#define RADIOLIB_NRF24_ARC_CNT 0b00000000 // 3 0 number of retransmitted packets
|
||||
// RADIOLIB_NRF24_REG_OBSERVE_TX
|
||||
#define RADIOLIB_NRF24_PLOS_CNT 0b00000000 // 7 4 number of lost packets
|
||||
#define RADIOLIB_NRF24_ARC_CNT 0b00000000 // 3 0 number of retransmitted packets
|
||||
|
||||
// NRF24_REG_RPD
|
||||
#define RADIOLIB_NRF24_RP_BELOW_64_DBM 0b00000000 // 0 0 received power in the current channel: less than -64 dBm
|
||||
#define RADIOLIB_NRF24_RP_ABOVE_64_DBM 0b00000001 // 0 0 more than -64 dBm
|
||||
// RADIOLIB_NRF24_REG_RPD
|
||||
#define RADIOLIB_NRF24_RP_BELOW_64_DBM 0b00000000 // 0 0 received power in the current channel: less than -64 dBm
|
||||
#define RADIOLIB_NRF24_RP_ABOVE_64_DBM 0b00000001 // 0 0 more than -64 dBm
|
||||
|
||||
// NRF24_REG_FIFO_STATUS
|
||||
#define RADIOLIB_NRF24_TX_REUSE 0b01000000 // 6 6 reusing last transmitted payload
|
||||
#define RADIOLIB_NRF24_TX_FIFO_FULL_FLAG 0b00100000 // 5 5 Tx FIFO is full
|
||||
#define RADIOLIB_NRF24_TX_FIFO_EMPTY_FLAG 0b00010000 // 4 4 Tx FIFO is empty
|
||||
#define RADIOLIB_NRF24_RX_FIFO_FULL_FLAG 0b00000010 // 1 1 Rx FIFO is full
|
||||
#define RADIOLIB_NRF24_RX_FIFO_EMPTY_FLAG 0b00000001 // 0 0 Rx FIFO is empty
|
||||
// RADIOLIB_NRF24_REG_FIFO_STATUS
|
||||
#define RADIOLIB_NRF24_TX_REUSE 0b01000000 // 6 6 reusing last transmitted payload
|
||||
#define RADIOLIB_NRF24_TX_FIFO_FULL_FLAG 0b00100000 // 5 5 Tx FIFO is full
|
||||
#define RADIOLIB_NRF24_TX_FIFO_EMPTY_FLAG 0b00010000 // 4 4 Tx FIFO is empty
|
||||
#define RADIOLIB_NRF24_RX_FIFO_FULL_FLAG 0b00000010 // 1 1 Rx FIFO is full
|
||||
#define RADIOLIB_NRF24_RX_FIFO_EMPTY_FLAG 0b00000001 // 0 0 Rx FIFO is empty
|
||||
|
||||
// NRF24_REG_DYNPD
|
||||
#define RADIOLIB_NRF24_DPL_P5_OFF 0b00000000 // 5 5 dynamic payload length on pipe 5: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P5_ON 0b00100000 // 5 5 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P4_OFF 0b00000000 // 4 4 dynamic payload length on pipe 4: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P4_ON 0b00010000 // 4 4 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P3_OFF 0b00000000 // 3 3 dynamic payload length on pipe 3: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P3_ON 0b00001000 // 3 3 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P2_OFF 0b00000000 // 2 2 dynamic payload length on pipe 2: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P2_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P1_OFF 0b00000000 // 1 1 dynamic payload length on pipe 1: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P1_ON 0b00000010 // 1 1 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P0_OFF 0b00000000 // 0 0 dynamic payload length on pipe 0: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P0_ON 0b00000001 // 0 0 enabled
|
||||
#define RADIOLIB_NRF24_DPL_ALL_OFF 0b00000000 // 5 0 disable all dynamic payloads
|
||||
#define RADIOLIB_NRF24_DPL_ALL_ON 0b00111111 // 5 0 enable all dynamic payloads
|
||||
// RADIOLIB_NRF24_REG_DYNPD
|
||||
#define RADIOLIB_NRF24_DPL_P5_OFF 0b00000000 // 5 5 dynamic payload length on pipe 5: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P5_ON 0b00100000 // 5 5 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P4_OFF 0b00000000 // 4 4 dynamic payload length on pipe 4: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P4_ON 0b00010000 // 4 4 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P3_OFF 0b00000000 // 3 3 dynamic payload length on pipe 3: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P3_ON 0b00001000 // 3 3 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P2_OFF 0b00000000 // 2 2 dynamic payload length on pipe 2: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P2_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P1_OFF 0b00000000 // 1 1 dynamic payload length on pipe 1: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P1_ON 0b00000010 // 1 1 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P0_OFF 0b00000000 // 0 0 dynamic payload length on pipe 0: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P0_ON 0b00000001 // 0 0 enabled
|
||||
#define RADIOLIB_NRF24_DPL_ALL_OFF 0b00000000 // 5 0 disable all dynamic payloads
|
||||
#define RADIOLIB_NRF24_DPL_ALL_ON 0b00111111 // 5 0 enable all dynamic payloads
|
||||
|
||||
// NRF24_REG_FEATURE
|
||||
#define RADIOLIB_NRF24_DPL_OFF 0b00000000 // 2 2 dynamic payload length: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_ACK_PAY_OFF 0b00000000 // 1 1 payload with ACK packets: disabled (default)
|
||||
#define RADIOLIB_NRF24_ACK_PAY_ON 0b00000010 // 1 1 enabled
|
||||
#define RADIOLIB_NRF24_DYN_ACK_OFF 0b00000000 // 0 0 payloads without ACK: disabled (default)
|
||||
#define RADIOLIB_NRF24_DYN_ACK_ON 0b00000001 // 0 0 enabled
|
||||
|
||||
// Defaults
|
||||
#define RADIOLIB_NRF24_DEFAULT_FREQ 2400
|
||||
#define RADIOLIB_NRF24_DEFAULT_DR 1000
|
||||
#define RADIOLIB_NRF24_DEFAULT_POWER -12
|
||||
#define RADIOLIB_NRF24_DEFAULT_ADDRWIDTH 5
|
||||
// RADIOLIB_NRF24_REG_FEATURE
|
||||
#define RADIOLIB_NRF24_DPL_OFF 0b00000000 // 2 2 dynamic payload length: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_ACK_PAY_OFF 0b00000000 // 1 1 payload with ACK packets: disabled (default)
|
||||
#define RADIOLIB_NRF24_ACK_PAY_ON 0b00000010 // 1 1 enabled
|
||||
#define RADIOLIB_NRF24_DYN_ACK_OFF 0b00000000 // 0 0 payloads without ACK: disabled (default)
|
||||
#define RADIOLIB_NRF24_DYN_ACK_ON 0b00000001 // 0 0 enabled
|
||||
|
||||
// RadioLib defaults
|
||||
#define RADIOLIB_NRF24_DEFAULT_FREQ 2400
|
||||
#define RADIOLIB_NRF24_DEFAULT_DR 1000
|
||||
#define RADIOLIB_NRF24_DEFAULT_POWER -12
|
||||
#define RADIOLIB_NRF24_DEFAULT_ADDRWIDTH 5
|
||||
|
||||
/*!
|
||||
\class nRF24
|
||||
|
||||
\brief Control class for %nRF24 module.
|
||||
*/
|
||||
class nRF24: public PhysicalLayer {
|
||||
|
@ -193,7 +191,6 @@ class nRF24: public PhysicalLayer {
|
|||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
nRF24(Module* mod);
|
||||
|
@ -204,42 +201,33 @@ class nRF24: public PhysicalLayer {
|
|||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\param freq Carrier frequency in MHz. Defaults to 2400 MHz.
|
||||
|
||||
\param dataRate Data rate to be used in kbps. Defaults to 1000 kbps.
|
||||
|
||||
\param power Output power in dBm. Defaults to -12 dBm.
|
||||
|
||||
\param dr Data rate to be used in kbps. Defaults to 1000 kbps.
|
||||
\param pwr Output power in dBm. Defaults to -12 dBm.
|
||||
\param addrWidth Address width in bytes. Defaults to 5 bytes.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(
|
||||
int16_t freq = RADIOLIB_NRF24_DEFAULT_FREQ,
|
||||
int16_t dataRate = RADIOLIB_NRF24_DEFAULT_DR,
|
||||
int8_t power = RADIOLIB_NRF24_DEFAULT_POWER,
|
||||
int16_t dr = RADIOLIB_NRF24_DEFAULT_DR,
|
||||
int8_t pwr = RADIOLIB_NRF24_DEFAULT_POWER,
|
||||
uint8_t addrWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH);
|
||||
|
||||
/*!
|
||||
\brief Sets the module to sleep mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sleep();
|
||||
|
||||
/*!
|
||||
\brief Sets the module to standby mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t standby() override;
|
||||
|
||||
/*!
|
||||
\brief Sets the module to standby.
|
||||
|
||||
\param mode Standby mode to be used.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t standby(uint8_t mode) override;
|
||||
|
@ -247,13 +235,9 @@ class nRF24: public PhysicalLayer {
|
|||
/*!
|
||||
\brief Blocking binary transmit method.
|
||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||
|
||||
\param data Binary data to be sent.
|
||||
|
||||
\param len Number of bytes to send.
|
||||
|
||||
\param addr Dummy address parameter, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(uint8_t* data, size_t len, uint8_t addr) override;
|
||||
|
@ -261,27 +245,21 @@ class nRF24: public PhysicalLayer {
|
|||
/*!
|
||||
\brief Blocking binary receive method.
|
||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||
|
||||
\param data Binary data to be sent.
|
||||
|
||||
\param len Number of bytes to send.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t receive(uint8_t* data, size_t len) override;
|
||||
|
||||
/*!
|
||||
\brief Starts direct mode transmission.
|
||||
|
||||
\param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmitDirect(uint32_t frf = 0) override;
|
||||
|
||||
/*!
|
||||
\brief Dummy direct mode reception method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t receiveDirect() override;
|
||||
|
@ -290,7 +268,6 @@ class nRF24: public PhysicalLayer {
|
|||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when IRQ activates.
|
||||
|
||||
\param func ISR to call.
|
||||
*/
|
||||
void setIrqAction(void (*func)(void));
|
||||
|
@ -298,53 +275,39 @@ class nRF24: public PhysicalLayer {
|
|||
/*!
|
||||
\brief Interrupt-driven binary transmit method. IRQ will be activated when full packet is transmitted.
|
||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||
|
||||
\param data Binary data to be sent.
|
||||
|
||||
\param len Number of bytes to send.
|
||||
|
||||
\param addr Dummy address parameter, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr) override;
|
||||
|
||||
/*!
|
||||
\brief Clean up after transmission is done.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t finishTransmit() override;
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven receive method. IRQ will be activated when full packet is received.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startReceive();
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven receive method, implemented for compatibility with PhysicalLayer.
|
||||
|
||||
\param timeout Ignored.
|
||||
|
||||
\param irqFlags Ignored.
|
||||
|
||||
\param irqMask Ignored.
|
||||
|
||||
\param len Ignored.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startReceive(uint32_t timeout, uint16_t irqFlags, uint16_t irqMask, size_t len);
|
||||
|
||||
/*!
|
||||
\brief Reads data received after calling startReceive method.
|
||||
|
||||
\param data Pointer to array to save the received binary data.
|
||||
|
||||
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t readData(uint8_t* data, size_t len) override;
|
||||
|
@ -353,188 +316,133 @@ class nRF24: public PhysicalLayer {
|
|||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 2400 MHz to 2525 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
|
||||
/*!
|
||||
\brief Sets bit rate. Allowed values are 2000, 1000 or 250 kbps.
|
||||
|
||||
\param br Bit rate to be set in kbps.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setBitRate(float br);
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are -18, -12, -6 or 0 dBm.
|
||||
|
||||
\param power Output power to be set in dBm.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
|
||||
/*!
|
||||
\brief Sets address width of transmit and receive pipes in bytes. Allowed values are 3, 4 or 5 bytes.
|
||||
|
||||
\param addrWidth Address width to be set in bytes.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setAddressWidth(uint8_t addrWidth);
|
||||
|
||||
/*!
|
||||
\brief Sets address of transmit pipe. The address width must be the same as the same as the configured in setAddressWidth.
|
||||
|
||||
\brief Sets address of transmit pipe. The address width must be the same as the same
|
||||
as the configured in setAddressWidth.
|
||||
\param addr Address to which the next packet shall be transmitted.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setTransmitPipe(uint8_t* addr);
|
||||
|
||||
/*!
|
||||
\brief Sets address of receive pipes 0 or 1. The address width must be the same as the same as the configured in setAddressWidth.
|
||||
|
||||
\param pipeNum Number of pipe to which the address shall be set. Either 0 or 1, other pipes are handled using overloaded method.
|
||||
|
||||
\brief Sets address of receive pipes 0 or 1. The address width must be the same as the same
|
||||
as the configured in setAddressWidth.
|
||||
\param pipeNum Number of pipe to which the address shall be set. Either 0 or 1,
|
||||
other pipes are handled using overloaded method.
|
||||
\param addr Address from which %nRF24 shall receive new packets on the specified pipe.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setReceivePipe(uint8_t pipeNum, uint8_t* addr);
|
||||
|
||||
/*!
|
||||
\brief Sets address of receive pipes 2 - 5. The first 2 - 4 address bytes for these pipes are the same as for address pipe 1, only the last byte can be set.
|
||||
|
||||
\brief Sets address of receive pipes 2 - 5. The first 2 - 4 address bytes for these pipes
|
||||
are the same as for address pipe 1, only the last byte can be set.
|
||||
\param pipeNum Number of pipe to which the address shall be set. Allowed values range from 2 to 5.
|
||||
|
||||
\param addrByte LSB of address from which %nRF24 shall receive new packets on the specified pipe.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setReceivePipe(uint8_t pipeNum, uint8_t addrByte);
|
||||
|
||||
/*!
|
||||
\brief Disables specified receive pipe.
|
||||
|
||||
\param pipeNum Receive pipe to be disabled.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t disablePipe(uint8_t pipeNum);
|
||||
|
||||
/*!
|
||||
\brief Gets nRF24 status register.
|
||||
|
||||
\param mask Bit mask to be used on the returned register value.
|
||||
|
||||
\returns Status register value or \ref status_codes
|
||||
*/
|
||||
int16_t getStatus(uint8_t mask = 0xFF);
|
||||
|
||||
/*!
|
||||
\brief Checks if carrier was detected during last RX
|
||||
|
||||
\returns Whatever the carrier was above threshold.
|
||||
*/
|
||||
bool isCarrierDetected();
|
||||
|
||||
/*!
|
||||
\brief Dummy configuration method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param freqDev Dummy frequency deviation parameter, no configuration will be changed.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequencyDeviation(float freqDev) override;
|
||||
|
||||
/*!
|
||||
\brief Query modem for the packet length of received payload.
|
||||
|
||||
\param update Update received packet length. Will return cached value when set to false.
|
||||
|
||||
\returns Length of last received packet in bytes.
|
||||
*/
|
||||
size_t getPacketLength(bool update = true) override;
|
||||
|
||||
/*!
|
||||
\brief Enable CRC filtering and generation.
|
||||
|
||||
\param crcOn Set or unset CRC check.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCrcFiltering(bool crcOn = true);
|
||||
|
||||
/*!
|
||||
\brief Enable or disable auto-acknowledge packets on all pipes
|
||||
|
||||
\brief Enable or disable auto-acknowledge packets on all pipes.
|
||||
\param autoAckOn Enable (true) or disable (false) auto-acks.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setAutoAck(bool autoAckOn = true);
|
||||
|
||||
/*!
|
||||
\brief Enable or disable auto-acknowledge packets on given pipe.
|
||||
|
||||
\param pipeNum Number of pipe to which enable / disable auto-acks.
|
||||
|
||||
\param autoAckOn Enable (true) or disable (false) auto-acks.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setAutoAck(uint8_t pipeNum, bool autoAckOn);
|
||||
|
||||
/*!
|
||||
\brief Dummy data shaping configuration method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param sh Ignored.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataShaping(uint8_t sh) override;
|
||||
|
||||
/*!
|
||||
\brief Dummy encoding configuration method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param sh Ignored.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setEncoding(uint8_t encoding) override;
|
||||
|
||||
/*!
|
||||
\brief Dummy random method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\returns Always returns 0.
|
||||
*/
|
||||
uint8_t randomByte();
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
/*!
|
||||
\brief Dummy method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param func Ignored.
|
||||
*/
|
||||
void setDirectAction(void (*func)(void));
|
||||
|
||||
/*!
|
||||
\brief Dummy method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param pin Ignored.
|
||||
*/
|
||||
void readBit(uint32_t pin);
|
||||
#endif
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
|
||||
protected:
|
||||
#endif
|
||||
Module* _mod;
|
||||
Module* mod;
|
||||
|
||||
void SPIreadRxPayload(uint8_t* data, uint8_t numBytes);
|
||||
void SPIwriteTxPayload(uint8_t* data, uint8_t numBytes);
|
||||
|
@ -544,11 +452,10 @@ class nRF24: public PhysicalLayer {
|
|||
protected:
|
||||
#endif
|
||||
|
||||
int16_t _freq = RADIOLIB_NRF24_DEFAULT_FREQ;
|
||||
int16_t _dataRate = RADIOLIB_NRF24_DEFAULT_DR;
|
||||
int8_t _power = RADIOLIB_NRF24_DEFAULT_POWER;
|
||||
uint8_t _addrWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH;
|
||||
|
||||
int16_t frequency = RADIOLIB_NRF24_DEFAULT_FREQ;
|
||||
int16_t dataRate = RADIOLIB_NRF24_DEFAULT_DR;
|
||||
int8_t power = RADIOLIB_NRF24_DEFAULT_POWER;
|
||||
uint8_t addressWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH;
|
||||
|
||||
int16_t config();
|
||||
void clearIRQ();
|
||||
|
|
Loading…
Add table
Reference in a new issue