Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into Updates
Browse files Browse the repository at this point in the history
Conflicts:
	RF24.cpp

Merge master with updates branch
  • Loading branch information
TMRh20 committed Feb 1, 2015
2 parents 39a6385 + e3f9f9a commit 3c652ed
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ out/
out_native/
version.h
Session.vim
*.so
*.dylib
.DS_Store
65 changes: 65 additions & 0 deletions Makefile.littlewire
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#############################################################################
#
# Makefile for librf24 via LittleWire
#
# License: GPL (General Public License)
# Author: Andreas Steinel
# Date: 2014/11/19
#
# Description:
# ------------
# use make all and make install to install the library
# You can change the install directory by editing the LIBDIR line
#

PREFIX=/opt/LittleWirePrefix

LIB=librf24

HEADER_DIR=${PREFIX}/include/RF24
LIB_DIR=$(PREFIX)/lib

ifeq ($(shell uname), Linux)
DYN_SUFFIX=so
LINK_FORMAT=-shared -Wl,-soname,$@.$(DYN_SUFFIX)
else ifeq ($(shell uname), Darwin)
DYN_SUFFIX=dylib
LINK_FORMAT=-dynamiclib -install_name ${LIB_DIR}/${LIB}.${DYN_SUFFIX}
else
$(shell echo "Unknown System, please fix Makefile!")
$(shell false )
endif

LIBNAME=$(LIB).$(DYN_SUFFIX)
CCFLAGS=-O2 -Wall -g -DLITTLEWIRE -I$(PREFIX)/include
LIBS=-L$(PREFIX)/lib -llittlewire-spi

# make all
# reinstall the library after each recompilation
all: $(LIB)

# Make the library
$(LIB): RF24.o
g++ $(LINK_FORMAT) ${LIBS} -o ${LIBNAME} $^

# Library parts
RF24.o: RF24.cpp
g++ -Wall -fPIC ${CCFLAGS} -c $^

# clear build files
clean:
rm -rf *.o ${LIBNAME}

install: all install-libs install-headers

# Install the library to LIBPATH
install-libs:
@echo "[Installing Libs]"
@if ( test ! -d ${LIB_DIR} ) ; then mkdir -p ${LIB_DIR}; fi
@install -m 0755 ${LIBNAME} ${LIB_DIR}
@ln -sf ${LIB_DIR}/${LIBNAME} ${LIB_DIR}/${LIBNAME}.1

install-headers:
@echo "[Installing Headers]"
@if ( test ! -d ${HEADER_DIR} ) ; then mkdir -p ${HEADER_DIR} ; fi
@install -m 0644 *.h ${HEADER_DIR}
51 changes: 31 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Optimized High Speed Arduino driver for nRF24L01 2.4GHz Wireless Transceiver
# Optimized High Speed Arduino/Rapsberry Pi/LittleWire driver for nRF24L01 2.4GHz Wireless Transceiver

Design Goals: This library is designed to be...

Expand Down Expand Up @@ -40,34 +40,43 @@ Supported Boards:
* Raspberry Pi
* See the [documentation](http://tmrh20.github.io/) for more info

## Pin layout
## µC Pin layout

The table below shows how to connect the the pins of the NRF24L01(+) to different boards.
CE and CSN are configurable.

| PIN | NRF24L01 | Arduino UNO | ATtiny25/45/85 [0] | ATtiny44/84 [1] |
|-----|----------|-------------|--------------------|-----------------|
| 1 | GND | GND | pin 4 | pin 14 |
| 2 | VCC | 3.3V | pin 8 | pin 1 |
| 3 | CE | digIO 7 | pin 2 | pin 12 |
| 4 | CSN | digIO 8 | pin 3 | pin 11 |
| 5 | SCK | digIO 13 | pin 7 | pin 9 |
| 6 | MOSI | digIO 11 | pin 6 | pin 7 |
| 7 | MISO | digIO 12 | pin 5 | pin 8 |
| 8 | IRQ | - | - | - |
| PIN | NRF24L01 | Arduino UNO | ATtiny25/45/85 [0] | ATtiny44/84 [1] | LittleWire [2]
|-----|----------|-------------|--------------------|-----------------|--------------
| 1 | GND | GND | pin 4 | pin 14 | GND
| 2 | VCC | 3.3V | pin 8 | pin 1 | regulator 3.3V required
| 3 | CE | digIO 7 | pin 2 | pin 12 | pin to 3.3V
| 4 | CSN | digIO 8 | pin 3 | pin 11 | RESET
| 5 | SCK | digIO 13 | pin 7 | pin 9 | SCK
| 6 | MOSI | digIO 11 | pin 6 | pin 7 | MOSI
| 7 | MISO | digIO 12 | pin 5 | pin 8 | MISO
| 8 | IRQ | - | - | - | -

[0] https://learn.sparkfun.com/tutorials/tiny-avr-programmer-hookup-guide/attiny85-use-hints

[1] http://highlowtech.org/?p=1695

[2] http://littlewire.cc/

### LittleWire

In order to connect it directly to your LittleWire powered device (ATtiny85-based), you need

* on the hardware side: regulated 3.3 volts by using some DC-DC converter like TSC295033
* [LittleWire Wrapper library](https:/lnxbil/LittleWireSPI) by [lnxbil](https:/lnxbil) to bridge SPI to the computer.

## Raspberry Pi Configuration:
## Raspberry Pi

### Configuration:

Library functions are mostly the same.
See the included examples for RPi specific usage

## Raspberry Pi - PreConfig

### Possible pre-configuration:
### Raspberry Pi - Possible pre-configuration:
If SPI is not already enabled, load it on boot:

sudo raspi-config
Expand Down Expand Up @@ -101,7 +110,9 @@ D. Run an example file from one of the libraries:
sudo ./gettingstarted


# RPi - RF24 Quick-Start

### RPi - RF24 Quick-Start

A. Make a directory to contain the RF24 and possibly RF24Network lib and enter it:

Expand All @@ -124,7 +135,7 @@ D. Build the library, and run an example file:
sudo ./gettingstarted


# RPi - RF24Network Quick-Start
### RPi - RF24Network Quick-Start

A. Enter the same directory that contains the RF24 library folder

Expand All @@ -146,7 +157,7 @@ D. Build the library
sudo ./helloworld_rx OR sudo ./helloworld_tx


# Connection Info
### Connection Info

Using pin 15/GPIO 22 for CE, pin 24/GPIO8 (CE0) for CSN

Expand Down Expand Up @@ -191,4 +202,4 @@ Network lib also based on https:/farconada/RF24Network

Currently optimized and aligned with Arduino fork of libraries by TMRh20:
https:/tmrh20/RF24/RPi and https:/tmrh20/RF24Network/RPi
Documentation: http://tmrh20.github.io
Documentation: http://tmrh20.github.io
50 changes: 36 additions & 14 deletions RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,16 +598,17 @@ void RF24::printDetails(void)
print_byte_register(PSTR("RF_SETUP"),RF_SETUP);
print_byte_register(PSTR("CONFIG"),CONFIG);
print_byte_register(PSTR("DYNPD/FEATURE"),DYNPD,2);
#if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__)

#if defined(__arm__) || defined (RF24_LINUX) || defined (__ARDUINO_X86__) || defined(LITTLEWIRE)
printf_P(PSTR("Data Rate\t = %s\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));
printf_P(PSTR("Model\t\t = %s\r\n"),pgm_read_word(&rf24_model_e_str_P[isPVariant()]));
printf_P(PSTR("CRC Length\t = %s\r\n"),pgm_read_word(&rf24_crclength_e_str_P[getCRCLength()]));
printf_P(PSTR("PA Power\t = %s\r\n"),pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()]));
printf_P(PSTR("PA Power\t = %s\r\n"), pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()]));
#else
printf_P(PSTR("Data Rate\t = %S\r\n"),pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));
printf_P(PSTR("Model\t\t = %S\r\n"),pgm_read_word(&rf24_model_e_str_P[isPVariant()]));
printf_P(PSTR("Data Rate\t = %S\r\n"), pgm_read_word(&rf24_datarate_e_str_P[getDataRate()]));
printf_P(PSTR("Model\t\t = %S\r\n"), pgm_read_word(&rf24_model_e_str_P[isPVariant()]));
printf_P(PSTR("CRC Length\t = %S\r\n"),pgm_read_word(&rf24_crclength_e_str_P[getCRCLength()]));
printf_P(PSTR("PA Power\t = %S\r\n"),pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()]));
printf_P(PSTR("PA Power\t = %S\r\n"), pgm_read_word(&rf24_pa_dbm_e_str_P[getPALevel()]));
#endif

}
Expand Down Expand Up @@ -637,6 +638,10 @@ void RF24::begin(void)
ce(LOW);
delay(100);

#elif defined(LITTLEWIRE)
pinMode(csn_pin,OUTPUT);
_SPI.begin();
csn(HIGH);
#else
// Initialize pins
if (ce_pin != csn_pin) pinMode(ce_pin,OUTPUT);
Expand All @@ -649,7 +654,11 @@ void RF24::begin(void)
ce(LOW);
//csn(HIGH);
#else
if (ce_pin != csn_pin) pinMode(csn_pin,OUTPUT);
#if ! defined(LITTLEWIRE)
if (ce_pin != csn_pin)
#endif
pinMode(csn_pin,OUTPUT);

_SPI.begin();
ce(LOW);
csn(HIGH);
Expand All @@ -667,6 +676,9 @@ void RF24::begin(void)
// WARNING: Delay is based on P-variant whereby non-P *may* require different timing.
delay( 5 ) ;

// Reset CONFIG and enable 16-bit CRC.
write_register( CONFIG, 0b00001100 ) ;

// 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
// sizes must never be used. See documentation for a more complete explanation.
Expand All @@ -689,9 +701,11 @@ void RF24::begin(void)
setDataRate( RF24_1MBPS ) ;

// Initialize CRC and request 2-byte (16bit) CRC
setCRCLength( RF24_CRC_16 ) ;

// Disable per-pipe dynpd settings
//setCRCLength( RF24_CRC_16 ) ;

// Disable dynamic payloads, to match dynamic_payloads_enabled setting - Reset value is 0
toggle_features();
write_register(FEATURE,0 );
write_register(DYNPD,0);

// Attempt to write to the 'FEATURE' register
Expand Down Expand Up @@ -730,7 +744,7 @@ void RF24::begin(void)

void RF24::startListening(void)
{
#if !defined (RF24_TINY)
#if !defined (RF24_TINY) && ! defined(LITTLEWIRE)
powerUp();
#endif
write_register(CONFIG, read_register(CONFIG) | _BV(PRIM_RX));
Expand Down Expand Up @@ -772,7 +786,7 @@ void RF24::stopListening(void)
//flush_rx();
write_register(CONFIG, ( read_register(CONFIG) ) & ~_BV(PRIM_RX) );

#if defined (RF24_TINY)
#if defined (RF24_TINY) || defined (LITTLEWIRE)
// for 3 pins solution TX mode is only left with additonal powerDown/powerUp cycle
if (ce_pin == csn_pin) {
powerDown();
Expand Down Expand Up @@ -958,11 +972,13 @@ bool RF24::writeFast( const void* buf, uint8_t len ){
//Otherwise we enter Standby-II mode, which is still faster than standby mode
//Also, we remove the need to keep writing the config register over and over and delaying for 150 us each time if sending a stream of data

void RF24::startFastWrite( const void* buf, uint8_t len, const bool multicast){ //TMRh20
void RF24::startFastWrite( const void* buf, uint8_t len, const bool multicast, bool startTx){ //TMRh20

//write_payload( buf,len);
write_payload( buf, len,multicast ? W_TX_PAYLOAD_NO_ACK : W_TX_PAYLOAD ) ;
ce(HIGH);
if(startTx){
ce(HIGH);
}

}

Expand Down Expand Up @@ -993,6 +1009,7 @@ bool RF24::rxFifoFull(){
/****************************************************************************/

bool RF24::txStandBy(){

#if defined (FAILURE_HANDLING) || defined (RF24_LINUX)
uint32_t timeout = millis();
#endif
Expand All @@ -1019,8 +1036,12 @@ bool RF24::txStandBy(){

/****************************************************************************/

bool RF24::txStandBy(uint32_t timeout){
bool RF24::txStandBy(uint32_t timeout, bool startTx){

if(startTx){
stopListening();
ce(HIGH);
}
uint32_t start = millis();

while( ! (read_register(FIFO_STATUS) & _BV(TX_EMPTY)) ){
Expand All @@ -1047,6 +1068,7 @@ bool RF24::txStandBy(uint32_t timeout){
return 1;

}

/****************************************************************************/

void RF24::maskIRQ(bool tx, bool fail, bool rx){
Expand Down
10 changes: 6 additions & 4 deletions RF24.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
#define __RF24_H__

#include "RF24_config.h"
#if (defined (__linux) || defined (LINUX)) && !defined (__ARDUINO_X86__)
#if ( defined (__linux) || defined (LINUX) ) && defined( __arm__ )
#include "RPi/bcm2835.h"
#elif LITTLEWIRE
#include <LittleWireSPI/LittleWireSPI.h>
#elif defined SOFTSPI
#include <DigitalIO.h>
#endif
Expand Down Expand Up @@ -463,7 +465,7 @@ s *
* @return True if transmission is successful
*
*/
bool txStandBy(uint32_t timeout);
bool txStandBy(uint32_t timeout, bool startTx = 0);

/**
* Write an ack payload for the specified pipe
Expand Down Expand Up @@ -543,7 +545,7 @@ s *
* @param multicast Request ACK (0) or NOACK (1)
* @return True if the payload was delivered successfully false if not
*/
void startFastWrite( const void* buf, uint8_t len, const bool multicast );
void startFastWrite( const void* buf, uint8_t len, const bool multicast, bool startTx = 1 );

/**
* Non-blocking write to the open writing pipe
Expand All @@ -566,7 +568,7 @@ s *
*
*/
void startWrite( const void* buf, uint8_t len, const bool multicast );

/**
* This function is mainly used internally to take advantage of the auto payload
* re-use functionality of the chip, but can be beneficial to users as well.
Expand Down
19 changes: 16 additions & 3 deletions RF24_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,29 @@
#define rf24_max(a,b) (a>b?a:b)
#define rf24_min(a,b) (a<b?a:b)

#if (defined (__linux) || defined (linux)) && !defined (__ARDUINO_X86__)
#if ( ( defined (__linux) || defined (linux) ) && defined( __arm__ ) || defined(LITTLEWIRE) )

#if defined(__arm__) && defined(linux)

#define RF24_LINUX
#endif

#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <sys/time.h>
#include <stddef.h>
#include "RPi/bcm2835.h"
#ifdef __arm__
#include "RPi/bcm2835.h"
#endif

// Additional fixes for LittleWire
#if defined(LITTLEWIRE)
#include <LittleWireSPI/LittleWireSPI.h>
#include <LittleWireSPI/avr_fixes.h>
extern LittleWireSPI _SPI;
#endif

// GCC a Arduino Missing
#define _BV(x) (1<<(x))
Expand All @@ -57,7 +70,7 @@
#define printf_P(...)
#endif
#endif

#else //Everything else

#if ARDUINO < 100
Expand Down
Loading

0 comments on commit 3c652ed

Please sign in to comment.