Merge pull request #115 from sieren/master

Added support for RedBearLab nRF51822 Board
This commit is contained in:
Kristian Sloth Lauszus 2014-11-23 23:55:09 -08:00
commit 3ba1c82cf4
4 changed files with 70 additions and 6 deletions

View file

@ -99,6 +99,8 @@ Currently the following boards are supported by the library:
* Balanduino * Balanduino
* Sanguino * Sanguino
* Black Widdow * Black Widdow
* RedBearLab nRF51822
* If you are using the RedBearLab nRF51822, then you must include the RedBearLab SPI library like so: ```#include <SPI.h>``` in your .ino file.
The following boards need to be activated manually in [settings.h](settings.h): The following boards need to be activated manually in [settings.h](settings.h):

View file

@ -961,6 +961,58 @@ MAKE_PIN(P78, PIOB, PIO_PB23); // Unconnected
#undef MAKE_PIN #undef MAKE_PIN
#elif defined(RBL_NRF51822)
#define MAKE_PIN(className, pin) \
class className { \
public: \
static void Set() { \
nrf_gpio_pin_set(pin); \
} \
static void Clear() { \
nrf_gpio_pin_clear(pin); \
} \
static void SetDirRead() { \
nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \
} \
static void SetDirWrite() { \
nrf_gpio_cfg_output(pin); \
} \
static uint8_t IsSet() { \
return (uint8_t)nrf_gpio_pin_read(pin); \
} \
};
// See: pin_transform.c in RBL nRF51822 SDK
MAKE_PIN(P0, Pin_nRF51822_to_Arduino(D0));
MAKE_PIN(P1, Pin_nRF51822_to_Arduino(D1));
MAKE_PIN(P2, Pin_nRF51822_to_Arduino(D2));
MAKE_PIN(P3, Pin_nRF51822_to_Arduino(D3));
MAKE_PIN(P4, Pin_nRF51822_to_Arduino(D4));
MAKE_PIN(P5, Pin_nRF51822_to_Arduino(D5));
MAKE_PIN(P6, Pin_nRF51822_to_Arduino(D6));
MAKE_PIN(P7, Pin_nRF51822_to_Arduino(D7));
MAKE_PIN(P8, Pin_nRF51822_to_Arduino(D8));
MAKE_PIN(P9, Pin_nRF51822_to_Arduino(D9)); // INT
MAKE_PIN(P10, Pin_nRF51822_to_Arduino(D10)); // SS
MAKE_PIN(P11, Pin_nRF51822_to_Arduino(D11));
MAKE_PIN(P12, Pin_nRF51822_to_Arduino(D12));
MAKE_PIN(P13, Pin_nRF51822_to_Arduino(D13));
MAKE_PIN(P14, Pin_nRF51822_to_Arduino(D14));
MAKE_PIN(P15, Pin_nRF51822_to_Arduino(D15));
MAKE_PIN(P17, Pin_nRF51822_to_Arduino(D17)); // MISO
MAKE_PIN(P18, Pin_nRF51822_to_Arduino(D18)); // MOSI
MAKE_PIN(P16, Pin_nRF51822_to_Arduino(D16)); // CLK
MAKE_PIN(P19, Pin_nRF51822_to_Arduino(D19));
MAKE_PIN(P20, Pin_nRF51822_to_Arduino(D20));
MAKE_PIN(P21, Pin_nRF51822_to_Arduino(D21));
MAKE_PIN(P22, Pin_nRF51822_to_Arduino(D22));
MAKE_PIN(P23, Pin_nRF51822_to_Arduino(D23));
MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24));
#undef MAKE_PIN
#else #else
#error "Please define board in avrpins.h" #error "Please define board in avrpins.h"

View file

@ -137,8 +137,8 @@ e-mail : support@circuitsathome.com
#define USING_SPI4TEENSY3 0 #define USING_SPI4TEENSY3 0
#endif #endif
#if defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) #if (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822)
#include <SPI.h> // Use the Arduino SPI library for the Arduino Due #include <SPI.h> // Use the Arduino SPI library for the Arduino Due and RedBearLab nRF51822
#endif #endif
#endif /* SETTINGS_H */ #endif /* SETTINGS_H */

View file

@ -27,6 +27,7 @@ e-mail : support@circuitsathome.com
#include <sys/types.h> #include <sys/types.h>
#endif #endif
/* SPI initialization */ /* SPI initialization */
template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_SS > class SPi { template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_SS > class SPi {
public: public:
@ -46,6 +47,13 @@ public:
SPI.begin(); SPI.begin();
SPI.setClockDivider(4); // Set speed to 84MHz/4=21MHz - the MAX3421E can handle up to 26MHz SPI.setClockDivider(4); // Set speed to 84MHz/4=21MHz - the MAX3421E can handle up to 26MHz
} }
#elif defined(RBL_NRF51822)
static void init() {
SPI_SS::SetDirWrite();
SPI_SS::Set();
SPI.begin();
// SPI.setFrequency(SPI_FREQUENCY_8M);
}
#else #else
static void init() { static void init() {
//uint8_t tmp; //uint8_t tmp;
@ -74,6 +82,8 @@ typedef SPi< Pb7, Pb5, Pb6, Pb4 > spi;
typedef SPi< P13, P11, P12, P10 > spi; typedef SPi< P13, P11, P12, P10 > spi;
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
typedef SPi< P76, P75, P74, P10 > spi; typedef SPi< P76, P75, P74, P10 > spi;
#elif defined(RBL_NRF51822)
typedef SPi< P16, P18, P17, P10 > spi;
#else #else
#error "No SPI entry in usbhost.h" #error "No SPI entry in usbhost.h"
#endif #endif
@ -135,7 +145,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) {
c[0] = reg | 0x02; c[0] = reg | 0x02;
c[1] = data; c[1] = data;
spi4teensy3::send(c, 2); spi4teensy3::send(c, 2);
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) #elif (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822)
SPI.transfer(reg | 0x02); SPI.transfer(reg | 0x02);
SPI.transfer(data); SPI.transfer(data);
#else #else
@ -159,7 +169,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t*
spi4teensy3::send(reg | 0x02); spi4teensy3::send(reg | 0x02);
spi4teensy3::send(data_p, nbytes); spi4teensy3::send(data_p, nbytes);
data_p += nbytes; data_p += nbytes;
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) #elif (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822)
SPI.transfer(reg | 0x02); SPI.transfer(reg | 0x02);
while(nbytes) { while(nbytes) {
SPI.transfer(*data_p); SPI.transfer(*data_p);
@ -201,7 +211,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) {
spi4teensy3::send(reg); spi4teensy3::send(reg);
uint8_t rv = spi4teensy3::receive(); uint8_t rv = spi4teensy3::receive();
SPI_SS::Set(); SPI_SS::Set();
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) #elif (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822)
SPI.transfer(reg); SPI.transfer(reg);
uint8_t rv = SPI.transfer(0); uint8_t rv = SPI.transfer(0);
SPI_SS::Set(); SPI_SS::Set();
@ -227,7 +237,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t*
spi4teensy3::send(reg); spi4teensy3::send(reg);
spi4teensy3::receive(data_p, nbytes); spi4teensy3::receive(data_p, nbytes);
data_p += nbytes; data_p += nbytes;
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) #elif (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822)
SPI.transfer(reg); SPI.transfer(reg);
while(nbytes) { while(nbytes) {
*data_p++ = SPI.transfer(0); *data_p++ = SPI.transfer(0);