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:
@@ -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_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_3,
|
||||
};
|
||||
|
||||
#if !defined (MINIMAL)
|
||||
void RF24::printDetails(void)
|
||||
{
|
||||
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 (ATTINY)
|
||||
|
||||
#include "pins_arduino.h"
|
||||
|
||||
#if defined( __AVR_ATtiny85__ )
|
||||
const static uint8_t _CS = PB4;
|
||||
const static uint8_t _MOSI = PB1;
|
||||
const static uint8_t _MISO = PB0;
|
||||
const static uint8_t _SCK = PB2;
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
|
||||
// see http://gammon.com.au/spi
|
||||
# define DI 0 // D0, pin 5 Data In
|
||||
# define DO 1 // D1, pin 6 Data Out (this is *not* MOSI)
|
||||
# define USCK 2 // D2, pin 7 Universal Serial Interface clock
|
||||
# define SS 3 // D3, pin 2 Slave Select
|
||||
#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
|
||||
// these depend on the core used (check pins_arduino.h)
|
||||
// this is for jeelabs' one (based on google-code core)
|
||||
# define DI 4 // PA6
|
||||
# define DO 5 // PA5
|
||||
# define USCK 6 // PA4
|
||||
# define SS 3 // PA7
|
||||
#endif
|
||||
|
||||
#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
|
||||
|
||||
SPIClass SPI;
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
|
||||
|
||||
void SPIClass::begin() {
|
||||
|
||||
pinMode(_SCK, OUTPUT);
|
||||
pinMode(_MOSI, OUTPUT);
|
||||
pinMode(_MISO,INPUT);
|
||||
digitalWrite(SS, HIGH);
|
||||
pinMode(USCK, OUTPUT);
|
||||
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::setClockDivider(byte rate){}
|
||||
void SPIClass::end() {}
|
||||
void SPIClass::setDataMode(uint8_t mode){}
|
||||
void SPIClass::setBitOrder(uint8_t bitOrder){}
|
||||
void SPIClass::setClockDivider(uint8_t rate){}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
@@ -1018,7 +1018,7 @@ private:
|
||||
* - Extended timeout periods have been added to aid in noisy or otherwise unreliable environments
|
||||
* - Delays have been removed where possible to ensure maximum efficiency
|
||||
* - 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.
|
||||
*
|
||||
* 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)
|
||||
* - 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
|
||||
* hardware SS/CSN pins.
|
||||
* - ATTiny boards (Not fully tested) Note: Do not include SPI.h. The SPI functions for ATTiny are already included.
|
||||
* hardware SS/CSN pins as extended SPI methods are used.
|
||||
* 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
|
||||
*
|
||||
|
||||
+54
-64
@@ -24,8 +24,15 @@
|
||||
//#define MINIMAL
|
||||
|
||||
// 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
|
||||
@@ -33,6 +40,9 @@
|
||||
#define IF_SERIAL_DEBUG(x) ({x;})
|
||||
#else
|
||||
#define IF_SERIAL_DEBUG(x)
|
||||
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)
|
||||
#define printf_P(...)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Avoid spurious warnings
|
||||
@@ -49,13 +59,13 @@
|
||||
// Progmem is Arduino-specific
|
||||
// Arduino DUE is arm and does not include avr/pgmspace
|
||||
#if defined(ARDUINO) && ! defined(__arm__)
|
||||
#include <avr/pgmspace.h>
|
||||
#define PRIPSTR "%S"
|
||||
#include <avr/pgmspace.h>
|
||||
#define PRIPSTR "%S"
|
||||
#else
|
||||
#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
|
||||
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
|
||||
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
|
||||
#endif
|
||||
|
||||
typedef uint16_t prog_uint16_t;
|
||||
@@ -65,75 +75,55 @@ typedef char const char;
|
||||
#define PROGMEM
|
||||
#define pgm_read_word(p) (*(p))
|
||||
#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
|
||||
// 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
|
||||
#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
|
||||
#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
|
||||
#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
|
||||
|
||||
|
||||
|
||||
class SPIClass {
|
||||
public:
|
||||
inline static byte transfer(byte _data);
|
||||
// ATTiny support code is from https://github.com/jscrane/RF24
|
||||
|
||||
static void begin(); // Default
|
||||
static void end();
|
||||
#if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
|
||||
#include <stdio.h>
|
||||
#include <Arduino.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
static void setDataMode(byte);
|
||||
static void setClockDivider(byte);
|
||||
static void setBitOrder(byte);
|
||||
};
|
||||
#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
|
||||
|
||||
extern SPIClass SPI;
|
||||
#define SPI_MODE0 0x00
|
||||
#define SPI_MODE1 0x04
|
||||
#define SPI_MODE2 0x08
|
||||
#define SPI_MODE3 0x0C
|
||||
|
||||
byte SPIClass::transfer(byte _data){
|
||||
#define SPI_MODE_MASK 0x0C // CPOL = bit 3, CPHA = bit 2 on SPCR
|
||||
#define SPI_CLOCK_MASK 0x03 // SPR1 = bit 1, SPR0 = bit 0 on SPCR
|
||||
#define SPI_2XCLOCK_MASK 0x01 // SPI2X = bit 0 on SPSR
|
||||
|
||||
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
|
||||
class SPIClass {
|
||||
public:
|
||||
static byte transfer(byte _data);
|
||||
|
||||
// SPI Configuration methods
|
||||
|
||||
inline static void attachInterrupt();
|
||||
inline static void detachInterrupt(); // Default
|
||||
|
||||
static void begin(); // Default
|
||||
static void end();
|
||||
|
||||
static void setBitOrder(uint8_t);
|
||||
static void setDataMode(uint8_t);
|
||||
static void setClockDivider(uint8_t);
|
||||
};
|
||||
extern SPIClass SPI;
|
||||
|
||||
#endif //ATTiny
|
||||
#endif // __RF24_CONFIG_H__
|
||||
|
||||
|
||||
Reference in New Issue
Block a user