Commit 3cc10bb6 authored by TMRh20's avatar TMRh20

Merge branch 'Updates' of https://github.com/nerdralph/RF24 into Updates

parents e3f4a6ba 3863f6fd
......@@ -90,20 +90,14 @@ uint8_t RF24::read_register(uint8_t reg, uint8_t* buf, uint8_t len)
// decrement before to skip status byte
while ( --size ){ *buf++ = *prx++; }
#elif defined (RF24_DUE)
status = _SPI.transfer(csn_pin, R_REGISTER | ( REGISTER_MASK & reg ), SPI_CONTINUE );
while ( len-- > 1 ){
*buf++ = _SPI.transfer(csn_pin,0xff, SPI_CONTINUE);
}
*buf++ = _SPI.transfer(csn_pin,0xff);
#else
csn(LOW);
beginTransaction();
status = _SPI.transfer( R_REGISTER | ( REGISTER_MASK & reg ) );
while ( len-- ){
*buf++ = _SPI.transfer(0xff);
}
csn(HIGH);
endTransaction();
#endif
......@@ -128,15 +122,13 @@ uint8_t RF24::read_register(uint8_t reg)
_SPI.transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, 2);
result = *++prx; // result is 2nd byte of receive buffer
#elif defined (RF24_DUE)
_SPI.transfer(csn_pin, R_REGISTER | ( REGISTER_MASK & reg ) , SPI_CONTINUE);
result = _SPI.transfer(csn_pin,0xff);
#else
csn(LOW);
beginTransaction();
_SPI.transfer( R_REGISTER | ( REGISTER_MASK & reg ) );
result = _SPI.transfer(0xff);
endTransaction();
csn(HIGH);
#endif
return result;
......@@ -162,20 +154,13 @@ uint8_t RF24::write_register(uint8_t reg, const uint8_t* buf, uint8_t len)
_SPI.transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, size);
status = *prx; // status is 1st byte of receive buffer
#elif defined (RF24_DUE)
status = _SPI.transfer(csn_pin, W_REGISTER | ( REGISTER_MASK & reg ), SPI_CONTINUE );
while ( --len){
_SPI.transfer(csn_pin,*buf++, SPI_CONTINUE);
}
_SPI.transfer(csn_pin,*buf++);
#else
csn(LOW);
beginTransaction();
status = _SPI.transfer( W_REGISTER | ( REGISTER_MASK & reg ) );
while ( len-- )
_SPI.transfer(*buf++);
csn(HIGH);
endTransaction();
#endif
......@@ -200,15 +185,12 @@ uint8_t RF24::write_register(uint8_t reg, uint8_t value)
_SPI.transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, 2);
status = *prx++; // status is 1st byte of receive buffer
#elif defined (RF24_DUE)
status = _SPI.transfer(csn_pin, W_REGISTER | ( REGISTER_MASK & reg ), SPI_CONTINUE);
_SPI.transfer(csn_pin,value);
#else
csn(LOW);
beginTransaction();
status = _SPI.transfer( W_REGISTER | ( REGISTER_MASK & reg ) );
_SPI.transfer(value);
csn(HIGH);
endTransaction();
#endif
......@@ -244,28 +226,10 @@ uint8_t RF24::write_payload(const void* buf, uint8_t data_len, const uint8_t wri
_SPI.transfernb( (char *) spi_txbuff, (char *) spi_rxbuff, size);
status = *prx; // status is 1st byte of receive buffer
#elif defined (RF24_DUE)
status = _SPI.transfer(csn_pin, writeType , SPI_CONTINUE);
if(blank_len){
while ( data_len--){
_SPI.transfer(csn_pin,*current++, SPI_CONTINUE);
}
while ( --blank_len ){
_SPI.transfer(csn_pin,0, SPI_CONTINUE);
}
_SPI.transfer(csn_pin,0);
}else{
while( --data_len ){
_SPI.transfer(csn_pin,*current++, SPI_CONTINUE);
}
_SPI.transfer(csn_pin,*current);
}
#else
csn(LOW);
beginTransaction();
status = _SPI.transfer( writeType );
while ( data_len-- ) {
_SPI.transfer(*current++);
......@@ -273,7 +237,7 @@ uint8_t RF24::write_payload(const void* buf, uint8_t data_len, const uint8_t wri
while ( blank_len-- ) {
_SPI.transfer(0);
}
csn(HIGH);
endTransaction();
#endif
......@@ -316,29 +280,9 @@ uint8_t RF24::read_payload(void* buf, uint8_t data_len)
*current = *prx;
#elif defined (RF24_DUE)
status = _SPI.transfer(csn_pin, R_RX_PAYLOAD, SPI_CONTINUE );
if( blank_len ){
while ( data_len-- ){
*current++ = _SPI.transfer(csn_pin,0xFF, SPI_CONTINUE);
}
while ( --blank_len ){
_SPI.transfer(csn_pin,0xFF, SPI_CONTINUE);
}
_SPI.transfer(csn_pin,0xFF);
}else{
while ( --data_len ){
*current++ = _SPI.transfer(csn_pin,0xFF, SPI_CONTINUE);
}
*current = _SPI.transfer(csn_pin,0xFF);
}
#else
csn(LOW);
beginTransaction();
status = _SPI.transfer( R_RX_PAYLOAD );
while ( data_len-- ) {
*current++ = _SPI.transfer(0xFF);
......@@ -346,7 +290,7 @@ uint8_t RF24::read_payload(void* buf, uint8_t data_len)
while ( blank_len-- ) {
_SPI.transfer(0xff);
}
csn(HIGH);
endTransaction();
#endif
......@@ -375,14 +319,15 @@ uint8_t RF24::spiTrans(uint8_t cmd){
#if defined (RF24_LINUX)
csn(LOW);
status = _SPI.transfer( cmd );
#elif defined (RF24_DUE)
status = _SPI.transfer(csn_pin, cmd );
#else
csn(LOW);
beginTransaction();
status = _SPI.transfer( cmd );
csn(HIGH);
endTransaction();
#endif
return status;
}
......@@ -617,9 +562,11 @@ void RF24::printDetails(void)
#endif
/****************************************************************************/
void RF24::begin(void)
bool RF24::begin(void)
{
uint8_t setup;
#if defined (RF24_LINUX)
SPI();
......@@ -694,11 +641,10 @@ void RF24::begin(void)
// Reset value is MAX
//setPALevel( RF24_PA_MAX ) ;
// Determine if this is a p or non-p RF24 module and then
// reset our data rate back to default value. This works
// because a non-P variant won't allow the data rate to
// be set to 250Kbps.
if( setDataRate( RF24_250KBPS ) )
// check for connected module and if this is a p nRF24l01 variant
//
setup = read_register(RF_SETUP);
if( setup == 0b00001110 ) // register default for nRF24L01P
{
p_variant = true ;
}
......@@ -734,6 +680,8 @@ void RF24::begin(void)
// PTX should use only 22uA of power
write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_RX) );
// if setup is 0 or ff then there was no response from module
return ( setup != 0 && setup != 0xff );
}
/****************************************************************************/
......
......@@ -80,6 +80,27 @@ private:
uint8_t addr_width; /**< The address width to use - 3,4 or 5 bytes. */
uint32_t txRxDelay; /**< Var for adjusting delays depending on datarate */
#if defined (ARDUINO)
protected:
/**
* SPI transactions
*
* Common code for SPI transactions including CSN toggle
*
*/
inline void beginTransaction() {
_SPI.beginTransaction(SPISettings(RF_SPI_SPEED, MSBFIRST, SPI_MODE0));
csn(LOW);
}
inline void endTransaction() {
csn(HIGH);
_SPI.endTransaction();
}
#endif /* ARDUINO */
public:
/**
......@@ -125,7 +146,7 @@ public:
* Call this in setup(), before calling any other methods.
* @code radio.begin() @endcode
*/
void begin(void);
bool begin(void);
/**
* Start listening on the pipes opened for reading.
......@@ -1309,6 +1330,7 @@ private:
* @section News News
*
* **March 2015**<br>
* - Uses SPI transactions on Arduino
* - New layout for <a href="Portability.html">easier portability:</a> Break out defines & includes for individual platforms to RF24/arch
* - <a href="MRAA.html">MRAA</a> support added ( Galileo, Edison, etc)
* - <a href="BBB.html">BBB/Generic Linux </a> support via spidev & MRAA
......
......@@ -5,8 +5,6 @@
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
Added Arduino Due support from https://github.com/mcrosson/
*/
/* spaniakos <spaniakos@gmail.com>
......@@ -35,12 +33,6 @@
// The includes.h file defines either RF24_RPi, MRAA or RF24_BBB and includes the correct RF24_arch_config.h file
#include "arch/includes.h"
//Arduino Due
#elif defined ARDUINO_SAM_DUE
#define RF24_DUE
#include "arch/Due/RF24_arch_config.h"
//ATTiny
#elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
......@@ -59,16 +51,11 @@
//Everything else
#else
#if ARDUINO < 100
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#include <stddef.h>
#include <Arduino.h>
// Define _BV for non-Arduino platforms and for Arduino DUE
// RF modules support 10 Mhz SPI bus speed
const uint32_t RF_SPI_SPEED = 10000000;
#if defined (ARDUINO) && !defined (__arm__) && !defined (__ARDUINO_X86__)
#if defined SPI_UART
#include <SPI_UART.h>
......@@ -87,6 +74,7 @@
#define _SPI SPI
#endif
#else
// Define _BV for non-Arduino platforms and for Arduino DUE
#include <stdint.h>
#include <stdio.h>
#include <string.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment