Harmonize RF24 definitions (#629)

This commit is contained in:
Olivier
2016-11-05 09:53:12 +01:00
committed by Embedded Innovation
parent c6ff9122b4
commit 6636a97562
3 changed files with 548 additions and 506 deletions
+41 -38
View File
@@ -25,12 +25,11 @@
#include "drivers/CircularBuffer/CircularBuffer.h" #include "drivers/CircularBuffer/CircularBuffer.h"
#if defined(MY_RF24_ENABLE_ENCRYPTION) #if defined(MY_RF24_ENABLE_ENCRYPTION)
#include "drivers/AES/AES.h" #include "drivers/AES/AES.h"
#endif #endif
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
typedef struct _transportQueuedMessage typedef struct _transportQueuedMessage {
{
uint8_t m_len; // Length of the data uint8_t m_len; // Length of the data
uint8_t m_data[MAX_MESSAGE_LENGTH]; // The raw data uint8_t m_data[MAX_MESSAGE_LENGTH]; // The raw data
} transportQueuedMessage; } transportQueuedMessage;
@@ -46,8 +45,7 @@ static void transportRxCallback(void)
{ {
// Called for each message received by radio, from interrupt context. // Called for each message received by radio, from interrupt context.
// This function _must_ call RF24_readMessage() to de-assert interrupt line! // This function _must_ call RF24_readMessage() to de-assert interrupt line!
if (!transportRxQueue.full()) if (!transportRxQueue.full()) {
{
transportQueuedMessage* msg = transportRxQueue.getFront(); transportQueuedMessage* msg = transportRxQueue.getFront();
msg->m_len = RF24_readMessage(msg->m_data); // Read payload & clear RX_DR msg->m_len = RF24_readMessage(msg->m_data); // Read payload & clear RX_DR
(void)transportRxQueue.pushFront(msg); (void)transportRxQueue.pushFront(msg);
@@ -55,8 +53,7 @@ static void transportRxCallback(void)
// Queue is full. Discard message. // Queue is full. Discard message.
(void)RF24_readMessage(NULL); // Read payload & clear RX_DR (void)RF24_readMessage(NULL); // Read payload & clear RX_DR
// Keep track of messages lost. Max 255, prevent wrapping. // Keep track of messages lost. Max 255, prevent wrapping.
if (transportLostMessageCount < 255) if (transportLostMessageCount < 255) {
{
++transportLostMessageCount; ++transportLostMessageCount;
} }
} }
@@ -64,86 +61,92 @@ static void transportRxCallback(void)
#endif #endif
#if defined(MY_RF24_ENABLE_ENCRYPTION) #if defined(MY_RF24_ENABLE_ENCRYPTION)
AES _aes; AES _aes;
uint8_t _dataenc[32] = {0}; uint8_t _dataenc[32] = {0};
uint8_t _psk[16]; uint8_t _psk[16];
#endif #endif
bool transportInit() { bool transportInit(void)
#if defined(MY_RF24_ENABLE_ENCRYPTION) {
#if defined(MY_RF24_ENABLE_ENCRYPTION)
hwReadConfigBlock((void*)_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16); hwReadConfigBlock((void*)_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
//set up AES-key //set up AES-key
_aes.set_key(_psk, 16); _aes.set_key(_psk, 16);
// Make sure it is purged from memory when set // Make sure it is purged from memory when set
memset(_psk, 0, 16); memset(_psk, 0, 16);
#endif #endif
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
RF24_registerReceiveCallback( transportRxCallback ); RF24_registerReceiveCallback( transportRxCallback );
#endif #endif
return RF24_initialize(); return RF24_initialize();
} }
void transportSetAddress(uint8_t address) { void transportSetAddress(const uint8_t address)
{
RF24_setNodeAddress(address); RF24_setNodeAddress(address);
RF24_startListening(); RF24_startListening();
} }
uint8_t transportGetAddress() { uint8_t transportGetAddress(void)
{
return RF24_getNodeID(); return RF24_getNodeID();
} }
bool transportSend(uint8_t recipient, const void* data, uint8_t len) { bool transportSend(const uint8_t recipient, const void* data, uint8_t len)
#if defined(MY_RF24_ENABLE_ENCRYPTION) {
#if defined(MY_RF24_ENABLE_ENCRYPTION)
// copy input data because it is read-only // copy input data because it is read-only
memcpy(_dataenc,data,len); (void)memcpy(_dataenc,data,len);
// has to be adjusted, WIP! // has to be adjusted, WIP!
_aes.set_IV(0); _aes.set_IV(0);
len = len > 16 ? 32 : 16; len = len > 16 ? 32 : 16;
//encrypt data //encrypt data
_aes.cbc_encrypt(_dataenc, _dataenc, len/16); _aes.cbc_encrypt(_dataenc, _dataenc, len/16);
bool status = RF24_sendMessage( recipient, _dataenc, len ); return RF24_sendMessage(recipient, _dataenc, len);
#else #else
bool status = RF24_sendMessage( recipient, data, len ); return RF24_sendMessage(recipient, data, len);
#endif #endif
return status;
} }
bool transportAvailable() { bool transportAvailable(void)
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) {
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
(void)RF24_isDataAvailable; // Prevent 'defined but not used' warning (void)RF24_isDataAvailable; // Prevent 'defined but not used' warning
return !transportRxQueue.empty(); return !transportRxQueue.empty();
#else #else
return RF24_isDataAvailable(); return RF24_isDataAvailable();
#endif #endif
} }
bool transportSanityCheck() { bool transportSanityCheck(void)
{
return RF24_sanityCheck(); return RF24_sanityCheck();
} }
uint8_t transportReceive(void* data) { uint8_t transportReceive(void* data)
{
uint8_t len = 0; uint8_t len = 0;
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
transportQueuedMessage* msg = transportRxQueue.getBack(); transportQueuedMessage* msg = transportRxQueue.getBack();
if (msg) { if (msg) {
len = msg->m_len; len = msg->m_len;
(void)memcpy(data, msg->m_data, len); (void)memcpy(data, msg->m_data, len);
(void)transportRxQueue.popBack(); (void)transportRxQueue.popBack();
} }
#else #else
len = RF24_readMessage(data); len = RF24_readMessage(data);
#endif #endif
#if defined(MY_RF24_ENABLE_ENCRYPTION) #if defined(MY_RF24_ENABLE_ENCRYPTION)
// has to be adjusted, WIP! // has to be adjusted, WIP!
_aes.set_IV(0); _aes.set_IV(0);
// decrypt data // decrypt data
_aes.cbc_decrypt((byte*)(data), (byte*)(data), len>16?2:1); _aes.cbc_decrypt((byte*)(data), (byte*)(data), len>16?2:1);
#endif #endif
return len; return len;
} }
void transportPowerDown() { void transportPowerDown(void)
{
RF24_powerDown(); RF24_powerDown();
} }
+160 -121
View File
@@ -26,32 +26,35 @@ LOCAL uint8_t MY_RF24_BASE_ADDR[MY_RF24_ADDR_WIDTH] = { MY_RF24_BASE_RADIO_ID };
LOCAL uint8_t MY_RF24_NODE_ADDRESS = AUTO; LOCAL uint8_t MY_RF24_NODE_ADDRESS = AUTO;
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
LOCAL RF24_receiveCallbackType RF24_receiveCallback = NULL; LOCAL RF24_receiveCallbackType RF24_receiveCallback = NULL;
#endif #endif
#ifdef LINUX_ARCH_RASPBERRYPI #ifdef LINUX_ARCH_RASPBERRYPI
uint8_t spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes) uint8_t spi_rxbuff[32+1] ; //SPI receive buffer (payload max 32 bytes)
uint8_t spi_txbuff[32+1] ; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command) uint8_t spi_txbuff[32+1] ; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command)
#endif #endif
LOCAL void RF24_csn(bool level) { LOCAL void RF24_csn(const bool level)
{
hwDigitalWrite(MY_RF24_CS_PIN, level); hwDigitalWrite(MY_RF24_CS_PIN, level);
} }
LOCAL void RF24_ce(bool level) { LOCAL void RF24_ce(const bool level)
{
hwDigitalWrite(MY_RF24_CE_PIN, level); hwDigitalWrite(MY_RF24_CE_PIN, level);
} }
LOCAL uint8_t RF24_spiMultiByteTransfer(uint8_t cmd, uint8_t* buf, uint8_t len, bool aReadMode) { LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, uint8_t len, const bool aReadMode)
{
uint8_t status; uint8_t status;
uint8_t* current = buf; uint8_t* current = buf;
#if !defined(MY_SOFTSPI) #if !defined(MY_SOFTSPI)
_SPI.beginTransaction(SPISettings(MY_RF24_SPI_MAX_SPEED, MY_RF24_SPI_DATA_ORDER, MY_RF24_SPI_DATA_MODE)); _SPI.beginTransaction(SPISettings(MY_RF24_SPI_MAX_SPEED, MY_RF24_SPI_DATA_ORDER, MY_RF24_SPI_DATA_MODE));
#endif #endif
RF24_csn(LOW); RF24_csn(LOW);
// timing // timing
delayMicroseconds(10); delayMicroseconds(10);
#ifdef LINUX_ARCH_RASPBERRYPI #ifdef LINUX_ARCH_RASPBERRYPI
uint8_t * prx = spi_rxbuff; uint8_t * prx = spi_rxbuff;
uint8_t * ptx = spi_txbuff; uint8_t * ptx = spi_txbuff;
uint8_t size = len + 1; // Add register value to transmit buffer uint8_t size = len + 1; // Add register value to transmit buffer
@@ -71,244 +74,278 @@ LOCAL uint8_t RF24_spiMultiByteTransfer(uint8_t cmd, uint8_t* buf, uint8_t len,
} else { } else {
status = *prx++; // status is 1st byte of receive buffer status = *prx++; // status is 1st byte of receive buffer
// decrement before to skip status byte // decrement before to skip status byte
while (--size) { *buf++ = *prx++; } while (--size) {
*buf++ = *prx++;
}
} }
} else { } else {
status = *prx; // status is 1st byte of receive buffer status = *prx; // status is 1st byte of receive buffer
} }
#else #else
status = _SPI.transfer( cmd ); status = _SPI.transfer(cmd);
while ( len-- ) { while ( len-- ) {
if (aReadMode) { if (aReadMode) {
status = _SPI.transfer( NOP ); status = _SPI.transfer(RF24_NOP);
if (buf != NULL) { if (buf != NULL) {
*current++ = status; *current++ = status;
} }
} else status = _SPI.transfer(*current++); } else {
status = _SPI.transfer(*current++);
} }
#endif }
#endif
RF24_csn(HIGH); RF24_csn(HIGH);
#if !defined(MY_SOFTSPI) #if !defined(MY_SOFTSPI)
_SPI.endTransaction(); _SPI.endTransaction();
#endif #endif
// timing // timing
delayMicroseconds(10); delayMicroseconds(10);
return status; return status;
} }
LOCAL uint8_t RF24_spiByteTransfer(uint8_t cmd) { LOCAL uint8_t RF24_spiByteTransfer(const uint8_t cmd)
return RF24_spiMultiByteTransfer( cmd, NULL, 0, false); {
return RF24_spiMultiByteTransfer(cmd, NULL, 0, false);
} }
LOCAL uint8_t RF24_RAW_readByteRegister(uint8_t cmd) { LOCAL uint8_t RF24_RAW_readByteRegister(const uint8_t cmd)
const uint8_t value = RF24_spiMultiByteTransfer( cmd, NULL, 1, true); {
RF24_DEBUG(PSTR("RF24:read register, reg=%d, value=%d\n"), cmd & (R_REGISTER ^ 0xFF), value); const uint8_t value = RF24_spiMultiByteTransfer(cmd, NULL, 1, true);
RF24_DEBUG(PSTR("RF24:read register, reg=%d, value=%d\n"), cmd & RF24_REGISTER_MASK, value);
return value; return value;
} }
LOCAL uint8_t RF24_RAW_writeByteRegister(uint8_t cmd, uint8_t value) { LOCAL uint8_t RF24_RAW_writeByteRegister(const uint8_t cmd, uint8_t value)
RF24_DEBUG(PSTR("RF24:write register, reg=%d, value=%d\n"), cmd & (W_REGISTER ^ 0xFF), value); {
RF24_DEBUG(PSTR("RF24:write register, reg=%d, value=%d\n"), cmd & RF24_REGISTER_MASK, value);
return RF24_spiMultiByteTransfer( cmd , &value, 1, false); return RF24_spiMultiByteTransfer( cmd , &value, 1, false);
} }
LOCAL void RF24_flushRX(void) { LOCAL void RF24_flushRX(void)
{
RF24_DEBUG(PSTR("RF24:flushRX\n")); RF24_DEBUG(PSTR("RF24:flushRX\n"));
RF24_spiByteTransfer( FLUSH_RX ); RF24_spiByteTransfer(RF24_FLUSH_RX);
} }
LOCAL void RF24_flushTX(void) { LOCAL void RF24_flushTX(void)
{
RF24_DEBUG(PSTR("RF24:flushTX\n")); RF24_DEBUG(PSTR("RF24:flushTX\n"));
RF24_spiByteTransfer( FLUSH_TX ); RF24_spiByteTransfer(RF24_FLUSH_TX);
} }
LOCAL uint8_t RF24_getStatus(void) { LOCAL uint8_t RF24_getStatus(void)
return RF24_spiByteTransfer( NOP ); {
return RF24_spiByteTransfer(RF24_NOP);
} }
LOCAL uint8_t RF24_getFIFOStatus(void) { LOCAL uint8_t RF24_getFIFOStatus(void)
return RF24_readByteRegister(FIFO_STATUS); {
return RF24_readByteRegister(RF24_FIFO_STATUS);
} }
LOCAL void RF24_setChannel(uint8_t channel) { LOCAL void RF24_setChannel(const uint8_t channel)
RF24_writeByteRegister(RF_CH, channel); {
RF24_writeByteRegister(RF24_RF_CH,channel);
} }
LOCAL void RF24_setRetries(uint8_t retransmitDelay, uint8_t retransmitCount) { LOCAL void RF24_setRetries(const uint8_t retransmitDelay, const uint8_t retransmitCount)
RF24_writeByteRegister(SETUP_RETR, retransmitDelay << ARD | retransmitCount << ARC); {
RF24_writeByteRegister(RF24_SETUP_RETR, retransmitDelay << RF24_ARD | retransmitCount << RF24_ARC);
} }
LOCAL void RF24_setAddressWidth(uint8_t width) { LOCAL void RF24_setAddressWidth(const uint8_t width)
RF24_writeByteRegister(SETUP_AW, width - 2); {
RF24_writeByteRegister(RF24_SETUP_AW, width - 2);
} }
LOCAL void RF24_setRFSetup(uint8_t RFsetup) { LOCAL void RF24_setRFSetup(const uint8_t RFsetup)
RF24_writeByteRegister(RF_SETUP, RFsetup); {
RF24_writeByteRegister(RF24_RF_SETUP, RFsetup);
} }
LOCAL void RF24_setFeature(uint8_t feature) { LOCAL void RF24_setFeature(const uint8_t feature)
RF24_writeByteRegister(FEATURE, feature); {
RF24_writeByteRegister(RF24_FEATURE, feature);
} }
LOCAL void RF24_setPipe(uint8_t pipe) { LOCAL void RF24_setPipe(const uint8_t pipe)
RF24_writeByteRegister(EN_RXADDR, pipe); {
RF24_writeByteRegister(RF24_EN_RXADDR, pipe);
} }
LOCAL void RF24_setAutoACK(uint8_t pipe) { LOCAL void RF24_setAutoACK(const uint8_t pipe)
RF24_writeByteRegister(EN_AA, pipe); {
RF24_writeByteRegister(RF24_EN_AA, pipe);
} }
LOCAL void RF24_setDynamicPayload(uint8_t pipe) { LOCAL void RF24_setDynamicPayload(const uint8_t pipe)
RF24_writeByteRegister(DYNPD, pipe); {
RF24_writeByteRegister(RF24_DYNPD, pipe);
} }
LOCAL void RF24_setRFConfiguration(uint8_t configuration) { LOCAL void RF24_setRFConfiguration(const uint8_t configuration)
RF24_writeByteRegister(NRF_CONFIG, configuration); {
RF24_writeByteRegister(RF24_NRF_CONFIG, configuration);
} }
LOCAL void RF24_setPipeAddress(uint8_t pipe, uint8_t* address, uint8_t width) { LOCAL void RF24_setPipeAddress(const uint8_t pipe, uint8_t* address, const uint8_t width)
{
RF24_writeMultiByteRegister(pipe, address, width); RF24_writeMultiByteRegister(pipe, address, width);
} }
LOCAL void RF24_setPipeLSB(uint8_t pipe, uint8_t LSB) { LOCAL void RF24_setPipeLSB(const uint8_t pipe, const uint8_t LSB)
{
RF24_writeByteRegister(pipe, LSB); RF24_writeByteRegister(pipe, LSB);
} }
LOCAL uint8_t RF24_getObserveTX(void) { LOCAL uint8_t RF24_getObserveTX(void)
return RF24_readByteRegister(OBSERVE_TX); {
return RF24_readByteRegister(RF24_OBSERVE_TX);
} }
LOCAL void RF24_setStatus(uint8_t status) { LOCAL void RF24_setStatus(const uint8_t status)
{
RF24_writeByteRegister(RF24_STATUS, status); RF24_writeByteRegister(RF24_STATUS, status);
} }
LOCAL void RF24_enableFeatures(void) { LOCAL void RF24_enableFeatures(void)
RF24_RAW_writeByteRegister(ACTIVATE, 0x73); {
RF24_RAW_writeByteRegister(RF24_ACTIVATE, 0x73);
} }
LOCAL void RF24_openWritingPipe(uint8_t recipient) { LOCAL void RF24_openWritingPipe(const uint8_t recipient)
RF24_DEBUG(PSTR("RF24:open writing pipe, recipient=%d\n"), recipient); {
RF24_DEBUG(PSTR("RF24:OPEN WPIPE,RCPT=%d\n"), recipient); // open writing pipe
// only write LSB of RX0 and TX pipe // only write LSB of RX0 and TX pipe
RF24_setPipeLSB(RX_ADDR_P0, recipient); RF24_setPipeLSB(RF24_RX_ADDR_P0, recipient);
RF24_setPipeLSB(TX_ADDR, recipient); RF24_setPipeLSB(RF24_TX_ADDR, recipient);
} }
LOCAL void RF24_startListening(void) { LOCAL void RF24_startListening(void)
RF24_DEBUG(PSTR("RF24:start listening\n")); {
RF24_DEBUG(PSTR("RF24:STRT LIS\n")); // start listening
// toggle PRX // toggle PRX
RF24_setRFConfiguration(MY_RF24_CONFIGURATION | _BV(PWR_UP) | _BV(PRIM_RX) ); RF24_setRFConfiguration(MY_RF24_CONFIGURATION | _BV(RF24_PWR_UP) | _BV(RF24_PRIM_RX) );
// all RX pipe addresses must be unique, therefore skip if node ID is 0xFF // all RX pipe addresses must be unique, therefore skip if node ID is AUTO
if(MY_RF24_NODE_ADDRESS!=AUTO) { if(MY_RF24_NODE_ADDRESS!=AUTO) {
RF24_setPipeLSB(RX_ADDR_P0, MY_RF24_NODE_ADDRESS); RF24_setPipeLSB(RF24_RX_ADDR_P0, MY_RF24_NODE_ADDRESS);
} }
// start listening // start listening
RF24_ce(HIGH); RF24_ce(HIGH);
} }
LOCAL void RF24_stopListening(void) { LOCAL void RF24_stopListening(void)
RF24_DEBUG(PSTR("RF24:stop listening\n")); {
RF24_DEBUG(PSTR("RF24:STP LIS\n")); // stop listening
RF24_ce(LOW); RF24_ce(LOW);
// timing // timing
delayMicroseconds(130); delayMicroseconds(130);
RF24_setRFConfiguration(MY_RF24_CONFIGURATION | _BV(PWR_UP) ); RF24_setRFConfiguration(MY_RF24_CONFIGURATION | _BV(RF24_PWR_UP) );
// timing // timing
delayMicroseconds(100); delayMicroseconds(100);
} }
LOCAL void RF24_powerDown(void) { LOCAL void RF24_powerDown(void)
{
RF24_ce(LOW); RF24_ce(LOW);
RF24_setRFConfiguration(MY_RF24_CONFIGURATION); RF24_setRFConfiguration(MY_RF24_CONFIGURATION);
RF24_DEBUG(PSTR("RF24:power down\n")); RF24_DEBUG(PSTR("RF24:PD\n")); // power down
} }
LOCAL bool RF24_sendMessage( uint8_t recipient, const void* buf, uint8_t len ) { LOCAL bool RF24_sendMessage(const uint8_t recipient, const void* buf, const uint8_t len)
uint8_t status; {
uint8_t RF24_status;
RF24_stopListening(); RF24_stopListening();
RF24_openWritingPipe( recipient ); RF24_openWritingPipe( recipient );
RF24_DEBUG(PSTR("RF24:send message to %d, len=%d\n"),recipient,len); RF24_DEBUG(PSTR("RF24:SND:TO=%d,LEN=%d\n"),recipient,len); // send message
// flush TX FIFO // flush TX FIFO
RF24_flushTX(); RF24_flushTX();
// this command is affected in clones (e.g. Si24R1): flipped NoACK bit when using W_TX_PAYLOAD_NO_ACK / W_TX_PAYLOAD // this command is affected in clones (e.g. Si24R1): flipped NoACK bit when using W_TX_PAYLOAD_NO_ACK / W_TX_PAYLOAD
// AutoACK is disabled on the broadcasting pipe - NO_ACK prevents resending // AutoACK is disabled on the broadcasting pipe - NO_ACK prevents resending
RF24_spiMultiByteTransfer(recipient == BROADCAST_ADDRESS ? W_TX_PAYLOAD_NO_ACK : W_TX_PAYLOAD, (uint8_t*)buf, len, false ); RF24_spiMultiByteTransfer(recipient == BROADCAST_ADDRESS ? RF24_WRITE_TX_PAYLOAD_NO_ACK : RF24_WRITE_TX_PAYLOAD, (uint8_t*)buf, len, false );
// go, TX starts after ~10us // go, TX starts after ~10us
RF24_ce(HIGH); RF24_ce(HIGH);
// timeout counter to detect HW issues // timeout counter to detect HW issues
uint16_t timeout = 0xFFFF; uint16_t timeout = 0xFFFF;
do { do {
status = RF24_getStatus(); RF24_status = RF24_getStatus();
} while (!(status & ( _BV(MAX_RT) | _BV(TX_DS) )) && timeout--); } while (!(RF24_status & ( _BV(RF24_MAX_RT) | _BV(RF24_TX_DS) )) && timeout--);
// timeout value after successful TX on 16Mhz AVR ~ 65500, i.e. msg is transmitted after ~36 loop cycles // timeout value after successful TX on 16Mhz AVR ~ 65500, i.e. msg is transmitted after ~36 loop cycles
RF24_ce(LOW); RF24_ce(LOW);
// reset interrupts // reset interrupts
RF24_setStatus(_BV(TX_DS) | _BV(MAX_RT) ); RF24_setStatus(_BV(RF24_TX_DS) | _BV(RF24_MAX_RT) );
// Max retries exceeded // Max retries exceeded
if( status & _BV(MAX_RT)){ if(RF24_status & _BV(RF24_MAX_RT)) {
// flush packet // flush packet
RF24_DEBUG(PSTR("RF24:MAX_RT\n")); RF24_DEBUG(PSTR("!RF24:SND:MAX_RT\n")); // max retries, no ACK
RF24_flushTX(); RF24_flushTX();
} }
RF24_startListening(); RF24_startListening();
// true if message sent // true if message sent
return ( status & _BV(TX_DS) ); return (RF24_status & _BV(RF24_TX_DS));
} }
LOCAL uint8_t RF24_getDynamicPayloadSize(void) { LOCAL uint8_t RF24_getDynamicPayloadSize(void)
uint8_t result = RF24_spiMultiByteTransfer(R_RX_PL_WID, NULL, 1, true); {
uint8_t result = RF24_spiMultiByteTransfer(RF24_READ_RX_PL_WID, NULL, 1, true);
// check if payload size invalid // check if payload size invalid
if(result > 32) { if(result > 32) {
RF24_DEBUG(PSTR("RF24:invalid payload length = %d\n"),result); RF24_DEBUG(PSTR("!RF24:GDP:PAYL LEN INVALID=%d\n"),result); // payload len invalid
RF24_flushRX(); RF24_flushRX();
result = 0; result = 0;
} }
return result; return result;
} }
LOCAL bool RF24_isDataAvailable() { LOCAL bool RF24_isDataAvailable()
return ( !(RF24_getFIFOStatus() & _BV(0)) ); {
return (!(RF24_getFIFOStatus() & _BV(0)) );
} }
LOCAL uint8_t RF24_readMessage( void* buf) { LOCAL uint8_t RF24_readMessage(void* buf)
{
const uint8_t len = RF24_getDynamicPayloadSize(); const uint8_t len = RF24_getDynamicPayloadSize();
RF24_DEBUG(PSTR("RF24:read message, len=%d\n"), len); RF24_DEBUG(PSTR("RF24:RDM:MSG LEN=%d\n"), len); // read message
RF24_spiMultiByteTransfer( R_RX_PAYLOAD , (uint8_t*)buf, len, true ); RF24_spiMultiByteTransfer(RF24_READ_RX_PAYLOAD,(uint8_t*)buf,len,true);
// clear RX interrupt // clear RX interrupt
RF24_setStatus(_BV(RX_DR) ); RF24_setStatus(_BV(RF24_RX_DR));
return len; return len;
} }
LOCAL void RF24_setNodeAddress(uint8_t address) { LOCAL void RF24_setNodeAddress(const uint8_t address)
if(address!=AUTO){ {
if(address!=AUTO) {
MY_RF24_NODE_ADDRESS = address; MY_RF24_NODE_ADDRESS = address;
// enable node pipe // enable node pipe
RF24_setPipe(_BV(ERX_P0 + BROADCAST_PIPE) | _BV(ERX_P0) ); RF24_setPipe(_BV(RF24_ERX_P0 + RF24_BROADCAST_PIPE) | _BV(RF24_ERX_P0));
// enable autoACK on pipe 0 // enable autoACK on pipe 0
RF24_setAutoACK(_BV(ENAA_P0) ); RF24_setAutoACK(_BV(RF24_ENAA_P0));
} }
} }
LOCAL uint8_t RF24_getNodeID(void) { LOCAL uint8_t RF24_getNodeID(void)
{
return MY_RF24_NODE_ADDRESS; return MY_RF24_NODE_ADDRESS;
} }
LOCAL bool RF24_sanityCheck(void) { LOCAL bool RF24_sanityCheck(void)
{
// detect HW defect, configuration errors or interrupted SPI line, CE disconnect cannot be detected // detect HW defect, configuration errors or interrupted SPI line, CE disconnect cannot be detected
return (RF24_readByteRegister(RF_SETUP) == MY_RF24_RF_SETUP) & (RF24_readByteRegister(RF_CH) == MY_RF24_CHANNEL); return (RF24_readByteRegister(RF24_RF_SETUP) == MY_RF24_RF_SETUP) & (RF24_readByteRegister(RF24_RF_CH) == MY_RF24_CHANNEL);
} }
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
LOCAL void RF24_irqHandler( void ) LOCAL void RF24_irqHandler(void)
{ {
if (RF24_receiveCallback) if (RF24_receiveCallback) {
{
// Will stay for a while (several 100us) in this interrupt handler. Any interrupts from serial // Will stay for a while (several 100us) in this interrupt handler. Any interrupts from serial
// rx coming in during our stay will not be handled and will cause characters to be lost. // rx coming in during our stay will not be handled and will cause characters to be lost.
// As a workaround we re-enable interrupts to allow nested processing of other interrupts. // As a workaround we re-enable interrupts to allow nested processing of other interrupts.
// Our own handler is disconnected to prevent recursive calling of this handler. // Our own handler is disconnected to prevent recursive calling of this handler.
#if defined(MY_GATEWAY_SERIAL) && !defined(__linux__) #if defined(MY_GATEWAY_SERIAL) && !defined(__linux__)
detachInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN)); detachInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN));
interrupts(); interrupts();
#endif #endif
// Read FIFO until empty. // Read FIFO until empty.
// Procedure acc. to datasheet (pg. 63): // Procedure acc. to datasheet (pg. 63):
// 1.Read payload, 2.Clear RX_DR IRQ, 3.Read FIFO_status, 4.Repeat when more data available. // 1.Read payload, 2.Clear RX_DR IRQ, 3.Read FIFO_status, 4.Repeat when more data available.
@@ -320,53 +357,55 @@ LOCAL void RF24_irqHandler( void )
RF24_receiveCallback(); // Must call RF24_readMessage(), which will clear RX_DR IRQ ! RF24_receiveCallback(); // Must call RF24_readMessage(), which will clear RX_DR IRQ !
} }
// Restore our interrupt handler. // Restore our interrupt handler.
#if defined(MY_GATEWAY_SERIAL) && !defined(__linux__) #if defined(MY_GATEWAY_SERIAL) && !defined(__linux__)
noInterrupts(); noInterrupts();
attachInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN), RF24_irqHandler, FALLING); attachInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN), RF24_irqHandler, FALLING);
#endif #endif
} else { } else {
// clear RX interrupt // clear RX interrupt
RF24_setStatus(_BV(RX_DR)); RF24_setStatus(_BV(RF24_RX_DR));
} }
} }
LOCAL void RF24_registerReceiveCallback( RF24_receiveCallbackType cb ) { LOCAL void RF24_registerReceiveCallback(RF24_receiveCallbackType cb)
{
MY_CRITICAL_SECTION { MY_CRITICAL_SECTION {
RF24_receiveCallback = cb; RF24_receiveCallback = cb;
} }
} }
#endif #endif
LOCAL bool RF24_initialize(void) { LOCAL bool RF24_initialize(void)
{
// prevent warning // prevent warning
(void)RF24_getObserveTX; (void)RF24_getObserveTX;
// Initialize pins // Initialize pins
hwPinMode(MY_RF24_CE_PIN,OUTPUT); hwPinMode(MY_RF24_CE_PIN,OUTPUT);
hwPinMode(MY_RF24_CS_PIN,OUTPUT); hwPinMode(MY_RF24_CS_PIN,OUTPUT);
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
hwPinMode(MY_RF24_IRQ_PIN,INPUT); hwPinMode(MY_RF24_IRQ_PIN,INPUT);
#endif #endif
// Initialize SPI // Initialize SPI
_SPI.begin(); _SPI.begin();
RF24_ce(LOW); RF24_ce(LOW);
RF24_csn(HIGH); RF24_csn(HIGH);
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
// assure SPI can be used from interrupt context // assure SPI can be used from interrupt context
// Note: ESP8266 & SoftSPI currently do not support interrupt usage for SPI, // Note: ESP8266 & SoftSPI currently do not support interrupt usage for SPI,
// therefore it is unsafe to use MY_RF24_IRQ_PIN with ESP8266/SoftSPI! // therefore it is unsafe to use MY_RF24_IRQ_PIN with ESP8266/SoftSPI!
_SPI.usingInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN)); _SPI.usingInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN));
// attach interrupt // attach interrupt
attachInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN), RF24_irqHandler, FALLING); attachInterrupt(digitalPinToInterrupt(MY_RF24_IRQ_PIN), RF24_irqHandler, FALLING);
#endif #endif
// CRC and power up // CRC and power up
RF24_setRFConfiguration(MY_RF24_CONFIGURATION | _BV(PWR_UP) ) ; RF24_setRFConfiguration(MY_RF24_CONFIGURATION | _BV(RF24_PWR_UP)) ;
// settle >2ms // settle >2ms
delay(5); delay(5);
// set address width // set address width
RF24_setAddressWidth(MY_RF24_ADDR_WIDTH); RF24_setAddressWidth(MY_RF24_ADDR_WIDTH);
// auto retransmit delay 1500us, auto retransmit count 15 // auto retransmit delay 1500us, auto retransmit count 15
RF24_setRetries(RF24_ARD, RF24_ARC); RF24_setRetries(RF24_SET_ARD, RF24_SET_ARC);
// set channel // set channel
RF24_setChannel(MY_RF24_CHANNEL); RF24_setChannel(MY_RF24_CHANNEL);
// set data rate and pa level // set data rate and pa level
@@ -377,25 +416,25 @@ LOCAL bool RF24_initialize(void) {
RF24_setFeature(MY_RF24_FEATURE); RF24_setFeature(MY_RF24_FEATURE);
// sanity check (this function is P/non-P independent) // sanity check (this function is P/non-P independent)
if (!RF24_sanityCheck()) { if (!RF24_sanityCheck()) {
RF24_DEBUG(PSTR("!RF24:Sanity check failed: configuration mismatch! Check wiring or replace module\n")); RF24_DEBUG(PSTR("!RF24:INIT:SANCHK FAIL\n")); // sanity check failed, check wiring or replace module
return false; return false;
} }
// enable broadcasting pipe // enable broadcasting pipe
RF24_setPipe(_BV(ERX_P0 + BROADCAST_PIPE)); RF24_setPipe(_BV(RF24_ERX_P0 + RF24_BROADCAST_PIPE));
// disable AA on all pipes, activate when node pipe set // disable AA on all pipes, activate when node pipe set
RF24_setAutoACK(0x00); RF24_setAutoACK(0x00);
// enable dynamic payloads on used pipes // enable dynamic payloads on used pipes
RF24_setDynamicPayload(_BV(DPL_P0 + BROADCAST_PIPE) | _BV(DPL_P0)); RF24_setDynamicPayload(_BV(RF24_DPL_P0 + RF24_BROADCAST_PIPE) | _BV(RF24_DPL_P0));
// listen to broadcast pipe // listen to broadcast pipe
MY_RF24_BASE_ADDR[0] = BROADCAST_ADDRESS; MY_RF24_BASE_ADDR[0] = BROADCAST_ADDRESS;
RF24_setPipeAddress(RX_ADDR_P0 + BROADCAST_PIPE, (uint8_t*)&MY_RF24_BASE_ADDR, BROADCAST_PIPE > 1 ? 1 : MY_RF24_ADDR_WIDTH); RF24_setPipeAddress(RF24_RX_ADDR_P0 + RF24_BROADCAST_PIPE, (uint8_t*)&MY_RF24_BASE_ADDR, RF24_BROADCAST_PIPE > 1 ? 1 : MY_RF24_ADDR_WIDTH);
// pipe 0, set full address, later only LSB is updated // pipe 0, set full address, later only LSB is updated
RF24_setPipeAddress(RX_ADDR_P0, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH); RF24_setPipeAddress(RF24_RX_ADDR_P0, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH);
RF24_setPipeAddress(TX_ADDR, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH); RF24_setPipeAddress(RF24_TX_ADDR, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH);
// reset FIFO // reset FIFO
RF24_flushRX(); RF24_flushRX();
RF24_flushTX(); RF24_flushTX();
// reset interrupts // reset interrupts
RF24_setStatus(_BV(TX_DS) | _BV(MAX_RT) | _BV(RX_DR)); RF24_setStatus(_BV(RF24_TX_DS) | _BV(RF24_MAX_RT) | _BV(RF24_RX_DR));
return true; return true;
} }
+131 -131
View File
@@ -83,16 +83,16 @@
// RF24 settings // RF24 settings
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
#define MY_RF24_CONFIGURATION (uint8_t) ((RF24_CRC_16 << 2) | (1 << MASK_TX_DS) | (1 << MASK_MAX_RT)) #define MY_RF24_CONFIGURATION (uint8_t) ((RF24_CRC_16 << 2) | (1 << RF24_MASK_TX_DS) | (1 << RF24_MASK_MAX_RT))
#else #else
#define MY_RF24_CONFIGURATION (uint8_t) (RF24_CRC_16 << 2) #define MY_RF24_CONFIGURATION (uint8_t) (RF24_CRC_16 << 2)
#endif #endif
#define MY_RF24_FEATURE (uint8_t)( _BV(EN_DPL) | _BV(EN_ACK_PAY) ) #define MY_RF24_FEATURE (uint8_t)( _BV(RF24_EN_DPL) | _BV(RF24_EN_ACK_PAY) )
#define MY_RF24_RF_SETUP (uint8_t)( ((MY_RF24_DATARATE & 0b10 ) << 4) | ((MY_RF24_DATARATE & 0b01 ) << 3) | (MY_RF24_PA_LEVEL << 1) ) + 1 // +1 for Si24R1 #define MY_RF24_RF_SETUP (uint8_t)( ((MY_RF24_DATARATE & 0b10 ) << 4) | ((MY_RF24_DATARATE & 0b01 ) << 3) | (MY_RF24_PA_LEVEL << 1) ) + 1 // +1 for Si24R1
// pipes // pipes
#define BROADCAST_PIPE 1 #define RF24_BROADCAST_PIPE (1)
#define NODE_PIPE 0 #define RF24_NODE_PIPE (0)
// debug // debug
#if defined(MY_DEBUG_VERBOSE_RF24) #if defined(MY_DEBUG_VERBOSE_RF24)
@@ -102,146 +102,146 @@
#endif #endif
// PA levels // PA levels
#define RF24_PA_MIN 0 #define RF24_PA_MIN (0)
#define RF24_PA_LOW 1 #define RF24_PA_LOW (1)
#define RF24_PA_HIGH 2 #define RF24_PA_HIGH (2)
#define RF24_PA_MAX 3 #define RF24_PA_MAX (3)
// data rate // data rate
#define RF24_1MBPS 0 #define RF24_1MBPS (0)
#define RF24_2MBPS 1 #define RF24_2MBPS (1)
#define RF24_250KBPS 2 #define RF24_250KBPS (2)
// CRC // CRC
#define RF24_CRC_DISABLED 0 #define RF24_CRC_DISABLED (0)
#define RF24_CRC_8 2 #define RF24_CRC_8 (2)
#define RF24_CRC_16 3 #define RF24_CRC_16 (3)
// ARD, auto retry delay // ARD, auto retry delay
#define RF24_ARD 5 //=1500us #define RF24_SET_ARD (5) //=1500us
// ARD, auto retry count // ARD, auto retry count
#define RF24_ARC 15 #define RF24_SET_ARC (15)
// nRF24L01(+) register definitions // nRF24L01(+) register definitions
#define NRF_CONFIG 0x00 #define RF24_NRF_CONFIG (0x00)
#define EN_AA 0x01 #define RF24_EN_AA (0x01)
#define EN_RXADDR 0x02 #define RF24_EN_RXADDR (0x02)
#define SETUP_AW 0x03 #define RF24_SETUP_AW (0x03)
#define SETUP_RETR 0x04 #define RF24_SETUP_RETR (0x04)
#define RF_CH 0x05 #define RF24_RF_CH (0x05)
#define RF_SETUP 0x06 #define RF24_RF_SETUP (0x06)
#define RF24_STATUS 0x07 #define RF24_STATUS (0x07)
#define OBSERVE_TX 0x08 #define RF24_OBSERVE_TX (0x08)
#define CD 0x09 #define RF24_CD (0x09)
#define RX_ADDR_P0 0x0A #define RF24_RX_ADDR_P0 (0x0A)
#define RX_ADDR_P1 0x0B #define RF24_RX_ADDR_P1 (0x0B)
#define RX_ADDR_P2 0x0C #define RF24_RX_ADDR_P2 (0x0C)
#define RX_ADDR_P3 0x0D #define RF24_RX_ADDR_P3 (0x0D)
#define RX_ADDR_P4 0x0E #define RF24_RX_ADDR_P4 (0x0E)
#define RX_ADDR_P5 0x0F #define RF24_RX_ADDR_P5 (0x0F)
#define TX_ADDR 0x10 #define RF24_TX_ADDR (0x10)
#define RX_PW_P0 0x11 #define RF24_RX_PW_P0 (0x11)
#define RX_PW_P1 0x12 #define RF24_RX_PW_P1 (0x12)
#define RX_PW_P2 0x13 #define RF24_RX_PW_P2 (0x13)
#define RX_PW_P3 0x14 #define RF24_RX_PW_P3 (0x14)
#define RX_PW_P4 0x15 #define RF24_RX_PW_P4 (0x15)
#define RX_PW_P5 0x16 #define RF24_RX_PW_P5 (0x16)
#define FIFO_STATUS 0x17 #define RF24_FIFO_STATUS (0x17)
#define DYNPD 0x1C #define RF24_DYNPD (0x1C)
#define FEATURE 0x1D #define RF24_FEATURE (0x1D)
// instructions // instructions
#define R_REGISTER 0x00 #define RF24_READ_REGISTER (0x00)
#define RPD 0x09 #define RF24_RPD (0x09)
#define W_REGISTER 0x20 #define RF24_WRITE_REGISTER (0x20)
#define REGISTER_MASK 0x1F #define RF24_REGISTER_MASK (0x1F)
#define ACTIVATE 0x50 #define RF24_ACTIVATE (0x50)
#define R_RX_PL_WID 0x60 #define RF24_READ_RX_PL_WID (0x60)
#define R_RX_PAYLOAD 0x61 #define RF24_READ_RX_PAYLOAD (0x61)
#define W_TX_PAYLOAD 0xA0 #define RF24_WRITE_TX_PAYLOAD (0xA0)
#define W_ACK_PAYLOAD 0xA8 #define RF24_WRITE_ACK_PAYLOAD (0xA8)
#define W_TX_PAYLOAD_NO_ACK 0xB0 #define RF24_WRITE_TX_PAYLOAD_NO_ACK (0xB0)
#define FLUSH_TX 0xE1 #define RF24_FLUSH_TX (0xE1)
#define FLUSH_RX 0xE2 #define RF24_FLUSH_RX (0xE2)
#define REUSE_TX_PL 0xE3 #define RF24_REUSE_TX_PL (0xE3)
#define NOP 0xFF #define RF24_NOP (0xFF)
// bit mnemonics // bit mnemonics
#define MASK_RX_DR 6 #define RF24_MASK_RX_DR (6)
#define MASK_TX_DS 5 #define RF24_MASK_TX_DS (5)
#define MASK_MAX_RT 4 #define RF24_MASK_MAX_RT (4)
#define EN_CRC 3 #define RF24_EN_CRC (3)
#define CRCO 2 #define RF24_CRCO (2)
#define PWR_UP 1 #define RF24_PWR_UP (1)
#define PRIM_RX 0 #define RF24_PRIM_RX (0)
// auto ACK // auto ACK
#define ENAA_P5 5 #define RF24_ENAA_P5 (5)
#define ENAA_P4 4 #define RF24_ENAA_P4 (4)
#define ENAA_P3 3 #define RF24_ENAA_P3 (3)
#define ENAA_P2 2 #define RF24_ENAA_P2 (2)
#define ENAA_P1 1 #define RF24_ENAA_P1 (1)
#define ENAA_P0 0 #define RF24_ENAA_P0 (0)
// rx pipe // rx pipe
#define ERX_P5 5 #define RF24_ERX_P5 (5)
#define ERX_P4 4 #define RF24_ERX_P4 (4)
#define ERX_P3 3 #define RF24_ERX_P3 (3)
#define ERX_P2 2 #define RF24_ERX_P2 (2)
#define ERX_P1 1 #define RF24_ERX_P1 (1)
#define ERX_P0 0 #define RF24_ERX_P0 (0)
// dynamic payload // dynamic payload
#define DPL_P5 5 #define RF24_DPL_P5 (5)
#define DPL_P4 4 #define RF24_DPL_P4 (4)
#define DPL_P3 3 #define RF24_DPL_P3 (3)
#define DPL_P2 2 #define RF24_DPL_P2 (2)
#define DPL_P1 1 #define RF24_DPL_P1 (1)
#define DPL_P0 0 #define RF24_DPL_P0 (0)
#define AW 0 #define RF24_AW (0)
#define ARD 4 #define RF24_ARD (4)
#define ARC 0 #define RF24_ARC (0)
#define PLL_LOCK 4 #define RF24_PLL_LOCK (4)
#define RF_DR 3 #define RF24_RF_DR (3)
#define RF_PWR 6 #define RF24_RF_PWR (6)
#define RX_DR 6 #define RF24_RX_DR (6)
#define TX_DS 5 #define RF24_TX_DS (5)
#define MAX_RT 4 #define RF24_MAX_RT (4)
#define RX_P_NO 1 #define RF24_RX_P_NO (1)
#define TX_FULL 0 #define RF24_TX_FULL (0)
#define PLOS_CNT 4 #define RF24_PLOS_CNT (4)
#define ARC_CNT 0 #define RF24_ARC_CNT (0)
#define TX_REUSE 6 #define RF24_TX_REUSE (6)
#define FIFO_FULL 5 #define RF24_FIFO_FULL (5)
#define TX_EMPTY 4 #define RF24_TX_EMPTY (4)
#define RX_FULL 1 #define RF24_RX_FULL (1)
#define RX_EMPTY 0 #define RF24_RX_EMPTY (0)
// features // features
#define EN_DPL 2 #define RF24_EN_DPL (2)
#define EN_ACK_PAY 1 #define RF24_EN_ACK_PAY (1)
#define EN_DYN_ACK 0 #define RF24_EN_DYN_ACK (0)
#define LNA_HCURR 0 #define RF24_LNA_HCURR (0)
#define RF_DR_LOW 5 #define RF24_RF_DR_LOW (5)
#define RF_DR_HIGH 3 #define RF24_RF_DR_HIGH (3)
#define RF_PWR_LOW 1 #define RF24_RF_PWR_LOW (1)
#define RF_PWR_HIGH 2 #define RF24_RF_PWR_HIGH (2)
// functions // functions
LOCAL void RF24_csn(bool level); LOCAL void RF24_csn(const bool level);
LOCAL void RF24_ce(bool level); LOCAL void RF24_ce(const bool level);
LOCAL uint8_t RF24_spiMultiByteTransfer(uint8_t cmd, uint8_t* buf, uint8_t len, bool aReadMode); LOCAL uint8_t RF24_spiMultiByteTransfer(const uint8_t cmd, uint8_t* buf, const uint8_t len, const bool aReadMode);
LOCAL uint8_t RF24_spiByteTransfer(uint8_t cmd); LOCAL uint8_t RF24_spiByteTransfer(const uint8_t cmd);
LOCAL uint8_t RF24_RAW_readByteRegister(uint8_t cmd); LOCAL uint8_t RF24_RAW_readByteRegister(const uint8_t cmd);
LOCAL uint8_t RF24_RAW_writeByteRegister(uint8_t cmd, uint8_t value); LOCAL uint8_t RF24_RAW_writeByteRegister(const uint8_t cmd, const uint8_t value);
#define RF24_readByteRegister(reg) RF24_RAW_readByteRegister( R_REGISTER | ( REGISTER_MASK & (reg) ) ) #define RF24_readByteRegister(__reg) RF24_RAW_readByteRegister(RF24_READ_REGISTER | (RF24_REGISTER_MASK & __reg))
#define RF24_writeByteRegister(reg, value) RF24_RAW_writeByteRegister( W_REGISTER | ( REGISTER_MASK & (reg) ), value ) #define RF24_writeByteRegister(__reg,__value) RF24_RAW_writeByteRegister(RF24_WRITE_REGISTER | (RF24_REGISTER_MASK & __reg), __value)
#define RF24_writeMultiByteRegister(reg, buf, len) RF24_spiMultiByteTransfer( W_REGISTER | ( REGISTER_MASK & (reg) ), (uint8_t*)buf, len, false ) #define RF24_writeMultiByteRegister(__reg,__buf,__len) RF24_spiMultiByteTransfer(RF24_WRITE_REGISTER | (RF24_REGISTER_MASK & __reg),(uint8_t*)__buf, __len,false)
LOCAL void RF24_flushRX(void); LOCAL void RF24_flushRX(void);
LOCAL void RF24_flushTX(void); LOCAL void RF24_flushTX(void);
@@ -251,27 +251,27 @@ LOCAL void RF24_openWritingPipe(uint8_t recipient);
LOCAL void RF24_startListening(void); LOCAL void RF24_startListening(void);
LOCAL void RF24_stopListening(void); LOCAL void RF24_stopListening(void);
LOCAL void RF24_powerDown(void); LOCAL void RF24_powerDown(void);
LOCAL bool RF24_sendMessage(uint8_t recipient, const void* buf, uint8_t len); LOCAL bool RF24_sendMessage(const uint8_t recipient, const void* buf, const uint8_t len);
LOCAL uint8_t RF24_getDynamicPayloadSize(void); LOCAL uint8_t RF24_getDynamicPayloadSize(void);
LOCAL bool RF24_isDataAvailable(); LOCAL bool RF24_isDataAvailable();
LOCAL uint8_t RF24_readMessage(void* buf); LOCAL uint8_t RF24_readMessage(void* buf);
LOCAL void RF24_setNodeAddress(uint8_t address); LOCAL void RF24_setNodeAddress(const uint8_t address);
LOCAL uint8_t RF24_getNodeID(void); LOCAL uint8_t RF24_getNodeID(void);
LOCAL bool RF24_sanityCheck(void); LOCAL bool RF24_sanityCheck(void);
LOCAL bool RF24_initialize(void); LOCAL bool RF24_initialize(void);
LOCAL void RF24_setChannel(uint8_t channel); LOCAL void RF24_setChannel(const uint8_t channel);
LOCAL void RF24_setRetries(uint8_t retransmitDelay, uint8_t retransmitCount); LOCAL void RF24_setRetries(const uint8_t retransmitDelay, const uint8_t retransmitCount);
LOCAL void RF24_setAddressWidth(uint8_t width); LOCAL void RF24_setAddressWidth(const uint8_t width);
LOCAL void RF24_setRFSetup(uint8_t RFsetup); LOCAL void RF24_setRFSetup(const uint8_t RFsetup);
LOCAL void RF24_setFeature(uint8_t feature); LOCAL void RF24_setFeature(const uint8_t feature);
LOCAL void RF24_setPipe(uint8_t pipe); LOCAL void RF24_setPipe(const uint8_t pipe);
LOCAL void RF24_setAutoACK(uint8_t pipe); LOCAL void RF24_setAutoACK(const uint8_t pipe);
LOCAL void RF24_setDynamicPayload(uint8_t pipe); LOCAL void RF24_setDynamicPayload(const uint8_t pipe);
LOCAL void RF24_setRFConfiguration(uint8_t configuration); LOCAL void RF24_setRFConfiguration(const uint8_t configuration);
LOCAL void RF24_setPipeAddress(uint8_t pipe, uint8_t* address, uint8_t width); LOCAL void RF24_setPipeAddress(const uint8_t pipe, uint8_t* address, const uint8_t width);
LOCAL void RF24_setPipeLSB(uint8_t pipe, uint8_t LSB); LOCAL void RF24_setPipeLSB(const uint8_t pipe, const uint8_t LSB);
LOCAL uint8_t RF24_getObserveTX(void); LOCAL uint8_t RF24_getObserveTX(void);
LOCAL void RF24_setStatus(uint8_t status); LOCAL void RF24_setStatus(const uint8_t status);
LOCAL void RF24_enableFeatures(void); LOCAL void RF24_enableFeatures(void);
#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) #if defined(MY_RX_MESSAGE_BUFFER_FEATURE)
@@ -282,7 +282,7 @@ LOCAL void RF24_enableFeatures(void);
* by calling RF24_readMessage(). Otherwise the interrupt will not get deasserted * by calling RF24_readMessage(). Otherwise the interrupt will not get deasserted
* and message reception will stop. * and message reception will stop.
*/ */
LOCAL void RF24_registerReceiveCallback( RF24_receiveCallbackType cb ); LOCAL void RF24_registerReceiveCallback(RF24_receiveCallbackType cb);
#endif #endif
#endif // __RF24_H__ #endif // __RF24_H__