@@ -240,8 +240,7 @@
|
||||
#if defined(ARDUINO_ARCH_ESP8266)
|
||||
#error Soft SPI is not available on ESP8266
|
||||
#endif
|
||||
#include "drivers/AVR/DigitalIO/SoftI2cMaster.cpp"
|
||||
#include "drivers/AVR/DigitalIO/PinIO.cpp"
|
||||
#include "drivers/AVR/DigitalIO/DigitalIO.h"
|
||||
#endif
|
||||
|
||||
// FLASH
|
||||
|
||||
@@ -41,16 +41,16 @@ bool transportInit() {
|
||||
memset(_psk, 0, 16);
|
||||
#endif
|
||||
|
||||
return initializeRF24();
|
||||
return RF24_initialize();
|
||||
}
|
||||
|
||||
void transportSetAddress(uint8_t address) {
|
||||
setNodeAddress(address);
|
||||
startListening();
|
||||
RF24_setNodeAddress(address);
|
||||
RF24_startListening();
|
||||
}
|
||||
|
||||
uint8_t transportGetAddress() {
|
||||
return getNodeID();
|
||||
return RF24_getNodeID();
|
||||
}
|
||||
|
||||
bool transportSend(uint8_t recipient, const void* data, uint8_t len) {
|
||||
@@ -62,21 +62,21 @@ bool transportSend(uint8_t recipient, const void* data, uint8_t len) {
|
||||
len = len > 16 ? 32 : 16;
|
||||
//encrypt data
|
||||
_aes.cbc_encrypt(_dataenc, _dataenc, len/16);
|
||||
bool status = sendMessage( recipient, _dataenc, len );
|
||||
bool status = RF24_sendMessage( recipient, _dataenc, len );
|
||||
#else
|
||||
bool status = sendMessage( recipient, data, len );
|
||||
bool status = RF24_sendMessage( recipient, data, len );
|
||||
#endif
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
bool transportAvailable(uint8_t *to) {
|
||||
bool avail = IsDataAvailable(to);
|
||||
bool avail = RF24_isDataAvailable(to);
|
||||
return avail;
|
||||
}
|
||||
|
||||
uint8_t transportReceive(void* data) {
|
||||
uint8_t len = readMessage(data);
|
||||
uint8_t len = RF24_readMessage(data);
|
||||
#if defined(MY_RF24_ENABLE_ENCRYPTION)
|
||||
// has to be adjusted, WIP!
|
||||
_aes.set_IV(0);
|
||||
@@ -87,5 +87,5 @@ uint8_t transportReceive(void* data) {
|
||||
}
|
||||
|
||||
void transportPowerDown() {
|
||||
powerDown();
|
||||
RF24_powerDown();
|
||||
}
|
||||
|
||||
@@ -22,23 +22,23 @@
|
||||
|
||||
#include "RF24.h"
|
||||
|
||||
uint8_t MY_RF24_BASE_ADDR[MY_RF24_ADDR_WIDTH] = { MY_RF24_BASE_RADIO_ID };
|
||||
uint8_t MY_RF24_NODE_ADDRESS = AUTO;
|
||||
LOCAL uint8_t MY_RF24_BASE_ADDR[MY_RF24_ADDR_WIDTH] = { MY_RF24_BASE_RADIO_ID };
|
||||
LOCAL uint8_t MY_RF24_NODE_ADDRESS = AUTO;
|
||||
|
||||
void csn(bool level) {
|
||||
LOCAL void RF24_csn(bool level) {
|
||||
digitalWrite(MY_RF24_CS_PIN, level);
|
||||
}
|
||||
|
||||
void ce(bool level) {
|
||||
LOCAL void RF24_ce(bool level) {
|
||||
digitalWrite(MY_RF24_CE_PIN, level);
|
||||
}
|
||||
|
||||
uint8_t spiMultiByteTransfer(uint8_t cmd, uint8_t* buf, uint8_t len, bool aReadMode) {
|
||||
LOCAL uint8_t RF24_spiMultiByteTransfer(uint8_t cmd, uint8_t* buf, uint8_t len, bool aReadMode) {
|
||||
uint8_t* current = buf;
|
||||
#if !defined(MY_SOFTSPI)
|
||||
_SPI.beginTransaction(SPISettings(MY_RF24_SPI_MAX_SPEED, MY_RF24_SPI_DATA_ORDER, MY_RF24_SPI_DATA_MODE));
|
||||
#endif
|
||||
csn(LOW);
|
||||
RF24_csn(LOW);
|
||||
// timing
|
||||
delayMicroseconds(10);
|
||||
uint8_t status = _SPI.transfer( cmd );
|
||||
@@ -48,7 +48,7 @@ uint8_t spiMultiByteTransfer(uint8_t cmd, uint8_t* buf, uint8_t len, bool aReadM
|
||||
if(buf != NULL) *current++ = status;
|
||||
} else status = _SPI.transfer(*current++);
|
||||
}
|
||||
csn(HIGH);
|
||||
RF24_csn(HIGH);
|
||||
#if !defined(MY_SOFTSPI)
|
||||
_SPI.endTransaction();
|
||||
#endif
|
||||
@@ -57,120 +57,116 @@ uint8_t spiMultiByteTransfer(uint8_t cmd, uint8_t* buf, uint8_t len, bool aReadM
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t spiByteTransfer(uint8_t cmd) {
|
||||
return spiMultiByteTransfer( cmd, NULL, 0, false);
|
||||
LOCAL uint8_t RF24_spiByteTransfer(uint8_t cmd) {
|
||||
return RF24_spiMultiByteTransfer( cmd, NULL, 0, false);
|
||||
}
|
||||
|
||||
uint8_t _readByteRegister(uint8_t cmd) {
|
||||
uint8_t value = spiMultiByteTransfer( cmd, NULL, 1, true);
|
||||
LOCAL uint8_t RF24_RAW_readByteRegister(uint8_t cmd) {
|
||||
uint8_t value = RF24_spiMultiByteTransfer( cmd, NULL, 1, true);
|
||||
RF24_DEBUG(PSTR("read register, reg=%d, value=%d\n"), cmd & (R_REGISTER ^ 0xFF), value);
|
||||
return value;
|
||||
}
|
||||
|
||||
uint8_t _writeByteRegister(uint8_t cmd, uint8_t value) {
|
||||
LOCAL uint8_t RF24_RAW_writeByteRegister(uint8_t cmd, uint8_t value) {
|
||||
RF24_DEBUG(PSTR("write register, reg=%d, value=%d\n"), cmd & (W_REGISTER ^ 0xFF), value);
|
||||
return spiMultiByteTransfer( cmd , &value, 1, false);
|
||||
return RF24_spiMultiByteTransfer( cmd , &value, 1, false);
|
||||
}
|
||||
|
||||
#define readByteRegister(reg) _readByteRegister( R_REGISTER | ( REGISTER_MASK & (reg) ) )
|
||||
#define writeByteRegister(reg, value) _writeByteRegister( W_REGISTER | ( REGISTER_MASK & (reg) ), value )
|
||||
#define writeMultiByteRegister(reg, buf, len) spiMultiByteTransfer( W_REGISTER | ( REGISTER_MASK & (reg) ), (uint8_t*)buf, len, false )
|
||||
|
||||
void flushRX(void) {
|
||||
RF24_DEBUG(PSTR("flushRX\n"));
|
||||
spiByteTransfer( FLUSH_RX );
|
||||
LOCAL void RF24_flushRX(void) {
|
||||
RF24_DEBUG(PSTR("RF24_flushRX\n"));
|
||||
RF24_spiByteTransfer( FLUSH_RX );
|
||||
}
|
||||
|
||||
void flushTX(void) {
|
||||
RF24_DEBUG(PSTR("flushTX\n"));
|
||||
spiByteTransfer( FLUSH_TX );
|
||||
LOCAL void RF24_flushTX(void) {
|
||||
RF24_DEBUG(PSTR("RF24_flushTX\n"));
|
||||
RF24_spiByteTransfer( FLUSH_TX );
|
||||
}
|
||||
|
||||
uint8_t getStatus(void) {
|
||||
return spiByteTransfer( NOP );
|
||||
LOCAL uint8_t RF24_getStatus(void) {
|
||||
return RF24_spiByteTransfer( NOP );
|
||||
}
|
||||
|
||||
void openWritingPipe(uint8_t recipient) {
|
||||
LOCAL void RF24_openWritingPipe(uint8_t recipient) {
|
||||
RF24_DEBUG(PSTR("open writing pipe, recipient=%d\n"), recipient);
|
||||
// only write LSB of RX0 and TX pipe
|
||||
writeByteRegister(RX_ADDR_P0, recipient);
|
||||
writeByteRegister(TX_ADDR, recipient);
|
||||
RF24_writeByteRegister(RX_ADDR_P0, recipient);
|
||||
RF24_writeByteRegister(TX_ADDR, recipient);
|
||||
}
|
||||
|
||||
void startListening(void) {
|
||||
LOCAL void RF24_startListening(void) {
|
||||
RF24_DEBUG(PSTR("start listening\n"));
|
||||
// toggle PRX
|
||||
writeByteRegister(NRF_CONFIG, MY_RF24_CONFIGURATION | _BV(PWR_UP) | _BV(PRIM_RX) );
|
||||
RF24_writeByteRegister(NRF_CONFIG, MY_RF24_CONFIGURATION | _BV(PWR_UP) | _BV(PRIM_RX) );
|
||||
// all RX pipe addresses must be unique, therefore skip if node ID is 0xFF
|
||||
if(MY_RF24_NODE_ADDRESS!=AUTO) writeByteRegister(RX_ADDR_P0, MY_RF24_NODE_ADDRESS);
|
||||
if(MY_RF24_NODE_ADDRESS!=AUTO) RF24_writeByteRegister(RX_ADDR_P0, MY_RF24_NODE_ADDRESS);
|
||||
// start listening
|
||||
ce(HIGH);
|
||||
RF24_ce(HIGH);
|
||||
}
|
||||
|
||||
void stopListening(void) {
|
||||
LOCAL void RF24_stopListening(void) {
|
||||
RF24_DEBUG(PSTR("stop listening\n"));
|
||||
ce(LOW);
|
||||
RF24_ce(LOW);
|
||||
// timing
|
||||
delayMicroseconds(130);
|
||||
writeByteRegister(NRF_CONFIG, MY_RF24_CONFIGURATION | _BV(PWR_UP) );
|
||||
RF24_writeByteRegister(NRF_CONFIG, MY_RF24_CONFIGURATION | _BV(PWR_UP) );
|
||||
// timing
|
||||
delayMicroseconds(100);
|
||||
}
|
||||
|
||||
void powerDown(void) {
|
||||
ce(LOW);
|
||||
writeByteRegister(NRF_CONFIG, 0x00);
|
||||
LOCAL void RF24_powerDown(void) {
|
||||
RF24_ce(LOW);
|
||||
RF24_writeByteRegister(NRF_CONFIG, 0x00);
|
||||
RF24_DEBUG(PSTR("power down\n"));
|
||||
}
|
||||
|
||||
bool sendMessage( uint8_t recipient, const void* buf, uint8_t len ) {
|
||||
LOCAL bool RF24_sendMessage( uint8_t recipient, const void* buf, uint8_t len ) {
|
||||
uint8_t status;
|
||||
|
||||
stopListening();
|
||||
openWritingPipe( recipient );
|
||||
RF24_stopListening();
|
||||
RF24_openWritingPipe( recipient );
|
||||
RF24_DEBUG(PSTR("send message to %d, len=%d\n"),recipient,len);
|
||||
// flush TX FIFO
|
||||
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
|
||||
// spiMultiByteTransfer( recipient==BROADCAST_ADDRESS ? W_TX_PAYLOAD_NO_ACK : W_TX_PAYLOAD, (uint8_t*)buf, len, false );
|
||||
// RF24_spiMultiByteTransfer( recipient==BROADCAST_ADDRESS ? W_TX_PAYLOAD_NO_ACK : W_TX_PAYLOAD, (uint8_t*)buf, len, false );
|
||||
// we are safe by disabling AutoACK on the broadcasting pipe
|
||||
spiMultiByteTransfer( W_TX_PAYLOAD, (uint8_t*)buf, len, false );
|
||||
RF24_spiMultiByteTransfer( W_TX_PAYLOAD, (uint8_t*)buf, len, false );
|
||||
// go
|
||||
ce(HIGH);
|
||||
RF24_ce(HIGH);
|
||||
// TX starts after ~10us
|
||||
do {
|
||||
status = getStatus();
|
||||
status = RF24_getStatus();
|
||||
} while (!(status & ( _BV(MAX_RT) | _BV(TX_DS) )));
|
||||
|
||||
ce(LOW);
|
||||
RF24_ce(LOW);
|
||||
// reset interrupts
|
||||
writeByteRegister(RF24_STATUS, _BV(TX_DS) | _BV(MAX_RT) );
|
||||
RF24_writeByteRegister(RF24_STATUS, _BV(TX_DS) | _BV(MAX_RT) );
|
||||
// Max retries exceeded
|
||||
if( status & _BV(MAX_RT)){
|
||||
// flush packet
|
||||
RF24_DEBUG(PSTR("MAX_RT\n"));
|
||||
flushTX();
|
||||
RF24_flushTX();
|
||||
}
|
||||
|
||||
startListening();
|
||||
RF24_startListening();
|
||||
|
||||
return (status & _BV(TX_DS));
|
||||
}
|
||||
|
||||
uint8_t getDynamicPayloadSize(void) {
|
||||
uint8_t result = spiMultiByteTransfer(R_RX_PL_WID,NULL,1,true);
|
||||
LOCAL uint8_t RF24_getDynamicPayloadSize(void) {
|
||||
uint8_t result = RF24_spiMultiByteTransfer(R_RX_PL_WID,NULL,1,true);
|
||||
// check if payload size invalid
|
||||
if(result > 32) {
|
||||
RF24_DEBUG(PSTR("invalid payload length = %d\n"),result);
|
||||
flushRX();
|
||||
RF24_flushRX();
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool IsDataAvailable(uint8_t* to) {
|
||||
uint8_t pipe_num = ( getStatus() >> RX_P_NO ) & 0b0111;
|
||||
LOCAL bool RF24_isDataAvailable(uint8_t* to) {
|
||||
uint8_t pipe_num = ( RF24_getStatus() >> RX_P_NO ) & 0b0111;
|
||||
#if defined(MY_DEBUG_VERBOSE_RF24)
|
||||
if(pipe_num <= 5)
|
||||
RF24_DEBUG(PSTR("Data available on pipe %d\n"),pipe_num);
|
||||
@@ -183,75 +179,77 @@ bool IsDataAvailable(uint8_t* to) {
|
||||
}
|
||||
|
||||
|
||||
uint8_t readMessage( void* buf) {
|
||||
uint8_t len = getDynamicPayloadSize();
|
||||
LOCAL uint8_t RF24_readMessage( void* buf) {
|
||||
uint8_t len = RF24_getDynamicPayloadSize();
|
||||
RF24_DEBUG(PSTR("read message, len=%d\n"), len);
|
||||
spiMultiByteTransfer( R_RX_PAYLOAD , (uint8_t*)buf, len, true );
|
||||
RF24_spiMultiByteTransfer( R_RX_PAYLOAD , (uint8_t*)buf, len, true );
|
||||
// clear RX interrupt
|
||||
writeByteRegister(RF24_STATUS, _BV(RX_DR) );
|
||||
RF24_writeByteRegister(RF24_STATUS, _BV(RX_DR) );
|
||||
return len;
|
||||
}
|
||||
|
||||
void setNodeAddress(uint8_t address) {
|
||||
MY_RF24_NODE_ADDRESS = address;
|
||||
// enable node pipe
|
||||
writeByteRegister(EN_RXADDR, _BV(ERX_P0 + BROADCAST_PIPE) | _BV(ERX_P0) );
|
||||
// enable autoACK on pipe 0
|
||||
writeByteRegister(EN_AA, _BV(ENAA_P0) );
|
||||
LOCAL void RF24_setNodeAddress(uint8_t address) {
|
||||
if(address!=AUTO){
|
||||
MY_RF24_NODE_ADDRESS = address;
|
||||
// enable node pipe
|
||||
RF24_writeByteRegister(EN_RXADDR, _BV(ERX_P0 + BROADCAST_PIPE) | _BV(ERX_P0) );
|
||||
// enable autoACK on pipe 0
|
||||
RF24_writeByteRegister(EN_AA, _BV(ENAA_P0) );
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t getNodeID(void) {
|
||||
LOCAL uint8_t RF24_getNodeID(void) {
|
||||
return MY_RF24_NODE_ADDRESS;
|
||||
}
|
||||
|
||||
bool initializeRF24(void) {
|
||||
LOCAL bool RF24_initialize(void) {
|
||||
// Initialize pins
|
||||
pinMode(MY_RF24_CE_PIN,OUTPUT);
|
||||
pinMode(MY_RF24_CS_PIN,OUTPUT);
|
||||
// Initialize SPI
|
||||
_SPI.begin();
|
||||
ce(LOW);
|
||||
csn(HIGH);
|
||||
RF24_ce(LOW);
|
||||
RF24_csn(HIGH);
|
||||
// CRC and power up
|
||||
writeByteRegister(NRF_CONFIG, MY_RF24_CONFIGURATION | _BV(PWR_UP) ) ;
|
||||
RF24_writeByteRegister(NRF_CONFIG, MY_RF24_CONFIGURATION | _BV(PWR_UP) ) ;
|
||||
// settle >2ms
|
||||
delay(5);
|
||||
// set address width
|
||||
writeByteRegister(SETUP_AW, MY_RF24_ADDR_WIDTH - 2 );
|
||||
RF24_writeByteRegister(SETUP_AW, MY_RF24_ADDR_WIDTH - 2 );
|
||||
// auto retransmit delay 1500us, auto retransmit count 15
|
||||
writeByteRegister(SETUP_RETR, RF24_ARD << ARD | RF24_ARC << ARC);
|
||||
RF24_writeByteRegister(SETUP_RETR, RF24_ARD << ARD | RF24_ARC << ARC);
|
||||
// set channel
|
||||
writeByteRegister(RF_CH, MY_RF24_CHANNEL);
|
||||
RF24_writeByteRegister(RF_CH, MY_RF24_CHANNEL);
|
||||
// set data rate and pa level
|
||||
writeByteRegister(RF_SETUP, MY_RF24_RF_SETUP);
|
||||
RF24_writeByteRegister(RF_SETUP, MY_RF24_RF_SETUP);
|
||||
// sanity check
|
||||
#if defined(MY_RF24_SANITY_CHECK)
|
||||
if(readByteRegister(RF_SETUP)!=MY_RF24_RF_SETUP) {
|
||||
RF24_DEBUG(PSTR("Sanity check failed: RF_SETUP register=%d instead of %d, check wiring, replace module or non-P version\n"),readByteRegister(RF_SETUP), MY_RF24_RF_SETUP);
|
||||
if(RF24_readByteRegister(RF_SETUP)!=MY_RF24_RF_SETUP) {
|
||||
RF24_DEBUG(PSTR("Sanity check failed: RF_SETUP register=%d instead of %d, check wiring, replace module or non-P version\n"),RF24_readByteRegister(RF_SETUP), MY_RF24_RF_SETUP);
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
// toggle features (necessary on some clones)
|
||||
writeByteRegister(ACTIVATE,0x73);
|
||||
RF24_writeByteRegister(ACTIVATE,0x73);
|
||||
// enable ACK payload and dynamic payload
|
||||
writeByteRegister(FEATURE, MY_RF24_FEATURE );
|
||||
RF24_writeByteRegister(FEATURE, MY_RF24_FEATURE );
|
||||
// enable broadcasting pipe
|
||||
writeByteRegister(EN_RXADDR, _BV(ERX_P0 + BROADCAST_PIPE) );
|
||||
RF24_writeByteRegister(EN_RXADDR, _BV(ERX_P0 + BROADCAST_PIPE) );
|
||||
// disable AA on all pipes, activate when node pipe set
|
||||
writeByteRegister(EN_AA, 0x00 );
|
||||
RF24_writeByteRegister(EN_AA, 0x00 );
|
||||
// enable dynamic payloads on used pipes
|
||||
writeByteRegister(DYNPD, _BV(DPL_P0 + BROADCAST_PIPE) | _BV(DPL_P0));
|
||||
RF24_writeByteRegister(DYNPD, _BV(DPL_P0 + BROADCAST_PIPE) | _BV(DPL_P0));
|
||||
// listen to broadcast pipe
|
||||
MY_RF24_BASE_ADDR[0] = BROADCAST_ADDRESS;
|
||||
writeMultiByteRegister(RX_ADDR_P0 + BROADCAST_PIPE, (uint8_t*)&MY_RF24_BASE_ADDR, BROADCAST_PIPE > 1 ? 1 : MY_RF24_ADDR_WIDTH);
|
||||
RF24_writeMultiByteRegister(RX_ADDR_P0 + BROADCAST_PIPE, (uint8_t*)&MY_RF24_BASE_ADDR, BROADCAST_PIPE > 1 ? 1 : MY_RF24_ADDR_WIDTH);
|
||||
// pipe 0, set full address, later only LSB is updated
|
||||
writeMultiByteRegister(RX_ADDR_P0, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH);
|
||||
writeMultiByteRegister(TX_ADDR, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH);
|
||||
RF24_writeMultiByteRegister(RX_ADDR_P0, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH);
|
||||
RF24_writeMultiByteRegister(TX_ADDR, (uint8_t*)&MY_RF24_BASE_ADDR, MY_RF24_ADDR_WIDTH);
|
||||
// reset FIFO
|
||||
flushRX();
|
||||
flushTX();
|
||||
RF24_flushRX();
|
||||
RF24_flushTX();
|
||||
// reset interrupts
|
||||
writeByteRegister(RF24_STATUS, _BV(TX_DS) | _BV(MAX_RT) | _BV(RX_DR));
|
||||
RF24_writeByteRegister(RF24_STATUS, _BV(TX_DS) | _BV(MAX_RT) | _BV(RX_DR));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,11 +23,7 @@
|
||||
#ifndef __RF24_H__
|
||||
#define __RF24_H__
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <stddef.h>
|
||||
#if defined SOFTSPI
|
||||
#include <DigitalIO.h>
|
||||
#endif
|
||||
#define LOCAL static
|
||||
|
||||
// SPI settings
|
||||
#if !defined(MY_RF24_SPI_MAX_SPEED)
|
||||
@@ -37,7 +33,35 @@
|
||||
#define MY_RF24_SPI_DATA_ORDER MSBFIRST
|
||||
#define MY_RF24_SPI_DATA_MODE SPI_MODE0
|
||||
|
||||
// settings
|
||||
#if defined (ARDUINO) && !defined (__arm__) && !defined (_SPI)
|
||||
#if defined(MY_SOFTSPI)
|
||||
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, MY_RF24_SPI_DATA_MODE> _SPI;
|
||||
#elif defined(ARDUINO_ARCH_SAMD)
|
||||
#include <SPI.h>
|
||||
#define _SPI SPI1
|
||||
#else
|
||||
#include <SPI.h>
|
||||
#define _SPI SPI
|
||||
#endif
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define _BV(x) (1<<(x))
|
||||
|
||||
#if defined(__arm__)
|
||||
#include <SPI.h>
|
||||
#else
|
||||
extern HardwareSPI SPI;
|
||||
#endif
|
||||
|
||||
#if !defined(_SPI)
|
||||
#define _SPI SPI
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// RF24 settings
|
||||
#define MY_RF24_CONFIGURATION (uint8_t) (RF24_CRC_16 << 2)
|
||||
#define MY_RF24_FEATURE (uint8_t)( _BV(EN_DPL) | _BV(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
|
||||
@@ -75,52 +99,6 @@
|
||||
// ARD, auto retry count
|
||||
#define RF24_ARC 15
|
||||
|
||||
#if defined (ARDUINO) && !defined (__arm__) && !defined (_SPI)
|
||||
#if defined(SPI_UART)
|
||||
#include <SPI_UART.h>
|
||||
#define _SPI uspi
|
||||
#elif defined(MY_SOFTSPI)
|
||||
#include "drivers/AVR/DigitalIO/DigitalIO.h"
|
||||
// change these pins to your liking
|
||||
const uint8_t SOFT_SPI_MISO_PIN = MY_SOFT_SPI_MOSI_PIN;
|
||||
const uint8_t SOFT_SPI_MOSI_PIN = MY_SOFT_SPI_MISO_PIN;
|
||||
const uint8_t SOFT_SPI_SCK_PIN = MY_SOFT_SPI_SCK_PIN;
|
||||
const uint8_t SPI_MODE = 0;
|
||||
#define _SPI spi
|
||||
#elif defined(ARDUINO_ARCH_SAMD)
|
||||
#include <SPI.h>
|
||||
#define _SPI SPI1
|
||||
#else
|
||||
#include <SPI.h>
|
||||
#define _SPI SPI
|
||||
#endif
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#if defined(__arm__) || defined (CORE_TEENSY)
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
#if !defined(CORE_TEENSY)
|
||||
#define _BV(x) (1<<(x))
|
||||
#if !defined(__arm__)
|
||||
extern HardwareSPI SPI;
|
||||
#endif
|
||||
#else
|
||||
#define printf MY_SERIALDEVICE.printf
|
||||
#endif
|
||||
#if !defined(_SPI)
|
||||
#define _SPI SPI
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(MY_SOFTSPI)
|
||||
SoftSPI<MY_SOFT_SPI_MISO_PIN, MY_SOFT_SPI_MOSI_PIN, MY_SOFT_SPI_SCK_PIN, SPI_MODE> spi;
|
||||
#elif defined (SPI_UART)
|
||||
SPIUARTClass uspi;
|
||||
#endif
|
||||
|
||||
// nRF24L01(+) register definitions
|
||||
#define NRF_CONFIG 0x00
|
||||
#define EN_AA 0x01
|
||||
@@ -228,6 +206,34 @@
|
||||
#define RF_PWR_LOW 1
|
||||
#define RF_PWR_HIGH 2
|
||||
|
||||
// functions
|
||||
|
||||
LOCAL void RF24_csn(bool level);
|
||||
LOCAL void RF24_ce(bool level);
|
||||
LOCAL uint8_t RF24_spiMultiByteTransfer(uint8_t cmd, uint8_t* buf, uint8_t len, bool aReadMode);
|
||||
LOCAL uint8_t RF24_spiByteTransfer(uint8_t cmd);
|
||||
LOCAL uint8_t RF24_RAW_readByteRegister(uint8_t cmd);
|
||||
LOCAL uint8_t RF24_RAW_writeByteRegister(uint8_t cmd, uint8_t value);
|
||||
|
||||
#define RF24_readByteRegister(reg) RF24_RAW_readByteRegister( R_REGISTER | ( REGISTER_MASK & (reg) ) )
|
||||
#define RF24_writeByteRegister(reg, value) RF24_RAW_writeByteRegister( W_REGISTER | ( REGISTER_MASK & (reg) ), value )
|
||||
#define RF24_writeMultiByteRegister(reg, buf, len) RF24_spiMultiByteTransfer( W_REGISTER | ( REGISTER_MASK & (reg) ), (uint8_t*)buf, len, false )
|
||||
|
||||
LOCAL void RF24_flushRX(void);
|
||||
LOCAL void RF24_flushTX(void);
|
||||
LOCAL uint8_t RF24_getStatus(void);
|
||||
LOCAL void RF24_openWritingPipe(uint8_t recipient);
|
||||
LOCAL void RF24_startListening(void);
|
||||
LOCAL void RF24_stopListening(void);
|
||||
LOCAL void RF24_powerDown(void);
|
||||
LOCAL bool RF24_sendMessage(uint8_t recipient, const void* buf, uint8_t len);
|
||||
LOCAL uint8_t RF24_getDynamicPayloadSize(void);
|
||||
LOCAL bool RF24_isDataAvailable(uint8_t* to);
|
||||
LOCAL uint8_t RF24_readMessage(void* buf);
|
||||
LOCAL void RF24_setNodeAddress(uint8_t address);
|
||||
LOCAL uint8_t RF24_getNodeID(void);
|
||||
LOCAL bool RF24_initialize(void);
|
||||
|
||||
#endif // __RF24_H__
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user