|
|
@@ -37,13 +37,12 @@ Nrf24L01::Nrf24L01(NrfSettings_t *settings, SpiManager *spi_manager,
|
|
|
this->setCRCScheme(settings->crcScheme);
|
|
|
this->setAddrWidth(settings->addrWidth);
|
|
|
this->setAddr(settings->pipe, settings->address);
|
|
|
- if(settings->pipe != nRF24_PIPETX) {
|
|
|
+
|
|
|
+ if(settings->operationalMode == nRF24_MODE_RX) {
|
|
|
this->setRXPipe(settings->pipe, nRF24_AA_OFF, settings->payoladLength);
|
|
|
}
|
|
|
|
|
|
- if(settings->operationalMode == nRF24_MODE_TX) {
|
|
|
- this->setTXPower(settings->txPower);
|
|
|
- }
|
|
|
+ this->setTXPower(settings->txPower);
|
|
|
|
|
|
this->setOperationalMode(settings->operationalMode);
|
|
|
this->clearIRQFlags();
|
|
|
@@ -78,8 +77,6 @@ uint8_t Nrf24L01::init() {
|
|
|
// Clear any pending interrupt flags
|
|
|
this->clearIRQFlags();
|
|
|
|
|
|
- PIN_HIGH(_spiManager->_csn_port, _spiManager->_csn_pin);
|
|
|
-
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -143,7 +140,7 @@ uint8_t Nrf24L01::doCheck(void) {
|
|
|
// Control transceiver power mode
|
|
|
// input:
|
|
|
// mode - new state of power mode, one of nRF24_PWR_xx values
|
|
|
-void Nrf24L01::setPowerMode(uint8_t mode) {
|
|
|
+void Nrf24L01::setPowerMode(NrfPowerMode mode) {
|
|
|
uint8_t reg;
|
|
|
reg = readReg(nRF24_REG_CONFIG);
|
|
|
if (mode == nRF24_PWR_UP) {
|
|
|
@@ -162,7 +159,7 @@ void Nrf24L01::setPowerMode(uint8_t mode) {
|
|
|
// Set transceiver operational mode
|
|
|
// input:
|
|
|
// mode - operational mode, one of nRF24_MODE_xx values
|
|
|
-void Nrf24L01::setOperationalMode(uint8_t mode) {
|
|
|
+void Nrf24L01::setOperationalMode(NrfOperationalMode mode) {
|
|
|
uint8_t reg;
|
|
|
// Configure PRIM_RX bit of the CONFIG register
|
|
|
reg = readReg(nRF24_REG_CONFIG);
|
|
|
@@ -204,7 +201,7 @@ void Nrf24L01::setPayloadWithAck(uint8_t mode) {
|
|
|
// scheme - CRC scheme, one of nRF24_CRC_xx values
|
|
|
// note: transceiver will forcibly turn on the CRC in case if auto acknowledgment
|
|
|
// enabled for at least one RX pipe
|
|
|
-void Nrf24L01::setCRCScheme(uint8_t scheme) {
|
|
|
+void Nrf24L01::setCRCScheme(NrfCrcScheme scheme) {
|
|
|
uint8_t reg;
|
|
|
|
|
|
// Configure EN_CRC[3] and CRCO[2] bits of the CONFIG register
|
|
|
@@ -286,7 +283,7 @@ void Nrf24L01::setAddr(uint8_t pipe, const uint8_t *addr) {
|
|
|
// Configure RF output power in TX mode
|
|
|
// input:
|
|
|
// tx_pwr - RF output power, one of nRF24_TXPWR_xx values
|
|
|
-void Nrf24L01::setTXPower(uint8_t tx_pwr) {
|
|
|
+void Nrf24L01::setTXPower(NrfTxPower tx_pwr) {
|
|
|
uint8_t reg;
|
|
|
// Configure RF_PWR[2:1] bits of the RF_SETUP register
|
|
|
reg = readReg(nRF24_REG_RF_SETUP);
|
|
|
@@ -298,7 +295,7 @@ void Nrf24L01::setTXPower(uint8_t tx_pwr) {
|
|
|
// Configure transceiver data rate
|
|
|
// input:
|
|
|
// data_rate - data rate, one of nRF24_DR_xx values
|
|
|
-void Nrf24L01::setDataRate(uint8_t data_rate) {
|
|
|
+void Nrf24L01::setDataRate(NrfDataRate data_rate) {
|
|
|
uint8_t reg;
|
|
|
// Configure RF_DR_LOW[5] and RF_DR_HIGH[3] bits of the RF_SETUP register
|
|
|
reg = readReg(nRF24_REG_RF_SETUP);
|
|
|
@@ -312,7 +309,7 @@ void Nrf24L01::setDataRate(uint8_t data_rate) {
|
|
|
// pipe - number of the RX pipe, value from 0 to 5
|
|
|
// aa_state - state of auto acknowledgment, one of nRF24_AA_xx values
|
|
|
// payload_len - payload length in bytes
|
|
|
-void Nrf24L01::setRXPipe(uint8_t pipe, uint8_t aa_state, uint8_t payload_len) {
|
|
|
+void Nrf24L01::setRXPipe(NrfPipe pipe, NrfAcknowledgementState aa_state, uint8_t payload_len) {
|
|
|
uint8_t reg;
|
|
|
// Enable the specified pipe (EN_RXADDR register)
|
|
|
reg = (readReg(nRF24_REG_EN_RXADDR) | (1 << pipe)) & nRF24_MASK_EN_RX;
|
|
|
@@ -448,7 +445,7 @@ uint8_t Nrf24L01::getRxDplPayloadWidth() {
|
|
|
return _spiManager->SPI_ReadReg(nRF24_CMD_R_RX_PL_WID);
|
|
|
}
|
|
|
|
|
|
-nRF24_RXResult Nrf24L01::readPayloadGeneric(uint8_t *pBuf, uint8_t *length, uint8_t dpl) {
|
|
|
+nRF24_RXResult Nrf24L01::readPayloadGeneric(uint8_t *pBuf, uint8_t *length, uint8_t dynamicPayloadLength) {
|
|
|
uint8_t pipe;
|
|
|
// Extract a payload pipe number from the STATUS register
|
|
|
pipe = (readReg(nRF24_REG_STATUS) & nRF24_MASK_RX_P_NO) >> 1;
|
|
|
@@ -456,7 +453,7 @@ nRF24_RXResult Nrf24L01::readPayloadGeneric(uint8_t *pBuf, uint8_t *length, uint
|
|
|
// RX FIFO empty?
|
|
|
if (pipe < 6) {
|
|
|
// Get payload length
|
|
|
- if(dpl) {
|
|
|
+ if(dynamicPayloadLength) {
|
|
|
*length = getRxDplPayloadWidth();
|
|
|
if(*length>32) { //broken packet
|
|
|
*length = 0;
|
|
|
@@ -487,11 +484,11 @@ nRF24_RXResult Nrf24L01::readPayloadGeneric(uint8_t *pBuf, uint8_t *length, uint
|
|
|
// return: one of nRF24_RX_xx values
|
|
|
// nRF24_RX_PIPEX - packet has been received from the pipe number X
|
|
|
// nRF24_RX_EMPTY - the RX FIFO is empty
|
|
|
-nRF24_RXResult Nrf24L01::readPayload(uint8_t *pBuf, uint8_t *length) {
|
|
|
+nRF24_RXResult Nrf24L01::receivePayload(uint8_t *pBuf, uint8_t *length) {
|
|
|
return readPayloadGeneric(pBuf, length, 0);
|
|
|
}
|
|
|
|
|
|
-nRF24_RXResult Nrf24L01::readPayloadDpl(uint8_t *pBuf, uint8_t *length) {
|
|
|
+nRF24_RXResult Nrf24L01::receivePayloadDpl(uint8_t *pBuf, uint8_t *length) {
|
|
|
return readPayloadGeneric(pBuf, length, 1);
|
|
|
}
|
|
|
|
|
|
@@ -503,8 +500,8 @@ void Nrf24L01::activateFeatures() {
|
|
|
_spiManager->SPI_WritedReg(nRF24_CMD_ACTIVATE, 0x73);
|
|
|
}
|
|
|
|
|
|
-void Nrf24L01::writeAckPayload(nRF24_RXResult pipe, char *payload, uint8_t length) {
|
|
|
- PIN_LOW(_spiManager->_csn_port, _spiManager->_csn_pin);
|
|
|
+void Nrf24L01::transmitPayloadAck(nRF24_RXResult pipe, char *payload, uint8_t length) {
|
|
|
+ PIN_LOW(_spiManager->_csn_port, _spiManager->_csn_pin); // TODO prehodit do spiManagera
|
|
|
_spiManager->SPI_ReadWriteSingle(nRF24_CMD_W_ACK_PAYLOAD | pipe);
|
|
|
while (length--) {
|
|
|
_spiManager->SPI_ReadWriteSingle((uint8_t) *payload++);
|
|
|
@@ -513,7 +510,7 @@ void Nrf24L01::writeAckPayload(nRF24_RXResult pipe, char *payload, uint8_t lengt
|
|
|
|
|
|
}
|
|
|
|
|
|
-nRF24_TXResult Nrf24L01::transmitPacket(uint8_t *pBuf, uint8_t length) {
|
|
|
+nRF24_TXResult Nrf24L01::transmitPayload(uint8_t *pBuf, uint8_t length) {
|
|
|
volatile uint32_t wait = nRF24_WAIT_TIMEOUT;
|
|
|
uint8_t status;
|
|
|
|