From 15079334752c26ebd540e41ed8c1eea3876a8d11 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 1 Oct 2022 15:29:29 +0200 Subject: [PATCH] [nRF24] Fixed interface for PhysicalLayer --- src/modules/nRF24/nRF24.cpp | 13 +++++++------ src/modules/nRF24/nRF24.h | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/modules/nRF24/nRF24.cpp b/src/modules/nRF24/nRF24.cpp index 5ac59810..972eaff7 100644 --- a/src/modules/nRF24/nRF24.cpp +++ b/src/modules/nRF24/nRF24.cpp @@ -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); diff --git a/src/modules/nRF24/nRF24.h b/src/modules/nRF24/nRF24.h index 26f8393a..3d4af395 100644 --- a/src/modules/nRF24/nRF24.h +++ b/src/modules/nRF24/nRF24.h @@ -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.