Merge pull request #142 from felis/Galileo

Added support for Intel Galileo 1 & 2 and Intel Edison
This commit is contained in:
Kristian Sloth Lauszus 2015-04-07 15:41:50 +02:00
commit fb95a7f383
6 changed files with 92 additions and 15 deletions

View file

@ -95,8 +95,9 @@ By default serial debugging is disabled. To turn it on simply change ```ENABLE_U
Currently the following boards are supported by the library:
* All official Arduino AVR boards (Uno, Duemilanove, Mega, Mega 2560, Mega ADK, Leonardo etc.)
* Arduino Due
* If you are using the Arduino Due, then you must include the Arduino SPI library like so: ```#include <SPI.h>``` in your .ino file.
* Arduino Due, Intel Galileo, Intel Galileo 2, and Intel Edison
* If you are using the Arduino Due, Intel Galileo or Intel Galileo 2, then you must include the Arduino SPI library like so: ```#include <SPI.h>``` in your .ino file.
* Note that the Intel Galileo uses pin 2 and 3 as INT and SS pin respectively by default, so some modifications to the shield are needed. See the "Interface modifications" section in the [hardware manual](https://www.circuitsathome.com/usb-host-shield-hardware-manual) for more information.
* 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

View file

@ -37,8 +37,10 @@ typedef MAX3421e<P9, P8> MAX3421E; // Teensy++ 1.0 and 2.0
typedef MAX3421e<P53, P54> MAX3421E; // Arduino Mega ADK
#elif defined(ARDUINO_AVR_BALANDUINO)
typedef MAX3421e<P20, P19> MAX3421E; // Balanduino
#elif defined(__ARDUINO_X86__) && PLATFORM_ID == 0x06
typedef MAX3421e<P3, P2> MAX3421E; // The Intel Galileo supports much faster read and write speed at pin 2 and 3
#else
typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.) or Teensy 2.0 and 3.0
typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.0
#endif
/* Common setup data constant combinations */

View file

@ -763,9 +763,7 @@ public:
#endif // Arduino pin definitions
#endif // __AVR__
#if defined(__arm__)
#elif defined(__arm__)
// pointers are 32 bits on ARM
#define pgm_read_pointer(p) pgm_read_dword(p)
@ -1017,9 +1015,70 @@ MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24));
#endif
#endif // __arm__
#elif defined(__ARDUINO_X86__) // Intel Galileo, Intel Galileo 2 and Intel Edison
#if defined(__MIPSEL__)
#include <avr/pgmspace.h>
// Pointers are 32 bits on x86
#define pgm_read_pointer(p) pgm_read_dword(p)
#if PLATFORM_ID == 0xE1 // Edison platform id
#define pinToFastPin(pin) 1 // As far as I can tell all pins can be used as fast pins
#endif
// Pin 2 and 3 on the Intel Galileo supports a higher rate,
// so it is recommended to use one of these as the SS pin.
#define MAKE_PIN(className, pin) \
class className { \
public: \
static void Set() { \
fastDigitalWrite(pin, HIGH); \
} \
static void Clear() { \
fastDigitalWrite(pin, LOW); \
} \
static void SetDirRead() { \
if (pinToFastPin(pin)) \
pinMode(pin, INPUT_FAST); \
else \
pinMode(pin, INPUT); \
} \
static void SetDirWrite() { \
if (pinToFastPin(pin)) \
pinMode(pin, OUTPUT_FAST); \
else \
pinMode(pin, OUTPUT); \
} \
static uint8_t IsSet() { \
return fastDigitalRead(pin); \
} \
};
MAKE_PIN(P0, 0);
MAKE_PIN(P1, 1);
MAKE_PIN(P2, 2);
MAKE_PIN(P3, 3);
MAKE_PIN(P4, 4);
MAKE_PIN(P5, 5);
MAKE_PIN(P6, 6);
MAKE_PIN(P7, 7);
MAKE_PIN(P8, 8);
MAKE_PIN(P9, 9);
MAKE_PIN(P10, 10);
MAKE_PIN(P11, 11);
MAKE_PIN(P12, 12);
MAKE_PIN(P13, 13);
MAKE_PIN(P14, 14); // A0
MAKE_PIN(P15, 15); // A1
MAKE_PIN(P16, 16); // A2
MAKE_PIN(P17, 17); // A3
MAKE_PIN(P18, 18); // A4
MAKE_PIN(P19, 19); // A5
#undef MAKE_PIN
#elif defined(__MIPSEL__)
// MIPSEL (MIPS architecture using a little endian byte order)
// MIPS size_t = 4
@ -1062,6 +1121,10 @@ MAKE_PIN(P12, 12); //
MAKE_PIN(P13, 13); //
#undef MAKE_PIN
#else
#error "Please define board in avrpins.h"
#endif
#endif //_avrpins_h_

View file

@ -121,7 +121,7 @@ void setup() {
}
Usb.regWr(rUSBCTL, 0x00); //release from reset
uint16_t j = 0;
for(j = 0; j < 65535; j++) { //tracking off to on time
for(j = 1; j < 65535; j++) { //tracking off to on time
if(Usb.regRd(rUSBIRQ) & bmOSCOKIRQ) {
E_Notify(PSTR(" Time to stabilize - "), 0x80);
Serial.print(j, DEC);

View file

@ -129,8 +129,8 @@ e-mail : support@circuitsathome.com
#define USING_SPI4TEENSY3 0
#endif
#if ((defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822) || ARDUINO >= 10600) && !USING_SPI4TEENSY3
#include <SPI.h> // Use the Arduino SPI library for the Arduino Due, RedBearLab nRF51822 or if the SPI library with transaction is available
#if ((defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822) || defined(__ARDUINO_X86__) || ARDUINO >= 10600) && !USING_SPI4TEENSY3
#include <SPI.h> // Use the Arduino SPI library for the Arduino Due, RedBearLab nRF51822, Intel Galileo 1 & 2, Intel Edison or if the SPI library with transaction is available
#endif
#if defined(__PIC32MX__) || defined(__PIC32MZ__)
#include <../../../../hardware/pic32/libraries/SPI/SPI.h> // Hack to use the SPI library

View file

@ -27,7 +27,6 @@ e-mail : support@circuitsathome.com
#include <sys/types.h>
#endif
/* SPI initialization */
template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_SS > class SPi {
public:
@ -51,6 +50,12 @@ public:
SPI.begin();
#if defined(__MIPSEL__)
SPI.setClockDivider(1);
#elif defined(__ARDUINO_X86__)
#ifdef SPI_CLOCK_1M // Hack used to check if setClockSpeed is available
SPI.setClockSpeed(12000000); // The MAX3421E can handle up to 26MHz, but in practice this was the maximum that I could reliably use
#else
SPI.setClockDivider(SPI_CLOCK_DIV2); // This will set the SPI frequency to 8MHz - it could be higher, but it is not supported in the old API
#endif
#else
SPI.setClockDivider(4); // Set speed to 84MHz/4=21MHz - the MAX3421E can handle up to 26MHz
#endif
@ -86,14 +91,12 @@ typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi;
typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi;
#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
typedef SPi< Pb7, Pb5, Pb6, Pb4 > spi;
#elif defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__))
#elif (defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__))) || defined(__ARDUINO_X86__) || defined(__MIPSEL__)
typedef SPi< P13, P11, P12, P10 > spi;
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
typedef SPi< P76, P75, P74, P10 > spi;
#elif defined(RBL_NRF51822)
typedef SPi< P16, P18, P17, P10 > spi;
#elif defined(__MIPSEL__)
typedef SPi< P13, P11, P12, P10 > spi;
#else
#error "No SPI entry in usbhost.h"
#endif
@ -200,6 +203,10 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t*
spi4teensy3::send(reg | 0x02);
spi4teensy3::send(data_p, nbytes);
data_p += nbytes;
#elif defined(__ARDUINO_X86__)
SPI.transfer(reg | 0x02);
SPI.transferBuffer(data_p, NULL, nbytes);
data_p += nbytes;
#elif !defined(SPDR)
SPI.transfer(reg | 0x02);
while(nbytes) {
@ -289,6 +296,10 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t*
spi4teensy3::send(reg);
spi4teensy3::receive(data_p, nbytes);
data_p += nbytes;
#elif defined(__ARDUINO_X86__)
SPI.transfer(reg);
SPI.transferBuffer(NULL, data_p, nbytes);
data_p += nbytes;
#elif !defined(SPDR)
SPI.transfer(reg);
while(nbytes) {