[nRF24] Fixed interface for PhysicalLayer

This commit is contained in:
jgromes 2022-10-01 15:29:29 +02:00
parent e5fe82f334
commit 1507933475
2 changed files with 11 additions and 10 deletions

View file

@ -45,7 +45,7 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW
RADIOLIB_ASSERT(state);
// set data rate
state = setDataRate(dataRate);
state = setBitRate(dataRate);
RADIOLIB_ASSERT(state);
// set output power
@ -103,7 +103,7 @@ int16_t nRF24::transmit(uint8_t* data, size_t len, uint8_t addr) {
return(RADIOLIB_ERR_TX_TIMEOUT);
}
}
return(finishTransmit());
}
@ -249,20 +249,21 @@ int16_t nRF24::readData(uint8_t* data, size_t len) {
return(RADIOLIB_ERR_NONE);
}
int16_t nRF24::setFrequency(int16_t freq) {
RADIOLIB_CHECK_RANGE(freq, 2400, 2525, RADIOLIB_ERR_INVALID_FREQUENCY);
int16_t nRF24::setFrequency(float freq) {
RADIOLIB_CHECK_RANGE((uint16_t)freq, 2400, 2525, RADIOLIB_ERR_INVALID_FREQUENCY);
// set frequency
uint8_t freqRaw = freq - 2400;
uint8_t freqRaw = (uint16_t)freq - 2400;
return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0));
}
int16_t nRF24::setDataRate(int16_t dataRate) {
int16_t nRF24::setBitRate(float br) {
// set mode to standby
int16_t state = standby();
RADIOLIB_ASSERT(state);
// 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);

View file

@ -323,16 +323,16 @@ class nRF24: public PhysicalLayer {
\returns \ref status_codes
*/
int16_t setFrequency(int16_t freq);
int16_t setFrequency(float freq);
/*!
\brief Sets data rate. Allowed values are 2000, 1000 or 250 kbps.
\brief Sets bit rate. Allowed values are 2000, 1000 or 250 kbps.
\param dataRate Data rate to be set in kbps.
\param br Bit rate to be set in kbps.
\returns \ref status_codes
*/
int16_t setDataRate(int16_t dataRate);
int16_t setBitRate(float br);
/*!
\brief Sets output power. Allowed values are -18, -12, -6 or 0 dBm.