From a3db3d9451c17fdd6f28597017f853c79f1b1ce2 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 24 Aug 2014 16:40:18 -0700 Subject: [PATCH] Added support for the Intel Galileo Still not tested --- Usb.h | 2 +- UsbCore.h | 2 +- avrpins.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++----- settings.h | 4 ++-- usbhost.h | 24 +++++++++++++++++++----- 5 files changed, 73 insertions(+), 14 deletions(-) diff --git a/Usb.h b/Usb.h index d903ff51..8fbac80d 100644 --- a/Usb.h +++ b/Usb.h @@ -26,12 +26,12 @@ e-mail : support@circuitsathome.com // None of these should ever be included by a driver, or a user's sketch. #include "settings.h" #include "printhex.h" +#include "avrpins.h" #include "message.h" #include "hexdump.h" #include "sink_parser.h" #include "max3421e.h" #include "address.h" -#include "avrpins.h" #include "usb_ch9.h" #include "usbhost.h" #include "UsbCore.h" diff --git a/UsbCore.h b/UsbCore.h index 76d9d5ee..5a54328f 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -38,7 +38,7 @@ typedef MAX3421e MAX3421E; // Arduino Mega ADK #elif defined(ARDUINO_AVR_BALANDUINO) typedef MAX3421e MAX3421E; // Balanduino #else -typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.) or Teensy 2.0 and 3.0 +typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Galileo or Teensy 2.0 and 3.0 #endif /* Common setup data constant combinations */ diff --git a/avrpins.h b/avrpins.h index c59e9c52..b19897b8 100644 --- a/avrpins.h +++ b/avrpins.h @@ -747,9 +747,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) @@ -950,6 +948,53 @@ MAKE_PIN(P78, PIOB, PIO_PB23); // Unconnected #endif -#endif // __arm__ +#elif defined(__ARDUINO_X86__) -#endif //_avrpins_h_ +#include + +// 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_ diff --git a/settings.h b/settings.h index b1010786..93891b84 100644 --- a/settings.h +++ b/settings.h @@ -137,8 +137,8 @@ e-mail : support@circuitsathome.com #define USING_SPI4TEENSY3 0 #endif -#if ((defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || ARDUINO >= 158) && !USING_SPI4TEENSY3 -#include // Use the Arduino SPI library for the Arduino Due or if the SPI library with transaction is available +#if ((defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(__ARDUINO_X86__) || ARDUINO >= 158) && !USING_SPI4TEENSY3 +#include // Use the Arduino SPI library for the Arduino Due, Intel Galileo or if the SPI library with transaction is available #endif #endif /* SETTINGS_H */ diff --git a/usbhost.h b/usbhost.h index 31c0e128..37f9465c 100644 --- a/usbhost.h +++ b/usbhost.h @@ -43,12 +43,16 @@ public: SPI_SS::SetDirWrite(); SPI_SS::Set(); } -#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) +#elif (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(__ARDUINO_X86__) static void init() { SPI_SS::SetDirWrite(); SPI_SS::Set(); 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 +#endif } #else static void init() { @@ -78,6 +82,8 @@ typedef SPi< Pb7, Pb5, Pb6, Pb4 > spi; typedef SPi< P13, P11, P12, P10 > spi; #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) typedef SPi< P76, P75, P74, P10 > spi; +#elif defined(__ARDUINO_X86__) +typedef SPi< P13, P11, P12, P10 > spi; #else #error "No SPI entry in usbhost.h" #endif @@ -148,7 +154,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { c[0] = reg | 0x02; c[1] = data; 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(data); #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(data_p, nbytes); data_p += nbytes; -#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) +#elif (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) SPI.transfer(reg | 0x02); while(nbytes) { SPI.transfer(*data_p); nbytes--; data_p++; // advance data pointer } +#elif defined(__ARDUINO_X86__) + SPI.transfer(reg | 0x02); + SPI.transferBuffer(data_p, NULL, nbytes); + data_p += nbytes; #else SPDR = (reg | 0x02); //set WR bit and send register number while(nbytes) { @@ -230,7 +240,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { #endif 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); uint8_t rv = SPI.transfer(0); // Send empty byte 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::receive(data_p, nbytes); data_p += nbytes; -#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) +#elif (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) SPI.transfer(reg); while(nbytes) { *data_p++ = SPI.transfer(0); nbytes--; } +#elif defined(__ARDUINO_X86__) + SPI.transfer(reg); + SPI.transferBuffer(NULL, data_p, nbytes); + data_p += nbytes; #else SPDR = reg; while(!(SPSR & (1 << SPIF))); //wait