ATTiny support fr jscrane fork tested and working

ATTiny support pulled in from https://github.com/jscrane/RF24
- SPI support for ATTiny is included with the library. Do NOT include
SPI.h with tiny.

Pin info etc can be found at:
http://programmablehardware.blogspot.ca/2013/09/rf24-with-attiny84.html

ATTiny 85 Example:
RF24 radio(4,3);    // CE: 4  CS: 3
This commit is contained in:
TMRh20
2014-04-09 10:53:47 -06:00
parent 8077f56a7f
commit 07eb9f8749
3 changed files with 97 additions and 103 deletions
+36 -35
View File
@@ -380,7 +380,7 @@ uint8_t RF24::getPayloadSize(void)
/****************************************************************************/ /****************************************************************************/
#if !defined (MINIMAL)
static const char rf24_datarate_e_str_0[] PROGMEM = "1MBPS"; static const char rf24_datarate_e_str_0[] PROGMEM = "1MBPS";
static const char rf24_datarate_e_str_1[] PROGMEM = "2MBPS"; static const char rf24_datarate_e_str_1[] PROGMEM = "2MBPS";
@@ -414,7 +414,7 @@ static const char * const rf24_pa_dbm_e_str_P[] PROGMEM = {
rf24_pa_dbm_e_str_2, rf24_pa_dbm_e_str_2,
rf24_pa_dbm_e_str_3, rf24_pa_dbm_e_str_3,
}; };
#if !defined (MINIMAL)
void RF24::printDetails(void) void RF24::printDetails(void)
{ {
print_status(get_status()); print_status(get_status());
@@ -1210,50 +1210,51 @@ void RF24::setRetries(uint8_t delay, uint8_t count)
} }
//ATTiny support code pulled in from https://github.com/jscrane/RF24
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
// see http://gammon.com.au/spi
# define DI 0 // D0, pin 5 Data In
#if defined (ATTINY) # define DO 1 // D1, pin 6 Data Out (this is *not* MOSI)
# define USCK 2 // D2, pin 7 Universal Serial Interface clock
#include "pins_arduino.h" # define SS 3 // D3, pin 2 Slave Select
#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
#if defined( __AVR_ATtiny85__ ) // these depend on the core used (check pins_arduino.h)
const static uint8_t _CS = PB4; // this is for jeelabs' one (based on google-code core)
const static uint8_t _MOSI = PB1; # define DI 4 // PA6
const static uint8_t _MISO = PB0; # define DO 5 // PA5
const static uint8_t _SCK = PB2; # define USCK 6 // PA4
# define SS 3 // PA7
#endif #endif
#if defined( __AVR_ATtiny84__ ) #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
const static uint8_t _CS = 3;
const static uint8_t _MOSI = 5;
const static uint8_t _MISO = 4;
const static uint8_t _SCK = 6;
#endif
SPIClass SPI;
void SPIClass::begin() { void SPIClass::begin() {
pinMode(_SCK, OUTPUT); digitalWrite(SS, HIGH);
pinMode(_MOSI, OUTPUT); pinMode(USCK, OUTPUT);
pinMode(_MISO,INPUT); pinMode(DO, OUTPUT);
pinMode(SS, OUTPUT);
pinMode(DI, INPUT);
USICR = _BV(USIWM0);
digitalWrite(_MISO,HIGH);
digitalWrite(_SCK, LOW);
digitalWrite(_MOSI, LOW);
} }
void SPIClass::end() { byte SPIClass::transfer(byte b) {
USIDR = b;
USISR = _BV(USIOIF);
do
USICR = _BV(USIWM0) | _BV(USICS1) | _BV(USICLK) | _BV(USITC);
while ((USISR & _BV(USIOIF)) == 0);
return USIDR;
pinMode(_SCK, INPUT);
pinMode(_MOSI, INPUT);
pinMode(_MISO,INPUT);
} }
void SPIClass::setDataMode(byte mode){} void SPIClass::end() {}
void SPIClass::setClockDivider(byte rate){} void SPIClass::setDataMode(uint8_t mode){}
void SPIClass::setBitOrder(uint8_t bitOrder){}
void SPIClass::setClockDivider(uint8_t rate){}
#endif #endif
+7 -4
View File
@@ -948,7 +948,7 @@ private:
*/ */
/** /**
* @example pingpair_dyn.pde * @example pingpair_dyn.ino
* *
* This is an example of how to use payloads of a varying (dynamic) size. * This is an example of how to use payloads of a varying (dynamic) size.
*/ */
@@ -1018,7 +1018,7 @@ private:
* - Extended timeout periods have been added to aid in noisy or otherwise unreliable environments * - Extended timeout periods have been added to aid in noisy or otherwise unreliable environments
* - Delays have been removed where possible to ensure maximum efficiency * - Delays have been removed where possible to ensure maximum efficiency
* - Full Due support with extended SPI functions * - Full Due support with extended SPI functions
* - Initial ATTiny support added (Untested) * - ATTiny 24/44/84 25/45/85 now supported.
* - More! See the links below and class documentation for more info. * - More! See the links below and class documentation for more info.
* *
* If issues are discovered with the documentation, please report them here: <a href="https://github.com/TMRh20/tmrh20.github.io/issues"> here</a> * If issues are discovered with the documentation, please report them here: <a href="https://github.com/TMRh20/tmrh20.github.io/issues"> here</a>
@@ -1042,8 +1042,11 @@ private:
* - ATMega 328 based boards (Uno, Nano, etc) * - ATMega 328 based boards (Uno, Nano, etc)
* - Mega Boards (1280, 2560, etc) * - Mega Boards (1280, 2560, etc)
* - ARM based boards (Arduino Due) Note: Do not include printf.h or use printf begin. This functionality is already present. Must use one of the * - ARM based boards (Arduino Due) Note: Do not include printf.h or use printf begin. This functionality is already present. Must use one of the
* hardware SS/CSN pins. * hardware SS/CSN pins as extended SPI methods are used.
* - ATTiny boards (Not fully tested) Note: Do not include SPI.h. The SPI functions for ATTiny are already included. * Initial Due support taken from https://github.com/mcrosson/RF24/tree/due
* - ATTiny board support added from https://github.com/jscrane/RF24
* Note: ATTiny support is built into the library. Do not include SPI.h.
* See <a href="http://programmablehardware.blogspot.ca/2013/09/rf24-with-attiny84.html">here </a>for wiring/pin info.
* *
* @section More More Information * @section More More Information
* *
+27 -37
View File
@@ -24,8 +24,15 @@
//#define MINIMAL //#define MINIMAL
// Define _BV for non-Arduino platforms and for Arduino DUE // Define _BV for non-Arduino platforms and for Arduino DUE
#if defined (ARDUINO)
#include <SPI.h>
#else
#include <stdint.h>
#include <stdio.h>
#include <string.h>
extern HardwareSPI SPI;
#define _BV(x) (1<<(x))
#endif
#undef SERIAL_DEBUG #undef SERIAL_DEBUG
@@ -33,6 +40,9 @@
#define IF_SERIAL_DEBUG(x) ({x;}) #define IF_SERIAL_DEBUG(x) ({x;})
#else #else
#define IF_SERIAL_DEBUG(x) #define IF_SERIAL_DEBUG(x)
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)
#define printf_P(...)
#endif
#endif #endif
// Avoid spurious warnings // Avoid spurious warnings
@@ -68,24 +78,13 @@ typedef char const char;
#endif #endif
// Define _BV for non-Arduino platforms and for Arduino DUE
#if ! defined(ARDUINO) || (defined(ARDUINO) && defined(__arm__))
#define _BV(x) (1<<(x))
#endif
// Stuff that is normally provided by Arduino
#if !defined (ARDUINO)
#include <stdint.h> // ATTiny support code is from https://github.com/jscrane/RF24
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <Arduino.h>
extern HardwareSPI SPI; #include <avr/pgmspace.h>
#define _BV(x) (1<<(x))
#else
#if !defined( __AVR_ATtiny85__ ) || defined( __AVR_ATtiny84__)
#include <SPI.h>
#else
#define ATTINY
#define SPI_CLOCK_DIV4 0x00 #define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01 #define SPI_CLOCK_DIV16 0x01
@@ -109,31 +108,22 @@ typedef char const char;
class SPIClass { class SPIClass {
public: public:
inline static byte transfer(byte _data); static byte transfer(byte _data);
// SPI Configuration methods
inline static void attachInterrupt();
inline static void detachInterrupt(); // Default
static void begin(); // Default static void begin(); // Default
static void end(); static void end();
static void setDataMode(byte); static void setBitOrder(uint8_t);
static void setClockDivider(byte); static void setDataMode(uint8_t);
static void setBitOrder(byte); static void setClockDivider(uint8_t);
}; };
extern SPIClass SPI; extern SPIClass SPI;
byte SPIClass::transfer(byte _data){ #endif //ATTiny
USIDR = _data;
USISR = _BV(USIOIF);
while((USISR & _BV(USIOIF)) == 0){
USICR = _BV(USIWM0) | _BV(USICS1) | _BV(USICLK) | _BV(USITC);
}
return USIDR;
}
#endif //ATTINY
#endif //Defined Arduino
#endif // __RF24_CONFIG_H__ #endif // __RF24_CONFIG_H__