Commit 07eb9f87 authored by TMRh20's avatar TMRh20

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
parent 8077f56a
...@@ -380,7 +380,7 @@ uint8_t RF24::getPayloadSize(void) ...@@ -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 = { ...@@ -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) ...@@ -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
#if defined (ATTINY) # define DI 0 // D0, pin 5 Data In
# define DO 1 // D1, pin 6 Data Out (this is *not* MOSI)
#include "pins_arduino.h" # define USCK 2 // D2, pin 7 Universal Serial Interface clock
# define SS 3 // D3, pin 2 Slave Select
#if defined( __AVR_ATtiny85__ ) #elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
const static uint8_t _CS = PB4; // these depend on the core used (check pins_arduino.h)
const static uint8_t _MOSI = PB1; // this is for jeelabs' one (based on google-code core)
const static uint8_t _MISO = PB0; # define DI 4 // PA6
const static uint8_t _SCK = PB2; # define DO 5 // PA5
#endif # define USCK 6 // PA4
# define SS 3 // PA7
#if 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 #endif
SPIClass SPI; #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
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
...@@ -948,7 +948,7 @@ private: ...@@ -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: ...@@ -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: ...@@ -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
* *
......
...@@ -24,8 +24,15 @@ ...@@ -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 @@ ...@@ -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
...@@ -49,13 +59,13 @@ ...@@ -49,13 +59,13 @@
// Progmem is Arduino-specific // Progmem is Arduino-specific
// Arduino DUE is arm and does not include avr/pgmspace // Arduino DUE is arm and does not include avr/pgmspace
#if defined(ARDUINO) && ! defined(__arm__) #if defined(ARDUINO) && ! defined(__arm__)
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#define PRIPSTR "%S" #define PRIPSTR "%S"
#else #else
#if ! defined(ARDUINO) // This doesn't work on Arduino DUE #if ! defined(ARDUINO) // This doesn't work on Arduino DUE
typedef char const char; typedef char const char;
#else // Fill in pgm_read_byte that is used, but missing from DUE #else // Fill in pgm_read_byte that is used, but missing from DUE
#define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#endif #endif
typedef uint16_t prog_uint16_t; typedef uint16_t prog_uint16_t;
...@@ -65,75 +75,55 @@ typedef char const char; ...@@ -65,75 +75,55 @@ typedef char const char;
#define PROGMEM #define PROGMEM
#define pgm_read_word(p) (*(p)) #define pgm_read_word(p) (*(p))
#define PRIPSTR "%s" #define PRIPSTR "%s"
#endif
// Define _BV for non-Arduino platforms and for Arduino DUE
#if ! defined(ARDUINO) || (defined(ARDUINO) && defined(__arm__))
#define _BV(x) (1<<(x))
#endif #endif
// Stuff that is normally provided by Arduino
#if !defined (ARDUINO)
#include <stdint.h>
#include <stdio.h>
#include <string.h>
extern HardwareSPI SPI;
#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_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06
//#define SPI_CLOCK_DIV64 0x07
#define SPI_MODE0 0x00 // ATTiny support code is from https://github.com/jscrane/RF24
#define SPI_MODE1 0x04
#define SPI_MODE2 0x08
#define SPI_MODE3 0x0C
#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR #include <stdio.h>
#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR #include <Arduino.h>
#include <avr/pgmspace.h>
#define SPI_CLOCK_DIV4 0x00
#define SPI_CLOCK_DIV16 0x01
#define SPI_CLOCK_DIV64 0x02
#define SPI_CLOCK_DIV128 0x03
#define SPI_CLOCK_DIV2 0x04
#define SPI_CLOCK_DIV8 0x05
#define SPI_CLOCK_DIV32 0x06
//#define SPI_CLOCK_DIV64 0x07
#define SPI_MODE0 0x00
#define SPI_MODE1 0x04
#define SPI_MODE2 0x08
#define SPI_MODE3 0x0C
class SPIClass { #define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
public: #define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
inline static byte transfer(byte _data); #define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
static void begin(); // Default
static void end();
static void setDataMode(byte);
static void setClockDivider(byte);
static void setBitOrder(byte);
};
extern SPIClass SPI; class SPIClass {
public:
static byte transfer(byte _data);
byte SPIClass::transfer(byte _data){ // SPI Configuration methods
USIDR = _data; inline static void attachInterrupt();
USISR = _BV(USIOIF); inline static void detachInterrupt(); // Default
while((USISR & _BV(USIOIF)) == 0){ static void begin(); // Default
USICR = _BV(USIWM0) | _BV(USICS1) | _BV(USICLK) | _BV(USITC); static void end();
}
return USIDR;
}
#endif //ATTINY
#endif //Defined Arduino static void setBitOrder(uint8_t);
static void setDataMode(uint8_t);
static void setClockDivider(uint8_t);
};
extern SPIClass SPI;
#endif //ATTiny
#endif // __RF24_CONFIG_H__ #endif // __RF24_CONFIG_H__
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment