From 4158a501a953792e7c0e3eff1a25957e45fe56df Mon Sep 17 00:00:00 2001 From: Joe Bowbeer Date: Fri, 3 Feb 2017 22:44:51 -0800 Subject: [PATCH 1/6] Add Arduino 101 mods from https://github.com/KitPan/USB_Host_Shield_2.0 --- avrpins.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ usbhost.h | 4 ++++ 2 files changed, 56 insertions(+) diff --git a/avrpins.h b/avrpins.h index e782de8b..ce50d16a 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1167,6 +1167,58 @@ MAKE_PIN(P19, GPIOC, GPIO_PIN_0); // A5 #endif +#elif defined(__ARDUINO_ARC__) + +#include +// Pointers are 32 bits on arc +#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); //PWM +MAKE_PIN(P4, 4); +MAKE_PIN(P5, 5); //PWM +MAKE_PIN(P6, 6); //PWM +MAKE_PIN(P7, 7); +MAKE_PIN(P8, 8); +MAKE_PIN(P9, 9); //PWM + +MAKE_PIN(P10, 10); //SPI SS +MAKE_PIN(P11, 11); //SPI MOSI +MAKE_PIN(P12, 12); //SPI MISO +MAKE_PIN(P13, 13); //SPI SCK / BUILTIN LED + +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 SDA +MAKE_PIN(P19, 19); // A5 SCL +MAKE_PIN(P20, 20); // ATN + +#undef MAKE_PIN + #elif defined(__ARDUINO_X86__) // Intel Galileo, Intel Galileo 2 and Intel Edison #include diff --git a/usbhost.h b/usbhost.h index 705aeebf..cbff60cb 100644 --- a/usbhost.h +++ b/usbhost.h @@ -63,6 +63,8 @@ public: #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 +#elif defined(__ARDUINO_ARC__) + SPI.setClockDivider(SPI_CLOCK_DIV2); #elif !defined(RBL_NRF51822) SPI.setClockDivider(4); // Set speed to 84MHz/4=21MHz - the MAX3421E can handle up to 26MHz #endif @@ -97,6 +99,8 @@ typedef SPi< P13, P11, P12, P10 > spi; typedef SPi< P76, P75, P74, P10 > spi; #elif defined(RBL_NRF51822) typedef SPi< P16, P18, P17, P10 > spi; +#elif defined(__ARDUINO_ARC__) +typedef SPi< P13, P11, P12, P10 > spi; #else #error "No SPI entry in usbhost.h" #endif From d57d810e9335bb922e199d6c32006db66372f62c Mon Sep 17 00:00:00 2001 From: Joe Bowbeer Date: Fri, 3 Feb 2017 22:52:01 -0800 Subject: [PATCH 2/6] Remove duplicate code --- usbhost.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/usbhost.h b/usbhost.h index cbff60cb..e4e9be8b 100644 --- a/usbhost.h +++ b/usbhost.h @@ -93,14 +93,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__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__))) || defined(__ARDUINO_X86__) || defined(__MIPSEL__) || defined(STM32F4) +#elif (defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__))) || defined(__ARDUINO_ARC__) || defined(__ARDUINO_X86__) || defined(__MIPSEL__) || defined(STM32F4) 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(__ARDUINO_ARC__) -typedef SPi< P13, P11, P12, P10 > spi; #else #error "No SPI entry in usbhost.h" #endif From e2902bd8a18266a0841109a82261e066222831e2 Mon Sep 17 00:00:00 2001 From: Joe Bowbeer Date: Sun, 5 Feb 2017 19:35:23 -0800 Subject: [PATCH 3/6] Add genuino101 to travis, remove call to setClockDivider (obsolete) --- .travis.yml | 2 +- usbhost.h | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 06af6041..0abcea7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,4 +74,4 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --lib="." + - platformio ci --board=uno --board=genuino101 --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --lib="." diff --git a/usbhost.h b/usbhost.h index e4e9be8b..24a6cfee 100644 --- a/usbhost.h +++ b/usbhost.h @@ -63,8 +63,6 @@ public: #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 -#elif defined(__ARDUINO_ARC__) - SPI.setClockDivider(SPI_CLOCK_DIV2); #elif !defined(RBL_NRF51822) SPI.setClockDivider(4); // Set speed to 84MHz/4=21MHz - the MAX3421E can handle up to 26MHz #endif From 56c6e3d42b5f00b5b04ea6eba340f8d27124ae70 Mon Sep 17 00:00:00 2001 From: Joe Bowbeer Date: Mon, 6 Feb 2017 03:24:19 -0800 Subject: [PATCH 4/6] Define CLOCK_SPEED as type int --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0abcea7b..a629db95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,4 +74,6 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=genuino101 --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --lib="." + - platformio ci --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --lib="." + - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DCLOCK_SPEED=32 -Wno-error" # Workaround https://github.com/felis/USB_Host_Shield_2.0/pull/284 + - platformio ci --board=genuino101 --lib="." From 695325c1784974a17bc604dca76d781fe4182b7f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 6 Feb 2017 13:06:13 +0100 Subject: [PATCH 5/6] CLOCK_SPEED is now correctly defined as an int instead of a double See: https://github.com/platformio/platform-intel_arc32/commit/edcc7062ae8ca344ac90533dfab1166bc2ca25eb --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index a629db95..8d04757c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,6 +74,4 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --lib="." - - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DCLOCK_SPEED=32 -Wno-error" # Workaround https://github.com/felis/USB_Host_Shield_2.0/pull/284 - - platformio ci --board=genuino101 --lib="." + - platformio ci --board=uno --board=due --board=genuino101 --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --lib="." From 276c7a332abd52a45a143c85d4432a006eca9a12 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 6 Feb 2017 14:04:33 +0100 Subject: [PATCH 6/6] millis() is 64-bits on the Arduino/Genuino 101 See: https://travis-ci.org/felis/USB_Host_Shield_2.0/jobs/198814525 --- examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino index db8faadb..d5e3f1db 100644 --- a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -69,7 +69,11 @@ void MIDI_poll() pid = Midi.pid; } if (Midi.RecvData( &rcvd, bufMidi) == 0 ) { +#ifdef __ARDUINO_ARC__ + sprintf(buf, "%016llX: ", millis()); // millis() is 64-bits on the Arduino/Genuino 101 +#else sprintf(buf, "%08lX: ", millis()); +#endif Serial.print(buf); Serial.print(rcvd); Serial.print(':');