Added support for the Intel Galileo

Still not tested
This commit is contained in:
Kristian Lauszus 2014-08-24 16:40:18 -07:00
parent 32c6b91e5a
commit a3db3d9451
5 changed files with 73 additions and 14 deletions

2
Usb.h
View file

@ -26,12 +26,12 @@ e-mail : support@circuitsathome.com
// None of these should ever be included by a driver, or a user's sketch. // None of these should ever be included by a driver, or a user's sketch.
#include "settings.h" #include "settings.h"
#include "printhex.h" #include "printhex.h"
#include "avrpins.h"
#include "message.h" #include "message.h"
#include "hexdump.h" #include "hexdump.h"
#include "sink_parser.h" #include "sink_parser.h"
#include "max3421e.h" #include "max3421e.h"
#include "address.h" #include "address.h"
#include "avrpins.h"
#include "usb_ch9.h" #include "usb_ch9.h"
#include "usbhost.h" #include "usbhost.h"
#include "UsbCore.h" #include "UsbCore.h"

View file

@ -38,7 +38,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, Due etc.) or Teensy 2.0 and 3.0 typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Galileo or Teensy 2.0 and 3.0
#endif #endif
/* Common setup data constant combinations */ /* Common setup data constant combinations */

View file

@ -747,9 +747,7 @@ public:
#endif // Arduino pin definitions #endif // Arduino pin definitions
#endif // __AVR__ #elif defined(__arm__)
#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)
@ -950,6 +948,53 @@ MAKE_PIN(P78, PIOB, PIO_PB23); // Unconnected
#endif #endif
#endif // __arm__ #elif defined(__ARDUINO_X86__)
#include <avr/pgmspace.h>
// Pointers are 32 bits on x86
#define pgm_read_pointer(p) pgm_read_dword(p)
#define MAKE_PIN(className, pin) \
class className { \
public: \
static void Set() { \
digitalWrite(pin, HIGH); \
} \
static void Clear() { \
digitalWrite(pin, LOW); \
} \
static void SetDirRead() { \
pinMode(pin, INPUT); \
} \
static void SetDirWrite() { \
pinMode(pin, OUTPUT); \
} \
static uint8_t IsSet() { \
return digitalRead(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);
#undef MAKE_PIN
#else
#error "Please define board in avrpins.h"
#endif
#endif // _avrpins_h_ #endif // _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__)) || ARDUINO >= 158) && !USING_SPI4TEENSY3 #if ((defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(__ARDUINO_X86__) || ARDUINO >= 158) && !USING_SPI4TEENSY3
#include <SPI.h> // Use the Arduino SPI library for the Arduino Due or if the SPI library with transaction is available #include <SPI.h> // Use the Arduino SPI library for the Arduino Due, Intel Galileo or if the SPI library with transaction is available
#endif #endif
#endif /* SETTINGS_H */ #endif /* SETTINGS_H */

View file

@ -43,12 +43,16 @@ public:
SPI_SS::SetDirWrite(); SPI_SS::SetDirWrite();
SPI_SS::Set(); SPI_SS::Set();
} }
#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) #elif (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(__ARDUINO_X86__)
static void init() { static void init() {
SPI_SS::SetDirWrite(); SPI_SS::SetDirWrite();
SPI_SS::Set(); SPI_SS::Set();
SPI.begin(); SPI.begin();
#ifdef __ARDUINO_X86__
SPI.setClockDivider(SPI_CLOCK_DIV2); // This will set the SPI frequency to 8MHz - it could be higher, but it is not supported in the API
#else
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
#endif
} }
#else #else
static void init() { static void init() {
@ -78,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(__ARDUINO_X86__)
typedef SPi< P13, P11, P12, P10 > spi;
#else #else
#error "No SPI entry in usbhost.h" #error "No SPI entry in usbhost.h"
#endif #endif
@ -148,7 +154,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(__ARDUINO_X86__)
SPI.transfer(reg | 0x02); SPI.transfer(reg | 0x02);
SPI.transfer(data); SPI.transfer(data);
#else #else
@ -184,13 +190,17 @@ 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__))
SPI.transfer(reg | 0x02); SPI.transfer(reg | 0x02);
while(nbytes) { while(nbytes) {
SPI.transfer(*data_p); SPI.transfer(*data_p);
nbytes--; nbytes--;
data_p++; // advance data pointer data_p++; // advance data pointer
} }
#elif defined(__ARDUINO_X86__)
SPI.transfer(reg | 0x02);
SPI.transferBuffer(data_p, NULL, nbytes);
data_p += nbytes;
#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) {
@ -230,7 +240,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) {
#endif #endif
SPI_SS::Clear(); SPI_SS::Clear();
#if (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || SPI_HAS_TRANSACTION #if (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || SPI_HAS_TRANSACTION || defined(__ARDUINO_X86__)
SPI.transfer(reg); SPI.transfer(reg);
uint8_t rv = SPI.transfer(0); // Send empty byte uint8_t rv = SPI.transfer(0); // Send empty byte
SPI_SS::Set(); SPI_SS::Set();
@ -273,12 +283,16 @@ 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__))
SPI.transfer(reg); SPI.transfer(reg);
while(nbytes) { while(nbytes) {
*data_p++ = SPI.transfer(0); *data_p++ = SPI.transfer(0);
nbytes--; nbytes--;
} }
#elif defined(__ARDUINO_X86__)
SPI.transfer(reg);
SPI.transferBuffer(NULL, data_p, nbytes);
data_p += nbytes;
#else #else
SPDR = reg; SPDR = reg;
while(!(SPSR & (1 << SPIF))); //wait while(!(SPSR & (1 << SPIF))); //wait