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/ ...@@ -13,5 +13,12 @@ out_native/
version.h version.h
Session.vim Session.vim
*.so *.so
*.so.*
*.dylib *.dylib
*.dylib.*
.DS_Store .DS_Store
Makefile.inc
utility/includes.h
examples_linux/*
!examples_linux/**/
!examples_linux/*.*
...@@ -897,7 +897,7 @@ EXCLUDE_SYMBOLS = ...@@ -897,7 +897,7 @@ EXCLUDE_SYMBOLS =
# command). # command).
EXAMPLE_PATH = examples \ EXAMPLE_PATH = examples \
examples_RPi examples_linux
# If the value of the EXAMPLE_PATH tag contains directories, you can use the # 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 # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
......
...@@ -50,7 +50,7 @@ void RF24::csn(bool mode) ...@@ -50,7 +50,7 @@ void RF24::csn(bool mode)
#if !defined (RF24_LINUX) #if !defined (RF24_LINUX)
digitalWrite(csn_pin,mode); digitalWrite(csn_pin,mode);
delayMicroseconds(5); delayMicroseconds(csDelay);
#endif #endif
} }
...@@ -357,7 +357,7 @@ void RF24::print_status(uint8_t status) ...@@ -357,7 +357,7 @@ void RF24::print_status(uint8_t status)
(status & _BV(RX_DR))?1:0, (status & _BV(RX_DR))?1:0,
(status & _BV(TX_DS))?1:0, (status & _BV(TX_DS))?1:0,
(status & _BV(MAX_RT))?1:0, (status & _BV(MAX_RT))?1:0,
((status >> RX_P_NO) & 0b111), ((status >> RX_P_NO) & 0x07),
(status & _BV(TX_FULL))?1:0 (status & _BV(TX_FULL))?1:0
); );
} }
...@@ -368,8 +368,8 @@ void RF24::print_observe_tx(uint8_t value) ...@@ -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"), printf_P(PSTR("OBSERVE_TX=%02x: POLS_CNT=%x ARC_CNT=%x\r\n"),
value, value,
(value >> PLOS_CNT) & 0b1111, (value >> PLOS_CNT) & 0x0F,
(value >> ARC_CNT) & 0b1111 (value >> ARC_CNT) & 0x0F
); );
} }
...@@ -417,7 +417,7 @@ void RF24::print_address_register(const char* name, uint8_t reg, uint8_t qty) ...@@ -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): RF24::RF24(uint16_t _cepin, uint16_t _cspin):
ce_pin(_cepin), csn_pin(_cspin), p_variant(false), 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; pipe0_reading_address[0]=0;
} }
...@@ -425,6 +425,7 @@ RF24::RF24(uint16_t _cepin, uint16_t _cspin): ...@@ -425,6 +425,7 @@ RF24::RF24(uint16_t _cepin, uint16_t _cspin):
/****************************************************************************/ /****************************************************************************/
#if defined (RF24_LINUX) && !defined (MRAA)//RPi constructor #if defined (RF24_LINUX) && !defined (MRAA)//RPi constructor
RF24::RF24(uint16_t _cepin, uint16_t _cspin, uint32_t _spi_speed): 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) 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) ...@@ -602,6 +603,12 @@ bool RF24::begin(void)
pinMode(csn_pin,OUTPUT); pinMode(csn_pin,OUTPUT);
_SPI.begin(); _SPI.begin();
csn(HIGH); 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 #else
// Initialize pins // Initialize pins
if (ce_pin != csn_pin) pinMode(ce_pin,OUTPUT); if (ce_pin != csn_pin) pinMode(ce_pin,OUTPUT);
...@@ -628,7 +635,7 @@ bool RF24::begin(void) ...@@ -628,7 +635,7 @@ bool RF24::begin(void)
delay( 5 ) ; delay( 5 ) ;
// Reset NRF_CONFIG and enable 16-bit CRC. // 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 // 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 // WARNING: If this is ever lowered, either 250KBS mode with AA is broken or maximum packet
...@@ -661,6 +668,7 @@ bool RF24::begin(void) ...@@ -661,6 +668,7 @@ bool RF24::begin(void)
toggle_features(); toggle_features();
write_register(FEATURE,0 ); write_register(FEATURE,0 );
write_register(DYNPD,0); write_register(DYNPD,0);
dynamic_payloads_enabled = false;
// Reset current status // Reset current status
// Notice reset and flush is the last thing we do // Notice reset and flush is the last thing we do
...@@ -722,10 +730,10 @@ void RF24::stopListening(void) ...@@ -722,10 +730,10 @@ void RF24::stopListening(void)
{ {
ce(LOW); ce(LOW);
delayMicroseconds(txRxDelay); delayMicroseconds(txDelay);
if(read_register(FEATURE) & _BV(EN_ACK_PAY)){ if(read_register(FEATURE) & _BV(EN_ACK_PAY)){
delayMicroseconds(txRxDelay); //200 delayMicroseconds(txDelay); //200
flush_tx(); flush_tx();
} }
//flush_rx(); //flush_rx();
...@@ -1065,7 +1073,7 @@ bool RF24::available(uint8_t* pipe_num) ...@@ -1065,7 +1073,7 @@ bool RF24::available(uint8_t* pipe_num)
// If the caller wants the pipe number, include that // If the caller wants the pipe number, include that
if ( pipe_num ){ if ( pipe_num ){
uint8_t status = get_status(); uint8_t status = get_status();
*pipe_num = ( status >> RX_P_NO ) & 0b111; *pipe_num = ( status >> RX_P_NO ) & 0x07;
} }
return 1; return 1;
} }
...@@ -1175,7 +1183,10 @@ void RF24::setAddressWidth(uint8_t a_width){ ...@@ -1175,7 +1183,10 @@ void RF24::setAddressWidth(uint8_t a_width){
if(a_width -= 2){ if(a_width -= 2){
write_register(SETUP_AW,a_width%4); write_register(SETUP_AW,a_width%4);
addr_width = (a_width%4) + 2; 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) ...@@ -1292,7 +1303,7 @@ void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
beginTransaction(); beginTransaction();
uint8_t * ptx = spi_txbuff; uint8_t * ptx = spi_txbuff;
uint8_t size = data_len + 1 ; // Add register value to transmit buffer 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-- ){ while ( data_len-- ){
*ptx++ = *current++; *ptx++ = *current++;
} }
...@@ -1301,7 +1312,7 @@ void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len) ...@@ -1301,7 +1312,7 @@ void RF24::writeAckPayload(uint8_t pipe, const void* buf, uint8_t len)
endTransaction(); endTransaction();
#else #else
beginTransaction(); beginTransaction();
_SPI.transfer(W_ACK_PAYLOAD | ( pipe & 0b111 ) ); _SPI.transfer(W_ACK_PAYLOAD | ( pipe & 0x07 ) );
while ( data_len-- ) while ( data_len-- )
_SPI.transfer(*current++); _SPI.transfer(*current++);
...@@ -1330,7 +1341,7 @@ bool RF24::isPVariant(void) ...@@ -1330,7 +1341,7 @@ bool RF24::isPVariant(void)
void RF24::setAutoAck(bool enable) void RF24::setAutoAck(bool enable)
{ {
if ( enable ) if ( enable )
write_register(EN_AA, 0b111111); write_register(EN_AA, 0x3F);
else else
write_register(EN_AA, 0); write_register(EN_AA, 0);
} }
...@@ -1373,7 +1384,7 @@ bool RF24::testRPD(void) ...@@ -1373,7 +1384,7 @@ bool RF24::testRPD(void)
void RF24::setPALevel(uint8_t level) 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 if(level > 3){ // If invalid level, go to max PA
level = (RF24_PA_MAX << 1) + 1; // +1 to support the SI24R1 chip extra bit 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) ...@@ -1404,9 +1415,9 @@ bool RF24::setDataRate(rf24_datarate_e speed)
setup &= ~(_BV(RF_DR_LOW) | _BV(RF_DR_HIGH)) ; setup &= ~(_BV(RF_DR_LOW) | _BV(RF_DR_HIGH)) ;
#if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__) #if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__)
txRxDelay=250; txDelay=250;
#else //16Mhz Arduino #else //16Mhz Arduino
txRxDelay=85; txDelay=85;
#endif #endif
if( speed == RF24_250KBPS ) if( speed == RF24_250KBPS )
{ {
...@@ -1414,9 +1425,9 @@ bool RF24::setDataRate(rf24_datarate_e speed) ...@@ -1414,9 +1425,9 @@ bool RF24::setDataRate(rf24_datarate_e speed)
// Making it '10'. // Making it '10'.
setup |= _BV( RF_DR_LOW ) ; setup |= _BV( RF_DR_LOW ) ;
#if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__) #if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__)
txRxDelay=450; txDelay=450;
#else //16Mhz Arduino #else //16Mhz Arduino
txRxDelay=155; txDelay=155;
#endif #endif
} }
else else
...@@ -1427,9 +1438,9 @@ bool RF24::setDataRate(rf24_datarate_e speed) ...@@ -1427,9 +1438,9 @@ bool RF24::setDataRate(rf24_datarate_e speed)
{ {
setup |= _BV(RF_DR_HIGH); setup |= _BV(RF_DR_HIGH);
#if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__) #if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__)
txRxDelay=190; txDelay=190;
#else //16Mhz Arduino #else //16Mhz Arduino
txRxDelay=65; txDelay=65;
#endif #endif
} }
} }
......
This diff is collapsed.
...@@ -28,8 +28,14 @@ ...@@ -28,8 +28,14 @@
#if defined SPI_HAS_TRANSACTION && !defined SPI_UART && !defined SOFTSPI #if defined SPI_HAS_TRANSACTION && !defined SPI_UART && !defined SOFTSPI
#define RF24_SPI_TRANSACTIONS #define RF24_SPI_TRANSACTIONS
#endif #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 // 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 // This behavior can be overridden by calling configure with respective parameters
...@@ -41,6 +47,12 @@ ...@@ -41,6 +47,12 @@
#define RF24_TINY #define RF24_TINY
#include "utility/ATTiny/RF24_arch_config.h" #include "utility/ATTiny/RF24_arch_config.h"
//LittleWire
#elif defined(LITTLEWIRE)
#include "utility/LittleWire/RF24_arch_config.h"
//Teensy //Teensy
#elif defined (TEENSYDUINO) #elif defined (TEENSYDUINO)
...@@ -78,17 +90,19 @@ ...@@ -78,17 +90,19 @@
#if defined(__arm__) || defined (__ARDUINO_X86__) #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 #endif
#define _BV(x) (1<<(x)) #define _BV(x) (1<<(x))
#if !defined(__arm__) && !defined (__ARDUINO_X86__)
extern HardwareSPI SPI;
#endif
#define _SPI SPI
#endif #endif
#ifdef SERIAL_DEBUG #ifdef SERIAL_DEBUG
...@@ -119,7 +133,7 @@ ...@@ -119,7 +133,7 @@
#define pgm_read_word(p) (*(p)) #define pgm_read_word(p) (*(p))
#define PRIPSTR "%s" #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> #include <avr/pgmspace.h>
#define PRIPSTR "%S" #define PRIPSTR "%S"
#else #else
......
...@@ -17,7 +17,7 @@ Driver options: ...@@ -17,7 +17,7 @@ Driver options:
Building options: Building options:
--os=[LINUX|DARWIN] Operating system. [configure autodetected] --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] SoC type to be used. [configure autodetected]
--cpu-flags=<CFLAGS> CPU defining/optimizing flags 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. [] --extra-cflags=<CFLAGS> Extra C flags passed to C/C++ compilation. []
...@@ -64,10 +64,12 @@ function die { ...@@ -64,10 +64,12 @@ function die {
function detect_machine { function detect_machine {
local cpu=$(execute_check "uname -m 2>/dev/null") local cpu=$(execute_check "uname -m 2>/dev/null")
local machine=$(execute_check "cat /sys/firmware/devicetree/base/model 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 soc="unknown"
local tp="unknown" local tp="unknown"
hardware=$(echo ${hardware/*:/} | sed 's/^ *//g')
if [ -z "$cpu" ]; then if [ -z "$cpu" ]; then
cpu="unknown" cpu="unknown"
...@@ -86,16 +88,25 @@ function detect_machine { ...@@ -86,16 +88,25 @@ function detect_machine {
tp="RPi2" tp="RPi2"
fi fi
;; ;;
sun4i) sun4i|Sun4iw1p1)
soc="A10" soc="A10"
;; ;;
sun5i) sun5i|Sun4iw2p1)
soc="A13" soc="A13"
;; ;;
sun6i) Sun4iw2p2)
soc="A12"
;;
Sun4iw2p3)
soc="A10s"
;;
sun6i|Sun8iw1p1)
soc="A31" soc="A31"
;; ;;
sun7i) Sun8iw1p2)
soc="A31s"
;;
sun7i|Sun8iw2p1)
soc="A20" soc="A20"
if [[ $machine == "Banana Pi"* ]]; then if [[ $machine == "Banana Pi"* ]]; then
tp="BananaPi" tp="BananaPi"
...@@ -103,13 +114,25 @@ function detect_machine { ...@@ -103,13 +114,25 @@ function detect_machine {
tp="BananaPro" tp="BananaPro"
fi fi
;; ;;
sun8i) sun8i|Sun8iw7p1)
soc="H3"
;;
Sun8iw3p1)
soc="A23" soc="A23"
;; ;;
sun9i) Sun8iw5p1)
soc="A33"
;;
Sun8iw6p1)
soc="A83t"
;;
sun9i|Sun9iw1p1)
soc="A80" soc="A80"
;; ;;
sun50i) Sun9iw1p2)
soc="A80t"
;;
sun50i|Sun50iw1p1)
soc="A64" soc="A64"
;; ;;
'Generic AM33XX'*) 'Generic AM33XX'*)
...@@ -142,6 +165,9 @@ function gcc_cpu_flags { ...@@ -142,6 +165,9 @@ function gcc_cpu_flags {
A20) A20)
flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard" 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="" flags=""
esac esac
...@@ -398,11 +424,11 @@ fi ...@@ -398,11 +424,11 @@ fi
case ${OS} in case ${OS} in
LINUX) LINUX)
DYN_SUFFIX=so 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) DARWIN)
DYN_SUFFIX=dylib 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 die "Unsupported OS: ${OS}." 3
......
...@@ -62,6 +62,8 @@ void setup(void) ...@@ -62,6 +62,8 @@ void setup(void)
radio.startListening(); radio.startListening();
radio.stopListening(); radio.stopListening();
radio.printDetails();
// Print out header, high then low digit // Print out header, high then low digit
int i = 0; int i = 0;
while ( i < num_channels ) while ( i < num_channels )
...@@ -102,14 +104,13 @@ void loop(void) ...@@ -102,14 +104,13 @@ void loop(void)
// Listen for a little // Listen for a little
radio.startListening(); radio.startListening();
delayMicroseconds(225); delayMicroseconds(128);
radio.stopListening();
// Did we get a carrier? // Did we get a carrier?
if ( radio.testCarrier() ){ if ( radio.testCarrier() ){
++values[i]; ++values[i];
} }
radio.stopListening();
} }
} }
......
...@@ -42,8 +42,10 @@ using namespace std; ...@@ -42,8 +42,10 @@ using namespace std;
//RF24 radio(RPI_V2_GPIO_P1_15, BCM2835_SPI_CS0, BCM2835_SPI_SPEED_4MHZ); //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 // 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 // Channel info
...@@ -97,49 +99,44 @@ int main(int argc, char** argv) ...@@ -97,49 +99,44 @@ int main(int argc, char** argv)
} }
printf("\n"); printf("\n");
// forever loop // forever loop
while(1) while(1)
{ {
if ( reset_array == 1 ) // Clear measurement values
{ memset(values,0,sizeof(values));
// Clear measurement values
memset(values,0,sizeof(values)); // Scan all channels num_reps times
printf("\n"); int rep_counter = num_reps;
} while(rep_counter--)
{
// Scan all channels num_reps times
int i = num_channels; int i = num_channels;
while (i--) while (i--)
{ {
// Select this channel
radio.setChannel(i); // Select this channel
radio.setChannel(i);
// Listen for a little
radio.startListening(); // Listen for a little
delayMicroseconds(128); radio.startListening();
//radio.stopListening(); delayMicroseconds(128);
radio.stopListening();
// Did we get a carrier?
if ( radio.testCarrier() ) // Did we get a carrier?
++values[i]; if ( radio.testCarrier() ) ++values[i];
if ( values[i] == 0xf ) }
{ }
reset_array = 2;
} // Print out channel measurements, clamped to a single hex digit
radio.stopListening(); i = 0;
} while ( i < num_channels )
{
// Print out channel measurements, clamped to a single hex digit printf("%x",min(0xf,(values[i]&0xf)));
i = 0; ++i;
while ( i < num_channels ) }
{ printf("\n");
printf("%x",min(0xf,(values[i]&0xf))); }
++i;
}
printf("\n");
}
return 0; return 0;
} }
......
...@@ -7,15 +7,7 @@ ...@@ -7,15 +7,7 @@
"type": "git", "type": "git",
"url": "https://github.com/TMRh20/RF24.git" "url": "https://github.com/TMRh20/RF24.git"
}, },
"include": [ "version": "1.1.7",
"*.h",
"*.c",
"*.cpp",
"arch/ATTiny/*",
"arch/Due/*",
"arch/Teensy/*",
"examples/*/*.ino"
],
"frameworks": "arduino", "frameworks": "arduino",
"platforms": [ "platforms": [
"atmelavr", "atmelavr",
......
name=RF24 name=RF24
version=1.1.6 version=1.2.0
author=TMRh20 author=TMRh20
maintainer=TMRh20 maintainer=TMRh20
sentence=A library for NRF24L01(+) communication. 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/> ...@@ -23,7 +23,7 @@ see <http://www.gnu.org/licenses/>
#define delay(x) bcm2835_delay(x) #define delay(x) bcm2835_delay(x)
static pthread_mutex_t pinMutex ; static pthread_mutex_t pinMutex = PTHREAD_MUTEX_INITIALIZER;
static volatile int pinPass = -1 ; static volatile int pinPass = -1 ;
pthread_t threadId [64]; pthread_t threadId [64];
......
#include "spi.h" #include "spi.h"
#include <pthread.h> #include <pthread.h>
static pthread_mutex_t spiMutex; static pthread_mutex_t spiMutex = PTHREAD_MUTEX_INITIALIZER;
SPI::SPI() { 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