Commit 3c4f8420 authored by corcrash's avatar corcrash Committed by GitHub

Merge branch 'master' into master

parents c10147f6 575183c3
......@@ -13,5 +13,12 @@ out_native/
version.h
Session.vim
*.so
*.so.*
*.dylib
*.dylib.*
.DS_Store
Makefile.inc
utility/includes.h
examples_linux/*
!examples_linux/**/
!examples_linux/*.*
......@@ -897,7 +897,7 @@ EXCLUDE_SYMBOLS =
# command).
EXAMPLE_PATH = examples \
examples_RPi
examples_linux
# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
......
......@@ -50,7 +50,7 @@ void RF24::csn(bool mode)
#if !defined (RF24_LINUX)
digitalWrite(csn_pin,mode);
delayMicroseconds(5);
delayMicroseconds(csDelay);
#endif
}
......@@ -357,7 +357,7 @@ void RF24::print_status(uint8_t status)
(status & _BV(RX_DR))?1:0,
(status & _BV(TX_DS))?1:0,
(status & _BV(MAX_RT))?1:0,
((status >> RX_P_NO) & 0b111),
((status >> RX_P_NO) & 0x07),
(status & _BV(TX_FULL))?1:0
);
}
......@@ -368,8 +368,8 @@ void RF24::print_observe_tx(uint8_t value)
{
printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\r\n"),
value,
(value >> PLOS_CNT) & 0b1111,
(value >> ARC_CNT) & 0b1111
(value >> PLOS_CNT) & 0x0F,
(value >> ARC_CNT) & 0x0F
);
}
......@@ -417,7 +417,7 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty)
RF24::RF24(uint16_t _cepin, uint16_t _cspin):
ce_pin(_cepin), csn_pin(_cspin), p_variant(false),
payload_size(32), dynamic_payloads_enabled(false), addr_width(5)//,pipe0_reading_address(0)
payload_size(32), dynamic_payloads_enabled(false), addr_width(5),csDelay(5)//,pipe0_reading_address(0)
{
pipe0_reading_address[0]=0;
}
......@@ -425,6 +425,7 @@ RF24::RF24(uint16_t _cepin, uint16_t _cspin):
/****************************************************************************/
#if defined (RF24_LINUX) && !defined (MRAA)//RPi constructor
RF24::RF24(uint16_t _cepin, uint16_t _cspin, uint32_t _spi_speed):
ce_pin(_cepin),csn_pin(_cspin),spi_speed(_spi_speed),p_variant(false), payload_size(32), dynamic_payloads_enabled(false),addr_width(5)//,pipe0_reading_address(0)
{
......@@ -602,6 +603,12 @@ bool RF24::begin(void)
pinMode(csn_pin,OUTPUT);
_SPI.begin();
csn(HIGH);
#elif defined(XMEGA_D3)
if (ce_pin != csn_pin) pinMode(ce_pin,OUTPUT);
_SPI.begin(csn_pin);
ce(LOW);
csn(HIGH);
delay(200);
#else
// Initialize pins
if (ce_pin != csn_pin) pinMode(ce_pin,OUTPUT);
......@@ -628,7 +635,7 @@ bool RF24::begin(void)
delay( 5 ) ;
// Reset NRF_CONFIG and enable 16-bit CRC.
write_register( NRF_CONFIG, 0b00001100 ) ;
write_register( NRF_CONFIG, 0x0C ) ;
// Set 1500uS (minimum for 32B payload in ESB@250KBPS) timeouts, to make testing a little easier
// WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet
......@@ -661,6 +668,7 @@ bool RF24::begin(void)
toggle_features();
write_register(FEATURE,0 );
write_register(DYNPD,0);
dynamic_payloads_enabled = false;
// Reset current status
// Notice reset and flush is the last thing we do
......@@ -722,10 +730,10 @@ void RF24::stopListening(void)
{
ce(LOW);
delayMicroseconds(txRxDelay);
delayMicroseconds(txDelay);
if(read_register(FEATURE) & _BV(EN_ACK_PAY)){
delayMicroseconds(txRxDelay); //200
delayMicroseconds(txDelay); //200
flush_tx();
}
//flush_rx();
......@@ -1065,7 +1073,7 @@ bool RF24::available(uint8_t* pipe_num)
// If the caller wants the pipe number, include that
if ( pipe_num ){
uint8_t status = get_status();
*pipe_num = ( status >> RX_P_NO ) & 0b111;
*pipe_num = ( status >> RX_P_NO ) & 0x07;
}
return 1;
}
......@@ -1175,7 +1183,10 @@ void RF24::setAddressWidth(uint8_t a_width){
if(a_width -= 2){
write_register(SETUP_AW,a_width%4);
addr_width = (a_width%4) + 2;
}
}else{
write_register(SETUP_AW,0);
addr_width = 2;
}
}
......@@ -1292,7 +1303,7 @@ void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
beginTransaction();
uint8_t * ptx = spi_txbuff;
uint8_t size = data_len + 1 ; // Add register value to transmit buffer
*ptx++ = W_ACK_PAYLOAD | ( pipe & 0b111 );
*ptx++ = W_ACK_PAYLOAD | ( pipe & 0x07 );
while ( data_len-- ){
*ptx++ = *current++;
}
......@@ -1301,7 +1312,7 @@ void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
endTransaction();
#else
beginTransaction();
_SPI.transfer(W_ACK_PAYLOAD | ( pipe & 0b111 ) );
_SPI.transfer(W_ACK_PAYLOAD | ( pipe & 0x07 ) );
while ( data_len-- )
_SPI.transfer(*current++);
......@@ -1330,7 +1341,7 @@ bool RF24::isPVariant(void)
void RF24::setAutoAck(bool enable)
{
if ( enable )
write_register(EN_AA, 0b111111);
write_register(EN_AA, 0x3F);
else
write_register(EN_AA, 0);
}
......@@ -1373,7 +1384,7 @@ bool RF24::testRPD(void)
void RF24::setPALevel(uint8_t level)
{
uint8_t setup = read_register(RF_SETUP) & 0b11111000;
uint8_t setup = read_register(RF_SETUP) & 0xF8;
if(level > 3){ // If invalid level, go to max PA
level = (RF24_PA_MAX << 1) + 1; // +1 to support the SI24R1 chip extra bit
......@@ -1404,9 +1415,9 @@ bool RF24::setDataRate(rf24_datarate_e speed)
setup &= ~(_BV(RF_DR_LOW) | _BV(RF_DR_HIGH)) ;
#if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__)
txRxDelay=250;
txDelay=250;
#else //16Mhz Arduino
txRxDelay=85;
txDelay=85;
#endif
if( speed == RF24_250KBPS )
{
......@@ -1414,9 +1425,9 @@ bool RF24::setDataRate(rf24_datarate_e speed)
// Making it '10'.
setup |= _BV( RF_DR_LOW ) ;
#if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__)
txRxDelay=450;
txDelay=450;
#else //16Mhz Arduino
txRxDelay=155;
txDelay=155;
#endif
}
else
......@@ -1427,9 +1438,9 @@ bool RF24::setDataRate(rf24_datarate_e speed)
{
setup |= _BV(RF_DR_HIGH);
#if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__)
txRxDelay=190;
txDelay=190;
#else //16Mhz Arduino
txRxDelay=65;
txDelay=65;
#endif
}
}
......
......@@ -57,7 +57,7 @@ private:
SPIUARTClass uspi;
#endif
#if defined (RF24_LINUX)
#if defined (RF24_LINUX) || defined (XMEGA_D3) /* XMEGA can use SPI class */
SPI spi;
#endif
#if defined (MRAA)
......@@ -67,7 +67,7 @@ private:
uint16_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
uint16_t csn_pin; /**< SPI Chip select */
uint16_t spi_speed; /**< SPI Bus Speed */
#if defined (RF24_LINUX)
#if defined (RF24_LINUX) || defined (XMEGA_D3)
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)
#endif
......@@ -76,7 +76,6 @@ private:
bool dynamic_payloads_enabled; /**< Whether dynamic payloads are enabled. */
uint8_t pipe0_reading_address[5]; /**< Last address set on pipe 0 for reading. */
uint8_t addr_width; /**< The address width to use - 3,4 or 5 bytes. */
uint32_t txRxDelay; /**< Var for adjusting delays depending on datarate */
protected:
......@@ -112,7 +111,7 @@ public:
//#if defined (RF24_LINUX)
/**
* Optional Raspberry Pi Constructor
* Optional Linux Constructor
*
* Creates a new instance of this driver. Before using, you create an instance
* and send in the unique pins that this chip is connected to.
......@@ -877,7 +876,7 @@ s *
/**
* Get the CRC length
* <br>CRC checking cannot be disabled if auto-ack is enabled
* @return RF24_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
* @return RF24_CRC_DISABLED if disabled or RF24_CRC_8 for 8-bit or RF24_CRC_16 for 16-bit
*/
rf24_crclength_e getCRCLength(void);
......@@ -906,6 +905,31 @@ s *
*/
void maskIRQ(bool tx_ok,bool tx_fail,bool rx_ready);
/**
*
* The driver will delay for this duration when stopListening() is called
*
* When responding to payloads, faster devices like ARM(RPi) are much faster than Arduino:
* 1. Arduino sends data to RPi, switches to RX mode
* 2. The RPi receives the data, switches to TX mode and sends before the Arduino radio is in RX mode
* 3. If AutoACK is disabled, this can be set as low as 0. If AA/ESB enabled, set to 100uS minimum on RPi
*
* @warning If set to 0, ensure 130uS delay after stopListening() and before any sends
*/
uint32_t txDelay;
/**
*
* On all devices but Linux and ATTiny, a small delay is added to the CSN toggling function
*
* This is intended to minimise the speed of SPI polling due to radio commands
*
* If using interrupts or timed requests, this can be set to 0 Default:5
*/
uint32_t csDelay;
/**@}*/
/**
* @name Deprecated
......@@ -1135,8 +1159,8 @@ private:
*/
/**
* @example GettingStarted.cpp
* <b>For Raspberry Pi</b><br>
* @example gettingstarted.cpp
* <b>For Linux</b><br>
* <b>Updated: TMRh20 2014 </b><br>
*
* This is an example of how to use the RF24 class to communicate on a basic level. Configure and write this sketch to two
......@@ -1159,8 +1183,8 @@ private:
*/
/**
* @example GettingStarted_Call_Response.cpp
* <b>For Raspberry Pi</b><br>
* @example gettingstarted_call_response.cpp
* <b>For Linux</b><br>
* <b>New: TMRh20 2014</b><br>
*
* This example continues to make use of all the normal functionality of the radios including
......@@ -1190,8 +1214,8 @@ private:
*/
/**
* @example Transfer.cpp
* <b>For Raspberry Pi</b><br>
* @example transfer.cpp
* <b>For Linux</b><br>
* This example demonstrates half-rate transfer using the FIFO buffers<br>
*
* It is an example of how to use the RF24 class. Write this sketch to two
......@@ -1282,7 +1306,7 @@ private:
/**
* @example pingpair_dyn.cpp
*
* This is an example of how to use payloads of a varying (dynamic) size on Raspberry Pi.
* This is an example of how to use payloads of a varying (dynamic) size on Linux.
*/
/**
......@@ -1291,18 +1315,6 @@ private:
* This is a python example for RPi of how to use payloads of a varying (dynamic) size.
*/
/**
* @example pingpair_dyn.ino
*
* This is an example of how to use payloads of a varying (dynamic) size.
*/
/**
* @example pingpair_dyn.ino
*
* This is an example of how to use payloads of a varying (dynamic) size.
*/
/**
* @example scanner.ino
*
......@@ -1341,7 +1353,7 @@ private:
* - Uses SPI transactions on Arduino
* - New layout for <a href="Portability.html">easier portability:</a> Break out defines & includes for individual platforms to RF24/utility
* - <a href="MRAA.html">MRAA</a> support added ( Galileo, Edison, etc)
* - <a href="BBB.html">BBB/Generic Linux </a> support via spidev & MRAA
* - <a href="Linux.html">Generic Linux support (SPIDEV)</a> support
* - Support for RPi 2 added
* - Major Documentation cleanup & update (Move all docs to github.io)
*
......@@ -1356,6 +1368,7 @@ private:
* @li <a href="https://github.com/TMRh20/RF24/archive/master.zip"><b>Download</b></a>
* @li <a href="https://github.com/tmrh20/RF24/"><b>Source Code</b></a>
* @li <a href="http://tmrh20.blogspot.com/2014/03/high-speed-data-transfers-and-wireless.html"><b>My Blog:</b> RF24 Optimization Overview</a>
* @li <a href="http://tmrh20.blogspot.com/2016/08/raspberry-pilinux-with-nrf24l01.html"><b>My Blog:</b> RPi/Linux w/RF24Gateway</a>
* @li <a href="http://www.nordicsemi.com/files/Product/data_sheet/nRF24L01_Product_Specification_v2_0.pdf">Chip Datasheet</a>
*
* **Additional Information and Add-ons**
......@@ -1384,8 +1397,9 @@ private:
*
* @li <a href="Arduino.html"><b>Arduino</b></a> (Uno, Nano, Mega, Due, Galileo, etc)
* @li <a href="ATTiny.html"><b>ATTiny</b></a>
* @li Linux ( <a href="RPi.html"><b>RPi</b></a> , <a href="BBB.html"><b>BBB</b></a>, <a href="MRAA.html"><b>MRAA</b></a> supported boards ( Galileo, Edison, etc))
* @li <a href="Python.html"><b>Python</b></a> wrapper available for RPi
* @li <a href="Linux.html"><b>Linux devices</b></a>( <a href="RPi.html"><b>RPi</b></a> , <a href="Linux.html"><b>Linux SPI userspace device</b></a>, <a href="MRAA.html"><b>MRAA</b></a> supported boards ( Galileo, Edison, etc), <a href="LittleWire.html"><b>LittleWire</b></a>)
* @li <a href="CrossCompile.html"><b>Cross-compilation</b></a> for linux devices
* @li <a href="Python.html"><b>Python</b></a> wrapper available for Linux devices
*
* <br>
* **General µC Pin layout** (See the individual board support pages for more info)
......@@ -1559,27 +1573,27 @@ private:
*
*
*
* @page BBB BeagleBone Black
* @page Linux Linux devices
*
* BeagleBone Black is supported via MRAA or SPIDEV.
* Generic Linux devices are supported via SPIDEV, MRAA, RPi native via BCM2835, or using LittleWire.
*
* @note The SPIDEV option should work with most Linux systems supporting SPIDEV. <br>
* Users may need to edit the RF24/utility/BBB/spi.cpp file to configure the spi device. (Defaults: "/dev/spidev1.0"; or "/dev/spidev1.1"; )
* @note The SPIDEV option should work with most Linux systems supporting spi userspace device. <br>
*
* <br>
* @section AutoInstall Automated Install
*(**Designed & Tested on RPi** - Defaults to SPIDEV on BBB)
*(**Designed & Tested on RPi** - Defaults to SPIDEV on devices supporting it)
*
*
* 1. Download the install.sh file from http://tmrh20.github.io/RF24Installer/RPi/install.sh
* 1. Install prerequisites if there are any (MRAA, LittleWire libraries, setup SPI device etc)
* 2. Download the install.sh file from http://tmrh20.github.io/RF24Installer/RPi/install.sh
* @code wget http://tmrh20.github.io/RF24Installer/RPi/install.sh @endcode
* 2. Make it executable:
* 3. Make it executable
* @code chmod +x install.sh @endcode
* 3. Run it and choose your options
* 4. Run it and choose your options
* @code ./install.sh @endcode
* 4. Run an example from one of the libraries
* 5. Run an example from one of the libraries
* @code
* cd rf24libs/RF24/examples_RPi
* cd rf24libs/RF24/examples_linux
* @endcode
* Edit the gettingstarted example, to set your pin configuration
* @code nano gettingstarted.cpp
......@@ -1589,20 +1603,22 @@ private:
*
* <br>
* @section ManInstall Manual Install
* 1. Make a directory to contain the RF24 and possibly RF24Network lib and enter it:
* 1. Install prerequisites if there are any (MRAA, LittleWire libraries, setup SPI device etc)
* @note See the <a href="http://iotdk.intel.com/docs/master/mraa/index.html">MRAA </a> documentation for more info on installing MRAA <br>
* 2. Make a directory to contain the RF24 and possibly RF24Network lib and enter it
* @code
* mkdir ~/rf24libs
* cd ~/rf24libs
* @endcode
* 2. Clone the RF24 repo:
* 3. Clone the RF24 repo
* @code git clone https://github.com/tmrh20/RF24.git RF24 @endcode
* 3. Change to the new RF24 directory
* 4. Change to the new RF24 directory
* @code cd RF24 @endcode
* 4. Build the library, and run an example file:
* **Note:** See the <a href="http://iotdk.intel.com/docs/master/mraa/index.html">MRAA </a> documentation for more info on installing MRAA
* @code sudo make install OR sudo make install RF24_MRAA=1 @endcode
* 5. Configure build environment using @code ./configure @endcode script. It auto detectes device and build environment. For overriding autodetections, use command-line switches, see @code ./configure --help @endcode for description.
* 6. Build the library, and run an example file
* @code sudo make install @endcode
* @code
* cd examples_RPi
* cd examples_linux
* @endcode
* Edit the gettingstarted example, to set your pin configuration
* @code nano gettingstarted.cpp
......@@ -1620,33 +1636,11 @@ private:
* RF24 supports all MRAA supported platforms, but might not be tested on each individual platform due to the wide range of hardware support:<br>
* <a href="https://github.com/TMRh20/RF24/issues">Report an RF24 bug or issue </a>
*
* @section Setup Setup
* @section Setup Setup and installation
* 1. Install the MRAA lib
* 2. As per your device, SPI may need to be enabled
* 3. Follow <a href="Linux.html">Linux installation steps</a> to install RF24 libraries
*
* @section MRAA_Install Install
*
* 1. Make a directory to contain the RF24 and possibly RF24Network lib and enter it:
* @code
* mkdir ~/rf24libs
* cd ~/rf24libs
* @endcode
* 2. Clone the RF24 repo:
* @code git clone https://github.com/tmrh20/RF24.git RF24 @endcode
* 3. Change to the new RF24 directory
* @code cd RF24 @endcode
* 4. Build the library:
* @code sudo make install -B RF24_MRAA=1 @endcode
* 5. Configure the correct pins in gettingstarted.cpp (See http://iotdk.intel.com/docs/master/mraa/index.html )
* @code
* cd examples_RPi
* nano gettingstarted.cpp
* @endcode
* 6. Build an example
* @code
* make
* sudo ./gettingstarted
* @endcode
*
* <br><br><br>
*
......@@ -1665,43 +1659,11 @@ private:
* @code sudo raspi-config @endcode
* A. Update the tool via the menu as required<br>
* B. Select **Advanced** and **enable the SPI kernel module** <br>
* C. Update other software and libraries:
* C. Update other software and libraries
* @code sudo apt-get update @endcode
* @code sudo apt-get upgrade @endcode
* <br>
* @section AutoInstall Automated Install
*
* 1. Download the install.sh file from http://tmrh20.github.io/RF24Installer/RPi/install.sh
* @code wget http://tmrh20.github.io/RF24Installer/RPi/install.sh @endcode
* 2. Make it executable:
* @code chmod +x install.sh @endcode
* 3. Run it and choose your options
* @code ./install.sh @endcode
* 4. Run an example from one of the libraries
* @code
* cd rf24libs/RF24/examples_RPi
* make
* sudo ./gettingstarted
* @endcode
* <br><br>
* @section ManInstall Manual Install
* 1. Make a directory to contain the RF24 and possibly RF24Network lib and enter it:
* @code
* mkdir ~/rf24libs
* cd ~/rf24libs
* @endcode
* 2. Clone the RF24 repo:
* @code git clone https://github.com/tmrh20/RF24.git RF24 @endcode
* 3. Change to the new RF24 directory
* @code cd RF24 @endcode
* 4. Build the library, and run an example file:
* @code sudo make install
* cd examples_RPi
* make
* sudo ./gettingstarted
* @endcode
*
* <br><br>
* @section Build Build Options
* The default build on Raspberry Pi utilizes the included **BCM2835** driver from http://www.airspayce.com/mikem/bcm2835
* 1. @code sudo make install -B @endcode
......@@ -1709,7 +1671,7 @@ private:
* Build using the **MRAA** library from http://iotdk.intel.com/docs/master/mraa/index.html <br>
* MRAA is not included. See the <a href="MRAA.html">MRAA</a> platform page for more information.
*
* 1. Install, and build MRAA:
* 1. Install, and build MRAA
* @code
* git clone https://github.com/intel-iot-devkit/mraa.git
* cd mraa
......@@ -1725,15 +1687,21 @@ private:
* Run @code sudo ldconfig @endcode
*
* 3. Install RF24, using MRAA
* @code sudo make install -B RF24_MRAA=1 @endcode
* @code
* ./configure --driver=MRAA
* sudo make install -B
* @endcode
* See the gettingstarted example for an example of pin configuration
*
* Build using **spidev**:
* Build using **SPIDEV**
*
* 1. Edit the RF24/utility/BBB/spi.cpp file
* 2. Change the default device definition to @code this->device = "/dev/spidev0.0";; @endcode
* 3. Run @code sudo make install -B RF24_SPIDEV=1 @endcode
* 4. See the gettingstarted example for an example of pin configuration
* 1. Make sure that spi device support is enabled and /dev/spidev\<a\>.\<b\> is present
* 2. Install RF24, using SPIDEV
* @code
* ./configure --driver=SPIDEV
* sudo make install -B
* @endcode
* 3. See the gettingstarted example for an example of pin configuration
*
* <br>
* @section Pins Connections and Pin Configuration
......@@ -1774,6 +1742,7 @@ private:
* **SPI_DEV Constructor**
*
* @code RF24 radio(22,0); @endcode
* In general, use @code RF24 radio(<ce_pin>, <a>*10+<b>); @endcode for proper SPIDEV constructor to address correct spi device at /dev/spidev\<a\>.\<b\>
*
* See http://pi.gadgetoid.com/pinout
*
......@@ -1809,39 +1778,165 @@ private:
*
*
* @page Python Python Wrapper (by https://github.com/mz-fuzzy)
*
*
* @note Both python2 and python3 are supported.
*
* @section Install Installation:
*
* Install the boost libraries: (Note: Only the python libraries should be needed, this is just for simplicity)
*
* @code sudo apt-get install libboost1.50-all @endcode
* 1. Install the python-dev (or python3-dev) and boost libraries
* @code sudo apt-get install python-dev libboost-python-dev @endcode
* @note For python3 in Raspbian, it's needed to manually link python boost library, like this:
* @code sudo ln -s /usr/lib/arm-linux-gnueabihf/libboost_python-py34.so /usr/lib/arm-linux-gnueabihf/libboost_python3.so @endcode
*
* Build the library:
* 2. Install python-setuptools (or python3-setuptools)
* @code sudo apt-get install python-setuptools @endcode
*
* 3. Build the library
* @code ./setup.py build @endcode
* @note Build takes several minutes on arm-based machines. Machines with RAM <1GB may need to increase amount of swap for build.
*
* Install the library
*
* 4. Install the library
* @code sudo ./setup.py install @endcode
*
*
* See the additional <a href="pages.html">Platform Support</a> pages for information on connecting your hardware <br>
* See the included <a href="pingpair_dyn_8py-example.html">example </a> for usage information.
*
* Running the Example:
*
* 5. Running the Example
* Edit the pingpair_dyn.py example to configure the appropriate pins per the above documentation:
*
* @code nano pingpair_dyn.py @endcode
* Configure another device, Arduino or RPi with the <a href="pingpair_dyn_8py-example.html">pingpair_dyn</a> example <br>
* Run the example
* @code sudo ./pingpair_dyn.py @endcode
*
* Configure another device, Arduino or RPi with the <a href="pingpair_dyn_8py-example.html">pingpair_dyn</a> example
* <br><br><br>
*
* Run the example
* @page CrossCompile Linux cross-compilation
*
* RF24 library supports cross-compilation. Advantages of cross-compilation:
* - development tools don't have to be installed on target machine
* - resources of target machine don't have to be sufficient for compilation
* - compilation time can be reduced for large projects
*
* Following prerequisites need to be assured:
* - ssh passwordless access to target machine (https://linuxconfig.org/passwordless-ssh)
* - sudo of a remote user without password (http://askubuntu.com/questions/334318/sudoers-file-enable-nopasswd-for-user-all-commands)
* - cross-compilation toolchain for your target machine; for RPi
* @code git clone https://github.com/raspberrypi/tools rpi_tools @endcode
* and cross-compilation tools must be in PATH, for example
* @code export PATH=$PATH:/your/dir/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin @endcode
*
* @section CxSteps Cross compilation steps:
* 1. clone RF24 to a machine for cross-compilation
* @code
* git clone https://github.com/TMRh20/RF24
* cd RF24
* @endcode
* 2. configure for cross compilation
* @code ./configure --remote=pi@target_linux_host @endcode
* eventually
* @code ./configure --remote=pi@target_linux_host --driver=<driver> @endcode
* 3. build
* @code make @endcode
* 4. (opt) install library to cross-compilation machine into cross-exvironment - important for compilation of examples
* @code sudo make install @endcode
* 5. upload library to target machine
* @code make upload @endcode
* 6. (opt) compile examples
* @code
* cd examples_linux
* make
* @endcode
* 7. (opt) upload examples to target machine
* @code make upload @endcode
*
* @code sudo ./pingpair_dyn.py @endcode
* @section CxStepsPython Cross comilation steps for python wrapper
*
* Prerequisites:
* - Python setuptools must be installed on both target and cross-compilation machines
* @code sudo pip install setuptools @endcode
* or
* @code sudo apt-get install python-setuptools @endcode
*
* Installation steps:
* 1. Assure having libboost-python-dev library in your cross-compilation environment. Alternatively, you can install it into your target machine and copy /usr and /lib directories to the cross-compilation machine.
* For example
* @code
* mkdir -p rpi_root && rsync -a pi@target_linux_host:/usr :/lib rpi_root
* export CFLAGS="--sysroot=/your/dir/rpi_root -I/your/dir/rpi_root/usr/include/python2.7/"
* @endcode
*
* 2. Build the python wrapper
* @code
* cd pyRF24
* ./setup.py build --compiler=crossunix
* @endcode
*
* 3. Make the egg package
* @code ./setup.py bdist_egg --plat-name=cross @endcode
* dist/RF24-<version>-cross.egg should be created.
*
* 4. Upload it to the target machine and install there:
* @code
* scp dist/RF24-*-cross.egg pi@target_linux_host:
* ssh pi@target_linux_host 'sudo easy_install RF24-*-cross.egg'
* @endcode
*
* <br><br><br>
*
* @page ATXMEGA ATXMEGA
*
* The RF24 driver can be build as a static library with Atmel Studio 7 in order to be included as any other library in another program for the XMEGA family.
*
* Currently only the <b>ATXMEGA D3</b> family is implemented.
*
* @section Preparation
*
* Create an empty GCC Static Library project in AS7.<br>
* As not all files are required, copy the following directory structure in the project:
*
* @code
* utility\
* ATXMegaD3\
* compatibility.c
* compatibility.h
* gpio.cpp
* gpio.h
* gpio_helper.c
* gpio_helper.h
* includes.h
* RF24_arch_config.h
* spi.cpp
* spi.h
* nRF24L01.h
* printf.h
* RF24.cpp
* RF24.h
* RF24_config.h
* @endcode
*
* @section Usage
*
* Add the library to your project!<br>
* In the file where the **main()** is put the following in order to update the millisecond functionality:
*
* @code
* ISR(TCE0_OVF_vect)
* {
* update_milisec();
* }
* @endcode
*
* Declare the rf24 radio with **RF24 radio(XMEGA_PORTC_PIN3, XMEGA_SPI_PORT_C);**
*
* First parameter is the CE pin which can be any available pin on the uC.
*
* Second parameter is the CS which can be on port C (**XMEGA_SPI_PORT_C**) or on port D (**XMEGA_SPI_PORT_D**).
*
* Call the **__start_timer()** to start the millisecond timer.
*
* @note Note about the millisecond functionality:<br>
*
* The millisecond functionality is based on the TCE0 so don't use these pins as IO.<br>
* The operating frequency of the uC is 32MHz. If you have other frequency change the TCE0 registers appropriatly in function **__start_timer()** in **compatibility.c** file for your frequency.
*
* @page Portability RF24 Portability
*
......@@ -1873,7 +1968,7 @@ private:
*<br>
* @section Device_Detection Device Detection
*
* 1. The main detection for Linux devices is done in the Makefile, with the includes.h from the proper hardware directory copied to RF24/utility/includes.h <br>
* 1. The main detection for Linux devices is done in the configure script, with the includes.h from the proper hardware directory copied to RF24/utility/includes.h <br>
* 2. Secondary detection is completed in RF24_config.h, causing the include.h file to be included for all supported Linux devices <br>
* 3. RF24.h contains the declaration for SPI and GPIO objects 'spi' and 'gpio' to be used for porting-in related functions.
*
......
......@@ -28,8 +28,14 @@
#if defined SPI_HAS_TRANSACTION && !defined SPI_UART && !defined SOFTSPI
#define RF24_SPI_TRANSACTIONS
#endif
#if ( !defined (ARDUINO) ) // Any non-arduino device is handled via configure/Makefile
//ATXMega
#if defined(__AVR_ATxmega64D3__) || defined(__AVR_ATxmega128D3__) || defined(__AVR_ATxmega192D3__) || defined(__AVR_ATxmega256D3__) || defined(__AVR_ATxmega384D3__) // In order to be available both in windows and linux this should take presence here.
#define XMEGA
#define XMEGA_D3
#include "utility/ATXMegaD3/RF24_arch_config.h"
#elif ( !defined (ARDUINO) ) // Any non-arduino device is handled via configure/Makefile
// The configure script detects device and copies the correct includes.h file to /utility/includes.h
// This behavior can be overridden by calling configure with respective parameters
......@@ -41,6 +47,12 @@
#define RF24_TINY
#include "utility/ATTiny/RF24_arch_config.h"
//LittleWire
#elif defined(LITTLEWIRE)
#include "utility/LittleWire/RF24_arch_config.h"
//Teensy
#elif defined (TEENSYDUINO)
......@@ -78,17 +90,19 @@
#if defined(__arm__) || defined (__ARDUINO_X86__)
#include <SPI.h>
#if defined (__arm__) && defined (SPI_UART)
#include <SPI_UART.h>
#define _SPI uspi
#else
#include <SPI.h>
#define _SPI SPI
#endif
#elif !defined(__arm__) && !defined (__ARDUINO_X86__)
extern HardwareSPI SPI;
#endif
#define _BV(x) (1<<(x))
#if !defined(__arm__) && !defined (__ARDUINO_X86__)
extern HardwareSPI SPI;
#endif
#define _SPI SPI
#endif
#ifdef SERIAL_DEBUG
......@@ -119,7 +133,7 @@
#define pgm_read_word(p) (*(p))
#define PRIPSTR "%s"
#elif defined(ARDUINO) && ! defined(__arm__) && !defined (__ARDUINO_X86__)
#elif defined(ARDUINO) && ! defined(__arm__) && !defined (__ARDUINO_X86__) || defined(XMEGA)
#include <avr/pgmspace.h>
#define PRIPSTR "%S"
#else
......
......@@ -17,7 +17,7 @@ Driver options:
Building options:
--os=[LINUX|DARWIN] Operating system. [configure autodetected]
--soc=[BCM2835|BCM2836|AM33XX|A10|A13|A20]
--soc=[BCM2835|BCM2836|AM33XX|A10|A13|A20|H3]
SoC type to be used. [configure autodetected]
--cpu-flags=<CFLAGS> CPU defining/optimizing flags to be used. [configure autodetected]
--extra-cflags=<CFLAGS> Extra C flags passed to C/C++ compilation. []
......@@ -64,10 +64,12 @@ function die {
function detect_machine {
local cpu=$(execute_check "uname -m 2>/dev/null")
local machine=$(execute_check "cat /sys/firmware/devicetree/base/model 2>/dev/null")
local hardware=$(execute_check "grep Hardware /proc/cpuinfo 2>/dev/null")
local hardware=$(execute_check "grep sunxi_platform /sys/class/sunxi_info/sys_info 2>/dev/null | sed 's/^.*: \(.*\)$/\1/'")
if [ -z "$hardware" ]; then
local hardware=$(execute_check "grep Hardware /proc/cpuinfo 2>/dev/null | sed 's/^.*: \(.*\)$/\1/'")
fi
local soc="unknown"
local tp="unknown"
hardware=$(echo ${hardware/*:/} | sed 's/^ *//g')
if [ -z "$cpu" ]; then
cpu="unknown"
......@@ -86,16 +88,25 @@ function detect_machine {
tp="RPi2"
fi
;;
sun4i)
sun4i|Sun4iw1p1)
soc="A10"
;;
sun5i)
sun5i|Sun4iw2p1)
soc="A13"
;;
sun6i)
Sun4iw2p2)
soc="A12"
;;
Sun4iw2p3)
soc="A10s"
;;
sun6i|Sun8iw1p1)
soc="A31"
;;
sun7i)
Sun8iw1p2)
soc="A31s"
;;
sun7i|Sun8iw2p1)
soc="A20"
if [[ $machine == "Banana Pi"* ]]; then
tp="BananaPi"
......@@ -103,13 +114,25 @@ function detect_machine {
tp="BananaPro"
fi
;;
sun8i)
sun8i|Sun8iw7p1)
soc="H3"
;;
Sun8iw3p1)
soc="A23"
;;
sun9i)
Sun8iw5p1)
soc="A33"
;;
Sun8iw6p1)
soc="A83t"
;;
sun9i|Sun9iw1p1)
soc="A80"
;;
sun50i)
Sun9iw1p2)
soc="A80t"
;;
sun50i|Sun50iw1p1)
soc="A64"
;;
'Generic AM33XX'*)
......@@ -142,6 +165,9 @@ function gcc_cpu_flags {
A20)
flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard"
;;
H3)
flags="-march=armv8-a -mtune=cortex-a53 -mfpu=neon-vfpv4 -mfloat-abi=hard"
;;
*)
flags=""
esac
......@@ -398,11 +424,11 @@ fi
case ${OS} in
LINUX)
DYN_SUFFIX=so
SHARED_LINKER_FLAGS+=" -shared -Wl,-soname,lib${LIB}.${DYN_SUFFIX}"
SHARED_LINKER_FLAGS+=" -shared -Wl,-soname,lib${LIB}.${DYN_SUFFIX}.${LIB_VERSION%%.*}"
;;
DARWIN)
DYN_SUFFIX=dylib
SHARED_LINKER_FLAGS+=" -dynamiclib -install_name ${LIB_DIR}/lib${LIB}.${DYN_SUFFIX}"
SHARED_LINKER_FLAGS+=" -dynamiclib -install_name ${LIB_DIR}/lib${LIB}.${DYN_SUFFIX}.${LIB_VERSION%%.*}"
;;
*)
die "Unsupported OS: ${OS}." 3
......
......@@ -62,6 +62,8 @@ void setup(void)
radio.startListening();
radio.stopListening();
radio.printDetails();
// Print out header, high then low digit
int i = 0;
while ( i < num_channels )
......@@ -102,14 +104,13 @@ void loop(void)
// Listen for a little
radio.startListening();
delayMicroseconds(225);
delayMicroseconds(128);
radio.stopListening();
// Did we get a carrier?
if ( radio.testCarrier() ){
++values[i];
}
radio.stopListening();
}
}
......
......@@ -42,8 +42,10 @@ using namespace std;
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ);
// Setup for GPIO 22 CE and CE1 CSN with SPI Speed @ 8Mhz
RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
//RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
// Generic setup
RF24 radio(22, 0);
//
// Channel info
......@@ -97,49 +99,44 @@ int main(int argc, char** argv)
}
printf("\n");
// forever loop
// forever loop
while(1)
{
if ( reset_array == 1 )
{
// Clear measurement values
memset(values,0,sizeof(values));
printf("\n");
}
// Scan all channels num_reps times
int i = num_channels;
while (i--)
{
// Select this channel
radio.setChannel(i);
// Listen for a little
radio.startListening();
delayMicroseconds(128);
//radio.stopListening();
// Did we get a carrier?
if ( radio.testCarrier() )
++values[i];
if ( values[i] == 0xf )
{
reset_array = 2;
}
radio.stopListening();
}
// Print out channel measurements, clamped to a single hex digit
i = 0;
while ( i < num_channels )
{
printf("%x",min(0xf,(values[i]&0xf)));
++i;
}
printf("\n");
}
{
// Clear measurement values
memset(values,0,sizeof(values));
// Scan all channels num_reps times
int rep_counter = num_reps;
while(rep_counter--)
{
int i = num_channels;
while (i--)
{
// Select this channel
radio.setChannel(i);
// Listen for a little
radio.startListening();
delayMicroseconds(128);
radio.stopListening();
// Did we get a carrier?
if ( radio.testCarrier() ) ++values[i];
}
}
// Print out channel measurements, clamped to a single hex digit
i = 0;
while ( i < num_channels )
{
printf("%x",min(0xf,(values[i]&0xf)));
++i;
}
printf("\n");
}
return 0;
}
......
......@@ -7,15 +7,7 @@
"type": "git",
"url": "https://github.com/TMRh20/RF24.git"
},
"include": [
"*.h",
"*.c",
"*.cpp",
"arch/ATTiny/*",
"arch/Due/*",
"arch/Teensy/*",
"examples/*/*.ino"
],
"version": "1.1.7",
"frameworks": "arduino",
"platforms": [
"atmelavr",
......
name=RF24
version=1.1.6
version=1.2.0
author=TMRh20
maintainer=TMRh20
sentence=A library for NRF24L01(+) communication.
......
This is a fork from **http://tmrh20.github.io/RF24** which can be build as a static library for Atmel Studio 7.
Not all files are needed.
Just copy the following structure into a GCC Static Library project in AS7:
```
utility\
ATXMega256D3\
compatibility.c
compatibility.h
gpio.cpp
gpio.h
gpio_helper.c
gpio_helper.h
includes.h
RF24_arch_config.h
spi.cpp
spi.h
nRF24L01.h
printf.h
RF24.cpp
RF24.h
RF24_config.h
```
Only ATXMega256D3 is supported right now!
## Notes
The millisecond functionality is based on the TCE0 so don't use these pins as IO.
The operating frequency of the uC is 32MHz. If else change the TCE0 registers appropriatly in function **__start_timer()** in **compatibility.c** file for your frequency.
## Usage
Add the library to your project!
In the file where the **main()** is put the following in order to update the millisecond functionality:
```
ISR(TCE0_OVF_vect)
{
update_milisec();
}
```
Declare the rf24 radio with **RF24 radio(XMEGA_PORTC_PIN3, XMEGA_SPI_PORT_C);**
First parameter is the CE pin which can be any available pin on the uC.
Second parameter is the CS which can be on port C (**XMEGA_SPI_PORT_C**) or on port D (**XMEGA_SPI_PORT_D**).
Call the **__start_timer()** to start the millisecond timer.
** For further information please see http://tmrh20.github.io/RF24 for all documentation**
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
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.
*/
/**
* @file RF24_arch_config.h
* General defines and includes for RF24/Linux
*/
/**
* Example of RF24_arch_config.h for RF24 portability
*
* @defgroup Porting_General Porting: General
*
*
* @{
*/
#ifndef __RF24_ARCH_CONFIG_H__
#define __RF24_ARCH_CONFIG_H__
#include <stddef.h>
#include <avr/pgmspace.h>
#include "spi.h"
#include "gpio.h"
#include "compatibility.h"
#include <stdint.h>
#include <stdio.h>
//#include <time.h>
#include <string.h>
//#include <sys/time.h>
//#define _BV(x) (1<<(x))
#define _SPI spi
#undef SERIAL_DEBUG
#ifdef SERIAL_DEBUG
#define IF_SERIAL_DEBUG(x) ({x;})
#else
#define IF_SERIAL_DEBUG(x)
#endif
// Use the avr pgmspace commands
//// Avoid spurious warnings
//#if 1
//#if ! defined( NATIVE ) && defined( ARDUINO )
//#undef PROGMEM
//#define PROGMEM __attribute__(( section(".progmem.data") ))
//#undef PSTR
//#define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];}))
//#endif
//#endif
typedef uint16_t prog_uint16_t;
//#define PSTR(x) (x)
//#define printf_P printf
//#define strlen_P strlen
//#define PROGMEM
//#define pgm_read_word(p) (*(p))
#define PRIPSTR "%s"
//#define pgm_read_byte(p) (*(p))
// Function, constant map as a result of migrating from Arduino
#define LOW GPIO::OUTPUT_LOW
#define HIGH GPIO::OUTPUT_HIGH
#define INPUT GPIO::DIRECTION_IN
#define OUTPUT GPIO::DIRECTION_OUT
#define digitalWrite(pin, value) GPIO::write(pin, value)
#define pinMode(pin, direction) GPIO::open(pin, direction)
#define delay(milisec) __msleep(milisec)
#define delayMicroseconds(usec) __usleep(usec)
#define millis() __millis()
#endif // __RF24_ARCH_CONFIG_H__
/*@}*/
/*
* compatibility.c
*
* Created: 19/1/2016 15:31:35
* Author: akatran
*/
#include <avr/io.h>
#include <stdint.h>
#include <util/delay.h>
volatile uint32_t _millis;
void __msleep(int milisec)
{
while(milisec-- >0)
{
_delay_ms(1);
}
}
void __usleep(int usec)
{
while(usec-- >0)
{
_delay_us(1);
}
}
void __start_timer()
{
// Timer details : Clock is 32MHz, Timer resolution is 8bit, Prescaler is 256, Period is 124, Real Time is 0.001s
/* Set the timer to run at the fastest rate. */
TCE0.CTRLA = TC_CLKSEL_DIV256_gc;
/* Configure the timer for normal counting. */
TCE0.CTRLB = TC_WGMODE_NORMAL_gc;
/* At 2 MHz, one tick is 0.5 us. Set period to 8 us. */
TCE0.PER = 124;
//TCC0.PER = 2;
/* Configure timer to generate an interrupt on overflow. */
TCE0.INTCTRLA = TC_OVFINTLVL_HI_gc;
/* Enable this interrupt level. */
PMIC.CTRL = PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm;
_millis=0;
}
long __millis()
{
return _millis;
}
void update_milisec()
{
_millis++;
}
/*
* File: compatiblity.h
* Author: purinda
*
* Created on 24 June 2012, 3:08 PM
*/
/**
* @file compatibility.h
* Class declaration for SPI helper files
*/
/**
* Example of compatibility.h class declaration for timing functions portability
*
* @defgroup Porting_Timing Porting: Timing
*
*
* @{
*/
#ifndef COMPATIBLITY_H
#define COMPATIBLITY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
//#include <time.h>
//#include <sys/time.h>
void __msleep(int milisec);
void __usleep(int usec);
void __start_timer();
long __millis();
void update_milisec();
#ifdef __cplusplus
}
#endif
#endif /* COMPATIBLITY_H */
/*@}*/
\ No newline at end of file
/*
* gpio.cpp
*
* Created: 20/1/2016 11:57:21
* Author: akatran
*/
//#include "gpio_helper.h"
#include "gpio.h"
#include <stdlib.h>
void GPIO::open(int port, int DDR)
{
uint8_t pin;
PORT_t * p = GPIO_getPort(port,&pin);
if (DDR==0)
{
p->DIRCLR=pin;
}else if (DDR==1)
{
p->DIRSET = pin;
}
}
void GPIO::close(int port)
{
// Nothing to do with close;
}
int read(int port)
{
uint8_t pin;
PORT_t * p = GPIO_getPort(port,&pin);
return p->IN;
}
void GPIO::write(int port,int value)
{
uint8_t pin;
PORT_t * p = GPIO_getPort(port,&pin);
if (value==0)
{
p->OUTCLR=pin;
}else if (value==1)
{
p->OUTSET = pin;
}
}
/**
* @file gpio.h
* Class declaration for SPI helper files
*/
/**
* Example of gpio.h class declaration for GPIO portability
*
* @defgroup Porting_GPIO Porting: GPIO
*
*
* @{
*/
#ifndef GPIO_H
#define GPIO_H
#include <avr/io.h>
#include "gpio_helper.h"
class GPIO {
public:
/* Constants */
static const int DIRECTION_OUT = 1;
static const int DIRECTION_IN = 0;
static const int OUTPUT_HIGH = 1;
static const int OUTPUT_LOW = 0;
GPIO();
/**
* Similar to Arduino pinMode(pin,mode);
* @param port
* @param DDR
*/
static void open(int port, int DDR);
/**
*
* @param port
*/
static void close(int port);
/**
* Similar to Arduino digitalRead(pin);
* @param port
* @param value
*/
static int read(int port);
/**
* Similar to Arduino digitalWrite(pin,state);
* @param port
* @param value
*/
static void write(int port,int value);
virtual ~GPIO();
};
#endif /* GPIO_H */
/*@}*/
\ No newline at end of file
/*
* gpio_helper.c
*
* Created: 22/1/2016 15:28:48
* Author: akatran
*/
#include "gpio_helper.h"
/**
* Get the port corresponding in portnum. Default is PORTC.
*/
PORT_t * GPIO_getPort(int pinnum, uint8_t * pin_bm)
//PORT_t * GPIO_getPort(int portnum)
{
PORT_t * port = &PORTC;
if ( (pinnum >= XMEGA_PORTA_PIN0) && (pinnum<= XMEGA_PORTA_PIN7) )
{
port = &PORTA;
*pin_bm = (1<<pinnum);
}else if ( (pinnum >= XMEGA_PORTB_PIN0) && (pinnum<= XMEGA_PORTB_PIN7) )
{
port = &PORTB;
*pin_bm = (1<<(pinnum-8));
}else if ( (pinnum >= XMEGA_PORTC_PIN0) && (pinnum<= XMEGA_PORTC_PIN7) )
{
port = &PORTC;
*pin_bm = (1<<(pinnum-16));
}else if ( (pinnum >= XMEGA_PORTD_PIN0) && (pinnum<= XMEGA_PORTD_PIN7) )
{
port = &PORTD;
*pin_bm = (1<<(pinnum-24));
}else if ( (pinnum >= XMEGA_PORTE_PIN0) && (pinnum<= XMEGA_PORTE_PIN7) )
{
port = &PORTE;
*pin_bm = (1<<(pinnum-32));
}else if ( (pinnum >= XMEGA_PORTF_PIN0) && (pinnum<= XMEGA_PORTF_PIN7) )
{
port = &PORTF;
*pin_bm = (1<<(pinnum-40));
}
return port;
}
\ No newline at end of file
/*
* gpio_helper.h
*
* Created: 22/1/2016 15:29:12
* Author: akatran
*/
#ifndef GPIO_HELPER_H_
#define GPIO_HELPER_H_
#include <avr/io.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Defines */
#define XMEGA_PORTA_PIN0 0
#define XMEGA_PORTA_PIN1 1
#define XMEGA_PORTA_PIN2 2
#define XMEGA_PORTA_PIN3 3
#define XMEGA_PORTA_PIN4 4
#define XMEGA_PORTA_PIN5 5
#define XMEGA_PORTA_PIN6 6
#define XMEGA_PORTA_PIN7 7
#define XMEGA_PORTB_PIN0 8
#define XMEGA_PORTB_PIN1 9
#define XMEGA_PORTB_PIN2 10
#define XMEGA_PORTB_PIN3 11
#define XMEGA_PORTB_PIN4 12
#define XMEGA_PORTB_PIN5 13
#define XMEGA_PORTB_PIN6 14
#define XMEGA_PORTB_PIN7 15
#define XMEGA_PORTC_PIN0 16
#define XMEGA_PORTC_PIN1 17
#define XMEGA_PORTC_PIN2 18
#define XMEGA_PORTC_PIN3 19
#define XMEGA_PORTC_PIN4 20
#define XMEGA_PORTC_PIN5 21
#define XMEGA_PORTC_PIN6 22
#define XMEGA_PORTC_PIN7 23
#define XMEGA_PORTD_PIN0 24
#define XMEGA_PORTD_PIN1 25
#define XMEGA_PORTD_PIN2 26
#define XMEGA_PORTD_PIN3 27
#define XMEGA_PORTD_PIN4 28
#define XMEGA_PORTD_PIN5 29
#define XMEGA_PORTD_PIN6 30
#define XMEGA_PORTD_PIN7 31
#define XMEGA_PORTE_PIN0 32
#define XMEGA_PORTE_PIN1 33
#define XMEGA_PORTE_PIN2 34
#define XMEGA_PORTE_PIN3 35
#define XMEGA_PORTE_PIN4 36
#define XMEGA_PORTE_PIN5 37
#define XMEGA_PORTE_PIN6 38
#define XMEGA_PORTE_PIN7 39
#define XMEGA_PORTF_PIN0 40
#define XMEGA_PORTF_PIN1 41
#define XMEGA_PORTF_PIN2 42
#define XMEGA_PORTF_PIN3 43
#define XMEGA_PORTF_PIN4 44
#define XMEGA_PORTF_PIN5 45
#define XMEGA_PORTF_PIN6 46
#define XMEGA_PORTF_PIN7 47
#define XMEGA_SPI_PORT_C 20
#define XMEGA_SPI_PORT_D 28
//void GPIO_getPort(int pinnum, PORT_t * port, uint8_t pin);
//void GPIO_getPort(int pinnum, PORT_t * port, uint8_t * pin_bm);
PORT_t * GPIO_getPort(int pinnum, uint8_t * pin_bm);
#ifdef __cplusplus
}
#endif
#endif /* GPIO_HELPER_H_ */
\ No newline at end of file
/**
* @file includes.h
* Configuration defines for RF24/Linux
*/
/**
* Example of includes.h for RF24 Linux portability
*
* @defgroup Porting_Includes Porting: Includes
*
*
* @{
*/
#ifndef __RF24_INCLUDES_H__
#define __RF24_INCLUDES_H__
/**
* Define a specific platform for this configuration
*/
// #define RF24_BBB
/**
* Load the correct configuration for this platform
*/
//#include "BBB/RF24_arch_config.h"
#endif
/*@}*/
\ No newline at end of file
/*
* spi.cpp
*
* Created: 20/1/2016 10:10:39
* Author: akatran
*/
#include <avr/io.h>
#include "gpio_helper.h"
#include "spi.h"
using namespace std;
void SPI::begin(uint8_t _port)
{
if (_port==XMEGA_SPI_PORT_C) // Select SPI on PORTC
{
device = &SPIC;
port = &PORTC;
}else if (_port==XMEGA_SPI_PORT_D) // Select SPI on PORTD
{
device = &SPID;
port = &PORTD;
}
init();
}
uint8_t SPI::transfer(uint8_t tx_)
{
register8_t data;
device->DATA = tx_;
while(!(device->STATUS & (1<<7)));
data = device->DATA;
//PORTF.OUT = data;
return data;
}
void SPI::init()
{
port->DIRCLR = SPI_MISO_bm;
port->DIRSET = SPI_MOSI_bm | SPI_SCK_bm | SPI_SS_bm;
//device->CTRL = 0;
device->CTRL = SPI_ENABLE_bm | SPI_MASTER_bm | SPI_MODE_0_gc | SPI_PRESCALER_DIV4_gc;
device->INTCTRL =0; //Disable interrupts
}
SPI::SPI()
{
}
SPI::~SPI()
{
}
void operator delete(void * p) // or delete(void *, std::size_t)
{
}
\ No newline at end of file
/**
* @file spi.h
* Class declaration for SPI helper files
*/
/**
* Example of spi.h class declaration for SPI portability
*
* @defgroup Porting_SPI Porting: SPI
*
*
* @{
*/
#ifndef __XMEGASPI_H__
#define __XMEGASPI_H__
#include <avr/io.h>
#include <stdint.h>
//#include <string.h>
//#include <unistd.h>
//#include <stdio.h>
//#include <stdlib.h>
//#include <getopt.h>
//#include <fcntl.h>
//#include <sys/ioctl.h>
//#include <inttypes.h>
//#include <linux/types.h>
//#include <linux/spi/spidev.h>
#define SPI_SS_bm (1<<4) /* SPI SS pin mask 4 */
#define SPI_MOSI_bm (1<<5) /* SPI MOSI pin mask 5 */
#define SPI_MISO_bm (1<<6) /* SPI MISO pin mask 6 */
#define SPI_SCK_bm (1<<7) /* SPI SCK pin mask 7 */
using namespace std;
class SPI {
public:
/**
* SPI constructor
*/
SPI();
/**
* Start SPI
* @param port is the SPI port (XMEGA_SPI_PORT_C for SPI on PORTC, XMEGA_SPI_PORT_D on PORTD etc).
*/
void begin(uint8_t port);
/**
* Transfer a single byte
* @param tx_ Byte to send
* @return Data returned via spi
*/
uint8_t transfer(uint8_t tx_);
/**
* Transfer a buffer of data
* @param tbuf Transmit buffer
* @param rbuf Receive buffer
* @param len Length of the data
*/
void transfernb(char* tbuf, char* rbuf, uint32_t len);
/**
* Transfer a buffer of data without an rx buffer
* @param buf Pointer to a buffer of data
* @param len Length of the data
*/
void transfern(char* buf, uint32_t len);
virtual ~SPI();
private:
/** Default SPI device */
SPI_t * device;
/* Port of the SPI */
PORT_t * port;
void init();
};
#endif /*__XMEGASPI_H__*/
/*@}*/
\ No newline at end of file
......@@ -23,7 +23,7 @@ see <http://www.gnu.org/licenses/>
#define delay(x) bcm2835_delay(x)
static pthread_mutex_t pinMutex ;
static pthread_mutex_t pinMutex = PTHREAD_MUTEX_INITIALIZER;
static volatile int pinPass = -1 ;
pthread_t threadId [64];
......
#include "spi.h"
#include <pthread.h>
static pthread_mutex_t spiMutex;
static pthread_mutex_t spiMutex = PTHREAD_MUTEX_INITIALIZER;
SPI::SPI() {
......
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