Merge branch 'Due'

This commit is contained in:
Kristian Lauszus 2014-03-06 21:45:01 +01:00
commit 2bb6c970b0
5 changed files with 102 additions and 17 deletions

View file

@ -57,7 +57,7 @@ Documentation for the library can be found at the following link: <http://felis.
By default serial debugging is disabled. To turn it on simply change ```ENABLE_UHS_DEBUGGING``` to 1 in [settings.h](settings.h) like so: By default serial debugging is disabled. To turn it on simply change ```ENABLE_UHS_DEBUGGING``` to 1 in [settings.h](settings.h) like so:
``` ```C++
#define ENABLE_UHS_DEBUGGING 1 #define ENABLE_UHS_DEBUGGING 1
``` ```
@ -66,8 +66,10 @@ By default serial debugging is disabled. To turn it on simply change ```ENABLE_U
Currently the following boards are supported by the library: Currently the following boards are supported by the library:
* All official Arduino AVR boards (Uno, Duemilanove, Mega, Mega 2560, Mega ADK, Leonardo etc.) * All official Arduino AVR boards (Uno, Duemilanove, Mega, Mega 2560, Mega ADK, Leonardo etc.)
* Teensy (Teensy++ 1.0, Teensy 2.0, Teensy++ 2.0, and Teensy 3.0) * If you are using the Arduino Due, then you must include the Arduino SPI library like so: ```#include <SPI.h>``` in your .ino file.
* Note if you are using the Teensy 3.0 you should download this SPI library as well: <https://github.com/xxxajk/spi4teensy3>. You should then add ```#include <spi4teensy3.h>``` to your .ino file. * Arduino Due
* Teensy (Teensy++ 1.0, Teensy 2.0, Teensy++ 2.0, and Teensy 3.x)
* Note if you are using the Teensy 3.x you should download this SPI library as well: <https://github.com/xxxajk/spi4teensy3>. You should then add ```#include <spi4teensy3.h>``` to your .ino file.
* Balanduino * Balanduino
* Sanguino * Sanguino
* Black Widdow * Black Widdow
@ -203,7 +205,7 @@ The [Wii](Wii.cpp) library support the Wiimote, but also the Nunchuch and Motion
First you have to pair with the controller, this is done automatically by the library if you create the instance like so: First you have to pair with the controller, this is done automatically by the library if you create the instance like so:
``` ```C++
WII Wii(&Btd, PAIR); WII Wii(&Btd, PAIR);
``` ```
@ -211,7 +213,7 @@ And then press 1 & 2 at once on the Wiimote or press sync if you are using a Wii
After that you can simply create the instance like so: After that you can simply create the instance like so:
``` ```C++
WII Wii(&Btd); WII Wii(&Btd);
``` ```

View file

@ -24,7 +24,7 @@ typedef MAX3421e<P53, P54> MAX3421E; // Arduino Mega ADK
#elif defined(ARDUINO_AVR_BALANDUINO) #elif defined(ARDUINO_AVR_BALANDUINO)
typedef MAX3421e<P20, P19> MAX3421E; // Balanduino typedef MAX3421e<P20, P19> MAX3421E; // Balanduino
#else #else
typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo etc.) or Teensy 2.0 and 3.0 typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.) or Teensy 2.0 and 3.0
#endif #endif
/* Common setup data constant combinations */ /* Common setup data constant combinations */

View file

@ -749,11 +749,13 @@ public:
#endif // __AVR__ #endif // __AVR__
#if defined(__arm__) && defined(CORE_TEENSY) #if defined(__arm__)
// pointers are 32 bits on ARM // pointers are 32 bits on ARM
#define pgm_read_pointer(p) pgm_read_dword(p) #define pgm_read_pointer(p) pgm_read_dword(p)
#if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__))
#include "core_pins.h" #include "core_pins.h"
#include "avr_emulation.h" #include "avr_emulation.h"
@ -819,6 +821,59 @@ MAKE_PIN(P33, CORE_PIN33_PORTREG, CORE_PIN33_BIT, CORE_PIN33_CONFIG);
#undef MAKE_PIN #undef MAKE_PIN
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
// SetDirRead:
// Disable interrupts
// Disable the pull up resistor
// Set to INPUT
// Enable PIO
// SetDirWrite:
// Disable interrupts
// Disable the pull up resistor
// Set to OUTPUT
// Enable PIO
#define MAKE_PIN(className, pio, pinMask) \
class className { \
public: \
static void Set() { \
pio->PIO_SODR = pinMask; \
} \
static void Clear() { \
pio->PIO_CODR = pinMask; \
} \
static void SetDirRead() { \
pio->PIO_IDR = pinMask ; \
pio->PIO_PUDR = pinMask; \
pio->PIO_ODR = pinMask; \
pio->PIO_PER = pinMask; \
} \
static void SetDirWrite() { \
pio->PIO_IDR = pinMask ; \
pio->PIO_PUDR = pinMask; \
pio->PIO_OER = pinMask; \
pio->PIO_PER = pinMask; \
} \
static uint8_t IsSet() { \
return pio->PIO_PDSR & pinMask; \
} \
};
MAKE_PIN(P9, PIOC, PIO_PC21); // INT
MAKE_PIN(P10, PIOC, PIO_PC29); // SS
MAKE_PIN(P74, PIOA, PIO_PA25); // MISO
MAKE_PIN(P75, PIOA, PIO_PA26); // MOSI
MAKE_PIN(P76, PIOA, PIO_PA27); // CLK
#undef MAKE_PIN
#else
#error "Please define board in avrpins.h"
#endif
#endif // __arm__ #endif // __arm__
#endif //_avrpins_h_ #endif //_avrpins_h_

View file

@ -68,7 +68,6 @@
// No user serviceable parts below this line. // No user serviceable parts below this line.
// DO NOT change anything below here unless you are a developer! // DO NOT change anything below here unless you are a developer!
// When will we drop support for the older bug-ridden stuff?
#if defined(ARDUINO) && ARDUINO >=100 #if defined(ARDUINO) && ARDUINO >=100
#include <Arduino.h> #include <Arduino.h>
#else #else
@ -79,7 +78,7 @@
#define F(str) (str) #define F(str) (str)
#endif #endif
#ifdef __GNUC__ #if defined(__GNUC__) && defined(__AVR__)
#ifndef GCC_VERSION #ifndef GCC_VERSION
#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) #define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
#endif #endif
@ -110,10 +109,14 @@
#define XMEM_RELEASE_SPI() (void(0)) #define XMEM_RELEASE_SPI() (void(0))
#endif #endif
#if defined(__MK20DX128__) || defined(__MK20DX256__) #if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__))
#define USING_SPI4TEENSY3 USE_SPI4TEENSY3 #define USING_SPI4TEENSY3 USE_SPI4TEENSY3
#else #else
#define USING_SPI4TEENSY3 0 #define USING_SPI4TEENSY3 0
#endif #endif
#if defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
#include <SPI.h> // Use the Arduino SPI library for the Arduino Due
#endif
#endif /* SETTINGS_H */ #endif /* SETTINGS_H */

View file

@ -29,9 +29,8 @@ e-mail : support@circuitsathome.com
/* 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 {
#if USING_SPI4TEENSY3
public: public:
#if USING_SPI4TEENSY3
static void init() { static void init() {
// spi4teensy3 inits everything for us, except /SS // spi4teensy3 inits everything for us, except /SS
// CLK, MOSI and MISO are hard coded for now. // CLK, MOSI and MISO are hard coded for now.
@ -40,10 +39,14 @@ public:
SPI_SS::SetDirWrite(); SPI_SS::SetDirWrite();
SPI_SS::Set(); SPI_SS::Set();
} }
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
static void init() {
SPI_SS::SetDirWrite();
SPI_SS::Set();
SPI.begin();
SPI.setClockDivider(BOARD_SPI_DEFAULT_SS, 4); // Set speed to 84MHz/4=21MHz - the MAX3421E can handle up to 26MHz
}
#else #else
public:
static void init() { static void init() {
//uint8_t tmp; //uint8_t tmp;
SPI_CLK::SetDirWrite(); SPI_CLK::SetDirWrite();
@ -67,8 +70,10 @@ typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi; typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi;
#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
typedef SPi< Pb7, Pb5, Pb6, Pb4 > spi; typedef SPi< Pb7, Pb5, Pb6, Pb4 > spi;
#elif defined(__MK20DX128__) || defined(__MK20DX256__) #elif defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__))
typedef SPi< P13, P11, P12, P10 > spi; typedef SPi< P13, P11, P12, P10 > spi;
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
typedef SPi< P76, P75, P74, P10 > spi;
#else #else
#error "No SPI entry in usbhost.h" #error "No SPI entry in usbhost.h"
#endif #endif
@ -130,6 +135,9 @@ 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__)
SPI.transfer(reg | 0x02);
SPI.transfer(data);
#else #else
SPDR = (reg | 0x02); SPDR = (reg | 0x02);
while(!(SPSR & (1 << SPIF))); while(!(SPSR & (1 << SPIF)));
@ -151,6 +159,13 @@ 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__)
SPI.transfer(reg | 0x02);
while(nbytes) {
SPI.transfer(*data_p);
nbytes--;
data_p++; // advance data pointer
}
#else #else
SPDR = (reg | 0x02); //set WR bit and send register number SPDR = (reg | 0x02); //set WR bit and send register number
while(nbytes) { while(nbytes) {
@ -186,6 +201,10 @@ 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__)
SPI.transfer(reg);
uint8_t rv = SPI.transfer(0);
SPI_SS::Set();
#else #else
SPDR = reg; SPDR = reg;
while(!(SPSR & (1 << SPIF))); while(!(SPSR & (1 << SPIF)));
@ -208,6 +227,12 @@ 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__)
SPI.transfer(reg);
while(nbytes) {
*data_p++ = SPI.transfer(0);
nbytes--;
}
#else #else
SPDR = reg; SPDR = reg;
while(!(SPSR & (1 << SPIF))); //wait while(!(SPSR & (1 << SPIF))); //wait