From 165c45326e93d7b16f5e1ac72e8c77e5e5f0312c Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Sat, 10 Oct 2020 13:00:32 +0100 Subject: [PATCH 1/2] remove SPI class for ATTiny: provided by ATTinyCore --- RF24.cpp | 40 ------------------- utility/ATTiny/RF24_arch_config.h | 66 +++++++++++++++---------------- utility/ATTiny/spi.h | 55 -------------------------- 3 files changed, 33 insertions(+), 128 deletions(-) delete mode 100644 utility/ATTiny/spi.h diff --git a/RF24.cpp b/RF24.cpp index 962d787e6..159f277bf 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1568,43 +1568,3 @@ void RF24::stopConstCarrier() write_register(RF_SETUP, (read_register(RF_SETUP)) & ~_BV(PLL_LOCK)); ce(LOW); } - -//ATTiny support code pulled in from https://github.com/jscrane/RF24 -#if defined(RF24_TINY) - -void SPIClass::begin() { - // set USCK and DO for output - // set DI for input - #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - DDRB |= (1 << PB2) | (1 << PB1); - DDRB &= ~(1 << PB0); - #elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) - DDRA |= (1 << PA4) | (1 << PA5); - DDRA &= ~(1 << PA6); - #elif defined(__AVR_ATtiny2313__) || defined(__AVR_ATtiny4313__) - DDRB |= (1 << PB7) | (1 << PB6); - DDRB &= ~(1 << PB5); - #elif defined(__AVR_ATtiny861__) - DDRB |= (1 << PB2) | (1 << PB1); - DDRB &= ~(1 << PB0); - #endif // defined(__AVR_ATtiny861__) - USICR = _BV(USIWM0); -} - -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; -} - -void SPIClass::end() {} -void SPIClass::setDataMode(uint8_t mode){} -void SPIClass::setBitOrder(uint8_t bitOrder){} -void SPIClass::setClockDivider(uint8_t rate){} - -#endif diff --git a/utility/ATTiny/RF24_arch_config.h b/utility/ATTiny/RF24_arch_config.h index dc5b0aa42..81fcb9c0b 100644 --- a/utility/ATTiny/RF24_arch_config.h +++ b/utility/ATTiny/RF24_arch_config.h @@ -1,3 +1,4 @@ + /* TMRh20 2015 ATTiny Configuration File @@ -6,41 +7,40 @@ #ifndef __RF24_ARCH_CONFIG_H__ #define __RF24_ARCH_CONFIG_H__ -/*** USER DEFINES: ***/ -//#define FAILURE_HANDLING -//#define MINIMAL -/**********************/ - -#define rf24_max(a, b) (a>b?a:b) -#define rf24_min(a, b) (a - -#else - #include -#endif - -#include - -// Include the header file for SPI functions ( Main SPI code is contained in RF24.cpp for simplicity ) -#include "spi.h" - -#define _SPI SPI - -#ifdef SERIAL_DEBUG - #define IF_SERIAL_DEBUG(x) ({x;}) -#else - #define IF_SERIAL_DEBUG(x) - #if defined(RF24_TINY) - #define printf_P(...) + /*** USER DEFINES: ***/ + //#define FAILURE_HANDLING + //#define MINIMAL + /**********************/ + + #define rf24_max(a,b) (a>b?a:b) + #define rf24_min(a,b) (a + #else + #include + #endif + #include + + #include + + #define _SPI SPI + + #ifdef SERIAL_DEBUG + #define IF_SERIAL_DEBUG(x) ({x;}) + #else + #define IF_SERIAL_DEBUG(x) + #if defined(RF24_TINY) + #define printf_P(...) #endif -#endif - -#include + #endif -#define PRIPSTR "%S" + #include + #define PRIPSTR "%S" + + #endif // __RF24_ARCH_CONFIG_H__ diff --git a/utility/ATTiny/spi.h b/utility/ATTiny/spi.h deleted file mode 100644 index 4cba54d4c..000000000 --- a/utility/ATTiny/spi.h +++ /dev/null @@ -1,55 +0,0 @@ -// ATTiny support code is from https://github.com/jscrane/RF24 - -/** - * @file spi.h - * \cond HIDDEN_SYMBOLS - * Class declaration for SPI helper files - */ - -#include -#include -#include - -#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: - 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; - -/** - * \endcond - */ \ No newline at end of file From 77f22cbd64a84ea8e1cf7cab23b9cdc26e59e204 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Sun, 11 Oct 2020 11:24:03 +0100 Subject: [PATCH 2/2] fix formatting --- utility/ATTiny/RF24_arch_config.h | 62 +++++++++++++++---------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/utility/ATTiny/RF24_arch_config.h b/utility/ATTiny/RF24_arch_config.h index 81fcb9c0b..585d066e5 100644 --- a/utility/ATTiny/RF24_arch_config.h +++ b/utility/ATTiny/RF24_arch_config.h @@ -7,40 +7,38 @@ #ifndef __RF24_ARCH_CONFIG_H__ #define __RF24_ARCH_CONFIG_H__ - /*** USER DEFINES: ***/ - //#define FAILURE_HANDLING - //#define MINIMAL - /**********************/ - - #define rf24_max(a,b) (a>b?a:b) - #define rf24_min(a,b) (a - #else - #include - #endif - #include - - #include - - #define _SPI SPI - - #ifdef SERIAL_DEBUG - #define IF_SERIAL_DEBUG(x) ({x;}) - #else - #define IF_SERIAL_DEBUG(x) - #if defined(RF24_TINY) - #define printf_P(...) +/*** USER DEFINES: ***/ +//#define FAILURE_HANDLING +//#define MINIMAL +/**********************/ + +#define rf24_max(a, b) (a>b?a:b) +#define rf24_min(a, b) (a +#else + #include +#endif + +#include + +#include + +#define _SPI SPI + +#ifdef SERIAL_DEBUG + #define IF_SERIAL_DEBUG(x) ({x;}) +#else + #define IF_SERIAL_DEBUG(x) + #if defined(RF24_TINY) + #define printf_P(...) #endif - #endif +#endif + +#include - #include - #define PRIPSTR "%S" - - +#define PRIPSTR "%S" #endif // __RF24_ARCH_CONFIG_H__