Commit 56b7711e authored by TMRh20's avatar TMRh20

#24 Add softSPI supp, fix SPI_UART

- Added softSPI support for https://github.com/greiman/DigitalIO library
- Updated SPI_UART code to allow use at the same time as the SPI library
parent 3f4a1cbc
......@@ -19,7 +19,7 @@ void RF24::csn(bool mode)
// divider of 4 is the minimum we want.
// CLK:BUS 8Mhz:2Mhz, 16Mhz:4Mhz, or 20Mhz:5Mhz
#ifdef ARDUINO
#if ( !defined(RF24_TINY) && !defined (__arm__) ) || defined (CORE_TEENSY)
#if ( !defined(RF24_TINY) && !defined (__arm__) && !defined (SOFTSPI)) || defined (CORE_TEENSY)
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2);
......@@ -38,7 +38,7 @@ void RF24::csn(bool mode)
}
else {
PORTB &= ~(1<<PINB2); // SCK->CSN LOW
delayMicroseconds(20); // allow csn to settle
delayMicroseconds(11); // allow csn to settle
}
}
#else if !defined (__arm__) || defined (CORE_TEENSY)
......
......@@ -16,7 +16,9 @@
#define __RF24_H__
#include <RF24_config.h>
#if defined SOFTSPI
#include <DigitalIO.h>
#endif
/**
* Power Amplifier level.
*
......@@ -45,6 +47,12 @@ typedef enum { RF24_CRC_DISABLED = 0, RF24_CRC_8, RF24_CRC_16 } rf24_crclength_e
class RF24
{
private:
#ifdef SOFTSPI
SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, SPI_MODE> spi;
#endif
#ifdef SPI_UART
SPIUARTClass spi;
#endif
uint8_t ce_pin; /**< "Chip Enable" pin, activates the RX or TX role */
uint8_t csn_pin; /**< SPI Chip select */
bool p_variant; /* False for RF24L01 and true for RF24L01P */
......
......@@ -25,6 +25,7 @@
//#define SERIAL_DEBUG
//#define MINIMAL
#define SPI_UART
//#define SOFTSPI
/**********************/
// Define _BV for non-Arduino platforms and for Arduino DUE
......@@ -34,6 +35,16 @@
#else
#if defined SPI_UART
#include <SPI_UART.h>
#define SPI spi
#elif defined SOFTSPI
// change these pins to your liking
//
const uint8_t SOFT_SPI_MISO_PIN = 16;
const uint8_t SOFT_SPI_MOSI_PIN = 15;
const uint8_t SOFT_SPI_SCK_PIN = 14;
const uint8_t SPI_MODE = 0;
#define SPI spi
#else
#include <SPI.h>
#endif
......
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