diff --git a/README.md b/README.md index 680e376d..2203c977 100644 --- a/README.md +++ b/README.md @@ -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 ``` 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 ``` 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: . You should then add ```#include ``` to your .ino file. * Balanduino diff --git a/UsbCore.h b/UsbCore.h index aad62afd..5c6c7710 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -37,8 +37,10 @@ typedef MAX3421e MAX3421E; // Teensy++ 1.0 and 2.0 typedef MAX3421e MAX3421E; // Arduino Mega ADK #elif defined(ARDUINO_AVR_BALANDUINO) typedef MAX3421e MAX3421E; // Balanduino +#elif defined(__ARDUINO_X86__) && PLATFORM_ID == 0x06 +typedef MAX3421e MAX3421E; // The Intel Galileo supports much faster read and write speed at pin 2 and 3 #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 Edison, Intel Galileo 2 or Teensy 2.0 and 3.0 #endif /* Common setup data constant combinations */ diff --git a/avrpins.h b/avrpins.h index 982f2fa6..4e60e3a2 100644 --- a/avrpins.h +++ b/avrpins.h @@ -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 + +// 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_ diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index 2d8529e4..573c3ce0 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -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); diff --git a/settings.h b/settings.h index 9f7e60ad..5c060354 100644 --- a/settings.h +++ b/settings.h @@ -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 // 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 // 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 diff --git a/usbhost.h b/usbhost.h index 24580e1c..0a2b7bff 100644 --- a/usbhost.h +++ b/usbhost.h @@ -27,7 +27,6 @@ e-mail : support@circuitsathome.com #include #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) {