From 45df70641b7f5cda7348a9769a25c7dace8ad4f5 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sat, 2 Aug 2014 15:06:46 -0700 Subject: [PATCH 001/220] Use new Arduino SPI library See: https://github.com/arduino/Arduino/pull/2223 --- settings.h | 6 ++--- usbhost.h | 73 +++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 15 deletions(-) diff --git a/settings.h b/settings.h index e3d0ed1d..28503550 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__) -#include // Use the Arduino SPI library for the Arduino Due +#if (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || ARDUINO >= 158 +#include // Use the Arduino SPI library for the Arduino Due or if the SPI library with transaction is available #endif -#endif /* SETTINGS_H */ +#endif /* SETTINGS_H */ diff --git a/usbhost.h b/usbhost.h index cf26c1f0..e489da62 100644 --- a/usbhost.h +++ b/usbhost.h @@ -30,7 +30,11 @@ e-mail : support@circuitsathome.com /* SPI initialization */ template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_SS > class SPi { public: -#if USING_SPI4TEENSY3 +#if SPI_HAS_TRANSACTION + static void init() { + SPI.begin(); // The SPI library with transaction will take care of setting up the pins - settings is set in beginTransaction() + } +#elif USING_SPI4TEENSY3 static void init() { // spi4teensy3 inits everything for us, except /SS // CLK, MOSI and MISO are hard coded for now. @@ -129,8 +133,17 @@ MAX3421e< SPI_SS, INTR >::MAX3421e() { template< typename SPI_SS, typename INTR > void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { XMEM_ACQUIRE_SPI(); +#if SPI_HAS_TRANSACTION + SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 +#endif SPI_SS::Clear(); -#if USING_SPI4TEENSY3 + +#if SPI_HAS_TRANSACTION + uint8_t c[2]; + c[0] = reg | 0x02; + c[1] = data; + SPI.transfer(c, 2); +#elif USING_SPI4TEENSY3 uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; @@ -144,7 +157,11 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { SPDR = data; while(!(SPSR & (1 << SPIF))); #endif + SPI_SS::Set(); +#if SPI_HAS_TRANSACTION + SPI.endTransaction(); +#endif XMEM_RELEASE_SPI(); return; }; @@ -154,8 +171,16 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { template< typename SPI_SS, typename INTR > uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p) { XMEM_ACQUIRE_SPI(); +#if SPI_HAS_TRANSACTION + SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 +#endif SPI_SS::Clear(); -#if USING_SPI4TEENSY3 + +#if SPI_HAS_TRANSACTION + SPI.transfer(reg | 0x02); + SPI.transfer(data_p, nbytes); + data_p += nbytes; +#elif USING_SPI4TEENSY3 spi4teensy3::send(reg | 0x02); spi4teensy3::send(data_p, nbytes); data_p += nbytes; @@ -176,7 +201,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* } while(!(SPSR & (1 << SPIF))); #endif + SPI_SS::Set(); +#if SPI_HAS_TRANSACTION + SPI.endTransaction(); +#endif XMEM_RELEASE_SPI(); return ( data_p); } @@ -196,23 +225,31 @@ void MAX3421e< SPI_SS, INTR >::gpioWr(uint8_t data) { template< typename SPI_SS, typename INTR > uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { XMEM_ACQUIRE_SPI(); +#if SPI_HAS_TRANSACTION + SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 +#endif SPI_SS::Clear(); -#if USING_SPI4TEENSY3 - spi4teensy3::send(reg); - uint8_t rv = spi4teensy3::receive(); - SPI_SS::Set(); -#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) + +#if (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || SPI_HAS_TRANSACTION SPI.transfer(reg); - uint8_t rv = SPI.transfer(0); + uint8_t rv = SPI.transfer(0); // Send empty byte + SPI_SS::Set(); +#elif USING_SPI4TEENSY3 + spi4teensy3::send(reg); + uint8_t rv = spi4teensy3::receive(); // Send empty byte SPI_SS::Set(); #else SPDR = reg; while(!(SPSR & (1 << SPIF))); - SPDR = 0; //send empty byte + SPDR = 0; // Send empty byte while(!(SPSR & (1 << SPIF))); SPI_SS::Set(); uint8_t rv = SPDR; #endif + +#if SPI_HAS_TRANSACTION + SPI.endTransaction(); +#endif XMEM_RELEASE_SPI(); return (rv); } @@ -222,8 +259,16 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { template< typename SPI_SS, typename INTR > uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* data_p) { XMEM_ACQUIRE_SPI(); +#if SPI_HAS_TRANSACTION + SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 +#endif SPI_SS::Clear(); -#if USING_SPI4TEENSY3 + +#if SPI_HAS_TRANSACTION + SPI.transfer(reg); + SPI.transfer(data_p, nbytes); + data_p += nbytes; +#elif USING_SPI4TEENSY3 spi4teensy3::send(reg); spi4teensy3::receive(data_p, nbytes); data_p += nbytes; @@ -253,7 +298,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* } #endif #endif + SPI_SS::Set(); +#if SPI_HAS_TRANSACTION + SPI.endTransaction(); +#endif XMEM_RELEASE_SPI(); return ( data_p); } @@ -439,7 +488,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::IntHandler() { //template< typename SPI_SS, typename INTR > //uint8_t MAX3421e< SPI_SS, INTR >::GpxHandler() //{ -// uint8_t GPINIRQ = regRd( rGPINIRQ ); //read GPIN IRQ register +// uint8_t GPINIRQ = regRd( rGPINIRQ ); //read GPIN IRQ register //// if( GPINIRQ & bmGPINIRQ7 ) { //vbus overload //// vbusPwr( OFF ); //attempt powercycle //// delay( 1000 ); From b46ead88e8117ffc88228ebdaf88be129b558a62 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sat, 2 Aug 2014 15:16:29 -0700 Subject: [PATCH 002/220] Don't use Arduino SPI library if spi4teensy3 should be used --- settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.h b/settings.h index 28503550..b1010786 100644 --- a/settings.h +++ b/settings.h @@ -137,7 +137,7 @@ e-mail : support@circuitsathome.com #define USING_SPI4TEENSY3 0 #endif -#if (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || ARDUINO >= 158 +#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 #endif From 7d3154bce7c76538ef854e28ec78c3b93d8c3403 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sat, 2 Aug 2014 18:57:37 -0400 Subject: [PATCH 003/220] Work around Arduino IDE bug See: https://github.com/arduino/Arduino/pull/1726 --- examples/Bluetooth/BTHID/BTHID.ino | 5 +++-- examples/Bluetooth/PS3BT/PS3BT.ino | 5 +++-- examples/Bluetooth/PS3Multi/PS3Multi.ino | 5 +++-- examples/Bluetooth/PS3SPP/PS3SPP.ino | 5 +++-- examples/Bluetooth/PS4BT/PS4BT.ino | 4 ++-- examples/Bluetooth/SPP/SPP.ino | 5 +++-- examples/Bluetooth/SPPMulti/SPPMulti.ino | 5 +++-- examples/Bluetooth/Wii/Wii.ino | 5 +++-- examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino | 5 +++-- examples/Bluetooth/WiiMulti/WiiMulti.ino | 5 +++-- examples/Bluetooth/WiiUProController/WiiUProController.ino | 5 +++-- examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino | 5 +++-- examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino | 5 +++++ examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino | 5 +++-- examples/HID/USBHIDJoystick/USBHIDJoystick.ino | 5 +++++ examples/HID/USBHID_desc/USBHID_desc.ino | 5 +++-- examples/HID/le3dp/le3dp.ino | 5 +++-- examples/HID/scale/scale.ino | 5 +++-- examples/PS3USB/PS3USB.ino | 5 +++-- examples/PS4USB/PS4USB.ino | 4 ++-- examples/PSBuzz/PSBuzz.ino | 4 ++-- examples/USB_desc/USB_desc.ino | 5 +++-- examples/Xbox/XBOXOLD/XBOXOLD.ino | 5 +++-- examples/Xbox/XBOXRECV/XBOXRECV.ino | 5 +++-- examples/Xbox/XBOXUSB/XBOXUSB.ino | 5 +++-- examples/acm/acm_terminal/acm_terminal.ino | 4 ++-- examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino | 5 +++++ examples/adk/adk_barcode/adk_barcode.ino | 5 +++++ examples/adk/demokit_20/demokit_20.ino | 5 +++++ examples/adk/term_test/term_test.ino | 5 +++++ examples/adk/term_time/term_time.ino | 5 +++++ examples/board_qc/board_qc.ino | 5 +++-- examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino | 5 +++-- examples/hub_demo/hub_demo.ino | 5 +++-- examples/max_LCD/max_LCD.ino | 5 +++++ .../pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino | 5 +++-- examples/pl2303/pl2303_gps/pl2303_gps.ino | 5 +++-- examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino | 5 +++-- .../pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino | 5 +++-- examples/testusbhostFAT/testusbhostFAT.ino | 1 + 40 files changed, 130 insertions(+), 62 deletions(-) mode change 100755 => 100644 examples/testusbhostFAT/testusbhostFAT.ino diff --git a/examples/Bluetooth/BTHID/BTHID.ino b/examples/Bluetooth/BTHID/BTHID.ino index fcfd686a..a548e613 100644 --- a/examples/Bluetooth/BTHID/BTHID.ino +++ b/examples/Bluetooth/BTHID/BTHID.ino @@ -8,8 +8,9 @@ #include #include "KeyboardParser.h" #include "MouseParser.h" -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index 982eb384..769536f4 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -6,8 +6,9 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index 23e8cd9a..074145d4 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -7,8 +7,9 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index 440ea79e..9023f2ad 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -12,8 +12,9 @@ #include #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/PS4BT/PS4BT.ino b/examples/Bluetooth/PS4BT/PS4BT.ino index e47cfae0..492fc791 100644 --- a/examples/Bluetooth/PS4BT/PS4BT.ino +++ b/examples/Bluetooth/PS4BT/PS4BT.ino @@ -7,8 +7,8 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/SPP/SPP.ino b/examples/Bluetooth/SPP/SPP.ino index d8276b7b..4436349c 100644 --- a/examples/Bluetooth/SPP/SPP.ino +++ b/examples/Bluetooth/SPP/SPP.ino @@ -6,8 +6,9 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/SPPMulti/SPPMulti.ino b/examples/Bluetooth/SPPMulti/SPPMulti.ino index 0304257e..73d4bc46 100644 --- a/examples/Bluetooth/SPPMulti/SPPMulti.ino +++ b/examples/Bluetooth/SPPMulti/SPPMulti.ino @@ -6,8 +6,9 @@ #include #include -// Satisfy IDE, which only needs to see the include statement in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/Wii/Wii.ino b/examples/Bluetooth/Wii/Wii.ino index f4d68a62..18051dde 100644 --- a/examples/Bluetooth/Wii/Wii.ino +++ b/examples/Bluetooth/Wii/Wii.ino @@ -6,8 +6,9 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino index e7ca456b..f1326bf7 100644 --- a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino +++ b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino @@ -13,8 +13,9 @@ Otherwise, wire up a IR LED yourself. #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/WiiMulti/WiiMulti.ino b/examples/Bluetooth/WiiMulti/WiiMulti.ino index 08444f10..0e81d20d 100644 --- a/examples/Bluetooth/WiiMulti/WiiMulti.ino +++ b/examples/Bluetooth/WiiMulti/WiiMulti.ino @@ -7,8 +7,9 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Bluetooth/WiiUProController/WiiUProController.ino b/examples/Bluetooth/WiiUProController/WiiUProController.ino index 59c4f1dc..36bbfbdb 100644 --- a/examples/Bluetooth/WiiUProController/WiiUProController.ino +++ b/examples/Bluetooth/WiiUProController/WiiUProController.ino @@ -6,8 +6,9 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino index b5944f0a..8d945dac 100644 --- a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino +++ b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino @@ -1,7 +1,8 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino index 92dc226b..f3ccdc7d 100644 --- a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -1,6 +1,11 @@ #include #include +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include +#include +#endif + class MouseRptParser : public MouseReportParser { protected: diff --git a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino index aa2e3b34..bddd960d 100644 --- a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino +++ b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino @@ -1,7 +1,8 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino index d0106e1a..940ac795 100644 --- a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino +++ b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino @@ -4,6 +4,11 @@ #include "hidjoystickrptparser.h" +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include +#include +#endif + USB Usb; USBHub Hub(&Usb); HIDUniversal Hid(&Usb); diff --git a/examples/HID/USBHID_desc/USBHID_desc.ino b/examples/HID/USBHID_desc/USBHID_desc.ino index 806936f9..ec08f01e 100644 --- a/examples/HID/USBHID_desc/USBHID_desc.ino +++ b/examples/HID/USBHID_desc/USBHID_desc.ino @@ -3,8 +3,9 @@ #include #include #include "pgmstrings.h" -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/HID/le3dp/le3dp.ino b/examples/HID/le3dp/le3dp.ino index fbf07b2f..878f3471 100644 --- a/examples/HID/le3dp/le3dp.ino +++ b/examples/HID/le3dp/le3dp.ino @@ -5,8 +5,9 @@ #include #include "le3dp_rptparser.h" -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/HID/scale/scale.ino b/examples/HID/scale/scale.ino index c790cb1c..20b96fa9 100644 --- a/examples/HID/scale/scale.ino +++ b/examples/HID/scale/scale.ino @@ -6,8 +6,9 @@ #include #include "scale_rptparser.h" -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index 2db3afd5..b9b42c30 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -5,8 +5,9 @@ */ #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/PS4USB/PS4USB.ino b/examples/PS4USB/PS4USB.ino index b3a2436b..7ab0f6ca 100644 --- a/examples/PS4USB/PS4USB.ino +++ b/examples/PS4USB/PS4USB.ino @@ -6,8 +6,8 @@ #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/PSBuzz/PSBuzz.ino b/examples/PSBuzz/PSBuzz.ino index 6944cb6b..5f2e538e 100644 --- a/examples/PSBuzz/PSBuzz.ino +++ b/examples/PSBuzz/PSBuzz.ino @@ -6,8 +6,8 @@ #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index b0013914..ae5430f3 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -1,8 +1,9 @@ #include #include "pgmstrings.h" -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Xbox/XBOXOLD/XBOXOLD.ino b/examples/Xbox/XBOXOLD/XBOXOLD.ino index 968c8df7..c41fc7cc 100644 --- a/examples/Xbox/XBOXOLD/XBOXOLD.ino +++ b/examples/Xbox/XBOXOLD/XBOXOLD.ino @@ -6,8 +6,9 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Xbox/XBOXRECV/XBOXRECV.ino b/examples/Xbox/XBOXRECV/XBOXRECV.ino index 1f43b912..37d11c21 100644 --- a/examples/Xbox/XBOXRECV/XBOXRECV.ino +++ b/examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -6,8 +6,9 @@ */ #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/Xbox/XBOXUSB/XBOXUSB.ino b/examples/Xbox/XBOXUSB/XBOXUSB.ino index 89161d24..3c303f0a 100644 --- a/examples/Xbox/XBOXUSB/XBOXUSB.ino +++ b/examples/Xbox/XBOXUSB/XBOXUSB.ino @@ -5,8 +5,9 @@ */ #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/acm/acm_terminal/acm_terminal.ino b/examples/acm/acm_terminal/acm_terminal.ino index 5e4d152c..c68e1a7c 100644 --- a/examples/acm/acm_terminal/acm_terminal.ino +++ b/examples/acm/acm_terminal/acm_terminal.ino @@ -3,8 +3,8 @@ #include "pgmstrings.h" -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino index dc6ab92c..a7e3db7e 100644 --- a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino +++ b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino @@ -2,6 +2,11 @@ // The code for the Android application is heavily based on this guide: http://allaboutee.com/2011/12/31/arduino-adk-board-blink-an-led-with-your-phone-code-and-explanation/ by Miguel #include +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include +#include +#endif + USB Usb; ADK adk(&Usb, "TKJElectronics", // Manufacturer Name "ArduinoBlinkLED", // Model Name diff --git a/examples/adk/adk_barcode/adk_barcode.ino b/examples/adk/adk_barcode/adk_barcode.ino index b410572a..a6c93680 100644 --- a/examples/adk/adk_barcode/adk_barcode.ino +++ b/examples/adk/adk_barcode/adk_barcode.ino @@ -5,6 +5,11 @@ #include #include +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include +#include +#endif + USB Usb; USBHub Hub1(&Usb); USBHub Hub2(&Usb); diff --git a/examples/adk/demokit_20/demokit_20.ino b/examples/adk/demokit_20/demokit_20.ino index 87662297..f26d9ef2 100644 --- a/examples/adk/demokit_20/demokit_20.ino +++ b/examples/adk/demokit_20/demokit_20.ino @@ -1,6 +1,11 @@ #include #include +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include +#include +#endif + USB Usb; USBHub hub0(&Usb); USBHub hub1(&Usb); diff --git a/examples/adk/term_test/term_test.ino b/examples/adk/term_test/term_test.ino index dea6533f..948ab795 100644 --- a/examples/adk/term_test/term_test.ino +++ b/examples/adk/term_test/term_test.ino @@ -1,6 +1,11 @@ #include #include +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include +#include +#endif + USB Usb; //USBHub Hub(&Usb); diff --git a/examples/adk/term_time/term_time.ino b/examples/adk/term_time/term_time.ino index 39fe3a49..fbdc774f 100644 --- a/examples/adk/term_time/term_time.ino +++ b/examples/adk/term_time/term_time.ino @@ -1,6 +1,11 @@ #include #include +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include +#include +#endif + USB Usb; ADK adk(&Usb,"Circuits@Home, ltd.", diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index 94df16cf..3fcf9251 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -4,8 +4,9 @@ /* otherwise press any key after getting GPIO error to complete the test */ /**/ #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino index 26b5624d..2424f8ee 100644 --- a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino +++ b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino @@ -2,8 +2,9 @@ #include #include "pgmstrings.h" -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index 329c6230..3109ef32 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -1,7 +1,8 @@ #include #include "pgmstrings.h" -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/max_LCD/max_LCD.ino b/examples/max_LCD/max_LCD.ino index f60ed4d5..b92ede9b 100644 --- a/examples/max_LCD/max_LCD.ino +++ b/examples/max_LCD/max_LCD.ino @@ -5,6 +5,11 @@ #include +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include +#include +#endif + USB Usb; Max_LCD lcd(&Usb); diff --git a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino index 4770809d..4b19a1a9 100644 --- a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino +++ b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino @@ -4,8 +4,9 @@ /* CDC support */ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/pl2303/pl2303_gps/pl2303_gps.ino b/examples/pl2303/pl2303_gps/pl2303_gps.ino index 908763c4..5831326b 100644 --- a/examples/pl2303/pl2303_gps/pl2303_gps.ino +++ b/examples/pl2303/pl2303_gps/pl2303_gps.ino @@ -5,8 +5,9 @@ /* CDC support */ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index db25e42a..536734e9 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -11,8 +11,9 @@ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino index 9e17d3cf..c8053821 100644 --- a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino +++ b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino @@ -5,8 +5,9 @@ /* CDC support */ #include #include -// Satisfy IDE, which only needs to see the include statment in the ino. -#ifdef dobogusinclude + +#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. +#include #include #endif diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino old mode 100755 new mode 100644 index 70107963..987e0a50 --- a/examples/testusbhostFAT/testusbhostFAT.ino +++ b/examples/testusbhostFAT/testusbhostFAT.ino @@ -59,6 +59,7 @@ #if WANT_HUB_TEST #include #endif +#include #include #include #include From 963c157bc5af4b2a0940a0bca2b2c309c5ad4f19 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 3 Aug 2014 18:01:55 +0200 Subject: [PATCH 004/220] Make sure that we send out empty bytes when receiving multiple bytes Also fixed some comments --- usbhost.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/usbhost.h b/usbhost.h index e489da62..31c0e128 100644 --- a/usbhost.h +++ b/usbhost.h @@ -236,7 +236,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { SPI_SS::Set(); #elif USING_SPI4TEENSY3 spi4teensy3::send(reg); - uint8_t rv = spi4teensy3::receive(); // Send empty byte + uint8_t rv = spi4teensy3::receive(); SPI_SS::Set(); #else SPDR = reg; @@ -266,6 +266,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* #if SPI_HAS_TRANSACTION SPI.transfer(reg); + memset(data_p, 0, nbytes); // Make sure we send out empty bytes SPI.transfer(data_p, nbytes); data_p += nbytes; #elif USING_SPI4TEENSY3 @@ -282,7 +283,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* SPDR = reg; while(!(SPSR & (1 << SPIF))); //wait while(nbytes) { - SPDR = 0; //send empty byte + SPDR = 0; // Send empty byte nbytes--; while(!(SPSR & (1 << SPIF))); #if 0 From 32c6b91e5a1eece453404590492d5f69df95a72c Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 24 Aug 2014 15:56:36 -0700 Subject: [PATCH 005/220] All virtual functions inside BluetoothService needed to be pure for the Intel Galileo --- BTD.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/BTD.h b/BTD.h index 3a639abb..c62ad5eb 100755 --- a/BTD.h +++ b/BTD.h @@ -214,13 +214,13 @@ public: * Used to pass acldata to the Bluetooth service. * @param ACLData Pointer to the incoming acldata. */ - virtual void ACLData(uint8_t* ACLData); + virtual void ACLData(uint8_t* ACLData) = 0; /** Used to run the different state machines in the Bluetooth service. */ - virtual void Run(); + virtual void Run() = 0; /** Used to reset the Bluetooth service. */ - virtual void Reset(); + virtual void Reset() = 0; /** Used to disconnect both the L2CAP Channel and the HCI Connection for the Bluetooth service. */ - virtual void disconnect(); + virtual void disconnect() = 0; }; /** From a3db3d9451c17fdd6f28597017f853c79f1b1ce2 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 24 Aug 2014 16:40:18 -0700 Subject: [PATCH 006/220] 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 From af4c3f673c22147c82fd5a4e765b4aa06cd64f62 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 24 Aug 2014 17:10:50 -0700 Subject: [PATCH 007/220] The analog pins can also be used as digital pins --- avrpins.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/avrpins.h b/avrpins.h index b19897b8..b7d05b38 100644 --- a/avrpins.h +++ b/avrpins.h @@ -948,7 +948,7 @@ MAKE_PIN(P78, PIOB, PIO_PB23); // Unconnected #endif -#elif defined(__ARDUINO_X86__) +#elif defined(__ARDUINO_X86__) // Intel Galileo #include @@ -989,6 +989,12 @@ 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 From 81a861d4d5f7f1a294affaaab69851d6de1ee2bc Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 2 Sep 2014 00:18:05 -0700 Subject: [PATCH 008/220] Mention Arduino Galileo in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 58599d42..7d45ca3c 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,8 @@ 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 and Arduino Galileo + * If you are using the Arduino Due or Galileo, then you must include the Arduino SPI library like so: ```#include ``` in your .ino file. * 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 From 4ab24d9973e53908853c3fb8ce0fae31052a3e32 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 7 Sep 2014 22:06:19 -0700 Subject: [PATCH 009/220] No need to __ARDUINO_X86__ to have it's own entry --- usbhost.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/usbhost.h b/usbhost.h index 37f9465c..bf2bf5ac 100644 --- a/usbhost.h +++ b/usbhost.h @@ -78,12 +78,10 @@ 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__) 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 @@ -190,7 +188,7 @@ 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); @@ -283,7 +281,7 @@ 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); From 9fb4cb18472084f483a7b3a6fe18bbe85f6a1089 Mon Sep 17 00:00:00 2001 From: v173k Date: Tue, 18 Nov 2014 18:56:28 -0600 Subject: [PATCH 010/220] Fix for PL2303HX chips so that PL2303::SndData() works. Details: This was worked earlier by uncommenting "#define PL2303_COMPAT" from cdcprolific.h I just re-added code by Oleg Mazurov which for some reason was lost during a later merge/pull request. Also see: http://www.circuitsathome.com/mcu/major-acmprolific-bug-fix-posted-on-github --- cdcprolific.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- cdcprolific.h | 22 +++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/cdcprolific.cpp b/cdcprolific.cpp index d629ad55..8a06c388 100644 --- a/cdcprolific.cpp +++ b/cdcprolific.cpp @@ -30,6 +30,7 @@ uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) { UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint8_t num_of_conf; // number of configurations + enum pl2303_type pltype = unknown; AddressPool &addrPool = pUsb->GetAddressPool(); @@ -69,6 +70,21 @@ uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) { if(udd->idVendor != PL_VID && udd->idProduct != PL_PID) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; + /* determine chip variant */ + + if (udd->bDeviceClass == 0x02 ) { + pltype = type_0; + } + else if (udd->bMaxPacketSize0 == 0x40 ) { + pltype = rev_HX; + } + else if (udd->bDeviceClass == 0x00) { + pltype = type_1; + } + else if (udd->bDeviceClass == 0xff) { + pltype = type_1; + } + // Save type of PL chip wPLType = udd->bcdDevice; @@ -144,7 +160,30 @@ uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) { if(rcode) goto FailSetConfDescr; - + + #if defined(PL2303_COMPAT) + /* shamanic dance - sending Prolific init data as-is */ + vendorRead( 0x84, 0x84, 0, buf ); + vendorWrite( 0x04, 0x04, 0 ); + vendorRead( 0x84, 0x84, 0, buf ); + vendorRead( 0x83, 0x83, 0, buf ); + vendorRead( 0x84, 0x84, 0, buf ); + vendorWrite( 0x04, 0x04, 1 ); + vendorRead( 0x84, 0x84, 0, buf); + vendorRead( 0x83, 0x83, 0, buf); + vendorWrite( 0, 0, 1 ); + vendorWrite( 1, 0, 0 ); + if ( pltype == rev_HX ) { + vendorWrite( 2, 0, 0x44 ); + vendorWrite( 0x06, 0x06, 0 ); //from W7 init + } + else { + vendorWrite( 2, 0, 0x24 ); + } + /* shamanic dance end */ + #endif + + /* calling post-init callback */ rcode = pAsync->OnInit(this); if(rcode) diff --git a/cdcprolific.h b/cdcprolific.h index bfa92fe3..7b964ca7 100644 --- a/cdcprolific.h +++ b/cdcprolific.h @@ -19,6 +19,8 @@ e-mail : support@circuitsathome.com #include "cdcacm.h" +#define PL2303_COMPAT //uncomment it if you have compatibility problems + #define PL_VID 0x067B #define PL_PID ( 0x2303 || 0x0609 ) @@ -106,7 +108,8 @@ enum tXO_State { enum pl2303_type { unknown, - type_1, /* don't know the difference between type 0 and */ + type_0, + type_1, /* don't know the difference between type 0 and */ rev_X, /* type 1, until someone from prolific tells us... */ rev_HX, /* HX version of the pl2303 chip */ rev_H @@ -129,6 +132,23 @@ public: //// UsbConfigXtracter implementation //virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); + +private: + /* Prolific proprietary requests */ + uint8_t vendorRead( uint8_t val_lo, uint8_t val_hi, uint16_t index, uint8_t* buf ); + uint8_t vendorWrite( uint8_t val_lo, uint8_t val_hi, uint8_t index ); }; +/* vendor read request */ +inline uint8_t PL2303::vendorRead( uint8_t val_lo, uint8_t val_hi, uint16_t index, uint8_t* buf ) +{ + return( pUsb->ctrlReq(bAddress, 0, VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, val_lo, val_hi, index, 1, 1, buf, NULL )); +} + +/* vendor write request */ +inline uint8_t PL2303::vendorWrite( uint8_t val_lo, uint8_t val_hi, uint8_t index ) +{ + return( pUsb->ctrlReq(bAddress, 0, VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, val_lo, val_hi, index, 0, 0, NULL, NULL )); +} + #endif // __CDCPROLIFIC_H__ From 7c475c91e01821f00ed01d0014b30e8cd0d375f4 Mon Sep 17 00:00:00 2001 From: Fred Date: Sat, 14 Feb 2015 11:09:24 +0000 Subject: [PATCH 011/220] Xbox ONE Controller support --- README.md | 13 +- XBOXONE.cpp | 359 ++++++++++++++++++++++++++++++ XBOXONE.h | 180 +++++++++++++++ controllerEnums.h | 8 + examples/Xbox/XBOXONE/XBOXONE.ino | 110 +++++++++ keywords.txt | 6 + 6 files changed, 675 insertions(+), 1 deletion(-) create mode 100644 XBOXONE.cpp create mode 100644 XBOXONE.h create mode 100644 examples/Xbox/XBOXONE/XBOXONE.ino diff --git a/README.md b/README.md index e7f4ed56..a0372681 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ For more information about the hardware see the [Hardware Manual](http://www.cir * Developer of the [BTD](#bluetooth-libraries), [BTHID](#bthid-library), [SPP](#spp-library), [PS4](#ps4-library), [PS3](#ps3-library), [Wii](#wii-library), [Xbox](#xbox-library), and [PSBuzz](#ps-buzz-library) libraries * __Andrew Kroll__ - * Major contributor to mass storage code +* __guruthree__ + * [Xbox ONE](#xbox-one-library) controller support # Donate @@ -47,6 +49,7 @@ Help yourself by helping us support you! Many thousands of hours have been spent * [Xbox Libraries](#xbox-libraries) * [Xbox library](#xbox-library) * [Xbox 360 Library](#xbox-360-library) + * [Xbox ONE Library](#xbox-one-library) * [Wii library](#wii-library) * [PS Buzz Library](#ps-buzz-library) * [Interface modifications](#interface-modifications) @@ -229,6 +232,14 @@ All the information regarding the Xbox 360 controller protocol are form these si * * +#### Xbox ONE Library + +An Xbox ONE controller is supported via USB in the [XBOXONE](XBOXONE.cpp) class. It is heavily based on the 360 library above. In addition to cross referencing the above, information on the protocol was found at: + +* +* +* + ### [Wii library](Wii.cpp) The [Wii](Wii.cpp) library support the Wiimote, but also the Nunchuch and Motion Plus extensions via Bluetooth. The Wii U Pro Controller is also supported via Bluetooth. @@ -308,4 +319,4 @@ See the "Interface modifications" section in the [hardware manual](https://www.c > When I plug my device into the USB connector nothing happens? * Try to connect a external power supply to the Arduino - this solves the problem in most cases. -* You can also use a powered hub between the device and the USB Host Shield. You should then include the USB hub library: ```#include ``` and create the instance like so: ```USBHub Hub1(&Usb);```. \ No newline at end of file +* You can also use a powered hub between the device and the USB Host Shield. You should then include the USB hub library: ```#include ``` and create the instance like so: ```USBHub Hub1(&Usb);```. diff --git a/XBOXONE.cpp b/XBOXONE.cpp new file mode 100644 index 00000000..8df3500e --- /dev/null +++ b/XBOXONE.cpp @@ -0,0 +1,359 @@ +/* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved. + Copyright (C) 2015 guruthree + + This software may be distributed and modified under the terms of the GNU + General Public License version 2 (GPL2) as published by the Free Software + Foundation and appearing in the file GPL2.TXT included in the packaging of + this file. Please note that GPL2 Section 2[b] requires that all works based + on this software must also be made publicly available under the terms of + the GPL2 ("Copyleft"). + + Contact information + ------------------- + + Kristian Lauszus, TKJ Electronics + Web : http://www.tkjelectronics.com + e-mail : kristianl@tkjelectronics.com + + guruthree + Web : https://github.com/guruthree/ + */ + +#include "XBOXONE.h" +// To enable serial debugging see "settings.h" +//#define EXTRADEBUG // Uncomment to get even more debugging data +//#define PRINTREPORT // Uncomment to print the report send by the Xbox ONE Controller + +XBOXONE::XBOXONE(USB *p) : +pUsb(p), // pointer to USB class instance - mandatory +bAddress(0), // device address - mandatory +bPollEnable(false) { // don't start polling before dongle is connected + for(uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) { + epInfo[i].epAddr = 0; + epInfo[i].maxPktSize = (i) ? 0 : 8; + epInfo[i].epAttribs = 0; + epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; + } + + if(pUsb) // register in USB subsystem + pUsb->RegisterDeviceClass(this); //set devConfig[] entry +} + +uint8_t XBOXONE::Init(uint8_t parent, uint8_t port, bool lowspeed) { + uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; + USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast(buf); + uint8_t rcode; + UsbDevice *p = NULL; + EpInfo *oldep_ptr = NULL; + uint16_t PID; + uint16_t VID; + + // get memory address of USB device address pool + AddressPool &addrPool = pUsb->GetAddressPool(); +#ifdef EXTRADEBUG + Notify(PSTR("\r\nXBOXONE Init"), 0x80); +#endif + // check if address has already been assigned to an instance + if(bAddress) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nAddress in use"), 0x80); +#endif + return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; + } + + // Get pointer to pseudo device with address 0 assigned + p = addrPool.GetUsbDevicePtr(0); + + if(!p) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nAddress not found"), 0x80); +#endif + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + } + + if(!p->epinfo) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nepinfo is null"), 0x80); +#endif + return USB_ERROR_EPINFO_IS_NULL; + } + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + + // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence + p->epinfo = epInfo; + + p->lowspeed = lowspeed; + + // Get device descriptor + rcode = pUsb->getDevDescr(0, 0, sizeof (USB_DEVICE_DESCRIPTOR), (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data + // Restore p->epinfo + p->epinfo = oldep_ptr; + + if(rcode) + goto FailGetDevDescr; + + VID = udd->idVendor; + PID = udd->idProduct; + + if(!VIDPIDOK(VID, PID)) // Check VID + goto FailUnknownDevice; + + // Allocate new address according to device class + bAddress = addrPool.AllocAddress(parent, false, port); + + if(!bAddress) + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + + // Extract Max Packet Size from device descriptor + epInfo[0].maxPktSize = udd->bMaxPacketSize0; + + // Assign new address to the device + rcode = pUsb->setAddr(0, 0, bAddress); + if(rcode) { + p->lowspeed = false; + addrPool.FreeAddress(bAddress); + bAddress = 0; +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nsetAddr: "), 0x80); + D_PrintHex (rcode, 0x80); +#endif + return rcode; + } +#ifdef EXTRADEBUG + Notify(PSTR("\r\nAddr: "), 0x80); + D_PrintHex (bAddress, 0x80); +#endif + //delay(300); // Spec says you should wait at least 200ms + + p->lowspeed = false; + + //get pointer to assigned address record + p = addrPool.GetUsbDevicePtr(bAddress); + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + p->lowspeed = lowspeed; + + // Assign epInfo to epinfo pointer - only EP0 is known + rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); + if(rcode) + goto FailSetDevTblEntry; + + /* The application will work in reduced host mode, so we can save program and data + memory space. After verifying the VID we will use known values for the + configuration values for device, interface, endpoints and HID for the XBOXONE Controllers */ + + /* Initialize data structures for endpoints of device */ + epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x01; // XBOX one output endpoint + epInfo[ XBOX_OUTPUT_PIPE ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; + epInfo[ XBOX_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints + epInfo[ XBOX_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE; + epInfo[ XBOX_OUTPUT_PIPE ].bmSndToggle = 0; + epInfo[ XBOX_OUTPUT_PIPE ].bmRcvToggle = 0; + epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01; // XBOX one input endpoint + epInfo[ XBOX_INPUT_PIPE ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; + epInfo[ XBOX_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints + epInfo[ XBOX_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE; + epInfo[ XBOX_INPUT_PIPE ].bmSndToggle = 0; + epInfo[ XBOX_INPUT_PIPE ].bmRcvToggle = 0; + + rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo); + if(rcode) + goto FailSetDevTblEntry; + + delay(200); // Give time for address change + + rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1); + if(rcode) + goto FailSetConfDescr; + +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nXbox One Controller Connected\r\n"), 0x80); +#endif + + delay(200); // let things settle + + // initialize the controller for input + writeBuf[0] = 0x05; + writeBuf[1] = 0x20; + rcode = XboxCommand(writeBuf, 2); + if (rcode) + goto Fail; + + onInit(); + XboxOneConnected = true; + bPollEnable = true; + return 0; // Successful configuration + + /* Diagnostic messages */ +FailGetDevDescr: +#ifdef DEBUG_USB_HOST + NotifyFailGetDevDescr(); + goto Fail; +#endif + +FailSetDevTblEntry: +#ifdef DEBUG_USB_HOST + NotifyFailSetDevTblEntry(); + goto Fail; +#endif + +FailSetConfDescr: +#ifdef DEBUG_USB_HOST + NotifyFailSetConfDescr(); +#endif + goto Fail; + +FailUnknownDevice: +#ifdef DEBUG_USB_HOST + NotifyFailUnknownDevice(VID, PID); +#endif + rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; + +Fail: +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nXbox One Init Failed, error code: "), 0x80); + NotifyFail(rcode); +#endif + Release(); + return rcode; +} + +/* Performs a cleanup after failed Init() attempt */ +uint8_t XBOXONE::Release() { + XboxOneConnected = false; + pUsb->GetAddressPool().FreeAddress(bAddress); + bAddress = 0; + bPollEnable = false; +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nXbox One Controller Disconnected\r\n"), 0x80); +#endif + return 0; +} + +uint8_t XBOXONE::Poll() { + if(!bPollEnable) + return 0; + uint16_t BUFFER_SIZE = EP_MAXPKTSIZE; + uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ XBOX_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); + if (!rcode) { + readReport(); +#ifdef PRINTREPORT + printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller +#endif + } +#ifdef DEBUG_USB_HOST + else if (rcode != 0x04) { // not a matter of no update to send + Notify(PSTR("\r\nXbox One Poll Failed, error code: "), 0x80); + NotifyFail(rcode); + } +#endif + return rcode; +} + +void XBOXONE::readReport() { + if(readBuf == NULL) + return; + if(readBuf[0] == 0x07) { + // The XBOX button has a seperate message + if (readBuf[4] == 1) { + ButtonState |= XBOX_BUTTONS[XBOX]; + } + else { + ButtonState &= XBOX_BUTTONS[XBOX]; + } + if(ButtonState != OldButtonState) { + ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable, but don't include the two trigger buttons L2 and R2 + OldButtonState = ButtonState; + } + } + if(readBuf[0] != 0x20) { // Check if it's the correct report, otherwise return - the controller also sends different status reports +#ifdef EXTRADEBUG + Notify(PSTR("\r\nXbox Poll: "), 0x80); + D_PrintHex (readBuf[0], 0x80); // 0x03 is a heart beat report! +#endif + return; + } + + uint16_t xbox = ButtonState & XBOX_BUTTONS[XBOX]; // since the XBOX button is seperate, save it and add it back in + // xbox button from before, dpad, abxy, start/back, sync, stick click, shoulder buttons + ButtonState = xbox | (((uint16_t)readBuf[5] & 0xF) << 8) | (readBuf[4] & 0xF0) | (((uint16_t)readBuf[4] & 0x0C) << 10) | ((readBuf[4] & 0x01) << 3) | (((uint16_t)readBuf[5] & 0xC0) << 8) | ((readBuf[5] & 0x30) >> 4); + + triggerValue[LeftTrigger] = (uint16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]); + triggerValue[RightTrigger] = (uint16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]); + + hatValue[LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]); + hatValue[LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]); + hatValue[RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]); + hatValue[RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]); + + //Notify(PSTR("\r\nButtonState"), 0x80); + //PrintHex(ButtonState, 0x80); + + if(ButtonState != OldButtonState) { + ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable + OldButtonState = ButtonState; + } +} + +void XBOXONE::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller +#ifdef PRINTREPORT + if(readBuf == NULL) + return; + for(uint8_t i = 0; i < XBOX_REPORT_BUFFER_SIZE; i++) { + D_PrintHex (readBuf[i], 0x80); + Notify(PSTR(" "), 0x80); + } + Notify(PSTR("\r\n"), 0x80); +#endif +} + +uint8_t XBOXONE::getButtonPress(ButtonEnum b) { + return (bool)(ButtonState & ((uint16_t)pgm_read_word(&XBOX_BUTTONS[(uint8_t)b]))); +} + +bool XBOXONE::getButtonClick(ButtonEnum b) { + uint16_t button = pgm_read_word(&XBOX_BUTTONS[(uint8_t)b]); + bool click = (ButtonClickState & button); + ButtonClickState &= ~button; // clear "click" event + return click; +} + +int16_t XBOXONE::getAnalogHat(AnalogHatEnum a) { + return hatValue[a]; +} + +uint16_t XBOXONE::getTrigger(TriggerEnum a) { + return triggerValue[a]; +} + +/* Xbox Controller commands */ +uint8_t XBOXONE::XboxCommand(uint8_t* data, uint16_t nbytes) { + uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ XBOX_OUTPUT_PIPE ].epAddr, nbytes, data); +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nXboxCommand, Return: "), 0x80); + D_PrintHex (rcode, 0x80); +#endif + return rcode; +} + +void XBOXONE::onInit() { + // a short buzz to show the controller is active + writeBuf[0] = 0x09; + writeBuf[1] = 0x08; + writeBuf[2] = 0x00; + writeBuf[3] = 0x09; + writeBuf[4] = 0x00; + writeBuf[5] = 0x0f; + writeBuf[6] = 0x04; + writeBuf[7] = 0x04; + writeBuf[8] = 0x20; + writeBuf[9] = 0x20; + writeBuf[10] = 0x80; + XboxCommand(writeBuf, 11); + + if(pFuncOnInit) + pFuncOnInit(); // Call the user function +} diff --git a/XBOXONE.h b/XBOXONE.h new file mode 100644 index 00000000..cbfe82ea --- /dev/null +++ b/XBOXONE.h @@ -0,0 +1,180 @@ +/* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved. + Copyright (C) 2015 guruthree + + This software may be distributed and modified under the terms of the GNU + General Public License version 2 (GPL2) as published by the Free Software + Foundation and appearing in the file GPL2.TXT included in the packaging of + this file. Please note that GPL2 Section 2[b] requires that all works based + on this software must also be made publicly available under the terms of + the GPL2 ("Copyleft"). + + Contact information + ------------------- + + Kristian Lauszus, TKJ Electronics + Web : http://www.tkjelectronics.com + e-mail : kristianl@tkjelectronics.com + + guruthree + Web : https://github.com/guruthree/ + */ + + +#ifndef _xboxone_h_ +#define _xboxone_h_ + +#include "Usb.h" +#include "xboxEnums.h" + +/* Data Xbox ONE taken from descriptors */ +#define EP_MAXPKTSIZE 32 // max size for data via USB + +/* Names we give to the 3 XboxONE pipes */ +#define XBOX_CONTROL_PIPE 0 +#define XBOX_OUTPUT_PIPE 1 +#define XBOX_INPUT_PIPE 2 + +// PID and VID of the different devices +#define XBOX_VID 0x045E // Microsoft Corporation +#define XBOX_ONE_PID 0x02D1 // Microsoft One Wired controller + +#define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer + +// Used in control endpoint header for HID Commands +#define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE +#define HID_REQUEST_SET_REPORT 0x09 + +#define XBOX_MAX_ENDPOINTS 3 + +/** This class implements support for a Xbox wired controller via USB. */ +class XBOXONE : public USBDeviceConfig { +public: + /** + * Constructor for the XBOXONE class. + * @param pUsb Pointer to USB class instance. + */ + XBOXONE(USB *pUsb); + + /** @name USBDeviceConfig implementation */ + /** + * Initialize the Xbox Controller. + * @param parent Hub number. + * @param port Port number on the hub. + * @param lowspeed Speed of the device. + * @return 0 on success. + */ + virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); + /** + * Release the USB device. + * @return 0 on success. + */ + virtual uint8_t Release(); + /** + * Poll the USB Input endpoins and run the state machines. + * @return 0 on success. + */ + virtual uint8_t Poll(); + + /** + * Get the device address. + * @return The device address. + */ + virtual uint8_t GetAddress() { + return bAddress; + }; + + /** + * Used to check if the controller has been initialized. + * @return True if it's ready. + */ + virtual bool isReady() { + return bPollEnable; + }; + + /** + * Used by the USB core to check what this driver support. + * @param vid The device's VID. + * @param pid The device's PID. + * @return Returns true if the device's VID and PID matches this driver. + */ + virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) { + return (vid == XBOX_VID && pid == XBOX_ONE_PID); + }; + /**@}*/ + + /** @name Xbox Controller functions */ + /** + * getButtonPress(ButtonEnum b) will return true as long as the button is held down. + * + * While getButtonClick(ButtonEnum b) will only return it once. + * + * So you instance if you need to increase a variable once you would use getButtonClick(ButtonEnum b), + * but if you need to drive a robot forward you would use getButtonPress(ButtonEnum b). + * @param b ::ButtonEnum to read. + * @return getButtonClick(ButtonEnum b) will return a bool, while getButtonPress(ButtonEnum b) will return a byte if reading ::L2 or ::R2. + */ + uint8_t getButtonPress(ButtonEnum b); + bool getButtonClick(ButtonEnum b); + + /** + * Return the analog value from the joysticks on the controller. + * @param a Either ::LeftHatX, ::LeftHatY, ::RightHatX or ::RightHatY. + * @return Returns a signed 16-bit integer. + */ + int16_t getAnalogHat(AnalogHatEnum a); + + /** @name Xbox Controller functions */ + /** + * Return the analog value from the triggers on the controller. + * @param a Either ::LeftTrigger, or ::RightTrigger. + * @return Returns an unsigned 16-bit integer. + */ + uint16_t getTrigger(TriggerEnum a); + + /** + * Used to call your own function when the controller is successfully initialized. + * @param funcOnInit Function to call. + */ + void attachOnInit(void (*funcOnInit)(void)) { + pFuncOnInit = funcOnInit; + }; + /**@}*/ + + /** True if a Xbox ONE controller is connected. */ + bool XboxOneConnected; + +protected: + /** Pointer to USB class instance. */ + USB *pUsb; + /** Device address. */ + uint8_t bAddress; + /** Endpoint info structure. */ + EpInfo epInfo[XBOX_MAX_ENDPOINTS]; + +private: + /** + * Called when the controller is successfully initialized. + * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. + */ + void onInit(); + void (*pFuncOnInit)(void); // Pointer to function called in onInit() + + bool bPollEnable; + + /* Variables to store the buttons */ + uint16_t ButtonState; + uint16_t OldButtonState; + uint16_t ButtonClickState; + int16_t hatValue[4]; + int16_t triggerValue[2]; + + uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data + uint8_t writeBuf[12]; // General purpose buffer for output data + + void readReport(); // read incoming data + void printReport(); // print incoming date - Uncomment for debugging + + /* Private commands */ + uint8_t XboxCommand(uint8_t* data, uint16_t nbytes); +}; +#endif diff --git a/controllerEnums.h b/controllerEnums.h index 0169c763..9d971f85 100644 --- a/controllerEnums.h +++ b/controllerEnums.h @@ -159,6 +159,14 @@ enum AnalogHatEnum { RightHatY = 3, }; +/** Triggers on Xbox One controller. */ +enum TriggerEnum { + /** Left trigger */ + LeftTrigger = 0, + /** Right trigger */ + RightTrigger = 1, +}; + /** * Sensors inside the Sixaxis Dualshock 3, Move controller and PS4 controller. * Note: that the location is shifted 9 when it's connected via USB on the PS3 controller. diff --git a/examples/Xbox/XBOXONE/XBOXONE.ino b/examples/Xbox/XBOXONE/XBOXONE.ino new file mode 100644 index 00000000..5e2c8d99 --- /dev/null +++ b/examples/Xbox/XBOXONE/XBOXONE.ino @@ -0,0 +1,110 @@ +/* + Example sketch for the Xbox ONE USB library - by guruthree, based on work by + Kristian Lauszus. + */ + +#include +// Satisfy IDE, which only needs to see the include statment in the ino. +#ifdef dobogusinclude +#include +#endif + +USB Usb; +XBOXONE Xbox(&Usb); + +void setup() { + Serial.begin(115200); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + if (Usb.Init() == -1) { + Serial.print(F("\r\nOSC did not start")); + while (1); //halt + } + Serial.print(F("\r\nXBOX USB Library Started")); +} +void loop() { + Usb.Task(); + if (Xbox.XboxOneConnected) { + + if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500 || Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500 || Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500 || Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { + if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) { + Serial.print(F("LeftHatX: ")); + Serial.print(Xbox.getAnalogHat(LeftHatX)); + Serial.print("\t"); + } + if (Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500) { + Serial.print(F("LeftHatY: ")); + Serial.print(Xbox.getAnalogHat(LeftHatY)); + Serial.print("\t"); + } + if (Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500) { + Serial.print(F("RightHatX: ")); + Serial.print(Xbox.getAnalogHat(RightHatX)); + Serial.print("\t"); + } + if (Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { + Serial.print(F("RightHatY: ")); + Serial.print(Xbox.getAnalogHat(RightHatY)); + } + Serial.println(); + } + + if (Xbox.getTrigger(LeftTrigger) > 0 || Xbox.getTrigger(RightTrigger) > 0) { + if (Xbox.getTrigger(LeftTrigger) > 0) { + Serial.print(F("LeftTrigger: ")); + Serial.print(Xbox.getTrigger(LeftTrigger)); + Serial.print("\t"); + } + if (Xbox.getTrigger(RightTrigger) > 0) { + Serial.print(F("RightTrigger: ")); + Serial.print(Xbox.getTrigger(RightTrigger)); + Serial.print("\t"); + } + Serial.println(); + } + + if (Xbox.getButtonClick(UP)) { + Serial.println(F("Up")); + } + if (Xbox.getButtonClick(DOWN)) { + Serial.println(F("Down")); + } + if (Xbox.getButtonClick(LEFT)) { + Serial.println(F("Left")); + } + if (Xbox.getButtonClick(RIGHT)) { + Serial.println(F("Right")); + } + + if (Xbox.getButtonClick(START)) { + Serial.println(F("Start")); + } + if (Xbox.getButtonClick(BACK)) { + Serial.println(F("Back")); + } + if (Xbox.getButtonClick(L3)) + Serial.println(F("L3")); + if (Xbox.getButtonClick(R3)) + Serial.println(F("R3")); + + if (Xbox.getButtonClick(L1)) + Serial.println(F("L1")); + if (Xbox.getButtonClick(R1)) + Serial.println(F("R1")); + if (Xbox.getButtonClick(XBOX)) { + Serial.println(F("Xbox")); + } + if (Xbox.getButtonClick(SYNC)) { + Serial.println(F("Sync")); + } + + if (Xbox.getButtonClick(A)) + Serial.println(F("A")); + if (Xbox.getButtonClick(B)) + Serial.println(F("B")); + if (Xbox.getButtonClick(X)) + Serial.println(F("X")); + if (Xbox.getButtonClick(Y)) + Serial.println(F("Y")); + } + delay(1); +} diff --git a/keywords.txt b/keywords.txt index c7bd007c..0d4469a6 100644 --- a/keywords.txt +++ b/keywords.txt @@ -56,6 +56,7 @@ get9DOFValues KEYWORD2 getStatus KEYWORD2 printStatusString KEYWORD2 getTemperature KEYWORD2 +getTrigger KEYWORD2 disconnect KEYWORD2 setAllOff KEYWORD2 @@ -139,6 +140,9 @@ LeftHatY LITERAL1 RightHatX LITERAL1 RightHatY LITERAL1 +LeftTrigger LITERAL1 +RightTrigger LITERAL1 + aX LITERAL1 aY LITERAL1 aZ LITERAL1 @@ -192,6 +196,7 @@ RumbleLow LITERAL1 #################################################### XBOXUSB KEYWORD1 +XBOXONE KEYWORD1 XBOXOLD KEYWORD1 XBOXRECV KEYWORD1 @@ -207,6 +212,7 @@ buttonChanged KEYWORD2 XboxReceiverConnected KEYWORD2 Xbox360Connected KEYWORD2 +XboxOneConnected KEYWORD2 #################################################### # Constants and enums (LITERAL1) From 2d4ab30005c996bed248ad0973ba9e6318338276 Mon Sep 17 00:00:00 2001 From: Fred Date: Sat, 14 Feb 2015 11:15:29 +0000 Subject: [PATCH 012/220] Fixed tabbing... --- XBOXONE.cpp | 66 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/XBOXONE.cpp b/XBOXONE.cpp index 8df3500e..4e54e240 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -239,16 +239,16 @@ uint8_t XBOXONE::Poll() { uint16_t BUFFER_SIZE = EP_MAXPKTSIZE; uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ XBOX_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); if (!rcode) { - readReport(); + readReport(); #ifdef PRINTREPORT - printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller + printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox ONE Controller #endif } #ifdef DEBUG_USB_HOST - else if (rcode != 0x04) { // not a matter of no update to send - Notify(PSTR("\r\nXbox One Poll Failed, error code: "), 0x80); - NotifyFail(rcode); - } + else if (rcode != 0x04) { // not a matter of no update to send + Notify(PSTR("\r\nXbox One Poll Failed, error code: "), 0x80); + NotifyFail(rcode); + } #endif return rcode; } @@ -257,22 +257,22 @@ void XBOXONE::readReport() { if(readBuf == NULL) return; if(readBuf[0] == 0x07) { - // The XBOX button has a seperate message - if (readBuf[4] == 1) { - ButtonState |= XBOX_BUTTONS[XBOX]; - } - else { - ButtonState &= XBOX_BUTTONS[XBOX]; - } - if(ButtonState != OldButtonState) { - ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable, but don't include the two trigger buttons L2 and R2 - OldButtonState = ButtonState; - } + // The XBOX button has a seperate message + if (readBuf[4] == 1) { + ButtonState |= XBOX_BUTTONS[XBOX]; + } + else { + ButtonState &= XBOX_BUTTONS[XBOX]; + } + if(ButtonState != OldButtonState) { + ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable, but don't include the two trigger buttons L2 and R2 + OldButtonState = ButtonState; + } } if(readBuf[0] != 0x20) { // Check if it's the correct report, otherwise return - the controller also sends different status reports #ifdef EXTRADEBUG - Notify(PSTR("\r\nXbox Poll: "), 0x80); - D_PrintHex (readBuf[0], 0x80); // 0x03 is a heart beat report! + Notify(PSTR("\r\nXbox Poll: "), 0x80); + D_PrintHex (readBuf[0], 0x80); // 0x03 is a heart beat report! #endif return; } @@ -298,7 +298,7 @@ void XBOXONE::readReport() { } } -void XBOXONE::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller +void XBOXONE::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox ONE Controller #ifdef PRINTREPORT if(readBuf == NULL) return; @@ -336,22 +336,22 @@ uint8_t XBOXONE::XboxCommand(uint8_t* data, uint16_t nbytes) { Notify(PSTR("\r\nXboxCommand, Return: "), 0x80); D_PrintHex (rcode, 0x80); #endif - return rcode; + return rcode; } void XBOXONE::onInit() { - // a short buzz to show the controller is active - writeBuf[0] = 0x09; - writeBuf[1] = 0x08; - writeBuf[2] = 0x00; - writeBuf[3] = 0x09; - writeBuf[4] = 0x00; - writeBuf[5] = 0x0f; - writeBuf[6] = 0x04; - writeBuf[7] = 0x04; - writeBuf[8] = 0x20; - writeBuf[9] = 0x20; - writeBuf[10] = 0x80; + // a short buzz to show the controller is active + writeBuf[0] = 0x09; + writeBuf[1] = 0x08; + writeBuf[2] = 0x00; + writeBuf[3] = 0x09; + writeBuf[4] = 0x00; + writeBuf[5] = 0x0f; + writeBuf[6] = 0x04; + writeBuf[7] = 0x04; + writeBuf[8] = 0x20; + writeBuf[9] = 0x20; + writeBuf[10] = 0x80; XboxCommand(writeBuf, 11); if(pFuncOnInit) From 519e2a530906342aec692016f9bf9801f02116df Mon Sep 17 00:00:00 2001 From: Fred Date: Sun, 15 Feb 2015 17:56:20 +0000 Subject: [PATCH 013/220] cleanup --- XBOXONE.h | 4 ---- examples/Xbox/XBOXONE/XBOXONE.ino | 1 - 2 files changed, 5 deletions(-) diff --git a/XBOXONE.h b/XBOXONE.h index cbfe82ea..6b6a349f 100644 --- a/XBOXONE.h +++ b/XBOXONE.h @@ -40,10 +40,6 @@ #define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer -// Used in control endpoint header for HID Commands -#define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE -#define HID_REQUEST_SET_REPORT 0x09 - #define XBOX_MAX_ENDPOINTS 3 /** This class implements support for a Xbox wired controller via USB. */ diff --git a/examples/Xbox/XBOXONE/XBOXONE.ino b/examples/Xbox/XBOXONE/XBOXONE.ino index 5e2c8d99..83c5397f 100644 --- a/examples/Xbox/XBOXONE/XBOXONE.ino +++ b/examples/Xbox/XBOXONE/XBOXONE.ino @@ -24,7 +24,6 @@ void setup() { void loop() { Usb.Task(); if (Xbox.XboxOneConnected) { - if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500 || Xbox.getAnalogHat(LeftHatY) > 7500 || Xbox.getAnalogHat(LeftHatY) < -7500 || Xbox.getAnalogHat(RightHatX) > 7500 || Xbox.getAnalogHat(RightHatX) < -7500 || Xbox.getAnalogHat(RightHatY) > 7500 || Xbox.getAnalogHat(RightHatY) < -7500) { if (Xbox.getAnalogHat(LeftHatX) > 7500 || Xbox.getAnalogHat(LeftHatX) < -7500) { Serial.print(F("LeftHatX: ")); From 9979e50426b0de177891cfec87aca75cbfe46ea2 Mon Sep 17 00:00:00 2001 From: Fred Date: Sun, 15 Feb 2015 19:47:06 +0000 Subject: [PATCH 014/220] LeftTrigger/RightTrigger => L2/R2 for consistency --- XBOXONE.cpp | 36 ++++++++++++++++---- XBOXONE.h | 18 ++++------ controllerEnums.h | 8 ----- examples/Xbox/XBOXONE/XBOXONE.ino | 55 +++++++++++++++---------------- keywords.txt | 5 +-- 5 files changed, 63 insertions(+), 59 deletions(-) diff --git a/XBOXONE.cpp b/XBOXONE.cpp index 4e54e240..69e1a40e 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -281,8 +281,8 @@ void XBOXONE::readReport() { // xbox button from before, dpad, abxy, start/back, sync, stick click, shoulder buttons ButtonState = xbox | (((uint16_t)readBuf[5] & 0xF) << 8) | (readBuf[4] & 0xF0) | (((uint16_t)readBuf[4] & 0x0C) << 10) | ((readBuf[4] & 0x01) << 3) | (((uint16_t)readBuf[5] & 0xC0) << 8) | ((readBuf[5] & 0x30) >> 4); - triggerValue[LeftTrigger] = (uint16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]); - triggerValue[RightTrigger] = (uint16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]); + triggerValue[0] = (uint16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]); + triggerValue[1] = (uint16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]); hatValue[LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]); hatValue[LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]); @@ -296,6 +296,15 @@ void XBOXONE::readReport() { ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable OldButtonState = ButtonState; } + + if (triggerValue[0] != triggerValueOld[0]) { + triggerValueOld[0] = triggerValue[0]; + L2Clicked = true; + } + if (triggerValue[1] != triggerValueOld[1]) { + triggerValueOld[1] = triggerValue[1]; + R2Clicked = true; + } } void XBOXONE::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox ONE Controller @@ -310,11 +319,28 @@ void XBOXONE::printReport() { //Uncomment "#define PRINTREPORT" to print the rep #endif } -uint8_t XBOXONE::getButtonPress(ButtonEnum b) { +uint16_t XBOXONE::getButtonPress(ButtonEnum b) { + if(b == L2) // These are analog buttons + return triggerValue[0]; + else if(b == R2) + return triggerValue[1]; return (bool)(ButtonState & ((uint16_t)pgm_read_word(&XBOX_BUTTONS[(uint8_t)b]))); } bool XBOXONE::getButtonClick(ButtonEnum b) { + if(b == L2) { + if(L2Clicked) { + L2Clicked = false; + return true; + } + return false; + } else if(b == R2) { + if(R2Clicked) { + R2Clicked = false; + return true; + } + return false; + } uint16_t button = pgm_read_word(&XBOX_BUTTONS[(uint8_t)b]); bool click = (ButtonClickState & button); ButtonClickState &= ~button; // clear "click" event @@ -325,10 +351,6 @@ int16_t XBOXONE::getAnalogHat(AnalogHatEnum a) { return hatValue[a]; } -uint16_t XBOXONE::getTrigger(TriggerEnum a) { - return triggerValue[a]; -} - /* Xbox Controller commands */ uint8_t XBOXONE::XboxCommand(uint8_t* data, uint16_t nbytes) { uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ XBOX_OUTPUT_PIPE ].epAddr, nbytes, data); diff --git a/XBOXONE.h b/XBOXONE.h index 6b6a349f..7fab80ac 100644 --- a/XBOXONE.h +++ b/XBOXONE.h @@ -42,7 +42,7 @@ #define XBOX_MAX_ENDPOINTS 3 -/** This class implements support for a Xbox wired controller via USB. */ +/** This class implements support for a Xbox ONE controller connected via USB. */ class XBOXONE : public USBDeviceConfig { public: /** @@ -107,9 +107,9 @@ public: * So you instance if you need to increase a variable once you would use getButtonClick(ButtonEnum b), * but if you need to drive a robot forward you would use getButtonPress(ButtonEnum b). * @param b ::ButtonEnum to read. - * @return getButtonClick(ButtonEnum b) will return a bool, while getButtonPress(ButtonEnum b) will return a byte if reading ::L2 or ::R2. + * @return getButtonClick(ButtonEnum b) will return a bool, while getButtonPress(ButtonEnum b) will return a word if reading ::L2 or ::R2. */ - uint8_t getButtonPress(ButtonEnum b); + uint16_t getButtonPress(ButtonEnum b); bool getButtonClick(ButtonEnum b); /** @@ -119,14 +119,6 @@ public: */ int16_t getAnalogHat(AnalogHatEnum a); - /** @name Xbox Controller functions */ - /** - * Return the analog value from the triggers on the controller. - * @param a Either ::LeftTrigger, or ::RightTrigger. - * @return Returns an unsigned 16-bit integer. - */ - uint16_t getTrigger(TriggerEnum a); - /** * Used to call your own function when the controller is successfully initialized. * @param funcOnInit Function to call. @@ -163,6 +155,10 @@ private: uint16_t ButtonClickState; int16_t hatValue[4]; int16_t triggerValue[2]; + int16_t triggerValueOld[2]; + + bool L2Clicked; // These buttons are analog, so we use we use these bools to check if they where clicked or not + bool R2Clicked; uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data uint8_t writeBuf[12]; // General purpose buffer for output data diff --git a/controllerEnums.h b/controllerEnums.h index 9d971f85..0169c763 100644 --- a/controllerEnums.h +++ b/controllerEnums.h @@ -159,14 +159,6 @@ enum AnalogHatEnum { RightHatY = 3, }; -/** Triggers on Xbox One controller. */ -enum TriggerEnum { - /** Left trigger */ - LeftTrigger = 0, - /** Right trigger */ - RightTrigger = 1, -}; - /** * Sensors inside the Sixaxis Dualshock 3, Move controller and PS4 controller. * Note: that the location is shifted 9 when it's connected via USB on the PS3 controller. diff --git a/examples/Xbox/XBOXONE/XBOXONE.ino b/examples/Xbox/XBOXONE/XBOXONE.ino index 83c5397f..9526f53d 100644 --- a/examples/Xbox/XBOXONE/XBOXONE.ino +++ b/examples/Xbox/XBOXONE/XBOXONE.ino @@ -47,54 +47,51 @@ void loop() { Serial.println(); } - if (Xbox.getTrigger(LeftTrigger) > 0 || Xbox.getTrigger(RightTrigger) > 0) { - if (Xbox.getTrigger(LeftTrigger) > 0) { - Serial.print(F("LeftTrigger: ")); - Serial.print(Xbox.getTrigger(LeftTrigger)); + if (Xbox.getButtonPress(L2) > 0 || Xbox.getButtonPress(R2) > 0) { + if (Xbox.getButtonPress(L2) > 0) { + Serial.print(F("L2: ")); + Serial.print(Xbox.getButtonPress(L2)); Serial.print("\t"); } - if (Xbox.getTrigger(RightTrigger) > 0) { - Serial.print(F("RightTrigger: ")); - Serial.print(Xbox.getTrigger(RightTrigger)); + if (Xbox.getButtonPress(R2) > 0) { + Serial.print(F("R2: ")); + Serial.print(Xbox.getButtonPress(R2)); Serial.print("\t"); } Serial.println(); } - if (Xbox.getButtonClick(UP)) { + if (Xbox.getButtonClick(UP)) Serial.println(F("Up")); - } - if (Xbox.getButtonClick(DOWN)) { + if (Xbox.getButtonClick(DOWN)) Serial.println(F("Down")); - } - if (Xbox.getButtonClick(LEFT)) { + if (Xbox.getButtonClick(LEFT)) Serial.println(F("Left")); - } - if (Xbox.getButtonClick(RIGHT)) { + if (Xbox.getButtonClick(RIGHT)) Serial.println(F("Right")); - } - if (Xbox.getButtonClick(START)) { + if (Xbox.getButtonClick(START)) Serial.println(F("Start")); - } - if (Xbox.getButtonClick(BACK)) { + if (Xbox.getButtonClick(BACK)) Serial.println(F("Back")); - } - if (Xbox.getButtonClick(L3)) - Serial.println(F("L3")); - if (Xbox.getButtonClick(R3)) - Serial.println(F("R3")); + if (Xbox.getButtonClick(XBOX)) + Serial.println(F("Xbox")); + if (Xbox.getButtonClick(SYNC)) + Serial.println(F("Sync")); if (Xbox.getButtonClick(L1)) Serial.println(F("L1")); if (Xbox.getButtonClick(R1)) Serial.println(F("R1")); - if (Xbox.getButtonClick(XBOX)) { - Serial.println(F("Xbox")); - } - if (Xbox.getButtonClick(SYNC)) { - Serial.println(F("Sync")); - } + if (Xbox.getButtonClick(L2)) + Serial.println(F("L2")); + if (Xbox.getButtonClick(R2)) + Serial.println(F("R2")); + if (Xbox.getButtonClick(L3)) + Serial.println(F("L3")); + if (Xbox.getButtonClick(R3)) + Serial.println(F("R3")); + if (Xbox.getButtonClick(A)) Serial.println(F("A")); diff --git a/keywords.txt b/keywords.txt index 0d4469a6..2d3931dc 100644 --- a/keywords.txt +++ b/keywords.txt @@ -140,9 +140,6 @@ LeftHatY LITERAL1 RightHatX LITERAL1 RightHatY LITERAL1 -LeftTrigger LITERAL1 -RightTrigger LITERAL1 - aX LITERAL1 aY LITERAL1 aZ LITERAL1 @@ -364,4 +361,4 @@ RED LITERAL1 YELLOW LITERAL1 GREEN LITERAL1 ORANGE LITERAL1 -BLUE LITERAL1 \ No newline at end of file +BLUE LITERAL1 From 199612e93e8d1a956a8876560030818f76b67acd Mon Sep 17 00:00:00 2001 From: Fred Date: Sun, 15 Feb 2015 19:56:17 +0000 Subject: [PATCH 015/220] bug fix: would only detect first XBOX button press --- XBOXONE.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/XBOXONE.cpp b/XBOXONE.cpp index 69e1a40e..9be283a0 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -262,10 +262,10 @@ void XBOXONE::readReport() { ButtonState |= XBOX_BUTTONS[XBOX]; } else { - ButtonState &= XBOX_BUTTONS[XBOX]; + ButtonState &= ~XBOX_BUTTONS[XBOX]; } if(ButtonState != OldButtonState) { - ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable, but don't include the two trigger buttons L2 and R2 + ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable OldButtonState = ButtonState; } } @@ -296,7 +296,7 @@ void XBOXONE::readReport() { ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable OldButtonState = ButtonState; } - + // handle click detection for triggers if (triggerValue[0] != triggerValueOld[0]) { triggerValueOld[0] = triggerValue[0]; L2Clicked = true; From 22d82ecd0a328b6a45c59133dd48aaf3c57e22b6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 3 Mar 2015 19:08:39 +0100 Subject: [PATCH 016/220] SPI library was added twice after merge - see: c39e8a180cf0d7a1b1d75055730e0b555fa2dedb --- examples/Bluetooth/BTHID/BTHID.ino | 4 ++-- examples/Bluetooth/PS3BT/PS3BT.ino | 4 ++-- examples/Bluetooth/PS3Multi/PS3Multi.ino | 4 ++-- examples/Bluetooth/PS3SPP/PS3SPP.ino | 4 ++-- examples/Bluetooth/PS4BT/PS4BT.ino | 4 ++-- examples/Bluetooth/SPP/SPP.ino | 4 ++-- examples/Bluetooth/Wii/Wii.ino | 4 ++-- examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino | 4 ++-- examples/Bluetooth/WiiMulti/WiiMulti.ino | 4 ++-- examples/Bluetooth/WiiUProController/WiiUProController.ino | 4 ++-- examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino | 4 ++-- .../HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino | 6 +----- examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino | 4 ++-- examples/HID/USBHIDJoystick/USBHIDJoystick.ino | 6 +----- examples/HID/USBHID_desc/USBHID_desc.ino | 4 ++-- examples/HID/le3dp/le3dp.ino | 4 ++-- examples/HID/scale/scale.ino | 4 ++-- examples/PS3USB/PS3USB.ino | 4 ++-- examples/PS4USB/PS4USB.ino | 4 ++-- examples/PSBuzz/PSBuzz.ino | 4 ++-- examples/USB_desc/USB_desc.ino | 4 ++-- examples/Xbox/XBOXOLD/XBOXOLD.ino | 4 ++-- examples/Xbox/XBOXRECV/XBOXRECV.ino | 4 ++-- examples/Xbox/XBOXUSB/XBOXUSB.ino | 4 ++-- examples/acm/acm_terminal/acm_terminal.ino | 4 ++-- examples/adk/adk_barcode/adk_barcode.ino | 6 +----- examples/adk/demokit_20/demokit_20.ino | 6 +----- examples/adk/term_test/term_test.ino | 6 +----- examples/adk/term_time/term_time.ino | 6 +----- examples/board_qc/board_qc.ino | 4 ++-- examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino | 4 ++-- examples/hub_demo/hub_demo.ino | 4 ++-- examples/max_LCD/max_LCD.ino | 6 +----- .../pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino | 4 ++-- examples/pl2303/pl2303_gps/pl2303_gps.ino | 4 ++-- examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino | 4 ++-- .../pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino | 4 ++-- examples/testusbhostFAT/testusbhostFAT.ino | 0 38 files changed, 67 insertions(+), 95 deletions(-) mode change 100644 => 100755 examples/testusbhostFAT/testusbhostFAT.ino diff --git a/examples/Bluetooth/BTHID/BTHID.ino b/examples/Bluetooth/BTHID/BTHID.ino index a5b0c0ed..919a5646 100644 --- a/examples/Bluetooth/BTHID/BTHID.ino +++ b/examples/Bluetooth/BTHID/BTHID.ino @@ -9,8 +9,8 @@ #include "KeyboardParser.h" #include "MouseParser.h" -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index e9c98341..b8967344 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -7,8 +7,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index fda21616..5ebfd781 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -8,8 +8,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index 46f6cf10..8f234cbd 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -13,8 +13,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Bluetooth/PS4BT/PS4BT.ino b/examples/Bluetooth/PS4BT/PS4BT.ino index bee617e3..c3ba696b 100644 --- a/examples/Bluetooth/PS4BT/PS4BT.ino +++ b/examples/Bluetooth/PS4BT/PS4BT.ino @@ -7,8 +7,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Bluetooth/SPP/SPP.ino b/examples/Bluetooth/SPP/SPP.ino index f67367ea..8fb9c4ec 100644 --- a/examples/Bluetooth/SPP/SPP.ino +++ b/examples/Bluetooth/SPP/SPP.ino @@ -7,8 +7,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Bluetooth/Wii/Wii.ino b/examples/Bluetooth/Wii/Wii.ino index 85f2151f..b1935681 100644 --- a/examples/Bluetooth/Wii/Wii.ino +++ b/examples/Bluetooth/Wii/Wii.ino @@ -7,8 +7,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino index c2f10c08..573b8bd4 100644 --- a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino +++ b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino @@ -14,8 +14,8 @@ Otherwise, wire up a IR LED yourself. #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Bluetooth/WiiMulti/WiiMulti.ino b/examples/Bluetooth/WiiMulti/WiiMulti.ino index 89baf920..07c6f13d 100644 --- a/examples/Bluetooth/WiiMulti/WiiMulti.ino +++ b/examples/Bluetooth/WiiMulti/WiiMulti.ino @@ -8,8 +8,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Bluetooth/WiiUProController/WiiUProController.ino b/examples/Bluetooth/WiiUProController/WiiUProController.ino index f1e105b9..ab35a274 100644 --- a/examples/Bluetooth/WiiUProController/WiiUProController.ino +++ b/examples/Bluetooth/WiiUProController/WiiUProController.ino @@ -7,8 +7,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino index 0f6b1f64..48b33abf 100644 --- a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino +++ b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino @@ -1,8 +1,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino index dbb2bb4b..5fc8c96f 100644 --- a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -1,16 +1,12 @@ #include #include + // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include #include #endif -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include -#include -#endif - class MouseRptParser : public MouseReportParser { protected: diff --git a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino index aa1add0c..53102512 100644 --- a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino +++ b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino @@ -1,8 +1,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino index 335ecea3..956441d6 100644 --- a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino +++ b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino @@ -1,6 +1,7 @@ #include #include #include + // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include @@ -9,11 +10,6 @@ #include "hidjoystickrptparser.h" -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include -#include -#endif - USB Usb; USBHub Hub(&Usb); HIDUniversal Hid(&Usb); diff --git a/examples/HID/USBHID_desc/USBHID_desc.ino b/examples/HID/USBHID_desc/USBHID_desc.ino index 588f1eff..85cfc19a 100644 --- a/examples/HID/USBHID_desc/USBHID_desc.ino +++ b/examples/HID/USBHID_desc/USBHID_desc.ino @@ -4,8 +4,8 @@ #include #include "pgmstrings.h" -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/HID/le3dp/le3dp.ino b/examples/HID/le3dp/le3dp.ino index eefd9d79..837d7f5a 100644 --- a/examples/HID/le3dp/le3dp.ino +++ b/examples/HID/le3dp/le3dp.ino @@ -6,8 +6,8 @@ #include "le3dp_rptparser.h" -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/HID/scale/scale.ino b/examples/HID/scale/scale.ino index 283266b7..f26ff964 100644 --- a/examples/HID/scale/scale.ino +++ b/examples/HID/scale/scale.ino @@ -7,8 +7,8 @@ #include "scale_rptparser.h" -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index 0a7c4f44..a53dcfbe 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -6,8 +6,8 @@ #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/PS4USB/PS4USB.ino b/examples/PS4USB/PS4USB.ino index 87c611ca..d0d76790 100644 --- a/examples/PS4USB/PS4USB.ino +++ b/examples/PS4USB/PS4USB.ino @@ -6,8 +6,8 @@ #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/PSBuzz/PSBuzz.ino b/examples/PSBuzz/PSBuzz.ino index 06e0afaa..6ee462c1 100644 --- a/examples/PSBuzz/PSBuzz.ino +++ b/examples/PSBuzz/PSBuzz.ino @@ -6,8 +6,8 @@ #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index 275224e2..0ae15663 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -2,8 +2,8 @@ #include "pgmstrings.h" -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Xbox/XBOXOLD/XBOXOLD.ino b/examples/Xbox/XBOXOLD/XBOXOLD.ino index b00e1ea4..64a3ed61 100644 --- a/examples/Xbox/XBOXOLD/XBOXOLD.ino +++ b/examples/Xbox/XBOXOLD/XBOXOLD.ino @@ -7,8 +7,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Xbox/XBOXRECV/XBOXRECV.ino b/examples/Xbox/XBOXRECV/XBOXRECV.ino index f4c0af42..491b287e 100644 --- a/examples/Xbox/XBOXRECV/XBOXRECV.ino +++ b/examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -7,8 +7,8 @@ #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/Xbox/XBOXUSB/XBOXUSB.ino b/examples/Xbox/XBOXUSB/XBOXUSB.ino index 500ba53d..8a5691c6 100644 --- a/examples/Xbox/XBOXUSB/XBOXUSB.ino +++ b/examples/Xbox/XBOXUSB/XBOXUSB.ino @@ -6,8 +6,8 @@ #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/acm/acm_terminal/acm_terminal.ino b/examples/acm/acm_terminal/acm_terminal.ino index 9d1b7928..f509cda8 100644 --- a/examples/acm/acm_terminal/acm_terminal.ino +++ b/examples/acm/acm_terminal/acm_terminal.ino @@ -3,8 +3,8 @@ #include "pgmstrings.h" -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/adk/adk_barcode/adk_barcode.ino b/examples/adk/adk_barcode/adk_barcode.ino index f6c6609b..a308ff0f 100644 --- a/examples/adk/adk_barcode/adk_barcode.ino +++ b/examples/adk/adk_barcode/adk_barcode.ino @@ -4,17 +4,13 @@ #include #include #include + // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include #include #endif -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include -#include -#endif - USB Usb; USBHub Hub1(&Usb); USBHub Hub2(&Usb); diff --git a/examples/adk/demokit_20/demokit_20.ino b/examples/adk/demokit_20/demokit_20.ino index 7d7ce4c8..f65adf57 100644 --- a/examples/adk/demokit_20/demokit_20.ino +++ b/examples/adk/demokit_20/demokit_20.ino @@ -1,16 +1,12 @@ #include #include + // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include #include #endif -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include -#include -#endif - USB Usb; USBHub hub0(&Usb); USBHub hub1(&Usb); diff --git a/examples/adk/term_test/term_test.ino b/examples/adk/term_test/term_test.ino index 8feee494..db681c3b 100644 --- a/examples/adk/term_test/term_test.ino +++ b/examples/adk/term_test/term_test.ino @@ -1,16 +1,12 @@ #include #include + // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include #include #endif -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include -#include -#endif - USB Usb; //USBHub Hub(&Usb); diff --git a/examples/adk/term_time/term_time.ino b/examples/adk/term_time/term_time.ino index 33a2e5aa..a3f1dbc8 100644 --- a/examples/adk/term_time/term_time.ino +++ b/examples/adk/term_time/term_time.ino @@ -1,16 +1,12 @@ #include #include + // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include #include #endif -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include -#include -#endif - USB Usb; ADK adk(&Usb,"Circuits@Home, ltd.", diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index e18f163e..2d8529e4 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -5,8 +5,8 @@ /**/ #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include <../../../../hardware/pic32/libraries/SPI/SPI.h> // Hack to use the SPI library #include // Hack to use the SPI library diff --git a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino index dbf95f3c..5be7adc2 100644 --- a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino +++ b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino @@ -3,8 +3,8 @@ #include "pgmstrings.h" -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index 5738babc..20685067 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -1,8 +1,8 @@ #include #include "pgmstrings.h" -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/max_LCD/max_LCD.ino b/examples/max_LCD/max_LCD.ino index 9f2000bc..6603ab90 100644 --- a/examples/max_LCD/max_LCD.ino +++ b/examples/max_LCD/max_LCD.ino @@ -4,17 +4,13 @@ // pinout: D[4-7] -> GPOUT[4-7], RS-> GPOUT[2], E ->GPOUT[3] #include + // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include #include #endif -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include -#include -#endif - USB Usb; Max_LCD lcd(&Usb); diff --git a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino index 81ad0c54..7c4c9f6c 100644 --- a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino +++ b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino @@ -5,8 +5,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/pl2303/pl2303_gps/pl2303_gps.ino b/examples/pl2303/pl2303_gps/pl2303_gps.ino index 25b4ae54..e8c8a022 100644 --- a/examples/pl2303/pl2303_gps/pl2303_gps.ino +++ b/examples/pl2303/pl2303_gps/pl2303_gps.ino @@ -6,8 +6,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index 3266b69f..d527eabe 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -12,8 +12,8 @@ #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino index d9d9b98c..67b7dab6 100644 --- a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino +++ b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino @@ -6,8 +6,8 @@ #include #include -#ifdef dobogusinclude // Satisfy the IDE, which needs to see the include statment in the ino too. -#include +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude #include #include #endif diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino old mode 100644 new mode 100755 From a9dd1125020f4817ad4904ea73cc5843f7643f51 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 3 Mar 2015 19:10:46 +0100 Subject: [PATCH 017/220] Update submodules --- examples/testusbhostFAT/Arduino_Makefile_master | 2 +- examples/testusbhostFAT/RTClib | 2 +- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master index 7ada91a9..94c560c8 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit 7ada91a90027ccb7558b74087fb68d3940ecf64d +Subproject commit 94c560c854c7a1dfc35e9de9db05de1b202de6c6 diff --git a/examples/testusbhostFAT/RTClib b/examples/testusbhostFAT/RTClib index b119b97e..c30fcdf1 160000 --- a/examples/testusbhostFAT/RTClib +++ b/examples/testusbhostFAT/RTClib @@ -1 +1 @@ -Subproject commit b119b97e1484a08aebcf24e070113d78c82fb023 +Subproject commit c30fcdf1f112de581de7b145a97630539e5cff44 diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index 72b5bf46..9233df8b 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit 72b5bf467a1c2479ba7354ee4d864e382c167425 +Subproject commit 9233df8bc2cd0c16d363c8e298398b6eaefad257 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index 2bf8f633..77b03342 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit 2bf8f633e7f9bc5a7bf4c00f3f45c7b79484198e +Subproject commit 77b033420485f7d3d35430c0e8d4d844aa894834 From 5d3356c784bc420b31c457ed0b8d10b34028e14c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 3 Mar 2015 19:20:27 +0100 Subject: [PATCH 018/220] Set Arduino minimum version to 1.6.0, as SPI multibyte transfer were missing for sam until then See: https://github.com/arduino/Arduino/commit/6a5b82f062f1c28472cfe2015416246808f77264 --- settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.h b/settings.h index e5e5a5ba..42e5fda3 100644 --- a/settings.h +++ b/settings.h @@ -129,7 +129,7 @@ e-mail : support@circuitsathome.com #define USING_SPI4TEENSY3 0 #endif -#if ((defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822) || ARDUINO >= 158) && !USING_SPI4TEENSY3 +#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 #endif #if defined(__PIC32MX__) || defined(__PIC32MZ__) From d19d78f940d6249f41ecbd7987284d86d26ff88c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 3 Mar 2015 19:22:43 +0100 Subject: [PATCH 019/220] Always favour SPI library if it has transactions --- usbhost.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usbhost.h b/usbhost.h index 9572154c..0bd5c6ef 100644 --- a/usbhost.h +++ b/usbhost.h @@ -246,7 +246,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { #endif SPI_SS::Clear(); -#if !defined(SPDR) +#if !defined(SPDR) || SPI_HAS_TRANSACTION SPI.transfer(reg); uint8_t rv = SPI.transfer(0); // Send empty byte SPI_SS::Set(); From 2dfca7d936e985b4dd3fab4cc609fbcac0a7bc16 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 3 Mar 2015 20:00:28 +0100 Subject: [PATCH 020/220] Update submodules --- examples/testusbhostFAT/Arduino_Makefile_master | 2 +- examples/testusbhostFAT/RTClib | 2 +- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master index 7ada91a9..94c560c8 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit 7ada91a90027ccb7558b74087fb68d3940ecf64d +Subproject commit 94c560c854c7a1dfc35e9de9db05de1b202de6c6 diff --git a/examples/testusbhostFAT/RTClib b/examples/testusbhostFAT/RTClib index b119b97e..c30fcdf1 160000 --- a/examples/testusbhostFAT/RTClib +++ b/examples/testusbhostFAT/RTClib @@ -1 +1 @@ -Subproject commit b119b97e1484a08aebcf24e070113d78c82fb023 +Subproject commit c30fcdf1f112de581de7b145a97630539e5cff44 diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index 72b5bf46..9233df8b 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit 72b5bf467a1c2479ba7354ee4d864e382c167425 +Subproject commit 9233df8bc2cd0c16d363c8e298398b6eaefad257 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index 2bf8f633..77b03342 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit 2bf8f633e7f9bc5a7bf4c00f3f45c7b79484198e +Subproject commit 77b033420485f7d3d35430c0e8d4d844aa894834 From dd0296ca6570d2b9fdccbd6b116eb03d9d42eace Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 3 Mar 2015 23:11:45 +0100 Subject: [PATCH 021/220] Replaced #if with #elif for MIPSEL --- avrpins.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/avrpins.h b/avrpins.h index d312f9c8..46bcf722 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1010,7 +1010,6 @@ MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24)); #undef MAKE_PIN - #else #error "Please define board in avrpins.h" @@ -1066,12 +1065,7 @@ MAKE_PIN(P19, 19); // A5 #undef MAKE_PIN -#else -#error "Please define board in avrpins.h" - -#endif - -#if defined(__MIPSEL__) +#elif defined(__MIPSEL__) // MIPSEL (MIPS architecture using a little endian byte order) // MIPS size_t = 4 @@ -1114,6 +1108,10 @@ MAKE_PIN(P12, 12); // MAKE_PIN(P13, 13); // #undef MAKE_PIN + +#else +#error "Please define board in avrpins.h" + #endif #endif //_avrpins_h_ From cc14152c54d597518550b49e1bc8bc16396936a8 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 19 Mar 2015 16:31:29 +0100 Subject: [PATCH 022/220] Slow SPI devices like the Galileo might actually read it as stabilised in the first go --- examples/board_qc/board_qc.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 424e35192374a3ed75d42110695afb230d16e777 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 19 Mar 2015 18:24:41 +0100 Subject: [PATCH 023/220] Put avrpins include back at original order Also some whitespace fixes --- README.md | 2 +- Usb.h | 2 +- usbhost.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 22f07ad6..4df40f13 100644 --- a/README.md +++ b/README.md @@ -322,4 +322,4 @@ LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0 LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0 ``` -* This means that your dongle does not support 2.0+EDR, so you will need another dongle. Please see the following [list](https://github.com/felis/USB_Host_Shield_2.0/wiki/Bluetooth-dongles) for tested working dongles. +* This means that your dongle does not support 2.0+EDR, so you will need another dongle. Please see the following [list](https://github.com/felis/USB_Host_Shield_2.0/wiki/Bluetooth-dongles) for tested working dongles. \ No newline at end of file diff --git a/Usb.h b/Usb.h index fa801891..47bd626c 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/usbhost.h b/usbhost.h index 4e6154da..56cfd396 100644 --- a/usbhost.h +++ b/usbhost.h @@ -524,4 +524,4 @@ uint8_t MAX3421e< SPI_SS, INTR >::IntHandler() { // return( GPINIRQ ); //} -#endif //_USBHOST_H_ +#endif // _USBHOST_H_ From d881e514ee75480ae00bb2e99f47512aff44e29c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 19 Mar 2015 18:25:26 +0100 Subject: [PATCH 024/220] Check for MIPSEL at the same place as Teensy 3.x and Galileo --- usbhost.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/usbhost.h b/usbhost.h index 56cfd396..da710a1b 100644 --- a/usbhost.h +++ b/usbhost.h @@ -87,14 +87,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(__ARDUINO_X86__) +#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 From 08ddabf7a5c5607626c467c70d63ee4bee4ebe0c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 19 Mar 2015 20:09:27 +0100 Subject: [PATCH 025/220] Use much faster GPIO pin 2 and 3 on Intel Galileo & Intel Galileo 2 --- README.md | 5 +++-- UsbCore.h | 4 +++- avrpins.h | 21 +++++++++++++++------ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4df40f13..53b55204 100644 --- a/README.md +++ b/README.md @@ -92,8 +92,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 and Arduino Galileo - * If you are using the Arduino Due or Galileo, then you must include the Arduino SPI library like so: ```#include ``` in your .ino file. +* Arduino Due, Intel Galileo and Intel Galileo 2 + * 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 both the Intel Galileo and Intel Galileo 2 use 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 d76f1858..d8356d04 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__) +typedef MAX3421e MAX3421E; // The Intel Galileo and Intel Galileo 2 both support much faster read and write speed at pin 2 and 3 #else -typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Galileo or Teensy 2.0 and 3.0 +typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.) or Teensy 2.0 and 3.0 #endif /* Common setup data constant combinations */ diff --git a/avrpins.h b/avrpins.h index 7acf492a..3f02d5c4 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1015,30 +1015,39 @@ MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24)); #endif -#elif defined(__ARDUINO_X86__) // Intel Galileo +#elif defined(__ARDUINO_X86__) // Intel Galileo and Intel Galileo 2 #include // Pointers are 32 bits on x86 #define pgm_read_pointer(p) pgm_read_dword(p) +// Pin 2 and 3 support a higher rate, so it is recommended to use one of these as the SS pin. +// I know Intel Galileo 2 support higher rate at some other pins as well, but 2 and 3 are only +// available on the original Intel Galileo. #define MAKE_PIN(className, pin) \ class className { \ public: \ static void Set() { \ - digitalWrite(pin, HIGH); \ + fastDigitalWrite(pin, HIGH); \ } \ static void Clear() { \ - digitalWrite(pin, LOW); \ + fastDigitalWrite(pin, LOW); \ } \ static void SetDirRead() { \ - pinMode(pin, INPUT); \ + if (pinToFastPin(pin)) \ + pinMode(pin, INPUT_FAST); \ + else \ + pinMode(pin, INPUT); \ } \ static void SetDirWrite() { \ - pinMode(pin, OUTPUT); \ + if (pinToFastPin(pin)) \ + pinMode(pin, OUTPUT_FAST); \ + else \ + pinMode(pin, OUTPUT); \ } \ static uint8_t IsSet() { \ - return digitalRead(pin); \ + return fastDigitalRead(pin); \ } \ }; From 42a26346fa7b552f7a271ce2d276b4fe669b70e4 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 19 Mar 2015 20:47:48 +0100 Subject: [PATCH 026/220] Added support for Intel Edison Closes #132 --- README.md | 2 +- UsbCore.h | 2 +- avrpins.h | 14 ++++++++++---- settings.h | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 53b55204..ac543395 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ 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, Intel Galileo and Intel Galileo 2 +* 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 both the Intel Galileo and Intel Galileo 2 use 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) diff --git a/UsbCore.h b/UsbCore.h index d8356d04..0b1ded02 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -40,7 +40,7 @@ typedef MAX3421e MAX3421E; // Balanduino #elif defined(__ARDUINO_X86__) typedef MAX3421e MAX3421E; // The Intel Galileo and Intel Galileo 2 both support 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 or Teensy 2.0 and 3.0 #endif /* Common setup data constant combinations */ diff --git a/avrpins.h b/avrpins.h index 3f02d5c4..2b94d609 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1015,16 +1015,22 @@ MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24)); #endif -#elif defined(__ARDUINO_X86__) // Intel Galileo and Intel Galileo 2 +#elif defined(__ARDUINO_X86__) // Intel Galileo, Intel Galileo 2 and Intel Edison #include // Pointers are 32 bits on x86 #define pgm_read_pointer(p) pgm_read_dword(p) -// Pin 2 and 3 support a higher rate, so it is recommended to use one of these as the SS pin. -// I know Intel Galileo 2 support higher rate at some other pins as well, but 2 and 3 are only -// available on the original Intel Galileo. +#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 1 & 2 support a higher rate, +// so it is recommended to use one of these as the SS pin. +// I know Intel Galileo 2 support higher rate at some other pins as well, +// but 2 and 3 are only available on the original Intel Galileo. + #define MAKE_PIN(className, pin) \ class className { \ public: \ diff --git a/settings.h b/settings.h index 33757495..5c060354 100644 --- a/settings.h +++ b/settings.h @@ -130,7 +130,7 @@ e-mail : support@circuitsathome.com #endif #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 or if the SPI library with transaction is available +#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 From 4e80db2b3f06633c55fbd1d4806bc6af66bfb638 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 19 Mar 2015 21:20:06 +0100 Subject: [PATCH 027/220] Use setClockSpeed to increase SPI clock speed This is only available in newer version of the API. It can be downloaded here: http://www.intel.com/support/edison/sb/CS-035180.htm and can both be used with the Edison and the Galileo Note that I tried to set the clock rate higher than 12 MHz, but it did not work --- usbhost.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/usbhost.h b/usbhost.h index da710a1b..0a2b7bff 100644 --- a/usbhost.h +++ b/usbhost.h @@ -51,7 +51,11 @@ public: #if defined(__MIPSEL__) SPI.setClockDivider(1); #elif defined(__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 + #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 From fcab83dcb398ec904db22009d21fa2c1fa133ba1 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 25 Mar 2015 01:16:41 +0100 Subject: [PATCH 028/220] Fixed some bugs in: https://github.com/felis/USB_Host_Shield_2.0/pull/135 --- XBOXONE.cpp | 27 ++++++++++----------------- XBOXONE.h | 4 ++-- keywords.txt | 1 - 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/XBOXONE.cpp b/XBOXONE.cpp index 9be283a0..2159c052 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -257,17 +257,11 @@ void XBOXONE::readReport() { if(readBuf == NULL) return; if(readBuf[0] == 0x07) { - // The XBOX button has a seperate message - if (readBuf[4] == 1) { + // The XBOX button has a separate message + if(readBuf[4] == 1) ButtonState |= XBOX_BUTTONS[XBOX]; - } - else { + else ButtonState &= ~XBOX_BUTTONS[XBOX]; - } - if(ButtonState != OldButtonState) { - ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable - OldButtonState = ButtonState; - } } if(readBuf[0] != 0x20) { // Check if it's the correct report, otherwise return - the controller also sends different status reports #ifdef EXTRADEBUG @@ -277,7 +271,7 @@ void XBOXONE::readReport() { return; } - uint16_t xbox = ButtonState & XBOX_BUTTONS[XBOX]; // since the XBOX button is seperate, save it and add it back in + uint16_t xbox = ButtonState & XBOX_BUTTONS[XBOX]; // Since the XBOX button is separate, save it and add it back in // xbox button from before, dpad, abxy, start/back, sync, stick click, shoulder buttons ButtonState = xbox | (((uint16_t)readBuf[5] & 0xF) << 8) | (readBuf[4] & 0xF0) | (((uint16_t)readBuf[4] & 0x0C) << 10) | ((readBuf[4] & 0x01) << 3) | (((uint16_t)readBuf[5] & 0xC0) << 8) | ((readBuf[5] & 0x30) >> 4); @@ -296,15 +290,14 @@ void XBOXONE::readReport() { ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable OldButtonState = ButtonState; } - // handle click detection for triggers - if (triggerValue[0] != triggerValueOld[0]) { - triggerValueOld[0] = triggerValue[0]; + + // Handle click detection for triggers + if(triggerValue[0] != 0 && triggerValueOld[0] == 0) L2Clicked = true; - } - if (triggerValue[1] != triggerValueOld[1]) { - triggerValueOld[1] = triggerValue[1]; + triggerValueOld[0] = triggerValue[0]; + if(triggerValue[1] != 0 && triggerValueOld[1] == 0) R2Clicked = true; - } + triggerValueOld[1] = triggerValue[1]; } void XBOXONE::printReport() { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox ONE Controller diff --git a/XBOXONE.h b/XBOXONE.h index 7fab80ac..02efbf21 100644 --- a/XBOXONE.h +++ b/XBOXONE.h @@ -154,8 +154,8 @@ private: uint16_t OldButtonState; uint16_t ButtonClickState; int16_t hatValue[4]; - int16_t triggerValue[2]; - int16_t triggerValueOld[2]; + uint16_t triggerValue[2]; + uint16_t triggerValueOld[2]; bool L2Clicked; // These buttons are analog, so we use we use these bools to check if they where clicked or not bool R2Clicked; diff --git a/keywords.txt b/keywords.txt index 2d3931dc..bbbfb03e 100644 --- a/keywords.txt +++ b/keywords.txt @@ -56,7 +56,6 @@ get9DOFValues KEYWORD2 getStatus KEYWORD2 printStatusString KEYWORD2 getTemperature KEYWORD2 -getTrigger KEYWORD2 disconnect KEYWORD2 setAllOff KEYWORD2 From 6a956962da048a9367015770744eaf286c0cba14 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Fri, 3 Apr 2015 17:05:49 +0200 Subject: [PATCH 029/220] Added library.properties Needed for the Arduino library manager --- library.properties | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 library.properties diff --git a/library.properties b/library.properties new file mode 100644 index 00000000..345b35f3 --- /dev/null +++ b/library.properties @@ -0,0 +1,9 @@ +name=USB Host Shield Library 2.0 +version=1.0.0 +author=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll , Alexei Glushchenko (Circuits@Home)  +maintainer=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll +sentence=Revision 2.0 of MAX3421E-based USB Host Shield Library. +paragraph=Supports HID devices, FTDI, ADK, ACM, PL2303, Bluetooth HID devices, SPP communication and mass storage devices. Furthermore it supports PS3, PS4, PS Buzz, Wii and Xbox controllers. +category=Other +url=https://github.com/felis/USB_Host_Shield_2.0 +architectures=* \ No newline at end of file From 67a7a66d3d3cf5b3e4808a0c30d1cd496a81937c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 5 Apr 2015 00:17:51 +0200 Subject: [PATCH 030/220] Updated to newest version of testusbhostFAT Fixes #143 --- examples/testusbhostFAT/testusbhostFAT.ino | 71 +++++++++++++--------- 1 file changed, 43 insertions(+), 28 deletions(-) mode change 100755 => 100644 examples/testusbhostFAT/testusbhostFAT.ino diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino old mode 100755 new mode 100644 index 3854b74f..493ca797 --- a/examples/testusbhostFAT/testusbhostFAT.ino +++ b/examples/testusbhostFAT/testusbhostFAT.ino @@ -38,9 +38,9 @@ //#define _FS_TINY 1 //#define _USE_LFN 3 -//#define EXT_RAM_STACK 1 -//#define EXT_RAM_HEAP 1 //#define _MAX_SS 512 + + ///////////////////////////////////////////////////////////// // End of Arduino IDE specific information // ///////////////////////////////////////////////////////////// @@ -48,24 +48,36 @@ // You can set this to 0 if you are not using a USB hub. // It will save a little bit of flash and RAM. // Set to 1 if you want to use a hub. -#define WANT_HUB_TEST 0 +#define WANT_HUB_TEST 1 +// this is for XMEM2 +#define EXT_RAM_STACK 1 +#define EXT_RAM_HEAP 1 +#define LOAD_XMEM + +#if defined(CORE_TEENSY) && !defined(_AVR_) +#include +#include +#endif #if defined(__AVR__) #include -#else -#include +#include +#elif defined(ARDUINO_ARCH_SAM) +#include #endif + #if WANT_HUB_TEST #include #endif +#include +#define LOAD_RTCLIB +#include #include #include #include #include #include -#include -#include #include #if defined(__AVR__) static FILE tty_stdio; @@ -80,14 +92,14 @@ USB Usb; volatile uint8_t current_state = 1; volatile uint8_t last_state = 0; -volatile bool fatready = false; -volatile bool partsready = false; -volatile bool notified = false; -volatile bool runtest = false; -volatile bool usbon = false; +volatile boolean fatready = false; +volatile boolean partsready = false; +volatile boolean notified = false; +volatile boolean runtest = false; +volatile boolean usbon = false; volatile uint32_t usbon_time; -volatile bool change = false; -volatile bool reportlvl = false; +volatile boolean change = false; +volatile boolean reportlvl = false; int cpart = 0; PCPartition *PT; @@ -112,14 +124,15 @@ static uint8_t My_Buff_x[mbxs]; /* File read buffer */ #define prescale256 ((1 << WGM12) | (1 << CS12)) #define prescale1024 ((1 << WGM12) | (1 << CS12) | (1 << CS10)) -extern "C" unsigned int freeHeap(); - +extern "C" { + extern unsigned int freeHeap(); +} static int tty_stderr_putc(char c, FILE *t) { USB_HOST_SERIAL.write(c); return 0; } -static int tty_stderr_flush(FILE *t) { +static int __attribute__((unused)) tty_stderr_flush(FILE *t) { USB_HOST_SERIAL.flush(); return 0; } @@ -134,14 +147,16 @@ static int tty_std_getc(FILE *t) { return Serial.read(); } -static int tty_std_flush(FILE *t) { +static int __attribute__((unused)) tty_std_flush(FILE *t) { Serial.flush(); return 0; } #else +// Supposedly the DUE has stdio already pointing to serial... +#if !defined(ARDUINO_ARCH_SAM) +// But newlib needs this... extern "C" { - int _write(int fd, const char *ptr, int len) { int j; for(j = 0; j < len; j++) { @@ -175,10 +190,11 @@ extern "C" { return (fd < 3) ? 1 : 0; } } +#endif // !defined(ARDUINO_ARCH_SAM) #endif void setup() { - bool serr = false; + boolean serr = false; for(int i = 0; i < _VOLUMES; i++) { Fats[i] = NULL; sto[i].private_data = new pvt_t; @@ -186,7 +202,7 @@ void setup() { } // Set this to higher values to enable more debug information // minimum 0x00, maximum 0xff - UsbDEBUGlvl = 0x51; + UsbDEBUGlvl = 0x81; #if !defined(CORE_TEENSY) && defined(__AVR__) // make LED pin as an output: @@ -454,14 +470,14 @@ void loop() { } // This is horrible, and needs to be moved elsewhere! for(int B = 0; B < MAX_USB_MS_DRIVERS; B++) { - if(!partsready && (UHS_USB_Storage[B]->GetAddress() != NULL)) { + if((!partsready) && (UHS_USB_BulkOnly[B]->GetAddress())) { // Build a list. - int ML = UHS_USB_Storage[B]->GetbMaxLUN(); + int ML = UHS_USB_BulkOnly[B]->GetbMaxLUN(); //printf("MAXLUN = %i\r\n", ML); ML++; for(int i = 0; i < ML; i++) { - if(UHS_USB_Storage[B]->LUNIsGood(i)) { + if(UHS_USB_BulkOnly[B]->LUNIsGood(i)) { partsready = true; ((pvt_t *)(sto[i].private_data))->lun = i; ((pvt_t *)(sto[i].private_data))->B = B; @@ -470,8 +486,8 @@ void loop() { sto[i].Status = *UHS_USB_BulkOnly_Status; sto[i].Initialize = *UHS_USB_BulkOnly_Initialize; sto[i].Commit = *UHS_USB_BulkOnly_Commit; - sto[i].TotalSectors = UHS_USB_Storage[B]->GetCapacity(i); - sto[i].SectorSize = UHS_USB_Storage[B]->GetSectorSize(i); + sto[i].TotalSectors = UHS_USB_BulkOnly[B]->GetCapacity(i); + sto[i].SectorSize = UHS_USB_BulkOnly[B]->GetSectorSize(i); printf_P(PSTR("LUN:\t\t%u\r\n"), i); printf_P(PSTR("Total Sectors:\t%08lx\t%lu\r\n"), sto[i].TotalSectors, sto[i].TotalSectors); printf_P(PSTR("Sector Size:\t%04x\t\t%u\r\n"), sto[i].SectorSize, sto[i].SectorSize); @@ -524,7 +540,7 @@ void loop() { if(Fats[0] != NULL) { struct Pvt * p; p = ((struct Pvt *)(Fats[0]->storage->private_data)); - if(!UHS_USB_Storage[p->B]->LUNIsGood(p->lun)) { + if(!UHS_USB_BulkOnly[p->B]->LUNIsGood(p->lun)) { // media change #if !defined(CORE_TEENSY) && defined(__AVR__) fadeAmount = 80; @@ -718,4 +734,3 @@ failed: } } } - From 9e32aef86c12b4c58a721511b7f79e1b394061e0 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 5 Apr 2015 00:18:52 +0200 Subject: [PATCH 031/220] Replace boolean with bool --- examples/testusbhostFAT/testusbhostFAT.ino | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino index 493ca797..e8b9cd35 100644 --- a/examples/testusbhostFAT/testusbhostFAT.ino +++ b/examples/testusbhostFAT/testusbhostFAT.ino @@ -92,14 +92,14 @@ USB Usb; volatile uint8_t current_state = 1; volatile uint8_t last_state = 0; -volatile boolean fatready = false; -volatile boolean partsready = false; -volatile boolean notified = false; -volatile boolean runtest = false; -volatile boolean usbon = false; +volatile bool fatready = false; +volatile bool partsready = false; +volatile bool notified = false; +volatile bool runtest = false; +volatile bool usbon = false; volatile uint32_t usbon_time; -volatile boolean change = false; -volatile boolean reportlvl = false; +volatile bool change = false; +volatile bool reportlvl = false; int cpart = 0; PCPartition *PT; @@ -194,7 +194,7 @@ extern "C" { #endif void setup() { - boolean serr = false; + bool serr = false; for(int i = 0; i < _VOLUMES; i++) { Fats[i] = NULL; sto[i].private_data = new pvt_t; From 2eea8d4112fa9decc27ac8cb01d49fb0883888b7 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 5 Apr 2015 00:22:36 +0200 Subject: [PATCH 032/220] Update submodules --- examples/testusbhostFAT/RTClib | 2 +- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/testusbhostFAT/RTClib b/examples/testusbhostFAT/RTClib index 7fd6a306..c30fcdf1 160000 --- a/examples/testusbhostFAT/RTClib +++ b/examples/testusbhostFAT/RTClib @@ -1 +1 @@ -Subproject commit 7fd6a306ca53d08bf53b2bbfc1b80eb056f2c55b +Subproject commit c30fcdf1f112de581de7b145a97630539e5cff44 diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index 0b8e3076..77762338 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit 0b8e3076b5a072251e01cfc6e6333b364d4e71e7 +Subproject commit 77762338286535dabb9c94b87060e33e487ff0f3 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index 2bf8f633..77b03342 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit 2bf8f633e7f9bc5a7bf4c00f3f45c7b79484198e +Subproject commit 77b033420485f7d3d35430c0e8d4d844aa894834 From d79de9d7046ef4971126a841c076de03016f0aae Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 5 Apr 2015 00:46:43 +0200 Subject: [PATCH 033/220] Update makefile to work with newest version of Arduino --- examples/testusbhostFAT/Makefile | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/testusbhostFAT/Makefile b/examples/testusbhostFAT/Makefile index 232d338e..8a12ddc0 100644 --- a/examples/testusbhostFAT/Makefile +++ b/examples/testusbhostFAT/Makefile @@ -2,13 +2,16 @@ # These are set for a mega 1280 + quadram plus my serial patch. # If you lack quadram, or want to disable LFN, just change _FS_TINY=1 _USE_LFN=0 # -# If your board is a mega 2560 uncomment the following two lines -# BOARD = mega2560 -# PROGRAMMER = wiring -# ...and then comment out the following two lines +# If your board is a mega 2560 comment out the following two lines BOARD = mega + +BOARD_SUB = mega.menu.cpu.atmega1280 PROGRAMMER = arduino +# ...and then uncomment out the following two lines +#BOARD_SUB = mega.menu.cpu.atmega2560 +#PROGRAMMER = wiring + #BOARD = teensypp2 #BOARD = teensy3 #BOARD = teensy31 @@ -53,6 +56,9 @@ LIB_DIRS += ../testusbhostFAT/generic_storage LIB_DIRS += ../testusbhostFAT/RTClib LIB_DIRS += $(ARD_HOME)/libraries/Wire LIB_DIRS += $(ARD_HOME)/libraries/Wire/utility +LIB_DIRS += $(ARD_HOME)/hardware/arduino/$(BUILD_ARCH)/libraries/Wire +LIB_DIRS += $(ARD_HOME)/hardware/arduino/$(BUILD_ARCH)/libraries/Wire/utility +LIB_DIRS += $(ARD_HOME)/hardware/arduino/$(BUILD_ARCH)/libraries/SPI # And finally, the part that brings everything together for you. include Arduino_Makefile_master/_Makefile.master From 54aef653fe42f20ee327c59d76ad49aefcd87d7f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 5 Apr 2015 00:55:26 +0200 Subject: [PATCH 034/220] Update master makefile --- examples/testusbhostFAT/Arduino_Makefile_master | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master index d35bb955..7e765621 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit d35bb955e3818f0c14e47c8a1998003da8dc1b5a +Subproject commit 7e76562151522380e1dc65501991a408d6f2ae94 From b41150643f280906bc8c207bef968671dfdf18b4 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 5 Apr 2015 13:01:24 +0200 Subject: [PATCH 035/220] Only use pin 2 and 3 as INT and SS when using Intel Galileo 1 --- README.md | 2 +- UsbCore.h | 6 +++--- avrpins.h | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ac543395..146fc47f 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ 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, 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 both the Intel Galileo and Intel Galileo 2 use 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. + * 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 0b1ded02..5c6c7710 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -37,10 +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__) -typedef MAX3421e MAX3421E; // The Intel Galileo and Intel Galileo 2 both support much faster read and write speed at pin 2 and 3 +#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.), Intel Edison 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 2b94d609..4e60e3a2 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1026,10 +1026,8 @@ MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24)); #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 1 & 2 support a higher rate, +// 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. -// I know Intel Galileo 2 support higher rate at some other pins as well, -// but 2 and 3 are only available on the original Intel Galileo. #define MAKE_PIN(className, pin) \ class className { \ From bc1172358928901fd55adb07c4e025cccddc104c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 7 Apr 2015 15:51:30 +0200 Subject: [PATCH 036/220] Added Digilent chipKIT to supported boards --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 2203c977..da1d16f0 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,8 @@ Currently the following boards are supported by the library: * Black Widdow * RedBearLab nRF51822 * If you are using the RedBearLab nRF51822, then you must include the RedBearLab SPI library like so: ```#include ``` in your .ino file. +* Digilent chipKIT + * Please see: . The following boards need to be activated manually in [settings.h](settings.h): From 271520919bfdd9a55a1808ff91bb4db968a6e8c2 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 7 Apr 2015 16:02:29 +0200 Subject: [PATCH 037/220] Updated link to USB Host shield image --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da1d16f0..3efcfb03 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Some information can also be found at: . The shield can be purchased at the main site: or from [TKJ Electronics](http://tkjelectronics.com/): . -![USB Host Shield](http://www.circuitsathome.com/wp/wp-content/uploads/2012/02/UHS_20_main-288x216.jpg) +![USB Host Shield](http://shop.tkjelectronics.dk/images/USB_Host_Shield1.jpg) For more information about the hardware see the [Hardware Manual](http://www.circuitsathome.com/usb-host-shield-hardware-manual). From 05c71da9c1c7f20f874246cf147d2551cd91a9d3 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 14 Apr 2015 02:02:05 +0200 Subject: [PATCH 038/220] Replace boolean with bool Please see: https://github.com/felis/USB_Host_Shield_2.0/commit/bd8c8e740419095f3c1d8875d199e16858058899 --- XBOXONE.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XBOXONE.h b/XBOXONE.h index 02efbf21..11710fcf 100644 --- a/XBOXONE.h +++ b/XBOXONE.h @@ -93,7 +93,7 @@ public: * @param pid The device's PID. * @return Returns true if the device's VID and PID matches this driver. */ - virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) { + virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) { return (vid == XBOX_VID && pid == XBOX_ONE_PID); }; /**@}*/ From c61f9ce1c23fe2f21cddfecac59584dcf6588078 Mon Sep 17 00:00:00 2001 From: Phillip Stevens Date: Wed, 15 Apr 2015 12:54:29 +1000 Subject: [PATCH 039/220] Update Usb.cpp Typo in the InTransfer function relating to resolving toggle errors arising from hrTOGERR --- Usb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Usb.cpp b/Usb.cpp index 3e07149a..cd1c3496 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -234,7 +234,7 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui rcode = dispatchPkt(tokIN, pep->epAddr, nak_limit); //IN packet to EP-'endpoint'. Function takes care of NAKS. if(rcode == hrTOGERR) { // yes, we flip it wrong here so that next time it is actually correct! - pep->bmRcvToggle = (regRd(rHRSL) & bmSNDTOGRD) ? 0 : 1; + pep->bmRcvToggle = (regRd(rHRSL) & bmRCVTOGRD) ? 0 : 1; regWr(rHCTL, (pep->bmRcvToggle) ? bmRCVTOG1 : bmRCVTOG0); //set toggle value continue; } From 3d5b46d0556270a2d7fe6a5abf71cfa5cb5c205a Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 00:07:47 +0200 Subject: [PATCH 040/220] Fixed "warning: no return statement in function returning non-void" --- cdcacm.h | 2 +- cdcftdi.h | 2 ++ hid.h | 8 ++++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cdcacm.h b/cdcacm.h index 8372f56b..2a38524d 100644 --- a/cdcacm.h +++ b/cdcacm.h @@ -204,7 +204,7 @@ public: uint8_t Poll(); bool available(void) { - + return false; }; virtual uint8_t GetAddress() { diff --git a/cdcftdi.h b/cdcftdi.h index 5a133241..b7312526 100644 --- a/cdcftdi.h +++ b/cdcftdi.h @@ -80,9 +80,11 @@ class FTDIAsyncOper { public: virtual uint8_t OnInit(FTDI *pftdi) { + return 0; }; virtual uint8_t OnRelease(FTDI *pftdi) { + return 0; }; }; diff --git a/hid.h b/hid.h index 14507183..72942ebc 100644 --- a/hid.h +++ b/hid.h @@ -156,7 +156,9 @@ protected: void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); void PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc); - virtual HIDReportParser* GetReportParser(uint8_t id) {}; + virtual HIDReportParser* GetReportParser(uint8_t id) { + return NULL; + }; public: @@ -167,7 +169,9 @@ public: return pUsb; }; - virtual bool SetReportParser(uint8_t id, HIDReportParser *prs) {}; + virtual bool SetReportParser(uint8_t id, HIDReportParser *prs) { + return false; + }; uint8_t SetProtocol(uint8_t iface, uint8_t protocol); uint8_t GetProtocol(uint8_t iface, uint8_t* dataptr); From b1902b2a5509a5149fbe9b7d64002da6e380327f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 01:57:00 +0200 Subject: [PATCH 041/220] Initial support for Wii Balance Board Still need to convert readings into something meaningful --- BTD.cpp | 55 ++++++++++--------- BTD.h | 2 + README.md | 6 +- Wii.cpp | 35 +++++++++++- Wii.h | 2 + .../WiiBalanceBoard/WiiBalanceBoard.ino | 44 +++++++++++++++ keywords.txt | 1 + 7 files changed, 113 insertions(+), 32 deletions(-) create mode 100644 examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino diff --git a/BTD.cpp b/BTD.cpp index 42cf3d62..5c470bab 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -445,11 +445,17 @@ void BTD::HCI_event_task() { for(uint8_t j = 0; j < 3; j++) classOfDevice[j] = hcibuf[j + 4 + offset]; +#ifdef EXTRADEBUG + Notify(PSTR("\r\nClass of device: "), 0x80); + D_PrintHex (classOfDevice[2], 0x80); + Notify(PSTR(" "), 0x80); + D_PrintHex (classOfDevice[1], 0x80); + Notify(PSTR(" "), 0x80); + D_PrintHex (classOfDevice[0], 0x80); +#endif + if(pairWithWii && classOfDevice[2] == 0x00 && (classOfDevice[1] & 0x05) && (classOfDevice[0] & 0x0C)) { // See http://wiibrew.org/wiki/Wiimote#SDP_information - if(classOfDevice[0] & 0x08) // Check if it's the new Wiimote with motion plus inside that was detected - motionPlusInside = true; - else - motionPlusInside = false; + checkRemoteName = true; // Check remote name to distinguish between the different controllers for(uint8_t j = 0; j < 6; j++) disc_bdaddr[j] = hcibuf[j + 3 + 6 * i]; @@ -472,16 +478,6 @@ void BTD::HCI_event_task() { hci_set_flag(HCI_FLAG_DEVICE_FOUND); break; } -#ifdef EXTRADEBUG - else { - Notify(PSTR("\r\nClass of device: "), 0x80); - D_PrintHex (classOfDevice[2], 0x80); - Notify(PSTR(" "), 0x80); - D_PrintHex (classOfDevice[1], 0x80); - Notify(PSTR(" "), 0x80); - D_PrintHex (classOfDevice[0], 0x80); - } -#endif } } break; @@ -555,7 +551,7 @@ void BTD::HCI_event_task() { case EV_PIN_CODE_REQUEST: if(pairWithWii) { #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nPairing with wiimote"), 0x80); + Notify(PSTR("\r\nPairing with Wiimote"), 0x80); #endif hci_pin_code_request_reply(); } else if(btdPin != NULL) { @@ -705,7 +701,7 @@ void BTD::HCI_task() { if(pairWithHIDDevice || pairWithWii) { // Check if it should try to connect to a Wiimote #ifdef DEBUG_USB_HOST if(pairWithWii) - Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80); + Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press the SYNC button if you are using a Wii U Pro Controller or Wii Balance Board"), 0x80); else Notify(PSTR("\r\nPlease enable discovery of your device"), 0x80); #endif @@ -736,8 +732,8 @@ void BTD::HCI_task() { else Notify(PSTR("device"), 0x80); #endif - if(motionPlusInside) { - hci_remote_name(); // We need to know the name to distinguish between a Wiimote and a Wii U Pro Controller + if(checkRemoteName) { + hci_remote_name(); // We need to know the name to distinguish between the Wiimote, the new Wiimote with Motion Plus inside, a Wii U Pro Controller and a Wii Balance Board hci_state = HCI_REMOTE_NAME_STATE; } else hci_state = HCI_CONNECT_DEVICE_STATE; @@ -752,6 +748,7 @@ void BTD::HCI_task() { else Notify(PSTR("\r\nConnecting to HID device"), 0x80); #endif + checkRemoteName = false; hci_connect(); hci_state = HCI_CONNECTED_DEVICE_STATE; } @@ -809,6 +806,9 @@ void BTD::HCI_task() { #endif if(strncmp((const char*)remote_name, "Nintendo", 8) == 0) { incomingWii = true; + motionPlusInside = false; + wiiUProController = false; + pairWiiUsingSync = false; #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWiimote is connecting"), 0x80); #endif @@ -821,11 +821,12 @@ void BTD::HCI_task() { #ifdef DEBUG_USB_HOST Notify(PSTR(" - Wii U Pro Controller"), 0x80); #endif - motionPlusInside = true; - wiiUProController = true; - } else { - motionPlusInside = false; - wiiUProController = false; + wiiUProController = motionPlusInside = pairWiiUsingSync = true; + } else if(strncmp((const char*)remote_name, "Nintendo RVL-WBC-01", 19) == 0) { +#ifdef DEBUG_USB_HOST + Notify(PSTR(" - Wii Balance Board"), 0x80); +#endif + pairWiiUsingSync = true; } } if(classOfDevice[2] == 0 && classOfDevice[1] == 0x25 && classOfDevice[0] == 0x08 && strncmp((const char*)remote_name, "Wireless Controller", 19) == 0) { @@ -834,7 +835,7 @@ void BTD::HCI_task() { #endif incomingPS4 = true; } - if(pairWithWii && motionPlusInside) + if(pairWithWii && checkRemoteName) hci_state = HCI_CONNECT_DEVICE_STATE; else { hci_accept_connection(); @@ -886,7 +887,7 @@ void BTD::HCI_task() { memset(l2capinbuf, 0, BULK_MAXPKTSIZE); connectToWii = incomingWii = pairWithWii = false; - connectToHIDDevice = incomingHIDDevice = pairWithHIDDevice = false; + connectToHIDDevice = incomingHIDDevice = pairWithHIDDevice = checkRemoteName = false; incomingPS4 = false; hci_state = HCI_SCANNING_STATE; @@ -1085,9 +1086,9 @@ void BTD::hci_pin_code_request_reply() { hcibuf[8] = disc_bdaddr[5]; if(pairWithWii) { hcibuf[9] = 6; // Pin length is the length of the Bluetooth address - if(wiiUProController) { + if(pairWiiUsingSync) { #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80); + Notify(PSTR("\r\nParing with Wii controller via SYNC"), 0x80); #endif for(uint8_t i = 0; i < 6; i++) hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards diff --git a/BTD.h b/BTD.h index b7683f65..312e45f7 100755 --- a/BTD.h +++ b/BTD.h @@ -535,6 +535,8 @@ private: uint8_t pollInterval; bool bPollEnable; + bool pairWiiUsingSync; // True if paring was done using the SYNC button. + bool checkRemoteName; // Used to check remote device's name before connecting. bool incomingPS4; // True if a PS4 controller is connecting uint8_t classOfDevice[3]; // Class of device of last device diff --git a/README.md b/README.md index 3efcfb03..60877437 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ An Xbox ONE controller is supported via USB in the [XBOXONE](XBOXONE.cpp) class. ### [Wii library](Wii.cpp) -The [Wii](Wii.cpp) library support the Wiimote, but also the Nunchuch and Motion Plus extensions via Bluetooth. The Wii U Pro Controller is also supported via Bluetooth. +The [Wii](Wii.cpp) library support the Wiimote, but also the Nunchuch and Motion Plus extensions via Bluetooth. The Wii U Pro Controller and Wii Balance Board are also supported via Bluetooth. First you have to pair with the controller, this is done automatically by the library if you create the instance like so: @@ -253,7 +253,7 @@ First you have to pair with the controller, this is done automatically by the li WII Wii(&Btd, PAIR); ``` -And then press 1 & 2 at once on the Wiimote or press sync if you are using a Wii U Pro Controller. +And then press 1 & 2 at once on the Wiimote or the SYNC buttons if you are using a Wii U Pro Controller or a Wii Balance Board. After that you can simply create the instance like so: @@ -273,13 +273,13 @@ The Wii IR camera can also be used, but you will have to activate the code for i The [WiiIRCamera.ino](examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino) example shows how it can be used. - All the information about the Wii controllers are from these sites: * * * * +* * The old library created by _Tomoyuki Tanaka_: also helped a lot. ### [PS Buzz Library](PSBuzz.cpp) diff --git a/Wii.cpp b/Wii.cpp index 008e5329..a0aa9d53 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -108,6 +108,7 @@ void WII::Reset() { motionPlusInside = false; pBtd->wiiUProController = false; wiiUProControllerConnected = false; + wiiBalanceBoardConnected = false; l2cap_event_flag = 0; // Reset flags l2cap_state = L2CAP_WAIT; } @@ -380,6 +381,12 @@ void WII::ACLData(uint8_t* l2capinbuf) { Notify(PSTR("\r\nWii U Pro Controller connected"), 0x80); #endif wiiUProControllerConnected = true; + } else if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x02) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nWii Balance Board connected"), 0x80); +#endif + setReportMode(false, 0x32); // Read the Wii Balance Board extension + wiiBalanceBoardConnected = true; } #ifdef DEBUG_USB_HOST else { @@ -414,8 +421,32 @@ void WII::ACLData(uint8_t* l2capinbuf) { break; case 0x31: // Core Buttons and Accelerometer - (a1) 31 BB BB AA AA AA break; - case 0x32: // Core Buttons with 8 Extension bytes - (a1) 32 BB BB EE EE EE EE EE EE EE EE - break; + case 0x32: { // Core Buttons with 8 Extension bytes - (a1) 32 BB BB EE EE EE EE EE EE EE EE +#if 1 + uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); + Notify(PSTR("\r\nLength: "), 0x80); + D_PrintHex (length - 2, 0x80); + Notify(PSTR("\tData: "), 0x80); + for(uint8_t i = 0; i < length - 2; i++) { + D_PrintHex (l2capinbuf[10 + i], 0x80); + Notify(PSTR(" "), 0x80); + } + + uint16_t topRight = (l2capinbuf[13] | l2capinbuf[12] << 8); + uint16_t botRight = (l2capinbuf[15] | l2capinbuf[14] << 8); + uint16_t topLeft = (l2capinbuf[17] | l2capinbuf[16] << 8); + uint16_t botleft = (l2capinbuf[19] | l2capinbuf[18] << 8); + + Notify(PSTR("\ttopRight: "), 0x80); + Notify(topRight, 0x80); + Notify(PSTR("\tbotRight: "), 0x80); + Notify(botRight, 0x80); + Notify(PSTR("\ttopLeft: "), 0x80); + Notify(topLeft, 0x80); + Notify(PSTR("\tbotleft: "), 0x80); + Notify(botleft, 0x80); +#endif + } break; case 0x33: // Core Buttons with Accelerometer and 12 IR bytes - (a1) 33 BB BB AA AA AA II II II II II II II II II II II II #ifdef WIICAMERA // Read the IR data diff --git a/Wii.h b/Wii.h index 13ba8d50..c8a477aa 100755 --- a/Wii.h +++ b/Wii.h @@ -191,6 +191,8 @@ public: bool motionPlusConnected; /** Variable used to indicate if a Wii U Pro controller is connected. */ bool wiiUProControllerConnected; + /** Variable used to indicate if a Wii Balance Board is connected. */ + bool wiiBalanceBoardConnected; /**@}*/ /* IMU Data, might be usefull if you need to do something more advanced than just calculating the angle */ diff --git a/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino new file mode 100644 index 00000000..af8a78bf --- /dev/null +++ b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino @@ -0,0 +1,44 @@ +/* + Example sketch for the Wii Balance Board Bluetooth library - developed by Kristian Lauszus + For more information visit my blog: http://blog.tkjelectronics.dk/ or + send me an e-mail: kristianl@tkjelectronics.com + */ + +#include +#include + +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude +#include +#include +#endif + +USB Usb; +//USBHub Hub1(&Usb); // Some dongles have a hub inside + +BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so +/* You can create the instance of the class in two ways */ +WII Wii(&Btd, PAIR); // This will start an inquiry and then pair with your Wii Balance Board - you only have to do this once +//WII Wii(&Btd); // After that you can simply create the instance like so and then press the power button on the Wii Balance Board + +void setup() { + Serial.begin(115200); +#if !defined(__MIPSEL__) + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection +#endif + if (Usb.Init() == -1) { + Serial.print(F("\r\nOSC did not start")); + while (1); //halt + } + Serial.print(F("\r\nWii Balance Board Bluetooth Library Started")); +} +void loop() { + Usb.Task(); + if (Wii.wiiBalanceBoardConnected) { + if (Wii.getButtonClick(A)) { + Serial.print(F("\r\nA")); + Wii.setLedToggle(LED1); + //Wii.disconnect(); + } + } +} diff --git a/keywords.txt b/keywords.txt index bbbfb03e..ade71b28 100644 --- a/keywords.txt +++ b/keywords.txt @@ -269,6 +269,7 @@ wiimoteConnected KEYWORD2 nunchuckConnected KEYWORD2 motionPlusConnected KEYWORD2 wiiUProControllerConnected KEYWORD2 +wiiBalanceBoardConnected KEYWORD2 setRumbleToggle KEYWORD2 getPitch KEYWORD2 getRoll KEYWORD2 From 03e0ec5d6d558aa859fb425732182aa63b3cd047 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 02:15:52 +0200 Subject: [PATCH 042/220] Print values properly --- Wii.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index a0aa9d53..bb5935d6 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -438,13 +438,13 @@ void WII::ACLData(uint8_t* l2capinbuf) { uint16_t botleft = (l2capinbuf[19] | l2capinbuf[18] << 8); Notify(PSTR("\ttopRight: "), 0x80); - Notify(topRight, 0x80); + Serial.print(topRight); Notify(PSTR("\tbotRight: "), 0x80); - Notify(botRight, 0x80); + Serial.print(botRight); Notify(PSTR("\ttopLeft: "), 0x80); - Notify(topLeft, 0x80); + Serial.print(topLeft); Notify(PSTR("\tbotleft: "), 0x80); - Notify(botleft, 0x80); + Serial.print(botleft); #endif } break; case 0x33: // Core Buttons with Accelerometer and 12 IR bytes - (a1) 33 BB BB AA AA AA II II II II II II II II II II II II @@ -452,7 +452,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { // Read the IR data IR_object_x1 = (l2capinbuf[15] | ((uint16_t)(l2capinbuf[17] & 0x30) << 4)); // x position IR_object_y1 = (l2capinbuf[16] | ((uint16_t)(l2capinbuf[17] & 0xC0) << 2)); // y position - IR_object_s1 = (l2capinbuf[17] & 0x0F); // size value, 0-15 + IR_object_s1 = (l2capinbuf[17] & 0x0F); // Size value, 0-15 IR_object_x2 = (l2capinbuf[18] | ((uint16_t)(l2capinbuf[20] & 0x30) << 4)); IR_object_y2 = (l2capinbuf[19] | ((uint16_t)(l2capinbuf[20] & 0xC0) << 2)); From e555195e42d85d31d53f1ebdfd3c8667c43b7919 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 02:26:18 +0200 Subject: [PATCH 043/220] Print raw Wii Balance Board values in example --- Wii.cpp | 33 ++++--------------- Wii.h | 5 +++ .../WiiBalanceBoard/WiiBalanceBoard.ino | 9 +++++ 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index bb5935d6..bfb91175 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -421,32 +421,13 @@ void WII::ACLData(uint8_t* l2capinbuf) { break; case 0x31: // Core Buttons and Accelerometer - (a1) 31 BB BB AA AA AA break; - case 0x32: { // Core Buttons with 8 Extension bytes - (a1) 32 BB BB EE EE EE EE EE EE EE EE -#if 1 - uint16_t length = ((uint16_t)l2capinbuf[5] << 8 | l2capinbuf[4]); - Notify(PSTR("\r\nLength: "), 0x80); - D_PrintHex (length - 2, 0x80); - Notify(PSTR("\tData: "), 0x80); - for(uint8_t i = 0; i < length - 2; i++) { - D_PrintHex (l2capinbuf[10 + i], 0x80); - Notify(PSTR(" "), 0x80); - } - - uint16_t topRight = (l2capinbuf[13] | l2capinbuf[12] << 8); - uint16_t botRight = (l2capinbuf[15] | l2capinbuf[14] << 8); - uint16_t topLeft = (l2capinbuf[17] | l2capinbuf[16] << 8); - uint16_t botleft = (l2capinbuf[19] | l2capinbuf[18] << 8); - - Notify(PSTR("\ttopRight: "), 0x80); - Serial.print(topRight); - Notify(PSTR("\tbotRight: "), 0x80); - Serial.print(botRight); - Notify(PSTR("\ttopLeft: "), 0x80); - Serial.print(topLeft); - Notify(PSTR("\tbotleft: "), 0x80); - Serial.print(botleft); -#endif - } break; + case 0x32: // Core Buttons with 8 Extension bytes - (a1) 32 BB BB EE EE EE EE EE EE EE EE + // See: http://wiibrew.org/wiki/Wii_Balance_Board#Data_Format + topRight = l2capinbuf[13] | l2capinbuf[12] << 8; + botRight = l2capinbuf[15] | l2capinbuf[14] << 8; + topLeft = l2capinbuf[17] | l2capinbuf[16] << 8; + botleft = l2capinbuf[19] | l2capinbuf[18] << 8; + break; case 0x33: // Core Buttons with Accelerometer and 12 IR bytes - (a1) 33 BB BB AA AA AA II II II II II II II II II II II II #ifdef WIICAMERA // Read the IR data diff --git a/Wii.h b/Wii.h index c8a477aa..1578e5b8 100755 --- a/Wii.h +++ b/Wii.h @@ -263,6 +263,11 @@ public: int16_t gyroPitchZero; /**@}*/ + /**@{*/ + /** Wii Balance Board raw values. */ + uint16_t topRight, botRight, topLeft, botleft; + /**@}*/ + #ifdef WIICAMERA /** @name Wiimote IR camera functions * You will have to set ::ENABLE_WII_IR_CAMERA in settings.h to 1 in order use the IR camera. diff --git a/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino index af8a78bf..11459519 100644 --- a/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino +++ b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino @@ -35,6 +35,15 @@ void setup() { void loop() { Usb.Task(); if (Wii.wiiBalanceBoardConnected) { + Serial.print(F("\r\ntopRight: ")); + Serial.print(Wii.topRight); + Serial.print(F("\tbotRight: ")); + Serial.print(Wii.botRight); + Serial.print(F("\ttopLeft: ")); + Serial.print(Wii.topLeft); + Serial.print(F("\tbotleft: ")); + Serial.print(Wii.botleft); + if (Wii.getButtonClick(A)) { Serial.print(F("\r\nA")); Wii.setLedToggle(LED1); From a3fbffb42c6e2f5efe6106403acb6858b43bc2e3 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 02:34:27 +0200 Subject: [PATCH 044/220] Updated some comments --- BTD.cpp | 2 +- BTD.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 5c470bab..bcfba14b 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -701,7 +701,7 @@ void BTD::HCI_task() { if(pairWithHIDDevice || pairWithWii) { // Check if it should try to connect to a Wiimote #ifdef DEBUG_USB_HOST if(pairWithWii) - Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press the SYNC button if you are using a Wii U Pro Controller or Wii Balance Board"), 0x80); + Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press the SYNC button if you are using a Wii U Pro Controller or a Wii Balance Board"), 0x80); else Notify(PSTR("\r\nPlease enable discovery of your device"), 0x80); #endif diff --git a/BTD.h b/BTD.h index 312e45f7..6549c30c 100755 --- a/BTD.h +++ b/BTD.h @@ -535,7 +535,7 @@ private: uint8_t pollInterval; bool bPollEnable; - bool pairWiiUsingSync; // True if paring was done using the SYNC button. + bool pairWiiUsingSync; // True if paring was done using the Wii SYNC button. bool checkRemoteName; // Used to check remote device's name before connecting. bool incomingPS4; // True if a PS4 controller is connecting uint8_t classOfDevice[3]; // Class of device of last device From 9cb31799a8f14e5036ad35f06ff5502ba7dcc4b6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 16:50:08 +0200 Subject: [PATCH 045/220] Fix initialisation of extension bug in status report. The first status report were missed because checkExtension had to be true. Should fix bug reported here: http://blog.tkjelectronics.dk/2012/08/wiimote-added-to-usb-host-library/#comment-500635 --- Wii.cpp | 21 +++++++++++++-------- Wii.h | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index bfb91175..902a4301 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -296,11 +296,8 @@ void WII::ACLData(uint8_t* l2capinbuf) { #endif wiiState = l2capinbuf[12]; // (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4) batteryLevel = l2capinbuf[15]; // Update battery level -#ifdef DEBUG_USB_HOST - if(l2capinbuf[12] & 0x01) - Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80); -#endif - if(checkExtension) { // If this is false it means that the user must have called getBatteryLevel() + + if(!checkBatteryLevel) { // If this is true it means that the user must have called getBatteryLevel() if(l2capinbuf[12] & 0x02) { // Check if a extension is connected #ifdef DEBUG_USB_HOST if(!unknownExtensionConnected) @@ -334,8 +331,16 @@ void WII::ACLData(uint8_t* l2capinbuf) { } else setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer } - } else - checkExtension = true; // Check for extensions by default + } +#ifdef DEBUG_USB_HOST + else + Notify(PSTR("\r\nChecking battery level"), 0x80); + + if(l2capinbuf[12] & 0x01) + Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80); +#endif + + checkBatteryLevel = false; // Check for extensions by default break; case 0x21: // Read Memory Data if((l2capinbuf[12] & 0x0F) == 0) { // No error @@ -926,7 +931,7 @@ void WII::setLedStatus() { } uint8_t WII::getBatteryLevel() { - checkExtension = false; // This is needed so the library knows that the status response is a response to this function + checkBatteryLevel = true; // This is needed so the library knows that the status response is a response to this function statusRequest(); // This will update the battery level return batteryLevel; }; diff --git a/Wii.h b/Wii.h index 1578e5b8..f2e52947 100755 --- a/Wii.h +++ b/Wii.h @@ -422,7 +422,7 @@ private: uint16_t stateCounter; bool unknownExtensionConnected; bool extensionConnected; - bool checkExtension; // Set to false when getBatteryLevel() is called otherwise if should be true + bool checkBatteryLevel; // Set to true when getBatteryLevel() is called otherwise if should be false bool motionPlusInside; // True if it's a new Wiimote with the Motion Plus extension build into it /* L2CAP Channels */ From 7acf598a59d01113140022a0cf94637bea116307 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 16:55:35 +0200 Subject: [PATCH 046/220] Convert Wii Balance Board readings into kg --- Wii.cpp | 40 +++++++++++-- Wii.h | 57 ++++++++++++++++++- .../WiiBalanceBoard/WiiBalanceBoard.ino | 22 ++++--- keywords.txt | 7 +++ 4 files changed, 105 insertions(+), 21 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index 902a4301..d7b0b8c0 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -344,6 +344,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { break; case 0x21: // Read Memory Data if((l2capinbuf[12] & 0x0F) == 0) { // No error + uint8_t reportLength = (l2capinbuf[12] >> 4) + 1; // // Bit 4-7 is the length - 1 // See: http://wiibrew.org/wiki/Wiimote/Extension_Controllers if(l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) { #ifdef DEBUG_USB_HOST @@ -391,15 +392,30 @@ void WII::ACLData(uint8_t* l2capinbuf) { Notify(PSTR("\r\nWii Balance Board connected"), 0x80); #endif setReportMode(false, 0x32); // Read the Wii Balance Board extension + wiiBalanceBoardCalibrationComplete = false; wiiBalanceBoardConnected = true; } + // Wii Balance Board calibration reports (24 bits in total) + else if(l2capinbuf[13] == 0x00 && l2capinbuf[14] == 0x24 && reportLength == 16) { // First 16-bit + for(uint8_t i = 0; i < 2; i++) { + for(uint8_t j = 0; j < 4; j++) + balanceBoardCal[i][j] = l2capinbuf[16 + 8 * i + 2 * j] | l2capinbuf[15 + 8 * i + 2 * j] << 8; + } + } else if(l2capinbuf[13] == 0x00 && l2capinbuf[14] == 0x34 && reportLength == 8) { // Last 8-bit + for(uint8_t j = 0; j < 4; j++) + balanceBoardCal[2][j] = l2capinbuf[16 + 2 * j] | l2capinbuf[15 + 2 * j] << 8; +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nWii Balance Board calibrated successfully"), 0x80); +#endif + wiiBalanceBoardCalibrationComplete = true; + } #ifdef DEBUG_USB_HOST else { Notify(PSTR("\r\nUnknown Device: "), 0x80); D_PrintHex (l2capinbuf[13], 0x80); D_PrintHex (l2capinbuf[14], 0x80); Notify(PSTR("\r\nData: "), 0x80); - for(uint8_t i = 0; i < ((l2capinbuf[12] >> 4) + 1); i++) { // bit 4-7 is the length-1 + for(uint8_t i = 0; i < reportLength; i++) { D_PrintHex (l2capinbuf[15 + i], 0x80); Notify(PSTR(" "), 0x80); } @@ -428,10 +444,10 @@ void WII::ACLData(uint8_t* l2capinbuf) { break; case 0x32: // Core Buttons with 8 Extension bytes - (a1) 32 BB BB EE EE EE EE EE EE EE EE // See: http://wiibrew.org/wiki/Wii_Balance_Board#Data_Format - topRight = l2capinbuf[13] | l2capinbuf[12] << 8; - botRight = l2capinbuf[15] | l2capinbuf[14] << 8; - topLeft = l2capinbuf[17] | l2capinbuf[16] << 8; - botleft = l2capinbuf[19] | l2capinbuf[18] << 8; + balanceBoardRaw[TopRight] = l2capinbuf[13] | l2capinbuf[12] << 8; // Top right + balanceBoardRaw[BotRight] = l2capinbuf[15] | l2capinbuf[14] << 8; // Bottom right + balanceBoardRaw[TopLeft] = l2capinbuf[17] | l2capinbuf[16] << 8; // Top left + balanceBoardRaw[BotLeft] = l2capinbuf[19] | l2capinbuf[18] << 8; // Bottom left break; case 0x33: // Core Buttons with Accelerometer and 12 IR bytes - (a1) 33 BB BB AA AA AA II II II II II II II II II II II II #ifdef WIICAMERA @@ -768,13 +784,21 @@ void WII::Run() { if(unknownExtensionConnected) // Check if there is a extension is connected to the port initExtension1(); else - stateCounter = 399; + stateCounter = 499; } else if(stateCounter == 200) initExtension2(); else if(stateCounter == 300) { readExtensionType(); unknownExtensionConnected = false; } else if(stateCounter == 400) { + if(wiiBalanceBoardConnected) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nCalibrating Wii Balance Board"), 0x80); +#endif + calibrateWiiBalanceBoard(); + } else + stateCounter = 499; + } else if(stateCounter == 500) { stateCounter = 0; l2cap_state = TURN_ON_LED; } @@ -1047,6 +1071,10 @@ void WII::checkMotionPresent() { readData(0xA600FA, 6, false); } +void WII::calibrateWiiBalanceBoard() { + readData(0xA40024, 24, false); +} + /************************************************************/ /* WII Commands */ diff --git a/Wii.h b/Wii.h index f2e52947..91026469 100755 --- a/Wii.h +++ b/Wii.h @@ -39,6 +39,14 @@ enum HatEnum { HatY = 1, }; +/** Enum used to read the weight on Wii Balance Board. */ +enum BalanceBoardEnum { + TopRight = 0, + BotRight = 1, + TopLeft = 2, + BotLeft = 3, +}; + /** * This BluetoothService class implements support for the Wiimote including the Nunchuck and Motion Plus extension. * @@ -263,9 +271,48 @@ public: int16_t gyroPitchZero; /**@}*/ - /**@{*/ - /** Wii Balance Board raw values. */ - uint16_t topRight, botRight, topLeft, botleft; + /** @name Wii Balance Board functions */ + + /** + * Used to get the weight at the specific position on the Wii Balance Board. + * @param ::BalanceBoardEnum to read from. + * @return Returns the weight in kg. + */ + float getWeight(BalanceBoardEnum pos) { + // Based on: https://github.com/skorokithakis/gr8w8upd8m8/blob/master/gr8w8upd8m8.py + // calibration[pos][0] is calibration values for 0 kg + // calibration[pos][1] is calibration values for 17 kg + // calibration[pos][2] is calibration values for 34 kg + float val = 0; + if(balanceBoardRaw[pos] < balanceBoardCal[0][pos]) + return val; + else if(balanceBoardRaw[pos] < balanceBoardCal[1][pos]) + val = 17 * ((balanceBoardRaw[pos] - balanceBoardCal[0][pos]) / float((balanceBoardCal[1][pos] - balanceBoardCal[0][pos]))); + else if(balanceBoardRaw[pos] > balanceBoardCal[1][pos]) + val = 17 + 17 * ((balanceBoardRaw[pos] - balanceBoardCal[1][pos]) / float((balanceBoardCal[2][pos] - balanceBoardCal[1][pos]))); + + return val; + }; + + /** + * Used to get total weight on the Wii Balance Board. + * @returnReturns the weight in kg. + */ + float getTotalWeight() { + return getWeight(TopRight) + getWeight(BotRight) + getWeight(TopLeft) + getWeight(BotLeft); + }; + + /** + * Used to get the raw reading at the specific position on the Wii Balance Board. + * @param ::BalanceBoardEnum to read from. + * @return Returns the raw reading. + */ + uint16_t getWeightRaw(BalanceBoardEnum pos) { + return balanceBoardRaw[pos]; + }; + + /** Indicates when the calibration of the Wii Balance Board is done. */ + bool wiiBalanceBoardCalibrationComplete; /**@}*/ #ifdef WIICAMERA @@ -448,6 +495,10 @@ private: void checkMotionPresent(); // Used to see if a Motion Plus is connected to the Wiimote void initMotionPlus(); void activateMotionPlus(); + void calibrateWiiBalanceBoard(); + + uint16_t balanceBoardRaw[4]; // Wii Balance Board raw values + uint16_t balanceBoardCal[3][4]; // Wii Balance Board calibration values double compPitch; // Fusioned angle using a complimentary filter if the Motion Plus is connected double compRoll; // Fusioned angle using a complimentary filter if the Motion Plus is connected diff --git a/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino index 11459519..6186a179 100644 --- a/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino +++ b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino @@ -34,20 +34,18 @@ void setup() { } void loop() { Usb.Task(); - if (Wii.wiiBalanceBoardConnected) { - Serial.print(F("\r\ntopRight: ")); - Serial.print(Wii.topRight); - Serial.print(F("\tbotRight: ")); - Serial.print(Wii.botRight); - Serial.print(F("\ttopLeft: ")); - Serial.print(Wii.topLeft); - Serial.print(F("\tbotleft: ")); - Serial.print(Wii.botleft); - + if (Wii.wiiBalanceBoardConnected && Wii.wiiBalanceBoardCalibrationComplete) { + Serial.print(F("\r\nWeight: ")); + for (uint8_t i = 0; i < 4; i++) { + Serial.print(Wii.getWeight((BalanceBoardEnum)i)); + Serial.print(F("\t")); + } + Serial.print(F("Total Weight: ")); + Serial.print(Wii.getTotalWeight()); if (Wii.getButtonClick(A)) { Serial.print(F("\r\nA")); - Wii.setLedToggle(LED1); - //Wii.disconnect(); + //Wii.setLedToggle(LED1); // The Wii Balance Board has one LED as well + Wii.disconnect(); } } } diff --git a/keywords.txt b/keywords.txt index ade71b28..f4e19cd1 100644 --- a/keywords.txt +++ b/keywords.txt @@ -282,6 +282,9 @@ PAIR KEYWORD2 statusRequest KEYWORD2 getBatteryLevel KEYWORD2 getWiiState KEYWORD2 +getWeight KEYWORD2 +getTotalWeight KEYWORD2 +getWeightRaw KEYWORD2 #################################################### # Constants and enums (LITERAL1) @@ -300,6 +303,10 @@ ZL LITERAL1 ZR LITERAL1 HatX LITERAL1 HatY LITERAL1 +TopRight LITERAL1 +BotRight LITERAL1 +TopLeft LITERAL1 +BotLeft LITERAL1 #################################################### # Methods and Functions for the IR Camera From d2511df4a190d5c9b43d761a01ac4a6fa4ba54d1 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 17:00:07 +0200 Subject: [PATCH 047/220] Move functions into .cpp file --- Wii.cpp | 29 ++++++++++++++++++++++++++--- Wii.h | 20 ++------------------ 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index d7b0b8c0..72c26113 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -880,8 +880,8 @@ void WII::Run() { /************************************************************/ /* HID Commands */ - /************************************************************/ + void WII::HID_Command(uint8_t* data, uint8_t nbytes) { if(motionPlusInside) pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // It's the new Wiimote with the Motion Plus Inside or Wii U Pro controller @@ -982,8 +982,8 @@ void WII::statusRequest() { /************************************************************/ /* Memmory Commands */ - /************************************************************/ + void WII::writeData(uint32_t offset, uint8_t size, uint8_t* data) { uint8_t cmd_buf[23]; cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02) @@ -1077,7 +1077,6 @@ void WII::calibrateWiiBalanceBoard() { /************************************************************/ /* WII Commands */ - /************************************************************/ bool WII::getButtonPress(ButtonEnum b) { // Return true when a button is pressed @@ -1129,6 +1128,30 @@ void WII::onInit() { setLedStatus(); } +/************************************************************/ +/* Wii Balance Board Commands */ +/************************************************************/ + +float WII::getWeight(BalanceBoardEnum pos) { + // Based on: https://github.com/skorokithakis/gr8w8upd8m8/blob/master/gr8w8upd8m8.py + // calibration[pos][0] is calibration values for 0 kg + // calibration[pos][1] is calibration values for 17 kg + // calibration[pos][2] is calibration values for 34 kg + float val = 0; + if(balanceBoardRaw[pos] < balanceBoardCal[0][pos]) + return val; + else if(balanceBoardRaw[pos] < balanceBoardCal[1][pos]) + val = 17 * ((balanceBoardRaw[pos] - balanceBoardCal[0][pos]) / float((balanceBoardCal[1][pos] - balanceBoardCal[0][pos]))); + else if(balanceBoardRaw[pos] > balanceBoardCal[1][pos]) + val = 17 + 17 * ((balanceBoardRaw[pos] - balanceBoardCal[1][pos]) / float((balanceBoardCal[2][pos] - balanceBoardCal[1][pos]))); + + return val; +}; + +float WII::getTotalWeight() { + return getWeight(TopRight) + getWeight(BotRight) + getWeight(TopLeft) + getWeight(BotLeft); +}; + /************************************************************/ /* The following functions are for the IR camera */ /************************************************************/ diff --git a/Wii.h b/Wii.h index 91026469..3922aca8 100755 --- a/Wii.h +++ b/Wii.h @@ -278,29 +278,13 @@ public: * @param ::BalanceBoardEnum to read from. * @return Returns the weight in kg. */ - float getWeight(BalanceBoardEnum pos) { - // Based on: https://github.com/skorokithakis/gr8w8upd8m8/blob/master/gr8w8upd8m8.py - // calibration[pos][0] is calibration values for 0 kg - // calibration[pos][1] is calibration values for 17 kg - // calibration[pos][2] is calibration values for 34 kg - float val = 0; - if(balanceBoardRaw[pos] < balanceBoardCal[0][pos]) - return val; - else if(balanceBoardRaw[pos] < balanceBoardCal[1][pos]) - val = 17 * ((balanceBoardRaw[pos] - balanceBoardCal[0][pos]) / float((balanceBoardCal[1][pos] - balanceBoardCal[0][pos]))); - else if(balanceBoardRaw[pos] > balanceBoardCal[1][pos]) - val = 17 + 17 * ((balanceBoardRaw[pos] - balanceBoardCal[1][pos]) / float((balanceBoardCal[2][pos] - balanceBoardCal[1][pos]))); - - return val; - }; + float getWeight(BalanceBoardEnum pos); /** * Used to get total weight on the Wii Balance Board. * @returnReturns the weight in kg. */ - float getTotalWeight() { - return getWeight(TopRight) + getWeight(BotRight) + getWeight(TopLeft) + getWeight(BotLeft); - }; + float getTotalWeight(); /** * Used to get the raw reading at the specific position on the Wii Balance Board. From 7334f7e9a4667e35327342f6fe32989f08392b7e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 19:45:03 +0200 Subject: [PATCH 048/220] Changed some variable names and simplified the way the weight is calculated There was actually a bug, as it will return 0 if wiiBalanceBoardRaw[pos] is exactly the same as wiiBalanceBoardCal[1][pos] --- Wii.cpp | 35 ++++++++++++++++------------------- Wii.h | 6 +++--- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index 72c26113..f8d7186d 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -399,11 +399,11 @@ void WII::ACLData(uint8_t* l2capinbuf) { else if(l2capinbuf[13] == 0x00 && l2capinbuf[14] == 0x24 && reportLength == 16) { // First 16-bit for(uint8_t i = 0; i < 2; i++) { for(uint8_t j = 0; j < 4; j++) - balanceBoardCal[i][j] = l2capinbuf[16 + 8 * i + 2 * j] | l2capinbuf[15 + 8 * i + 2 * j] << 8; + wiiBalanceBoardCal[i][j] = l2capinbuf[16 + 8 * i + 2 * j] | l2capinbuf[15 + 8 * i + 2 * j] << 8; } } else if(l2capinbuf[13] == 0x00 && l2capinbuf[14] == 0x34 && reportLength == 8) { // Last 8-bit for(uint8_t j = 0; j < 4; j++) - balanceBoardCal[2][j] = l2capinbuf[16 + 2 * j] | l2capinbuf[15 + 2 * j] << 8; + wiiBalanceBoardCal[2][j] = l2capinbuf[16 + 2 * j] | l2capinbuf[15 + 2 * j] << 8; #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWii Balance Board calibrated successfully"), 0x80); #endif @@ -444,10 +444,10 @@ void WII::ACLData(uint8_t* l2capinbuf) { break; case 0x32: // Core Buttons with 8 Extension bytes - (a1) 32 BB BB EE EE EE EE EE EE EE EE // See: http://wiibrew.org/wiki/Wii_Balance_Board#Data_Format - balanceBoardRaw[TopRight] = l2capinbuf[13] | l2capinbuf[12] << 8; // Top right - balanceBoardRaw[BotRight] = l2capinbuf[15] | l2capinbuf[14] << 8; // Bottom right - balanceBoardRaw[TopLeft] = l2capinbuf[17] | l2capinbuf[16] << 8; // Top left - balanceBoardRaw[BotLeft] = l2capinbuf[19] | l2capinbuf[18] << 8; // Bottom left + wiiBalanceBoardRaw[TopRight] = l2capinbuf[13] | l2capinbuf[12] << 8; // Top right + wiiBalanceBoardRaw[BotRight] = l2capinbuf[15] | l2capinbuf[14] << 8; // Bottom right + wiiBalanceBoardRaw[TopLeft] = l2capinbuf[17] | l2capinbuf[16] << 8; // Top left + wiiBalanceBoardRaw[BotLeft] = l2capinbuf[19] | l2capinbuf[18] << 8; // Bottom left break; case 0x33: // Core Buttons with Accelerometer and 12 IR bytes - (a1) 33 BB BB AA AA AA II II II II II II II II II II II II #ifdef WIICAMERA @@ -1133,19 +1133,16 @@ void WII::onInit() { /************************************************************/ float WII::getWeight(BalanceBoardEnum pos) { - // Based on: https://github.com/skorokithakis/gr8w8upd8m8/blob/master/gr8w8upd8m8.py - // calibration[pos][0] is calibration values for 0 kg - // calibration[pos][1] is calibration values for 17 kg - // calibration[pos][2] is calibration values for 34 kg - float val = 0; - if(balanceBoardRaw[pos] < balanceBoardCal[0][pos]) - return val; - else if(balanceBoardRaw[pos] < balanceBoardCal[1][pos]) - val = 17 * ((balanceBoardRaw[pos] - balanceBoardCal[0][pos]) / float((balanceBoardCal[1][pos] - balanceBoardCal[0][pos]))); - else if(balanceBoardRaw[pos] > balanceBoardCal[1][pos]) - val = 17 + 17 * ((balanceBoardRaw[pos] - balanceBoardCal[1][pos]) / float((balanceBoardCal[2][pos] - balanceBoardCal[1][pos]))); - - return val; + // Use interpolating between two points - based on: https://github.com/skorokithakis/gr8w8upd8m8/blob/master/gr8w8upd8m8.py + // wiiBalanceBoardCal[pos][0] is calibration values for 0 kg + // wiiBalanceBoardCal[pos][1] is calibration values for 17 kg + // wiiBalanceBoardCal[pos][2] is calibration values for 34 kg + if(wiiBalanceBoardRaw[pos] < wiiBalanceBoardCal[0][pos]) + return 0.0f; // Below 0 kg + else if(wiiBalanceBoardRaw[pos] < wiiBalanceBoardCal[1][pos]) // Between 0 and 17 kg + return 17.0f * (float)(wiiBalanceBoardRaw[pos] - wiiBalanceBoardCal[0][pos]) / (float)(wiiBalanceBoardCal[1][pos] - wiiBalanceBoardCal[0][pos]); + else // More than 17 kg + return 17.0f + 17.0f * (float)(wiiBalanceBoardRaw[pos] - wiiBalanceBoardCal[1][pos]) / (float)(wiiBalanceBoardCal[2][pos] - wiiBalanceBoardCal[1][pos]); }; float WII::getTotalWeight() { diff --git a/Wii.h b/Wii.h index 3922aca8..3cf4edc0 100755 --- a/Wii.h +++ b/Wii.h @@ -292,7 +292,7 @@ public: * @return Returns the raw reading. */ uint16_t getWeightRaw(BalanceBoardEnum pos) { - return balanceBoardRaw[pos]; + return wiiBalanceBoardRaw[pos]; }; /** Indicates when the calibration of the Wii Balance Board is done. */ @@ -481,8 +481,8 @@ private: void activateMotionPlus(); void calibrateWiiBalanceBoard(); - uint16_t balanceBoardRaw[4]; // Wii Balance Board raw values - uint16_t balanceBoardCal[3][4]; // Wii Balance Board calibration values + uint16_t wiiBalanceBoardRaw[4]; // Wii Balance Board raw values + uint16_t wiiBalanceBoardCal[3][4]; // Wii Balance Board calibration values double compPitch; // Fusioned angle using a complimentary filter if the Motion Plus is connected double compRoll; // Fusioned angle using a complimentary filter if the Motion Plus is connected From 9426e4192d2dc89801f7f5a0c25cd527dc435db6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 20:19:33 +0200 Subject: [PATCH 049/220] Updated some variables names and updated some debug messages --- Wii.cpp | 15 ++++++++------- Wii.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index f8d7186d..189bdcd3 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -264,7 +264,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { else if(wiiUProControllerConnected) ButtonState = (uint32_t)(((~l2capinbuf[23]) & 0xFE) | ((uint16_t)(~l2capinbuf[24]) << 8) | ((uint32_t)((~l2capinbuf[25]) & 0x03) << 16)); else if(motionPlusConnected) { - if(l2capinbuf[20] & 0x02) // Only update the wiimote buttons, since the extension bytes are from the Motion Plus + if(l2capinbuf[20] & 0x02) // Only update the Wiimote buttons, since the extension bytes are from the Motion Plus ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)(ButtonState & 0xFFFF0000))); else if(nunchuckConnected) // Update if it's a report from the Nunchuck ButtonState = (uint32_t)((l2capinbuf[10] & 0x1F) | ((uint16_t)(l2capinbuf[11] & 0x9F) << 8) | ((uint32_t)((~l2capinbuf[20]) & 0x0C) << 14)); @@ -332,10 +332,11 @@ void WII::ACLData(uint8_t* l2capinbuf) { setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer } } -#ifdef DEBUG_USB_HOST +#ifdef EXTRADEBUG else Notify(PSTR("\r\nChecking battery level"), 0x80); - +#endif +#ifdef DEBUG_USB_HOST if(l2capinbuf[12] & 0x01) Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80); #endif @@ -405,7 +406,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { for(uint8_t j = 0; j < 4; j++) wiiBalanceBoardCal[2][j] = l2capinbuf[16 + 2 * j] | l2capinbuf[15 + 2 * j] << 8; #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nWii Balance Board calibrated successfully"), 0x80); + Notify(PSTR("\r\nWii Balance Board calibration values read successfully"), 0x80); #endif wiiBalanceBoardCalibrationComplete = true; } @@ -793,9 +794,9 @@ void WII::Run() { } else if(stateCounter == 400) { if(wiiBalanceBoardConnected) { #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nCalibrating Wii Balance Board"), 0x80); + Notify(PSTR("\r\nReading Wii Balance Board calibration values"), 0x80); #endif - calibrateWiiBalanceBoard(); + readWiiBalanceBoardCalibration(); } else stateCounter = 499; } else if(stateCounter == 500) { @@ -1071,7 +1072,7 @@ void WII::checkMotionPresent() { readData(0xA600FA, 6, false); } -void WII::calibrateWiiBalanceBoard() { +void WII::readWiiBalanceBoardCalibration() { readData(0xA40024, 24, false); } diff --git a/Wii.h b/Wii.h index 3cf4edc0..2a3b5a3e 100755 --- a/Wii.h +++ b/Wii.h @@ -475,11 +475,11 @@ private: void readData(uint32_t offset, uint16_t size, bool EEPROM); void readExtensionType(); void readCalData(); + void readWiiBalanceBoardCalibration(); // Used by the library to read the Wii Balance Board calibration values void checkMotionPresent(); // Used to see if a Motion Plus is connected to the Wiimote void initMotionPlus(); void activateMotionPlus(); - void calibrateWiiBalanceBoard(); uint16_t wiiBalanceBoardRaw[4]; // Wii Balance Board raw values uint16_t wiiBalanceBoardCal[3][4]; // Wii Balance Board calibration values From 2ebc8129a748ce1f48c26ccede0418775117188a Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 20:20:27 +0200 Subject: [PATCH 050/220] Show users how to easily save a lot of program space if extensions are not used --- Wii.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Wii.cpp b/Wii.cpp index 189bdcd3..d4b36381 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -494,6 +494,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { break; case 0x35: // Core Buttons and Accelerometer with 16 Extension Bytes // (a1) 35 BB BB AA AA AA EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE EE +#if 1 // Set this to 0 if you don't want to use an extension, this reduceds the size of the library a lot! if(motionPlusConnected) { if(l2capinbuf[20] & 0x02) { // Check if it's a report from the Motion controller or the extension if(motionValuesReset) { // We will only use the values when the gyro value has been set @@ -597,6 +598,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { hatValues[LeftHatY] = (l2capinbuf[19] | l2capinbuf[20] << 8); hatValues[RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8); } +#endif break; #ifdef DEBUG_USB_HOST default: From c44a80534b0dc0f2ba5a979c921a88a77dd7f455 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 20:31:23 +0200 Subject: [PATCH 051/220] Added missing keyword --- keywords.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/keywords.txt b/keywords.txt index f4e19cd1..dff01c2a 100644 --- a/keywords.txt +++ b/keywords.txt @@ -270,6 +270,7 @@ nunchuckConnected KEYWORD2 motionPlusConnected KEYWORD2 wiiUProControllerConnected KEYWORD2 wiiBalanceBoardConnected KEYWORD2 +wiiBalanceBoardCalibrationComplete KEYWORD2 setRumbleToggle KEYWORD2 getPitch KEYWORD2 getRoll KEYWORD2 From 11f80275a5e7abedf6f2d3eadbd4bc65bca1d3c6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 16 Apr 2015 22:08:33 +0200 Subject: [PATCH 052/220] Added information about Arduino Library Manager --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 60877437..864516e9 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ Help yourself by helping us support you! Many thousands of hours have been spent # Table of Contents * [How to include the library](#how-to-include-the-library) + * [Arduino Library Manager](#arduino-library-manager) + * [Manual installation](#manual-installation) * [How to use the library](#how-to-use-the-library) * [Documentation](#documentation) * [Enable debugging](#enable-debugging) @@ -57,6 +59,14 @@ Help yourself by helping us support you! Many thousands of hours have been spent # How to include the library +### Arduino Library Manager + +First install Arduino IDE version 1.6.2 or newer, then simply use the Arduino Library Manager to install the library. + +Please see the following page for instructions: . + +### Manual installation + First download the library by clicking on the following link: . Then uncompress the zip folder and rename the directory to "USB\_Host\_Shield\_20", as any special characters are not supported by the Arduino IDE. From 71580acca2e5f8ee9c7cc3388650356a3165dcd1 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Fri, 17 Apr 2015 22:51:41 +0200 Subject: [PATCH 053/220] PID was not checked properly in cdcprolific --- cdcprolific.cpp | 2 +- cdcprolific.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cdcprolific.cpp b/cdcprolific.cpp index 6490c40e..968fdc65 100644 --- a/cdcprolific.cpp +++ b/cdcprolific.cpp @@ -66,7 +66,7 @@ uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) { if(rcode) goto FailGetDevDescr; - if(udd->idVendor != PL_VID && udd->idProduct != PL_PID) + if(udd->idVendor != PL_VID && CHECK_PID(udd->idProduct)) return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Save type of PL chip diff --git a/cdcprolific.h b/cdcprolific.h index 32566585..15839550 100644 --- a/cdcprolific.h +++ b/cdcprolific.h @@ -20,7 +20,7 @@ e-mail : support@circuitsathome.com #include "cdcacm.h" #define PL_VID 0x067B -#define PL_PID ( 0x2303 || 0x0609 ) +#define CHECK_PID(pid) ( pid != 0x2303 && pid != 0x0609 ) //#define PL_PID 0x0609 From a032e0146598df5883945a5c67548b718da5dea7 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 20 Apr 2015 00:51:52 +0200 Subject: [PATCH 054/220] Fixed "warning: comparison between signed and unsigned integer expressions" Also return if length is too short --- PS4Parser.cpp | 17 ++++++++++++----- PSBuzz.cpp | 4 ++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/PS4Parser.cpp b/PS4Parser.cpp index 106d04ed..ca6adce4 100644 --- a/PS4Parser.cpp +++ b/PS4Parser.cpp @@ -62,7 +62,7 @@ uint8_t PS4Parser::getAnalogHat(AnalogHatEnum a) { } void PS4Parser::Parse(uint8_t len, uint8_t *buf) { - if (len > 0 && buf) { + if (len > 1 && buf) { #ifdef PRINTREPORT Notify(PSTR("\r\n"), 0x80); for (uint8_t i = 0; i < len; i++) { @@ -72,10 +72,17 @@ void PS4Parser::Parse(uint8_t len, uint8_t *buf) { #endif if (buf[0] == 0x01) // Check report ID - memcpy(&ps4Data, buf + 1, min(len - 1, sizeof(ps4Data))); - else if (buf[0] == 0x11) // This report is send via Bluetooth, it has an offset of 2 compared to the USB data - memcpy(&ps4Data, buf + 3, min(len - 3, sizeof(ps4Data))); - else { + memcpy(&ps4Data, buf + 1, min((uint8_t)(len - 1), sizeof(ps4Data))); + else if (buf[0] == 0x11) { // This report is send via Bluetooth, it has an offset of 2 compared to the USB data + if (len < 4) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nReport is too short: "), 0x80); + D_PrintHex (len, 0x80); +#endif + return; + } + memcpy(&ps4Data, buf + 3, min((uint8_t)(len - 3), sizeof(ps4Data))); + } else { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nUnknown report id: "), 0x80); D_PrintHex (buf[0], 0x80); diff --git a/PSBuzz.cpp b/PSBuzz.cpp index aa883712..498164d5 100644 --- a/PSBuzz.cpp +++ b/PSBuzz.cpp @@ -21,7 +21,7 @@ //#define PRINTREPORT // Uncomment to print the report send by the PS Buzz Controllers void PSBuzz::ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { - if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 0 && buf) { + if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 2 && buf) { #ifdef PRINTREPORT Notify(PSTR("\r\n"), 0x80); for (uint8_t i = 0; i < len; i++) { @@ -29,7 +29,7 @@ void PSBuzz::ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { Notify(PSTR(" "), 0x80); } #endif - memcpy(&psbuzzButtons, buf + 2, min(len - 2, sizeof(psbuzzButtons))); + memcpy(&psbuzzButtons, buf + 2, min((uint8_t)(len - 2), sizeof(psbuzzButtons))); if (psbuzzButtons.val != oldButtonState.val) { // Check if anything has changed buttonClickState.val = psbuzzButtons.val & ~oldButtonState.val; // Update click state variable From 5efed1938a57c4c60579b952d30cb28e68561ad1 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 20 Apr 2015 00:55:04 +0200 Subject: [PATCH 055/220] Fixed: "warning: value computed is not used [-Wunused-value]" See: http://stackoverflow.com/questions/4347684/pointer-value-computed-is-not-used-in-c-function --- Usb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Usb.cpp b/Usb.cpp index cd1c3496..14272588 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -92,7 +92,7 @@ uint8_t USB::SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_l return USB_ERROR_EP_NOT_FOUND_IN_TBL; *nak_limit = (0x0001UL << (((*ppep)->bmNakPower > USB_NAK_MAX_POWER) ? USB_NAK_MAX_POWER : (*ppep)->bmNakPower)); - *nak_limit--; + (*nak_limit)--; /* USBTRACE2("\r\nAddress: ", addr); USBTRACE2(" EP: ", ep); From 59af258a7982ac37762005fd999aa241b3cfbc7b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 20 Apr 2015 02:37:26 +0200 Subject: [PATCH 056/220] Fixed: "warning: "XR_REG_ERROR_STATUS_BREAK" redefined" --- cdc_XR21B1411.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cdc_XR21B1411.h b/cdc_XR21B1411.h index 347f0df6..c3262754 100644 --- a/cdc_XR21B1411.h +++ b/cdc_XR21B1411.h @@ -55,12 +55,12 @@ e-mail : support@circuitsathome.com #define XR_REG_ERROR_STATUS (0x0C09U) // ERROR STATUS REGISTER #define XR_REG_ERROR_STATUS_MASK (0x00F8U) // ERROR STATUS BITMASK -#define XR_REG_ERROR_STATUS_ERROR (0x0070U) // ERROR STATUS ERROR BITMASK -#define XR_REG_ERROR_STATUS_BREAK (0x0008U) // BREAK HAS BEEN DETECTED -#define XR_REG_ERROR_STATUS_OVERRUN (0x0010U) // RX OVERRUN ERROR -#define XR_REG_ERROR_STATUS_PARITY (0x0020U) // PARITY ERROR -#define XR_REG_ERROR_STATUS_FRAME (0x0040U) // FRAMING ERROR -#define XR_REG_ERROR_STATUS_BREAK (0x0080U) // BREAK IS BEING DETECTED +#define XR_REG_ERROR_STATUS_ERROR (0x0078U) // ERROR STATUS ERROR BITMASK +#define XR_REG_ERROR_STATUS_BREAK (0x0008U) // BREAK ERROR HAS BEEN DETECTED +#define XR_REG_ERROR_STATUS_FRAME (0x0010U) // FRAMING ERROR HAS BEEN DETECTED +#define XR_REG_ERROR_STATUS_PARITY (0x0020U) // PARITY ERROR HAS BEEN DETECTED +#define XR_REG_ERROR_STATUS_OVERRUN (0x0040U) // RX OVERRUN ERROR HAS BEEN DETECTED +#define XR_REG_ERROR_STATUS_BREAK_STATUS (0x0080U) // BREAK CONDITION IS CURRENTLY BEING DETECTED #define XR_REG_TX_BREAK (0x0C0AU) // TRANSMIT BREAK. 0X0001-0XFFE TIME IN MS, 0X0000 STOP, 0X0FFF BREAK ON From 50b6ce4c9c7051e61bc69ae8bf411bd3256b8fa6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 20 Apr 2015 03:03:04 +0200 Subject: [PATCH 057/220] All boards now rely on the SPI library after: https://github.com/felis/USB_Host_Shield_2.0/pull/137 --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3efcfb03..18776bed 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,6 @@ 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, 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. @@ -104,7 +103,6 @@ Currently the following boards are supported by the library: * Sanguino * Black Widdow * RedBearLab nRF51822 - * If you are using the RedBearLab nRF51822, then you must include the RedBearLab SPI library like so: ```#include ``` in your .ino file. * Digilent chipKIT * Please see: . @@ -337,3 +335,7 @@ LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0 ``` * This means that your dongle does not support 2.0+EDR, so you will need another dongle. Please see the following [list](https://github.com/felis/USB_Host_Shield_2.0/wiki/Bluetooth-dongles) for tested working dongles. + +> When compiling I am getting the following error: "fatal error: SPI.h: No such file or directory". + +* Please make sure to include the SPI library like so: ```#include ``` in your .ino file. \ No newline at end of file From 0ef5fa5357e9e152b2fd74644475281ac9515738 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 20 Apr 2015 21:44:31 +0200 Subject: [PATCH 058/220] Always prioritise USING_SPI4TEENSY3 if set to 1 Fixes: #147 --- usbhost.h | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/usbhost.h b/usbhost.h index 0a2b7bff..eba480e6 100644 --- a/usbhost.h +++ b/usbhost.h @@ -30,11 +30,7 @@ e-mail : support@circuitsathome.com /* SPI initialization */ template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_SS > class SPi { public: -#if SPI_HAS_TRANSACTION - static void init() { - SPI.begin(); // The SPI library with transaction will take care of setting up the pins - settings is set in beginTransaction() - } -#elif USING_SPI4TEENSY3 +#if USING_SPI4TEENSY3 static void init() { // spi4teensy3 inits everything for us, except /SS // CLK, MOSI and MISO are hard coded for now. @@ -43,6 +39,10 @@ public: SPI_SS::SetDirWrite(); SPI_SS::Set(); } +#elif SPI_HAS_TRANSACTION + static void init() { + SPI.begin(); // The SPI library with transaction will take care of setting up the pins - settings is set in beginTransaction() + } #elif !defined(SPDR) static void init() { SPI_SS::SetDirWrite(); @@ -157,16 +157,16 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { #endif SPI_SS::Clear(); -#if SPI_HAS_TRANSACTION - uint8_t c[2]; - c[0] = reg | 0x02; - c[1] = data; - SPI.transfer(c, 2); -#elif USING_SPI4TEENSY3 +#if USING_SPI4TEENSY3 uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; spi4teensy3::send(c, 2); +#elif SPI_HAS_TRANSACTION + uint8_t c[2]; + c[0] = reg | 0x02; + c[1] = data; + SPI.transfer(c, 2); #elif !defined(SPDR) SPI.transfer(reg | 0x02); SPI.transfer(data); @@ -195,14 +195,14 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* #endif SPI_SS::Clear(); -#if SPI_HAS_TRANSACTION - SPI.transfer(reg | 0x02); - SPI.transfer(data_p, nbytes); - data_p += nbytes; -#elif USING_SPI4TEENSY3 +#if USING_SPI4TEENSY3 spi4teensy3::send(reg | 0x02); spi4teensy3::send(data_p, nbytes); data_p += nbytes; +#elif SPI_HAS_TRANSACTION + SPI.transfer(reg | 0x02); + SPI.transfer(data_p, nbytes); + data_p += nbytes; #elif defined(__ARDUINO_X86__) SPI.transfer(reg | 0x02); SPI.transferBuffer(data_p, NULL, nbytes); @@ -253,14 +253,14 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { #endif SPI_SS::Clear(); -#if !defined(SPDR) || SPI_HAS_TRANSACTION - SPI.transfer(reg); - uint8_t rv = SPI.transfer(0); // Send empty byte - SPI_SS::Set(); -#elif USING_SPI4TEENSY3 +#if USING_SPI4TEENSY3 spi4teensy3::send(reg); uint8_t rv = spi4teensy3::receive(); SPI_SS::Set(); +#elif !defined(SPDR) || SPI_HAS_TRANSACTION + SPI.transfer(reg); + uint8_t rv = SPI.transfer(0); // Send empty byte + SPI_SS::Set(); #else SPDR = reg; while(!(SPSR & (1 << SPIF))); @@ -287,15 +287,15 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* #endif SPI_SS::Clear(); -#if SPI_HAS_TRANSACTION +#if USING_SPI4TEENSY3 + spi4teensy3::send(reg); + spi4teensy3::receive(data_p, nbytes); + data_p += nbytes; +#elif SPI_HAS_TRANSACTION SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes SPI.transfer(data_p, nbytes); data_p += nbytes; -#elif USING_SPI4TEENSY3 - spi4teensy3::send(reg); - spi4teensy3::receive(data_p, nbytes); - data_p += nbytes; #elif defined(__ARDUINO_X86__) SPI.transfer(reg); SPI.transferBuffer(NULL, data_p, nbytes); From e4c581c99153d7ef6af49577ba903ed00e60942a Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 20 Apr 2015 23:39:57 +0200 Subject: [PATCH 059/220] The is no need for Wii calibration flag to have its own variable --- Wii.cpp | 8 ++++---- Wii.h | 8 +++----- examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino | 2 +- keywords.txt | 1 - 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index d4b36381..aef7613a 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -393,8 +393,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { Notify(PSTR("\r\nWii Balance Board connected"), 0x80); #endif setReportMode(false, 0x32); // Read the Wii Balance Board extension - wiiBalanceBoardCalibrationComplete = false; - wiiBalanceBoardConnected = true; + wii_set_flag(WII_FLAG_CALIBRATE_BALANCE_BOARD); } // Wii Balance Board calibration reports (24 bits in total) else if(l2capinbuf[13] == 0x00 && l2capinbuf[14] == 0x24 && reportLength == 16) { // First 16-bit @@ -408,7 +407,8 @@ void WII::ACLData(uint8_t* l2capinbuf) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nWii Balance Board calibration values read successfully"), 0x80); #endif - wiiBalanceBoardCalibrationComplete = true; + wii_clear_flag(WII_FLAG_CALIBRATE_BALANCE_BOARD); + wiiBalanceBoardConnected = true; } #ifdef DEBUG_USB_HOST else { @@ -794,7 +794,7 @@ void WII::Run() { readExtensionType(); unknownExtensionConnected = false; } else if(stateCounter == 400) { - if(wiiBalanceBoardConnected) { + if(wii_check_flag(WII_FLAG_CALIBRATE_BALANCE_BOARD)) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nReading Wii Balance Board calibration values"), 0x80); #endif diff --git a/Wii.h b/Wii.h index 2a3b5a3e..960f2273 100755 --- a/Wii.h +++ b/Wii.h @@ -24,8 +24,9 @@ #include "controllerEnums.h" /* Wii event flags */ -#define WII_FLAG_MOTION_PLUS_CONNECTED 0x01 -#define WII_FLAG_NUNCHUCK_CONNECTED 0x02 +#define WII_FLAG_MOTION_PLUS_CONNECTED (1 << 0) +#define WII_FLAG_NUNCHUCK_CONNECTED (1 << 1) +#define WII_FLAG_CALIBRATE_BALANCE_BOARD (1 << 2) #define wii_check_flag(flag) (wii_event_flag & (flag)) #define wii_set_flag(flag) (wii_event_flag |= (flag)) @@ -294,9 +295,6 @@ public: uint16_t getWeightRaw(BalanceBoardEnum pos) { return wiiBalanceBoardRaw[pos]; }; - - /** Indicates when the calibration of the Wii Balance Board is done. */ - bool wiiBalanceBoardCalibrationComplete; /**@}*/ #ifdef WIICAMERA diff --git a/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino index 6186a179..18c5b411 100644 --- a/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino +++ b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino @@ -34,7 +34,7 @@ void setup() { } void loop() { Usb.Task(); - if (Wii.wiiBalanceBoardConnected && Wii.wiiBalanceBoardCalibrationComplete) { + if (Wii.wiiBalanceBoardConnected) { Serial.print(F("\r\nWeight: ")); for (uint8_t i = 0; i < 4; i++) { Serial.print(Wii.getWeight((BalanceBoardEnum)i)); diff --git a/keywords.txt b/keywords.txt index dff01c2a..f4e19cd1 100644 --- a/keywords.txt +++ b/keywords.txt @@ -270,7 +270,6 @@ nunchuckConnected KEYWORD2 motionPlusConnected KEYWORD2 wiiUProControllerConnected KEYWORD2 wiiBalanceBoardConnected KEYWORD2 -wiiBalanceBoardCalibrationComplete KEYWORD2 setRumbleToggle KEYWORD2 getPitch KEYWORD2 getRoll KEYWORD2 From b3303d14fc9594efa3b2d538c29ce38da9bb1056 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 20 Apr 2015 23:40:34 +0200 Subject: [PATCH 060/220] Set checkBatteryLevel false only when it was actually true --- Wii.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index aef7613a..4bbf4c91 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -332,16 +332,17 @@ void WII::ACLData(uint8_t* l2capinbuf) { setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer } } + else { #ifdef EXTRADEBUG - else Notify(PSTR("\r\nChecking battery level"), 0x80); #endif + checkBatteryLevel = false; // Check for extensions by default + } #ifdef DEBUG_USB_HOST if(l2capinbuf[12] & 0x01) Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80); #endif - checkBatteryLevel = false; // Check for extensions by default break; case 0x21: // Read Memory Data if((l2capinbuf[12] & 0x0F) == 0) { // No error From 1f3072b343acdaf1d18d7997609234c2ad8903ac Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 20 Apr 2015 23:42:41 +0200 Subject: [PATCH 061/220] Added Nordic nRF51 to supported platforms for PlatformIO --- library.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index 6f7c5753..1d649b1e 100644 --- a/library.json +++ b/library.json @@ -41,6 +41,7 @@ [ "atmelavr", "teensy", - "atmelsam" + "atmelsam", + "nordicnrf51" ] } From bce1541026cd346911e10ac2d5dda9e840edbcc9 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 22 Apr 2015 15:41:17 +0200 Subject: [PATCH 062/220] Fixed: warning: variable 'rcode' set but not used --- examples/USB_desc/USB_desc.ino | 2 +- examples/hub_demo/hub_demo.ino | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index 0ae15663..1af80340 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -240,7 +240,7 @@ byte getconfdescr( byte addr, byte conf ) }//switch( descr_type buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer }//while( buf_ptr <=... - return( 0 ); + return ( rcode ); } /* prints hex numbers with leading zeroes */ // copyright, Peter H Anderson, Baltimore, MD, Nov, '07 diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index 20685067..e8dc6ab9 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -236,7 +236,7 @@ byte getconfdescr( byte addr, byte conf ) }//switch( descr_type buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer }//while( buf_ptr <=... - return( 0 ); + return ( rcode ); } /* prints hex numbers with leading zeroes */ // copyright, Peter H Anderson, Baltimore, MD, Nov, '07 From 5053e8dfae0be9764bedf5448e59e7a16472fd22 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 22 Apr 2015 15:48:18 +0200 Subject: [PATCH 063/220] Don't use deprecated prog_ macro Fixes: #147 --- examples/USB_desc/USB_desc.ino | 2 +- examples/hub_demo/hub_demo.ino | 2 +- version_helper.h | 28 ---------------------------- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index 1af80340..4dc9a780 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -340,7 +340,7 @@ void printunkdescr( uint8_t* descr_ptr ) /* Print a string from Program Memory directly to save RAM */ -void printProgStr(prog_char str[]) +void printProgStr(const char* str) { char c; if(!str) return; diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index e8dc6ab9..81aae805 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -336,7 +336,7 @@ void printunkdescr( uint8_t* descr_ptr ) /* Print a string from Program Memory directly to save RAM */ -void printProgStr(prog_char str[]) +void printProgStr(const char* str) { char c; if(!str) return; diff --git a/version_helper.h b/version_helper.h index b018000e..0cb3b4ad 100644 --- a/version_helper.h +++ b/version_helper.h @@ -53,34 +53,6 @@ e-mail : support@circuitsathome.com #define _SFR_BYTE(n) (n) #endif -#ifndef prog_void -typedef void prog_void; -#endif -#ifndef prog_char -typedef char prog_char; -#endif -#ifndef prog_uchar -typedef unsigned char prog_uchar; -#endif -#ifndef prog_int8_t -typedef int8_t prog_int8_t; -#endif -#ifndef prog_uint8_t -typedef uint8_t prog_uint8_t; -#endif -#ifndef prog_int16_t -typedef int16_t prog_int16_t; -#endif -#ifndef prog_uint16_t -typedef uint16_t prog_uint16_t; -#endif -#ifndef prog_int32_t -typedef int32_t prog_int32_t; -#endif -#ifndef prog_uint32_t -typedef uint32_t prog_uint32_t; -#endif - #ifndef memchr_P #define memchr_P(str, c, len) memchr((str), (c), (len)) #endif From cbea36f76ffa0a0b1f74eb59e7ec845ccba380aa Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 22 Apr 2015 15:48:43 +0200 Subject: [PATCH 064/220] Fixed formatting No new code added --- examples/USB_desc/USB_desc.ino | 192 ++++++++++++++++----------------- examples/hub_demo/hub_demo.ino | 192 ++++++++++++++++----------------- 2 files changed, 192 insertions(+), 192 deletions(-) diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index 4dc9a780..acfe57d3 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -21,31 +21,31 @@ uint32_t next_time; void PrintAllAddresses(UsbDevice *pdev) { - UsbDeviceAddress adr; - adr.devAddress = pdev->address.devAddress; - Serial.print("\r\nAddr:"); - Serial.print(adr.devAddress, HEX); - Serial.print("("); - Serial.print(adr.bmHub, HEX); - Serial.print("."); - Serial.print(adr.bmParent, HEX); - Serial.print("."); - Serial.print(adr.bmAddress, HEX); - Serial.println(")"); + UsbDeviceAddress adr; + adr.devAddress = pdev->address.devAddress; + Serial.print("\r\nAddr:"); + Serial.print(adr.devAddress, HEX); + Serial.print("("); + Serial.print(adr.bmHub, HEX); + Serial.print("."); + Serial.print(adr.bmParent, HEX); + Serial.print("."); + Serial.print(adr.bmAddress, HEX); + Serial.println(")"); } void PrintAddress(uint8_t addr) { - UsbDeviceAddress adr; - adr.devAddress = addr; - Serial.print("\r\nADDR:\t"); - Serial.println(adr.devAddress,HEX); - Serial.print("DEV:\t"); - Serial.println(adr.bmAddress,HEX); - Serial.print("PRNT:\t"); - Serial.println(adr.bmParent,HEX); - Serial.print("HUB:\t"); - Serial.println(adr.bmHub,HEX); + UsbDeviceAddress adr; + adr.devAddress = addr; + Serial.print("\r\nADDR:\t"); + Serial.println(adr.devAddress, HEX); + Serial.print("DEV:\t"); + Serial.println(adr.bmAddress, HEX); + Serial.print("PRNT:\t"); + Serial.println(adr.bmParent, HEX); + Serial.print("HUB:\t"); + Serial.println(adr.bmHub, HEX); } void setup() @@ -57,7 +57,7 @@ void setup() Serial.println("Start"); if (Usb.Init() == -1) - Serial.println("OSC did not start."); + Serial.println("OSC did not start."); delay( 200 ); @@ -68,49 +68,49 @@ byte getdevdescr( byte addr, byte &num_conf ); void PrintDescriptors(uint8_t addr) { - uint8_t rcode = 0; - byte num_conf = 0; + uint8_t rcode = 0; + byte num_conf = 0; - rcode = getdevdescr( (byte)addr, num_conf ); - if( rcode ) + rcode = getdevdescr( (byte)addr, num_conf ); + if ( rcode ) + { + printProgStr(Gen_Error_str); + print_hex( rcode, 8 ); + } + Serial.print("\r\n"); + + for (int i = 0; i < num_conf; i++) + { + rcode = getconfdescr( addr, i ); // get configuration descriptor + if ( rcode ) { printProgStr(Gen_Error_str); - print_hex( rcode, 8 ); - } - Serial.print("\r\n"); - - for (int i=0; iaddress.devAddress, 8); - Serial.println("\r\n--"); - PrintDescriptors( pdev->address.devAddress ); + Serial.println("\r\n"); + print_hex(pdev->address.devAddress, 8); + Serial.println("\r\n--"); + PrintDescriptors( pdev->address.devAddress ); } void loop() { Usb.Task(); - if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //if (millis() >= next_time) { - Usb.ForEachUsbDevice(&PrintAllDescriptors); - Usb.ForEachUsbDevice(&PrintAllAddresses); + Usb.ForEachUsbDevice(&PrintAllDescriptors); + Usb.ForEachUsbDevice(&PrintAllAddresses); - while( 1 ); //stop + while ( 1 ); //stop } } } @@ -120,8 +120,8 @@ byte getdevdescr( byte addr, byte &num_conf ) USB_DEVICE_DESCRIPTOR buf; byte rcode; rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf ); - if( rcode ) { - return( rcode ); + if ( rcode ) { + return ( rcode ); } printProgStr(Dev_Header_str); printProgStr(Dev_Length_str); @@ -153,53 +153,53 @@ byte getdevdescr( byte addr, byte &num_conf ) printProgStr(Dev_Nconf_str); print_hex( buf.bNumConfigurations, 8 ); num_conf = buf.bNumConfigurations; - return( 0 ); + return ( 0 ); } void printhubdescr(uint8_t *descrptr, uint8_t addr) { - HubDescriptor *pHub = (HubDescriptor*) descrptr; - uint8_t len = *((uint8_t*)descrptr); + HubDescriptor *pHub = (HubDescriptor*) descrptr; + uint8_t len = *((uint8_t*)descrptr); - printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n")); - printProgStr(PSTR("bDescLength:\t\t")); - Serial.println(pHub->bDescLength, HEX); + printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n")); + printProgStr(PSTR("bDescLength:\t\t")); + Serial.println(pHub->bDescLength, HEX); - printProgStr(PSTR("bDescriptorType:\t")); - Serial.println(pHub->bDescriptorType, HEX); + printProgStr(PSTR("bDescriptorType:\t")); + Serial.println(pHub->bDescriptorType, HEX); - printProgStr(PSTR("bNbrPorts:\t\t")); - Serial.println(pHub->bNbrPorts, HEX); + printProgStr(PSTR("bNbrPorts:\t\t")); + Serial.println(pHub->bNbrPorts, HEX); - printProgStr(PSTR("LogPwrSwitchMode:\t")); - Serial.println(pHub->LogPwrSwitchMode, BIN); + printProgStr(PSTR("LogPwrSwitchMode:\t")); + Serial.println(pHub->LogPwrSwitchMode, BIN); - printProgStr(PSTR("CompoundDevice:\t\t")); - Serial.println(pHub->CompoundDevice, BIN); + printProgStr(PSTR("CompoundDevice:\t\t")); + Serial.println(pHub->CompoundDevice, BIN); - printProgStr(PSTR("OverCurrentProtectMode:\t")); - Serial.println(pHub->OverCurrentProtectMode, BIN); + printProgStr(PSTR("OverCurrentProtectMode:\t")); + Serial.println(pHub->OverCurrentProtectMode, BIN); - printProgStr(PSTR("TTThinkTime:\t\t")); - Serial.println(pHub->TTThinkTime, BIN); + printProgStr(PSTR("TTThinkTime:\t\t")); + Serial.println(pHub->TTThinkTime, BIN); - printProgStr(PSTR("PortIndicatorsSupported:")); - Serial.println(pHub->PortIndicatorsSupported, BIN); + printProgStr(PSTR("PortIndicatorsSupported:")); + Serial.println(pHub->PortIndicatorsSupported, BIN); - printProgStr(PSTR("Reserved:\t\t")); - Serial.println(pHub->Reserved, HEX); + printProgStr(PSTR("Reserved:\t\t")); + Serial.println(pHub->Reserved, HEX); - printProgStr(PSTR("bPwrOn2PwrGood:\t\t")); - Serial.println(pHub->bPwrOn2PwrGood, HEX); + printProgStr(PSTR("bPwrOn2PwrGood:\t\t")); + Serial.println(pHub->bPwrOn2PwrGood, HEX); - printProgStr(PSTR("bHubContrCurrent:\t")); - Serial.println(pHub->bHubContrCurrent, HEX); + printProgStr(PSTR("bHubContrCurrent:\t")); + Serial.println(pHub->bHubContrCurrent, HEX); - for (uint8_t i=7; ibNbrPorts; i++) - // PrintHubPortStatus(&Usb, addr, i, 1); + //for (uint8_t i=1; i<=pHub->bNbrPorts; i++) + // PrintHubPortStatus(&Usb, addr, i, 1); } byte getconfdescr( byte addr, byte conf ) @@ -213,22 +213,22 @@ byte getconfdescr( byte addr, byte conf ) rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length LOBYTE( total_length ) = buf[ 2 ]; HIBYTE( total_length ) = buf[ 3 ]; - if( total_length > 256 ) { //check if total length is larger than buffer + if ( total_length > 256 ) { //check if total length is larger than buffer printProgStr(Conf_Trunc_str); total_length = 256; } rcode = Usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor - while( buf_ptr < buf + total_length ) { //parsing descriptors + while ( buf_ptr < buf + total_length ) { //parsing descriptors descr_length = *( buf_ptr ); descr_type = *( buf_ptr + 1 ); - switch( descr_type ) { - case( USB_DESCRIPTOR_CONFIGURATION ): + switch ( descr_type ) { + case ( USB_DESCRIPTOR_CONFIGURATION ): printconfdescr( buf_ptr ); break; - case( USB_DESCRIPTOR_INTERFACE ): + case ( USB_DESCRIPTOR_INTERFACE ): printintfdescr( buf_ptr ); break; - case( USB_DESCRIPTOR_ENDPOINT ): + case ( USB_DESCRIPTOR_ENDPOINT ): printepdescr( buf_ptr ); break; case 0x29: @@ -237,7 +237,7 @@ byte getconfdescr( byte addr, byte conf ) default: printunkdescr( buf_ptr ); break; - }//switch( descr_type + }//switch( descr_type buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer }//while( buf_ptr <=... return ( rcode ); @@ -247,9 +247,9 @@ byte getconfdescr( byte addr, byte conf ) // source: http://www.phanderson.com/arduino/arduino_display.html void print_hex(int v, int num_places) { - int mask=0, n, num_nibbles, digit; + int mask = 0, n, num_nibbles, digit; - for (n=1; n<=num_places; n++) { + for (n = 1; n <= num_places; n++) { mask = (mask << 1) | 0x0001; } v = v & mask; // truncate v to specified number of places @@ -259,15 +259,15 @@ void print_hex(int v, int num_places) ++num_nibbles; } do { - digit = ((v >> (num_nibbles-1) * 4)) & 0x0f; + digit = ((v >> (num_nibbles - 1) * 4)) & 0x0f; Serial.print(digit, HEX); } - while(--num_nibbles); + while (--num_nibbles); } /* function to print configuration descriptor */ void printconfdescr( uint8_t* descr_ptr ) { - USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr; + USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr; printProgStr(Conf_Header_str); printProgStr(Conf_Totlen_str); print_hex( conf_ptr->wTotalLength, 16 ); @@ -286,7 +286,7 @@ void printconfdescr( uint8_t* descr_ptr ) /* function to print interface descriptor */ void printintfdescr( uint8_t* descr_ptr ) { - USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr; + USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr; printProgStr(Int_Header_str); printProgStr(Int_Number_str); print_hex( intf_ptr->bInterfaceNumber, 8 ); @@ -307,7 +307,7 @@ void printintfdescr( uint8_t* descr_ptr ) /* function to print endpoint descriptor */ void printepdescr( uint8_t* descr_ptr ) { - USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr; + USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr; printProgStr(End_Header_str); printProgStr(End_Address_str); print_hex( ep_ptr->bEndpointAddress, 8 ); @@ -332,7 +332,7 @@ void printunkdescr( uint8_t* descr_ptr ) print_hex( *(descr_ptr + 1 ), 8 ); printProgStr(Unk_Contents_str); descr_ptr += 2; - for( i = 0; i < length; i++ ) { + for ( i = 0; i < length; i++ ) { print_hex( *descr_ptr, 8 ); descr_ptr++; } @@ -343,7 +343,7 @@ void printunkdescr( uint8_t* descr_ptr ) void printProgStr(const char* str) { char c; - if(!str) return; - while((c = pgm_read_byte(str++))) + if (!str) return; + while ((c = pgm_read_byte(str++))) Serial.print(c); } diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index 81aae805..d8b2d4bb 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -17,31 +17,31 @@ uint32_t next_time; void PrintAllAddresses(UsbDevice *pdev) { - UsbDeviceAddress adr; - adr.devAddress = pdev->address.devAddress; - Serial.print("\r\nAddr:"); - Serial.print(adr.devAddress, HEX); - Serial.print("("); - Serial.print(adr.bmHub, HEX); - Serial.print("."); - Serial.print(adr.bmParent, HEX); - Serial.print("."); - Serial.print(adr.bmAddress, HEX); - Serial.println(")"); + UsbDeviceAddress adr; + adr.devAddress = pdev->address.devAddress; + Serial.print("\r\nAddr:"); + Serial.print(adr.devAddress, HEX); + Serial.print("("); + Serial.print(adr.bmHub, HEX); + Serial.print("."); + Serial.print(adr.bmParent, HEX); + Serial.print("."); + Serial.print(adr.bmAddress, HEX); + Serial.println(")"); } void PrintAddress(uint8_t addr) { - UsbDeviceAddress adr; - adr.devAddress = addr; - Serial.print("\r\nADDR:\t"); - Serial.println(adr.devAddress,HEX); - Serial.print("DEV:\t"); - Serial.println(adr.bmAddress,HEX); - Serial.print("PRNT:\t"); - Serial.println(adr.bmParent,HEX); - Serial.print("HUB:\t"); - Serial.println(adr.bmHub,HEX); + UsbDeviceAddress adr; + adr.devAddress = addr; + Serial.print("\r\nADDR:\t"); + Serial.println(adr.devAddress, HEX); + Serial.print("DEV:\t"); + Serial.println(adr.bmAddress, HEX); + Serial.print("PRNT:\t"); + Serial.println(adr.bmParent, HEX); + Serial.print("HUB:\t"); + Serial.println(adr.bmHub, HEX); } void setup() @@ -53,7 +53,7 @@ void setup() Serial.println("Start"); if (Usb.Init() == -1) - Serial.println("OSC did not start."); + Serial.println("OSC did not start."); delay( 200 ); @@ -64,49 +64,49 @@ byte getdevdescr( byte addr, byte &num_conf ); void PrintDescriptors(uint8_t addr) { - uint8_t rcode = 0; - byte num_conf = 0; + uint8_t rcode = 0; + byte num_conf = 0; - rcode = getdevdescr( (byte)addr, num_conf ); - if( rcode ) + rcode = getdevdescr( (byte)addr, num_conf ); + if ( rcode ) + { + printProgStr(Gen_Error_str); + print_hex( rcode, 8 ); + } + Serial.print("\r\n"); + + for (int i = 0; i < num_conf; i++) + { + rcode = getconfdescr( addr, i ); // get configuration descriptor + if ( rcode ) { printProgStr(Gen_Error_str); - print_hex( rcode, 8 ); - } - Serial.print("\r\n"); - - for (int i=0; iaddress.devAddress, 8); - Serial.println("\r\n--"); - PrintDescriptors( pdev->address.devAddress ); + Serial.println("\r\n"); + print_hex(pdev->address.devAddress, 8); + Serial.println("\r\n--"); + PrintDescriptors( pdev->address.devAddress ); } void loop() { Usb.Task(); - if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { if ((millis() - next_time) >= 0L) { - Usb.ForEachUsbDevice(&PrintAllDescriptors); - Usb.ForEachUsbDevice(&PrintAllAddresses); + Usb.ForEachUsbDevice(&PrintAllDescriptors); + Usb.ForEachUsbDevice(&PrintAllAddresses); - while( 1 ); //stop + while ( 1 ); //stop } } } @@ -116,8 +116,8 @@ byte getdevdescr( byte addr, byte &num_conf ) USB_DEVICE_DESCRIPTOR buf; byte rcode; rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf ); - if( rcode ) { - return( rcode ); + if ( rcode ) { + return ( rcode ); } printProgStr(Dev_Header_str); printProgStr(Dev_Length_str); @@ -149,53 +149,53 @@ byte getdevdescr( byte addr, byte &num_conf ) printProgStr(Dev_Nconf_str); print_hex( buf.bNumConfigurations, 8 ); num_conf = buf.bNumConfigurations; - return( 0 ); + return ( 0 ); } void printhubdescr(uint8_t *descrptr, uint8_t addr) { - HubDescriptor *pHub = (HubDescriptor*) descrptr; - uint8_t len = *((uint8_t*)descrptr); + HubDescriptor *pHub = (HubDescriptor*) descrptr; + uint8_t len = *((uint8_t*)descrptr); - printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n")); - printProgStr(PSTR("bDescLength:\t\t")); - Serial.println(pHub->bDescLength, HEX); + printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n")); + printProgStr(PSTR("bDescLength:\t\t")); + Serial.println(pHub->bDescLength, HEX); - printProgStr(PSTR("bDescriptorType:\t")); - Serial.println(pHub->bDescriptorType, HEX); + printProgStr(PSTR("bDescriptorType:\t")); + Serial.println(pHub->bDescriptorType, HEX); - printProgStr(PSTR("bNbrPorts:\t\t")); - Serial.println(pHub->bNbrPorts, HEX); + printProgStr(PSTR("bNbrPorts:\t\t")); + Serial.println(pHub->bNbrPorts, HEX); - printProgStr(PSTR("LogPwrSwitchMode:\t")); - Serial.println(pHub->LogPwrSwitchMode, BIN); + printProgStr(PSTR("LogPwrSwitchMode:\t")); + Serial.println(pHub->LogPwrSwitchMode, BIN); - printProgStr(PSTR("CompoundDevice:\t\t")); - Serial.println(pHub->CompoundDevice, BIN); + printProgStr(PSTR("CompoundDevice:\t\t")); + Serial.println(pHub->CompoundDevice, BIN); - printProgStr(PSTR("OverCurrentProtectMode:\t")); - Serial.println(pHub->OverCurrentProtectMode, BIN); + printProgStr(PSTR("OverCurrentProtectMode:\t")); + Serial.println(pHub->OverCurrentProtectMode, BIN); - printProgStr(PSTR("TTThinkTime:\t\t")); - Serial.println(pHub->TTThinkTime, BIN); + printProgStr(PSTR("TTThinkTime:\t\t")); + Serial.println(pHub->TTThinkTime, BIN); - printProgStr(PSTR("PortIndicatorsSupported:")); - Serial.println(pHub->PortIndicatorsSupported, BIN); + printProgStr(PSTR("PortIndicatorsSupported:")); + Serial.println(pHub->PortIndicatorsSupported, BIN); - printProgStr(PSTR("Reserved:\t\t")); - Serial.println(pHub->Reserved, HEX); + printProgStr(PSTR("Reserved:\t\t")); + Serial.println(pHub->Reserved, HEX); - printProgStr(PSTR("bPwrOn2PwrGood:\t\t")); - Serial.println(pHub->bPwrOn2PwrGood, HEX); + printProgStr(PSTR("bPwrOn2PwrGood:\t\t")); + Serial.println(pHub->bPwrOn2PwrGood, HEX); - printProgStr(PSTR("bHubContrCurrent:\t")); - Serial.println(pHub->bHubContrCurrent, HEX); + printProgStr(PSTR("bHubContrCurrent:\t")); + Serial.println(pHub->bHubContrCurrent, HEX); - for (uint8_t i=7; ibNbrPorts; i++) - // PrintHubPortStatus(&Usb, addr, i, 1); + //for (uint8_t i=1; i<=pHub->bNbrPorts; i++) + // PrintHubPortStatus(&Usb, addr, i, 1); } byte getconfdescr( byte addr, byte conf ) @@ -209,22 +209,22 @@ byte getconfdescr( byte addr, byte conf ) rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length LOBYTE( total_length ) = buf[ 2 ]; HIBYTE( total_length ) = buf[ 3 ]; - if( total_length > 256 ) { //check if total length is larger than buffer + if ( total_length > 256 ) { //check if total length is larger than buffer printProgStr(Conf_Trunc_str); total_length = 256; } rcode = Usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor - while( buf_ptr < buf + total_length ) { //parsing descriptors + while ( buf_ptr < buf + total_length ) { //parsing descriptors descr_length = *( buf_ptr ); descr_type = *( buf_ptr + 1 ); - switch( descr_type ) { - case( USB_DESCRIPTOR_CONFIGURATION ): + switch ( descr_type ) { + case ( USB_DESCRIPTOR_CONFIGURATION ): printconfdescr( buf_ptr ); break; - case( USB_DESCRIPTOR_INTERFACE ): + case ( USB_DESCRIPTOR_INTERFACE ): printintfdescr( buf_ptr ); break; - case( USB_DESCRIPTOR_ENDPOINT ): + case ( USB_DESCRIPTOR_ENDPOINT ): printepdescr( buf_ptr ); break; case 0x29: @@ -233,7 +233,7 @@ byte getconfdescr( byte addr, byte conf ) default: printunkdescr( buf_ptr ); break; - }//switch( descr_type + }//switch( descr_type buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer }//while( buf_ptr <=... return ( rcode ); @@ -243,9 +243,9 @@ byte getconfdescr( byte addr, byte conf ) // source: http://www.phanderson.com/arduino/arduino_display.html void print_hex(int v, int num_places) { - int mask=0, n, num_nibbles, digit; + int mask = 0, n, num_nibbles, digit; - for (n=1; n<=num_places; n++) { + for (n = 1; n <= num_places; n++) { mask = (mask << 1) | 0x0001; } v = v & mask; // truncate v to specified number of places @@ -255,15 +255,15 @@ void print_hex(int v, int num_places) ++num_nibbles; } do { - digit = ((v >> (num_nibbles-1) * 4)) & 0x0f; + digit = ((v >> (num_nibbles - 1) * 4)) & 0x0f; Serial.print(digit, HEX); } - while(--num_nibbles); + while (--num_nibbles); } /* function to print configuration descriptor */ void printconfdescr( uint8_t* descr_ptr ) { - USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr; + USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr; printProgStr(Conf_Header_str); printProgStr(Conf_Totlen_str); print_hex( conf_ptr->wTotalLength, 16 ); @@ -282,7 +282,7 @@ void printconfdescr( uint8_t* descr_ptr ) /* function to print interface descriptor */ void printintfdescr( uint8_t* descr_ptr ) { - USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr; + USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr; printProgStr(Int_Header_str); printProgStr(Int_Number_str); print_hex( intf_ptr->bInterfaceNumber, 8 ); @@ -303,7 +303,7 @@ void printintfdescr( uint8_t* descr_ptr ) /* function to print endpoint descriptor */ void printepdescr( uint8_t* descr_ptr ) { - USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr; + USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr; printProgStr(End_Header_str); printProgStr(End_Address_str); print_hex( ep_ptr->bEndpointAddress, 8 ); @@ -328,7 +328,7 @@ void printunkdescr( uint8_t* descr_ptr ) print_hex( *(descr_ptr + 1 ), 8 ); printProgStr(Unk_Contents_str); descr_ptr += 2; - for( i = 0; i < length; i++ ) { + for ( i = 0; i < length; i++ ) { print_hex( *descr_ptr, 8 ); descr_ptr++; } @@ -339,7 +339,7 @@ void printunkdescr( uint8_t* descr_ptr ) void printProgStr(const char* str) { char c; - if(!str) return; - while((c = pgm_read_byte(str++))) + if (!str) return; + while ((c = pgm_read_byte(str++))) Serial.print(c); } From 5db356282f44121689097805391d23ebfaa35aa9 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 25 Apr 2015 01:39:08 +0200 Subject: [PATCH 065/220] Removed some hidden characters after closing parentheses --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 345b35f3..9f515696 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=USB Host Shield Library 2.0 version=1.0.0 -author=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll , Alexei Glushchenko (Circuits@Home)  +author=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll , Alexei Glushchenko (Circuits@Home) maintainer=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll sentence=Revision 2.0 of MAX3421E-based USB Host Shield Library. paragraph=Supports HID devices, FTDI, ADK, ACM, PL2303, Bluetooth HID devices, SPP communication and mass storage devices. Furthermore it supports PS3, PS4, PS Buzz, Wii and Xbox controllers. From 98c25155c8fb6855e1dafd822de7cf6b8285e2f2 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 28 Apr 2015 12:20:18 +0200 Subject: [PATCH 066/220] Updated version to 1.1.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 9f515696..7881b05e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=USB Host Shield Library 2.0 -version=1.0.0 +version=1.1.0 author=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll , Alexei Glushchenko (Circuits@Home) maintainer=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll sentence=Revision 2.0 of MAX3421E-based USB Host Shield Library. From 4df0d9db252f8f5f4ad49e1f9c4e15e244f42bf5 Mon Sep 17 00:00:00 2001 From: Michi302 Date: Sun, 17 May 2015 18:52:25 +0200 Subject: [PATCH 067/220] Corrected spelling mistake "Purble" to "Purple" --- controllerEnums.h | 1 + examples/PS3USB/PS3USB.ino | 2 +- keywords.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/controllerEnums.h b/controllerEnums.h index 0169c763..47fd975e 100644 --- a/controllerEnums.h +++ b/controllerEnums.h @@ -55,6 +55,7 @@ enum ColorsEnum { /** r = 0, g = 255, b = 255 */ Lightblue = 0xFFFF, /** r = 255, g = 0, b = 255 */ + Purple = 0xFF00FF, Purble = 0xFF00FF, /** r = 255, g = 255, b = 255 */ diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index a53dcfbe..9d033ea6 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -134,7 +134,7 @@ void loop() { PS3.moveSetBulb(Lightblue); } else if (state == 6) { PS3.moveSetRumble(225); - PS3.moveSetBulb(Purble); + PS3.moveSetBulb(Purple); } else if (state == 7) { PS3.moveSetRumble(250); PS3.moveSetBulb(White); diff --git a/keywords.txt b/keywords.txt index f4e19cd1..26707d1d 100644 --- a/keywords.txt +++ b/keywords.txt @@ -106,6 +106,7 @@ Green LITERAL1 Blue LITERAL1 Yellow LITERAL1 Lightblue LITERAL1 +Purple LITERAL1 Purble LITERAL1 White LITERAL1 Off LITERAL1 From 4839669636dd89ca8eb4dd3f94bcad12557c6348 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 23 May 2015 00:00:46 +0300 Subject: [PATCH 068/220] Continuous Integration with TravisCI + PlatformIO More details http://docs.platformio.org/en/latest/ci/travis.html --- .travis.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..80de3757 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: python +python: + - "2.7" + +env: + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP/PS3SPP.ino + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps/pl2303_gps.ino + +install: + - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + - wget https://github.com/xxxajk/spi4teensy3/archive/master.zip -O /tmp/spi4teensy3.zip + - unzip /tmp/spi4teensy3.zip -d /tmp + +script: + - platformio ci --lib="." --lib="/tmp/spi4teensy3-master" --board=uno --board=teensy31 --board=due From 73fa5609b89bd97c4978e6080e3e09d91f55828e Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 23 May 2015 00:03:57 +0300 Subject: [PATCH 069/220] Add TravisCI badge of build status --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 49cd83e0..f6bdb36b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ The code is released under the GNU General Public License. __________ +[![Build Status](https://travis-ci.org/ivankravets/USB_Host_Shield_2.0.svg)](https://travis-ci.org/ivankravets/USB_Host_Shield_2.0) # Summary This is Revision 2.0 of MAX3421E-based USB Host Shield Library for AVR's. From 89dd398ab1a07e122982571c76ad3e0a7a53ba16 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 23 May 2015 00:07:25 +0300 Subject: [PATCH 070/220] Change TravisCI owner to felis --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f6bdb36b..097fefd0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ The code is released under the GNU General Public License. __________ -[![Build Status](https://travis-ci.org/ivankravets/USB_Host_Shield_2.0.svg)](https://travis-ci.org/ivankravets/USB_Host_Shield_2.0) +[![Build Status](https://travis-ci.org/felis/USB_Host_Shield_2.0.svg)](https://travis-ci.org/felis/USB_Host_Shield_2.0) # Summary This is Revision 2.0 of MAX3421E-based USB Host Shield Library for AVR's. From 9d80320e9b851571a55d69f1377eb5e6dd8447ff Mon Sep 17 00:00:00 2001 From: Oleg Mazurov Date: Fri, 22 May 2015 18:08:30 -0600 Subject: [PATCH 071/220] cdc_XR21B1411.cpp changed date in the header --- cdc_XR21B1411.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdc_XR21B1411.cpp b/cdc_XR21B1411.cpp index 74df8c3b..1c4cd5c6 100644 --- a/cdc_XR21B1411.cpp +++ b/cdc_XR21B1411.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. +/* Copyright (C) 2015 Circuits At Home, LTD. All rights reserved. This software may be distributed and modified under the terms of the GNU General Public License version 2 (GPL2) as published by the Free Software From 251efba57bd9d33a958081e12598123482893082 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 23 May 2015 02:17:11 +0200 Subject: [PATCH 072/220] Added all example to .travis.yml The list was generated using: find . -type f -name '*.ino' | awk '{ print "- PLATFORMIO_CI_SRC="$1 }' | sed 's/.\///' --- .travis.yml | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/.travis.yml b/.travis.yml index 80de3757..8493a433 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,54 @@ python: - "2.7" env: + - PLATFORMIO_CI_SRC=examples/acm/acm_terminal/acm_terminal.ino + - PLATFORMIO_CI_SRC=examples/adk/adk_barcode/adk_barcode.ino + - PLATFORMIO_CI_SRC=examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino + - PLATFORMIO_CI_SRC=examples/adk/demokit_20/demokit_20.ino + - PLATFORMIO_CI_SRC=examples/adk/term_test/term_test.ino + - PLATFORMIO_CI_SRC=examples/adk/term_time/term_time.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/BTHID/BTHID.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3BT/PS3BT.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3Multi/PS3Multi.ino - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP/PS3SPP.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS4BT/PS4BT.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/SPP/SPP.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/SPPMulti/SPPMulti.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/Wii/Wii.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiMulti/WiiMulti.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController/WiiUProController.ino + - PLATFORMIO_CI_SRC=examples/board_qc/board_qc.ino + - PLATFORMIO_CI_SRC=examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino + - PLATFORMIO_CI_SRC=examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino + - PLATFORMIO_CI_SRC=examples/HID/le3dp/le3dp.ino + - PLATFORMIO_CI_SRC=examples/HID/scale/scale.ino + - PLATFORMIO_CI_SRC=examples/HID/USBHID_desc/USBHID_desc.ino + - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino + - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino + - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino + - PLATFORMIO_CI_SRC=examples/HID/USBHIDJoystick/USBHIDJoystick.ino + - PLATFORMIO_CI_SRC=examples/hub_demo/hub_demo.ino + - PLATFORMIO_CI_SRC=examples/max_LCD/max_LCD.ino + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps/pl2303_gps.ino + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino + - PLATFORMIO_CI_SRC=examples/PS3USB/PS3USB.ino + - PLATFORMIO_CI_SRC=examples/PS4USB/PS4USB.ino + - PLATFORMIO_CI_SRC=examples/PSBuzz/PSBuzz.ino + - PLATFORMIO_CI_SRC=examples/testusbhostFAT/RTClib/examples/datecalc/datecalc.ino + - PLATFORMIO_CI_SRC=examples/testusbhostFAT/RTClib/examples/ds1307Memory/ds1307Memory.ino + - PLATFORMIO_CI_SRC=examples/testusbhostFAT/RTClib/examples/ds1307SqwPin/ds1307SqwPin.ino + - PLATFORMIO_CI_SRC=examples/testusbhostFAT/RTClib/examples/RTC/RTC.ino + - PLATFORMIO_CI_SRC=examples/testusbhostFAT/testusbhostFAT.ino + - PLATFORMIO_CI_SRC=examples/testusbhostFAT/xmem2/examples/QuadRAMtest/QuadRAMtest.ino + - PLATFORMIO_CI_SRC=examples/USB_desc/USB_desc.ino + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXOLD/XBOXOLD.ino + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXONE/XBOXONE.ino + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXRECV/XBOXRECV.ino + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXUSB/XBOXUSB.ino install: - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" From c7f9ed65e9f5fdd0994c3d0f146026b40af891b4 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 23 May 2015 03:03:42 +0200 Subject: [PATCH 073/220] Don't run examples inside submodules and add libraries needed by testusbhostFAT.ino --- .travis.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8493a433..70c18c1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,12 +40,7 @@ env: - PLATFORMIO_CI_SRC=examples/PS3USB/PS3USB.ino - PLATFORMIO_CI_SRC=examples/PS4USB/PS4USB.ino - PLATFORMIO_CI_SRC=examples/PSBuzz/PSBuzz.ino - - PLATFORMIO_CI_SRC=examples/testusbhostFAT/RTClib/examples/datecalc/datecalc.ino - - PLATFORMIO_CI_SRC=examples/testusbhostFAT/RTClib/examples/ds1307Memory/ds1307Memory.ino - - PLATFORMIO_CI_SRC=examples/testusbhostFAT/RTClib/examples/ds1307SqwPin/ds1307SqwPin.ino - - PLATFORMIO_CI_SRC=examples/testusbhostFAT/RTClib/examples/RTC/RTC.ino - PLATFORMIO_CI_SRC=examples/testusbhostFAT/testusbhostFAT.ino - - PLATFORMIO_CI_SRC=examples/testusbhostFAT/xmem2/examples/QuadRAMtest/QuadRAMtest.ino - PLATFORMIO_CI_SRC=examples/USB_desc/USB_desc.ino - PLATFORMIO_CI_SRC=examples/Xbox/XBOXOLD/XBOXOLD.ino - PLATFORMIO_CI_SRC=examples/Xbox/XBOXONE/XBOXONE.ino @@ -55,7 +50,13 @@ env: install: - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" - wget https://github.com/xxxajk/spi4teensy3/archive/master.zip -O /tmp/spi4teensy3.zip + - wget https://github.com/xxxajk/xmem2/archive/master.zip -O /tmp/xmem2.zip + - wget https://github.com/xxxajk/generic_storage/archive/master.zip -O /tmp/generic_storage.zip + - wget https://github.com/xxxajk/RTClib/archive/master.zip -O /tmp/RTClib.zip - unzip /tmp/spi4teensy3.zip -d /tmp + - unzip /tmp/xmem2.zip -d /tmp + - unzip /tmp/generic_storage.zip -d /tmp + - unzip /tmp/RTClib.zip -d /tmp script: - - platformio ci --lib="." --lib="/tmp/spi4teensy3-master" --board=uno --board=teensy31 --board=due + - platformio ci --lib="." --lib="/tmp/spi4teensy3-master" --lib="/tmp/xmem2-master" --lib="/tmp/generic_storage-master" --lib="/tmp/RTClib-master" --board=uno --board=teensy31 --board=due From ee4a1fdd121df019e65b8ea3c1b54a38b7aa1fe7 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 23 May 2015 13:00:46 +0300 Subject: [PATCH 074/220] Use external libs from submodules --- .travis.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 70c18c1e..897448cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,13 +50,7 @@ env: install: - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" - wget https://github.com/xxxajk/spi4teensy3/archive/master.zip -O /tmp/spi4teensy3.zip - - wget https://github.com/xxxajk/xmem2/archive/master.zip -O /tmp/xmem2.zip - - wget https://github.com/xxxajk/generic_storage/archive/master.zip -O /tmp/generic_storage.zip - - wget https://github.com/xxxajk/RTClib/archive/master.zip -O /tmp/RTClib.zip - unzip /tmp/spi4teensy3.zip -d /tmp - - unzip /tmp/xmem2.zip -d /tmp - - unzip /tmp/generic_storage.zip -d /tmp - - unzip /tmp/RTClib.zip -d /tmp script: - - platformio ci --lib="." --lib="/tmp/spi4teensy3-master" --lib="/tmp/xmem2-master" --lib="/tmp/generic_storage-master" --lib="/tmp/RTClib-master" --board=uno --board=teensy31 --board=due + - platformio ci --board=uno --board=teensy31 --board=due --lib="." --lib="/tmp/spi4teensy3-master" --lib="examples/testusbhostFAT/xmem2" --lib="examples/testusbhostFAT/RTClib" --lib="examples/testusbhostFAT/generic_storage" From aceb03a948a660c071ec6dfd84aadacf0649bce8 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 23 May 2015 15:14:04 +0300 Subject: [PATCH 075/220] Improve examples handling --- .travis.yml | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 897448cf..159b8c6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,13 +3,13 @@ python: - "2.7" env: - - PLATFORMIO_CI_SRC=examples/acm/acm_terminal/acm_terminal.ino + - PLATFORMIO_CI_SRC=examples/acm/acm_terminal - PLATFORMIO_CI_SRC=examples/adk/adk_barcode/adk_barcode.ino - PLATFORMIO_CI_SRC=examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino - PLATFORMIO_CI_SRC=examples/adk/demokit_20/demokit_20.ino - PLATFORMIO_CI_SRC=examples/adk/term_test/term_test.ino - PLATFORMIO_CI_SRC=examples/adk/term_time/term_time.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/BTHID/BTHID.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/BTHID - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3BT/PS3BT.ino - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3Multi/PS3Multi.ino - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -23,15 +23,15 @@ env: - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController/WiiUProController.ino - PLATFORMIO_CI_SRC=examples/board_qc/board_qc.ino - PLATFORMIO_CI_SRC=examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino - - PLATFORMIO_CI_SRC=examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino - - PLATFORMIO_CI_SRC=examples/HID/le3dp/le3dp.ino - - PLATFORMIO_CI_SRC=examples/HID/scale/scale.ino - - PLATFORMIO_CI_SRC=examples/HID/USBHID_desc/USBHID_desc.ino + - PLATFORMIO_CI_SRC=examples/ftdi/USBFTDILoopback + - PLATFORMIO_CI_SRC=examples/HID/le3dp + - PLATFORMIO_CI_SRC=examples/HID/scale + - PLATFORMIO_CI_SRC=examples/HID/USBHID_desc - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino - - PLATFORMIO_CI_SRC=examples/HID/USBHIDJoystick/USBHIDJoystick.ino - - PLATFORMIO_CI_SRC=examples/hub_demo/hub_demo.ino + - PLATFORMIO_CI_SRC=examples/HID/USBHIDJoystick + - PLATFORMIO_CI_SRC=examples/hub_demo - PLATFORMIO_CI_SRC=examples/max_LCD/max_LCD.ino - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps/pl2303_gps.ino @@ -40,8 +40,8 @@ env: - PLATFORMIO_CI_SRC=examples/PS3USB/PS3USB.ino - PLATFORMIO_CI_SRC=examples/PS4USB/PS4USB.ino - PLATFORMIO_CI_SRC=examples/PSBuzz/PSBuzz.ino - - PLATFORMIO_CI_SRC=examples/testusbhostFAT/testusbhostFAT.ino - - PLATFORMIO_CI_SRC=examples/USB_desc/USB_desc.ino +# - PLATFORMIO_CI_SRC=examples/testusbhostFAT/testusbhostFAT.ino + - PLATFORMIO_CI_SRC=examples/USB_desc - PLATFORMIO_CI_SRC=examples/Xbox/XBOXOLD/XBOXOLD.ino - PLATFORMIO_CI_SRC=examples/Xbox/XBOXONE/XBOXONE.ino - PLATFORMIO_CI_SRC=examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -49,8 +49,16 @@ env: install: - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" - - wget https://github.com/xxxajk/spi4teensy3/archive/master.zip -O /tmp/spi4teensy3.zip - - unzip /tmp/spi4teensy3.zip -d /tmp + + # Use PlatformIO from development branch + # @TODO remove this line after 2.0.1 release + - pip install https://github.com/platformio/platformio/archive/develop.zip + + # Libraries from PlatformIO Library Register + # http://platformio.org/#!/lib/show/416/TinyGPS + # http://platformio.org/#!/lib/show/417/SPI4Teensy3 + - platformio lib install 416 417 script: - - platformio ci --board=uno --board=teensy31 --board=due --lib="." --lib="/tmp/spi4teensy3-master" --lib="examples/testusbhostFAT/xmem2" --lib="examples/testusbhostFAT/RTClib" --lib="examples/testusbhostFAT/generic_storage" + - if [[ $PLATFORMIO_CI_SRC == *"WiiIRCamera"* ]]; then sed -i -- 's/#define ENABLE_WII_IR_CAMERA 0/#define ENABLE_WII_IR_CAMERA 1/g' ./settings.h; fi + - platformio ci --board=uno --board=teensy31 --board=due --lib="." From 44d3b4a3223fc125b01370482b98e6f1ccbba370 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 23 May 2015 15:46:34 +0200 Subject: [PATCH 076/220] Added missing header needed for the Due --- examples/HID/scale/scale_rptparser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/HID/scale/scale_rptparser.cpp b/examples/HID/scale/scale_rptparser.cpp index 01ed980c..f88d21ac 100644 --- a/examples/HID/scale/scale_rptparser.cpp +++ b/examples/HID/scale/scale_rptparser.cpp @@ -1,4 +1,5 @@ /* Parser for standard HID scale (usage page 0x8d) data input report (ID 3) */ +#include #include "scale_rptparser.h" const char* UNITS[13] = { From 36056a40395d3b884ffe0562c223208563d8643f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 23 May 2015 15:49:46 +0200 Subject: [PATCH 077/220] Renamed Keyboard instance to HidKeyboard, so it works on the Due as well --- examples/adk/adk_barcode/adk_barcode.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/adk/adk_barcode/adk_barcode.ino b/examples/adk/adk_barcode/adk_barcode.ino index a308ff0f..04c8d258 100644 --- a/examples/adk/adk_barcode/adk_barcode.ino +++ b/examples/adk/adk_barcode/adk_barcode.ino @@ -14,7 +14,7 @@ USB Usb; USBHub Hub1(&Usb); USBHub Hub2(&Usb); -HIDBoot Keyboard(&Usb); +HIDBoot HidKeyboard(&Usb); ADK adk(&Usb,"Circuits@Home, ltd.", "USB Host Shield", @@ -80,7 +80,7 @@ void setup() while(1); //halt }//if (Usb.Init() == -1... - Keyboard.SetReportParser(0, (HIDReportParser*)&Prs); + HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs); delay( 200 ); } From 5ee8ee93251f02283c2695224bde9b3965a49a73 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 23 May 2015 16:03:50 +0200 Subject: [PATCH 078/220] avr/dtostrf.h should only be included if Due is used --- examples/HID/scale/scale_rptparser.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/HID/scale/scale_rptparser.cpp b/examples/HID/scale/scale_rptparser.cpp index f88d21ac..d9e00bc2 100644 --- a/examples/HID/scale/scale_rptparser.cpp +++ b/examples/HID/scale/scale_rptparser.cpp @@ -1,5 +1,7 @@ /* Parser for standard HID scale (usage page 0x8d) data input report (ID 3) */ +#ifdef ARDUINO_SAM_DUE #include +#endif #include "scale_rptparser.h" const char* UNITS[13] = { From 30e399f2764ce9fca47656ce43d54f64a716c203 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 23 May 2015 16:14:11 +0200 Subject: [PATCH 079/220] Remove all files names from .travis.yml to make it consistent --- .travis.yml | 66 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/.travis.yml b/.travis.yml index 159b8c6a..35cb4537 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,48 +4,48 @@ python: env: - PLATFORMIO_CI_SRC=examples/acm/acm_terminal - - PLATFORMIO_CI_SRC=examples/adk/adk_barcode/adk_barcode.ino - - PLATFORMIO_CI_SRC=examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino - - PLATFORMIO_CI_SRC=examples/adk/demokit_20/demokit_20.ino - - PLATFORMIO_CI_SRC=examples/adk/term_test/term_test.ino - - PLATFORMIO_CI_SRC=examples/adk/term_time/term_time.ino + - PLATFORMIO_CI_SRC=examples/adk/adk_barcode + - PLATFORMIO_CI_SRC=examples/adk/ArduinoBlinkLED + - PLATFORMIO_CI_SRC=examples/adk/demokit_20 + - PLATFORMIO_CI_SRC=examples/adk/term_test + - PLATFORMIO_CI_SRC=examples/adk/term_time - PLATFORMIO_CI_SRC=examples/Bluetooth/BTHID - - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3BT/PS3BT.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3Multi/PS3Multi.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP/PS3SPP.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/PS4BT/PS4BT.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/SPP/SPP.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/SPPMulti/SPPMulti.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/Wii/Wii.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiMulti/WiiMulti.ino - - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController/WiiUProController.ino - - PLATFORMIO_CI_SRC=examples/board_qc/board_qc.ino - - PLATFORMIO_CI_SRC=examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3BT + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3Multi + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS3SPP + - PLATFORMIO_CI_SRC=examples/Bluetooth/PS4BT + - PLATFORMIO_CI_SRC=examples/Bluetooth/SPP + - PLATFORMIO_CI_SRC=examples/Bluetooth/SPPMulti + - PLATFORMIO_CI_SRC=examples/Bluetooth/Wii + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiBalanceBoard + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiMulti + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController + - PLATFORMIO_CI_SRC=examples/board_qc + - PLATFORMIO_CI_SRC=examples/cdc_XR21B1411/XR_terminal - PLATFORMIO_CI_SRC=examples/ftdi/USBFTDILoopback - PLATFORMIO_CI_SRC=examples/HID/le3dp - PLATFORMIO_CI_SRC=examples/HID/scale - PLATFORMIO_CI_SRC=examples/HID/USBHID_desc - - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino - - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino - - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino + - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbd + - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbdAndMouse + - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootMouse - PLATFORMIO_CI_SRC=examples/HID/USBHIDJoystick - PLATFORMIO_CI_SRC=examples/hub_demo - - PLATFORMIO_CI_SRC=examples/max_LCD/max_LCD.ino - - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino - - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps/pl2303_gps.ino - - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino - - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino - - PLATFORMIO_CI_SRC=examples/PS3USB/PS3USB.ino - - PLATFORMIO_CI_SRC=examples/PS4USB/PS4USB.ino - - PLATFORMIO_CI_SRC=examples/PSBuzz/PSBuzz.ino + - PLATFORMIO_CI_SRC=examples/max_LCD + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gprs_terminal + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gps + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_tinygps + - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_xbee_terminal + - PLATFORMIO_CI_SRC=examples/PS3USB + - PLATFORMIO_CI_SRC=examples/PS4USB + - PLATFORMIO_CI_SRC=examples/PSBuzz # - PLATFORMIO_CI_SRC=examples/testusbhostFAT/testusbhostFAT.ino - PLATFORMIO_CI_SRC=examples/USB_desc - - PLATFORMIO_CI_SRC=examples/Xbox/XBOXOLD/XBOXOLD.ino - - PLATFORMIO_CI_SRC=examples/Xbox/XBOXONE/XBOXONE.ino - - PLATFORMIO_CI_SRC=examples/Xbox/XBOXRECV/XBOXRECV.ino - - PLATFORMIO_CI_SRC=examples/Xbox/XBOXUSB/XBOXUSB.ino + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXOLD + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXONE + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXRECV + - PLATFORMIO_CI_SRC=examples/Xbox/XBOXUSB install: - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" From 81ba812611db3cbedbfde3088d1df0f9b1f2df96 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 23 May 2015 18:53:37 +0200 Subject: [PATCH 080/220] Use PLATFORMIO_BUILD_FLAGS to define WIICAMERA --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 35cb4537..6547f97f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ env: - PLATFORMIO_CI_SRC=examples/Bluetooth/SPPMulti - PLATFORMIO_CI_SRC=examples/Bluetooth/Wii - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiBalanceBoard - - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera PLATFORMIO_BUILD_FLAGS="-DWIICAMERA" - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiMulti - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController - PLATFORMIO_CI_SRC=examples/board_qc @@ -60,5 +60,4 @@ install: - platformio lib install 416 417 script: - - if [[ $PLATFORMIO_CI_SRC == *"WiiIRCamera"* ]]; then sed -i -- 's/#define ENABLE_WII_IR_CAMERA 0/#define ENABLE_WII_IR_CAMERA 1/g' ./settings.h; fi - platformio ci --board=uno --board=teensy31 --board=due --lib="." From 0811d917d72b797eccdd9216e50d6417e1e208d1 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 27 May 2015 17:14:31 +0300 Subject: [PATCH 081/220] Switch to stable release of @PlatformIO --- .travis.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6547f97f..2d9ffa0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,11 +50,9 @@ env: install: - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" - # Use PlatformIO from development branch - # @TODO remove this line after 2.0.1 release - - pip install https://github.com/platformio/platformio/archive/develop.zip - - # Libraries from PlatformIO Library Register + # + # Libraries from PlatformIO Library Registry: + # # http://platformio.org/#!/lib/show/416/TinyGPS # http://platformio.org/#!/lib/show/417/SPI4Teensy3 - platformio lib install 416 417 From 71e4596ab14cb65c637ad6385cf0cbf6bd456613 Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Mon, 1 Jun 2015 20:52:47 +0200 Subject: [PATCH 082/220] Fixed Compile Error with RedBearLabs nRF51288 Fixed a macro definition which would cause the compiler to try to compile against an undefined function in the RBL SDK. --- usbhost.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usbhost.h b/usbhost.h index eba480e6..1d6f5955 100644 --- a/usbhost.h +++ b/usbhost.h @@ -56,7 +56,7 @@ 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 -#else +#elif !defined(RBL_NRF51822) SPI.setClockDivider(4); // Set speed to 84MHz/4=21MHz - the MAX3421E can handle up to 26MHz #endif } From b7587fb38778a397b12ea4126e521e9df65b8c07 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 2 Jun 2015 10:14:33 +0200 Subject: [PATCH 083/220] Don't show build status until bug in PlatformIO is fixed --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 097fefd0..49cd83e0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ The code is released under the GNU General Public License. __________ -[![Build Status](https://travis-ci.org/felis/USB_Host_Shield_2.0.svg)](https://travis-ci.org/felis/USB_Host_Shield_2.0) # Summary This is Revision 2.0 of MAX3421E-based USB Host Shield Library for AVR's. From 758cce56f534add2ad30a4ba32874eb13f44b006 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 2 Jun 2015 16:09:34 +0200 Subject: [PATCH 084/220] There is no need for RBL_NRF51822 to have it's own SPI implementation --- usbhost.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/usbhost.h b/usbhost.h index 1d6f5955..e610d938 100644 --- a/usbhost.h +++ b/usbhost.h @@ -60,13 +60,6 @@ public: SPI.setClockDivider(4); // Set speed to 84MHz/4=21MHz - the MAX3421E can handle up to 26MHz #endif } -#elif defined(RBL_NRF51822) - static void init() { - SPI_SS::SetDirWrite(); - SPI_SS::Set(); - SPI.begin(); - // SPI.setFrequency(SPI_FREQUENCY_8M); - } #else static void init() { //uint8_t tmp; From 67e64a08257d1b58f27b042a31478d6139450469 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 3 Jun 2015 23:41:25 +0200 Subject: [PATCH 085/220] Revert "Don't show build status until bug in PlatformIO is fixed" This reverts commit b7587fb38778a397b12ea4126e521e9df65b8c07. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 49cd83e0..097fefd0 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ The code is released under the GNU General Public License. __________ +[![Build Status](https://travis-ci.org/felis/USB_Host_Shield_2.0.svg)](https://travis-ci.org/felis/USB_Host_Shield_2.0) # Summary This is Revision 2.0 of MAX3421E-based USB Host Shield Library for AVR's. From 607932b437161bb20e284d4d05df0740d3ce591d Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 7 Jul 2015 09:58:30 +0200 Subject: [PATCH 086/220] Added missing include in the Xbox One example --- examples/Xbox/XBOXONE/XBOXONE.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/Xbox/XBOXONE/XBOXONE.ino b/examples/Xbox/XBOXONE/XBOXONE.ino index 9526f53d..20d94a42 100644 --- a/examples/Xbox/XBOXONE/XBOXONE.ino +++ b/examples/Xbox/XBOXONE/XBOXONE.ino @@ -4,9 +4,11 @@ */ #include -// Satisfy IDE, which only needs to see the include statment in the ino. + +// Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include +#include #endif USB Usb; From e7bb5fafb1656807510f10b19a56814233636a36 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 12 Jul 2015 19:17:12 +0200 Subject: [PATCH 087/220] Add delay between multiple calls to dispatchpkt inside InTransfer Fixes: #167 --- BTD.cpp | 4 ++-- Usb.cpp | 9 +++++---- UsbCore.h | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index bcfba14b..1bad3099 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -388,7 +388,7 @@ void BTD::disconnect() { void BTD::HCI_event_task() { uint16_t length = BULK_MAXPKTSIZE; // Request more than 16 bytes anyway, the inTransfer routine will take care of this - uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &length, hcibuf); // Input on endpoint 1 + uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_EVENT_PIPE ].epAddr, &length, hcibuf, pollInterval); // Input on endpoint 1 if(!rcode || rcode == hrNAK) { // Check for errors switch(hcibuf[0]) { // Switch on event type @@ -900,7 +900,7 @@ void BTD::HCI_task() { void BTD::ACL_event_task() { uint16_t length = BULK_MAXPKTSIZE; - uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &length, l2capinbuf); // Input on endpoint 2 + uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[ BTD_DATAIN_PIPE ].epAddr, &length, l2capinbuf, pollInterval); // Input on endpoint 2 if(!rcode) { // Check for errors if(length > 0) { // Check if any data was read diff --git a/Usb.cpp b/Usb.cpp index 14272588..2703c034 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -203,7 +203,7 @@ uint8_t USB::ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bReque /* rcode 0 if no errors. rcode 01-0f is relayed from dispatchPkt(). Rcode f0 means RCVDAVIRQ error, fe USB xfer timeout */ -uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data) { +uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval /*= 0*/) { EpInfo *pep = NULL; uint16_t nak_limit = 0; @@ -215,10 +215,10 @@ uint8_t USB::inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* USBTRACE3("(USB::InTransfer) ep requested ", ep, 0x81); return rcode; } - return InTransfer(pep, nak_limit, nbytesptr, data); + return InTransfer(pep, nak_limit, nbytesptr, data, bInterval); } -uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t* data) { +uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval /*= 0*/) { uint8_t rcode = 0; uint8_t pktsize; @@ -280,7 +280,8 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui //printf("\r\n"); rcode = 0; break; - } // if + } else if(bInterval > 0) + delay(bInterval); // Delay according to polling interval } //while( 1 ) return ( rcode); } diff --git a/UsbCore.h b/UsbCore.h index 5c6c7710..fdec87b0 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -245,7 +245,7 @@ public: /**/ uint8_t ctrlData(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* dataptr, bool direction); uint8_t ctrlStatus(uint8_t ep, bool direction, uint16_t nak_limit); - uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data); + uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t* data, uint8_t bInterval = 0); uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t* data); uint8_t dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit); @@ -262,7 +262,7 @@ private: void init(); uint8_t SetAddress(uint8_t addr, uint8_t ep, EpInfo **ppep, uint16_t *nak_limit); uint8_t OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8_t *data); - uint8_t InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t *data); + uint8_t InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval = 0); uint8_t AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lowspeed); }; From b83078414f4805c0e48cf7c5a32a7fde36fe6eeb Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 12 Jul 2015 23:14:43 +0200 Subject: [PATCH 088/220] Updated version to 1.1.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 7881b05e..1a539326 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=USB Host Shield Library 2.0 -version=1.1.0 +version=1.1.1 author=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll , Alexei Glushchenko (Circuits@Home) maintainer=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll sentence=Revision 2.0 of MAX3421E-based USB Host Shield Library. From 7cfb4fac2893457d9f4656bffbb9743c815a098f Mon Sep 17 00:00:00 2001 From: Barry Carter Date: Tue, 21 Jul 2015 20:10:49 +0100 Subject: [PATCH 089/220] Add Teensy LC support. Note: disables spi4teensy lib. (Barry Carter) --- avrpins.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ settings.h | 8 ++++++- usbhost.h | 4 +++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/avrpins.h b/avrpins.h index 4e60e3a2..05c9ab79 100644 --- a/avrpins.h +++ b/avrpins.h @@ -835,6 +835,70 @@ MAKE_PIN(P33, CORE_PIN33_PORTREG, CORE_PIN33_BIT, CORE_PIN33_CONFIG); #undef MAKE_PIN +#elif defined(CORE_TEENSY) && (defined(__MKL26Z64__)) + +// we could get lower level by making these macros work properly. +// for now just use the semi optimised version, it costs a lookup in the pin pgm table per op +// but for now it will do. +//#define GPIO_BITBAND_ADDR(reg, bit) (((volatile uint8_t *)&(reg) + ((bit) >> 3))) +//#define GPIO_BITBAND_MASK(reg, bit) (1<<((bit) & 7)) +//#define GPIO_BITBAND_PTR(reg, bit) ((volatile uint8_t *)GPIO_BITBAND_ADDR((reg), (bit))) + +#include "core_pins.h" +#include "avr_emulation.h" + +#define MAKE_PIN(className, baseReg, pinNum, configReg) \ +class className { \ +public: \ + static void Set() { \ + *portSetRegister(pinNum) = digitalPinToBitMask(pinNum); \ + } \ + static void Clear() { \ + *portClearRegister(pinNum) = digitalPinToBitMask(pinNum); \ + } \ + static void SetDirRead() { \ + configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ + *portModeRegister(pinNum) &= ~digitalPinToBitMask(pinNum); \ + } \ + static void SetDirWrite() { \ + configReg = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); \ + *portModeRegister(pinNum) |= digitalPinToBitMask(pinNum); \ + } \ + static uint8_t IsSet() { \ + return (*portInputRegister(pinNum) & digitalPinToBitMask(pinNum)) ? 1 : 0; \ + } \ +}; + +MAKE_PIN(P0, CORE_PIN0_PORTREG, 0, CORE_PIN0_CONFIG); +MAKE_PIN(P1, CORE_PIN1_PORTREG, 1, CORE_PIN1_CONFIG); +MAKE_PIN(P2, CORE_PIN2_PORTREG, 2, CORE_PIN2_CONFIG); +MAKE_PIN(P3, CORE_PIN3_PORTREG, 3, CORE_PIN3_CONFIG); +MAKE_PIN(P4, CORE_PIN4_PORTREG, 4, CORE_PIN4_CONFIG); +MAKE_PIN(P5, CORE_PIN5_PORTREG, 5, CORE_PIN5_CONFIG); +MAKE_PIN(P6, CORE_PIN6_PORTREG, 6, CORE_PIN6_CONFIG); +MAKE_PIN(P7, CORE_PIN7_PORTREG, 7, CORE_PIN7_CONFIG); +MAKE_PIN(P8, CORE_PIN8_PORTREG, 8, CORE_PIN8_CONFIG); +MAKE_PIN(P9, CORE_PIN9_PORTREG, 9, CORE_PIN9_CONFIG); +MAKE_PIN(P10, CORE_PIN10_PORTREG, 10, CORE_PIN10_CONFIG); +MAKE_PIN(P11, CORE_PIN11_PORTREG, 11, CORE_PIN11_CONFIG); +MAKE_PIN(P12, CORE_PIN12_PORTREG, 12, CORE_PIN12_CONFIG); +MAKE_PIN(P13, CORE_PIN13_PORTREG, 13, CORE_PIN13_CONFIG); +MAKE_PIN(P14, CORE_PIN14_PORTREG, 14, CORE_PIN14_CONFIG); +MAKE_PIN(P15, CORE_PIN15_PORTREG, 15, CORE_PIN15_CONFIG); +MAKE_PIN(P16, CORE_PIN16_PORTREG, 16, CORE_PIN16_CONFIG); +MAKE_PIN(P17, CORE_PIN17_PORTREG, 17, CORE_PIN17_CONFIG); +MAKE_PIN(P18, CORE_PIN18_PORTREG, 18, CORE_PIN18_CONFIG); +MAKE_PIN(P19, CORE_PIN19_PORTREG, 19, CORE_PIN19_CONFIG); +MAKE_PIN(P20, CORE_PIN20_PORTREG, 20, CORE_PIN20_CONFIG); +MAKE_PIN(P21, CORE_PIN21_PORTREG, 21, CORE_PIN21_CONFIG); +MAKE_PIN(P22, CORE_PIN22_PORTREG, 22, CORE_PIN22_CONFIG); +MAKE_PIN(P23, CORE_PIN23_PORTREG, 23, CORE_PIN23_CONFIG); +MAKE_PIN(P24, CORE_PIN24_PORTREG, 24, CORE_PIN24_CONFIG); +MAKE_PIN(P25, CORE_PIN25_PORTREG, 25, CORE_PIN25_CONFIG); +MAKE_PIN(P26, CORE_PIN26_PORTREG, 26, CORE_PIN26_CONFIG); + +#undef MAKE_PIN + #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) // SetDirRead: diff --git a/settings.h b/settings.h index 5c060354..9d3a69cd 100644 --- a/settings.h +++ b/settings.h @@ -71,6 +71,12 @@ e-mail : support@circuitsathome.com #define USE_SPI4TEENSY3 1 #endif +// disabled on the Teensy LC as it is incompatible for now +#if defined(__MKL26Z64__) +#undef USE_SPI4TEENSY3 +#define USE_SPI4TEENSY3 0 +#endif + //////////////////////////////////////////////////////////////////////////////// // AUTOMATIC Settings //////////////////////////////////////////////////////////////////////////////// @@ -123,7 +129,7 @@ e-mail : support@circuitsathome.com #define EXT_RAM 0 #endif -#if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__)) +#if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)) #define USING_SPI4TEENSY3 USE_SPI4TEENSY3 #else #define USING_SPI4TEENSY3 0 diff --git a/usbhost.h b/usbhost.h index e610d938..383ce7e8 100644 --- a/usbhost.h +++ b/usbhost.h @@ -42,6 +42,8 @@ public: #elif SPI_HAS_TRANSACTION static void init() { SPI.begin(); // The SPI library with transaction will take care of setting up the pins - settings is set in beginTransaction() + SPI_SS::SetDirWrite(); + SPI_SS::Set(); } #elif !defined(SPDR) static void init() { @@ -84,7 +86,7 @@ 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(__ARDUINO_X86__) || defined(__MIPSEL__) +#elif (defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__))) || 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; From e72e430b77da8a18e199b51f4c12ba4724352f5b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 22 Jul 2015 23:46:09 +0200 Subject: [PATCH 090/220] Teensy LC is now supported See: #170 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 097fefd0..548f46b6 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ 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, Intel Galileo, Intel Galileo 2, and Intel Edison * 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) +* Teensy (Teensy++ 1.0, Teensy 2.0, Teensy++ 2.0, Teensy 3.x, and Teensy LC) * 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 * Sanguino From 6d882549892a6838eaf67ee05160ba2dc6c88e06 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Fri, 24 Jul 2015 00:31:15 +0200 Subject: [PATCH 091/220] Migrate Travis from legacy to container-based infrastructure See: http://docs.travis-ci.com/user/migrating-from-legacy --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2d9ffa0e..b77449f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,10 @@ language: python + python: - "2.7" +sudo: false + env: - PLATFORMIO_CI_SRC=examples/acm/acm_terminal - PLATFORMIO_CI_SRC=examples/adk/adk_barcode From 26afaf4dea2fbbc78305f6444d15760abc6cb74a Mon Sep 17 00:00:00 2001 From: Allen Johnson-Weltzin Date: Mon, 31 Aug 2015 10:16:29 -0500 Subject: [PATCH 092/220] Correction to keyboard LED operation --- hidboot.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hidboot.h b/hidboot.h index fb63ec5e..55135d25 100644 --- a/hidboot.h +++ b/hidboot.h @@ -163,9 +163,11 @@ protected: break; } - if(old_keys != kbdLockingKeys.bLeds && hid) - return (hid->SetReport(0, 0/*hid->GetIface()*/, 2, 0, 1, &kbdLockingKeys.bLeds)); + if(old_keys != kbdLockingKeys.bLeds && hid){ + uint8_t lockLeds = kbdLockingKeys.bLeds; + return (hid->SetReport(0, 0/*hid->GetIface()*/, 2, 0, 1, &lockLeds)); + } return 0; }; From 12e184349feef534c9f1b074c61582dc869d89f6 Mon Sep 17 00:00:00 2001 From: Allen Johnson-Weltzin Date: Mon, 31 Aug 2015 10:21:26 -0500 Subject: [PATCH 093/220] Revert "Correction to keyboard LED operation" This reverts commit 26afaf4dea2fbbc78305f6444d15760abc6cb74a. --- hidboot.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hidboot.h b/hidboot.h index 55135d25..fb63ec5e 100644 --- a/hidboot.h +++ b/hidboot.h @@ -163,11 +163,9 @@ protected: break; } - if(old_keys != kbdLockingKeys.bLeds && hid){ - uint8_t lockLeds = kbdLockingKeys.bLeds; + if(old_keys != kbdLockingKeys.bLeds && hid) + return (hid->SetReport(0, 0/*hid->GetIface()*/, 2, 0, 1, &kbdLockingKeys.bLeds)); - return (hid->SetReport(0, 0/*hid->GetIface()*/, 2, 0, 1, &lockLeds)); - } return 0; }; From 8f86fd4e04ddb4aab4767a935d2149b1503ea817 Mon Sep 17 00:00:00 2001 From: Allen Johnson-Weltzin Date: Mon, 31 Aug 2015 10:28:26 -0500 Subject: [PATCH 094/220] fix for keyboard LED operation --- hidboot.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hidboot.h b/hidboot.h index fb63ec5e..f0fa92ef 100644 --- a/hidboot.h +++ b/hidboot.h @@ -163,9 +163,12 @@ protected: break; } - if(old_keys != kbdLockingKeys.bLeds && hid) - return (hid->SetReport(0, 0/*hid->GetIface()*/, 2, 0, 1, &kbdLockingKeys.bLeds)); - + if(old_keys != kbdLockingKeys.bLeds && hid){ + uint8_t lockLeds = kbdLockingKeys.bLeds; + + return (hid->SetReport(0, 0/*hid->GetIface()*/, 2, 0, 1, &lockLeds)); + } + return 0; }; From 2f4907ab31767220f2126883aeb4b59ce412f0a1 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Fri, 4 Sep 2015 00:41:30 +0200 Subject: [PATCH 095/220] Fix formatting --- hidboot.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hidboot.h b/hidboot.h index f0fa92ef..797c107a 100644 --- a/hidboot.h +++ b/hidboot.h @@ -163,12 +163,11 @@ protected: break; } - if(old_keys != kbdLockingKeys.bLeds && hid){ + if(old_keys != kbdLockingKeys.bLeds && hid) { uint8_t lockLeds = kbdLockingKeys.bLeds; - - return (hid->SetReport(0, 0/*hid->GetIface()*/, 2, 0, 1, &lockLeds)); - } - + return (hid->SetReport(0, 0/*hid->GetIface()*/, 2, 0, 1, &lockLeds)); + } + return 0; }; From acfcba6fa669c99c470433ef9556fde2afd80bb5 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 12 Oct 2015 10:52:51 +0200 Subject: [PATCH 096/220] Replace deprecated byte variable with uint8_t --- PS3USB.cpp | 2 +- max_LCD.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PS3USB.cpp b/PS3USB.cpp index c3217538..fbbf7844 100755 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -555,7 +555,7 @@ void PS3USB::getMoveCalibration(uint8_t *data) { // bmRequest = Device to host (0x80) | Class (0x20) | Interface (0x01) = 0xA1, bRequest = Get Report (0x01), Report ID (0x10), Report Type (Feature 0x03), interface (0x00), datalength, datalength, data pUsb->ctrlReq(bAddress, epInfo[PS3_CONTROL_PIPE].epAddr, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, 0x10, 0x03, 0x00, 49, 49, buf, NULL); - for(byte j = 0; j < 49; j++) + for(uint8_t j = 0; j < 49; j++) data[49 * i + j] = buf[j]; } } diff --git a/max_LCD.cpp b/max_LCD.cpp index f0c64666..7a9b1707 100644 --- a/max_LCD.cpp +++ b/max_LCD.cpp @@ -37,7 +37,7 @@ e-mail : support@circuitsathome.com sendbyte(a); \ } -static byte lcdPins; //copy of LCD pins +static uint8_t lcdPins; //copy of LCD pins Max_LCD::Max_LCD(USB *pusb) : pUsb(pusb) { lcdPins = 0; From 7e449d2d3a5c56f07be619bccba5ad6942817723 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 12 Oct 2015 13:20:48 +0200 Subject: [PATCH 097/220] Replaced all double variables with float --- PS3BT.cpp | 28 ++++++++++++++-------------- PS3BT.h | 4 ++-- PS3USB.cpp | 18 ++++++++---------- PS3USB.h | 2 +- PS4Parser.h | 6 +++--- Wii.cpp | 16 ++++++++-------- Wii.h | 38 +++++++++++++++++++------------------- 7 files changed, 55 insertions(+), 57 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index 235092e0..ab5a8ed5 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -82,15 +82,15 @@ int16_t PS3BT::getSensor(SensorEnum a) { return 0; } -double PS3BT::getAngle(AngleEnum a) { - double accXval, accYval, accZval; +float PS3BT::getAngle(AngleEnum a) { + float accXval, accYval, accZval; if(PS3Connected) { // Data for the Kionix KXPC4 used in the DualShock 3 - const double zeroG = 511.5; // 1.65/3.3*1023 (1.65V) - accXval = -((double)getSensor(aX) - zeroG); - accYval = -((double)getSensor(aY) - zeroG); - accZval = -((double)getSensor(aZ) - zeroG); + const float zeroG = 511.5f; // 1.65/3.3*1023 (1.65V) + accXval = -((float)getSensor(aX) - zeroG); + accYval = -((float)getSensor(aY) - zeroG); + accZval = -((float)getSensor(aZ) - zeroG); } else if(PS3MoveConnected) { // It's a Kionix KXSC4 inside the Motion controller const uint16_t zeroG = 0x8000; @@ -104,36 +104,36 @@ double PS3BT::getAngle(AngleEnum a) { // atan2 outputs the value of -Ï€ to Ï€ (radians) // We are then converting it to 0 to 2Ï€ and then to degrees if(a == Pitch) - return (atan2(accYval, accZval) + PI) * RAD_TO_DEG; + return (atan2f(accYval, accZval) + PI) * RAD_TO_DEG; else - return (atan2(accXval, accZval) + PI) * RAD_TO_DEG; + return (atan2f(accXval, accZval) + PI) * RAD_TO_DEG; } -double PS3BT::get9DOFValues(SensorEnum a) { // Thanks to Manfred Piendl +float PS3BT::get9DOFValues(SensorEnum a) { // Thanks to Manfred Piendl if(!PS3MoveConnected) return 0; int16_t value = getSensor(a); if(a == mXmove || a == mYmove || a == mZmove) { if(value > 2047) value -= 0x1000; - return (double)value / 3.2; // unit: muT = 10^(-6) Tesla + return (float)value / 3.2f; // unit: muT = 10^(-6) Tesla } else if(a == aXmove || a == aYmove || a == aZmove) { if(value < 0) value += 0x8000; else value -= 0x8000; - return (double)value / 442.0; // unit: m/(s^2) + return (float)value / 442.0f; // unit: m/(s^2) } else if(a == gXmove || a == gYmove || a == gZmove) { if(value < 0) value += 0x8000; else value -= 0x8000; if(a == gXmove) - return (double)value / 11.6; // unit: deg/s + return (float)value / 11.6f; // unit: deg/s else if(a == gYmove) - return (double)value / 11.2; // unit: deg/s + return (float)value / 11.2f; // unit: deg/s else // gZmove - return (double)value / 9.6; // unit: deg/s + return (float)value / 9.6f; // unit: deg/s } else return 0; } diff --git a/PS3BT.h b/PS3BT.h index c25ac5e5..5fd04c32 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -89,13 +89,13 @@ public: * @param a Either ::Pitch or ::Roll. * @return Return the angle in the range of 0-360. */ - double getAngle(AngleEnum a); + float getAngle(AngleEnum a); /** * Read the sensors inside the Move controller. * @param a ::aXmove, ::aYmove, ::aZmove, ::gXmove, ::gYmove, ::gZmove, ::mXmove, ::mYmove, and ::mXmove. * @return The value in SI units. */ - double get9DOFValues(SensorEnum a); + float get9DOFValues(SensorEnum a); /** * Get the status from the controller. * @param c The ::StatusEnum you want to read. diff --git a/PS3USB.cpp b/PS3USB.cpp index c3217538..43b12648 100755 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -335,25 +335,23 @@ uint16_t PS3USB::getSensor(SensorEnum a) { return ((readBuf[((uint16_t)a) - 9] << 8) | readBuf[((uint16_t)a + 1) - 9]); } -double PS3USB::getAngle(AngleEnum a) { +float PS3USB::getAngle(AngleEnum a) { if(PS3Connected) { - double accXval; - double accYval; - double accZval; + float accXval, accYval, accZval; // Data for the Kionix KXPC4 used in the DualShock 3 - const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V) - accXval = -((double)getSensor(aX) - zeroG); - accYval = -((double)getSensor(aY) - zeroG); - accZval = -((double)getSensor(aZ) - zeroG); + const float zeroG = 511.5f; // 1.65/3.3*1023 (1,65V) + accXval = -((float)getSensor(aX) - zeroG); + accYval = -((float)getSensor(aY) - zeroG); + accZval = -((float)getSensor(aZ) - zeroG); // Convert to 360 degrees resolution // atan2 outputs the value of -Ï€ to Ï€ (radians) // We are then converting it to 0 to 2Ï€ and then to degrees if(a == Pitch) - return (atan2(accYval, accZval) + PI) * RAD_TO_DEG; + return (atan2f(accYval, accZval) + PI) * RAD_TO_DEG; else - return (atan2(accXval, accZval) + PI) * RAD_TO_DEG; + return (atan2f(accXval, accZval) + PI) * RAD_TO_DEG; } else return 0; } diff --git a/PS3USB.h b/PS3USB.h index 2eba9258..c10faaea 100644 --- a/PS3USB.h +++ b/PS3USB.h @@ -177,7 +177,7 @@ public: * @param a Either ::Pitch or ::Roll. * @return Return the angle in the range of 0-360. */ - double getAngle(AngleEnum a); + float getAngle(AngleEnum a); /** * Get the ::StatusEnum from the controller. * @param c The ::StatusEnum you want to read. diff --git a/PS4Parser.h b/PS4Parser.h index 51f08063..5af13e80 100644 --- a/PS4Parser.h +++ b/PS4Parser.h @@ -225,11 +225,11 @@ public: * @param a Either ::Pitch or ::Roll. * @return Return the angle in the range of 0-360. */ - double getAngle(AngleEnum a) { + float getAngle(AngleEnum a) { if (a == Pitch) - return (atan2(ps4Data.accY, ps4Data.accZ) + PI) * RAD_TO_DEG; + return (atan2f(ps4Data.accY, ps4Data.accZ) + PI) * RAD_TO_DEG; else - return (atan2(ps4Data.accX, ps4Data.accZ) + PI) * RAD_TO_DEG; + return (atan2f(ps4Data.accX, ps4Data.accZ) + PI) * RAD_TO_DEG; }; /** diff --git a/Wii.cpp b/Wii.cpp index 4bbf4c91..20975a81 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -503,9 +503,9 @@ void WII::ACLData(uint8_t* l2capinbuf) { gyroRollRaw = ((l2capinbuf[16] | ((l2capinbuf[19] & 0xFC) << 6)) - gyroRollZero); gyroPitchRaw = ((l2capinbuf[17] | ((l2capinbuf[20] & 0xFC) << 6)) - gyroPitchZero); - yawGyroSpeed = (double)gyroYawRaw / ((double)gyroYawZero / yawGyroScale); - rollGyroSpeed = -(double)gyroRollRaw / ((double)gyroRollZero / rollGyroScale); // We invert these values so they will fit the acc values - pitchGyroSpeed = (double)gyroPitchRaw / ((double)gyroPitchZero / pitchGyroScale); + yawGyroSpeed = (float)gyroYawRaw / ((float)gyroYawZero / yawGyroScale); + rollGyroSpeed = -(float)gyroRollRaw / ((float)gyroRollZero / rollGyroScale); // We invert these values so they will fit the acc values + pitchGyroSpeed = (float)gyroPitchRaw / ((float)gyroPitchZero / pitchGyroScale); /* The onboard gyro has two ranges for slow and fast mode */ if(!(l2capinbuf[18] & 0x02)) // Check if fast mode is used @@ -515,12 +515,12 @@ void WII::ACLData(uint8_t* l2capinbuf) { if(!(l2capinbuf[19] & 0x02)) // Check if fast mode is used rollGyroSpeed *= 4.545; - compPitch = (0.93 * (compPitch + (pitchGyroSpeed * (double)(micros() - timer) / 1000000)))+(0.07 * getWiimotePitch()); // Use a complimentary filter to calculate the angle - compRoll = (0.93 * (compRoll + (rollGyroSpeed * (double)(micros() - timer) / 1000000)))+(0.07 * getWiimoteRoll()); + compPitch = (0.93f * (compPitch + (pitchGyroSpeed * (float)(micros() - timer) / 1000000.0f)))+(0.07f * getWiimotePitch()); // Use a complimentary filter to calculate the angle + compRoll = (0.93f * (compRoll + (rollGyroSpeed * (float)(micros() - timer) / 1000000.0f)))+(0.07f * getWiimoteRoll()); - gyroYaw += (yawGyroSpeed * ((double)(micros() - timer) / 1000000)); - gyroRoll += (rollGyroSpeed * ((double)(micros() - timer) / 1000000)); - gyroPitch += (pitchGyroSpeed * ((double)(micros() - timer) / 1000000)); + gyroYaw += (yawGyroSpeed * ((float)(micros() - timer) / 1000000.0f)); + gyroRoll += (rollGyroSpeed * ((float)(micros() - timer) / 1000000.0f)); + gyroPitch += (pitchGyroSpeed * ((float)(micros() - timer) / 1000000.0f)); timer = micros(); /* // Uncomment these lines to tune the gyro scale variabels diff --git a/Wii.h b/Wii.h index 960f2273..efb64b2f 100755 --- a/Wii.h +++ b/Wii.h @@ -107,7 +107,7 @@ public: * Pitch calculated from the Wiimote. A complimentary filter is used if the Motion Plus is connected. * @return Pitch in the range from 0-360. */ - double getPitch() { + float getPitch() { if(motionPlusConnected) return compPitch; return getWiimotePitch(); @@ -117,7 +117,7 @@ public: * Roll calculated from the Wiimote. A complimentary filter is used if the Motion Plus is connected. * @return Roll in the range from 0-360. */ - double getRoll() { + float getRoll() { if(motionPlusConnected) return compRoll; return getWiimoteRoll(); @@ -129,7 +129,7 @@ public: * NOTE: This angle will drift a lot and is only available if the Motion Plus extension is connected. * @return The angle calculated using the gyro. */ - double getYaw() { + float getYaw() { return gyroYaw; }; @@ -209,24 +209,24 @@ public: /**@{*/ /** Pitch and roll calculated from the accelerometer inside the Wiimote. */ - double getWiimotePitch() { - return (atan2(accYwiimote, accZwiimote) + PI) * RAD_TO_DEG; + float getWiimotePitch() { + return (atan2f(accYwiimote, accZwiimote) + PI) * RAD_TO_DEG; }; - double getWiimoteRoll() { - return (atan2(accXwiimote, accZwiimote) + PI) * RAD_TO_DEG; + float getWiimoteRoll() { + return (atan2f(accXwiimote, accZwiimote) + PI) * RAD_TO_DEG; }; /**@}*/ /**@{*/ /** Pitch and roll calculated from the accelerometer inside the Nunchuck. */ - double getNunchuckPitch() { - return (atan2(accYnunchuck, accZnunchuck) + PI) * RAD_TO_DEG; + float getNunchuckPitch() { + return (atan2f(accYnunchuck, accZnunchuck) + PI) * RAD_TO_DEG; }; - double getNunchuckRoll() { - return (atan2(accXnunchuck, accZnunchuck) + PI) * RAD_TO_DEG; + float getNunchuckRoll() { + return (atan2f(accXnunchuck, accZnunchuck) + PI) * RAD_TO_DEG; }; /**@}*/ @@ -238,17 +238,17 @@ public: /* Variables for the gyro inside the Motion Plus */ /** This is the pitch calculated by the gyro - use this to tune WII#pitchGyroScale. */ - double gyroPitch; + float gyroPitch; /** This is the roll calculated by the gyro - use this to tune WII#rollGyroScale. */ - double gyroRoll; + float gyroRoll; /** This is the yaw calculated by the gyro - use this to tune WII#yawGyroScale. */ - double gyroYaw; + float gyroYaw; /**@{*/ /** The speed in deg/s from the gyro. */ - double pitchGyroSpeed; - double rollGyroSpeed; - double yawGyroSpeed; + float pitchGyroSpeed; + float rollGyroSpeed; + float yawGyroSpeed; /**@}*/ /**@{*/ @@ -482,8 +482,8 @@ private: uint16_t wiiBalanceBoardRaw[4]; // Wii Balance Board raw values uint16_t wiiBalanceBoardCal[3][4]; // Wii Balance Board calibration values - double compPitch; // Fusioned angle using a complimentary filter if the Motion Plus is connected - double compRoll; // Fusioned angle using a complimentary filter if the Motion Plus is connected + float compPitch; // Fusioned angle using a complimentary filter if the Motion Plus is connected + float compRoll; // Fusioned angle using a complimentary filter if the Motion Plus is connected bool activateNunchuck; bool motionValuesReset; // This bool is true when the gyro values has been reset From bd679a8a195de02839173fdd4231d00825009a90 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Oct 2015 13:35:26 +0200 Subject: [PATCH 098/220] Added support for STM32F446 Nucleo board --- README.md | 2 ++ avrpins.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ settings.h | 5 +++++ usbhost.h | 27 +++++++++++++++++++++++++- 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 548f46b6..20e83432 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,8 @@ Currently the following boards are supported by the library: * RedBearLab nRF51822 * Digilent chipKIT * Please see: . +* STM32F4 + * Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: . The following boards need to be activated manually in [settings.h](settings.h): diff --git a/avrpins.h b/avrpins.h index 05c9ab79..b73a6bc6 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1074,6 +1074,62 @@ MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24)); #undef MAKE_PIN +#elif defined(STM32F446xx) +// NUCLEO-F446RE + +#define MAKE_PIN(className, port, pin) \ +class className { \ +public: \ + static void Set() { \ + HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET); \ + } \ + static void Clear() { \ + HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET); \ + } \ + static void SetDirRead() { \ + static GPIO_InitTypeDef GPIO_InitStruct; \ + GPIO_InitStruct.Pin = pin; \ + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; \ + GPIO_InitStruct.Pull = GPIO_NOPULL; \ + HAL_GPIO_Init(port, &GPIO_InitStruct); \ + } \ + static void SetDirWrite() { \ + static GPIO_InitTypeDef GPIO_InitStruct; \ + GPIO_InitStruct.Pin = pin; \ + GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; \ + GPIO_InitStruct.Pull = GPIO_NOPULL; \ + GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; \ + HAL_GPIO_Init(port, &GPIO_InitStruct); \ + } \ + static GPIO_PinState IsSet() { \ + return HAL_GPIO_ReadPin(port, pin); \ + } \ +}; + +MAKE_PIN(P0, GPIOA, GPIO_PIN_3); // D0 +MAKE_PIN(P1, GPIOA, GPIO_PIN_2); // D1 +MAKE_PIN(P2, GPIOA, GPIO_PIN_10); // D2 +MAKE_PIN(P3, GPIOB, GPIO_PIN_3); // D3 +MAKE_PIN(P4, GPIOB, GPIO_PIN_5); // D4 +MAKE_PIN(P5, GPIOB, GPIO_PIN_4); // D5 +MAKE_PIN(P6, GPIOB, GPIO_PIN_10); // D6 +MAKE_PIN(P7, GPIOA, GPIO_PIN_8); // D7 +MAKE_PIN(P8, GPIOA, GPIO_PIN_9); // D8 +MAKE_PIN(P9, GPIOC, GPIO_PIN_7); // D9 +MAKE_PIN(P10, GPIOB, GPIO_PIN_6); // D10 +MAKE_PIN(P11, GPIOA, GPIO_PIN_7); // D11 +MAKE_PIN(P12, GPIOA, GPIO_PIN_6); // D12 +MAKE_PIN(P13, GPIOA, GPIO_PIN_5); // D13 + +MAKE_PIN(P14, GPIOA, GPIO_PIN_0); // A0 +MAKE_PIN(P15, GPIOA, GPIO_PIN_1); // A1 +MAKE_PIN(P16, GPIOA, GPIO_PIN_4); // A2 +MAKE_PIN(P17, GPIOB, GPIO_PIN_0); // A3 +MAKE_PIN(P18, GPIOC, GPIO_PIN_1); // A4 +MAKE_PIN(P19, GPIOC, GPIO_PIN_0); // A5 + +#undef MAKE_PIN + #else #error "Please define board in avrpins.h" diff --git a/settings.h b/settings.h index 9d3a69cd..6c1979af 100644 --- a/settings.h +++ b/settings.h @@ -142,4 +142,9 @@ e-mail : support@circuitsathome.com #include <../../../../hardware/pic32/libraries/SPI/SPI.h> // Hack to use the SPI library #endif +#ifdef STM32F4 +#include "stm32f4xx_hal.h" +extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp +#endif + #endif /* SETTINGS_H */ diff --git a/usbhost.h b/usbhost.h index 383ce7e8..15a57bd1 100644 --- a/usbhost.h +++ b/usbhost.h @@ -45,6 +45,11 @@ public: SPI_SS::SetDirWrite(); SPI_SS::Set(); } +#elif defined(STM32F4) +#warning "You need to initialize the SPI interface manually when using the STM32F4 platform" + static void init() { + // Should be initialized by the user manually for now + } #elif !defined(SPDR) static void init() { SPI_SS::SetDirWrite(); @@ -86,7 +91,7 @@ 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(__MKL26Z64__))) || defined(__ARDUINO_X86__) || defined(__MIPSEL__) +#elif (defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__))) || 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; @@ -162,6 +167,11 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { c[0] = reg | 0x02; c[1] = data; SPI.transfer(c, 2); +#elif defined(STM32F4) + uint8_t c[2]; + c[0] = reg | 0x02; + c[1] = data; + HAL_SPI_Transmit(&SPI_Handle, c, 2, HAL_MAX_DELAY); #elif !defined(SPDR) SPI.transfer(reg | 0x02); SPI.transfer(data); @@ -202,6 +212,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* SPI.transfer(reg | 0x02); SPI.transferBuffer(data_p, NULL, nbytes); data_p += nbytes; +#elif defined(STM32F4) + uint8_t data = reg | 0x02; + HAL_SPI_Transmit(&SPI_Handle, &data, 1, HAL_MAX_DELAY); + HAL_SPI_Transmit(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY); + data_p += nbytes; #elif !defined(SPDR) SPI.transfer(reg | 0x02); while(nbytes) { @@ -252,6 +267,11 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { spi4teensy3::send(reg); uint8_t rv = spi4teensy3::receive(); SPI_SS::Set(); +#elif defined(STM32F4) + HAL_SPI_Transmit(&SPI_Handle, ®, 1, HAL_MAX_DELAY); + uint8_t rv = 0; + HAL_SPI_Receive(&SPI_Handle, &rv, 1, HAL_MAX_DELAY); + SPI_SS::Set(); #elif !defined(SPDR) || SPI_HAS_TRANSACTION SPI.transfer(reg); uint8_t rv = SPI.transfer(0); // Send empty byte @@ -295,6 +315,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* SPI.transfer(reg); SPI.transferBuffer(NULL, data_p, nbytes); data_p += nbytes; +#elif defined(STM32F4) + HAL_SPI_Transmit(&SPI_Handle, ®, 1, HAL_MAX_DELAY); + memset(data_p, 0, nbytes); // Make sure we send out empty bytes + HAL_SPI_Receive(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY); + data_p += nbytes; #elif !defined(SPDR) SPI.transfer(reg); while(nbytes) { From 906e6c069425bc3d8340312edc9c42bc0fa40371 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 19 Oct 2015 15:57:59 +0100 Subject: [PATCH 099/220] Cache @PlatformIO packages using @travis-ci container-based infrastructure --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b77449f0..b02d84a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,12 @@ language: python - python: - "2.7" +# Cache PlatformIO packages using Travis CI container-based infrastructure sudo: false +cache: + directories: + - "~/.platformio" env: - PLATFORMIO_CI_SRC=examples/acm/acm_terminal @@ -51,7 +54,7 @@ env: - PLATFORMIO_CI_SRC=examples/Xbox/XBOXUSB install: - - python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/master/scripts/get-platformio.py)" + - pip install -U platformio # # Libraries from PlatformIO Library Registry: From 92a369f64b4ef40d1b5cffcfae0018949a896b0d Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 7 Nov 2015 15:21:27 +0100 Subject: [PATCH 100/220] Added ST STM32 to library.json --- library.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index 1d649b1e..bf8798c1 100644 --- a/library.json +++ b/library.json @@ -42,6 +42,7 @@ "atmelavr", "teensy", "atmelsam", - "nordicnrf51" + "nordicnrf51", + "ststm32" ] } From 67f7861d7c78eb2d7778c0f2b3f8d275584574b5 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 7 Nov 2015 15:25:21 +0100 Subject: [PATCH 101/220] Added SPL to supported frameworks --- library.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library.json b/library.json index bf8798c1..f2cd6dab 100644 --- a/library.json +++ b/library.json @@ -33,10 +33,14 @@ }, "examples": [ - "examples/*/*.ino", - "examples/*/*/*.ino" + "examples/*/*.ino", + "examples/*/*/*.ino" + ], + "frameworks": + [ + "arduino", + "spl" ], - "frameworks": "arduino", "platforms": [ "atmelavr", From e605792212c0c02a7a39bd2940ae2fb04cf2bb41 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 7 Nov 2015 15:28:59 +0100 Subject: [PATCH 102/220] Release version 1.2.0 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 1a539326..3e894ef4 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=USB Host Shield Library 2.0 -version=1.1.1 +version=1.2.0 author=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll , Alexei Glushchenko (Circuits@Home) maintainer=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll sentence=Revision 2.0 of MAX3421E-based USB Host Shield Library. From 4266a5c388b7f5ad6ba25df7f2581c56b73b2e56 Mon Sep 17 00:00:00 2001 From: Andrew Kroll Date: Sun, 8 Nov 2015 22:58:28 -0500 Subject: [PATCH 103/220] Fix typo that that has been here forever, wrong opcode in ModeSense6 --- masstorage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/masstorage.cpp b/masstorage.cpp index 9299f71a..8e8313a2 100644 --- a/masstorage.cpp +++ b/masstorage.cpp @@ -754,7 +754,7 @@ uint8_t BulkOnly::ModeSense6(uint8_t lun, uint8_t pc, uint8_t page, uint8_t subp Notify(PSTR("\r\rModeSense\r\n"), 0x80); Notify(PSTR("------------\r\n"), 0x80); - CDB6_t cdb = CDB6_t(SCSI_CMD_TEST_UNIT_READY, lun, (uint32_t)((((pc << 6) | page) << 8) | subpage), len, 0); + CDB6_t cdb = CDB6_t(SCSI_CMD_MODE_SENSE_6, lun, (uint32_t)((((pc << 6) | page) << 8) | subpage), len, 0); return SCSITransaction6(&cdb, len, pbuf, (uint8_t)MASS_CMD_DIR_IN); } From fb723fcbb02c9b343209b954eff53bef5a7316e4 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 18 Nov 2015 00:11:33 +0100 Subject: [PATCH 104/220] Don't set epAttribs to 0, as this will set bmNakPower to 0 as well. Instead set bmSndToggle and bmRcvToggle explicit to 0. Fixes: #184 --- BTD.cpp | 3 ++- PS3USB.cpp | 3 ++- Usb.cpp | 3 ++- XBOXOLD.cpp | 3 ++- XBOXONE.cpp | 3 ++- XBOXRECV.cpp | 3 ++- XBOXUSB.cpp | 3 ++- address.h | 3 ++- adk.cpp | 3 ++- cdcacm.cpp | 6 ++++-- cdcftdi.cpp | 6 ++++-- hidboot.h | 6 ++++-- hiduniversal.cpp | 6 ++++-- masstorage.cpp | 11 ++++++----- usbhub.cpp | 6 ++++-- 15 files changed, 44 insertions(+), 24 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 1bad3099..075f5ed1 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -290,7 +290,8 @@ void BTD::Initialize() { for(i = 0; i < BTD_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; } for(i = 0; i < BTD_NUM_SERVICES; i++) { diff --git a/PS3USB.cpp b/PS3USB.cpp index cfe6f631..f247cc91 100755 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -28,7 +28,8 @@ bPollEnable(false) // don't start polling before dongle is connected for(uint8_t i = 0; i < PS3_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; } diff --git a/Usb.cpp b/Usb.cpp index 2703c034..d6755c9d 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -663,7 +663,8 @@ uint8_t USB::Configuring(uint8_t parent, uint8_t port, bool lowspeed) { epInfo.epAddr = 0; epInfo.maxPktSize = 8; - epInfo.epAttribs = 0; + epInfo.bmSndToggle = 0; + epInfo.bmRcvToggle = 0; epInfo.bmNakPower = USB_NAK_MAX_POWER; //delay(2000); diff --git a/XBOXOLD.cpp b/XBOXOLD.cpp index 78e6e9a5..3d88ea97 100644 --- a/XBOXOLD.cpp +++ b/XBOXOLD.cpp @@ -51,7 +51,8 @@ bPollEnable(false) { // don't start polling before dongle is connected for(uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; } diff --git a/XBOXONE.cpp b/XBOXONE.cpp index 2159c052..0698a6aa 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -31,7 +31,8 @@ bPollEnable(false) { // don't start polling before dongle is connected for(uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; } diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index 41f1ff58..39e14ef8 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -29,7 +29,8 @@ bPollEnable(false) { // don't start polling before dongle is connected for(uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; } diff --git a/XBOXUSB.cpp b/XBOXUSB.cpp index ddece21b..ce69f82b 100644 --- a/XBOXUSB.cpp +++ b/XBOXUSB.cpp @@ -27,7 +27,8 @@ bPollEnable(false) { // don't start polling before dongle is connected for(uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; } diff --git a/address.h b/address.h index c3e1b314..ec48adbf 100644 --- a/address.h +++ b/address.h @@ -169,7 +169,8 @@ public: thePool[0].epinfo = &dev0ep; dev0ep.epAddr = 0; dev0ep.maxPktSize = 8; - dev0ep.epAttribs = 0; //set DATA0/1 toggles to 0 + dev0ep.bmSndToggle = 0; // Set DATA0/1 toggles to 0 + dev0ep.bmRcvToggle = 0; dev0ep.bmNakPower = USB_NAK_MAX_POWER; InitAllAddresses(); diff --git a/adk.cpp b/adk.cpp index 9e4e0c8d..f9631ae8 100644 --- a/adk.cpp +++ b/adk.cpp @@ -45,7 +45,8 @@ ready(false) { for(uint8_t i = 0; i < ADK_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; }//for(uint8_t i=0; ibEndpointAddress & 0x0F); epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize; - epInfo[index].epAttribs = 0; + epInfo[index].bmSndToggle = 0; + epInfo[index].bmRcvToggle = 0; bNumEP++; diff --git a/cdcftdi.cpp b/cdcftdi.cpp index 80d21d16..e849d6e2 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -29,7 +29,8 @@ wFTDIType(0) { for(uint8_t i = 0; i < FTDI_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i==epDataInIndex) ? USB_NAK_NOWAIT: USB_NAK_MAX_POWER; } if(pUsb) @@ -227,7 +228,8 @@ void FTDI::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t prot // Fill in the endpoint info structure epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize; - epInfo[index].epAttribs = 0; + epInfo[index].bmSndToggle = 0; + epInfo[index].bmRcvToggle = 0; bNumEP++; diff --git a/hidboot.h b/hidboot.h index 797c107a..18cc7812 100644 --- a/hidboot.h +++ b/hidboot.h @@ -270,7 +270,8 @@ void HIDBoot::Initialize() { for(int i = 0; i < totalEndpoints(BOOT_PROTOCOL); i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; } bNumEP = 1; @@ -546,7 +547,8 @@ void HIDBoot::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t // Fill in the endpoint info structure epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; - epInfo[bNumEP].epAttribs = 0; + epInfo[bNumEP].bmSndToggle = 0; + epInfo[bNumEP].bmRcvToggle = 0; epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT; bNumEP++; diff --git a/hiduniversal.cpp b/hiduniversal.cpp index 395aa69e..ac9f0448 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -59,7 +59,8 @@ void HIDUniversal::Initialize() { for(uint8_t i = 0; i < totalEndpoints; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; } bNumEP = 1; @@ -323,7 +324,8 @@ void HIDUniversal::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint // Fill in the endpoint info structure epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; - epInfo[bNumEP].epAttribs = 0; + epInfo[bNumEP].bmSndToggle = 0; + epInfo[bNumEP].bmRcvToggle = 0; epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT; // Fill in the endpoint index list diff --git a/masstorage.cpp b/masstorage.cpp index 8e8313a2..b528bb80 100644 --- a/masstorage.cpp +++ b/masstorage.cpp @@ -555,7 +555,8 @@ void BulkOnly::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t // Fill in the endpoint info structure epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize; - epInfo[index].epAttribs = 0; + epInfo[index].bmSndToggle = 0; + epInfo[index].bmRcvToggle = 0; bNumEP++; @@ -574,7 +575,8 @@ void BulkOnly::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t // Fill in the endpoint info structure epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize; - epInfo[index].epAttribs = 0; + epInfo[index].bmSndToggle = 0; + epInfo[index].bmRcvToggle = 0; bNumEP++; @@ -850,7 +852,6 @@ uint8_t BulkOnly::ClearEpHalt(uint8_t index) { } epInfo[index].bmSndToggle = 0; epInfo[index].bmRcvToggle = 0; - // epAttribs = 0; return 0; } @@ -890,8 +891,8 @@ void BulkOnly::ClearAllEP() { for(uint8_t i = 0; i < MASS_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; - epInfo[i].epAttribs = 0; - + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; epInfo[i].bmNakPower = USB_NAK_DEFAULT; } diff --git a/usbhub.cpp b/usbhub.cpp index 7fed48e7..6ead8bd0 100644 --- a/usbhub.cpp +++ b/usbhub.cpp @@ -27,12 +27,14 @@ qNextPollTime(0), bPollEnable(false) { epInfo[0].epAddr = 0; epInfo[0].maxPktSize = 8; - epInfo[0].epAttribs = 0; + epInfo[0].bmSndToggle = 0; + epInfo[0].bmRcvToggle = 0; epInfo[0].bmNakPower = USB_NAK_MAX_POWER; epInfo[1].epAddr = 1; epInfo[1].maxPktSize = 8; //kludge - epInfo[1].epAttribs = 0; + epInfo[1].bmSndToggle = 0; + epInfo[1].bmRcvToggle = 0; epInfo[1].bmNakPower = USB_NAK_NOWAIT; if(pUsb) From 9a51211a3510319ff4b5568ae743a5655507478c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 18 Nov 2015 00:23:21 +0100 Subject: [PATCH 105/220] Allow to set LEDs using the KDBLEDS struct --- BTHID.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/BTHID.h b/BTHID.h index 1a7d8687..07ece32c 100644 --- a/BTHID.h +++ b/BTHID.h @@ -73,11 +73,16 @@ public: protocolMode = mode; }; + /**@{*/ /** * Used to set the leds on a keyboard. - * @param data See KBDLEDS in hidboot.h + * @param data See ::KBDLEDS in hidboot.h */ + void setLeds(struct KBDLEDS data) { + setLeds(*((uint8_t*)&data)); + }; void setLeds(uint8_t data); + /**@}*/ /** True if a device is connected */ bool connected; From 75eaa349f8bbeb34f427f4c1f5024e6a35b11b0c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 22 Nov 2015 13:31:33 +0100 Subject: [PATCH 106/220] Release version 1.2.1 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 3e894ef4..d5d4b408 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=USB Host Shield Library 2.0 -version=1.2.0 +version=1.2.1 author=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll , Alexei Glushchenko (Circuits@Home) maintainer=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll sentence=Revision 2.0 of MAX3421E-based USB Host Shield Library. From 50ae401566a27d265000618d236225a0ec2f2008 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 6 Dec 2015 18:35:16 +0100 Subject: [PATCH 107/220] Print error message if a USB Hub is detected in the BTD class This is useful as some Bluetooth dongles have a hub inside Fixes #187 --- BTD.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/BTD.cpp b/BTD.cpp index 075f5ed1..b3b41a7f 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -101,6 +101,9 @@ uint8_t BTD::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) { return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; } + if (udd->bDeviceClass == 0x09) // Some dongles have an USB hub inside + goto FailHub; + epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Extract Max Packet Size from device descriptor epInfo[1].epAddr = udd->bNumConfigurations; // Steal and abuse from epInfo structure to save memory @@ -109,6 +112,15 @@ uint8_t BTD::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) { return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; +FailHub: +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nPlease create a hub instance in your code: \"USBHub Hub1(&Usb);\""), 0x80); +#endif + pUsb->setAddr(bAddress, 0, 0); // Reset address + rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; + Release(); + return rcode; + FailGetDevDescr: #ifdef DEBUG_USB_HOST NotifyFailGetDevDescr(rcode); From 30ec2e942fabb8a21b1e10ed9aad5f7e24199703 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 21 Dec 2015 15:34:48 +0100 Subject: [PATCH 108/220] Added note about that native USB Host is not supported Fixes: #193 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 20e83432..553238f1 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ 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, Intel Galileo, Intel Galileo 2, and Intel Edison * 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. + * Note native USB host is not supported on any of these platforms. You will have to use the shield for now. * Teensy (Teensy++ 1.0, Teensy 2.0, Teensy++ 2.0, Teensy 3.x, and Teensy LC) * 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 From 69cc39989577f0a436e96ccec6afa90d02bf88cf Mon Sep 17 00:00:00 2001 From: Daniel Romero Date: Tue, 29 Dec 2015 20:51:40 +0100 Subject: [PATCH 109/220] Add possibility to set a custom FTDI PID, to be able to connect to customized FTDI chip --- cdcftdi.cpp | 15 ++++++++++++--- cdcftdi.h | 3 ++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cdcftdi.cpp b/cdcftdi.cpp index e849d6e2..98d7da70 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -20,12 +20,13 @@ const uint8_t FTDI::epDataInIndex = 1; const uint8_t FTDI::epDataOutIndex = 2; const uint8_t FTDI::epInterruptInIndex = 3; -FTDI::FTDI(USB *p, FTDIAsyncOper *pasync) : +FTDI::FTDI(USB *p, FTDIAsyncOper *pasync, uint16_t idProduct) : pAsync(pasync), pUsb(p), bAddress(0), bNumEP(1), -wFTDIType(0) { +wFTDIType(0), +wIdProduct(idProduct) { for(uint8_t i = 0; i < FTDI_MAX_ENDPOINTS; i++) { epInfo[i].epAddr = 0; epInfo[i].maxPktSize = (i) ? 0 : 8; @@ -82,8 +83,16 @@ uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) { if(rcode) goto FailGetDevDescr; - if(udd->idVendor != FTDI_VID || udd->idProduct != FTDI_PID) + if(udd->idVendor != FTDI_VID || udd->idProduct != wIdProduct) + { + USBTRACE("FTDI Init: Product not supported\r\n"); + USBTRACE2("Expected VID:", FTDI_VID); + USBTRACE2("Found VID:", udd->idVendor); + + USBTRACE2("Expected PID:", wIdProduct); + USBTRACE2("Found PID:", udd->idProduct); return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; + } // Save type of FTDI chip wFTDIType = udd->bcdDevice; diff --git a/cdcftdi.h b/cdcftdi.h index b7312526..8410bcdd 100644 --- a/cdcftdi.h +++ b/cdcftdi.h @@ -107,13 +107,14 @@ class FTDI : public USBDeviceConfig, public UsbConfigXtracter { uint32_t qNextPollTime; // next poll time bool bPollEnable; // poll enable flag uint16_t wFTDIType; // Type of FTDI chip + uint16_t wIdProduct; // expected PID EpInfo epInfo[FTDI_MAX_ENDPOINTS]; void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); public: - FTDI(USB *pusb, FTDIAsyncOper *pasync); + FTDI(USB *pusb, FTDIAsyncOper *pasync, uint16_t idProduct = FTDI_PID); uint8_t SetBaudRate(uint32_t baud); uint8_t SetModemControl(uint16_t control); From 969eabb8d7979c4cf76a02677f433d2ef5af7735 Mon Sep 17 00:00:00 2001 From: Pavel Fatin Date: Sat, 16 Jan 2016 20:01:11 +0100 Subject: [PATCH 110/220] Compatibility with Arduino's core HID / Mouse / Keyboard libraries The following collisions resolved: hid.h -> usbhid.h hid.cpp -> usbhid.cpp HID -> USBHID HID_BOOT_PROTOCOL -> USB_HID_BOOT_PROTOCOL HID_PROTOCOL_NONE -> USB_HID_PROTOCOL_NONE HID_PROTOCOL_KEYBOARD -> USB_HID_PROTOCOL_KEYBOARD HID_PROTOCOL_MOUSE -> USB_HID_PROTOCOL_MOUSE As a result, it's possible to use the library together with Arduino's bundled HID / Mouse / Keyboard libraries (Leonardo, Micro, or Due). https://www.arduino.cc/en/Reference/MouseKeyboard --- BTD.h | 2 +- BTHID.cpp | 10 +++--- BTHID.h | 2 +- PS3USB.h | 2 +- PS4USB.h | 2 +- PSBuzz.cpp | 2 +- PSBuzz.h | 2 +- XBOXOLD.h | 2 +- XBOXUSB.h | 2 +- examples/Bluetooth/BTHID/BTHID.ino | 2 +- examples/Bluetooth/BTHID/KeyboardParser.h | 4 +-- examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino | 2 +- .../USBHIDBootKbdAndMouse.ino | 6 ++-- .../HID/USBHIDBootMouse/USBHIDBootMouse.ino | 2 +- .../HID/USBHIDJoystick/USBHIDJoystick.ino | 2 +- .../USBHIDJoystick/hidjoystickrptparser.cpp | 2 +- .../HID/USBHIDJoystick/hidjoystickrptparser.h | 4 +-- examples/HID/USBHID_desc/USBHID_desc.ino | 2 +- examples/HID/le3dp/le3dp.ino | 2 +- examples/HID/le3dp/le3dp_rptparser.cpp | 2 +- examples/HID/le3dp/le3dp_rptparser.h | 4 +-- examples/HID/scale/scale.ino | 2 +- examples/HID/scale/scale_rptparser.cpp | 2 +- examples/HID/scale/scale_rptparser.h | 4 +-- examples/adk/adk_barcode/adk_barcode.ino | 2 +- hidboot.cpp | 4 +-- hidboot.h | 34 +++++++++---------- hidescriptorparser.cpp | 2 +- hidescriptorparser.h | 4 +-- hiduniversal.cpp | 2 +- hiduniversal.h | 6 ++-- hid.cpp => usbhid.cpp | 24 ++++++------- hid.h => usbhid.h | 22 ++++++------ 33 files changed, 84 insertions(+), 84 deletions(-) rename hid.cpp => usbhid.cpp (81%) rename hid.h => usbhid.h (93%) diff --git a/BTD.h b/BTD.h index 6549c30c..214931a8 100755 --- a/BTD.h +++ b/BTD.h @@ -19,7 +19,7 @@ #define _btd_h_ #include "Usb.h" -#include "hid.h" +#include "usbhid.h" //PID and VID of the Sony PS3 devices #define PS3_VID 0x054C // Sony Corporation diff --git a/BTHID.cpp b/BTHID.cpp index bfa9202c..d32e9aa6 100644 --- a/BTHID.cpp +++ b/BTHID.cpp @@ -22,7 +22,7 @@ BTHID::BTHID(BTD *p, bool pair, const char *pin) : BluetoothService(p), // Pointer to USB class instance - mandatory -protocolMode(HID_BOOT_PROTOCOL) { +protocolMode(USB_HID_BOOT_PROTOCOL) { for(uint8_t i = 0; i < NUM_PARSERS; i++) pRptParser[i] = NULL; @@ -192,12 +192,12 @@ void BTHID::ACLData(uint8_t* l2capinbuf) { switch(l2capinbuf[9]) { case 0x01: // Keyboard or Joystick events if(pRptParser[KEYBOARD_PARSER_ID]) - pRptParser[KEYBOARD_PARSER_ID]->Parse(reinterpret_cast(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance + pRptParser[KEYBOARD_PARSER_ID]->Parse(reinterpret_cast(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance break; case 0x02: // Mouse events if(pRptParser[MOUSE_PARSER_ID]) - pRptParser[MOUSE_PARSER_ID]->Parse(reinterpret_cast(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance + pRptParser[MOUSE_PARSER_ID]->Parse(reinterpret_cast(this), 0, (uint8_t)(length - 2), &l2capinbuf[10]); // Use reinterpret_cast again to extract the instance break; #ifdef EXTRADEBUG default: @@ -380,11 +380,11 @@ void BTHID::setProtocol() { Notify(PSTR("\r\nSet protocol mode: "), 0x80); D_PrintHex (protocolMode, 0x80); #endif - if (protocolMode != HID_BOOT_PROTOCOL && protocolMode != HID_RPT_PROTOCOL) { + if (protocolMode != USB_HID_BOOT_PROTOCOL && protocolMode != HID_RPT_PROTOCOL) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNot a valid protocol mode. Using Boot protocol instead."), 0x80); #endif - protocolMode = HID_BOOT_PROTOCOL; // Use Boot Protocol by default + protocolMode = USB_HID_BOOT_PROTOCOL; // Use Boot Protocol by default } uint8_t command = 0x70 | protocolMode; // Set Protocol, see Bluetooth HID specs page 33 pBtd->L2CAP_Command(hci_handle, &command, 1, control_scid[0], control_scid[1]); diff --git a/BTHID.h b/BTHID.h index 07ece32c..ac9128a2 100644 --- a/BTHID.h +++ b/BTHID.h @@ -67,7 +67,7 @@ public: /** * Set HID protocol mode. - * @param mode HID protocol to use. Either HID_BOOT_PROTOCOL or HID_RPT_PROTOCOL. + * @param mode HID protocol to use. Either USB_HID_BOOT_PROTOCOL or HID_RPT_PROTOCOL. */ void setProtocolMode(uint8_t mode) { protocolMode = mode; diff --git a/PS3USB.h b/PS3USB.h index c10faaea..338aa7af 100644 --- a/PS3USB.h +++ b/PS3USB.h @@ -19,7 +19,7 @@ #define _ps3usb_h_ #include "Usb.h" -#include "hid.h" +#include "usbhid.h" #include "PS3Enums.h" /* PS3 data taken from descriptors */ diff --git a/PS4USB.h b/PS4USB.h index b43079a6..b5346ff6 100644 --- a/PS4USB.h +++ b/PS4USB.h @@ -64,7 +64,7 @@ protected: * @param len The length of the incoming data. * @param buf Pointer to the data buffer. */ - virtual void ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { + virtual void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { if (HIDUniversal::VID == PS4_VID && HIDUniversal::PID == PS4_PID) PS4Parser::Parse(len, buf); }; diff --git a/PSBuzz.cpp b/PSBuzz.cpp index 498164d5..7a4615e0 100644 --- a/PSBuzz.cpp +++ b/PSBuzz.cpp @@ -20,7 +20,7 @@ // To enable serial debugging see "settings.h" //#define PRINTREPORT // Uncomment to print the report send by the PS Buzz Controllers -void PSBuzz::ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { +void PSBuzz::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { if (HIDUniversal::VID == PSBUZZ_VID && HIDUniversal::PID == PSBUZZ_PID && len > 2 && buf) { #ifdef PRINTREPORT Notify(PSTR("\r\n"), 0x80); diff --git a/PSBuzz.h b/PSBuzz.h index 8880d9e5..da83dff0 100644 --- a/PSBuzz.h +++ b/PSBuzz.h @@ -143,7 +143,7 @@ protected: * @param len The length of the incoming data. * @param buf Pointer to the data buffer. */ - void ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); + void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); /** * Called when a device is successfully initialized. diff --git a/XBOXOLD.h b/XBOXOLD.h index 9a36b5cc..6b0757b2 100644 --- a/XBOXOLD.h +++ b/XBOXOLD.h @@ -19,7 +19,7 @@ #define _xboxold_h_ #include "Usb.h" -#include "hid.h" +#include "usbhid.h" #include "controllerEnums.h" /* Data Xbox taken from descriptors */ diff --git a/XBOXUSB.h b/XBOXUSB.h index 1ab37851..7f75610e 100644 --- a/XBOXUSB.h +++ b/XBOXUSB.h @@ -19,7 +19,7 @@ #define _xboxusb_h_ #include "Usb.h" -#include "hid.h" +#include "usbhid.h" #include "xboxEnums.h" /* Data Xbox 360 taken from descriptors */ diff --git a/examples/Bluetooth/BTHID/BTHID.ino b/examples/Bluetooth/BTHID/BTHID.ino index 919a5646..d0504012 100644 --- a/examples/Bluetooth/BTHID/BTHID.ino +++ b/examples/Bluetooth/BTHID/BTHID.ino @@ -45,7 +45,7 @@ void setup() { // If "Boot Protocol Mode" does not work, then try "Report Protocol Mode" // If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report - bthid.setProtocolMode(HID_BOOT_PROTOCOL); // Boot Protocol Mode + bthid.setProtocolMode(USB_HID_BOOT_PROTOCOL); // Boot Protocol Mode //bthid.setProtocolMode(HID_RPT_PROTOCOL); // Report Protocol Mode Serial.print(F("\r\nHID Bluetooth Library Started")); diff --git a/examples/Bluetooth/BTHID/KeyboardParser.h b/examples/Bluetooth/BTHID/KeyboardParser.h index c5394331..5c1ff1ff 100644 --- a/examples/Bluetooth/BTHID/KeyboardParser.h +++ b/examples/Bluetooth/BTHID/KeyboardParser.h @@ -3,7 +3,7 @@ class KbdRptParser : public KeyboardReportParser { protected: - virtual uint8_t HandleLockingKeys(HID *hid, uint8_t key); + virtual uint8_t HandleLockingKeys(USBHID *hid, uint8_t key); virtual void OnControlKeysChanged(uint8_t before, uint8_t after); virtual void OnKeyDown(uint8_t mod, uint8_t key); virtual void OnKeyUp(uint8_t mod, uint8_t key); @@ -13,7 +13,7 @@ class KbdRptParser : public KeyboardReportParser { void PrintKey(uint8_t mod, uint8_t key); }; -uint8_t KbdRptParser::HandleLockingKeys(HID *hid, uint8_t key) { +uint8_t KbdRptParser::HandleLockingKeys(USBHID *hid, uint8_t key) { uint8_t old_keys = kbdLockingKeys.bLeds; switch (key) { diff --git a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino index 48b33abf..9667bfbc 100644 --- a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino +++ b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino @@ -98,7 +98,7 @@ void KbdRptParser::OnKeyPressed(uint8_t key) USB Usb; //USBHub Hub(&Usb); -HIDBoot HidKeyboard(&Usb); +HIDBoot HidKeyboard(&Usb); uint32_t next_time; diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino index 5fc8c96f..a4ffe25c 100644 --- a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -141,9 +141,9 @@ void KbdRptParser::OnKeyPressed(uint8_t key) USB Usb; USBHub Hub(&Usb); -HIDBoot < HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE > HidComposite(&Usb); -HIDBoot HidKeyboard(&Usb); -HIDBoot HidMouse(&Usb); +HIDBoot < USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE > HidComposite(&Usb); +HIDBoot HidKeyboard(&Usb); +HIDBoot HidMouse(&Usb); //uint32_t next_time; diff --git a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino index 53102512..03389959 100644 --- a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino +++ b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino @@ -52,7 +52,7 @@ void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi) USB Usb; USBHub Hub(&Usb); -HIDBoot HidMouse(&Usb); +HIDBoot HidMouse(&Usb); uint32_t next_time; diff --git a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino index 956441d6..dff9cd50 100644 --- a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino +++ b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp b/examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp index 083b95ca..732b564a 100644 --- a/examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp +++ b/examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp @@ -8,7 +8,7 @@ oldButtons(0) { oldPad[i] = 0xD; } -void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { +void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { bool match = true; // Checking if there are changes in report since the method was last called diff --git a/examples/HID/USBHIDJoystick/hidjoystickrptparser.h b/examples/HID/USBHIDJoystick/hidjoystickrptparser.h index 733b8f8d..3e037e15 100644 --- a/examples/HID/USBHIDJoystick/hidjoystickrptparser.h +++ b/examples/HID/USBHIDJoystick/hidjoystickrptparser.h @@ -1,7 +1,7 @@ #if !defined(__HIDJOYSTICKRPTPARSER_H__) #define __HIDJOYSTICKRPTPARSER_H__ -#include +#include struct GamePadEventData { uint8_t X, Y, Z1, Z2, Rz; @@ -27,7 +27,7 @@ class JoystickReportParser : public HIDReportParser { public: JoystickReportParser(JoystickEvents *evt); - virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); + virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); }; #endif // __HIDJOYSTICKRPTPARSER_H__ diff --git a/examples/HID/USBHID_desc/USBHID_desc.ino b/examples/HID/USBHID_desc/USBHID_desc.ino index 85cfc19a..cd7ced23 100644 --- a/examples/HID/USBHID_desc/USBHID_desc.ino +++ b/examples/HID/USBHID_desc/USBHID_desc.ino @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/examples/HID/le3dp/le3dp.ino b/examples/HID/le3dp/le3dp.ino index 837d7f5a..07a1da04 100644 --- a/examples/HID/le3dp/le3dp.ino +++ b/examples/HID/le3dp/le3dp.ino @@ -1,6 +1,6 @@ /* Simplified Logitech Extreme 3D Pro Joystick Report Parser */ -#include +#include #include #include diff --git a/examples/HID/le3dp/le3dp_rptparser.cpp b/examples/HID/le3dp/le3dp_rptparser.cpp index baece13b..ac9ab30b 100644 --- a/examples/HID/le3dp/le3dp_rptparser.cpp +++ b/examples/HID/le3dp/le3dp_rptparser.cpp @@ -4,7 +4,7 @@ JoystickReportParser::JoystickReportParser(JoystickEvents *evt) : joyEvents(evt) {} -void JoystickReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) +void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { bool match = true; diff --git a/examples/HID/le3dp/le3dp_rptparser.h b/examples/HID/le3dp/le3dp_rptparser.h index 2400364e..26d84a34 100644 --- a/examples/HID/le3dp/le3dp_rptparser.h +++ b/examples/HID/le3dp/le3dp_rptparser.h @@ -1,7 +1,7 @@ #if !defined(__HIDJOYSTICKRPTPARSER_H__) #define __HIDJOYSTICKRPTPARSER_H__ -#include +#include struct GamePadEventData { @@ -36,7 +36,7 @@ class JoystickReportParser : public HIDReportParser public: JoystickReportParser(JoystickEvents *evt); - virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); + virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); }; #endif // __HIDJOYSTICKRPTPARSER_H__ diff --git a/examples/HID/scale/scale.ino b/examples/HID/scale/scale.ino index f26ff964..0163df1e 100644 --- a/examples/HID/scale/scale.ino +++ b/examples/HID/scale/scale.ino @@ -1,7 +1,7 @@ /* Digital Scale Output. Written for Stamps.com Model 510 */ /* 5lb Digital Scale; any HID scale with Usage page 0x8d should work */ -#include +#include #include #include diff --git a/examples/HID/scale/scale_rptparser.cpp b/examples/HID/scale/scale_rptparser.cpp index d9e00bc2..97e216d5 100644 --- a/examples/HID/scale/scale_rptparser.cpp +++ b/examples/HID/scale/scale_rptparser.cpp @@ -24,7 +24,7 @@ ScaleReportParser::ScaleReportParser(ScaleEvents *evt) : scaleEvents(evt) {} -void ScaleReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) +void ScaleReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { bool match = true; diff --git a/examples/HID/scale/scale_rptparser.h b/examples/HID/scale/scale_rptparser.h index 57fbb033..302a2d10 100644 --- a/examples/HID/scale/scale_rptparser.h +++ b/examples/HID/scale/scale_rptparser.h @@ -2,7 +2,7 @@ #define __SCALERPTPARSER_H__ #include -#include +#include /* Scale status constants */ #define REPORT_FAULT 0x01 @@ -49,7 +49,7 @@ class ScaleReportParser : public HIDReportParser public: ScaleReportParser(ScaleEvents *evt); - virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); + virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); }; #endif // __SCALERPTPARSER_H__ diff --git a/examples/adk/adk_barcode/adk_barcode.ino b/examples/adk/adk_barcode/adk_barcode.ino index 04c8d258..b498ef93 100644 --- a/examples/adk/adk_barcode/adk_barcode.ino +++ b/examples/adk/adk_barcode/adk_barcode.ino @@ -14,7 +14,7 @@ USB Usb; USBHub Hub1(&Usb); USBHub Hub2(&Usb); -HIDBoot HidKeyboard(&Usb); +HIDBoot HidKeyboard(&Usb); ADK adk(&Usb,"Circuits@Home, ltd.", "USB Host Shield", diff --git a/hidboot.cpp b/hidboot.cpp index 280b2f97..757c3051 100644 --- a/hidboot.cpp +++ b/hidboot.cpp @@ -16,7 +16,7 @@ e-mail : support@circuitsathome.com */ #include "hidboot.h" -void MouseReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { +void MouseReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { MOUSEINFO *pmi = (MOUSEINFO*)buf; // Future: // bool event; @@ -124,7 +124,7 @@ void MouseReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *bu }; -void KeyboardReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { +void KeyboardReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { // On error - return if (buf[2] == 1) return; diff --git a/hidboot.h b/hidboot.h index 18cc7812..27fda78d 100644 --- a/hidboot.h +++ b/hidboot.h @@ -17,7 +17,7 @@ e-mail : support@circuitsathome.com #if !defined(__HIDBOOT_H__) #define __HIDBOOT_H__ -#include "hid.h" +#include "usbhid.h" #define UHS_HID_BOOT_KEY_ZERO 0x27 #define UHS_HID_BOOT_KEY_ENTER 0x28 @@ -29,9 +29,9 @@ e-mail : support@circuitsathome.com #define UHS_HID_BOOT_KEY_PERIOD 0x63 // Don't worry, GCC will optimize the result to a final value. -#define bitsEndpoints(p) ((((p) & HID_PROTOCOL_KEYBOARD)? 2 : 0) | (((p) & HID_PROTOCOL_MOUSE)? 1 : 0)) +#define bitsEndpoints(p) ((((p) & USB_HID_PROTOCOL_KEYBOARD)? 2 : 0) | (((p) & USB_HID_PROTOCOL_MOUSE)? 1 : 0)) #define totalEndpoints(p) ((bitsEndpoints(p) == 3) ? 3 : 2) -#define epMUL(p) ((((p) & HID_PROTOCOL_KEYBOARD)? 1 : 0) + (((p) & HID_PROTOCOL_MOUSE)? 1 : 0)) +#define epMUL(p) ((((p) & USB_HID_PROTOCOL_KEYBOARD)? 1 : 0) + (((p) & USB_HID_PROTOCOL_MOUSE)? 1 : 0)) // Already defined in hid.h // #define HID_MAX_HID_CLASS_DESCRIPTORS 5 @@ -56,7 +56,7 @@ class MouseReportParser : public HIDReportParser { } prevState; public: - void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); + void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); protected: @@ -144,11 +144,11 @@ public: kbdLockingKeys.bLeds = 0; }; - void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); + void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); protected: - virtual uint8_t HandleLockingKeys(HID* hid, uint8_t key) { + virtual uint8_t HandleLockingKeys(USBHID* hid, uint8_t key) { uint8_t old_keys = kbdLockingKeys.bLeds; switch(key) { @@ -198,7 +198,7 @@ protected: }; template -class HIDBoot : public HID //public USBDeviceConfig, public UsbConfigXtracter +class HIDBoot : public USBHID //public USBDeviceConfig, public UsbConfigXtracter { EpInfo epInfo[totalEndpoints(BOOT_PROTOCOL)]; HIDReportParser *pRptParser[epMUL(BOOT_PROTOCOL)]; @@ -253,7 +253,7 @@ public: template HIDBoot::HIDBoot(USB *p) : -HID(p), +USBHID(p), qNextPollTime(0), bPollEnable(false) { Initialize(); @@ -381,12 +381,12 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed USBTRACE2("NC:", num_of_conf); // GCC will optimize unused stuff away. - if((BOOT_PROTOCOL & (HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE)) == (HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE)) { + if((BOOT_PROTOCOL & (USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE)) == (USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE)) { USBTRACE("HID_PROTOCOL_KEYBOARD AND MOUSE\r\n"); ConfigDescParser< USB_CLASS_HID, HID_BOOT_INTF_SUBCLASS, - HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE, + USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE, CP_MASK_COMPARE_ALL > confDescrParser(this); confDescrParser.SetOR(); // Use the OR variant. for(uint8_t i = 0; i < num_of_conf; i++) { @@ -396,13 +396,13 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed } } else { // GCC will optimize unused stuff away. - if(BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD) { + if(BOOT_PROTOCOL & USB_HID_PROTOCOL_KEYBOARD) { USBTRACE("HID_PROTOCOL_KEYBOARD\r\n"); for(uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser< USB_CLASS_HID, HID_BOOT_INTF_SUBCLASS, - HID_PROTOCOL_KEYBOARD, + USB_HID_PROTOCOL_KEYBOARD, CP_MASK_COMPARE_ALL> confDescrParserA(this); pUsb->getConfDescr(bAddress, 0, i, &confDescrParserA); @@ -412,13 +412,13 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed } // GCC will optimize unused stuff away. - if(BOOT_PROTOCOL & HID_PROTOCOL_MOUSE) { + if(BOOT_PROTOCOL & USB_HID_PROTOCOL_MOUSE) { USBTRACE("HID_PROTOCOL_MOUSE\r\n"); for(uint8_t i = 0; i < num_of_conf; i++) { ConfigDescParser< USB_CLASS_HID, HID_BOOT_INTF_SUBCLASS, - HID_PROTOCOL_MOUSE, + USB_HID_PROTOCOL_MOUSE, CP_MASK_COMPARE_ALL> confDescrParserB(this); pUsb->getConfDescr(bAddress, 0, i, &confDescrParserB); @@ -456,7 +456,7 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed // Yes, mouse wants SetProtocol and SetIdle too! for(uint8_t i = 0; i < epMUL(BOOT_PROTOCOL); i++) { USBTRACE2("\r\nInterface:", i); - rcode = SetProtocol(i, HID_BOOT_PROTOCOL); + rcode = SetProtocol(i, USB_HID_BOOT_PROTOCOL); if(rcode) goto FailSetProtocol; USBTRACE2("PROTOCOL SET HID_BOOT rcode:", rcode); rcode = SetIdle(i, 0, 0); @@ -470,7 +470,7 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed // Get RPIPE and throw it away. - if(BOOT_PROTOCOL & HID_PROTOCOL_KEYBOARD) { + if(BOOT_PROTOCOL & USB_HID_PROTOCOL_KEYBOARD) { // Wake keyboard interface by twinkling up to 5 LEDs that are in the spec. // kana, compose, scroll, caps, num rcode = 0x20; // Reuse rcode. @@ -590,7 +590,7 @@ uint8_t HIDBoot::Poll() { // Since keyboard and mice must report at least 3 bytes, we ignore the extra data. if(!rcode && read > 2) { if(pRptParser[i]) - pRptParser[i]->Parse((HID*)this, 0, (uint8_t)read, buf); + pRptParser[i]->Parse((USBHID*)this, 0, (uint8_t)read, buf); #ifdef DEBUG_USB_HOST // We really don't care about errors and anomalies unless we are debugging. } else { diff --git a/hidescriptorparser.cpp b/hidescriptorparser.cpp index e4491b4e..62c8dac5 100644 --- a/hidescriptorparser.cpp +++ b/hidescriptorparser.cpp @@ -1578,7 +1578,7 @@ void ReportDescParser2::OnInputItem(uint8_t itm) { E_Notify(PSTR("\r\n"), 0x80); } -void UniversalReportParser::Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { +void UniversalReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { ReportDescParser2 prs(len, buf); uint8_t ret = hid->GetReportDescr(0, &prs); diff --git a/hidescriptorparser.h b/hidescriptorparser.h index f3b496ff..27927c90 100644 --- a/hidescriptorparser.h +++ b/hidescriptorparser.h @@ -17,7 +17,7 @@ e-mail : support@circuitsathome.com #if !defined(__HIDDESCRIPTORPARSER_H__) #define __HIDDESCRIPTORPARSER_H__ -#include "hid.h" +#include "usbhid.h" class ReportDescParserBase : public USBReadParser { public: @@ -170,7 +170,7 @@ public: class UniversalReportParser : public HIDReportParser { public: // Method should be defined here if virtual. - virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); + virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); }; #endif // __HIDDESCRIPTORPARSER_H__ diff --git a/hiduniversal.cpp b/hiduniversal.cpp index ac9f0448..1cc92521 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -18,7 +18,7 @@ e-mail : support@circuitsathome.com #include "hiduniversal.h" HIDUniversal::HIDUniversal(USB *p) : -HID(p), +USBHID(p), qNextPollTime(0), pollInterval(0), bPollEnable(false), diff --git a/hiduniversal.h b/hiduniversal.h index d7af3840..d64ad4cc 100644 --- a/hiduniversal.h +++ b/hiduniversal.h @@ -18,10 +18,10 @@ e-mail : support@circuitsathome.com #if !defined(__HIDUNIVERSAL_H__) #define __HIDUNIVERSAL_H__ -#include "hid.h" +#include "usbhid.h" //#include "hidescriptorparser.h" -class HIDUniversal : public HID { +class HIDUniversal : public USBHID { struct ReportParser { uint8_t rptId; @@ -75,7 +75,7 @@ protected: return 0; }; - virtual void ParseHIDData(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { + virtual void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { return; }; diff --git a/hid.cpp b/usbhid.cpp similarity index 81% rename from hid.cpp rename to usbhid.cpp index e4c7721a..e38b1ca3 100644 --- a/hid.cpp +++ b/usbhid.cpp @@ -15,12 +15,12 @@ Web : http://www.circuitsathome.com e-mail : support@circuitsathome.com */ -#include "hid.h" +#include "usbhid.h" //get HID report descriptor /* WRONG! Endpoint is _ALWAYS_ ZERO for HID! We want the _INTERFACE_ value here! -uint8_t HID::GetReportDescr(uint8_t ep, USBReadParser *parser) { +uint8_t USBHID::GetReportDescr(uint8_t ep, USBReadParser *parser) { const uint8_t constBufLen = 64; uint8_t buf[constBufLen]; @@ -31,7 +31,7 @@ uint8_t HID::GetReportDescr(uint8_t ep, USBReadParser *parser) { return rcode; } */ -uint8_t HID::GetReportDescr(uint16_t wIndex, USBReadParser *parser) { +uint8_t USBHID::GetReportDescr(uint16_t wIndex, USBReadParser *parser) { const uint8_t constBufLen = 64; uint8_t buf[constBufLen]; @@ -42,36 +42,36 @@ uint8_t HID::GetReportDescr(uint16_t wIndex, USBReadParser *parser) { return rcode; } -//uint8_t HID::getHidDescr( uint8_t ep, uint16_t nbytes, uint8_t* dataptr ) +//uint8_t USBHID::getHidDescr( uint8_t ep, uint16_t nbytes, uint8_t* dataptr ) //{ // return( pUsb->ctrlReq( bAddress, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_HID, 0x0000, nbytes, dataptr )); //} -uint8_t HID::SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) { +uint8_t USBHID::SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) { return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL)); } -uint8_t HID::GetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) { +uint8_t USBHID::GetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr) { return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HID_IN, HID_REQUEST_GET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL)); } -uint8_t HID::GetIdle(uint8_t iface, uint8_t reportID, uint8_t* dataptr) { +uint8_t USBHID::GetIdle(uint8_t iface, uint8_t reportID, uint8_t* dataptr) { return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_IN, HID_REQUEST_GET_IDLE, reportID, 0, iface, 0x0001, 0x0001, dataptr, NULL)); } -uint8_t HID::SetIdle(uint8_t iface, uint8_t reportID, uint8_t duration) { +uint8_t USBHID::SetIdle(uint8_t iface, uint8_t reportID, uint8_t duration) { return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_OUT, HID_REQUEST_SET_IDLE, reportID, duration, iface, 0x0000, 0x0000, NULL, NULL)); } -uint8_t HID::SetProtocol(uint8_t iface, uint8_t protocol) { +uint8_t USBHID::SetProtocol(uint8_t iface, uint8_t protocol) { return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_OUT, HID_REQUEST_SET_PROTOCOL, protocol, 0x00, iface, 0x0000, 0x0000, NULL, NULL)); } -uint8_t HID::GetProtocol(uint8_t iface, uint8_t* dataptr) { +uint8_t USBHID::GetProtocol(uint8_t iface, uint8_t* dataptr) { return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HID_IN, HID_REQUEST_GET_PROTOCOL, 0x00, 0x00, iface, 0x0001, 0x0001, dataptr, NULL)); } -void HID::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) { +void USBHID::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) { Notify(PSTR("Endpoint descriptor:"), 0x80); Notify(PSTR("\r\nLength:\t\t"), 0x80); D_PrintHex (ep_ptr->bLength, 0x80); @@ -87,7 +87,7 @@ void HID::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) { D_PrintHex (ep_ptr->bInterval, 0x80); } -void HID::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) { +void USBHID::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) { Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"), 0x80); Notify(PSTR("bDescLength:\t\t"), 0x80); D_PrintHex (pDesc->bLength, 0x80); diff --git a/hid.h b/usbhid.h similarity index 93% rename from hid.h rename to usbhid.h index 72942ebc..feca84db 100644 --- a/hid.h +++ b/usbhid.h @@ -14,8 +14,8 @@ Circuits At Home, LTD Web : http://www.circuitsathome.com e-mail : support@circuitsathome.com */ -#if !defined(__HID_H__) -#define __HID_H__ +#if !defined(__USBHID_H__) +#define __USBHID_H__ #include "Usb.h" #include "hidusagestr.h" @@ -79,7 +79,7 @@ e-mail : support@circuitsathome.com #define HID_DESRIPTOR_PHY 0x23 /* Protocol Selection */ -#define HID_BOOT_PROTOCOL 0x00 +#define USB_HID_BOOT_PROTOCOL 0x00 #define HID_RPT_PROTOCOL 0x01 /* HID Interface Class Code */ @@ -89,9 +89,9 @@ e-mail : support@circuitsathome.com #define HID_BOOT_INTF_SUBCLASS 0x01 /* HID Interface Class Protocol Codes */ -#define HID_PROTOCOL_NONE 0x00 -#define HID_PROTOCOL_KEYBOARD 0x01 -#define HID_PROTOCOL_MOUSE 0x02 +#define USB_HID_PROTOCOL_NONE 0x00 +#define USB_HID_PROTOCOL_KEYBOARD 0x01 +#define USB_HID_PROTOCOL_MOUSE 0x02 #define HID_ITEM_TYPE_MAIN 0 #define HID_ITEM_TYPE_GLOBAL 1 @@ -133,14 +133,14 @@ struct MainItemIOFeature { uint8_t bmIsVolatileOrNonVolatile : 1; }; -class HID; +class USBHID; class HIDReportParser { public: - virtual void Parse(HID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) = 0; + virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) = 0; }; -class HID : public USBDeviceConfig, public UsbConfigXtracter { +class USBHID : public USBDeviceConfig, public UsbConfigXtracter { protected: USB *pUsb; // USB class instance pointer uint8_t bAddress; // address @@ -162,7 +162,7 @@ protected: public: - HID(USB *pusb) : pUsb(pusb) { + USBHID(USB *pusb) : pUsb(pusb) { }; const USB* GetUsb() { @@ -185,4 +185,4 @@ public: uint8_t SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr); }; -#endif // __HID_H__ +#endif // __USBHID_H__ From 627c0ebc777c43ea452eb5508a9c5372e2382cda Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 13 Jan 2016 17:50:10 +0100 Subject: [PATCH 111/220] Store rumble value in local buffer, so the rumble is not affected when setting the LEDs Fixes #186 --- PS3BT.cpp | 25 ++++++++++++++----------- PS3USB.cpp | 25 ++++++++++++++----------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index ab5a8ed5..cf1670bb 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -528,12 +528,13 @@ void PS3BT::setAllOff() { } void PS3BT::setRumbleOff() { - HIDBuffer[3] = 0x00; - HIDBuffer[4] = 0x00; - HIDBuffer[5] = 0x00; - HIDBuffer[6] = 0x00; - - HID_Command(HIDBuffer, HID_BUFFERSIZE); + uint8_t rumbleBuf[HID_BUFFERSIZE]; + memcpy(rumbleBuf, HIDBuffer, HID_BUFFERSIZE); + rumbleBuf[3] = 0x00; + rumbleBuf[4] = 0x00; + rumbleBuf[5] = 0x00; + rumbleBuf[6] = 0x00; + HID_Command(rumbleBuf, HID_BUFFERSIZE); } void PS3BT::setRumbleOn(RumbleEnum mode) { @@ -546,11 +547,13 @@ void PS3BT::setRumbleOn(RumbleEnum mode) { } void PS3BT::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) { - HIDBuffer[3] = rightDuration; - HIDBuffer[4] = rightPower; - HIDBuffer[5] = leftDuration; - HIDBuffer[6] = leftPower; - HID_Command(HIDBuffer, HID_BUFFERSIZE); + uint8_t rumbleBuf[HID_BUFFERSIZE]; + memcpy(rumbleBuf, HIDBuffer, HID_BUFFERSIZE); + rumbleBuf[3] = rightDuration; + rumbleBuf[4] = rightPower; + rumbleBuf[5] = leftDuration; + rumbleBuf[6] = leftPower; + HID_Command(rumbleBuf, HID_BUFFERSIZE); } void PS3BT::setLedRaw(uint8_t value) { diff --git a/PS3USB.cpp b/PS3USB.cpp index f247cc91..c263613a 100755 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -408,12 +408,13 @@ void PS3USB::setAllOff() { } void PS3USB::setRumbleOff() { - writeBuf[1] = 0x00; - writeBuf[2] = 0x00; // Low mode off - writeBuf[3] = 0x00; - writeBuf[4] = 0x00; // High mode off - - PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE); + uint8_t rumbleBuf[EP_MAXPKTSIZE]; + memcpy(rumbleBuf, writeBuf, EP_MAXPKTSIZE); + rumbleBuf[1] = 0x00; + rumbleBuf[2] = 0x00; // Low mode off + rumbleBuf[3] = 0x00; + rumbleBuf[4] = 0x00; // High mode off + PS3_Command(rumbleBuf, PS3_REPORT_BUFFER_SIZE); } void PS3USB::setRumbleOn(RumbleEnum mode) { @@ -428,11 +429,13 @@ void PS3USB::setRumbleOn(RumbleEnum mode) { } void PS3USB::setRumbleOn(uint8_t rightDuration, uint8_t rightPower, uint8_t leftDuration, uint8_t leftPower) { - writeBuf[1] = rightDuration; - writeBuf[2] = rightPower; - writeBuf[3] = leftDuration; - writeBuf[4] = leftPower; - PS3_Command(writeBuf, PS3_REPORT_BUFFER_SIZE); + uint8_t rumbleBuf[EP_MAXPKTSIZE]; + memcpy(rumbleBuf, writeBuf, EP_MAXPKTSIZE); + rumbleBuf[1] = rightDuration; + rumbleBuf[2] = rightPower; + rumbleBuf[3] = leftDuration; + rumbleBuf[4] = leftPower; + PS3_Command(rumbleBuf, PS3_REPORT_BUFFER_SIZE); } void PS3USB::setLedRaw(uint8_t value) { From b9220a90e6d5df5211079d9f40174af2c8b3cf52 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 20 Jan 2016 01:07:26 +0100 Subject: [PATCH 112/220] Updated PS3BT example, so it demonstrates rumble functionality --- examples/Bluetooth/PS3BT/PS3BT.ino | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index b8967344..610269bb 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -21,8 +21,7 @@ BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so PS3BT PS3(&Btd); // This will just create the instance //PS3BT PS3(&Btd, 0x00, 0x15, 0x83, 0x3D, 0x0A, 0x57); // This will also store the bluetooth address - this can be obtained from the dongle when running the sketch -bool printTemperature; -bool printAngle; +bool printTemperature, printAngle; void setup() { Serial.begin(115200); @@ -61,15 +60,20 @@ void loop() { Serial.print(PS3.getAnalogButton(R2)); } } + if (PS3.getButtonClick(PS)) { Serial.print(F("\r\nPS")); PS3.disconnect(); } else { - if (PS3.getButtonClick(TRIANGLE)) + if (PS3.getButtonClick(TRIANGLE)) { Serial.print(F("\r\nTraingle")); - if (PS3.getButtonClick(CIRCLE)) + PS3.setRumbleOn(RumbleLow); + } + if (PS3.getButtonClick(CIRCLE)) { Serial.print(F("\r\nCircle")); + PS3.setRumbleOn(RumbleHigh); + } if (PS3.getButtonClick(CROSS)) Serial.print(F("\r\nCross")); if (PS3.getButtonClick(SQUARE)) From 9eed52026bae1b79af773e15910009973695e18e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 20 Jan 2016 14:59:16 +0100 Subject: [PATCH 113/220] There is no reason to cast implicit to HIDReportParser, as the classes already inherits it --- examples/Bluetooth/BTHID/BTHID.ino | 4 ++-- examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino | 2 +- .../HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino | 8 ++++---- examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino | 2 +- examples/adk/adk_barcode/adk_barcode.ino | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/Bluetooth/BTHID/BTHID.ino b/examples/Bluetooth/BTHID/BTHID.ino index d0504012..33ee96c5 100644 --- a/examples/Bluetooth/BTHID/BTHID.ino +++ b/examples/Bluetooth/BTHID/BTHID.ino @@ -40,8 +40,8 @@ void setup() { while (1); // Halt } - bthid.SetReportParser(KEYBOARD_PARSER_ID, (HIDReportParser*)&keyboardPrs); - bthid.SetReportParser(MOUSE_PARSER_ID, (HIDReportParser*)&mousePrs); + bthid.SetReportParser(KEYBOARD_PARSER_ID, &keyboardPrs); + bthid.SetReportParser(MOUSE_PARSER_ID, &mousePrs); // If "Boot Protocol Mode" does not work, then try "Report Protocol Mode" // If that does not work either, then uncomment PRINTREPORT in BTHID.cpp to see the raw report diff --git a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino index 9667bfbc..d7f7d60d 100644 --- a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino +++ b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino @@ -119,7 +119,7 @@ void setup() next_time = millis() + 5000; - HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs); + HidKeyboard.SetReportParser(0, &Prs); } void loop() diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino index a4ffe25c..95963444 100644 --- a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -165,10 +165,10 @@ void setup() //next_time = millis() + 5000; - HidComposite.SetReportParser(0, (HIDReportParser*)&KbdPrs); - HidComposite.SetReportParser(1, (HIDReportParser*)&MousePrs); - HidKeyboard.SetReportParser(0, (HIDReportParser*)&KbdPrs); - HidMouse.SetReportParser(0, (HIDReportParser*)&MousePrs); + HidComposite.SetReportParser(0, &KbdPrs); + HidComposite.SetReportParser(1, &MousePrs); + HidKeyboard.SetReportParser(0, &KbdPrs); + HidMouse.SetReportParser(0, &MousePrs); } void loop() diff --git a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino index 03389959..9816bcb5 100644 --- a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino +++ b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino @@ -73,7 +73,7 @@ void setup() next_time = millis() + 5000; - HidMouse.SetReportParser(0,(HIDReportParser*)&Prs); + HidMouse.SetReportParser(0, &Prs); } void loop() diff --git a/examples/adk/adk_barcode/adk_barcode.ino b/examples/adk/adk_barcode/adk_barcode.ino index b498ef93..e671c661 100644 --- a/examples/adk/adk_barcode/adk_barcode.ino +++ b/examples/adk/adk_barcode/adk_barcode.ino @@ -80,7 +80,7 @@ void setup() while(1); //halt }//if (Usb.Init() == -1... - HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs); + HidKeyboard.SetReportParser(0, &Prs); delay( 200 ); } From e9c28d762d81b639492fcbfc8c212c57aaf530fa Mon Sep 17 00:00:00 2001 From: "Jose A. Jimenez" Date: Sun, 7 Feb 2016 22:32:08 +0100 Subject: [PATCH 114/220] Added flag bRptProtoEnable to HIDBoot() constructor. The flag defaults to false in order to maintain current behavior (Boot Protocol). If flag is the to true, HIDBoot() will enable the Report Protocol. This modification is very useful for communication with HID devices with the full, richer, Report Protocol. --- hidboot.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hidboot.h b/hidboot.h index 27fda78d..7932efea 100644 --- a/hidboot.h +++ b/hidboot.h @@ -210,6 +210,7 @@ class HIDBoot : public USBHID //public USBDeviceConfig, public UsbConfigXtracter uint32_t qNextPollTime; // next poll time bool bPollEnable; // poll enable flag uint8_t bInterval; // largest interval + bool bRptProtoEnable; // Report Protocol enable flag void Initialize(); @@ -218,7 +219,7 @@ class HIDBoot : public USBHID //public USBDeviceConfig, public UsbConfigXtracter }; public: - HIDBoot(USB *p); + HIDBoot(USB *p, bool bRptProtoEnable=false); virtual bool SetReportParser(uint8_t id, HIDReportParser *prs) { pRptParser[id] = prs; @@ -252,10 +253,11 @@ public: }; template -HIDBoot::HIDBoot(USB *p) : +HIDBoot::HIDBoot(USB *p, bool bRptProtoEnable) : USBHID(p), qNextPollTime(0), -bPollEnable(false) { +bPollEnable(false), +bRptProtoEnable(bRptProtoEnable) { Initialize(); for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) { @@ -456,7 +458,7 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed // Yes, mouse wants SetProtocol and SetIdle too! for(uint8_t i = 0; i < epMUL(BOOT_PROTOCOL); i++) { USBTRACE2("\r\nInterface:", i); - rcode = SetProtocol(i, USB_HID_BOOT_PROTOCOL); + rcode = SetProtocol(i, bRptProtoEnable ? HID_RPT_PROTOCOL : HID_BOOT_PROTOCOL); if(rcode) goto FailSetProtocol; USBTRACE2("PROTOCOL SET HID_BOOT rcode:", rcode); rcode = SetIdle(i, 0, 0); From 0cdde7afe95651e642ac50909824215a370c9eca Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 9 Feb 2016 12:10:12 +0100 Subject: [PATCH 115/220] Check status byte in HCI Authentication Complete Event If paring fails simply disconnect --- BTD.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index b3b41a7f..05ef4901 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -589,16 +589,25 @@ void BTD::HCI_event_task() { break; case EV_AUTHENTICATION_COMPLETE: - if(pairWithWii && !connectToWii) { + if(!hcibuf[2]) { // Check if paring was successful + if(pairWithWii && !connectToWii) { #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nPairing successful with Wiimote"), 0x80); + Notify(PSTR("\r\nPairing successful with Wiimote"), 0x80); #endif - connectToWii = true; // Used to indicate to the Wii service, that it should connect to this device - } else if(pairWithHIDDevice && !connectToHIDDevice) { + connectToWii = true; // Used to indicate to the Wii service, that it should connect to this device + } else if(pairWithHIDDevice && !connectToHIDDevice) { #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nPairing successful with HID device"), 0x80); + Notify(PSTR("\r\nPairing successful with HID device"), 0x80); #endif - connectToHIDDevice = true; // Used to indicate to the BTHID service, that it should connect to this device + connectToHIDDevice = true; // Used to indicate to the BTHID service, that it should connect to this device + } + } else { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nParing Failed: "), 0x80); + D_PrintHex (hcibuf[2], 0x80); +#endif + hci_disconnect(hci_handle); + hci_state = HCI_DISCONNECT_STATE; } break; /* We will just ignore the following events */ From 0f80087ee76a73bd5295601793fc6b2c924667b3 Mon Sep 17 00:00:00 2001 From: matt-bull Date: Wed, 27 Jan 2016 20:59:37 -0600 Subject: [PATCH 116/220] Have PS3.printStatusString() print to a new line each time it is called. --- PS3BT.cpp | 8 ++++---- PS3USB.cpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index cf1670bb..742591fa 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -158,9 +158,9 @@ bool PS3BT::getStatus(StatusEnum c) { } void PS3BT::printStatusString() { - char statusOutput[100]; // Max string length plus null character + char statusOutput[102]; // Max string length plus null character if(PS3Connected || PS3NavigationConnected) { - strcpy_P(statusOutput, PSTR("ConnectionStatus: ")); + strcpy_P(statusOutput, PSTR("\r\nConnectionStatus: ")); if(getStatus(Plugged)) strcat_P(statusOutput, PSTR("Plugged")); else if(getStatus(Unplugged)) strcat_P(statusOutput, PSTR("Unplugged")); @@ -185,7 +185,7 @@ void PS3BT::printStatusString() { else if(getStatus(Bluetooth)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is off")); else strcat_P(statusOutput, PSTR("Error")); } else if(PS3MoveConnected) { - strcpy_P(statusOutput, PSTR("PowerRating: ")); + strcpy_P(statusOutput, PSTR("\r\nPowerRating: ")); if(getStatus(MoveCharging)) strcat_P(statusOutput, PSTR("Charging")); else if(getStatus(MoveNotCharging)) strcat_P(statusOutput, PSTR("Not Charging")); @@ -196,7 +196,7 @@ void PS3BT::printStatusString() { else if(getStatus(MoveFull)) strcat_P(statusOutput, PSTR("Full")); else strcat_P(statusOutput, PSTR("Error")); } else - strcpy_P(statusOutput, PSTR("Error")); + strcpy_P(statusOutput, PSTR("\r\nError")); USB_HOST_SERIAL.write(statusOutput); } diff --git a/PS3USB.cpp b/PS3USB.cpp index c263613a..cfa5f978 100755 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -362,9 +362,9 @@ bool PS3USB::getStatus(StatusEnum c) { } void PS3USB::printStatusString() { - char statusOutput[100]; // Max string length plus null character + char statusOutput[102]; // Max string length plus null character if(PS3Connected || PS3NavigationConnected) { - strcpy_P(statusOutput, PSTR("ConnectionStatus: ")); + strcpy_P(statusOutput, PSTR("\r\nConnectionStatus: ")); if(getStatus(Plugged)) strcat_P(statusOutput, PSTR("Plugged")); else if(getStatus(Unplugged)) strcat_P(statusOutput, PSTR("Unplugged")); @@ -389,7 +389,7 @@ void PS3USB::printStatusString() { else if(getStatus(Bluetooth)) strcat_P(statusOutput, PSTR("Bluetooth - Rumble is off")); else strcat_P(statusOutput, PSTR("Error")); } else - strcpy_P(statusOutput, PSTR("Error")); + strcpy_P(statusOutput, PSTR("\r\nError")); USB_HOST_SERIAL.write(statusOutput); } From a948b7afe5266331d937134d980d4aa91fc8cca0 Mon Sep 17 00:00:00 2001 From: "Jose A. Jimenez" Date: Tue, 16 Feb 2016 12:20:39 +0100 Subject: [PATCH 117/220] Some corrections as agreed with @Lauszus. Added flag bRptProtoEnable to HIDBoot() constructor. The flag defaults to false in order to maintain current behavior (Boot Protocol). If flag is the to true, HIDBoot() will enable the Report Protocol. This modification is very useful for communication with HID devices with the full, richer, Report Protocol. --- hidboot.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hidboot.h b/hidboot.h index 7932efea..4d0b0b26 100644 --- a/hidboot.h +++ b/hidboot.h @@ -219,7 +219,7 @@ class HIDBoot : public USBHID //public USBDeviceConfig, public UsbConfigXtracter }; public: - HIDBoot(USB *p, bool bRptProtoEnable=false); + HIDBoot(USB *p, bool bRptProtoEnable = false); virtual bool SetReportParser(uint8_t id, HIDReportParser *prs) { pRptParser[id] = prs; @@ -253,7 +253,7 @@ public: }; template -HIDBoot::HIDBoot(USB *p, bool bRptProtoEnable) : +HIDBoot::HIDBoot(USB *p, bool bRptProtoEnable/* = false*/) : USBHID(p), qNextPollTime(0), bPollEnable(false), @@ -458,7 +458,7 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed // Yes, mouse wants SetProtocol and SetIdle too! for(uint8_t i = 0; i < epMUL(BOOT_PROTOCOL); i++) { USBTRACE2("\r\nInterface:", i); - rcode = SetProtocol(i, bRptProtoEnable ? HID_RPT_PROTOCOL : HID_BOOT_PROTOCOL); + rcode = SetProtocol(i, bRptProtoEnable ? HID_RPT_PROTOCOL : USB_HID_BOOT_PROTOCOL); if(rcode) goto FailSetProtocol; USBTRACE2("PROTOCOL SET HID_BOOT rcode:", rcode); rcode = SetIdle(i, 0, 0); From c0f0ae4cb92470ddda9973bd12c7fee282f6c978 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 20 Feb 2016 02:25:10 +0100 Subject: [PATCH 118/220] Initial commit for the SteelSeries SRW-S1 Steering Wheel --- examples/HID/SRWS1/SRWS1.cpp | 140 +++++++++++++++++++++++++++++++++++ examples/HID/SRWS1/SRWS1.h | 82 ++++++++++++++++++++ examples/HID/SRWS1/SRWS1.ino | 57 ++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 examples/HID/SRWS1/SRWS1.cpp create mode 100644 examples/HID/SRWS1/SRWS1.h create mode 100644 examples/HID/SRWS1/SRWS1.ino diff --git a/examples/HID/SRWS1/SRWS1.cpp b/examples/HID/SRWS1/SRWS1.cpp new file mode 100644 index 00000000..460404c7 --- /dev/null +++ b/examples/HID/SRWS1/SRWS1.cpp @@ -0,0 +1,140 @@ +/* Copyright (C) 2016 Kristian Lauszus, TKJ Electronics. All rights reserved. + + This software may be distributed and modified under the terms of the GNU + General Public License version 2 (GPL2) as published by the Free Software + Foundation and appearing in the file GPL2.TXT included in the packaging of + this file. Please note that GPL2 Section 2[b] requires that all works based + on this software must also be made publicly available under the terms of + the GPL2 ("Copyleft"). + + Contact information + ------------------- + + Kristian Lauszus, TKJ Electronics + Web : http://www.tkjelectronics.com + e-mail : kristianl@tkjelectronics.com + */ + +#include "SRWS1.h" + +enum DPADEnum { + DPAD_UP = 0x0, + DPAD_UP_RIGHT = 0x1, + DPAD_RIGHT = 0x2, + DPAD_RIGHT_DOWN = 0x3, + DPAD_DOWN = 0x4, + DPAD_DOWN_LEFT = 0x5, + DPAD_LEFT = 0x6, + DPAD_LEFT_UP = 0x7, + DPAD_OFF = 0xF, +}; + +void SRWS1::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { + if (HIDUniversal::VID != STEELSERIES_VID || HIDUniversal::PID != STEELSERIES_SRWS1_PID) // Make sure the right device is actually connected + return; +#if 0 + if (len && buf) { + Notify(PSTR("\r\n"), 0x80); + for (uint8_t i = 0; i < len; i++) { + D_PrintHex (buf[i], 0x80); + Notify(PSTR(" "), 0x80); + } + } +#else + memcpy(&srws1Data, buf, min(len, sizeof(srws1Data))); + + if (srws1Data.leftTrigger) { + Serial.print(F("L2: ")); + Serial.println(srws1Data.leftTrigger); + } + if (srws1Data.rightTrigger) { + Serial.print(F("R2: ")); + Serial.println(srws1Data.rightTrigger); + } + if (srws1Data.btn.select) { + //Serial.println("Select"); + Serial.println(srws1Data.tilt); + } + + if (srws1Data.btn.back) Serial.println(F("Back")); + if (srws1Data.btn.lookLeft) Serial.println(F("Look Left")); + if (srws1Data.btn.lights) Serial.println(F("Lights")); + if (srws1Data.btn.lookBack) Serial.println(F("Look Back")); + if (srws1Data.btn.rearBrakeBalance) Serial.println(F("R. Brake Balance")); + if (srws1Data.btn.frontBrakeBalance) Serial.println(F("F. Brake Balance")); + if (srws1Data.btn.requestPit) Serial.println(F("Request Pit")); + if (srws1Data.btn.leftGear) Serial.println(F("Left Gear")); + + if (srws1Data.btn.camera) Serial.println(F("Camera")); + if (srws1Data.btn.lookRight) Serial.println(F("Look right")); + if (srws1Data.btn.boost) Serial.println(F("Boost")); + if (srws1Data.btn.horn) Serial.println(F("Horn")); + if (srws1Data.btn.hud) Serial.println(F("HUD")); + if (srws1Data.btn.launchControl) Serial.println(F("Launch Control")); + if (srws1Data.btn.speedLimiter) Serial.println(F("Speed Limiter")); + if (srws1Data.btn.rightGear) Serial.println(F("Right gear")); + + static SRWS1DataButtons buttonClickState, oldButtonState; + if (srws1Data.btn.val != oldButtonState.val) { // Check if anything has changed + buttonClickState.val = srws1Data.btn.val & ~oldButtonState.val; // Update click state variable + oldButtonState.val = srws1Data.btn.val; + } + + if (buttonClickState.lights) { + buttonClickState.lights = 0; // Clear event + static uint16_t leds = 0; + leds = leds << 1 | 1; + if (leds == 0xFFFF) + leds = 0; // Clear LEDs variable + setLeds(leds); // Note: disable the strobe light effect + } + + if (srws1Data.assists) Serial.println(srws1Data.assists); + if (srws1Data.steeringSensitivity) Serial.println(srws1Data.steeringSensitivity); + if (srws1Data.assistValues) Serial.println(srws1Data.assistValues); + + switch (srws1Data.btn.dpad) { + case DPAD_UP: + Serial.println(F("Up")); + break; + case DPAD_UP_RIGHT: + Serial.println(F("UP & RIGHT")); + break; + case DPAD_RIGHT: + Serial.println(F("Right")); + break; + case DPAD_RIGHT_DOWN: + Serial.println(F("Right & down")); + break; + case DPAD_DOWN: + Serial.println(F("Down")); + break; + case DPAD_DOWN_LEFT: + Serial.println(F("Down & left")); + break; + case DPAD_LEFT: + Serial.println(F("Left")); + break; + case DPAD_LEFT_UP: + Serial.println(F("Left & up")); + break; + case DPAD_OFF: + break; + default: + Serial.print(F("Unknown state: ")); + D_PrintHex (srws1Data.btn.dpad, 0x80); + Serial.println(); + break; + } +#endif +} + +// See: https://github.com/torvalds/linux/blob/master/drivers/hid/hid-steelseries.c +void SRWS1::setLeds(uint16_t leds) { + uint8_t buf[3]; + buf[0] = 0x40; // Report ID + buf[1] = leds & 0xFF; + buf[2] = leds >> 8; + pUsb->outTransfer(bAddress, epInfo[ hidInterfaces[0].epIndex[epInterruptOutIndex] ].epAddr, sizeof(buf), buf); +} + diff --git a/examples/HID/SRWS1/SRWS1.h b/examples/HID/SRWS1/SRWS1.h new file mode 100644 index 00000000..fb47fbb5 --- /dev/null +++ b/examples/HID/SRWS1/SRWS1.h @@ -0,0 +1,82 @@ +/* Copyright (C) 2016 Kristian Lauszus, TKJ Electronics. All rights reserved. + + This software may be distributed and modified under the terms of the GNU + General Public License version 2 (GPL2) as published by the Free Software + Foundation and appearing in the file GPL2.TXT included in the packaging of + this file. Please note that GPL2 Section 2[b] requires that all works based + on this software must also be made publicly available under the terms of + the GPL2 ("Copyleft"). + + Contact information + ------------------- + + Kristian Lauszus, TKJ Electronics + Web : http://www.tkjelectronics.com + e-mail : kristianl@tkjelectronics.com + */ + +#ifndef __srws1_h__ +#define __srws1_h__ + +#include + +#define STEELSERIES_VID 0x1038 +#define STEELSERIES_SRWS1_PID 0x1410 + +union SRWS1DataButtons { + struct { + uint8_t dpad : 4; + uint8_t dummy : 3; + uint8_t select : 1; + + uint8_t back : 1; + uint8_t lookLeft : 1; + uint8_t lights : 1; + uint8_t lookBack : 1; + uint8_t rearBrakeBalance : 1; + uint8_t frontBrakeBalance : 1; + uint8_t requestPit : 1; + uint8_t leftGear : 1; + + uint8_t camera : 1; + uint8_t lookRight : 1; + uint8_t boost : 1; + uint8_t horn : 1; + uint8_t hud : 1; + uint8_t launchControl : 1; + uint8_t speedLimiter : 1; + uint8_t rightGear : 1; + } __attribute__((packed)); + uint32_t val : 24; +} __attribute__((packed)); + +struct SRWS1Data { + int16_t tilt; // Range [-1800:1800] + uint16_t rightTrigger : 12; // Range [0:1023] i.e. only 10 bits + uint16_t leftTrigger : 12; // Range [0:1023] i.e. only 10 bits + SRWS1DataButtons btn; + uint8_t assists : 4; + uint8_t steeringSensitivity : 4; + uint8_t assistValues : 4; +} __attribute__((packed)); + +class SRWS1 : public HIDUniversal { +public: + SRWS1(USB *p) : HIDUniversal(p) {}; + bool connected() { + return HIDUniversal::isReady() && HIDUniversal::VID == STEELSERIES_VID && HIDUniversal::PID == STEELSERIES_SRWS1_PID; + }; + void setLeds(uint16_t leds); + +private: + void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDUniversal library + uint8_t OnInitSuccessful() { // Called by the HIDUniversal library on success + if (HIDUniversal::VID != STEELSERIES_VID || HIDUniversal::PID != STEELSERIES_SRWS1_PID) // Make sure the right device is actually connected + return 1; + setLeds(0); + return 0; + }; + SRWS1Data srws1Data; +}; + +#endif diff --git a/examples/HID/SRWS1/SRWS1.ino b/examples/HID/SRWS1/SRWS1.ino new file mode 100644 index 00000000..c1a3fe6a --- /dev/null +++ b/examples/HID/SRWS1/SRWS1.ino @@ -0,0 +1,57 @@ +/* + Example sketch for the SteelSeries SRW-S1 Steering Wheel - developed by Kristian Lauszus + For more information visit my blog: http://blog.tkjelectronics.dk/ or + send me an e-mail: kristianl@tkjelectronics.com + */ + +#include +#include "SRWS1.h" + +USB Usb; +SRWS1 srw1(&Usb); + +void setup() { + Serial.begin(115200); +#if !defined(__MIPSEL__) + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection +#endif + if (Usb.Init() == -1) { + Serial.print(F("\r\nOSC did not start")); + while (1); // Halt + } + Serial.println(F("\r\nSteelSeries SRW-S1 Steering Wheel example started")); +} + +void loop() { + Usb.Task(); + + if (srw1.connected()) { +#if 1 // Set to 1 in order to show a crazy strobe light effect + static uint32_t timer; + if (millis() - timer > 12) { + timer = millis(); // Reset timer + static uint16_t leds = 0; + + /*D_PrintHex (leds, 0x80); + Serial.println();*/ + srw1.setLeds(leds); // Update LEDs + + static bool dirUp = true; + if (dirUp) { + leds <<= 1; + if (leds == 0x8000) // All are actually turned off, as there is only 15 LEDs + dirUp = false; // If we have reached the end i.e. all LEDs are off, then change direction + if (!(leds & 0x8000)) // If last bit is not set set the lowest bit + leds |= 1; // Set lowest bit + } else { + leds >>= 1; + if (leds == 0) // Check if all LEDs are off + dirUp = true; // If all LEDs are off, then repeat the sequence + if (!(leds & 0x1)) // If last bit is not set set the lowest bit + leds |= 1 << 15; // Set top bit + } + } +#endif + } +} + From f05f791841b20ece897c1ffdfd729e6ec46e4558 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 25 Feb 2016 17:48:18 +0100 Subject: [PATCH 119/220] Show tilt using LEDs by default --- examples/HID/SRWS1/SRWS1.h | 2 +- examples/HID/SRWS1/SRWS1.ino | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/HID/SRWS1/SRWS1.h b/examples/HID/SRWS1/SRWS1.h index fb47fbb5..8222bdee 100644 --- a/examples/HID/SRWS1/SRWS1.h +++ b/examples/HID/SRWS1/SRWS1.h @@ -67,6 +67,7 @@ public: return HIDUniversal::isReady() && HIDUniversal::VID == STEELSERIES_VID && HIDUniversal::PID == STEELSERIES_SRWS1_PID; }; void setLeds(uint16_t leds); + SRWS1Data srws1Data; private: void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDUniversal library @@ -76,7 +77,6 @@ private: setLeds(0); return 0; }; - SRWS1Data srws1Data; }; #endif diff --git a/examples/HID/SRWS1/SRWS1.ino b/examples/HID/SRWS1/SRWS1.ino index c1a3fe6a..646f3df2 100644 --- a/examples/HID/SRWS1/SRWS1.ino +++ b/examples/HID/SRWS1/SRWS1.ino @@ -26,12 +26,12 @@ void loop() { Usb.Task(); if (srw1.connected()) { -#if 1 // Set to 1 in order to show a crazy strobe light effect +#if 0 // Set to 1 in order to show a crazy strobe light effect static uint32_t timer; if (millis() - timer > 12) { timer = millis(); // Reset timer - static uint16_t leds = 0; + static uint16_t leds = 0; /*D_PrintHex (leds, 0x80); Serial.println();*/ srw1.setLeds(leds); // Update LEDs @@ -41,16 +41,18 @@ void loop() { leds <<= 1; if (leds == 0x8000) // All are actually turned off, as there is only 15 LEDs dirUp = false; // If we have reached the end i.e. all LEDs are off, then change direction - if (!(leds & 0x8000)) // If last bit is not set set the lowest bit + else if (!(leds & 0x8000)) // If last bit is not set set the lowest bit leds |= 1; // Set lowest bit } else { leds >>= 1; if (leds == 0) // Check if all LEDs are off dirUp = true; // If all LEDs are off, then repeat the sequence - if (!(leds & 0x1)) // If last bit is not set set the lowest bit + else if (!(leds & 0x1)) // If last bit is not set set the lowest bit leds |= 1 << 15; // Set top bit } } +#else + srw1.setLeds(1 << map(srw1.srws1Data.tilt, -1800, 1800, 0, 14)); // Turn on a LED according to tilt value #endif } } From 267f330ed74cfd5be09a0cb1223334f5eba69a63 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Fri, 26 Feb 2016 01:02:39 +0100 Subject: [PATCH 120/220] Put DPADEnum into the source file, so it does not conflict with the one in the SRWS1 driver --- PS4Parser.cpp | 37 +++++++++++++++++++++++++++++++++++++ PS4Parser.h | 36 +----------------------------------- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/PS4Parser.cpp b/PS4Parser.cpp index ca6adce4..1e6bf207 100644 --- a/PS4Parser.cpp +++ b/PS4Parser.cpp @@ -17,6 +17,18 @@ #include "PS4Parser.h" +enum DPADEnum { + DPAD_UP = 0x0, + DPAD_UP_RIGHT = 0x1, + DPAD_RIGHT = 0x2, + DPAD_RIGHT_DOWN = 0x3, + DPAD_DOWN = 0x4, + DPAD_DOWN_LEFT = 0x5, + DPAD_LEFT = 0x6, + DPAD_LEFT_UP = 0x7, + DPAD_OFF = 0x8, +}; + // To enable serial debugging see "settings.h" //#define PRINTREPORT // Uncomment to print the report send by the PS4 Controller @@ -114,3 +126,28 @@ void PS4Parser::Parse(uint8_t len, uint8_t *buf) { if (ps4Output.reportChanged) sendOutputReport(&ps4Output); // Send output report } + +void PS4Parser::Reset() { + uint8_t i; + for (i = 0; i < sizeof(ps4Data.hatValue); i++) + ps4Data.hatValue[i] = 127; // Center value + ps4Data.btn.val = 0; + oldButtonState.val = 0; + for (i = 0; i < sizeof(ps4Data.trigger); i++) + ps4Data.trigger[i] = 0; + for (i = 0; i < sizeof(ps4Data.xy)/sizeof(ps4Data.xy[0]); i++) { + for (uint8_t j = 0; j < sizeof(ps4Data.xy[0].finger)/sizeof(ps4Data.xy[0].finger[0]); j++) + ps4Data.xy[i].finger[j].touching = 1; // The bit is cleared if the finger is touching the touchpad + } + + ps4Data.btn.dpad = DPAD_OFF; + oldButtonState.dpad = DPAD_OFF; + buttonClickState.dpad = 0; + oldDpad = 0; + + ps4Output.bigRumble = ps4Output.smallRumble = 0; + ps4Output.r = ps4Output.g = ps4Output.b = 0; + ps4Output.flashOn = ps4Output.flashOff = 0; + ps4Output.reportChanged = false; +}; + diff --git a/PS4Parser.h b/PS4Parser.h index 5af13e80..0ee8851e 100644 --- a/PS4Parser.h +++ b/PS4Parser.h @@ -120,18 +120,6 @@ struct PS4Output { bool reportChanged; // The data is send when data is received from the controller } __attribute__((packed)); -enum DPADEnum { - DPAD_UP = 0x0, - DPAD_UP_RIGHT = 0x1, - DPAD_RIGHT = 0x2, - DPAD_RIGHT_DOWN = 0x3, - DPAD_DOWN = 0x4, - DPAD_DOWN_LEFT = 0x5, - DPAD_LEFT = 0x6, - DPAD_LEFT_UP = 0x7, - DPAD_OFF = 0x8, -}; - /** This class parses all the data sent by the PS4 controller */ class PS4Parser { public: @@ -366,29 +354,7 @@ protected: void Parse(uint8_t len, uint8_t *buf); /** Used to reset the different buffers to their default values */ - void Reset() { - uint8_t i; - for (i = 0; i < sizeof(ps4Data.hatValue); i++) - ps4Data.hatValue[i] = 127; // Center value - ps4Data.btn.val = 0; - oldButtonState.val = 0; - for (i = 0; i < sizeof(ps4Data.trigger); i++) - ps4Data.trigger[i] = 0; - for (i = 0; i < sizeof(ps4Data.xy)/sizeof(ps4Data.xy[0]); i++) { - for (uint8_t j = 0; j < sizeof(ps4Data.xy[0].finger)/sizeof(ps4Data.xy[0].finger[0]); j++) - ps4Data.xy[i].finger[j].touching = 1; // The bit is cleared if the finger is touching the touchpad - } - - ps4Data.btn.dpad = DPAD_OFF; - oldButtonState.dpad = DPAD_OFF; - buttonClickState.dpad = 0; - oldDpad = 0; - - ps4Output.bigRumble = ps4Output.smallRumble = 0; - ps4Output.r = ps4Output.g = ps4Output.b = 0; - ps4Output.flashOn = ps4Output.flashOff = 0; - ps4Output.reportChanged = false; - }; + void Reset(); /** * Send the output to the PS4 controller. This is implemented in PS4BT.h and PS4USB.h. From 29c98503d17797ffae1c7b897416b2364728b900 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Fri, 26 Feb 2016 01:13:20 +0100 Subject: [PATCH 121/220] Make button click state public and disable debug printing by default --- examples/HID/SRWS1/SRWS1.cpp | 35 +++++++---------------------------- examples/HID/SRWS1/SRWS1.h | 13 +++++++++++++ 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/examples/HID/SRWS1/SRWS1.cpp b/examples/HID/SRWS1/SRWS1.cpp index 460404c7..fa33a7a0 100644 --- a/examples/HID/SRWS1/SRWS1.cpp +++ b/examples/HID/SRWS1/SRWS1.cpp @@ -17,18 +17,6 @@ #include "SRWS1.h" -enum DPADEnum { - DPAD_UP = 0x0, - DPAD_UP_RIGHT = 0x1, - DPAD_RIGHT = 0x2, - DPAD_RIGHT_DOWN = 0x3, - DPAD_DOWN = 0x4, - DPAD_DOWN_LEFT = 0x5, - DPAD_LEFT = 0x6, - DPAD_LEFT_UP = 0x7, - DPAD_OFF = 0xF, -}; - void SRWS1::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { if (HIDUniversal::VID != STEELSERIES_VID || HIDUniversal::PID != STEELSERIES_SRWS1_PID) // Make sure the right device is actually connected return; @@ -40,9 +28,15 @@ void SRWS1::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) Notify(PSTR(" "), 0x80); } } -#else +#endif memcpy(&srws1Data, buf, min(len, sizeof(srws1Data))); + static SRWS1DataButtons oldButtonState; + if (srws1Data.btn.val != oldButtonState.val) { // Check if anything has changed + buttonClickState.val = srws1Data.btn.val & ~oldButtonState.val; // Update click state variable + oldButtonState.val = srws1Data.btn.val; + } +#if 0 if (srws1Data.leftTrigger) { Serial.print(F("L2: ")); Serial.println(srws1Data.leftTrigger); @@ -74,21 +68,6 @@ void SRWS1::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) if (srws1Data.btn.speedLimiter) Serial.println(F("Speed Limiter")); if (srws1Data.btn.rightGear) Serial.println(F("Right gear")); - static SRWS1DataButtons buttonClickState, oldButtonState; - if (srws1Data.btn.val != oldButtonState.val) { // Check if anything has changed - buttonClickState.val = srws1Data.btn.val & ~oldButtonState.val; // Update click state variable - oldButtonState.val = srws1Data.btn.val; - } - - if (buttonClickState.lights) { - buttonClickState.lights = 0; // Clear event - static uint16_t leds = 0; - leds = leds << 1 | 1; - if (leds == 0xFFFF) - leds = 0; // Clear LEDs variable - setLeds(leds); // Note: disable the strobe light effect - } - if (srws1Data.assists) Serial.println(srws1Data.assists); if (srws1Data.steeringSensitivity) Serial.println(srws1Data.steeringSensitivity); if (srws1Data.assistValues) Serial.println(srws1Data.assistValues); diff --git a/examples/HID/SRWS1/SRWS1.h b/examples/HID/SRWS1/SRWS1.h index 8222bdee..934b1aee 100644 --- a/examples/HID/SRWS1/SRWS1.h +++ b/examples/HID/SRWS1/SRWS1.h @@ -23,6 +23,18 @@ #define STEELSERIES_VID 0x1038 #define STEELSERIES_SRWS1_PID 0x1410 +enum DPADEnum { + DPAD_UP = 0x0, + DPAD_UP_RIGHT = 0x1, + DPAD_RIGHT = 0x2, + DPAD_RIGHT_DOWN = 0x3, + DPAD_DOWN = 0x4, + DPAD_DOWN_LEFT = 0x5, + DPAD_LEFT = 0x6, + DPAD_LEFT_UP = 0x7, + DPAD_OFF = 0xF, +}; + union SRWS1DataButtons { struct { uint8_t dpad : 4; @@ -68,6 +80,7 @@ public: }; void setLeds(uint16_t leds); SRWS1Data srws1Data; + SRWS1DataButtons buttonClickState; private: void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDUniversal library From fb541dc8b9070f567a051bdb35102a56f0bd2ad6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Fri, 26 Feb 2016 01:13:46 +0100 Subject: [PATCH 122/220] Moved SRWS1 library into the root --- examples/HID/SRWS1/SRWS1.cpp => SRWS1.cpp | 0 examples/HID/SRWS1/SRWS1.h => SRWS1.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename examples/HID/SRWS1/SRWS1.cpp => SRWS1.cpp (100%) rename examples/HID/SRWS1/SRWS1.h => SRWS1.h (100%) diff --git a/examples/HID/SRWS1/SRWS1.cpp b/SRWS1.cpp similarity index 100% rename from examples/HID/SRWS1/SRWS1.cpp rename to SRWS1.cpp diff --git a/examples/HID/SRWS1/SRWS1.h b/SRWS1.h similarity index 100% rename from examples/HID/SRWS1/SRWS1.h rename to SRWS1.h From 51cb078fa0579c5afa78c64159d8c55e0d39360f Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Fri, 18 Mar 2016 22:40:10 +0100 Subject: [PATCH 123/220] Exclude specific enum defines and cast The unscoped Enum for the Controller LEDs is colliding with changes in the recent RedBearLab nRF51288 SDK, specifically the PinName enum in the mbed.h header file. As a simple RBL/mBed specific work-around we are now casting the LED enums into the USBH LEDEnum enum. This will potentially break support for controllers on RBL, but restore the ability to compile the project. --- PS3BT.cpp | 2 +- PS3USB.cpp | 2 +- XBOXRECV.cpp | 8 ++++---- XBOXUSB.cpp | 2 +- controllerEnums.h | 3 ++- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index ab5a8ed5..f534ad7b 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -629,6 +629,6 @@ void PS3BT::onInit() { if(PS3MoveConnected) moveSetBulb(Red); else // Dualshock 3 or Navigation controller - setLedOn(LED1); + setLedOn(static_cast(LED1)); } } diff --git a/PS3USB.cpp b/PS3USB.cpp index f247cc91..18b881ca 100755 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -566,6 +566,6 @@ void PS3USB::onInit() { if(PS3MoveConnected) moveSetBulb(Red); else // Dualshock 3 or Navigation controller - setLedOn(LED1); + setLedOn(static_cast(LED1)); } } diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index 39e14ef8..7431fa43 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -572,13 +572,13 @@ void XBOXRECV::onInit(uint8_t controller) { else { LEDEnum led; if(controller == 0) - led = LED1; + led = static_cast(LED1); else if(controller == 1) - led = LED2; + led = static_cast(LED2); else if(controller == 2) - led = LED3; + led = static_cast(LED3); else - led = LED4; + led = static_cast(LED4); setLedOn(led, controller); } } diff --git a/XBOXUSB.cpp b/XBOXUSB.cpp index ce69f82b..6799029d 100644 --- a/XBOXUSB.cpp +++ b/XBOXUSB.cpp @@ -358,5 +358,5 @@ void XBOXUSB::onInit() { if(pFuncOnInit) pFuncOnInit(); // Call the user function else - setLedOn(LED1); + setLedOn(static_cast(LED1)); } diff --git a/controllerEnums.h b/controllerEnums.h index 47fd975e..e51f15ca 100644 --- a/controllerEnums.h +++ b/controllerEnums.h @@ -26,11 +26,12 @@ /** Enum used to turn on the LEDs on the different controllers. */ enum LEDEnum { OFF = 0, +#ifndef RBL_NRF51822 LED1 = 1, LED2 = 2, LED3 = 3, LED4 = 4, - +#endif LED5 = 5, LED6 = 6, LED7 = 7, From 9b829e28b49ebe2c772b72793ce78f3cc18aed7f Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Sat, 16 Jan 2016 19:33:46 +0100 Subject: [PATCH 124/220] Print::write not on RBL It seems like this functionality got removed in the RBL SDK. Add condition for compiler target.. --- SPP.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SPP.h b/SPP.h index 233ac611..bb3027b4 100644 --- a/SPP.h +++ b/SPP.h @@ -120,7 +120,9 @@ public: */ size_t write(const uint8_t* data, size_t size); /** Pull in write(const char *str) from Print */ +#if !defined(RBL_NRF51822) using Print::write; +#endif #else /** * Writes the byte to send to a buffer. The message is send when either send() or after Usb.Task() is called. From 209e73bd72d84e178a26fd00bbdc22dc0a6b15d9 Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Fri, 26 Feb 2016 11:41:18 +0100 Subject: [PATCH 125/220] Add RBL SDK (S130) Headers Add the new SPI Headers and re-direct to the new SPI Interface. --- settings.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/settings.h b/settings.h index 6c1979af..97b46a0b 100644 --- a/settings.h +++ b/settings.h @@ -135,8 +135,13 @@ e-mail : support@circuitsathome.com #define USING_SPI4TEENSY3 0 #endif -#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 +#if ((defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(__ARDUINO_X86__) || ARDUINO >= 10600) && !USING_SPI4TEENSY3 +#include // Use the Arduino SPI library for the Arduino Due, Intel Galileo 1 & 2, Intel Edison or if the SPI library with transaction is available +#endif +#ifdef RBL_NRF51822 +#include +#include +#define SPI SPI_Master #endif #if defined(__PIC32MX__) || defined(__PIC32MZ__) #include <../../../../hardware/pic32/libraries/SPI/SPI.h> // Hack to use the SPI library From 8aeb975fac7f21b199f8de635ffb2ce25af31e0e Mon Sep 17 00:00:00 2001 From: Yuuichi Akagawa Date: Mon, 21 Mar 2016 23:35:40 +0900 Subject: [PATCH 126/220] added MIDI host class driver --- .../USBH_MIDI_dump/USBH_MIDI_dump.ino | 98 ++++ .../USB_MIDI_converter/USB_MIDI_converter.ino | 92 +++ .../USB_MIDI_converter_multi.ino | 100 ++++ .../bidrectional_converter.ino | 110 ++++ .../USBH_MIDI/eVY1_sample/eVY1_sample.ino | 93 +++ usbh_midi.cpp | 550 ++++++++++++++++++ usbh_midi.h | 86 +++ 7 files changed, 1129 insertions(+) create mode 100755 examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino create mode 100755 examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino create mode 100755 examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino create mode 100755 examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino create mode 100755 examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino create mode 100755 usbh_midi.cpp create mode 100755 usbh_midi.h diff --git a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino new file mode 100755 index 00000000..de58166a --- /dev/null +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -0,0 +1,98 @@ +/* + ******************************************************************************* + * USB-MIDI dump utility + * Copyright (C) 2013-2016 Yuuichi Akagawa + * + * for use with USB Host Shield 2.0 from Circuitsathome.com + * https://github.com/felis/USB_Host_Shield_2.0 + * + * This is sample program. Do not expect perfect behavior. + ******************************************************************************* + */ + +#include +#include + +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude +#include +#include +#endif + +USB Usb; +//USBHub Hub(&Usb); +USBH_MIDI Midi(&Usb); + +void MIDI_poll(); +void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); + +boolean bFirst; +uint16_t pid, vid; + +void setup() +{ + bFirst = true; + vid = pid = 0; + Serial.begin(115200); + + if (Usb.Init() == -1) { + while(1); //halt + }//if (Usb.Init() == -1... + delay( 200 ); +} + +void loop() +{ + unsigned long t1; + + Usb.Task(); + t1 = micros(); + if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + { + MIDI_poll(); + } + //delay(1ms) + //doDelay(t1, micros(), 1000); +} + +// Poll USB MIDI Controler and send to serial MIDI +void MIDI_poll() +{ + char buf[20]; + uint8_t bufMidi[64]; + uint16_t rcvd; + + if(Midi.vid != vid || Midi.pid != pid){ + sprintf(buf, "VID:%04X, PID:%04X", Midi.vid, Midi.pid); + Serial.println(buf); + vid = Midi.vid; + pid = Midi.pid; + } + if(Midi.RecvData( &rcvd, bufMidi) == 0 ){ + sprintf(buf, "%08X: ", millis()); + Serial.print(buf); + Serial.print(rcvd); + Serial.print(':'); + for(int i=0; i<64; i++){ + sprintf(buf, " %02X", bufMidi[i]); + Serial.print(buf); + } + Serial.println(""); + } +} + +// Delay time (max 16383 us) +void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +{ + unsigned long t3; + + if( t1 > t2 ){ + t3 = (4294967295 - t1 + t2); + }else{ + t3 = t2 - t1; + } + + if( t3 < delayTime ){ + delayMicroseconds(delayTime - t3); + } +} diff --git a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino new file mode 100755 index 00000000..d9b3acf3 --- /dev/null +++ b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino @@ -0,0 +1,92 @@ +/* + ******************************************************************************* + * USB-MIDI to Legacy Serial MIDI converter + * Copyright (C) 2012-2016 Yuuichi Akagawa + * + * Idea from LPK25 USB-MIDI to Serial MIDI converter + * by Collin Cunningham - makezine.com, narbotic.com + * + * This is sample program. Do not expect perfect behavior. + ******************************************************************************* + */ + +#include +#include + +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude +#include +#include +#endif + +#ifdef USBCON +#define _MIDI_SERIAL_PORT Serial1 +#else +#define _MIDI_SERIAL_PORT Serial +#endif +////////////////////////// +// MIDI Pin assign +// 2 : GND +// 4 : +5V(Vcc) with 220ohm +// 5 : TX +////////////////////////// + +USB Usb; +USBH_MIDI Midi(&Usb); + +void MIDI_poll(); +void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); + +void setup() +{ + _MIDI_SERIAL_PORT.begin(31250); + + if (Usb.Init() == -1) { + while(1); //halt + }//if (Usb.Init() == -1... + delay( 200 ); +} + +void loop() +{ + unsigned long t1; + + Usb.Task(); + t1 = micros(); + if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + { + MIDI_poll(); + } + //delay(1ms) + doDelay(t1, micros(), 1000); +} + +// Poll USB MIDI Controler and send to serial MIDI +void MIDI_poll() +{ + byte outBuf[ 3 ]; + uint8_t size; + + do { + if( (size=Midi.RecvData(outBuf)) > 0 ){ + //MIDI Output + _MIDI_SERIAL_PORT.write(outBuf, size); + } + }while(size>0); +} + +// Delay time (max 16383 us) +void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +{ + unsigned long t3; + + if( t1 > t2 ){ + t3 = (4294967295 - t1 + t2); + }else{ + t3 = t2 - t1; + } + + if( t3 < delayTime ){ + delayMicroseconds(delayTime - t3); + } +} diff --git a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino new file mode 100755 index 00000000..518b1b90 --- /dev/null +++ b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino @@ -0,0 +1,100 @@ +/* + ******************************************************************************* + * USB-MIDI to Legacy Serial MIDI converter + * Copyright (C) 2012-2016 Yuuichi Akagawa + * + * Idea from LPK25 USB-MIDI to Serial MIDI converter + * by Collin Cunningham - makezine.com, narbotic.com + * + * This is sample program. Do not expect perfect behavior. + ******************************************************************************* + */ + +#include +#include + +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude +#include +#include +#endif + +#ifdef USBCON +#define _MIDI_SERIAL_PORT Serial1 +#else +#define _MIDI_SERIAL_PORT Serial +#endif +////////////////////////// +// MIDI Pin assign +// 2 : GND +// 4 : +5V(Vcc) with 220ohm +// 5 : TX +////////////////////////// + +USB Usb; +USBHub Hub1(&Usb); +USBH_MIDI Midi1(&Usb); +USBH_MIDI Midi2(&Usb); + +void MIDI_poll(); +void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); + +void setup() +{ + _MIDI_SERIAL_PORT.begin(31250); + + if (Usb.Init() == -1) { + while(1); //halt + }//if (Usb.Init() == -1... + delay( 200 ); +} + +void loop() +{ + unsigned long t1; + + Usb.Task(); + t1 = micros(); + if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + { + MIDI_poll(); + } + //delay(1ms) + doDelay(t1, micros(), 1000); +} + +// Poll USB MIDI Controler and send to serial MIDI +void MIDI_poll() +{ + byte outBuf[ 3 ]; + uint8_t size; + + do { + if( (size=Midi1.RecvData(outBuf)) > 0 ){ + //MIDI Output + _MIDI_SERIAL_PORT.write(outBuf, size); + } + }while(size>0); + do { + if( (size=Midi2.RecvData(outBuf)) > 0 ){ + //MIDI Output + _MIDI_SERIAL_PORT.write(outBuf, size); + } + }while(size>0); +} + +// Delay time (max 16383 us) +void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +{ + unsigned long t3; + + if( t1 > t2 ){ + t3 = (4294967295 - t1 + t2); + }else{ + t3 = t2 - t1; + } + + if( t3 < delayTime ){ + delayMicroseconds(delayTime - t3); + } +} diff --git a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino new file mode 100755 index 00000000..a6646dcc --- /dev/null +++ b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino @@ -0,0 +1,110 @@ +/* + ******************************************************************************* + * Legacy Serial MIDI and USB Host bidirectional converter + * Copyright (C) 2013-2016 Yuuichi Akagawa + * + * for use with Arduino MIDI library + * https://github.com/FortySevenEffects/arduino_midi_library/ + * + * Note: + * - If you want use with Leonardo, you must choose Arduino MIDI library v4.0 or higher. + * - This is sample program. Do not expect perfect behavior. + ******************************************************************************* + */ + +#include +#include +#include + +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude +#include +#include +#endif + +//Arduino MIDI library v4.2 compatibility +#ifdef MIDI_CREATE_DEFAULT_INSTANCE +MIDI_CREATE_DEFAULT_INSTANCE(); +#endif +#ifdef USBCON +#define _MIDI_SERIAL_PORT Serial1 +#else +#define _MIDI_SERIAL_PORT Serial +#endif + +////////////////////////// +// MIDI Pin assign +// 2 : GND +// 4 : +5V(Vcc) with 220ohm +// 5 : TX +////////////////////////// + +USB Usb; +USBH_MIDI Midi(&Usb); + +void MIDI_poll(); +void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); + +void setup() +{ + MIDI.begin(MIDI_CHANNEL_OMNI); + + if (Usb.Init() == -1) { + while(1); //halt + }//if (Usb.Init() == -1... + delay( 200 ); +} + +void loop() +{ + unsigned long t1; + uint8_t msg[4]; + + Usb.Task(); + t1 = micros(); + if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + { + MIDI_poll(); + if (MIDI.read()) { + msg[0] = MIDI.getType(); + if( msg[0] == 0xf0 ) { //SysEX + //TODO + //SysEx implementation is not yet. + }else{ + msg[1] = MIDI.getData1(); + msg[2] = MIDI.getData2(); + Midi.SendData(msg, 0); + } + } + } + //delay(1ms) + doDelay(t1, micros(), 1000); +} + +// Poll USB MIDI Controler and send to serial MIDI +void MIDI_poll() +{ + byte outBuf[ 3 ]; + uint8_t size; + + if( (size=Midi.RecvData(outBuf)) > 0 ){ + //MIDI Output + _MIDI_SERIAL_PORT.write(outBuf, size); + } +} + +// Delay time (max 16383 us) +void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +{ + unsigned long t3; + + if( t1 > t2 ){ + t3 = (4294967295 - t1 + t2); + }else{ + t3 = t2 - t1; + } + + if( t3 < delayTime ){ + delayMicroseconds(delayTime - t3); + } +} diff --git a/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino new file mode 100755 index 00000000..87961056 --- /dev/null +++ b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino @@ -0,0 +1,93 @@ +/* + ******************************************************************************* + * eVY1 Shield sample - Say 'Konnichiwa' + * Copyright (C) 2014-2016 Yuuichi Akagawa + * + * This is sample program. Do not expect perfect behavior. + ******************************************************************************* + */ +#include +#include + +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude +#include +#include +#endif + +USB Usb; +//USBHub Hub(&Usb); +USBH_MIDI Midi(&Usb); + +void MIDI_poll(); +void noteOn(uint8_t note); +void noteOff(uint8_t note); + +uint16_t pid, vid; +uint8_t exdata[] ={ + 0xf0, 0x43, 0x79, 0x09, 0x00, 0x50, 0x10, + 'k',' ','o',',', //Ko + 'N','\\',',', //N + 'J',' ', 'i', ',', //Ni + 't','S',' ','i',',',//Chi + 'w',' ','a', //Wa + 0x00, 0xf7 +}; + +void setup() +{ + vid = pid = 0; + Serial.begin(115200); + + if (Usb.Init() == -1) { + while(1); //halt + }//if (Usb.Init() == -1... + delay( 200 ); +} + +void loop() +{ + Usb.Task(); + if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + { + MIDI_poll(); + noteOn(0x3f); + delay(400); + noteOff(0x3f); + delay(100); + } +} + +// Poll USB MIDI Controler +void MIDI_poll() +{ + byte inBuf[ 3 ]; + + //first call? + if(Midi.vid != vid || Midi.pid != pid){ + vid = Midi.vid; pid = Midi.pid; + Midi.SendSysEx(exdata, sizeof(exdata)); + delay(500); + } + uint8_t size = Midi.RecvData(inBuf); +} + +//note On +void noteOn(uint8_t note) +{ + uint8_t buf[3]; + buf[0] = 0x90; + buf[1] = note; + buf[2] = 0x7f; + Midi.SendData(buf); +} + +//note Off +void noteOff(uint8_t note) +{ + uint8_t buf[3]; + buf[0] = 0x80; + buf[1] = note; + buf[2] = 0x00; + Midi.SendData(buf); +} diff --git a/usbh_midi.cpp b/usbh_midi.cpp new file mode 100755 index 00000000..5612588e --- /dev/null +++ b/usbh_midi.cpp @@ -0,0 +1,550 @@ +/* + ******************************************************************************* + * USB-MIDI class driver for USB Host Shield 2.0 Library + * Copyright (c) 2012-2016 Yuuichi Akagawa + * + * Idea from LPK25 USB-MIDI to Serial MIDI converter + * by Collin Cunningham - makezine.com, narbotic.com + * + * for use with USB Host Shield 2.0 from Circuitsathome.com + * https://github.com/felis/USB_Host_Shield_2.0 + ******************************************************************************* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + ******************************************************************************* + */ + +#include "usbh_midi.h" +////////////////////////// +// MIDI MESAGES +// midi.org/techspecs/ +////////////////////////// +// STATUS BYTES +// 0x8n == noteOff +// 0x9n == noteOn +// 0xAn == afterTouch +// 0xBn == controlChange +// n == Channel(0x0-0xf) +////////////////////////// +//DATA BYTE 1 +// note# == (0-127) +// or +// control# == (0-119) +////////////////////////// +// DATA BYTE 2 +// velocity == (0-127) +// or +// controlVal == (0-127) +/////////////////////////////////////////////////////////////////////////////// +// USB-MIDI Event Packets +// usb.org - Universal Serial Bus Device Class Definition for MIDI Devices 1.0 +/////////////////////////////////////////////////////////////////////////////// +//+-------------+-------------+-------------+-------------+ +//| Byte 0 | Byte 1 | Byte 2 | Byte 3 | +//+------+------+-------------+-------------+-------------+ +//|Cable | Code | | | | +//|Number|Index | MIDI_0 | MIDI_1 | MIDI_2 | +//| |Number| | | | +//|(4bit)|(4bit)| (8bit) | (8bit) | (8bit) | +//+------+------+-------------+-------------+-------------+ +// CN == 0x0-0xf +//+-----+-----------+------------------------------------------------------------------- +//| CIN |MIDI_x size|Description +//+-----+-----------+------------------------------------------------------------------- +//| 0x0 | 1, 2 or 3 |Miscellaneous function codes. Reserved for future extensions. +//| 0x1 | 1, 2 or 3 |Cable events. Reserved for future expansion. +//| 0x2 | 2 |Two-byte System Common messages like MTC, SongSelect, etc. +//| 0x3 | 3 |Three-byte System Common messages like SPP, etc. +//| 0x4 | 3 |SysEx starts or continues +//| 0x5 | 1 |Single-byte System Common Message or SysEx ends with following single byte. +//| 0x6 | 2 |SysEx ends with following two bytes. +//| 0x7 | 3 |SysEx ends with following three bytes. +//| 0x8 | 3 |Note-off +//| 0x9 | 3 |Note-on +//| 0xA | 3 |Poly-KeyPress +//| 0xB | 3 |Control Change +//| 0xC | 2 |Program Change +//| 0xD | 2 |Channel Pressure +//| 0xE | 3 |PitchBend Change +//| 0xF | 1 |Single Byte +//+-----+-----------+------------------------------------------------------------------- + +const uint8_t USBH_MIDI::epDataInIndex = 1; +const uint8_t USBH_MIDI::epDataOutIndex = 2; +const uint8_t USBH_MIDI::epDataInIndexVSP = 3; +const uint8_t USBH_MIDI::epDataOutIndexVSP = 4; + +USBH_MIDI::USBH_MIDI(USB *p) : +pUsb(p), +bAddress(0), +bNumEP(1), +bPollEnable(false), +isMidiFound(false), +readPtr(0) { + // initialize endpoint data structures + for(uint8_t i=0; iRegisterDeviceClass(this); + } +} + +/* Connection initialization of an MIDI Device */ +uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) +{ + uint8_t buf[DESC_BUFF_SIZE]; + USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast(buf); + uint8_t rcode; + UsbDevice *p = NULL; + EpInfo *oldep_ptr = NULL; + uint8_t num_of_conf; // number of configurations + + // get memory address of USB device address pool + AddressPool &addrPool = pUsb->GetAddressPool(); +#ifdef DEBUG_USB_HOST + USBTRACE("\rMIDI Init\r\n"); +#endif + // check if address has already been assigned to an instance + if (bAddress) { + return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; + } + // Get pointer to pseudo device with address 0 assigned + p = addrPool.GetUsbDevicePtr(bAddress); + if (!p) { + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + } + if (!p->epinfo) { + return USB_ERROR_EPINFO_IS_NULL; + } + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + + // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence + p->epinfo = epInfo; + p->lowspeed = lowspeed; + + // Get device descriptor + rcode = pUsb->getDevDescr( 0, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf ); + vid = udd->idVendor; + pid = udd->idProduct; + // Restore p->epinfo + p->epinfo = oldep_ptr; + + if( rcode ){ + goto FailGetDevDescr; + } + + // Allocate new address according to device class + bAddress = addrPool.AllocAddress(parent, false, port); + if (!bAddress) { + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + } + + // Extract Max Packet Size from device descriptor + epInfo[0].maxPktSize = udd->bMaxPacketSize0; + + // Assign new address to the device + rcode = pUsb->setAddr( 0, 0, bAddress ); + if (rcode) { + p->lowspeed = false; + addrPool.FreeAddress(bAddress); + bAddress = 0; + return rcode; + }//if (rcode... +#ifdef DEBUG_USB_HOST + USBTRACE2("Addr:", bAddress); +#endif + p->lowspeed = false; + + //get pointer to assigned address record + p = addrPool.GetUsbDevicePtr(bAddress); + if (!p) { + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + } + p->lowspeed = lowspeed; + + num_of_conf = udd->bNumConfigurations; + + // Assign epInfo to epinfo pointer + rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); + if (rcode) { +#ifdef DEBUG_USB_HOST + USBTRACE("setEpInfoEntry failed"); +#endif + goto FailSetDevTblEntry; + } +#ifdef DEBUG_USB_HOST + USBTRACE2("NC:", num_of_conf); +#endif + for (uint8_t i=0; i 1) + break; + } // for +#ifdef DEBUG_USB_HOST + USBTRACE2("NumEP:", bNumEP); +#endif + if( bConfNum == 0 ){ //Device not found. + goto FailGetConfDescr; + } + + if( !isMidiFound ){ //MIDI Device not found. Try first Bulk transfer device + epInfo[epDataInIndex].epAddr = epInfo[epDataInIndexVSP].epAddr; + epInfo[epDataInIndex].maxPktSize = epInfo[epDataInIndexVSP].maxPktSize; + epInfo[epDataOutIndex].epAddr = epInfo[epDataOutIndexVSP].epAddr; + epInfo[epDataOutIndex].maxPktSize = epInfo[epDataOutIndexVSP].maxPktSize; + } + + // Assign epInfo to epinfo pointer + rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); +#ifdef DEBUG_USB_HOST + USBTRACE2("Conf:", bConfNum); +#endif + // Set Configuration Value + rcode = pUsb->setConf(bAddress, 0, bConfNum); + if (rcode) { + goto FailSetConfDescr; + } +#ifdef DEBUG_USB_HOST + USBTRACE("Init done."); +#endif + bPollEnable = true; + return 0; +FailGetDevDescr: +FailSetDevTblEntry: +FailGetConfDescr: +FailSetConfDescr: + Release(); + return rcode; +} + +/* get and parse config descriptor */ +void USBH_MIDI::parseConfigDescr( byte addr, byte conf ) +{ + uint8_t buf[ DESC_BUFF_SIZE ]; + uint8_t* buf_ptr = buf; + byte rcode; + byte descr_length; + byte descr_type; + unsigned int total_length; + USB_ENDPOINT_DESCRIPTOR *epDesc; + boolean isMidi = false; + + // get configuration descriptor (get descriptor size only) + rcode = pUsb->getConfDescr( addr, 0, 4, conf, buf ); + if( rcode ){ + return; + } + total_length = buf[2] | ((int)buf[3] << 8); + if( total_length > DESC_BUFF_SIZE ) { //check if total length is larger than buffer + total_length = DESC_BUFF_SIZE; + } + + // get configuration descriptor (all) + rcode = pUsb->getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor + if( rcode ){ + return; + } + + //parsing descriptors + while( buf_ptr < buf + total_length ) { + descr_length = *( buf_ptr ); + descr_type = *( buf_ptr + 1 ); + switch( descr_type ) { + case USB_DESCRIPTOR_CONFIGURATION : + bConfNum = buf_ptr[5]; + break; + case USB_DESCRIPTOR_INTERFACE : + if( buf_ptr[5] == USB_CLASS_AUDIO && buf_ptr[6] == USB_SUBCLASS_MIDISTREAMING ) { //p[5]; bInterfaceClass = 1(Audio), p[6]; bInterfaceSubClass = 3(MIDI Streaming) + isMidiFound = true; //MIDI device found. + isMidi = true; + }else{ +#ifdef DEBUG_USB_HOST + USBTRACE("No MIDI Device\n"); +#endif + isMidi = false; + } + break; + case USB_DESCRIPTOR_ENDPOINT : + epDesc = (USB_ENDPOINT_DESCRIPTOR *)buf_ptr; + if ((epDesc->bmAttributes & 0x02) == 2) {//bulk + uint8_t index; + if( isMidi ) + index = ((epDesc->bEndpointAddress & 0x80) == 0x80) ? epDataInIndex : epDataOutIndex; + else + index = ((epDesc->bEndpointAddress & 0x80) == 0x80) ? epDataInIndexVSP : epDataOutIndexVSP; + epInfo[index].epAddr = (epDesc->bEndpointAddress & 0x0F); + epInfo[index].maxPktSize = (uint8_t)epDesc->wMaxPacketSize; + bNumEP ++; +#ifdef DEBUG_USB_HOST + PrintEndpointDescriptor(epDesc); +#endif + } + break; + default: + break; + }//switch( descr_type + buf_ptr += descr_length; //advance buffer pointer + }//while( buf_ptr <=... +} + +/* Performs a cleanup after failed Init() attempt */ +uint8_t USBH_MIDI::Release() +{ + pUsb->GetAddressPool().FreeAddress(bAddress); + bNumEP = 1; //must have to be reset to 1 + bAddress = 0; + bPollEnable = false; + readPtr = 0; + return 0; +} + +/* Receive data from MIDI device */ +uint8_t USBH_MIDI::RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr) +{ + *bytes_rcvd = (uint16_t)epInfo[epDataInIndex].maxPktSize; + uint8_t r = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); + + if( *bytes_rcvd < (MIDI_EVENT_PACKET_SIZE-4)){ + dataptr[*bytes_rcvd] = '\0'; + dataptr[(*bytes_rcvd)+1] = '\0'; + } + return r; +} + +/* Receive data from MIDI device */ +uint8_t USBH_MIDI::RecvData(uint8_t *outBuf) +{ + byte rcode = 0; //return code + uint16_t rcvd; + + if( bPollEnable == false ) return false; + + //Checking unprocessed message in buffer. + if( readPtr != 0 && readPtr < MIDI_EVENT_PACKET_SIZE ){ + if(recvBuf[readPtr] == 0 && recvBuf[readPtr+1] == 0) { + //no unprocessed message left in the buffer. + }else{ + goto RecvData_return_from_buffer; + } + } + + readPtr = 0; + rcode = RecvData( &rcvd, recvBuf); + if( rcode != 0 ) { + return 0; + } + + //if all data is zero, no valid data received. + if( recvBuf[0] == 0 && recvBuf[1] == 0 && recvBuf[2] == 0 && recvBuf[3] == 0 ) { + return 0; + } + +RecvData_return_from_buffer: + readPtr++; + outBuf[0] = recvBuf[readPtr]; + readPtr++; + outBuf[1] = recvBuf[readPtr]; + readPtr++; + outBuf[2] = recvBuf[readPtr]; + readPtr++; + return lookupMsgSize(outBuf[0]); +} + +/* Send data to MIDI device */ +uint8_t USBH_MIDI::SendData(uint8_t *dataptr, byte nCable) +{ + byte buf[4]; + byte msg; + + msg = dataptr[0]; + // SysEx long message ? + if( msg == 0xf0 ) + { + return SendSysEx(dataptr, countSysExDataSize(dataptr), nCable); + } + + buf[0] = (nCable << 4) | (msg >> 4); + if( msg < 0xf0 ) msg = msg & 0xf0; + + + //Building USB-MIDI Event Packets + buf[1] = dataptr[0]; + buf[2] = dataptr[1]; + buf[3] = dataptr[2]; + + switch(lookupMsgSize(msg)) { + //3 bytes message + case 3 : + if(msg == 0xf2) {//system common message(SPP) + buf[0] = (nCable << 4) | 3; + } + break; + + //2 bytes message + case 2 : + if(msg == 0xf1 || msg == 0xf3) {//system common message(MTC/SongSelect) + buf[0] = (nCable << 4) | 2; + } + buf[3] = 0; + break; + + //1 bytes message + case 1 : + default : + buf[2] = 0; + buf[3] = 0; + break; + } + return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, 4, buf); +} + +#ifdef DEBUG_USB_HOST +void USBH_MIDI::PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ) +{ + Notify(PSTR("Endpoint descriptor:")); + Notify(PSTR("\r\nLength:\t\t")); + PrintHex(ep_ptr->bLength); + Notify(PSTR("\r\nType:\t\t")); + PrintHex(ep_ptr->bDescriptorType); + Notify(PSTR("\r\nAddress:\t")); + PrintHex(ep_ptr->bEndpointAddress); + Notify(PSTR("\r\nAttributes:\t")); + PrintHex(ep_ptr->bmAttributes); + Notify(PSTR("\r\nMaxPktSize:\t")); + PrintHex(ep_ptr->wMaxPacketSize); + Notify(PSTR("\r\nPoll Intrv:\t")); + PrintHex(ep_ptr->bInterval); + Notify(PSTR("\r\n")); +} +#endif + +/* look up a MIDI message size from spec */ +/*Return */ +/* 0 : undefined message */ +/* 0<: Vaild message size(1-3) */ +uint8_t USBH_MIDI::lookupMsgSize(uint8_t midiMsg) +{ + uint8_t msgSize = 0; + + if( midiMsg < 0xf0 ) midiMsg &= 0xf0; + switch(midiMsg) { + //3 bytes messages + case 0xf2 : //system common message(SPP) + case 0x80 : //Note off + case 0x90 : //Note on + case 0xa0 : //Poly KeyPress + case 0xb0 : //Control Change + case 0xe0 : //PitchBend Change + msgSize = 3; + break; + + //2 bytes messages + case 0xf1 : //system common message(MTC) + case 0xf3 : //system common message(SongSelect) + case 0xc0 : //Program Change + case 0xd0 : //Channel Pressure + msgSize = 2; + break; + + //1 bytes messages + case 0xf8 : //system realtime message + case 0xf9 : //system realtime message + case 0xfa : //system realtime message + case 0xfb : //system realtime message + case 0xfc : //system realtime message + case 0xfe : //system realtime message + case 0xff : //system realtime message + msgSize = 1; + break; + + //undefine messages + default : + break; + } + return msgSize; +} + +/* SysEx data size counter */ +unsigned int USBH_MIDI::countSysExDataSize(uint8_t *dataptr) +{ + unsigned int c = 1; + + if( *dataptr != 0xf0 ){ //not SysEx + return 0; + } + + //Search terminator(0xf7) + while(*dataptr != 0xf7) + { + dataptr++; + c++; + + //Limiter (upto 256 bytes) + if(c > 256){ + c = 0; + break; + } + } + return c; +} + +/* Send SysEx message to MIDI device */ +uint8_t USBH_MIDI::SendSysEx(uint8_t *dataptr, unsigned int datasize, byte nCable) +{ + byte buf[4]; + uint8_t rc; + unsigned int n = datasize; + + while(n > 0) { + //Byte 0 + buf[0] = (nCable << 4) | 0x4; //x4 SysEx starts or continues + + switch ( n ) { + case 1 : + buf[0] = (nCable << 4) | 0x5; //x5 SysEx ends with following single byte. + buf[1] = *(dataptr++); + buf[2] = 0x00; + buf[3] = 0x00; + n = n - 1; + break; + case 2 : + buf[0] = (nCable << 4) | 0x6; //x6 SysEx ends with following two bytes. + buf[1] = *(dataptr++); + buf[2] = *(dataptr++); + buf[3] = 0x00; + n = n - 2; + break; + case 3 : + buf[0] = (nCable << 4) | 0x7; //x7 SysEx ends with following three bytes. + default : + buf[1] = *(dataptr++); + buf[2] = *(dataptr++); + buf[3] = *(dataptr++); + n = n - 3; + break; + } + rc = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, 4, buf); + if(rc != 0) + break; + } + return(rc); +} diff --git a/usbh_midi.h b/usbh_midi.h new file mode 100755 index 00000000..0cf380de --- /dev/null +++ b/usbh_midi.h @@ -0,0 +1,86 @@ +/* + ******************************************************************************* + * USB-MIDI class driver for USB Host Shield 2.0 Library + * Copyright (c) 2012-2016 Yuuichi Akagawa + * + * Idea from LPK25 USB-MIDI to Serial MIDI converter + * by Collin Cunningham - makezine.com, narbotic.com + * + * for use with USB Host Shield 2.0 from Circuitsathome.com + * https://github.com/felis/USB_Host_Shield_2.0 + ******************************************************************************* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + ******************************************************************************* + */ + +#if !defined(_USBH_MIDI_H_) +#define _USBH_MIDI_H_ +#include "Usb.h" + +#define MIDI_MAX_ENDPOINTS 5 //endpoint 0, bulk_IN(MIDI), bulk_OUT(MIDI), bulk_IN(VSP), bulk_OUT(VSP) +#define USB_SUBCLASS_MIDISTREAMING 3 +#define DESC_BUFF_SIZE 256 +#define MIDI_EVENT_PACKET_SIZE 64 +class USBH_MIDI; + +class USBH_MIDI : public USBDeviceConfig +{ +private: + uint8_t lookupMsgSize(uint8_t midiMsg); + +protected: + static const uint8_t epDataInIndex; // DataIn endpoint index(MIDI) + static const uint8_t epDataOutIndex; // DataOUT endpoint index(MIDI) + static const uint8_t epDataInIndexVSP; // DataIn endpoint index(Vendor Specific Protocl) + static const uint8_t epDataOutIndexVSP; // DataOUT endpoint index(Vendor Specific Protocl) + + boolean isMidiFound; + + /* mandatory members */ + USB *pUsb; + uint8_t bAddress; + uint8_t bConfNum; // configuration number + uint8_t bNumEP; // total number of EP in the configuration + bool bPollEnable; + /* Endpoint data structure */ + EpInfo epInfo[MIDI_MAX_ENDPOINTS]; + /* MIDI Event packet buffer */ + uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE]; + uint8_t readPtr; + + void parseConfigDescr(byte addr, byte conf); + unsigned int countSysExDataSize(uint8_t *dataptr); +#ifdef DEBUG + void PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ); +#endif +public: + uint16_t pid, vid; + USBH_MIDI(USB *p); + // Methods for recieving and sending data + uint8_t RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr); + uint8_t RecvData(uint8_t *outBuf); + uint8_t SendData(uint8_t *dataptr, byte nCable=0); + uint8_t SendSysEx(uint8_t *dataptr, unsigned int datasize, byte nCable=0); + // backward compatibility functions + inline uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr){ return RecvData(bytes_rcvd, dataptr); }; + inline uint8_t RcvData(uint8_t *outBuf){ return RecvData(outBuf); }; + + // USBDeviceConfig implementation + virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); + virtual uint8_t Release(); + virtual uint8_t Poll(){}; //not implemented + virtual uint8_t GetAddress() { return bAddress; }; +}; + +#endif //_USBH_MIDI_H_ From 4b14c6910c468b413a830a1ea04e54e011aa11be Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 21 Mar 2016 17:57:33 +0100 Subject: [PATCH 127/220] Make sure that a invalid LED report is not sent Does not seem to make any difference, but just in case --- SRWS1.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SRWS1.cpp b/SRWS1.cpp index fa33a7a0..19003a27 100644 --- a/SRWS1.cpp +++ b/SRWS1.cpp @@ -113,7 +113,7 @@ void SRWS1::setLeds(uint16_t leds) { uint8_t buf[3]; buf[0] = 0x40; // Report ID buf[1] = leds & 0xFF; - buf[2] = leds >> 8; + buf[2] = (leds >> 8) & 0x7F; pUsb->outTransfer(bAddress, epInfo[ hidInterfaces[0].epIndex[epInterruptOutIndex] ].epAddr, sizeof(buf), buf); } From d67e637f2faaa516258c8bb0b003eb98bad98f9c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 21 Mar 2016 17:57:43 +0100 Subject: [PATCH 128/220] Updated some comments --- examples/HID/SRWS1/SRWS1.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/HID/SRWS1/SRWS1.ino b/examples/HID/SRWS1/SRWS1.ino index 646f3df2..f4a5e2a7 100644 --- a/examples/HID/SRWS1/SRWS1.ino +++ b/examples/HID/SRWS1/SRWS1.ino @@ -41,13 +41,13 @@ void loop() { leds <<= 1; if (leds == 0x8000) // All are actually turned off, as there is only 15 LEDs dirUp = false; // If we have reached the end i.e. all LEDs are off, then change direction - else if (!(leds & 0x8000)) // If last bit is not set set the lowest bit + else if (!(leds & 0x8000)) // If last bit is not set, then set the lowest bit leds |= 1; // Set lowest bit } else { leds >>= 1; if (leds == 0) // Check if all LEDs are off dirUp = true; // If all LEDs are off, then repeat the sequence - else if (!(leds & 0x1)) // If last bit is not set set the lowest bit + else if (!(leds & 0x1)) // If last bit is not set, then set the top bit leds |= 1 << 15; // Set top bit } } From 73fbb7ab9241f9939d0e5ce9715cdb199510f56c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 21 Mar 2016 18:13:30 +0100 Subject: [PATCH 129/220] Moved serial printing into the example --- SRWS1.cpp | 70 ------------------ examples/HID/SRWS1/SRWS1.ino | 135 +++++++++++++++++++++++++++++++++-- 2 files changed, 129 insertions(+), 76 deletions(-) diff --git a/SRWS1.cpp b/SRWS1.cpp index 19003a27..97e53a73 100644 --- a/SRWS1.cpp +++ b/SRWS1.cpp @@ -36,76 +36,6 @@ void SRWS1::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) buttonClickState.val = srws1Data.btn.val & ~oldButtonState.val; // Update click state variable oldButtonState.val = srws1Data.btn.val; } -#if 0 - if (srws1Data.leftTrigger) { - Serial.print(F("L2: ")); - Serial.println(srws1Data.leftTrigger); - } - if (srws1Data.rightTrigger) { - Serial.print(F("R2: ")); - Serial.println(srws1Data.rightTrigger); - } - if (srws1Data.btn.select) { - //Serial.println("Select"); - Serial.println(srws1Data.tilt); - } - - if (srws1Data.btn.back) Serial.println(F("Back")); - if (srws1Data.btn.lookLeft) Serial.println(F("Look Left")); - if (srws1Data.btn.lights) Serial.println(F("Lights")); - if (srws1Data.btn.lookBack) Serial.println(F("Look Back")); - if (srws1Data.btn.rearBrakeBalance) Serial.println(F("R. Brake Balance")); - if (srws1Data.btn.frontBrakeBalance) Serial.println(F("F. Brake Balance")); - if (srws1Data.btn.requestPit) Serial.println(F("Request Pit")); - if (srws1Data.btn.leftGear) Serial.println(F("Left Gear")); - - if (srws1Data.btn.camera) Serial.println(F("Camera")); - if (srws1Data.btn.lookRight) Serial.println(F("Look right")); - if (srws1Data.btn.boost) Serial.println(F("Boost")); - if (srws1Data.btn.horn) Serial.println(F("Horn")); - if (srws1Data.btn.hud) Serial.println(F("HUD")); - if (srws1Data.btn.launchControl) Serial.println(F("Launch Control")); - if (srws1Data.btn.speedLimiter) Serial.println(F("Speed Limiter")); - if (srws1Data.btn.rightGear) Serial.println(F("Right gear")); - - if (srws1Data.assists) Serial.println(srws1Data.assists); - if (srws1Data.steeringSensitivity) Serial.println(srws1Data.steeringSensitivity); - if (srws1Data.assistValues) Serial.println(srws1Data.assistValues); - - switch (srws1Data.btn.dpad) { - case DPAD_UP: - Serial.println(F("Up")); - break; - case DPAD_UP_RIGHT: - Serial.println(F("UP & RIGHT")); - break; - case DPAD_RIGHT: - Serial.println(F("Right")); - break; - case DPAD_RIGHT_DOWN: - Serial.println(F("Right & down")); - break; - case DPAD_DOWN: - Serial.println(F("Down")); - break; - case DPAD_DOWN_LEFT: - Serial.println(F("Down & left")); - break; - case DPAD_LEFT: - Serial.println(F("Left")); - break; - case DPAD_LEFT_UP: - Serial.println(F("Left & up")); - break; - case DPAD_OFF: - break; - default: - Serial.print(F("Unknown state: ")); - D_PrintHex (srws1Data.btn.dpad, 0x80); - Serial.println(); - break; - } -#endif } // See: https://github.com/torvalds/linux/blob/master/drivers/hid/hid-steelseries.c diff --git a/examples/HID/SRWS1/SRWS1.ino b/examples/HID/SRWS1/SRWS1.ino index f4a5e2a7..d2917fc9 100644 --- a/examples/HID/SRWS1/SRWS1.ino +++ b/examples/HID/SRWS1/SRWS1.ino @@ -1,8 +1,8 @@ /* - Example sketch for the SteelSeries SRW-S1 Steering Wheel - developed by Kristian Lauszus - For more information visit my blog: http://blog.tkjelectronics.dk/ or - send me an e-mail: kristianl@tkjelectronics.com - */ + Example sketch for the SteelSeries SRW-S1 Steering Wheel - developed by Kristian Lauszus + For more information visit my blog: http://blog.tkjelectronics.dk/ or + send me an e-mail: kristianl@tkjelectronics.com +*/ #include #include "SRWS1.h" @@ -10,6 +10,8 @@ USB Usb; SRWS1 srw1(&Usb); +bool printTilt; + void setup() { Serial.begin(115200); #if !defined(__MIPSEL__) @@ -32,8 +34,7 @@ void loop() { timer = millis(); // Reset timer static uint16_t leds = 0; - /*D_PrintHex (leds, 0x80); - Serial.println();*/ + //PrintHex (leds, 0x80); Serial.println(); srw1.setLeds(leds); // Update LEDs static bool dirUp = true; @@ -54,6 +55,128 @@ void loop() { #else srw1.setLeds(1 << map(srw1.srws1Data.tilt, -1800, 1800, 0, 14)); // Turn on a LED according to tilt value #endif + + if (srw1.srws1Data.leftTrigger) { + Serial.print(F("L2: ")); + Serial.println(srw1.srws1Data.leftTrigger); + } + if (srw1.srws1Data.rightTrigger) { + Serial.print(F("R2: ")); + Serial.println(srw1.srws1Data.rightTrigger); + } + + if (srw1.buttonClickState.select) { + srw1.buttonClickState.select = 0; // Clear event + Serial.println(F("Select")); + printTilt = !printTilt; // Print tilt value + } + + if (srw1.buttonClickState.back) { + srw1.buttonClickState.back = 0; // Clear event + Serial.println(F("Back")); + } + if (srw1.buttonClickState.lookLeft) { + srw1.buttonClickState.lookLeft = 0; // Clear event + Serial.println(F("Look Left")); + } + if (srw1.buttonClickState.lights) { + srw1.buttonClickState.lights = 0; // Clear event + Serial.println(F("Lights")); + } + if (srw1.buttonClickState.lookBack) { + srw1.buttonClickState.lookBack = 0; // Clear event + Serial.println(F("Look Back")); + } + if (srw1.buttonClickState.rearBrakeBalance) { + srw1.buttonClickState.rearBrakeBalance = 0; // Clear event + Serial.println(F("R. Brake Balance")); + } + if (srw1.buttonClickState.frontBrakeBalance) { + srw1.buttonClickState.frontBrakeBalance = 0; // Clear event + Serial.println(F("F. Brake Balance")); + } + if (srw1.buttonClickState.requestPit) { + srw1.buttonClickState.requestPit = 0; // Clear event + Serial.println(F("Request Pit")); + } + if (srw1.buttonClickState.leftGear) { + srw1.buttonClickState.leftGear = 0; // Clear event + Serial.println(F("Left Gear")); + } + + if (srw1.buttonClickState.camera) { + srw1.buttonClickState.camera = 0; // Clear event + Serial.println(F("Camera")); + } + if (srw1.buttonClickState.lookRight) { + srw1.buttonClickState.lookRight = 0; // Clear event + Serial.println(F("Look right")); + } + if (srw1.buttonClickState.boost) { + srw1.buttonClickState.boost = 0; // Clear event + Serial.println(F("Boost")); + } + if (srw1.buttonClickState.horn) { + srw1.buttonClickState.horn = 0; // Clear event + Serial.println(F("Horn")); + } + if (srw1.buttonClickState.hud) { + srw1.buttonClickState.hud = 0; // Clear event + Serial.println(F("HUD")); + } + if (srw1.buttonClickState.launchControl) { + srw1.buttonClickState.launchControl = 0; // Clear event + Serial.println(F("Launch Control")); + } + if (srw1.buttonClickState.speedLimiter) { + srw1.buttonClickState.speedLimiter = 0; // Clear event + Serial.println(F("Speed Limiter")); + } + if (srw1.buttonClickState.rightGear) { + srw1.buttonClickState.rightGear = 0; // Clear event + Serial.println(F("Right gear")); + } + + if (srw1.srws1Data.assists) Serial.println(srw1.srws1Data.assists); + if (srw1.srws1Data.steeringSensitivity) Serial.println(srw1.srws1Data.steeringSensitivity); + if (srw1.srws1Data.assistValues) Serial.println(srw1.srws1Data.assistValues); + + switch (srw1.srws1Data.btn.dpad) { + case DPAD_UP: + Serial.println(F("Up")); + break; + case DPAD_UP_RIGHT: + Serial.println(F("UP & right")); + break; + case DPAD_RIGHT: + Serial.println(F("Right")); + break; + case DPAD_RIGHT_DOWN: + Serial.println(F("Right & down")); + break; + case DPAD_DOWN: + Serial.println(F("Down")); + break; + case DPAD_DOWN_LEFT: + Serial.println(F("Down & left")); + break; + case DPAD_LEFT: + Serial.println(F("Left")); + break; + case DPAD_LEFT_UP: + Serial.println(F("Left & up")); + break; + case DPAD_OFF: + break; + default: + Serial.print(F("Unknown state: ")); + PrintHex (srw1.srws1Data.btn.dpad, 0x80); + Serial.println(); + break; + } + + if (printTilt) + Serial.println(srw1.srws1Data.tilt); } } From 92e24534e5d9271e0193de8dd1b089365794ec16 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 21 Mar 2016 18:14:43 +0100 Subject: [PATCH 130/220] Moved SRWS1 driver into example again --- SRWS1.cpp => examples/HID/SRWS1/SRWS1.cpp | 0 SRWS1.h => examples/HID/SRWS1/SRWS1.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename SRWS1.cpp => examples/HID/SRWS1/SRWS1.cpp (100%) rename SRWS1.h => examples/HID/SRWS1/SRWS1.h (100%) diff --git a/SRWS1.cpp b/examples/HID/SRWS1/SRWS1.cpp similarity index 100% rename from SRWS1.cpp rename to examples/HID/SRWS1/SRWS1.cpp diff --git a/SRWS1.h b/examples/HID/SRWS1/SRWS1.h similarity index 100% rename from SRWS1.h rename to examples/HID/SRWS1/SRWS1.h From 400f9c0dcf153ba0e107260f5a4503e58f0e8c06 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 21 Mar 2016 18:21:12 +0100 Subject: [PATCH 131/220] Toggle LED behaviour using the select button --- examples/HID/SRWS1/SRWS1.ino | 52 +++++++++++++++++------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/examples/HID/SRWS1/SRWS1.ino b/examples/HID/SRWS1/SRWS1.ino index d2917fc9..c83936fd 100644 --- a/examples/HID/SRWS1/SRWS1.ino +++ b/examples/HID/SRWS1/SRWS1.ino @@ -28,33 +28,34 @@ void loop() { Usb.Task(); if (srw1.connected()) { -#if 0 // Set to 1 in order to show a crazy strobe light effect - static uint32_t timer; - if (millis() - timer > 12) { - timer = millis(); // Reset timer + if (printTilt) { // Show tilt angle using the LEDs + srw1.setLeds(1 << map(srw1.srws1Data.tilt, -1800, 1800, 0, 14)); // Turn on a LED according to tilt value + Serial.println(srw1.srws1Data.tilt); + } else { // Show strobe light effect + static uint32_t timer; + if (millis() - timer > 12) { + timer = millis(); // Reset timer - static uint16_t leds = 0; - //PrintHex (leds, 0x80); Serial.println(); - srw1.setLeds(leds); // Update LEDs + static uint16_t leds = 0; + //PrintHex (leds, 0x80); Serial.println(); + srw1.setLeds(leds); // Update LEDs - static bool dirUp = true; - if (dirUp) { - leds <<= 1; - if (leds == 0x8000) // All are actually turned off, as there is only 15 LEDs - dirUp = false; // If we have reached the end i.e. all LEDs are off, then change direction - else if (!(leds & 0x8000)) // If last bit is not set, then set the lowest bit - leds |= 1; // Set lowest bit - } else { - leds >>= 1; - if (leds == 0) // Check if all LEDs are off - dirUp = true; // If all LEDs are off, then repeat the sequence - else if (!(leds & 0x1)) // If last bit is not set, then set the top bit - leds |= 1 << 15; // Set top bit + static bool dirUp = true; + if (dirUp) { + leds <<= 1; + if (leds == 0x8000) // All are actually turned off, as there is only 15 LEDs + dirUp = false; // If we have reached the end i.e. all LEDs are off, then change direction + else if (!(leds & 0x8000)) // If last bit is not set, then set the lowest bit + leds |= 1; // Set lowest bit + } else { + leds >>= 1; + if (leds == 0) // Check if all LEDs are off + dirUp = true; // If all LEDs are off, then repeat the sequence + else if (!(leds & 0x1)) // If last bit is not set, then set the top bit + leds |= 1 << 15; // Set top bit + } } } -#else - srw1.setLeds(1 << map(srw1.srws1Data.tilt, -1800, 1800, 0, 14)); // Turn on a LED according to tilt value -#endif if (srw1.srws1Data.leftTrigger) { Serial.print(F("L2: ")); @@ -68,7 +69,7 @@ void loop() { if (srw1.buttonClickState.select) { srw1.buttonClickState.select = 0; // Clear event Serial.println(F("Select")); - printTilt = !printTilt; // Print tilt value + printTilt = !printTilt; // Print tilt value & show it using the LEDs as well } if (srw1.buttonClickState.back) { @@ -174,9 +175,6 @@ void loop() { Serial.println(); break; } - - if (printTilt) - Serial.println(srw1.srws1Data.tilt); } } From 45e6a67cbc1786fce9296d913b707fcd6b177215 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 21 Mar 2016 18:28:58 +0100 Subject: [PATCH 132/220] Added small note about HID library to the README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 553238f1..48a45b76 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Help yourself by helping us support you! Many thousands of hours have been spent * [Xbox ONE Library](#xbox-one-library) * [Wii library](#wii-library) * [PS Buzz Library](#ps-buzz-library) + * [HID Libraries](#hid-libraries) * [Interface modifications](#interface-modifications) * [FAQ](#faq) @@ -307,6 +308,10 @@ More information about the controller can be found at the following sites: * http://www.developerfusion.com/article/84338/making-usb-c-friendly/ * https://github.com/torvalds/linux/blob/master/drivers/hid/hid-sony.c +### HID Libraries + +HID devices are also supported by the library. However these require you to write your own driver. A few example are provided in the [examples/HID](examples/HID) directory. Including an example for the [SteelSeries SRW-S1 Steering Wheel](examples/HID/SRWS1/SRWS1.ino). + # Interface modifications The shield is using SPI for communicating with the MAX3421E USB host controller. It uses the SCK, MISO and MOSI pins via the ICSP on your board. From ba5ab02622e842bf1685a6e5f6850b4477806e6c Mon Sep 17 00:00:00 2001 From: Yuuichi Akagawa Date: Wed, 23 Mar 2016 00:10:25 +0900 Subject: [PATCH 133/220] Added info about the MIDI library to the README --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 48a45b76..3c9d8e0d 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ For more information about the hardware see the [Hardware Manual](http://www.cir * Major contributor to mass storage code * __guruthree__ * [Xbox ONE](#xbox-one-library) controller support +* __Yuuichi Akagawa__ - [@YuuichiAkagawa](https://twitter.com/yuuichiakagawa) + * Developer of the [MIDI](#midi-library) library # Donate @@ -56,6 +58,7 @@ Help yourself by helping us support you! Many thousands of hours have been spent * [Wii library](#wii-library) * [PS Buzz Library](#ps-buzz-library) * [HID Libraries](#hid-libraries) + * [MIDI Library](#midi-library) * [Interface modifications](#interface-modifications) * [FAQ](#faq) @@ -312,6 +315,16 @@ More information about the controller can be found at the following sites: HID devices are also supported by the library. However these require you to write your own driver. A few example are provided in the [examples/HID](examples/HID) directory. Including an example for the [SteelSeries SRW-S1 Steering Wheel](examples/HID/SRWS1/SRWS1.ino). +### [MIDI Library](usbh_midi.cpp) + +The library support MIDI devices. +You can convert USB MIDI keyboard to legacy serial MIDI. + +* [USB_MIDI_converter.ino](USBH_MIDI/USB_MIDI_converter) +* [USB_MIDI_converter_multi.ino](USBH_MIDI/USB_MIDI_converter_multi) + +For information see the following page: . + # Interface modifications The shield is using SPI for communicating with the MAX3421E USB host controller. It uses the SCK, MISO and MOSI pins via the ICSP on your board. From 1fe606aa22d471a9254c2deb94b286a5dd46cf5a Mon Sep 17 00:00:00 2001 From: Hakan Lindestaf Date: Thu, 10 Mar 2016 00:30:43 -0800 Subject: [PATCH 134/220] #217 Added new class for HIDComposite that can listen to multiple interfaces. Added example for multimedia keyboard --- .../USBHIDMultimediaKbd.ino | 68 +++ hidcomposite.cpp | 417 ++++++++++++++++++ hidcomposite.h | 108 +++++ 3 files changed, 593 insertions(+) create mode 100644 examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino create mode 100644 hidcomposite.cpp create mode 100644 hidcomposite.h diff --git a/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino new file mode 100644 index 00000000..ed293b76 --- /dev/null +++ b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino @@ -0,0 +1,68 @@ +#include +#include + +// Satisfy the IDE, which needs to see the include statment in the ino too. +#ifdef dobogusinclude +#include +#include +#endif + +class HIDSelector : public HIDComposite +{ +public: + HIDSelector(USB *p) : HIDComposite(p) {}; + +protected: + void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDComposite library + bool SelectInterface(uint8_t iface, uint8_t proto); +}; + +bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto) +{ + if(proto != 0) + return true; + + return false; +} + +void HIDSelector::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { +#if 1 + if (len && buf) { + Notify(PSTR("\r\n"), 0x80); + for (uint8_t i = 0; i < len; i++) { + D_PrintHex (buf[i], 0x80); + Notify(PSTR(" "), 0x80); + } + } +#endif +} + + +USB Usb; +//USBHub Hub(&Usb); +HIDSelector hidSelector(&Usb); + + +void setup() +{ + Serial.begin( 115200 ); +#if !defined(__MIPSEL__) + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection +#endif + Serial.println("Start"); + + if (Usb.Init() == -1) + Serial.println("OSC did not start."); + + // Set this to higher values to enable more debug information + // minimum 0x00, maximum 0xff, default 0x80 + UsbDEBUGlvl = 0xff; + + delay( 200 ); +} + +void loop() +{ + Usb.Task(); +} + diff --git a/hidcomposite.cpp b/hidcomposite.cpp new file mode 100644 index 00000000..31822bc0 --- /dev/null +++ b/hidcomposite.cpp @@ -0,0 +1,417 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#include "hidcomposite.h" + +HIDComposite::HIDComposite(USB *p) : +USBHID(p), +qNextPollTime(0), +pollInterval(0), +bPollEnable(false), +bHasReportId(false) { + Initialize(); + + if(pUsb) + pUsb->RegisterDeviceClass(this); +} + +uint16_t HIDComposite::GetHidClassDescrLen(uint8_t type, uint8_t num) { + for(uint8_t i = 0, n = 0; i < HID_MAX_HID_CLASS_DESCRIPTORS; i++) { + if(descrInfo[i].bDescrType == type) { + if(n == num) + return descrInfo[i].wDescriptorLength; + n++; + } + } + return 0; +} + +void HIDComposite::Initialize() { + for(uint8_t i = 0; i < MAX_REPORT_PARSERS; i++) { + rptParsers[i].rptId = 0; + rptParsers[i].rptParser = NULL; + } + for(uint8_t i = 0; i < HID_MAX_HID_CLASS_DESCRIPTORS; i++) { + descrInfo[i].bDescrType = 0; + descrInfo[i].wDescriptorLength = 0; + } + for(uint8_t i = 0; i < maxHidInterfaces; i++) { + hidInterfaces[i].bmInterface = 0; + hidInterfaces[i].bmProtocol = 0; + + for(uint8_t j = 0; j < maxEpPerInterface; j++) + hidInterfaces[i].epIndex[j] = 0; + } + for(uint8_t i = 0; i < totalEndpoints; i++) { + epInfo[i].epAddr = 0; + epInfo[i].maxPktSize = (i) ? 0 : 8; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; + epInfo[i].bmNakPower = (i) ? USB_NAK_NOWAIT : USB_NAK_MAX_POWER; + } + bNumEP = 1; + bNumIface = 0; + bConfNum = 0; + pollInterval = 0; +} + +bool HIDComposite::SetReportParser(uint8_t id, HIDReportParser *prs) { + for(uint8_t i = 0; i < MAX_REPORT_PARSERS; i++) { + if(rptParsers[i].rptId == 0 && rptParsers[i].rptParser == NULL) { + rptParsers[i].rptId = id; + rptParsers[i].rptParser = prs; + return true; + } + } + return false; +} + +HIDReportParser* HIDComposite::GetReportParser(uint8_t id) { + if(!bHasReportId) + return ((rptParsers[0].rptParser) ? rptParsers[0].rptParser : NULL); + + for(uint8_t i = 0; i < MAX_REPORT_PARSERS; i++) { + if(rptParsers[i].rptId == id) + return rptParsers[i].rptParser; + } + return NULL; +} + +uint8_t HIDComposite::Init(uint8_t parent, uint8_t port, bool lowspeed) { + const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); + + uint8_t buf[constBufSize]; + USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast(buf); + uint8_t rcode; + UsbDevice *p = NULL; + EpInfo *oldep_ptr = NULL; + uint8_t len = 0; + + uint8_t num_of_conf; // number of configurations + //uint8_t num_of_intf; // number of interfaces + + AddressPool &addrPool = pUsb->GetAddressPool(); + + USBTRACE("HU Init\r\n"); + + if(bAddress) + return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; + + // Get pointer to pseudo device with address 0 assigned + p = addrPool.GetUsbDevicePtr(0); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + if(!p->epinfo) { + USBTRACE("epinfo\r\n"); + return USB_ERROR_EPINFO_IS_NULL; + } + + // Save old pointer to EP_RECORD of address 0 + oldep_ptr = p->epinfo; + + // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence + p->epinfo = epInfo; + + p->lowspeed = lowspeed; + + // Get device descriptor + rcode = pUsb->getDevDescr(0, 0, 8, (uint8_t*)buf); + + if(!rcode) + len = (buf[0] > constBufSize) ? constBufSize : buf[0]; + + if(rcode) { + // Restore p->epinfo + p->epinfo = oldep_ptr; + + goto FailGetDevDescr; + } + + // Restore p->epinfo + p->epinfo = oldep_ptr; + + // Allocate new address according to device class + bAddress = addrPool.AllocAddress(parent, false, port); + + if(!bAddress) + return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + + // Extract Max Packet Size from the device descriptor + epInfo[0].maxPktSize = udd->bMaxPacketSize0; + + // Assign new address to the device + rcode = pUsb->setAddr(0, 0, bAddress); + + if(rcode) { + p->lowspeed = false; + addrPool.FreeAddress(bAddress); + bAddress = 0; + USBTRACE2("setAddr:", rcode); + return rcode; + } + + //delay(2); //per USB 2.0 sect.9.2.6.3 + + USBTRACE2("Addr:", bAddress); + + p->lowspeed = false; + + p = addrPool.GetUsbDevicePtr(bAddress); + + if(!p) + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + + p->lowspeed = lowspeed; + + if(len) + rcode = pUsb->getDevDescr(bAddress, 0, len, (uint8_t*)buf); + + if(rcode) + goto FailGetDevDescr; + + VID = udd->idVendor; // Can be used by classes that inherits this class to check the VID and PID of the connected device + PID = udd->idProduct; + + num_of_conf = udd->bNumConfigurations; + + // Assign epInfo to epinfo pointer + rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); + + if(rcode) + goto FailSetDevTblEntry; + + USBTRACE2("NC:", num_of_conf); + + for(uint8_t i = 0; i < num_of_conf; i++) { + //HexDumper HexDump; + ConfigDescParser confDescrParser(this); + + //rcode = pUsb->getConfDescr(bAddress, 0, i, &HexDump); + rcode = pUsb->getConfDescr(bAddress, 0, i, &confDescrParser); + + if(rcode) + goto FailGetConfDescr; + + if(bNumEP > 1) + break; + } // for + + if(bNumEP < 2) + return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; + + // Assign epInfo to epinfo pointer + rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); + + USBTRACE2("Cnf:", bConfNum); + + // Set Configuration Value + rcode = pUsb->setConf(bAddress, 0, bConfNum); + + if(rcode) + goto FailSetConfDescr; + + USBTRACE2("NumIface:", bNumIface); + + for(uint8_t i = 0; i < bNumIface; i++) { + if(hidInterfaces[i].epIndex[epInterruptInIndex] == 0) + continue; + + USBTRACE2("SetIdle:", hidInterfaces[i].bmInterface); + + rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0); + + if(rcode && rcode != hrSTALL) + goto FailSetIdle; + } + + USBTRACE("HU configured\r\n"); + + OnInitSuccessful(); + + bPollEnable = true; + return 0; + +FailGetDevDescr: +#ifdef DEBUG_USB_HOST + NotifyFailGetDevDescr(); + goto Fail; +#endif + +FailSetDevTblEntry: +#ifdef DEBUG_USB_HOST + NotifyFailSetDevTblEntry(); + goto Fail; +#endif + +FailGetConfDescr: +#ifdef DEBUG_USB_HOST + NotifyFailGetConfDescr(); + goto Fail; +#endif + +FailSetConfDescr: +#ifdef DEBUG_USB_HOST + NotifyFailSetConfDescr(); + goto Fail; +#endif + + +FailSetIdle: +#ifdef DEBUG_USB_HOST + USBTRACE("SetIdle:"); +#endif + +#ifdef DEBUG_USB_HOST +Fail: + NotifyFail(rcode); +#endif + Release(); + return rcode; +} + +HIDComposite::HIDInterface* HIDComposite::FindInterface(uint8_t iface, uint8_t alt, uint8_t proto) { + for(uint8_t i = 0; i < bNumIface && i < maxHidInterfaces; i++) + if(hidInterfaces[i].bmInterface == iface && hidInterfaces[i].bmAltSet == alt + && hidInterfaces[i].bmProtocol == proto) + return hidInterfaces + i; + return NULL; +} + +void HIDComposite::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) { + //ErrorMessage(PSTR("\r\nConf.Val"), conf); + //ErrorMessage(PSTR("Iface Num"), iface); + //ErrorMessage(PSTR("Alt.Set"), alt); + + bConfNum = conf; + + uint8_t index = 0; + HIDInterface *piface = FindInterface(iface, alt, proto); + + // Fill in interface structure in case of new interface + if(!piface) { + piface = hidInterfaces + bNumIface; + piface->bmInterface = iface; + piface->bmAltSet = alt; + piface->bmProtocol = proto; + bNumIface++; + } + + if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) + index = epInterruptInIndex; + else + index = epInterruptOutIndex; + + if(!SelectInterface(iface, proto)) + index = 0; + + if(index) { + // Fill in the endpoint info structure + epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); + epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; + epInfo[bNumEP].bmSndToggle = 0; + epInfo[bNumEP].bmRcvToggle = 0; + epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT; + + // Fill in the endpoint index list + piface->epIndex[index] = bNumEP; //(pep->bEndpointAddress & 0x0F); + + if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints + pollInterval = pep->bInterval; + + bNumEP++; + } +} + +uint8_t HIDComposite::Release() { + pUsb->GetAddressPool().FreeAddress(bAddress); + + bNumEP = 1; + bAddress = 0; + qNextPollTime = 0; + bPollEnable = false; + return 0; +} + +void HIDComposite::ZeroMemory(uint8_t len, uint8_t *buf) { + for(uint8_t i = 0; i < len; i++) + buf[i] = 0; +} + +uint8_t HIDComposite::Poll() { + uint8_t rcode = 0; + + if(!bPollEnable) + return 0; + + if((long)(millis() - qNextPollTime) >= 0L) { + qNextPollTime = millis() + pollInterval; + + uint8_t buf[constBuffLen]; + + for(uint8_t i = 0; i < bNumIface; i++) { + uint8_t index = hidInterfaces[i].epIndex[epInterruptInIndex]; + + if (index == 0) + continue; + + uint16_t read = (uint16_t)epInfo[index].maxPktSize; + + ZeroMemory(constBuffLen, buf); + + uint8_t rcode = pUsb->inTransfer(bAddress, epInfo[index].epAddr, &read, buf); + + if(rcode) { + if(rcode != hrNAK) + USBTRACE3("(hidcomposite.h) Poll:", rcode, 0x81); + continue; + } + + if(read == 0) + continue; + + if(read > constBuffLen) + read = constBuffLen; + +#if 0 + Notify(PSTR("\r\nBuf: "), 0x80); + + for(uint8_t i = 0; i < read; i++) { + D_PrintHex (buf[i], 0x80); + Notify(PSTR(" "), 0x80); + } + + Notify(PSTR("\r\n"), 0x80); +#endif + ParseHIDData(this, bHasReportId, (uint8_t)read, buf); + + HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0)); + + if(prs) + prs->Parse(this, bHasReportId, (uint8_t)read, buf); + } + + } + return rcode; +} + +// Send a report to interrupt out endpoint. This is NOT SetReport() request! +uint8_t HIDComposite::SndRpt(uint16_t nbytes, uint8_t *dataptr) { + return pUsb->outTransfer(bAddress, epInfo[epInterruptOutIndex].epAddr, nbytes, dataptr); +} diff --git a/hidcomposite.h b/hidcomposite.h new file mode 100644 index 00000000..8c8400db --- /dev/null +++ b/hidcomposite.h @@ -0,0 +1,108 @@ +/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. + +This software may be distributed and modified under the terms of the GNU +General Public License version 2 (GPL2) as published by the Free Software +Foundation and appearing in the file GPL2.TXT included in the packaging of +this file. Please note that GPL2 Section 2[b] requires that all works based +on this software must also be made publicly available under the terms of +the GPL2 ("Copyleft"). + +Contact information +------------------- + +Circuits At Home, LTD +Web : http://www.circuitsathome.com +e-mail : support@circuitsathome.com + */ + +#if !defined(__HIDCOMPOSITE_H__) +#define __HIDCOMPOSITE_H__ + +#include "usbhid.h" +//#include "hidescriptorparser.h" + +class HIDComposite : public USBHID { + + struct ReportParser { + uint8_t rptId; + HIDReportParser *rptParser; + } rptParsers[MAX_REPORT_PARSERS]; + + // HID class specific descriptor type and length info obtained from HID descriptor + HID_CLASS_DESCRIPTOR_LEN_AND_TYPE descrInfo[HID_MAX_HID_CLASS_DESCRIPTORS]; + + // Returns HID class specific descriptor length by its type and order number + uint16_t GetHidClassDescrLen(uint8_t type, uint8_t num); + + struct HIDInterface { + struct { + uint8_t bmInterface : 3; + uint8_t bmAltSet : 3; + uint8_t bmProtocol : 2; + }; + uint8_t epIndex[maxEpPerInterface]; + }; + + uint8_t bConfNum; // configuration number + uint8_t bNumIface; // number of interfaces in the configuration + uint8_t bNumEP; // total number of EP in the configuration + uint32_t qNextPollTime; // next poll time + uint8_t pollInterval; + bool bPollEnable; // poll enable flag + + static const uint16_t constBuffLen = 64; // event buffer length + + void Initialize(); + HIDInterface* FindInterface(uint8_t iface, uint8_t alt, uint8_t proto); + + void ZeroMemory(uint8_t len, uint8_t *buf); + +protected: + EpInfo epInfo[totalEndpoints]; + HIDInterface hidInterfaces[maxHidInterfaces]; + + bool bHasReportId; + + uint16_t PID, VID; // PID and VID of connected device + + // HID implementation + HIDReportParser* GetReportParser(uint8_t id); + + virtual uint8_t OnInitSuccessful() { + return 0; + }; + + virtual void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { + return; + }; + +public: + HIDComposite(USB *p); + + // HID implementation + bool SetReportParser(uint8_t id, HIDReportParser *prs); + + // USBDeviceConfig implementation + uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); + uint8_t Release(); + uint8_t Poll(); + + virtual uint8_t GetAddress() { + return bAddress; + }; + + virtual bool isReady() { + return bPollEnable; + }; + + // UsbConfigXtracter implementation + void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); + + // Send report - do not mix with SetReport()! + uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr); + + // Returns true if we should listen on an interface, false if not + virtual bool SelectInterface(uint8_t iface, uint8_t proto) = 0; +}; + +#endif // __HIDCOMPOSITE_H__ From a3b8e8d00b810930014de073ab2db0f6fab853df Mon Sep 17 00:00:00 2001 From: Hakan Lindestaf Date: Thu, 10 Mar 2016 00:51:04 -0800 Subject: [PATCH 135/220] #217 Include endpoint in ParseHIDData --- examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino | 5 ++--- hidcomposite.cpp | 2 +- hidcomposite.h | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino index ed293b76..23a4f3d7 100644 --- a/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino +++ b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino @@ -13,7 +13,7 @@ public: HIDSelector(USB *p) : HIDComposite(p) {}; protected: - void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDComposite library + void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDComposite library bool SelectInterface(uint8_t iface, uint8_t proto); }; @@ -25,7 +25,7 @@ bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto) return false; } -void HIDSelector::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { +void HIDSelector::ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf) { #if 1 if (len && buf) { Notify(PSTR("\r\n"), 0x80); @@ -65,4 +65,3 @@ void loop() { Usb.Task(); } - diff --git a/hidcomposite.cpp b/hidcomposite.cpp index 31822bc0..266610ec 100644 --- a/hidcomposite.cpp +++ b/hidcomposite.cpp @@ -399,7 +399,7 @@ uint8_t HIDComposite::Poll() { Notify(PSTR("\r\n"), 0x80); #endif - ParseHIDData(this, bHasReportId, (uint8_t)read, buf); + ParseHIDData(this, bHasReportId, epInfo[index].epAddr, (uint8_t)read, buf); HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0)); diff --git a/hidcomposite.h b/hidcomposite.h index 8c8400db..6abd7933 100644 --- a/hidcomposite.h +++ b/hidcomposite.h @@ -72,7 +72,7 @@ protected: return 0; }; - virtual void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { + virtual void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf) { return; }; From c1c955c225cafe05adf055519a726c76c84e83be Mon Sep 17 00:00:00 2001 From: Hakan Lindestaf Date: Fri, 11 Mar 2016 16:29:58 -0800 Subject: [PATCH 136/220] #217 Fixed order of parameters --- hidcomposite.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hidcomposite.cpp b/hidcomposite.cpp index 266610ec..91a89265 100644 --- a/hidcomposite.cpp +++ b/hidcomposite.cpp @@ -399,7 +399,7 @@ uint8_t HIDComposite::Poll() { Notify(PSTR("\r\n"), 0x80); #endif - ParseHIDData(this, bHasReportId, epInfo[index].epAddr, (uint8_t)read, buf); + ParseHIDData(this, epInfo[index].epAddr, bHasReportId, (uint8_t)read, buf); HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0)); From 83a52b5063c0e051cbdb7a64b97d39c2a0c53d4b Mon Sep 17 00:00:00 2001 From: Hakan Lindestaf Date: Mon, 21 Mar 2016 11:54:30 -0700 Subject: [PATCH 137/220] Fixed tab/space and added comments --- .../USBHIDMultimediaKbd.ino | 3 + hidcomposite.cpp | 78 +++++++++---------- hidcomposite.h | 4 +- 3 files changed, 44 insertions(+), 41 deletions(-) diff --git a/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino index 23a4f3d7..598d94c1 100644 --- a/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino +++ b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino @@ -7,6 +7,7 @@ #include #endif +// Override HIDComposite to be able to select which interface we want to hook into class HIDSelector : public HIDComposite { public: @@ -17,6 +18,7 @@ protected: bool SelectInterface(uint8_t iface, uint8_t proto); }; +// Return true for the interface we want to hook into bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto) { if(proto != 0) @@ -25,6 +27,7 @@ bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto) return false; } +// Will be called for all HID data received from the USB interface void HIDSelector::ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf) { #if 1 if (len && buf) { diff --git a/hidcomposite.cpp b/hidcomposite.cpp index 91a89265..a22aaa02 100644 --- a/hidcomposite.cpp +++ b/hidcomposite.cpp @@ -227,15 +227,15 @@ uint8_t HIDComposite::Init(uint8_t parent, uint8_t port, bool lowspeed) { if(rcode) goto FailSetConfDescr; - USBTRACE2("NumIface:", bNumIface); - + USBTRACE2("NumIface:", bNumIface); + for(uint8_t i = 0; i < bNumIface; i++) { if(hidInterfaces[i].epIndex[epInterruptInIndex] == 0) continue; - USBTRACE2("SetIdle:", hidInterfaces[i].bmInterface); + USBTRACE2("SetIdle:", hidInterfaces[i].bmInterface); - rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0); + rcode = SetIdle(hidInterfaces[i].bmInterface, 0, 0); if(rcode && rcode != hrSTALL) goto FailSetIdle; @@ -314,29 +314,29 @@ void HIDComposite::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint } if((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) - index = epInterruptInIndex; + index = epInterruptInIndex; else - index = epInterruptOutIndex; + index = epInterruptOutIndex; + + if(!SelectInterface(iface, proto)) + index = 0; - if(!SelectInterface(iface, proto)) - index = 0; - if(index) { - // Fill in the endpoint info structure - epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); - epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; - epInfo[bNumEP].bmSndToggle = 0; - epInfo[bNumEP].bmRcvToggle = 0; - epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT; + // Fill in the endpoint info structure + epInfo[bNumEP].epAddr = (pep->bEndpointAddress & 0x0F); + epInfo[bNumEP].maxPktSize = (uint8_t)pep->wMaxPacketSize; + epInfo[bNumEP].bmSndToggle = 0; + epInfo[bNumEP].bmRcvToggle = 0; + epInfo[bNumEP].bmNakPower = USB_NAK_NOWAIT; - // Fill in the endpoint index list - piface->epIndex[index] = bNumEP; //(pep->bEndpointAddress & 0x0F); + // Fill in the endpoint index list + piface->epIndex[index] = bNumEP; //(pep->bEndpointAddress & 0x0F); - if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints - pollInterval = pep->bInterval; + if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints + pollInterval = pep->bInterval; - bNumEP++; - } + bNumEP++; + } } uint8_t HIDComposite::Release() { @@ -367,10 +367,10 @@ uint8_t HIDComposite::Poll() { for(uint8_t i = 0; i < bNumIface; i++) { uint8_t index = hidInterfaces[i].epIndex[epInterruptInIndex]; - - if (index == 0) - continue; - + + if (index == 0) + continue; + uint16_t read = (uint16_t)epInfo[index].maxPktSize; ZeroMemory(constBuffLen, buf); @@ -382,30 +382,30 @@ uint8_t HIDComposite::Poll() { USBTRACE3("(hidcomposite.h) Poll:", rcode, 0x81); continue; } - - if(read == 0) - continue; + + if(read == 0) + continue; if(read > constBuffLen) read = constBuffLen; #if 0 - Notify(PSTR("\r\nBuf: "), 0x80); + Notify(PSTR("\r\nBuf: "), 0x80); - for(uint8_t i = 0; i < read; i++) { - D_PrintHex (buf[i], 0x80); - Notify(PSTR(" "), 0x80); - } + for(uint8_t i = 0; i < read; i++) { + D_PrintHex (buf[i], 0x80); + Notify(PSTR(" "), 0x80); + } - Notify(PSTR("\r\n"), 0x80); + Notify(PSTR("\r\n"), 0x80); #endif - ParseHIDData(this, epInfo[index].epAddr, bHasReportId, (uint8_t)read, buf); + ParseHIDData(this, epInfo[index].epAddr, bHasReportId, (uint8_t)read, buf); - HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0)); + HIDReportParser *prs = GetReportParser(((bHasReportId) ? *buf : 0)); - if(prs) - prs->Parse(this, bHasReportId, (uint8_t)read, buf); - } + if(prs) + prs->Parse(this, bHasReportId, (uint8_t)read, buf); + } } return rcode; diff --git a/hidcomposite.h b/hidcomposite.h index 6abd7933..515e033d 100644 --- a/hidcomposite.h +++ b/hidcomposite.h @@ -101,8 +101,8 @@ public: // Send report - do not mix with SetReport()! uint8_t SndRpt(uint16_t nbytes, uint8_t *dataptr); - // Returns true if we should listen on an interface, false if not - virtual bool SelectInterface(uint8_t iface, uint8_t proto) = 0; + // Returns true if we should listen on an interface, false if not + virtual bool SelectInterface(uint8_t iface, uint8_t proto) = 0; }; #endif // __HIDCOMPOSITE_H__ From fc0f7ead5db65b6ceac0809c83df59fbd2827ee1 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 14 Apr 2016 23:02:12 +0200 Subject: [PATCH 138/220] Try to enable serial debugging in Travis again --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b02d84a4..2aba1c47 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ env: - PLATFORMIO_CI_SRC=examples/Bluetooth/SPPMulti - PLATFORMIO_CI_SRC=examples/Bluetooth/Wii - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiBalanceBoard - - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera PLATFORMIO_BUILD_FLAGS="-DWIICAMERA" + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiMulti - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController - PLATFORMIO_CI_SRC=examples/board_qc @@ -55,6 +55,7 @@ env: install: - pip install -U platformio + - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA" # # Libraries from PlatformIO Library Registry: From 8f3faf2bb86e090cec99601c06a7beb28d159c6c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 14 Apr 2016 23:04:38 +0200 Subject: [PATCH 139/220] Fix bug in the MIDI driver when debugging was turned on --- usbh_midi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usbh_midi.h b/usbh_midi.h index 0cf380de..41f24b6a 100755 --- a/usbh_midi.h +++ b/usbh_midi.h @@ -61,7 +61,7 @@ protected: void parseConfigDescr(byte addr, byte conf); unsigned int countSysExDataSize(uint8_t *dataptr); -#ifdef DEBUG +#ifdef DEBUG_USB_HOST void PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ); #endif public: From 00397199706b1c1f4029f78f0bd6f3ab2ef08e3f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 14 Apr 2016 23:12:18 +0200 Subject: [PATCH 140/220] MIDI driver was not setting the debug level either --- usbh_midi.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/usbh_midi.cpp b/usbh_midi.cpp index 5612588e..5e4661d9 100755 --- a/usbh_midi.cpp +++ b/usbh_midi.cpp @@ -420,20 +420,20 @@ uint8_t USBH_MIDI::SendData(uint8_t *dataptr, byte nCable) #ifdef DEBUG_USB_HOST void USBH_MIDI::PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ) { - Notify(PSTR("Endpoint descriptor:")); - Notify(PSTR("\r\nLength:\t\t")); - PrintHex(ep_ptr->bLength); - Notify(PSTR("\r\nType:\t\t")); - PrintHex(ep_ptr->bDescriptorType); - Notify(PSTR("\r\nAddress:\t")); - PrintHex(ep_ptr->bEndpointAddress); - Notify(PSTR("\r\nAttributes:\t")); - PrintHex(ep_ptr->bmAttributes); - Notify(PSTR("\r\nMaxPktSize:\t")); - PrintHex(ep_ptr->wMaxPacketSize); - Notify(PSTR("\r\nPoll Intrv:\t")); - PrintHex(ep_ptr->bInterval); - Notify(PSTR("\r\n")); + Notify(PSTR("Endpoint descriptor:"), 0x80); + Notify(PSTR("\r\nLength:\t\t"), 0x80); + PrintHex(ep_ptr->bLength, 0x80); + Notify(PSTR("\r\nType:\t\t"), 0x80); + PrintHex(ep_ptr->bDescriptorType, 0x80); + Notify(PSTR("\r\nAddress:\t"), 0x80); + PrintHex(ep_ptr->bEndpointAddress, 0x80); + Notify(PSTR("\r\nAttributes:\t"), 0x80); + PrintHex(ep_ptr->bmAttributes, 0x80); + Notify(PSTR("\r\nMaxPktSize:\t"), 0x80); + PrintHex(ep_ptr->wMaxPacketSize, 0x80); + Notify(PSTR("\r\nPoll Intrv:\t"), 0x80); + PrintHex(ep_ptr->bInterval, 0x80); + Notify(PSTR("\r\n"), 0x80); } #endif From 8ac2035681ac2b0e1c8e3962e6709cdb2cb47256 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 14 Apr 2016 23:13:35 +0200 Subject: [PATCH 141/220] Fix indentation, whitespace and convert tabs to spaces in MIDI driver --- usbh_midi.cpp | 22 +++++++++++----------- usbh_midi.h | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/usbh_midi.cpp b/usbh_midi.cpp index 5e4661d9..d8df9691 100755 --- a/usbh_midi.cpp +++ b/usbh_midi.cpp @@ -26,7 +26,7 @@ #include "usbh_midi.h" ////////////////////////// -// MIDI MESAGES +// MIDI MESAGES // midi.org/techspecs/ ////////////////////////// // STATUS BYTES @@ -148,7 +148,7 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) // Restore p->epinfo p->epinfo = oldep_ptr; - if( rcode ){ + if( rcode ){ goto FailGetDevDescr; } @@ -159,7 +159,7 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) } // Extract Max Packet Size from device descriptor - epInfo[0].maxPktSize = udd->bMaxPacketSize0; + epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr( 0, 0, bAddress ); @@ -171,7 +171,7 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) }//if (rcode... #ifdef DEBUG_USB_HOST USBTRACE2("Addr:", bAddress); -#endif +#endif p->lowspeed = false; //get pointer to assigned address record @@ -252,7 +252,7 @@ void USBH_MIDI::parseConfigDescr( byte addr, byte conf ) rcode = pUsb->getConfDescr( addr, 0, 4, conf, buf ); if( rcode ){ return; - } + } total_length = buf[2] | ((int)buf[3] << 8); if( total_length > DESC_BUFF_SIZE ) { //check if total length is larger than buffer total_length = DESC_BUFF_SIZE; @@ -265,7 +265,7 @@ void USBH_MIDI::parseConfigDescr( byte addr, byte conf ) } //parsing descriptors - while( buf_ptr < buf + total_length ) { + while( buf_ptr < buf + total_length ) { descr_length = *( buf_ptr ); descr_type = *( buf_ptr + 1 ); switch( descr_type ) { @@ -301,7 +301,7 @@ void USBH_MIDI::parseConfigDescr( byte addr, byte conf ) break; default: break; - }//switch( descr_type + }//switch( descr_type buf_ptr += descr_length; //advance buffer pointer }//while( buf_ptr <=... } @@ -310,7 +310,7 @@ void USBH_MIDI::parseConfigDescr( byte addr, byte conf ) uint8_t USBH_MIDI::Release() { pUsb->GetAddressPool().FreeAddress(bAddress); - bNumEP = 1; //must have to be reset to 1 + bNumEP = 1; //must have to be reset to 1 bAddress = 0; bPollEnable = false; readPtr = 0; @@ -322,7 +322,7 @@ uint8_t USBH_MIDI::RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr) { *bytes_rcvd = (uint16_t)epInfo[epDataInIndex].maxPktSize; uint8_t r = pUsb->inTransfer(bAddress, epInfo[epDataInIndex].epAddr, bytes_rcvd, dataptr); - + if( *bytes_rcvd < (MIDI_EVENT_PACKET_SIZE-4)){ dataptr[*bytes_rcvd] = '\0'; dataptr[(*bytes_rcvd)+1] = '\0'; @@ -384,7 +384,7 @@ uint8_t USBH_MIDI::SendData(uint8_t *dataptr, byte nCable) buf[0] = (nCable << 4) | (msg >> 4); if( msg < 0xf0 ) msg = msg & 0xf0; - + //Building USB-MIDI Event Packets buf[1] = dataptr[0]; @@ -497,7 +497,7 @@ unsigned int USBH_MIDI::countSysExDataSize(uint8_t *dataptr) { dataptr++; c++; - + //Limiter (upto 256 bytes) if(c > 256){ c = 0; diff --git a/usbh_midi.h b/usbh_midi.h index 41f24b6a..dbd843b0 100755 --- a/usbh_midi.h +++ b/usbh_midi.h @@ -40,10 +40,10 @@ private: uint8_t lookupMsgSize(uint8_t midiMsg); protected: - static const uint8_t epDataInIndex; // DataIn endpoint index(MIDI) - static const uint8_t epDataOutIndex; // DataOUT endpoint index(MIDI) - static const uint8_t epDataInIndexVSP; // DataIn endpoint index(Vendor Specific Protocl) - static const uint8_t epDataOutIndexVSP; // DataOUT endpoint index(Vendor Specific Protocl) + static const uint8_t epDataInIndex; // DataIn endpoint index(MIDI) + static const uint8_t epDataOutIndex; // DataOUT endpoint index(MIDI) + static const uint8_t epDataInIndexVSP; // DataIn endpoint index(Vendor Specific Protocl) + static const uint8_t epDataOutIndexVSP; // DataOUT endpoint index(Vendor Specific Protocl) boolean isMidiFound; From 4727471c0cb48f1d7d36f65d377a5c8b35f751ae Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 14 Apr 2016 23:15:22 +0200 Subject: [PATCH 142/220] One more whitespace fix in the MIDI driver --- usbh_midi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usbh_midi.h b/usbh_midi.h index dbd843b0..af9b15b7 100755 --- a/usbh_midi.h +++ b/usbh_midi.h @@ -75,7 +75,7 @@ public: // backward compatibility functions inline uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr){ return RecvData(bytes_rcvd, dataptr); }; inline uint8_t RcvData(uint8_t *outBuf){ return RecvData(outBuf); }; - + // USBDeviceConfig implementation virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); virtual uint8_t Release(); From 45eddcf2dbf95068cfb11aa33ac6170974fc8f28 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 18 Apr 2016 18:01:10 +0200 Subject: [PATCH 143/220] Fixed some warnings in the MIDI driver --- usbh_midi.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/usbh_midi.h b/usbh_midi.h index af9b15b7..25436ece 100755 --- a/usbh_midi.h +++ b/usbh_midi.h @@ -45,14 +45,14 @@ protected: static const uint8_t epDataInIndexVSP; // DataIn endpoint index(Vendor Specific Protocl) static const uint8_t epDataOutIndexVSP; // DataOUT endpoint index(Vendor Specific Protocl) - boolean isMidiFound; - /* mandatory members */ USB *pUsb; uint8_t bAddress; uint8_t bConfNum; // configuration number uint8_t bNumEP; // total number of EP in the configuration bool bPollEnable; + + bool isMidiFound; /* Endpoint data structure */ EpInfo epInfo[MIDI_MAX_ENDPOINTS]; /* MIDI Event packet buffer */ @@ -79,7 +79,6 @@ public: // USBDeviceConfig implementation virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); virtual uint8_t Release(); - virtual uint8_t Poll(){}; //not implemented virtual uint8_t GetAddress() { return bAddress; }; }; From ce7c93a28175d202cddfc6145458a7e8d6494720 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 18 Apr 2016 18:04:08 +0200 Subject: [PATCH 144/220] Autoformat all MIDI examples --- .../USBH_MIDI_dump/USBH_MIDI_dump.ino | 60 +++++++++---------- .../USB_MIDI_converter/USB_MIDI_converter.ino | 38 ++++++------ .../USB_MIDI_converter_multi.ino | 50 ++++++++-------- .../bidrectional_converter.ino | 52 ++++++++-------- .../USBH_MIDI/eVY1_sample/eVY1_sample.ino | 36 +++++------ 5 files changed, 118 insertions(+), 118 deletions(-) mode change 100755 => 100644 examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino mode change 100755 => 100644 examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino mode change 100755 => 100644 examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino mode change 100755 => 100644 examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino mode change 100755 => 100644 examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino diff --git a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino old mode 100755 new mode 100644 index de58166a..b2a1a43f --- a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -36,7 +36,7 @@ void setup() Serial.begin(115200); if (Usb.Init() == -1) { - while(1); //halt + while (1); //halt }//if (Usb.Init() == -1... delay( 200 ); } @@ -47,7 +47,7 @@ void loop() Usb.Task(); t1 = micros(); - if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); } @@ -58,41 +58,41 @@ void loop() // Poll USB MIDI Controler and send to serial MIDI void MIDI_poll() { - char buf[20]; - uint8_t bufMidi[64]; - uint16_t rcvd; + char buf[20]; + uint8_t bufMidi[64]; + uint16_t rcvd; - if(Midi.vid != vid || Midi.pid != pid){ - sprintf(buf, "VID:%04X, PID:%04X", Midi.vid, Midi.pid); - Serial.println(buf); - vid = Midi.vid; - pid = Midi.pid; - } - if(Midi.RecvData( &rcvd, bufMidi) == 0 ){ - sprintf(buf, "%08X: ", millis()); - Serial.print(buf); - Serial.print(rcvd); - Serial.print(':'); - for(int i=0; i<64; i++){ - sprintf(buf, " %02X", bufMidi[i]); - Serial.print(buf); - } - Serial.println(""); + if (Midi.vid != vid || Midi.pid != pid) { + sprintf(buf, "VID:%04X, PID:%04X", Midi.vid, Midi.pid); + Serial.println(buf); + vid = Midi.vid; + pid = Midi.pid; + } + if (Midi.RecvData( &rcvd, bufMidi) == 0 ) { + sprintf(buf, "%08X: ", millis()); + Serial.print(buf); + Serial.print(rcvd); + Serial.print(':'); + for (int i = 0; i < 64; i++) { + sprintf(buf, " %02X", bufMidi[i]); + Serial.print(buf); } + Serial.println(""); + } } // Delay time (max 16383 us) void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) { - unsigned long t3; + unsigned long t3; - if( t1 > t2 ){ - t3 = (4294967295 - t1 + t2); - }else{ - t3 = t2 - t1; - } + if ( t1 > t2 ) { + t3 = (4294967295 - t1 + t2); + } else { + t3 = t2 - t1; + } - if( t3 < delayTime ){ - delayMicroseconds(delayTime - t3); - } + if ( t3 < delayTime ) { + delayMicroseconds(delayTime - t3); + } } diff --git a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino old mode 100755 new mode 100644 index d9b3acf3..c8fb4172 --- a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino @@ -42,7 +42,7 @@ void setup() _MIDI_SERIAL_PORT.begin(31250); if (Usb.Init() == -1) { - while(1); //halt + while (1); //halt }//if (Usb.Init() == -1... delay( 200 ); } @@ -53,7 +53,7 @@ void loop() Usb.Task(); t1 = micros(); - if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); } @@ -64,29 +64,29 @@ void loop() // Poll USB MIDI Controler and send to serial MIDI void MIDI_poll() { - byte outBuf[ 3 ]; - uint8_t size; + byte outBuf[ 3 ]; + uint8_t size; - do { - if( (size=Midi.RecvData(outBuf)) > 0 ){ - //MIDI Output - _MIDI_SERIAL_PORT.write(outBuf, size); - } - }while(size>0); + do { + if ( (size = Midi.RecvData(outBuf)) > 0 ) { + //MIDI Output + _MIDI_SERIAL_PORT.write(outBuf, size); + } + } while (size > 0); } // Delay time (max 16383 us) void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) { - unsigned long t3; + unsigned long t3; - if( t1 > t2 ){ - t3 = (4294967295 - t1 + t2); - }else{ - t3 = t2 - t1; - } + if ( t1 > t2 ) { + t3 = (4294967295 - t1 + t2); + } else { + t3 = t2 - t1; + } - if( t3 < delayTime ){ - delayMicroseconds(delayTime - t3); - } + if ( t3 < delayTime ) { + delayMicroseconds(delayTime - t3); + } } diff --git a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino old mode 100755 new mode 100644 index 518b1b90..bbc8bf0b --- a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino @@ -44,7 +44,7 @@ void setup() _MIDI_SERIAL_PORT.begin(31250); if (Usb.Init() == -1) { - while(1); //halt + while (1); //halt }//if (Usb.Init() == -1... delay( 200 ); } @@ -55,7 +55,7 @@ void loop() Usb.Task(); t1 = micros(); - if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); } @@ -66,35 +66,35 @@ void loop() // Poll USB MIDI Controler and send to serial MIDI void MIDI_poll() { - byte outBuf[ 3 ]; - uint8_t size; + byte outBuf[ 3 ]; + uint8_t size; - do { - if( (size=Midi1.RecvData(outBuf)) > 0 ){ - //MIDI Output - _MIDI_SERIAL_PORT.write(outBuf, size); - } - }while(size>0); - do { - if( (size=Midi2.RecvData(outBuf)) > 0 ){ - //MIDI Output - _MIDI_SERIAL_PORT.write(outBuf, size); - } - }while(size>0); + do { + if ( (size = Midi1.RecvData(outBuf)) > 0 ) { + //MIDI Output + _MIDI_SERIAL_PORT.write(outBuf, size); + } + } while (size > 0); + do { + if ( (size = Midi2.RecvData(outBuf)) > 0 ) { + //MIDI Output + _MIDI_SERIAL_PORT.write(outBuf, size); + } + } while (size > 0); } // Delay time (max 16383 us) void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) { - unsigned long t3; + unsigned long t3; - if( t1 > t2 ){ - t3 = (4294967295 - t1 + t2); - }else{ - t3 = t2 - t1; - } + if ( t1 > t2 ) { + t3 = (4294967295 - t1 + t2); + } else { + t3 = t2 - t1; + } - if( t3 < delayTime ){ - delayMicroseconds(delayTime - t3); - } + if ( t3 < delayTime ) { + delayMicroseconds(delayTime - t3); + } } diff --git a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino old mode 100755 new mode 100644 index a6646dcc..4a45bc79 --- a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino +++ b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino @@ -50,7 +50,7 @@ void setup() MIDI.begin(MIDI_CHANNEL_OMNI); if (Usb.Init() == -1) { - while(1); //halt + while (1); //halt }//if (Usb.Init() == -1... delay( 200 ); } @@ -62,19 +62,19 @@ void loop() Usb.Task(); t1 = micros(); - if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); if (MIDI.read()) { - msg[0] = MIDI.getType(); - if( msg[0] == 0xf0 ) { //SysEX - //TODO - //SysEx implementation is not yet. - }else{ - msg[1] = MIDI.getData1(); - msg[2] = MIDI.getData2(); - Midi.SendData(msg, 0); - } + msg[0] = MIDI.getType(); + if ( msg[0] == 0xf0 ) { //SysEX + //TODO + //SysEx implementation is not yet. + } else { + msg[1] = MIDI.getData1(); + msg[2] = MIDI.getData2(); + Midi.SendData(msg, 0); + } } } //delay(1ms) @@ -84,27 +84,27 @@ void loop() // Poll USB MIDI Controler and send to serial MIDI void MIDI_poll() { - byte outBuf[ 3 ]; - uint8_t size; + byte outBuf[ 3 ]; + uint8_t size; - if( (size=Midi.RecvData(outBuf)) > 0 ){ - //MIDI Output - _MIDI_SERIAL_PORT.write(outBuf, size); - } + if ( (size = Midi.RecvData(outBuf)) > 0 ) { + //MIDI Output + _MIDI_SERIAL_PORT.write(outBuf, size); + } } // Delay time (max 16383 us) void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) { - unsigned long t3; + unsigned long t3; - if( t1 > t2 ){ - t3 = (4294967295 - t1 + t2); - }else{ - t3 = t2 - t1; - } + if ( t1 > t2 ) { + t3 = (4294967295 - t1 + t2); + } else { + t3 = t2 - t1; + } - if( t3 < delayTime ){ - delayMicroseconds(delayTime - t3); - } + if ( t3 < delayTime ) { + delayMicroseconds(delayTime - t3); + } } diff --git a/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino old mode 100755 new mode 100644 index 87961056..c5984d2b --- a/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino +++ b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino @@ -24,13 +24,13 @@ void noteOn(uint8_t note); void noteOff(uint8_t note); uint16_t pid, vid; -uint8_t exdata[] ={ - 0xf0, 0x43, 0x79, 0x09, 0x00, 0x50, 0x10, - 'k',' ','o',',', //Ko - 'N','\\',',', //N - 'J',' ', 'i', ',', //Ni - 't','S',' ','i',',',//Chi - 'w',' ','a', //Wa +uint8_t exdata[] = { + 0xf0, 0x43, 0x79, 0x09, 0x00, 0x50, 0x10, + 'k', ' ', 'o', ',', //Ko + 'N', '\\', ',', //N + 'J', ' ', 'i', ',', //Ni + 't', 'S', ' ', 'i', ',', //Chi + 'w', ' ', 'a', //Wa 0x00, 0xf7 }; @@ -40,7 +40,7 @@ void setup() Serial.begin(115200); if (Usb.Init() == -1) { - while(1); //halt + while (1); //halt }//if (Usb.Init() == -1... delay( 200 ); } @@ -48,7 +48,7 @@ void setup() void loop() { Usb.Task(); - if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) + if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); noteOn(0x3f); @@ -61,15 +61,15 @@ void loop() // Poll USB MIDI Controler void MIDI_poll() { - byte inBuf[ 3 ]; - - //first call? - if(Midi.vid != vid || Midi.pid != pid){ - vid = Midi.vid; pid = Midi.pid; - Midi.SendSysEx(exdata, sizeof(exdata)); - delay(500); - } - uint8_t size = Midi.RecvData(inBuf); + byte inBuf[ 3 ]; + + //first call? + if (Midi.vid != vid || Midi.pid != pid) { + vid = Midi.vid; pid = Midi.pid; + Midi.SendSysEx(exdata, sizeof(exdata)); + delay(500); + } + uint8_t size = Midi.RecvData(inBuf); } //note On From fadf7742356483bc7937fb262500c3fe739a5aea Mon Sep 17 00:00:00 2001 From: stumpja Date: Thu, 25 Feb 2016 14:44:55 -0500 Subject: [PATCH 145/220] Update hub_demo.ino Added functionality to print device string descriptors (I.E. Manufacturer, Product Description and Serial Number. --- examples/hub_demo/hub_demo.ino | 80 +++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index d8b2d4bb..457aeb63 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -19,7 +19,7 @@ void PrintAllAddresses(UsbDevice *pdev) { UsbDeviceAddress adr; adr.devAddress = pdev->address.devAddress; - Serial.print("\r\nAddr:"); + Serial.print("Addr:"); Serial.print(adr.devAddress, HEX); Serial.print("("); Serial.print(adr.bmHub, HEX); @@ -92,6 +92,7 @@ void PrintAllDescriptors(UsbDevice *pdev) Serial.println("\r\n"); print_hex(pdev->address.devAddress, 8); Serial.println("\r\n--"); + getallstrdescr(pdev->address.devAddress); PrintDescriptors( pdev->address.devAddress ); } @@ -238,6 +239,83 @@ byte getconfdescr( byte addr, byte conf ) }//while( buf_ptr <=... return ( rcode ); } + +// function to get all string descriptors +byte getallstrdescr(uint8_t addr) +{ + byte rcode; + Usb.Task(); + if( Usb.getUsbTaskState() >= 0x80 ) { // state configuring or higher + USB_DEVICE_DESCRIPTOR buf; + rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf ); + if ( rcode ) { + return ( rcode ); + } + Serial.println("String Descriptors:"); + if( buf.iManufacturer > 0 ) { + Serial.print("Manufacturer:\t\t"); + rcode = getstrdescr( addr, buf.iManufacturer ); // get manufacturer string + if( rcode ) { + Serial.println( rcode, HEX ); + } + Serial.print("\r\n"); + } + if( buf.iProduct > 0 ) { + Serial.print("Product:\t\t"); + rcode = getstrdescr( addr, buf.iProduct ); // get product string + if( rcode ) { + Serial.println( rcode, HEX ); + } + Serial.print("\r\n"); + } + if( buf.iSerialNumber > 0 ) { + Serial.print("Serial:\t\t\t"); + rcode = getstrdescr( addr, buf.iSerialNumber ); // get serial string + if( rcode ) { + Serial.println( rcode, HEX ); + } + Serial.print("\r\n"); + } + } +} + +// function to get single string description +unsigned int getstrdescr( unsigned int addr, byte idx ) +{ + byte buf[ 66 ]; + unsigned int rcode; + byte length; + byte i; + unsigned short langid; + rcode = Usb.getStrDescr( addr, 0, 1, 0, 0, buf ); //get language table length + if( rcode ) { + Serial.println("Error retrieving LangID table length"); + return( rcode ); + } + length = buf[ 0 ]; //length is the first byte + rcode = Usb.getStrDescr( addr, 0, length, 0, 0, buf ); //get language table + if( rcode ) { + Serial.print("Error retrieving LangID table "); + return( rcode ); + } + langid = word(buf[3], buf[2]); + rcode = Usb.getStrDescr( addr, 0, 1, idx, langid, buf ); + if( rcode ) { + Serial.print("Error retrieving string length "); + return( rcode ); + } + length = buf[ 0 ]; + rcode = Usb.getStrDescr( addr, 0, length, idx, langid, buf ); + if( rcode ) { + Serial.print("Error retrieving string "); + return( rcode ); + } + for( i = 2; i < length; i+=2 ) { + Serial.print((char) buf[i]); + } + return( rcode ); +} + /* prints hex numbers with leading zeroes */ // copyright, Peter H Anderson, Baltimore, MD, Nov, '07 // source: http://www.phanderson.com/arduino/arduino_display.html From 3413f5b21ea7bdf92816b565e024e6ae67043495 Mon Sep 17 00:00:00 2001 From: stumpja Date: Fri, 26 Feb 2016 10:59:02 -0500 Subject: [PATCH 146/220] Update hub_demo.ino updated hub_demo.ino with @Lauszus suggestions --- examples/hub_demo/hub_demo.ino | 114 ++++++++++++++++----------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index 457aeb63..256e7cd6 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -60,14 +60,14 @@ void setup() next_time = millis() + 10000; } -byte getdevdescr( byte addr, byte &num_conf ); +uint8_t getdevdescr( uint8_t addr, uint8_t &num_conf ); void PrintDescriptors(uint8_t addr) { uint8_t rcode = 0; - byte num_conf = 0; + uint8_t num_conf = 0; - rcode = getdevdescr( (byte)addr, num_conf ); + rcode = getdevdescr( (uint8_t)addr, num_conf ); if ( rcode ) { printProgStr(Gen_Error_str); @@ -112,11 +112,11 @@ void loop() } } -byte getdevdescr( byte addr, byte &num_conf ) +uint8_t getdevdescr( uint8_t addr, uint8_t &num_conf ) { USB_DEVICE_DESCRIPTOR buf; - byte rcode; - rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf ); + uint8_t rcode; + rcode = Usb.getDevDescr( addr, 0, DEV_DESCR_LEN, ( uint8_t *)&buf ); if ( rcode ) { return ( rcode ); } @@ -199,13 +199,13 @@ void printhubdescr(uint8_t *descrptr, uint8_t addr) // PrintHubPortStatus(&Usb, addr, i, 1); } -byte getconfdescr( byte addr, byte conf ) +uint8_t getconfdescr( uint8_t addr, uint8_t conf ) { uint8_t buf[ BUFSIZE ]; uint8_t* buf_ptr = buf; - byte rcode; - byte descr_length; - byte descr_type; + uint8_t rcode; + uint8_t descr_length; + uint8_t descr_type; unsigned int total_length; rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length LOBYTE( total_length ) = buf[ 2 ]; @@ -241,37 +241,37 @@ byte getconfdescr( byte addr, byte conf ) } // function to get all string descriptors -byte getallstrdescr(uint8_t addr) -{ - byte rcode; +uint8_t getallstrdescr(uint8_t addr) +{ + uint8_t rcode; Usb.Task(); - if( Usb.getUsbTaskState() >= 0x80 ) { // state configuring or higher - USB_DEVICE_DESCRIPTOR buf; - rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf ); + if ( Usb.getUsbTaskState() >= USB_STATE_CONFIGURING ) { // state configuring or higher + USB_DEVICE_DESCRIPTOR buf; + rcode = Usb.getDevDescr( addr, 0, DEV_DESCR_LEN, ( uint8_t *)&buf ); if ( rcode ) { return ( rcode ); } Serial.println("String Descriptors:"); - if( buf.iManufacturer > 0 ) { + if ( buf.iManufacturer > 0 ) { Serial.print("Manufacturer:\t\t"); rcode = getstrdescr( addr, buf.iManufacturer ); // get manufacturer string - if( rcode ) { + if ( rcode ) { Serial.println( rcode, HEX ); } Serial.print("\r\n"); } - if( buf.iProduct > 0 ) { + if ( buf.iProduct > 0 ) { Serial.print("Product:\t\t"); rcode = getstrdescr( addr, buf.iProduct ); // get product string - if( rcode ) { + if ( rcode ) { Serial.println( rcode, HEX ); } Serial.print("\r\n"); } - if( buf.iSerialNumber > 0 ) { + if ( buf.iSerialNumber > 0 ) { Serial.print("Serial:\t\t\t"); rcode = getstrdescr( addr, buf.iSerialNumber ); // get serial string - if( rcode ) { + if ( rcode ) { Serial.println( rcode, HEX ); } Serial.print("\r\n"); @@ -280,40 +280,40 @@ byte getallstrdescr(uint8_t addr) } // function to get single string description -unsigned int getstrdescr( unsigned int addr, byte idx ) +unsigned int getstrdescr( unsigned int addr, uint8_t idx ) { - byte buf[ 66 ]; - unsigned int rcode; - byte length; - byte i; - unsigned short langid; - rcode = Usb.getStrDescr( addr, 0, 1, 0, 0, buf ); //get language table length - if( rcode ) { - Serial.println("Error retrieving LangID table length"); - return( rcode ); - } - length = buf[ 0 ]; //length is the first byte - rcode = Usb.getStrDescr( addr, 0, length, 0, 0, buf ); //get language table - if( rcode ) { - Serial.print("Error retrieving LangID table "); - return( rcode ); - } - langid = word(buf[3], buf[2]); - rcode = Usb.getStrDescr( addr, 0, 1, idx, langid, buf ); - if( rcode ) { - Serial.print("Error retrieving string length "); - return( rcode ); - } - length = buf[ 0 ]; - rcode = Usb.getStrDescr( addr, 0, length, idx, langid, buf ); - if( rcode ) { - Serial.print("Error retrieving string "); - return( rcode ); - } - for( i = 2; i < length; i+=2 ) { - Serial.print((char) buf[i]); - } - return( rcode ); + uint8_t buf[ 66 ]; + unsigned int rcode; + uint8_t length; + uint8_t i; + unsigned short langid; + rcode = Usb.getStrDescr( addr, 0, 1, 0, 0, buf ); //get language table length + if ( rcode ) { + Serial.println("Error retrieving LangID table length"); + return ( rcode ); + } + length = buf[ 0 ]; //length is the first byte + rcode = Usb.getStrDescr( addr, 0, length, 0, 0, buf ); //get language table + if ( rcode ) { + Serial.print("Error retrieving LangID table "); + return ( rcode ); + } + langid = word(buf[3], buf[2]); + rcode = Usb.getStrDescr( addr, 0, 1, idx, langid, buf ); + if ( rcode ) { + Serial.print("Error retrieving string length "); + return ( rcode ); + } + length = buf[ 0 ]; + rcode = Usb.getStrDescr( addr, 0, length, idx, langid, buf ); + if ( rcode ) { + Serial.print("Error retrieving string "); + return ( rcode ); + } + for ( i = 2; i < length; i += 2 ) { + Serial.print((char) buf[i]); + } + return ( rcode ); } /* prints hex numbers with leading zeroes */ @@ -397,8 +397,8 @@ void printepdescr( uint8_t* descr_ptr ) /*function to print unknown descriptor */ void printunkdescr( uint8_t* descr_ptr ) { - byte length = *descr_ptr; - byte i; + uint8_t length = *descr_ptr; + uint8_t i; printProgStr(Unk_Header_str); printProgStr(Unk_Length_str); print_hex( *descr_ptr, 8 ); From 4be94d11c5d8b317d5aa8626bd5025a4368342c0 Mon Sep 17 00:00:00 2001 From: stumpja Date: Mon, 29 Feb 2016 08:50:20 -0500 Subject: [PATCH 147/220] Update hub_demo.ino Updated code per @Lauszus request. The first item updated was a comment on LINE #308 saying that the string is UTF-16LE encoded. This is why we have to skip every second character when printing the string. The second item was figuring out the proper buffer size for LINE #280. After some research I found that the maximum string length is limited to 255 bytes since the bLength field is 1 byte long. I changed the buffer size to 256 to accommodate for this. Finally, I cleaned up some of the code to make it more consistent. This is purely aesthetic, and subjective at that. --- examples/hub_demo/hub_demo.ino | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index 256e7cd6..d9773e5d 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -68,18 +68,15 @@ void PrintDescriptors(uint8_t addr) uint8_t num_conf = 0; rcode = getdevdescr( (uint8_t)addr, num_conf ); - if ( rcode ) - { + if ( rcode ) { printProgStr(Gen_Error_str); print_hex( rcode, 8 ); } Serial.print("\r\n"); - for (int i = 0; i < num_conf; i++) - { + for (int i = 0; i < num_conf; i++) { rcode = getconfdescr( addr, i ); // get configuration descriptor - if ( rcode ) - { + if ( rcode ) { printProgStr(Gen_Error_str); print_hex(rcode, 8); } @@ -100,10 +97,8 @@ void loop() { Usb.Task(); - if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) - { - if ((millis() - next_time) >= 0L) - { + if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { + if ((millis() - next_time) >= 0L) { Usb.ForEachUsbDevice(&PrintAllDescriptors); Usb.ForEachUsbDevice(&PrintAllAddresses); @@ -282,7 +277,7 @@ uint8_t getallstrdescr(uint8_t addr) // function to get single string description unsigned int getstrdescr( unsigned int addr, uint8_t idx ) { - uint8_t buf[ 66 ]; + uint8_t buf[ 256 ]; unsigned int rcode; uint8_t length; uint8_t i; @@ -310,7 +305,7 @@ unsigned int getstrdescr( unsigned int addr, uint8_t idx ) Serial.print("Error retrieving string "); return ( rcode ); } - for ( i = 2; i < length; i += 2 ) { + for ( i = 2; i < length; i += 2 ) { //string is UTF-16LE encoded Serial.print((char) buf[i]); } return ( rcode ); @@ -338,6 +333,7 @@ void print_hex(int v, int num_places) } while (--num_nibbles); } + /* function to print configuration descriptor */ void printconfdescr( uint8_t* descr_ptr ) { @@ -357,6 +353,7 @@ void printconfdescr( uint8_t* descr_ptr ) print_hex( conf_ptr->bMaxPower, 8 ); return; } + /* function to print interface descriptor */ void printintfdescr( uint8_t* descr_ptr ) { @@ -378,6 +375,7 @@ void printintfdescr( uint8_t* descr_ptr ) print_hex( intf_ptr->iInterface, 8 ); return; } + /* function to print endpoint descriptor */ void printepdescr( uint8_t* descr_ptr ) { @@ -394,6 +392,7 @@ void printepdescr( uint8_t* descr_ptr ) return; } + /*function to print unknown descriptor */ void printunkdescr( uint8_t* descr_ptr ) { From 5feb32601c58bd923625cf841dadbfc11762c2b0 Mon Sep 17 00:00:00 2001 From: stumpja Date: Tue, 5 Apr 2016 11:44:27 -0400 Subject: [PATCH 148/220] Update hub_demo.ino --- examples/hub_demo/hub_demo.ino | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index d9773e5d..ad2fa2cb 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -74,7 +74,7 @@ void PrintDescriptors(uint8_t addr) } Serial.print("\r\n"); - for (int i = 0; i < num_conf; i++) { + for (uint8_t i = 0; i < num_conf; i++) { rcode = getconfdescr( addr, i ); // get configuration descriptor if ( rcode ) { printProgStr(Gen_Error_str); @@ -201,7 +201,7 @@ uint8_t getconfdescr( uint8_t addr, uint8_t conf ) uint8_t rcode; uint8_t descr_length; uint8_t descr_type; - unsigned int total_length; + uint16_t total_length; rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length LOBYTE( total_length ) = buf[ 2 ]; HIBYTE( total_length ) = buf[ 3 ]; @@ -275,13 +275,13 @@ uint8_t getallstrdescr(uint8_t addr) } // function to get single string description -unsigned int getstrdescr( unsigned int addr, uint8_t idx ) +uint8_t getstrdescr( uint8_t addr, uint8_t idx ) { uint8_t buf[ 256 ]; - unsigned int rcode; + uint8_t rcode; uint8_t length; uint8_t i; - unsigned short langid; + uint16_t langid; rcode = Usb.getStrDescr( addr, 0, 1, 0, 0, buf ); //get language table length if ( rcode ) { Serial.println("Error retrieving LangID table length"); @@ -293,7 +293,7 @@ unsigned int getstrdescr( unsigned int addr, uint8_t idx ) Serial.print("Error retrieving LangID table "); return ( rcode ); } - langid = word(buf[3], buf[2]); + langid = (buf[3] << 8) | buf[2]; rcode = Usb.getStrDescr( addr, 0, 1, idx, langid, buf ); if ( rcode ) { Serial.print("Error retrieving string length "); @@ -411,7 +411,6 @@ void printunkdescr( uint8_t* descr_ptr ) } } - /* Print a string from Program Memory directly to save RAM */ void printProgStr(const char* str) { From 178af85a26159fc0ca5371fffabd6eafd2b48030 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 11:20:54 +0200 Subject: [PATCH 149/220] Fixed warning and remove function prototype --- examples/hub_demo/hub_demo.ino | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index ad2fa2cb..adc1751f 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -60,8 +60,6 @@ void setup() next_time = millis() + 10000; } -uint8_t getdevdescr( uint8_t addr, uint8_t &num_conf ); - void PrintDescriptors(uint8_t addr) { uint8_t rcode = 0; @@ -238,7 +236,7 @@ uint8_t getconfdescr( uint8_t addr, uint8_t conf ) // function to get all string descriptors uint8_t getallstrdescr(uint8_t addr) { - uint8_t rcode; + uint8_t rcode = 0; Usb.Task(); if ( Usb.getUsbTaskState() >= USB_STATE_CONFIGURING ) { // state configuring or higher USB_DEVICE_DESCRIPTOR buf; @@ -272,6 +270,7 @@ uint8_t getallstrdescr(uint8_t addr) Serial.print("\r\n"); } } + return rcode; } // function to get single string description From 854fb80e0891a8c82d0c84c8af84a3c93166e70b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 11:34:04 +0200 Subject: [PATCH 150/220] Autoformat USBHIDMultimediaKbd example No code change --- .../USBHIDMultimediaKbd.ino | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino index 598d94c1..f3b79dce 100644 --- a/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino +++ b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino @@ -11,17 +11,17 @@ class HIDSelector : public HIDComposite { public: - HIDSelector(USB *p) : HIDComposite(p) {}; + HIDSelector(USB *p) : HIDComposite(p) {}; protected: - void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDComposite library - bool SelectInterface(uint8_t iface, uint8_t proto); + void ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDComposite library + bool SelectInterface(uint8_t iface, uint8_t proto); }; // Return true for the interface we want to hook into bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto) { - if(proto != 0) + if (proto != 0) return true; return false; @@ -30,22 +30,20 @@ bool HIDSelector::SelectInterface(uint8_t iface, uint8_t proto) // Will be called for all HID data received from the USB interface void HIDSelector::ParseHIDData(USBHID *hid, uint8_t ep, bool is_rpt_id, uint8_t len, uint8_t *buf) { #if 1 - if (len && buf) { - Notify(PSTR("\r\n"), 0x80); - for (uint8_t i = 0; i < len; i++) { - D_PrintHex (buf[i], 0x80); - Notify(PSTR(" "), 0x80); - } - } + if (len && buf) { + Notify(PSTR("\r\n"), 0x80); + for (uint8_t i = 0; i < len; i++) { + D_PrintHex (buf[i], 0x80); + Notify(PSTR(" "), 0x80); + } + } #endif } - USB Usb; //USBHub Hub(&Usb); HIDSelector hidSelector(&Usb); - void setup() { Serial.begin( 115200 ); From 00658d60ebc00dccf7e194d3564c4065783d8810 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 11:48:51 +0200 Subject: [PATCH 151/220] Fixed typo --- BTD.cpp | 6 +++--- BTD.h | 2 +- BTHID.h | 2 +- README.md | 2 +- Wii.h | 2 +- examples/Bluetooth/PS4BT/PS4BT.ino | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 05ef4901..7eda8fd5 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -589,7 +589,7 @@ void BTD::HCI_event_task() { break; case EV_AUTHENTICATION_COMPLETE: - if(!hcibuf[2]) { // Check if paring was successful + if(!hcibuf[2]) { // Check if pairing was successful if(pairWithWii && !connectToWii) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nPairing successful with Wiimote"), 0x80); @@ -603,7 +603,7 @@ void BTD::HCI_event_task() { } } else { #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nParing Failed: "), 0x80); + Notify(PSTR("\r\nPairing Failed: "), 0x80); D_PrintHex (hcibuf[2], 0x80); #endif hci_disconnect(hci_handle); @@ -1110,7 +1110,7 @@ void BTD::hci_pin_code_request_reply() { hcibuf[9] = 6; // Pin length is the length of the Bluetooth address if(pairWiiUsingSync) { #ifdef DEBUG_USB_HOST - Notify(PSTR("\r\nParing with Wii controller via SYNC"), 0x80); + Notify(PSTR("\r\nPairing with Wii controller via SYNC"), 0x80); #endif for(uint8_t i = 0; i < 6; i++) hcibuf[10 + i] = my_bdaddr[i]; // The pin is the Bluetooth dongles Bluetooth address backwards diff --git a/BTD.h b/BTD.h index 214931a8..d3f735b8 100755 --- a/BTD.h +++ b/BTD.h @@ -535,7 +535,7 @@ private: uint8_t pollInterval; bool bPollEnable; - bool pairWiiUsingSync; // True if paring was done using the Wii SYNC button. + bool pairWiiUsingSync; // True if pairing was done using the Wii SYNC button. bool checkRemoteName; // Used to check remote device's name before connecting. bool incomingPS4; // True if a PS4 controller is connecting uint8_t classOfDevice[3]; // Class of device of last device diff --git a/BTHID.h b/BTHID.h index ac9128a2..282b832e 100644 --- a/BTHID.h +++ b/BTHID.h @@ -87,7 +87,7 @@ public: /** True if a device is connected */ bool connected; - /** Call this to start the paring sequence with a device */ + /** Call this to start the pairing sequence with a device */ void pair(void) { if(pBtd) pBtd->pairWithHID(); diff --git a/README.md b/README.md index 3c9d8e0d..c98c5692 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ The [PS4BT.ino](examples/Bluetooth/PS4BT/PS4BT.ino) and [PS4USB.ino](examples/PS Before you can use the PS4 controller via Bluetooth you will need to pair with it. -Simply create the PS4BT instance like so: ```PS4BT PS4(&Btd, PAIR);``` and then hold down the Share button and then hold down the PS without releasing the Share button. The PS4 controller will then start to blink rapidly indicating that it is in paring mode. +Simply create the PS4BT instance like so: ```PS4BT PS4(&Btd, PAIR);``` and then hold down the Share button and then hold down the PS without releasing the Share button. The PS4 controller will then start to blink rapidly indicating that it is in pairing mode. It should then automatically pair the dongle with your controller. This only have to be done once. diff --git a/Wii.h b/Wii.h index efb64b2f..5360682f 100755 --- a/Wii.h +++ b/Wii.h @@ -85,7 +85,7 @@ public: /** @name Wii Controller functions */ - /** Call this to start the paring sequence with a controller */ + /** Call this to start the pairing sequence with a controller */ void pair(void) { if(pBtd) pBtd->pairWithWiimote(); diff --git a/examples/Bluetooth/PS4BT/PS4BT.ino b/examples/Bluetooth/PS4BT/PS4BT.ino index c3ba696b..9cac6cdc 100644 --- a/examples/Bluetooth/PS4BT/PS4BT.ino +++ b/examples/Bluetooth/PS4BT/PS4BT.ino @@ -19,7 +19,7 @@ BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so /* You can create the instance of the PS4BT class in two ways */ // This will start an inquiry and then pair with the PS4 controller - you only have to do this once -// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in paring mode +// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in pairing mode PS4BT PS4(&Btd, PAIR); // After that you can simply create the instance like so and then press the PS button on the device From 38ed04fe771428f59e7a6246bde56887b80556d1 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 12:03:39 +0200 Subject: [PATCH 152/220] Turn on warnings when building using Travis and make all warnings errors This should catch warnings when people are sending PRs. For instance: https://github.com/felis/USB_Host_Shield_2.0/commit/178af85a26159fc0ca5371fffabd6eafd2b48030 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2aba1c47..9a6d94c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,7 +55,7 @@ env: install: - pip install -U platformio - - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA" + - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror" # # Libraries from PlatformIO Library Registry: From 9d4f9108e6aac16eafc780971c2b01b4dfd92f63 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 16:54:31 +0200 Subject: [PATCH 153/220] Fix warnings on Arduino Due --- settings.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/settings.h b/settings.h index 97b46a0b..af0eb175 100644 --- a/settings.h +++ b/settings.h @@ -152,4 +152,23 @@ e-mail : support@circuitsathome.com extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp #endif +// Fix defines on Arduino Due +#ifdef ARDUINO_SAM_DUE +#ifdef tokSETUP +#undef tokSETUP +#endif +#ifdef tokIN +#undef tokIN +#endif +#ifdef tokOUT +#undef tokOUT +#endif +#ifdef tokINHS +#undef tokINHS +#endif +#ifdef tokOUTHS +#undef tokOUTHS +#endif +#endif + #endif /* SETTINGS_H */ From 2ab25f0382ccf21ca5c803f0953157a5479f1fde Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 17:03:42 +0200 Subject: [PATCH 154/220] Fix unused-but-set-variable warning --- examples/adk/adk_barcode/adk_barcode.ino | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/adk/adk_barcode/adk_barcode.ino b/examples/adk/adk_barcode/adk_barcode.ino index e671c661..9417617d 100644 --- a/examples/adk/adk_barcode/adk_barcode.ino +++ b/examples/adk/adk_barcode/adk_barcode.ino @@ -55,9 +55,17 @@ uint8_t keylcl; if( keylcl == 0x13 ) { rcode = adk.SndData( strlen( new_line ), (uint8_t *)new_line ); + if (rcode && rcode != hrNAK) { + Serial.print(F("\r\nData send: ")); + Serial.print(rcode, HEX); + } } else { rcode = adk.SndData( 1, &keylcl ); + if (rcode && rcode != hrNAK) { + Serial.print(F("\r\nData send: ")); + Serial.print(rcode, HEX); + } } Serial.print((char) keylcl ); From 938880b71da838da8012b42c72e1f9c5127b990e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 17:04:20 +0200 Subject: [PATCH 155/220] Ignore strict-aliasing warning --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9a6d94c9..b480a181 100644 --- a/.travis.yml +++ b/.travis.yml @@ -55,7 +55,7 @@ env: install: - pip install -U platformio - - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror" + - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror -Wno-strict-aliasing" # # Libraries from PlatformIO Library Registry: From 14021813ef323ef3e29d5f6db64c7c466c101813 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 17:12:10 +0200 Subject: [PATCH 156/220] Fix some more unused-but-set-variable warnings And autoformat some of the examples --- examples/adk/term_test/term_test.ino | 60 ++++++++++++++++------------ examples/adk/term_time/term_time.ino | 48 ++++++++++++---------- 2 files changed, 62 insertions(+), 46 deletions(-) diff --git a/examples/adk/term_test/term_test.ino b/examples/adk/term_test/term_test.ino index db681c3b..2dea73fd 100644 --- a/examples/adk/term_test/term_test.ino +++ b/examples/adk/term_test/term_test.ino @@ -10,25 +10,25 @@ USB Usb; //USBHub Hub(&Usb); -ADK adk(&Usb,"Circuits@Home, ltd.", - "USB Host Shield", - "Arduino Terminal for Android", - "1.0", - "http://www.circuitsathome.com", - "0000000000000001"); +ADK adk(&Usb, "Circuits@Home, ltd.", + "USB Host Shield", + "Arduino Terminal for Android", + "1.0", + "http://www.circuitsathome.com", + "0000000000000001"); void setup() { - Serial.begin(115200); + Serial.begin(115200); #if !defined(__MIPSEL__) while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection #endif - Serial.println("\r\nADK demo start"); + Serial.println("\r\nADK demo start"); - if (Usb.Init() == -1) { - Serial.println("OSCOKIRQ failed to assert"); - while(1); //halt - }//if (Usb.Init() == -1... + if (Usb.Init() == -1) { + Serial.println("OSCOKIRQ failed to assert"); + while (1); //halt + }//if (Usb.Init() == -1... } void loop() @@ -37,29 +37,37 @@ void loop() uint8_t msg[64] = { 0x00 }; const char* recv = "Received: "; - Usb.Task(); + Usb.Task(); - if( adk.isReady() == false ) { - return; - } - uint16_t len = 64; + if ( adk.isReady() == false ) { + return; + } + uint16_t len = 64; - rcode = adk.RcvData(&len, msg); - if( rcode & ( rcode != hrNAK )) { - USBTRACE2("Data rcv. :", rcode ); - } - if(len > 0) { - USBTRACE("\r\nData Packet."); + rcode = adk.RcvData(&len, msg); + if ( rcode & ( rcode != hrNAK )) { + USBTRACE2("Data rcv. :", rcode ); + } + if (len > 0) { + USBTRACE("\r\nData Packet."); - for( uint8_t i = 0; i < len; i++ ) { + for ( uint8_t i = 0; i < len; i++ ) { Serial.print((char)msg[i]); } /* sending back what was received */ rcode = adk.SndData( strlen( recv ), (uint8_t *)recv ); + if (rcode && rcode != hrNAK) { + Serial.print(F("\r\nData send: ")); + Serial.print(rcode, HEX); + } rcode = adk.SndData( strlen(( char * )msg ), msg ); + if (rcode && rcode != hrNAK) { + Serial.print(F("\r\nData send: ")); + Serial.print(rcode, HEX); + } - }//if( len > 0 )... + }//if( len > 0 )... - delay( 1000 ); + delay( 1000 ); } diff --git a/examples/adk/term_time/term_time.ino b/examples/adk/term_time/term_time.ino index a3f1dbc8..778fb28f 100644 --- a/examples/adk/term_time/term_time.ino +++ b/examples/adk/term_time/term_time.ino @@ -9,25 +9,25 @@ USB Usb; -ADK adk(&Usb,"Circuits@Home, ltd.", - "USB Host Shield", - "Arduino Terminal for Android", - "1.0", - "http://www.circuitsathome.com", - "0000000000000001"); +ADK adk(&Usb, "Circuits@Home, ltd.", + "USB Host Shield", + "Arduino Terminal for Android", + "1.0", + "http://www.circuitsathome.com", + "0000000000000001"); void setup() { - Serial.begin(115200); + Serial.begin(115200); #if !defined(__MIPSEL__) while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection #endif - Serial.println("\r\nADK demo start"); + Serial.println("\r\nADK demo start"); - if (Usb.Init() == -1) { - Serial.println("OSCOKIRQ failed to assert"); - while(1); //halt - }//if (Usb.Init() == -1... + if (Usb.Init() == -1) { + Serial.println("OSCOKIRQ failed to assert"); + while (1); //halt + }//if (Usb.Init() == -1... } void loop() @@ -36,15 +36,23 @@ void loop() const char* sec_ela = " seconds elapsed\r"; uint8_t rcode; - Usb.Task(); - if( adk.isReady() == false ) { - return; - } + Usb.Task(); + if ( adk.isReady() == false ) { + return; + } - ultoa( millis()/1000, (char *)buf, 10 ); + ultoa( millis() / 1000, (char *)buf, 10 ); - rcode = adk.SndData( strlen((char *)buf), buf ); - rcode = adk.SndData( strlen( sec_ela), (uint8_t *)sec_ela ); + rcode = adk.SndData( strlen((char *)buf), buf ); + if (rcode && rcode != hrNAK) { + Serial.print(F("\r\nData send: ")); + Serial.print(rcode, HEX); + } + rcode = adk.SndData( strlen( sec_ela), (uint8_t *)sec_ela ); + if (rcode && rcode != hrNAK) { + Serial.print(F("\r\nData send: ")); + Serial.print(rcode, HEX); + } - delay( 1000 ); + delay( 1000 ); } From 51dde0252e7f1cd101ab2855bb7f4204b418a39e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 17:27:12 +0200 Subject: [PATCH 157/220] Fixed error=parentheses warning --- examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp b/examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp index 732b564a..7fa145ad 100644 --- a/examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp +++ b/examples/HID/USBHIDJoystick/hidjoystickrptparser.cpp @@ -43,11 +43,12 @@ void JoystickReportParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8 for (uint8_t i = 0; i < 0x0C; i++) { uint16_t mask = (0x0001 << i); - if (((mask & changes) > 0) && joyEvents) + if (((mask & changes) > 0) && joyEvents) { if ((buttons & mask) > 0) joyEvents->OnButtonDn(i + 1); else joyEvents->OnButtonUp(i + 1); + } } oldButtons = buttons; } From 421e8dea4b7a8c1b907cf35c6ad7e44908d592a7 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 19 Apr 2016 18:10:01 +0200 Subject: [PATCH 158/220] Fixed some documentation in the Wii driver --- Wii.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Wii.h b/Wii.h index 5360682f..dde886b3 100755 --- a/Wii.h +++ b/Wii.h @@ -276,21 +276,21 @@ public: /** * Used to get the weight at the specific position on the Wii Balance Board. - * @param ::BalanceBoardEnum to read from. - * @return Returns the weight in kg. + * @param pos ::BalanceBoardEnum to read from. + * @return Returns the weight in kg. */ float getWeight(BalanceBoardEnum pos); /** * Used to get total weight on the Wii Balance Board. - * @returnReturns the weight in kg. + * @return Returns the weight in kg. */ float getTotalWeight(); /** * Used to get the raw reading at the specific position on the Wii Balance Board. - * @param ::BalanceBoardEnum to read from. - * @return Returns the raw reading. + * @param pos ::BalanceBoardEnum to read from. + * @return Returns the raw reading. */ uint16_t getWeightRaw(BalanceBoardEnum pos) { return wiiBalanceBoardRaw[pos]; From 412c6665e2a3dc3480c23347323536099d7cdf6f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 24 Apr 2016 01:38:08 +0200 Subject: [PATCH 159/220] Added some missing examples to travis build --- .travis.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b480a181..e280d86f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ cache: directories: - "~/.platformio" +# Generated using: find examples -type f -name "*.ino" | rev | cut -d/ -f2- | rev | sed 's/^/ - PLATFORMIO_CI_SRC=/' > tmp.yml env: - PLATFORMIO_CI_SRC=examples/acm/acm_terminal - PLATFORMIO_CI_SRC=examples/adk/adk_barcode @@ -32,11 +33,13 @@ env: - PLATFORMIO_CI_SRC=examples/ftdi/USBFTDILoopback - PLATFORMIO_CI_SRC=examples/HID/le3dp - PLATFORMIO_CI_SRC=examples/HID/scale + - PLATFORMIO_CI_SRC=examples/HID/SRWS1 - PLATFORMIO_CI_SRC=examples/HID/USBHID_desc - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbd - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootKbdAndMouse - PLATFORMIO_CI_SRC=examples/HID/USBHIDBootMouse - PLATFORMIO_CI_SRC=examples/HID/USBHIDJoystick + - PLATFORMIO_CI_SRC=examples/HID/USBHIDMultimediaKbd - PLATFORMIO_CI_SRC=examples/hub_demo - PLATFORMIO_CI_SRC=examples/max_LCD - PLATFORMIO_CI_SRC=examples/pl2303/pl2303_gprs_terminal @@ -46,8 +49,13 @@ env: - PLATFORMIO_CI_SRC=examples/PS3USB - PLATFORMIO_CI_SRC=examples/PS4USB - PLATFORMIO_CI_SRC=examples/PSBuzz -# - PLATFORMIO_CI_SRC=examples/testusbhostFAT/testusbhostFAT.ino + # - PLATFORMIO_CI_SRC=examples/testusbhostFAT - PLATFORMIO_CI_SRC=examples/USB_desc + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/eVY1_sample + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter_multi + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USBH_MIDI_dump - PLATFORMIO_CI_SRC=examples/Xbox/XBOXOLD - PLATFORMIO_CI_SRC=examples/Xbox/XBOXONE - PLATFORMIO_CI_SRC=examples/Xbox/XBOXRECV From 738adc67f6b6386289bd590b065cea0a1ae015e8 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 24 Apr 2016 02:02:33 +0200 Subject: [PATCH 160/220] Fixed some warnings in the MIDI examples --- .travis.yml | 7 ++++--- examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino | 6 +++--- .../USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino | 2 +- .../USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino | 2 +- .../bidrectional_converter/bidrectional_converter.ino | 2 +- examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index e280d86f..c9351a50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,9 +68,10 @@ install: # # Libraries from PlatformIO Library Registry: # - # http://platformio.org/#!/lib/show/416/TinyGPS - # http://platformio.org/#!/lib/show/417/SPI4Teensy3 - - platformio lib install 416 417 + # http://platformio.org/lib/show/62/MIDI + # http://platformio.org/lib/show/416/TinyGPS + # http://platformio.org/lib/show/417/SPI4Teensy3 + - platformio lib install 62 416 417 script: - platformio ci --board=uno --board=teensy31 --board=due --lib="." 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 b2a1a43f..68d3472d 100644 --- a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -43,10 +43,10 @@ void setup() void loop() { - unsigned long t1; + //unsigned long t1; Usb.Task(); - t1 = micros(); + //t1 = micros(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); @@ -69,7 +69,7 @@ void MIDI_poll() pid = Midi.pid; } if (Midi.RecvData( &rcvd, bufMidi) == 0 ) { - sprintf(buf, "%08X: ", millis()); + sprintf(buf, "%08lX: ", millis()); Serial.print(buf); Serial.print(rcvd); Serial.print(':'); diff --git a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino index c8fb4172..589fe20d 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino @@ -81,7 +81,7 @@ void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) unsigned long t3; if ( t1 > t2 ) { - t3 = (4294967295 - t1 + t2); + t3 = (0xFFFFFFFF - t1 + t2); } else { t3 = t2 - t1; } diff --git a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino index bbc8bf0b..ffed71ab 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino @@ -89,7 +89,7 @@ void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) unsigned long t3; if ( t1 > t2 ) { - t3 = (4294967295 - t1 + t2); + t3 = (0xFFFFFFFF - t1 + t2); } else { t3 = t2 - t1; } diff --git a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino index 4a45bc79..f681cfb9 100644 --- a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino +++ b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino @@ -99,7 +99,7 @@ void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) unsigned long t3; if ( t1 > t2 ) { - t3 = (4294967295 - t1 + t2); + t3 = (0xFFFFFFFF - t1 + t2); } else { t3 = t2 - t1; } diff --git a/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino index c5984d2b..2d42c3d9 100644 --- a/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino +++ b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino @@ -69,7 +69,7 @@ void MIDI_poll() Midi.SendSysEx(exdata, sizeof(exdata)); delay(500); } - uint8_t size = Midi.RecvData(inBuf); + Midi.RecvData(inBuf); } //note On From c2a0c98d7116d8a8070fdc9ca09f886085d1c73f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 24 Apr 2016 02:37:34 +0200 Subject: [PATCH 161/220] Disable some more warnings in the MIDI examples --- .travis.yml | 4 ++-- examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9351a50..cdfa64f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ env: - PLATFORMIO_CI_SRC=examples/PSBuzz # - PLATFORMIO_CI_SRC=examples/testusbhostFAT - PLATFORMIO_CI_SRC=examples/USB_desc - - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter PLATFORMIO_CI_EXTRA_ARGS="-Wno-error -Wno-parentheses" - PLATFORMIO_CI_SRC=examples/USBH_MIDI/eVY1_sample - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter_multi @@ -74,4 +74,4 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=teensy31 --board=due --lib="." + - platformio ci --board=uno --board=teensy31 --board=due --lib="." $PLATFORMIO_CI_EXTRA_ARGS 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 68d3472d..db8faadb 100644 --- a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -87,7 +87,7 @@ void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) unsigned long t3; if ( t1 > t2 ) { - t3 = (4294967295 - t1 + t2); + t3 = (0xFFFFFFFF - t1 + t2); } else { t3 = t2 - t1; } From 0c70f742dbf7b3a6c66e0d1570f754fabbc17223 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 24 Apr 2016 02:51:10 +0200 Subject: [PATCH 162/220] Don't treat warnings as errors in the bidrectional_converter example --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cdfa64f8..f4985001 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ env: - PLATFORMIO_CI_SRC=examples/PSBuzz # - PLATFORMIO_CI_SRC=examples/testusbhostFAT - PLATFORMIO_CI_SRC=examples/USB_desc - - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter PLATFORMIO_CI_EXTRA_ARGS="-Wno-error -Wno-parentheses" + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Wno-strict-aliasing" - PLATFORMIO_CI_SRC=examples/USBH_MIDI/eVY1_sample - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter_multi @@ -74,4 +74,4 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=teensy31 --board=due --lib="." $PLATFORMIO_CI_EXTRA_ARGS + - platformio ci --board=uno --board=teensy31 --board=due --lib="." From 43b0736cf3e156bf258e91dcd03018dd88e15c82 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 24 Apr 2016 09:58:03 +0200 Subject: [PATCH 163/220] Just skip the bidrectional_converter example for now --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f4985001..95eda42a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ env: - PLATFORMIO_CI_SRC=examples/PSBuzz # - PLATFORMIO_CI_SRC=examples/testusbhostFAT - PLATFORMIO_CI_SRC=examples/USB_desc - - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Wno-strict-aliasing" + # - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter - PLATFORMIO_CI_SRC=examples/USBH_MIDI/eVY1_sample - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter_multi From 7efc0c766eb3605ebd953a407a543db7b6d33f28 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 24 Apr 2016 23:49:53 +0200 Subject: [PATCH 164/220] Warnings in the MIDI library were fixed upstream: https://github.com/FortySevenEffects/arduino_midi_library/commit/5b3e4ac0977a2a66ccb62e39f6c6c96aa6d3cdc4. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 95eda42a..c9351a50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ env: - PLATFORMIO_CI_SRC=examples/PSBuzz # - PLATFORMIO_CI_SRC=examples/testusbhostFAT - PLATFORMIO_CI_SRC=examples/USB_desc - # - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter - PLATFORMIO_CI_SRC=examples/USBH_MIDI/eVY1_sample - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter_multi From f369e7c500479c7338b092393d5b9b00c01d4691 Mon Sep 17 00:00:00 2001 From: Yuuichi Akagawa Date: Tue, 26 Apr 2016 23:44:07 +0900 Subject: [PATCH 165/220] update MIDI driver v0.3.1 --- README.md | 4 +- .../USB_MIDI_converter/USB_MIDI_converter.ino | 2 +- .../USB_MIDI_converter_multi.ino | 2 +- .../bidrectional_converter.ino | 83 ++++++- .../USBH_MIDI/eVY1_sample/eVY1_sample.ino | 2 +- usbh_midi.cpp | 224 ++++++++++++------ usbh_midi.h | 34 ++- 7 files changed, 258 insertions(+), 93 deletions(-) mode change 100755 => 100644 usbh_midi.cpp mode change 100755 => 100644 usbh_midi.h diff --git a/README.md b/README.md index c98c5692..e7345efb 100644 --- a/README.md +++ b/README.md @@ -320,8 +320,8 @@ HID devices are also supported by the library. However these require you to writ The library support MIDI devices. You can convert USB MIDI keyboard to legacy serial MIDI. -* [USB_MIDI_converter.ino](USBH_MIDI/USB_MIDI_converter) -* [USB_MIDI_converter_multi.ino](USBH_MIDI/USB_MIDI_converter_multi) +* [USB_MIDI_converter.ino](examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino) +* [USB_MIDI_converter_multi.ino](examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino) For information see the following page: . diff --git a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino index 589fe20d..38547a1b 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino @@ -64,7 +64,7 @@ void loop() // Poll USB MIDI Controler and send to serial MIDI void MIDI_poll() { - byte outBuf[ 3 ]; + uint8_t outBuf[ 3 ]; uint8_t size; do { diff --git a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino index ffed71ab..a4ddd333 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino @@ -66,7 +66,7 @@ void loop() // Poll USB MIDI Controler and send to serial MIDI void MIDI_poll() { - byte outBuf[ 3 ]; + uint8_t outBuf[ 3 ]; uint8_t size; do { diff --git a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino index f681cfb9..d5906c9f 100644 --- a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino +++ b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino @@ -40,15 +40,28 @@ MIDI_CREATE_DEFAULT_INSTANCE(); ////////////////////////// USB Usb; -USBH_MIDI Midi(&Usb); +USBH_MIDI Midi(&Usb); void MIDI_poll(); void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); +//If you want handle System Exclusive message, enable this #define otherwise comment out it. +#define USBH_MIDI_SYSEX_ENABLE + +#ifdef USBH_MIDI_SYSEX_ENABLE +MidiSysEx sysExData; +//SysEx: +void handle_sysex( byte* sysexmsg, uint16_t sizeofsysex) { + Midi.SendSysEx(sysexmsg, sizeofsysex); +} +#endif + void setup() { MIDI.begin(MIDI_CHANNEL_OMNI); - +#ifdef USBH_MIDI_SYSEX_ENABLE + MIDI.setHandleSystemExclusive(handle_sysex); +#endif if (Usb.Init() == -1) { while (1); //halt }//if (Usb.Init() == -1... @@ -67,13 +80,17 @@ void loop() MIDI_poll(); if (MIDI.read()) { msg[0] = MIDI.getType(); - if ( msg[0] == 0xf0 ) { //SysEX - //TODO - //SysEx implementation is not yet. - } else { - msg[1] = MIDI.getData1(); - msg[2] = MIDI.getData2(); - Midi.SendData(msg, 0); + switch (msg[0]) { + case midi::ActiveSensing : + break; + case midi::SystemExclusive : + //SysEx is handled by event. + break; + default : + msg[1] = MIDI.getData1(); + msg[2] = MIDI.getData2(); + Midi.SendData(msg, 0); + break; } } } @@ -84,13 +101,53 @@ void loop() // Poll USB MIDI Controler and send to serial MIDI void MIDI_poll() { - byte outBuf[ 3 ]; uint8_t size; +#ifdef USBH_MIDI_SYSEX_ENABLE + uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE]; + uint8_t rcode = 0; //return code + uint16_t rcvd; + uint8_t readPtr = 0; - if ( (size = Midi.RecvData(outBuf)) > 0 ) { - //MIDI Output - _MIDI_SERIAL_PORT.write(outBuf, size); + rcode = Midi.RecvData( &rcvd, recvBuf); + + //data check + if (rcode != 0) return; + if ( recvBuf[0] == 0 && recvBuf[1] == 0 && recvBuf[2] == 0 && recvBuf[3] == 0 ) { + return ; } + + uint8_t *p = recvBuf; + while (readPtr < MIDI_EVENT_PACKET_SIZE) { + if (*p == 0 && *(p + 1) == 0) break; //data end + MidiSysEx::Status rc = sysExData.set(p); + switch (rc) { + case MidiSysEx::nonsysex : //No SysEx message send data to Serial MIDI + p++; + size = Midi.lookupMsgSize(*p); + _MIDI_SERIAL_PORT.write(p, size); + p += 3; + break; + case MidiSysEx::done : //SysEx end. send data to Serial MIDI + _MIDI_SERIAL_PORT.write(sysExData.get(), sysExData.getSize()); + /* FALLTHROUGH */ + case MidiSysEx::overflow : //SysEx buffer over. ignore and flush buffer. + sysExData.clear(); + /* FALLTHROUGH */ + default: + p += 4; + break; + } + readPtr += 4; + } +#else + uint8_t outBuf[ 3 ]; + do { + if ( (size = Midi.RecvData(outBuf)) > 0 ) { + //MIDI Output + _MIDI_SERIAL_PORT.write(outBuf, size); + } + } while (size > 0); +#endif } // Delay time (max 16383 us) diff --git a/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino index 2d42c3d9..45d23c9f 100644 --- a/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino +++ b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino @@ -61,7 +61,7 @@ void loop() // Poll USB MIDI Controler void MIDI_poll() { - byte inBuf[ 3 ]; + uint8_t inBuf[ 3 ]; //first call? if (Midi.vid != vid || Midi.pid != pid) { diff --git a/usbh_midi.cpp b/usbh_midi.cpp old mode 100755 new mode 100644 index d8df9691..5282943a --- a/usbh_midi.cpp +++ b/usbh_midi.cpp @@ -116,11 +116,10 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) EpInfo *oldep_ptr = NULL; uint8_t num_of_conf; // number of configurations + USBTRACE("\rMIDI Init\r\n"); // get memory address of USB device address pool AddressPool &addrPool = pUsb->GetAddressPool(); -#ifdef DEBUG_USB_HOST - USBTRACE("\rMIDI Init\r\n"); -#endif + // check if address has already been assigned to an instance if (bAddress) { return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; @@ -169,9 +168,8 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) bAddress = 0; return rcode; }//if (rcode... -#ifdef DEBUG_USB_HOST USBTRACE2("Addr:", bAddress); -#endif + p->lowspeed = false; //get pointer to assigned address record @@ -186,27 +184,29 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) { -#ifdef DEBUG_USB_HOST USBTRACE("setEpInfoEntry failed"); -#endif goto FailSetDevTblEntry; } -#ifdef DEBUG_USB_HOST - USBTRACE2("NC:", num_of_conf); -#endif + + USBTRACE("VID:"), D_PrintHex(vid, 0x80); + USBTRACE(" PID:"), D_PrintHex(pid, 0x80); + USBTRACE2(" #Conf:", num_of_conf); + for (uint8_t i=0; i 1) break; } // for -#ifdef DEBUG_USB_HOST - USBTRACE2("NumEP:", bNumEP); -#endif - if( bConfNum == 0 ){ //Device not found. + + USBTRACE2("\r\nNumEP:", bNumEP); + + if( bNumEP < 3 ){ //Device not found. + rcode = 0xff; goto FailGetConfDescr; } - if( !isMidiFound ){ //MIDI Device not found. Try first Bulk transfer device + if( !isMidiFound ){ //MIDI Device not found. Try last Bulk transfer device + USBTRACE("MIDI not found. Attempts bulk device\r\n"); epInfo[epDataInIndex].epAddr = epInfo[epDataInIndexVSP].epAddr; epInfo[epDataInIndex].maxPktSize = epInfo[epDataInIndexVSP].maxPktSize; epInfo[epDataOutIndex].epAddr = epInfo[epDataOutIndexVSP].epAddr; @@ -215,18 +215,17 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) // Assign epInfo to epinfo pointer rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); -#ifdef DEBUG_USB_HOST USBTRACE2("Conf:", bConfNum); -#endif + USBTRACE2("EPin :", (uint8_t)(epInfo[epDataInIndex].epAddr + 0x80)); + USBTRACE2("EPout:", epInfo[epDataOutIndex].epAddr); + // Set Configuration Value rcode = pUsb->setConf(bAddress, 0, bConfNum); if (rcode) { goto FailSetConfDescr; } -#ifdef DEBUG_USB_HOST - USBTRACE("Init done."); -#endif bPollEnable = true; + USBTRACE("Init done.\r\n"); return 0; FailGetDevDescr: FailSetDevTblEntry: @@ -237,13 +236,13 @@ FailSetConfDescr: } /* get and parse config descriptor */ -void USBH_MIDI::parseConfigDescr( byte addr, byte conf ) +void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf ) { uint8_t buf[ DESC_BUFF_SIZE ]; uint8_t* buf_ptr = buf; - byte rcode; - byte descr_length; - byte descr_type; + uint8_t rcode; + uint8_t descr_length; + uint8_t descr_type; unsigned int total_length; USB_ENDPOINT_DESCRIPTOR *epDesc; boolean isMidi = false; @@ -264,27 +263,43 @@ void USBH_MIDI::parseConfigDescr( byte addr, byte conf ) return; } +#ifdef DEBUG_USB_HOST + uint8_t bNumInt; +#endif //parsing descriptors while( buf_ptr < buf + total_length ) { descr_length = *( buf_ptr ); descr_type = *( buf_ptr + 1 ); switch( descr_type ) { case USB_DESCRIPTOR_CONFIGURATION : +#ifdef DEBUG_USB_HOST + bNumInt = buf_ptr[4]; +#endif bConfNum = buf_ptr[5]; break; case USB_DESCRIPTOR_INTERFACE : + USBTRACE("\r\nConf:"), D_PrintHex(bConfNum, 0x80); + USBTRACE(" Int:"), D_PrintHex(buf_ptr[2], 0x80); + USBTRACE(" Alt:"), D_PrintHex(buf_ptr[3], 0x80); + USBTRACE(" EPs:"), D_PrintHex(buf_ptr[4], 0x80); + USBTRACE(" IntCl:"), D_PrintHex(buf_ptr[5], 0x80); + USBTRACE(" IntSubCl:"), D_PrintHex(buf_ptr[6], 0x80); + USBTRACE("\r\n"); + if( buf_ptr[5] == USB_CLASS_AUDIO && buf_ptr[6] == USB_SUBCLASS_MIDISTREAMING ) { //p[5]; bInterfaceClass = 1(Audio), p[6]; bInterfaceSubClass = 3(MIDI Streaming) isMidiFound = true; //MIDI device found. isMidi = true; + USBTRACE("MIDI Device\r\n"); }else{ -#ifdef DEBUG_USB_HOST - USBTRACE("No MIDI Device\n"); -#endif isMidi = false; + USBTRACE("No MIDI Device\r\n"); } break; case USB_DESCRIPTOR_ENDPOINT : epDesc = (USB_ENDPOINT_DESCRIPTOR *)buf_ptr; + USBTRACE("-EPAddr:"), D_PrintHex(epDesc->bEndpointAddress, 0x80); + USBTRACE(" bmAttr:"), D_PrintHex(epDesc->bmAttributes, 0x80); + USBTRACE2(" MaxPktSz:", (uint8_t)epDesc->wMaxPacketSize); if ((epDesc->bmAttributes & 0x02) == 2) {//bulk uint8_t index; if( isMidi ) @@ -333,7 +348,7 @@ uint8_t USBH_MIDI::RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr) /* Receive data from MIDI device */ uint8_t USBH_MIDI::RecvData(uint8_t *outBuf) { - byte rcode = 0; //return code + uint8_t rcode = 0; //return code uint16_t rcvd; if( bPollEnable == false ) return false; @@ -370,10 +385,10 @@ RecvData_return_from_buffer: } /* Send data to MIDI device */ -uint8_t USBH_MIDI::SendData(uint8_t *dataptr, byte nCable) +uint8_t USBH_MIDI::SendData(uint8_t *dataptr, uint8_t nCable) { - byte buf[4]; - byte msg; + uint8_t buf[4]; + uint8_t msg; msg = dataptr[0]; // SysEx long message ? @@ -407,7 +422,7 @@ uint8_t USBH_MIDI::SendData(uint8_t *dataptr, byte nCable) buf[3] = 0; break; - //1 bytes message + //1 byte message case 1 : default : buf[2] = 0; @@ -420,20 +435,13 @@ uint8_t USBH_MIDI::SendData(uint8_t *dataptr, byte nCable) #ifdef DEBUG_USB_HOST void USBH_MIDI::PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ) { - Notify(PSTR("Endpoint descriptor:"), 0x80); - Notify(PSTR("\r\nLength:\t\t"), 0x80); - PrintHex(ep_ptr->bLength, 0x80); - Notify(PSTR("\r\nType:\t\t"), 0x80); - PrintHex(ep_ptr->bDescriptorType, 0x80); - Notify(PSTR("\r\nAddress:\t"), 0x80); - PrintHex(ep_ptr->bEndpointAddress, 0x80); - Notify(PSTR("\r\nAttributes:\t"), 0x80); - PrintHex(ep_ptr->bmAttributes, 0x80); - Notify(PSTR("\r\nMaxPktSize:\t"), 0x80); - PrintHex(ep_ptr->wMaxPacketSize, 0x80); - Notify(PSTR("\r\nPoll Intrv:\t"), 0x80); - PrintHex(ep_ptr->bInterval, 0x80); - Notify(PSTR("\r\n"), 0x80); + USBTRACE("Endpoint descriptor:\r\n"); + USBTRACE2(" Length:\t", ep_ptr->bLength); + USBTRACE2(" Type:\t\t", ep_ptr->bDescriptorType); + USBTRACE2(" Address:\t", ep_ptr->bEndpointAddress); + USBTRACE2(" Attributes:\t", ep_ptr->bmAttributes); + USBTRACE2(" MaxPktSize:\t", ep_ptr->wMaxPacketSize); + USBTRACE2(" Poll Intrv:\t", ep_ptr->bInterval); } #endif @@ -465,7 +473,7 @@ uint8_t USBH_MIDI::lookupMsgSize(uint8_t midiMsg) msgSize = 2; break; - //1 bytes messages + //1 byte messages case 0xf8 : //system realtime message case 0xf9 : //system realtime message case 0xfa : //system realtime message @@ -508,43 +516,121 @@ unsigned int USBH_MIDI::countSysExDataSize(uint8_t *dataptr) } /* Send SysEx message to MIDI device */ -uint8_t USBH_MIDI::SendSysEx(uint8_t *dataptr, unsigned int datasize, byte nCable) +uint8_t USBH_MIDI::SendSysEx(uint8_t *dataptr, unsigned int datasize, uint8_t nCable) { - byte buf[4]; + uint8_t buf[64]; uint8_t rc; unsigned int n = datasize; + unsigned int pktSize = (n*10/3+7)/10*4; //Calculate total USB MIDI packet size + uint8_t wptr = 0; + uint8_t maxpkt = epInfo[epDataInIndex].maxPktSize; + + USBTRACE("SendSysEx:\r\t"); + USBTRACE2(" Length:\t", datasize); + USBTRACE2(" Total pktSize:\t", pktSize); while(n > 0) { //Byte 0 - buf[0] = (nCable << 4) | 0x4; //x4 SysEx starts or continues + buf[wptr] = (nCable << 4) | 0x4; //x4 SysEx starts or continues switch ( n ) { - case 1 : - buf[0] = (nCable << 4) | 0x5; //x5 SysEx ends with following single byte. - buf[1] = *(dataptr++); - buf[2] = 0x00; - buf[3] = 0x00; + case 1 : + buf[wptr++] = (nCable << 4) | 0x5; //x5 SysEx ends with following single byte. + buf[wptr++] = *(dataptr++); + buf[wptr++] = 0x00; + buf[wptr++] = 0x00; n = n - 1; break; - case 2 : - buf[0] = (nCable << 4) | 0x6; //x6 SysEx ends with following two bytes. - buf[1] = *(dataptr++); - buf[2] = *(dataptr++); - buf[3] = 0x00; + case 2 : + buf[wptr++] = (nCable << 4) | 0x6; //x6 SysEx ends with following two bytes. + buf[wptr++] = *(dataptr++); + buf[wptr++] = *(dataptr++); + buf[wptr++] = 0x00; n = n - 2; break; - case 3 : - buf[0] = (nCable << 4) | 0x7; //x7 SysEx ends with following three bytes. - default : - buf[1] = *(dataptr++); - buf[2] = *(dataptr++); - buf[3] = *(dataptr++); + case 3 : + buf[wptr] = (nCable << 4) | 0x7; //x7 SysEx ends with following three bytes. + default : + wptr++; + buf[wptr++] = *(dataptr++); + buf[wptr++] = *(dataptr++); + buf[wptr++] = *(dataptr++); n = n - 3; break; } - rc = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, 4, buf); - if(rc != 0) - break; + + if( wptr >= maxpkt || n == 0 ){ //Reach a maxPktSize or data end. + USBTRACE2(" wptr:\t", wptr); + if( (rc = pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, wptr, buf)) != 0 ){ + break; + } + wptr = 0; //rewind data pointer + } + } + return(rc); +} + +/* Send raw data to MIDI device */ +uint8_t USBH_MIDI::SendRawData(uint16_t bytes_send, uint8_t *dataptr) +{ + return pUsb->outTransfer(bAddress, epInfo[epDataOutIndex].epAddr, bytes_send, dataptr); + +} + +// +// System Exclusive packet data management class +// +MidiSysEx::MidiSysEx() +{ + clear(); +} + +void MidiSysEx::clear() +{ + pos = 0; + buf[0] = 0; +} + +MidiSysEx::Status MidiSysEx::set(uint8_t *p) +{ + MidiSysEx::Status rc = MidiSysEx::ok; + uint8_t cin = *(p) & 0x0f; + + //SysEx message? + if( (cin & 0xc) != 4 ) return MidiSysEx::nonsysex; + + switch(cin) { + case 4: + case 7: + if( pos+2 < MIDI_EVENT_PACKET_SIZE ) { + buf[pos++] = *(p+1); + buf[pos++] = *(p+2); + buf[pos++] = *(p+3); + }else{ + rc = MidiSysEx::overflow; + } + break; + case 5: + if( pos+1 < MIDI_EVENT_PACKET_SIZE ) { + buf[pos++] = *(p+1); + buf[pos++] = *(p+2); + }else{ + rc = MidiSysEx::overflow; + } + break; + case 6: + if( pos < MIDI_EVENT_PACKET_SIZE ) { + buf[pos++] = *(p+1); + }else{ + rc = MidiSysEx::overflow; + } + break; + default: + break; + } + //SysEx end? + if((cin & 0x3) != 0) { + rc = MidiSysEx::done; } return(rc); } diff --git a/usbh_midi.h b/usbh_midi.h old mode 100755 new mode 100644 index 25436ece..70973d0a --- a/usbh_midi.h +++ b/usbh_midi.h @@ -26,6 +26,7 @@ #if !defined(_USBH_MIDI_H_) #define _USBH_MIDI_H_ +//#define DEBUG_USB_HOST #include "Usb.h" #define MIDI_MAX_ENDPOINTS 5 //endpoint 0, bulk_IN(MIDI), bulk_OUT(MIDI), bulk_IN(VSP), bulk_OUT(VSP) @@ -36,9 +37,6 @@ class USBH_MIDI; class USBH_MIDI : public USBDeviceConfig { -private: - uint8_t lookupMsgSize(uint8_t midiMsg); - protected: static const uint8_t epDataInIndex; // DataIn endpoint index(MIDI) static const uint8_t epDataOutIndex; // DataOUT endpoint index(MIDI) @@ -59,7 +57,7 @@ protected: uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE]; uint8_t readPtr; - void parseConfigDescr(byte addr, byte conf); + void parseConfigDescr(uint8_t addr, uint8_t conf); unsigned int countSysExDataSize(uint8_t *dataptr); #ifdef DEBUG_USB_HOST void PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ); @@ -70,8 +68,10 @@ public: // Methods for recieving and sending data uint8_t RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr); uint8_t RecvData(uint8_t *outBuf); - uint8_t SendData(uint8_t *dataptr, byte nCable=0); - uint8_t SendSysEx(uint8_t *dataptr, unsigned int datasize, byte nCable=0); + uint8_t SendData(uint8_t *dataptr, uint8_t nCable=0); + uint8_t lookupMsgSize(uint8_t midiMsg); + uint8_t SendSysEx(uint8_t *dataptr, unsigned int datasize, uint8_t nCable=0); + uint8_t SendRawData(uint16_t bytes_send, uint8_t *dataptr); // backward compatibility functions inline uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr){ return RecvData(bytes_rcvd, dataptr); }; inline uint8_t RcvData(uint8_t *outBuf){ return RecvData(outBuf); }; @@ -82,4 +82,26 @@ public: virtual uint8_t GetAddress() { return bAddress; }; }; +// +// System Exclusive packet data management class +// +class MidiSysEx { +private: + uint8_t pos; + uint8_t buf[MIDI_EVENT_PACKET_SIZE]; +public: + typedef enum { + nonsysex = 0, + ok = 1, + done = 0xfe, + overflow = 0xff + } Status; + + MidiSysEx(); + void clear(); + MidiSysEx::Status set(uint8_t *p); + inline uint8_t *get(){return buf;}; + inline uint8_t getSize(){return pos;}; +}; + #endif //_USBH_MIDI_H_ From eb3a258aa621e4f8dd4e5b97267ad0b9e077d39b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 26 Apr 2016 17:00:44 +0200 Subject: [PATCH 166/220] Remove execute permission from source files --- BTD.cpp | 0 BTD.h | 0 PS3USB.cpp | 0 Wii.cpp | 0 Wii.h | 0 5 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 BTD.cpp mode change 100755 => 100644 BTD.h mode change 100755 => 100644 PS3USB.cpp mode change 100755 => 100644 Wii.cpp mode change 100755 => 100644 Wii.h diff --git a/BTD.cpp b/BTD.cpp old mode 100755 new mode 100644 diff --git a/BTD.h b/BTD.h old mode 100755 new mode 100644 diff --git a/PS3USB.cpp b/PS3USB.cpp old mode 100755 new mode 100644 diff --git a/Wii.cpp b/Wii.cpp old mode 100755 new mode 100644 diff --git a/Wii.h b/Wii.h old mode 100755 new mode 100644 From cf24646fe66065584ae230c8efeecd7b18f4bc06 Mon Sep 17 00:00:00 2001 From: Yuuichi Akagawa Date: Wed, 27 Apr 2016 00:28:57 +0900 Subject: [PATCH 167/220] Fix unused variable warning --- usbh_midi.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/usbh_midi.cpp b/usbh_midi.cpp index 5282943a..54231387 100644 --- a/usbh_midi.cpp +++ b/usbh_midi.cpp @@ -263,18 +263,12 @@ void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf ) return; } -#ifdef DEBUG_USB_HOST - uint8_t bNumInt; -#endif //parsing descriptors while( buf_ptr < buf + total_length ) { descr_length = *( buf_ptr ); descr_type = *( buf_ptr + 1 ); switch( descr_type ) { case USB_DESCRIPTOR_CONFIGURATION : -#ifdef DEBUG_USB_HOST - bNumInt = buf_ptr[4]; -#endif bConfNum = buf_ptr[5]; break; case USB_DESCRIPTOR_INTERFACE : From a69979a7eaf8e959b1d76c605f2d752a41c2f6a9 Mon Sep 17 00:00:00 2001 From: Yuuichi Akagawa Date: Wed, 27 Apr 2016 00:52:39 +0900 Subject: [PATCH 168/220] Fix type mismatch warning --- .../USBH_MIDI/bidrectional_converter/bidrectional_converter.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino index d5906c9f..78f62385 100644 --- a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino +++ b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino @@ -51,7 +51,7 @@ void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); #ifdef USBH_MIDI_SYSEX_ENABLE MidiSysEx sysExData; //SysEx: -void handle_sysex( byte* sysexmsg, uint16_t sizeofsysex) { +void handle_sysex( byte* sysexmsg, unsigned sizeofsysex) { Midi.SendSysEx(sysexmsg, sizeofsysex); } #endif From ce7f62e8d974b514261fdcce9df9ac3c36f65c59 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 2 Jul 2016 19:42:32 +0200 Subject: [PATCH 169/220] Keep reading the IR camera as well if an extension disconnects Fixes #234 Also added some debugging code, so this could be detected faster in the future --- Wii.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Wii.cpp b/Wii.cpp index 20975a81..460e4b23 100644 --- a/Wii.cpp +++ b/Wii.cpp @@ -327,9 +327,16 @@ void WII::ACLData(uint8_t* l2capinbuf) { nunchuckConnected = false; // It must be the Nunchuck controller then wii_clear_flag(WII_FLAG_NUNCHUCK_CONNECTED); onInit(); - setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer - } else - setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer +#ifdef WIICAMERA + if(!isIRCameraEnabled()) // We still want to read from the IR camera, so do not change the report mode +#endif + setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer + } else { +#ifdef WIICAMERA + if(!isIRCameraEnabled()) // We still want to read from the IR camera, so do not change the report mode +#endif + setReportMode(false, 0x31); // If there is no extension connected we will read the buttons and accelerometer + } } } else { @@ -965,6 +972,10 @@ uint8_t WII::getBatteryLevel() { }; void WII::setReportMode(bool continuous, uint8_t mode) { +#ifdef EXTRADEBUG + Notify(PSTR("\r\nReport mode was changed to: "), 0x80); + D_PrintHex (mode, 0x80); +#endif uint8_t cmd_buf[4]; cmd_buf[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02) cmd_buf[1] = 0x12; From 094f64b6970bf4a94130d6daeeb57a7fd7ac7c03 Mon Sep 17 00:00:00 2001 From: sieren Date: Tue, 27 Sep 2016 18:02:08 +0200 Subject: [PATCH 170/220] [RBL] Cast sizeof to uint8_t where needed The RedbearLab compiler has a type mismatch for STLs min() and sizeof. Thus we need to cast the occurences of sizeof to uint8_t. --- PS4Parser.cpp | 4 ++-- PSBuzz.cpp | 2 +- settings.h | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/PS4Parser.cpp b/PS4Parser.cpp index 1e6bf207..c484b83e 100644 --- a/PS4Parser.cpp +++ b/PS4Parser.cpp @@ -84,7 +84,7 @@ void PS4Parser::Parse(uint8_t len, uint8_t *buf) { #endif if (buf[0] == 0x01) // Check report ID - memcpy(&ps4Data, buf + 1, min((uint8_t)(len - 1), sizeof(ps4Data))); + memcpy(&ps4Data, buf + 1, min((uint8_t)(len - 1), MFK_CASTUINT8T sizeof(ps4Data))); else if (buf[0] == 0x11) { // This report is send via Bluetooth, it has an offset of 2 compared to the USB data if (len < 4) { #ifdef DEBUG_USB_HOST @@ -93,7 +93,7 @@ void PS4Parser::Parse(uint8_t len, uint8_t *buf) { #endif return; } - memcpy(&ps4Data, buf + 3, min((uint8_t)(len - 3), sizeof(ps4Data))); + memcpy(&ps4Data, buf + 3, min((uint8_t)(len - 3), MFK_CASTUINT8T sizeof(ps4Data))); } else { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nUnknown report id: "), 0x80); diff --git a/PSBuzz.cpp b/PSBuzz.cpp index 7a4615e0..3e184de9 100644 --- a/PSBuzz.cpp +++ b/PSBuzz.cpp @@ -29,7 +29,7 @@ void PSBuzz::ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf Notify(PSTR(" "), 0x80); } #endif - memcpy(&psbuzzButtons, buf + 2, min((uint8_t)(len - 2), sizeof(psbuzzButtons))); + memcpy(&psbuzzButtons, buf + 2, min((uint8_t)(len - 2), MFK_CASTUINT8T sizeof(psbuzzButtons))); if (psbuzzButtons.val != oldButtonState.val) { // Check if anything has changed buttonClickState.val = psbuzzButtons.val & ~oldButtonState.val; // Update click state variable diff --git a/settings.h b/settings.h index af0eb175..1fb371d8 100644 --- a/settings.h +++ b/settings.h @@ -142,6 +142,7 @@ e-mail : support@circuitsathome.com #include #include #define SPI SPI_Master +#define MFK_CASTUINT8T (uint8_t) // RBLs return type for sizeof needs casting to uint8_t #endif #if defined(__PIC32MX__) || defined(__PIC32MZ__) #include <../../../../hardware/pic32/libraries/SPI/SPI.h> // Hack to use the SPI library @@ -171,4 +172,9 @@ extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp #endif #endif +// Set defaults +#ifndef MFK_CASTUINT8T +#define MFK_CASTUINT8T +#endif + #endif /* SETTINGS_H */ From ddcf77a6a3de9fbc398d1f1f9e0a26dddccefcf3 Mon Sep 17 00:00:00 2001 From: Roman3349 Date: Tue, 27 Sep 2016 21:28:59 +0200 Subject: [PATCH 171/220] Add information about license and version to @PlatformIO Library Registry manifest file. Signed-off-by: Roman3349 --- library.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library.json b/library.json index f2cd6dab..a26311d1 100644 --- a/library.json +++ b/library.json @@ -31,6 +31,8 @@ "type": "git", "url": "https://github.com/felis/USB_Host_Shield_2.0.git" }, + "version": "1.2.1", + "license": "GPL-2.0", "examples": [ "examples/*/*.ino", From f087a578953866f3056bf6312f09f571b0b3c7ab Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 24 Oct 2016 23:01:19 -0500 Subject: [PATCH 172/220] Added support for ESP8266 Fixes #262 --- .travis.yml | 2 +- avrpins.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ library.json | 3 ++- usbhost.h | 2 ++ 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9351a50..f8ffbecd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,4 +74,4 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=teensy31 --board=due --lib="." + - platformio ci --board=uno --board=teensy31 --board=due --board=esp12e --board=nodemcu --lib="." diff --git a/avrpins.h b/avrpins.h index b73a6bc6..4b0d37a4 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1242,6 +1242,52 @@ MAKE_PIN(P13, 13); // #undef MAKE_PIN +#elif defined(ESP8266) + +#define pgm_read_pointer(p) pgm_read_ptr(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); \ + } \ +}; + +// Pinout for ESP-12 module +// 0 .. 16 - Digital pins +MAKE_PIN(P0, 0); +MAKE_PIN(P1, 1); // TX0 +MAKE_PIN(P2, 2); // TX1 +MAKE_PIN(P3, 3); // RX0 +MAKE_PIN(P4, 4); // SDA +MAKE_PIN(P5, 5); // SCL +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); // MISO +MAKE_PIN(P13, 13); // MOSI +MAKE_PIN(P14, 14); // SCK +MAKE_PIN(P15, 15); // SS +MAKE_PIN(P16, 16); + +#undef MAKE_PIN + #else #error "Please define board in avrpins.h" diff --git a/library.json b/library.json index a26311d1..7251409b 100644 --- a/library.json +++ b/library.json @@ -49,6 +49,7 @@ "teensy", "atmelsam", "nordicnrf51", - "ststm32" + "ststm32", + "espressif8266" ] } diff --git a/usbhost.h b/usbhost.h index 15a57bd1..b655f44b 100644 --- a/usbhost.h +++ b/usbhost.h @@ -97,6 +97,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(ESP8266) +typedef SPi< P14, P13, P12, P15 > spi; #else #error "No SPI entry in usbhost.h" #endif From 6fbe00703a45416821f6429f9eedd75f719eb323 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 24 Oct 2016 23:11:46 -0500 Subject: [PATCH 173/220] Workaround issue with SPI_HAS_TRANSACTION is just defined and not set to a value in the ESP8266 Arduino core --- usbhost.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/usbhost.h b/usbhost.h index b655f44b..8b4fc36b 100644 --- a/usbhost.h +++ b/usbhost.h @@ -39,7 +39,7 @@ public: SPI_SS::SetDirWrite(); SPI_SS::Set(); } -#elif SPI_HAS_TRANSACTION +#elif defined(SPI_HAS_TRANSACTION) static void init() { SPI.begin(); // The SPI library with transaction will take care of setting up the pins - settings is set in beginTransaction() SPI_SS::SetDirWrite(); @@ -154,7 +154,7 @@ MAX3421e< SPI_SS, INTR >::MAX3421e() { template< typename SPI_SS, typename INTR > void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { XMEM_ACQUIRE_SPI(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 #endif SPI_SS::Clear(); @@ -164,7 +164,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 SPI_HAS_TRANSACTION +#elif defined(SPI_HAS_TRANSACTION) uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; @@ -185,7 +185,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { #endif SPI_SS::Set(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.endTransaction(); #endif XMEM_RELEASE_SPI(); @@ -197,7 +197,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { template< typename SPI_SS, typename INTR > uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p) { XMEM_ACQUIRE_SPI(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 #endif SPI_SS::Clear(); @@ -206,7 +206,7 @@ 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 SPI_HAS_TRANSACTION +#elif defined(SPI_HAS_TRANSACTION) SPI.transfer(reg | 0x02); SPI.transfer(data_p, nbytes); data_p += nbytes; @@ -238,7 +238,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* #endif SPI_SS::Set(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.endTransaction(); #endif XMEM_RELEASE_SPI(); @@ -260,7 +260,7 @@ void MAX3421e< SPI_SS, INTR >::gpioWr(uint8_t data) { template< typename SPI_SS, typename INTR > uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { XMEM_ACQUIRE_SPI(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 #endif SPI_SS::Clear(); @@ -274,7 +274,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { uint8_t rv = 0; HAL_SPI_Receive(&SPI_Handle, &rv, 1, HAL_MAX_DELAY); SPI_SS::Set(); -#elif !defined(SPDR) || SPI_HAS_TRANSACTION +#elif !defined(SPDR) || defined(SPI_HAS_TRANSACTION) SPI.transfer(reg); uint8_t rv = SPI.transfer(0); // Send empty byte SPI_SS::Set(); @@ -287,7 +287,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { uint8_t rv = SPDR; #endif -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.endTransaction(); #endif XMEM_RELEASE_SPI(); @@ -299,7 +299,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { template< typename SPI_SS, typename INTR > uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* data_p) { XMEM_ACQUIRE_SPI(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0)); // The MAX3421E can handle up to 26MHz, use MSB First and SPI mode 0 #endif SPI_SS::Clear(); @@ -308,7 +308,7 @@ 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 SPI_HAS_TRANSACTION +#elif defined(SPI_HAS_TRANSACTION) SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes SPI.transfer(data_p, nbytes); @@ -350,7 +350,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* #endif SPI_SS::Set(); -#if SPI_HAS_TRANSACTION +#if defined(SPI_HAS_TRANSACTION) SPI.endTransaction(); #endif XMEM_RELEASE_SPI(); From 736eebcc36d097ba9e311bf164f9b0c435dbce92 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 24 Oct 2016 23:20:38 -0500 Subject: [PATCH 174/220] Do not generate warnings for unused functions --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f8ffbecd..225e1c66 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,7 @@ env: install: - pip install -U platformio - - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror -Wno-strict-aliasing" + - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror -Wno-strict-aliasing -Wno-unused-function" # # Libraries from PlatformIO Library Registry: From 58015d611d2bd5fc5774d2c98c134754489797f9 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 24 Oct 2016 23:27:19 -0500 Subject: [PATCH 175/220] Use SPI.writeBytes instead of SPI.transfer on the ESP8266 --- usbhost.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/usbhost.h b/usbhost.h index 8b4fc36b..daff87a7 100644 --- a/usbhost.h +++ b/usbhost.h @@ -168,7 +168,11 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; +#ifdef ESP8266 + SPI.writeBytes(c, 2); +#else SPI.transfer(c, 2); +#endif #elif defined(STM32F4) uint8_t c[2]; c[0] = reg | 0x02; @@ -208,7 +212,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p += nbytes; #elif defined(SPI_HAS_TRANSACTION) SPI.transfer(reg | 0x02); +#ifdef ESP8266 + SPI.writeBytes(data_p, nbytes); +#else SPI.transfer(data_p, nbytes); +#endif data_p += nbytes; #elif defined(__ARDUINO_X86__) SPI.transfer(reg | 0x02); @@ -311,7 +319,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* #elif defined(SPI_HAS_TRANSACTION) SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes +#ifdef ESP8266 + SPI.writeBytes(data_p, nbytes); +#else SPI.transfer(data_p, nbytes); +#endif data_p += nbytes; #elif defined(__ARDUINO_X86__) SPI.transfer(reg); From aa3731c230343575870c2e031a96a2e619229bec Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 25 Oct 2016 00:06:15 -0500 Subject: [PATCH 176/220] Workaround the following issue: https://github.com/esp8266/Arduino/issues/2078 Also see: https://travis-ci.org/felis/USB_Host_Shield_2.0/jobs/170350078 --- settings.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/settings.h b/settings.h index 1fb371d8..c8856a24 100644 --- a/settings.h +++ b/settings.h @@ -177,4 +177,16 @@ extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp #define MFK_CASTUINT8T #endif +// Workaround issue: https://github.com/esp8266/Arduino/issues/2078 +#ifdef ESP8266 +#undef PROGMEM +#define PROGMEM +#undef PSTR +#define PSTR(s) (s) +#undef pgm_read_byte +#define pgm_read_byte(addr) (*reinterpret_cast(addr)) +#undef pgm_read_word +#define pgm_read_word(addr) (*reinterpret_cast(addr)) +#endif + #endif /* SETTINGS_H */ From 31570861fe427068f54aa3fe90b85425d4591cc5 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 25 Oct 2016 00:01:55 -0500 Subject: [PATCH 177/220] Updated README --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e7345efb..d77b3bed 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ Currently the following boards are supported by the library: * Please see: . * STM32F4 * Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: . +* ESP8266 is supported using the [ESP8266 Arduino core](https://github.com/esp8266/Arduino) The following boards need to be activated manually in [settings.h](settings.h): @@ -317,11 +318,11 @@ HID devices are also supported by the library. However these require you to writ ### [MIDI Library](usbh_midi.cpp) -The library support MIDI devices. +The library support MIDI devices. You can convert USB MIDI keyboard to legacy serial MIDI. -* [USB_MIDI_converter.ino](examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino) -* [USB_MIDI_converter_multi.ino](examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino) +* [USB_MIDI_converter.ino](examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino) +* [USB_MIDI_converter_multi.ino](examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino) For information see the following page: . From 238c26908f116ee21ea5f5b320aa46e703eee3ec Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 25 Oct 2016 01:38:24 -0500 Subject: [PATCH 178/220] Use pin 15 and 16 for SS and INT respectivly The Wifio is not supported for now --- README.md | 1 + UsbCore.h | 2 ++ settings.h | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/README.md b/README.md index d77b3bed..01fb8a50 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,7 @@ Currently the following boards are supported by the library: * STM32F4 * Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: . * ESP8266 is supported using the [ESP8266 Arduino core](https://github.com/esp8266/Arduino) + * Note it uses pin 15 and 16 for SS and INT respectively The following boards need to be activated manually in [settings.h](settings.h): diff --git a/UsbCore.h b/UsbCore.h index fdec87b0..43703f63 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -39,6 +39,8 @@ typedef MAX3421e MAX3421E; // Arduino Mega ADK 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 +#elif defined(ESP8266) +typedef MAX3421e MAX3421E; // ESP8266 boards #else 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 diff --git a/settings.h b/settings.h index c8856a24..068bceba 100644 --- a/settings.h +++ b/settings.h @@ -189,4 +189,8 @@ extern SPI_HandleTypeDef SPI_Handle; // Needed to be declared in your main.cpp #define pgm_read_word(addr) (*reinterpret_cast(addr)) #endif +#ifdef ARDUINO_ESP8266_WIFIO +#error "This board is currently not supported" +#endif + #endif /* SETTINGS_H */ From 231fb542a8f42d5ada6325bdb5a3a2e1d8d37348 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 25 Oct 2016 03:23:40 -0500 Subject: [PATCH 179/220] SPI pins are defined in newer version of Arduino See: https://github.com/arduino/Arduino/pull/4814 --- usbhost.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/usbhost.h b/usbhost.h index daff87a7..3e8bd7a8 100644 --- a/usbhost.h +++ b/usbhost.h @@ -85,7 +85,19 @@ public: }; /* SPI pin definitions. see avrpins.h */ -#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) +#if defined(PIN_SPI_SCK) && defined(PIN_SPI_MOSI) && defined(PIN_SPI_MISO) && defined(PIN_SPI_SS) +// Use pin defines: https://github.com/arduino/Arduino/pull/4814 +// Based on: https://www.mikeash.com/pyblog/friday-qa-2015-03-20-preprocessor-abuse-and-optional-parentheses.html +#define NOTHING_EXTRACT +#define EXTRACT(...) EXTRACT __VA_ARGS__ +#define PASTE(x, ...) x ## __VA_ARGS__ +#define EVALUATING_PASTE(x, ...) PASTE(x, __VA_ARGS__) +#define UNPAREN(x) EVALUATING_PASTE(NOTHING_, EXTRACT x) +#define APPEND_PIN(pin) P ## pin // Appends the pin to 'P', e.g. 1 becomes P1 +#define MAKE_PIN(x) EVALUATING_PASTE(APPEND_, PIN(UNPAREN(x))) +typedef SPi< MAKE_PIN(PIN_SPI_SCK), MAKE_PIN(PIN_SPI_MOSI), MAKE_PIN(PIN_SPI_MISO), MAKE_PIN(PIN_SPI_SS) > spi; +#undef MAKE_PIN +#elif defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) typedef SPi< Pb1, Pb2, Pb3, Pb0 > spi; #elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) typedef SPi< Pb5, Pb3, Pb4, Pb2 > spi; From 6af321a7ac6c735f8fc8e3224e2c408cac7625b2 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 26 Oct 2016 00:58:51 -0500 Subject: [PATCH 180/220] Use transferBytes when we want to receive data --- usbhost.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usbhost.h b/usbhost.h index 3e8bd7a8..6eb8d663 100644 --- a/usbhost.h +++ b/usbhost.h @@ -332,11 +332,11 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes #ifdef ESP8266 - SPI.writeBytes(data_p, nbytes); + SPI.transferBytes(data_p, data_p, nbytes); #else SPI.transfer(data_p, nbytes); -#endif data_p += nbytes; +#endif #elif defined(__ARDUINO_X86__) SPI.transfer(reg); SPI.transferBuffer(NULL, data_p, nbytes); From dc2a224d2e6e683be4fa6c11743fd14c0ee07052 Mon Sep 17 00:00:00 2001 From: huming2207 Date: Wed, 2 Nov 2016 23:13:09 +1100 Subject: [PATCH 181/220] Change INT pin to GPIO0 temporarily as it cannot attach interrupt. --- README.md | 5 ++++- UsbCore.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 01fb8a50..a8b415bc 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,10 @@ Currently the following boards are supported by the library: * STM32F4 * Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: . * ESP8266 is supported using the [ESP8266 Arduino core](https://github.com/esp8266/Arduino) - * Note it uses pin 15 and 16 for SS and INT respectively + * Note it uses pin 15 and 0 for SS and INT respectively + * Also please be aware that: + * GPIO16 is **NOT** usable, as it will be used for some other purposes. For example, reset the SoC itself from sleep mode. + * GPIO6 to 11 is also **NOT** usable, as they are used to connect SPI flash chip and it is used for storing the executable binary content. The following boards need to be activated manually in [settings.h](settings.h): diff --git a/UsbCore.h b/UsbCore.h index 43703f63..f9fc6641 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -40,7 +40,7 @@ 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 #elif defined(ESP8266) -typedef MAX3421e MAX3421E; // ESP8266 boards +typedef MAX3421e MAX3421E; // ESP8266 boards #else 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 From 03ba29ca246471427d8abb9a71dc413d77d6ef60 Mon Sep 17 00:00:00 2001 From: huming2207 Date: Wed, 2 Nov 2016 23:15:08 +1100 Subject: [PATCH 182/220] Remove unusable pins --- avrpins.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/avrpins.h b/avrpins.h index 4b0d37a4..76445e47 100644 --- a/avrpins.h +++ b/avrpins.h @@ -1268,23 +1268,18 @@ public: \ // Pinout for ESP-12 module // 0 .. 16 - Digital pins +// GPIO 6 to 11 and 16 are not usable in this library. + MAKE_PIN(P0, 0); MAKE_PIN(P1, 1); // TX0 MAKE_PIN(P2, 2); // TX1 MAKE_PIN(P3, 3); // RX0 MAKE_PIN(P4, 4); // SDA MAKE_PIN(P5, 5); // SCL -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); // MISO MAKE_PIN(P13, 13); // MOSI MAKE_PIN(P14, 14); // SCK MAKE_PIN(P15, 15); // SS -MAKE_PIN(P16, 16); #undef MAKE_PIN From 6ec044c23045678d5734ca89458930916d097d12 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 26 Nov 2016 23:46:03 -0600 Subject: [PATCH 183/220] Added support for Teensy 3.5 and 3.6 --- .travis.yml | 2 +- UsbCore.h | 2 +- avrpins.h | 34 +++++++++++++++++++++++++++++++++- settings.h | 6 +++--- usbhost.h | 2 +- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9351a50..1640595b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,4 +74,4 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=teensy31 --board=due --lib="." + - platformio ci --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --lib="." diff --git a/UsbCore.h b/UsbCore.h index fdec87b0..8a22aa13 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -40,7 +40,7 @@ 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.), Intel Edison, Intel Galileo 2 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.x #endif /* Common setup data constant combinations */ diff --git a/avrpins.h b/avrpins.h index b73a6bc6..e782de8b 100644 --- a/avrpins.h +++ b/avrpins.h @@ -768,7 +768,7 @@ public: // pointers are 32 bits on ARM #define pgm_read_pointer(p) pgm_read_dword(p) -#if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__)) +#if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__)) #include "core_pins.h" #include "avr_emulation.h" @@ -832,6 +832,38 @@ MAKE_PIN(P30, CORE_PIN30_PORTREG, CORE_PIN30_BIT, CORE_PIN30_CONFIG); MAKE_PIN(P31, CORE_PIN31_PORTREG, CORE_PIN31_BIT, CORE_PIN31_CONFIG); MAKE_PIN(P32, CORE_PIN32_PORTREG, CORE_PIN32_BIT, CORE_PIN32_CONFIG); MAKE_PIN(P33, CORE_PIN33_PORTREG, CORE_PIN33_BIT, CORE_PIN33_CONFIG); +#if defined(__MK64FX512__) || defined(__MK66FX1M0__) +MAKE_PIN(P34, CORE_PIN34_PORTREG, CORE_PIN34_BIT, CORE_PIN34_CONFIG); +MAKE_PIN(P35, CORE_PIN35_PORTREG, CORE_PIN35_BIT, CORE_PIN35_CONFIG); +MAKE_PIN(P36, CORE_PIN36_PORTREG, CORE_PIN36_BIT, CORE_PIN36_CONFIG); +MAKE_PIN(P37, CORE_PIN37_PORTREG, CORE_PIN37_BIT, CORE_PIN37_CONFIG); +MAKE_PIN(P38, CORE_PIN38_PORTREG, CORE_PIN38_BIT, CORE_PIN38_CONFIG); +MAKE_PIN(P39, CORE_PIN39_PORTREG, CORE_PIN39_BIT, CORE_PIN39_CONFIG); +MAKE_PIN(P40, CORE_PIN40_PORTREG, CORE_PIN40_BIT, CORE_PIN40_CONFIG); +MAKE_PIN(P41, CORE_PIN41_PORTREG, CORE_PIN41_BIT, CORE_PIN41_CONFIG); +MAKE_PIN(P42, CORE_PIN42_PORTREG, CORE_PIN42_BIT, CORE_PIN42_CONFIG); +MAKE_PIN(P43, CORE_PIN43_PORTREG, CORE_PIN43_BIT, CORE_PIN43_CONFIG); +MAKE_PIN(P44, CORE_PIN44_PORTREG, CORE_PIN44_BIT, CORE_PIN44_CONFIG); +MAKE_PIN(P45, CORE_PIN45_PORTREG, CORE_PIN45_BIT, CORE_PIN45_CONFIG); +MAKE_PIN(P46, CORE_PIN46_PORTREG, CORE_PIN46_BIT, CORE_PIN46_CONFIG); +MAKE_PIN(P47, CORE_PIN47_PORTREG, CORE_PIN47_BIT, CORE_PIN47_CONFIG); +MAKE_PIN(P48, CORE_PIN48_PORTREG, CORE_PIN48_BIT, CORE_PIN48_CONFIG); +MAKE_PIN(P49, CORE_PIN49_PORTREG, CORE_PIN49_BIT, CORE_PIN49_CONFIG); +MAKE_PIN(P50, CORE_PIN50_PORTREG, CORE_PIN50_BIT, CORE_PIN50_CONFIG); +MAKE_PIN(P51, CORE_PIN51_PORTREG, CORE_PIN51_BIT, CORE_PIN51_CONFIG); +MAKE_PIN(P52, CORE_PIN52_PORTREG, CORE_PIN52_BIT, CORE_PIN52_CONFIG); +MAKE_PIN(P53, CORE_PIN53_PORTREG, CORE_PIN53_BIT, CORE_PIN53_CONFIG); +MAKE_PIN(P54, CORE_PIN54_PORTREG, CORE_PIN54_BIT, CORE_PIN54_CONFIG); +MAKE_PIN(P55, CORE_PIN55_PORTREG, CORE_PIN55_BIT, CORE_PIN55_CONFIG); +MAKE_PIN(P56, CORE_PIN56_PORTREG, CORE_PIN56_BIT, CORE_PIN56_CONFIG); +MAKE_PIN(P57, CORE_PIN57_PORTREG, CORE_PIN57_BIT, CORE_PIN57_CONFIG); +MAKE_PIN(P58, CORE_PIN58_PORTREG, CORE_PIN58_BIT, CORE_PIN58_CONFIG); +MAKE_PIN(P59, CORE_PIN59_PORTREG, CORE_PIN59_BIT, CORE_PIN59_CONFIG); +MAKE_PIN(P60, CORE_PIN60_PORTREG, CORE_PIN60_BIT, CORE_PIN60_CONFIG); +MAKE_PIN(P61, CORE_PIN61_PORTREG, CORE_PIN61_BIT, CORE_PIN61_CONFIG); +MAKE_PIN(P62, CORE_PIN62_PORTREG, CORE_PIN62_BIT, CORE_PIN62_CONFIG); +MAKE_PIN(P63, CORE_PIN63_PORTREG, CORE_PIN63_BIT, CORE_PIN63_CONFIG); +#endif #undef MAKE_PIN diff --git a/settings.h b/settings.h index 1fb371d8..2890cba8 100644 --- a/settings.h +++ b/settings.h @@ -71,8 +71,8 @@ e-mail : support@circuitsathome.com #define USE_SPI4TEENSY3 1 #endif -// disabled on the Teensy LC as it is incompatible for now -#if defined(__MKL26Z64__) +// Disabled on the Teensy LC, Teensy 3.5, and Teensy 3.6 as it is incompatible for now +#if defined(__MKL26Z64__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) #undef USE_SPI4TEENSY3 #define USE_SPI4TEENSY3 0 #endif @@ -129,7 +129,7 @@ e-mail : support@circuitsathome.com #define EXT_RAM 0 #endif -#if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__)) +#if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__)) #define USING_SPI4TEENSY3 USE_SPI4TEENSY3 #else #define USING_SPI4TEENSY3 0 diff --git a/usbhost.h b/usbhost.h index 15a57bd1..705aeebf 100644 --- a/usbhost.h +++ b/usbhost.h @@ -91,7 +91,7 @@ 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(__MKL26Z64__))) || defined(__ARDUINO_X86__) || defined(__MIPSEL__) || defined(STM32F4) +#elif (defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__))) || 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; From c362c0406541169df2e26d326c7248a7bbdf1af7 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 26 Nov 2016 23:56:45 -0600 Subject: [PATCH 184/220] The Xbox button on the Xbox One controller was not read properly XBOX_BUTTONS is stored in PROGMEM --- XBOXONE.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/XBOXONE.cpp b/XBOXONE.cpp index 0698a6aa..d3f1fd77 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -260,9 +260,9 @@ void XBOXONE::readReport() { if(readBuf[0] == 0x07) { // The XBOX button has a separate message if(readBuf[4] == 1) - ButtonState |= XBOX_BUTTONS[XBOX]; + ButtonState |= pgm_read_word(&XBOX_BUTTONS[XBOX]); else - ButtonState &= ~XBOX_BUTTONS[XBOX]; + ButtonState &= ~pgm_read_word(&XBOX_BUTTONS[XBOX]); } if(readBuf[0] != 0x20) { // Check if it's the correct report, otherwise return - the controller also sends different status reports #ifdef EXTRADEBUG @@ -272,7 +272,7 @@ void XBOXONE::readReport() { return; } - uint16_t xbox = ButtonState & XBOX_BUTTONS[XBOX]; // Since the XBOX button is separate, save it and add it back in + uint16_t xbox = ButtonState & pgm_read_word(&XBOX_BUTTONS[XBOX]); // Since the XBOX button is separate, save it and add it back in // xbox button from before, dpad, abxy, start/back, sync, stick click, shoulder buttons ButtonState = xbox | (((uint16_t)readBuf[5] & 0xF) << 8) | (readBuf[4] & 0xF0) | (((uint16_t)readBuf[4] & 0x0C) << 10) | ((readBuf[4] & 0x01) << 3) | (((uint16_t)readBuf[5] & 0xC0) << 8) | ((readBuf[5] & 0x30) >> 4); From 44fd6822cff133e2762d0cd578d18329ca1218b6 Mon Sep 17 00:00:00 2001 From: Anthony Lieuallen Date: Sat, 28 Jan 2017 12:41:10 -0500 Subject: [PATCH 185/220] Address "dereferencing type-punned pointer" warnings. With compiler warnings set to "More", and compiling against this library, I see warnings of the form: hidboot.h:381:21: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; ^ This change addresses those warnings, making issues in my own code easier to notice. --- hidboot.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hidboot.h b/hidboot.h index 4d0b0b26..61d63b59 100644 --- a/hidboot.h +++ b/hidboot.h @@ -286,6 +286,7 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); uint8_t buf[constBufSize]; + USB_DEVICE_DESCRIPTOR* device; uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; @@ -330,6 +331,8 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed if(!rcode) len = (buf[0] > constBufSize) ? constBufSize : buf[0]; + device = reinterpret_cast(buf); + if(rcode) { // Restore p->epinfo p->epinfo = oldep_ptr; @@ -347,7 +350,7 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from the device descriptor - epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; + epInfo[0].maxPktSize = (uint8_t)(device->bMaxPacketSize0); // Assign new address to the device rcode = pUsb->setAddr(0, 0, bAddress); @@ -378,7 +381,7 @@ uint8_t HIDBoot::Init(uint8_t parent, uint8_t port, bool lowspeed if(rcode) goto FailGetDevDescr; - num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; + num_of_conf = device->bNumConfigurations; USBTRACE2("NC:", num_of_conf); From e7a01565cdaed7b033dafcdd7742e82fcbafc069 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 31 Jan 2017 00:07:13 +0100 Subject: [PATCH 186/220] Use descriptor length in order to advance the buffer when parsing the descriptors This caused an issue with the PS4 Slim controller, as the endpoint descriptor was two bytes longer on the PS4 slim controller when reading the audio interface I suspect this is due to the fact that the audio interface (USB descriptor type 0x24) it is currently not supported by the library This is similar to what is done in the example as well: https://github.com/felis/USB_Host_Shield_2.0/blob/cbea36f76ffa0a0b1f74eb59e7ec845ccba380aa/examples/USB_desc/USB_desc.ino#L241 Fixes issue #273 --- PS4USB.h | 13 +++++++------ confdescparser.h | 7 ++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/PS4USB.h b/PS4USB.h index b5346ff6..178ebece 100644 --- a/PS4USB.h +++ b/PS4USB.h @@ -21,8 +21,9 @@ #include "hiduniversal.h" #include "PS4Parser.h" -#define PS4_VID 0x054C // Sony Corporation -#define PS4_PID 0x05C4 // PS4 Controller +#define PS4_VID 0x054C // Sony Corporation +#define PS4_PID 0x05C4 // PS4 Controller +#define PS4_PID_SLIM 0x09CC // PS4 Slim Controller /** * This class implements support for the PS4 controller via USB. @@ -44,7 +45,7 @@ public: * @return Returns true if it is connected. */ bool connected() { - return HIDUniversal::isReady() && HIDUniversal::VID == PS4_VID && HIDUniversal::PID == PS4_PID; + return HIDUniversal::isReady() && HIDUniversal::VID == PS4_VID && (HIDUniversal::PID == PS4_PID || HIDUniversal::PID == PS4_PID_SLIM); }; /** @@ -65,7 +66,7 @@ protected: * @param buf Pointer to the data buffer. */ virtual void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) { - if (HIDUniversal::VID == PS4_VID && HIDUniversal::PID == PS4_PID) + if (HIDUniversal::VID == PS4_VID && (HIDUniversal::PID == PS4_PID || HIDUniversal::PID == PS4_PID_SLIM)) PS4Parser::Parse(len, buf); }; @@ -75,7 +76,7 @@ protected: * This is useful for instance if you want to set the LEDs in a specific way. */ virtual uint8_t OnInitSuccessful() { - if (HIDUniversal::VID == PS4_VID && HIDUniversal::PID == PS4_PID) { + if (HIDUniversal::VID == PS4_VID && (HIDUniversal::PID == PS4_PID || HIDUniversal::PID == PS4_PID_SLIM)) { PS4Parser::Reset(); if (pFuncOnInit) pFuncOnInit(); // Call the user function @@ -120,7 +121,7 @@ protected: * @return Returns true if the device's VID and PID matches this driver. */ virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) { - return (vid == PS4_VID && pid == PS4_PID); + return (vid == PS4_VID && (pid == PS4_PID || HIDUniversal::PID == PS4_PID_SLIM)); }; /**@}*/ diff --git a/confdescparser.h b/confdescparser.h index a6806f2e..ed69b029 100644 --- a/confdescparser.h +++ b/confdescparser.h @@ -119,16 +119,13 @@ bool ConfigDescParser::ParseDescriptor switch(dscrType) { case USB_DESCRIPTOR_INTERFACE: isGoodInterface = false; + break; case USB_DESCRIPTOR_CONFIGURATION: - theBuffer.valueSize = sizeof (USB_CONFIGURATION_DESCRIPTOR) - 2; - break; case USB_DESCRIPTOR_ENDPOINT: - theBuffer.valueSize = sizeof (USB_ENDPOINT_DESCRIPTOR) - 2; - break; case HID_DESCRIPTOR_HID: - theBuffer.valueSize = dscrLen - 2; break; } + theBuffer.valueSize = dscrLen - 2; valParser.Initialize(&theBuffer); stateParseDescr = 4; case 4: From 3a2d0c6e1b27fd0686cd9c3ff3ad26a4aabab90b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 31 Jan 2017 00:32:09 +0100 Subject: [PATCH 187/220] Only show build status for master branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7345efb..b26b9503 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ The code is released under the GNU General Public License. __________ -[![Build Status](https://travis-ci.org/felis/USB_Host_Shield_2.0.svg)](https://travis-ci.org/felis/USB_Host_Shield_2.0) +[![Build Status](https://travis-ci.org/felis/USB_Host_Shield_2.0.svg?branch=master)](https://travis-ci.org/felis/USB_Host_Shield_2.0) # Summary This is Revision 2.0 of MAX3421E-based USB Host Shield Library for AVR's. From f89593e4ce82374b57e929f1f42cf534791656e5 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 31 Jan 2017 01:18:38 +0100 Subject: [PATCH 188/220] Re-enable strict-aliasing warnings for Travis build See #280 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1640595b..06af6041 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,7 @@ env: install: - pip install -U platformio - - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror -Wno-strict-aliasing" + - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror" # # Libraries from PlatformIO Library Registry: From 8f44b6247077adcd2b1524a0f84ee5126f501cc0 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 1 Feb 2017 11:20:09 +0100 Subject: [PATCH 189/220] Only define WIICAMERA for WiiIRCamera example --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0cdc4828..8a0adf38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ env: - PLATFORMIO_CI_SRC=examples/Bluetooth/SPPMulti - PLATFORMIO_CI_SRC=examples/Bluetooth/Wii - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiBalanceBoard - - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera + - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiIRCamera PLATFORMIO_BUILD_FLAGS="-DWIICAMERA" - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiMulti - PLATFORMIO_CI_SRC=examples/Bluetooth/WiiUProController - PLATFORMIO_CI_SRC=examples/board_qc @@ -63,7 +63,7 @@ env: install: - pip install -U platformio - - export PLATFORMIO_BUILD_FLAGS="-DDEBUG_USB_HOST -DWIICAMERA -Wall -Werror -Wno-unused-function" + - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DDEBUG_USB_HOST -Wall -Werror -Wno-unused-function" # # Libraries from PlatformIO Library Registry: From 14cf737d7d4c1ca77e85a8946ad147a6da5457e4 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 1 Feb 2017 11:26:35 +0100 Subject: [PATCH 190/220] Only ignore unused functions when building for the ESP8266 This should be removed when the ESP8266 core is updated in PlatformIO: https://github.com/esp8266/Arduino/pull/2881 --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a0adf38..afd87022 100644 --- a/.travis.yml +++ b/.travis.yml @@ -63,7 +63,7 @@ env: install: - pip install -U platformio - - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DDEBUG_USB_HOST -Wall -Werror -Wno-unused-function" + - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -DDEBUG_USB_HOST -Wall -Werror" # # Libraries from PlatformIO Library Registry: @@ -74,4 +74,6 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --board=esp12e --board=nodemcu --lib="." + - platformio ci --lib="." --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc + - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 + - platformio ci --lib="." --board=esp12e --board=nodemcu From 7b0487da80d71729a9dbe92100c23eb9915e094e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 1 Feb 2017 16:53:31 +0100 Subject: [PATCH 191/220] Try to set build flags --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index afd87022..23434961 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,5 +75,4 @@ install: script: - platformio ci --lib="." --board=uno --board=due --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc - - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 - - platformio ci --lib="." --board=esp12e --board=nodemcu + - platformio ci --verbose --lib="." --board=esp12e --board=nodemcu --project-option="build_flags=-Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 From 4158a501a953792e7c0e3eff1a25957e45fe56df Mon Sep 17 00:00:00 2001 From: Joe Bowbeer Date: Fri, 3 Feb 2017 22:44:51 -0800 Subject: [PATCH 192/220] 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 193/220] 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 194/220] 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 195/220] 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 196/220] 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 197/220] 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(':'); From 242ce6c92b4ccd88e7e65617d5c1818bffec68c8 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 7 Feb 2017 15:27:00 +0100 Subject: [PATCH 198/220] Fixed type in waitingForConnection variable and set it to false when pairing --- BTD.cpp | 6 +++--- BTD.h | 9 +++++---- keywords.txt | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 7eda8fd5..53a2c4f4 100644 --- a/BTD.cpp +++ b/BTD.cpp @@ -254,7 +254,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { hci_num_reset_loops = 100; // only loop 100 times before trying to send the hci reset command hci_counter = 0; hci_state = HCI_INIT_STATE; - watingForConnection = false; + waitingForConnection = false; bPollEnable = true; #ifdef DEBUG_USB_HOST @@ -802,14 +802,14 @@ void BTD::HCI_task() { Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80); #endif hci_write_scan_enable(); - watingForConnection = true; + waitingForConnection = true; hci_state = HCI_CONNECT_IN_STATE; } break; case HCI_CONNECT_IN_STATE: if(hci_check_flag(HCI_FLAG_INCOMING_REQUEST)) { - watingForConnection = false; + waitingForConnection = false; #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nIncoming Connection Request"), 0x80); #endif diff --git a/BTD.h b/BTD.h index d3f735b8..684835ab 100644 --- a/BTD.h +++ b/BTD.h @@ -432,7 +432,7 @@ public: /**@}*/ /** Use this to see if it is waiting for a incoming connection. */ - bool watingForConnection; + bool waitingForConnection; /** This is used by the service to know when to store the device information. */ bool l2capConnectionClaimed; /** This is used by the SPP library to claim the current SDP incoming request. */ @@ -476,14 +476,15 @@ public: /** True if it's a Wii U Pro Controller. */ bool wiiUProController; - /** Call this function to pair with a Wiimote */ + /** Call this function to pair with a HID device */ void pairWithHID() { + waitingForConnection = false; pairWithHIDDevice = true; hci_state = HCI_CHECK_DEVICE_SERVICE; }; - /** Used to only send the ACL data to the Wiimote. */ + /** Used to only send the ACL data to the HID device. */ bool connectToHIDDevice; - /** True if a Wiimote is connecting. */ + /** True if a HID device is connecting. */ bool incomingHIDDevice; /** True when it should pair with a device like a mouse or keyboard. */ bool pairWithHIDDevice; diff --git a/keywords.txt b/keywords.txt index 26707d1d..c56ad825 100644 --- a/keywords.txt +++ b/keywords.txt @@ -75,7 +75,7 @@ PS3MoveConnected KEYWORD2 PS3NavigationConnected KEYWORD2 isReady KEYWORD2 -watingForConnection KEYWORD2 +waitingForConnection KEYWORD2 isTouching KEYWORD2 getX KEYWORD2 From 5d06346303f42b18b72bbf99764150ab2e6892fa Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 7 Feb 2017 17:44:26 +0100 Subject: [PATCH 199/220] Added intel_arc32 to PlatformIO platforms --- library.json | 1 + 1 file changed, 1 insertion(+) diff --git a/library.json b/library.json index a26311d1..b3a45d26 100644 --- a/library.json +++ b/library.json @@ -46,6 +46,7 @@ "platforms": [ "atmelavr", + "intel_arc32", "teensy", "atmelsam", "nordicnrf51", From 831960bcc21d720af5e29751fed7202b72f8104a Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 7 Feb 2017 17:44:44 +0100 Subject: [PATCH 200/220] Release version 1.3.0 --- library.json | 2 +- library.properties | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library.json b/library.json index b3a45d26..d7973969 100644 --- a/library.json +++ b/library.json @@ -31,7 +31,7 @@ "type": "git", "url": "https://github.com/felis/USB_Host_Shield_2.0.git" }, - "version": "1.2.1", + "version": "1.3.0", "license": "GPL-2.0", "examples": [ diff --git a/library.properties b/library.properties index d5d4b408..dc8ac7e7 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ name=USB Host Shield Library 2.0 -version=1.2.1 +version=1.3.0 author=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll , Alexei Glushchenko (Circuits@Home) maintainer=Oleg Mazurov (Circuits@Home) , Kristian Lauszus (TKJ Electronics) , Andrew Kroll sentence=Revision 2.0 of MAX3421E-based USB Host Shield Library. paragraph=Supports HID devices, FTDI, ADK, ACM, PL2303, Bluetooth HID devices, SPP communication and mass storage devices. Furthermore it supports PS3, PS4, PS Buzz, Wii and Xbox controllers. category=Other url=https://github.com/felis/USB_Host_Shield_2.0 -architectures=* \ No newline at end of file +architectures=* From 9b4dd2dcfb832f9bb6ac30189d229dbcadca9508 Mon Sep 17 00:00:00 2001 From: Yuuichi Akagawa Date: Sun, 12 Feb 2017 22:02:00 +0900 Subject: [PATCH 201/220] Fix missing unsigned comparison. --- examples/hub_demo/hub_demo.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index adc1751f..ab77c345 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -96,7 +96,7 @@ void loop() Usb.Task(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { - if ((millis() - next_time) >= 0L) { + if ((long)(millis() - next_time) >= 0L) { Usb.ForEachUsbDevice(&PrintAllDescriptors); Usb.ForEachUsbDevice(&PrintAllAddresses); From 6fb48f48e417f1a71198abca9b536e9e2e256e5a Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 12 Feb 2017 15:10:07 +0100 Subject: [PATCH 202/220] Fix millis() and micros() rollover bug Also replace long with int32_t, so it is not architecture dependent --- BTD.cpp | 2 +- PS3BT.cpp | 10 +++++----- PS3USB.cpp | 4 ++-- SPP.cpp | 2 +- Usb.cpp | 14 +++++++------- Wii.cpp | 6 +++--- XBOXRECV.cpp | 2 +- examples/HID/SRWS1/SRWS1.ino | 2 +- examples/USB_desc/USB_desc.ino | 13 +++---------- examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino | 2 +- examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino | 4 ---- examples/hub_demo/hub_demo.ino | 2 +- examples/pl2303/pl2303_gps/pl2303_gps.ino | 2 +- examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino | 4 ++-- examples/testusbhostFAT/testusbhostFAT.ino | 6 +++--- hidboot.h | 2 +- hidcomposite.cpp | 2 +- hiduniversal.cpp | 4 ++-- masstorage.cpp | 2 +- usbhub.cpp | 2 +- 20 files changed, 38 insertions(+), 49 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 53a2c4f4..dd575fac 100644 --- a/BTD.cpp +++ b/BTD.cpp @@ -384,7 +384,7 @@ uint8_t BTD::Release() { uint8_t BTD::Poll() { if(!bPollEnable) return 0; - if((long)(millis() - qNextPollTime) >= 0L) { // Don't poll if shorter than polling interval + if((int32_t)(millis() - qNextPollTime) >= 0L) { // Don't poll if shorter than polling interval qNextPollTime = millis() + pollInterval; // Set new poll time HCI_event_task(); // Poll the HCI event pipe HCI_task(); // HCI state machine diff --git a/PS3BT.cpp b/PS3BT.cpp index 8381370b..3204125c 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -454,7 +454,7 @@ void PS3BT::L2CAP_task() { void PS3BT::Run() { switch(l2cap_state) { case PS3_ENABLE_SIXAXIS: - if(millis() - timer > 1000) { // loop 1 second before sending the command + if((int32_t)(millis() - timer) > 1000) { // loop 1 second before sending the command memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed for(uint8_t i = 15; i < 19; i++) l2capinbuf[i] = 0x7F; // Set the analog joystick values to center position @@ -465,7 +465,7 @@ void PS3BT::Run() { break; case TURN_ON_LED: - if(millis() - timer > 1000) { // loop 1 second before sending the command + if((int32_t)(millis() - timer) > 1000) { // loop 1 second before sending the command if(remote_name_first == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P') #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80); @@ -494,7 +494,7 @@ void PS3BT::Run() { case L2CAP_DONE: if(PS3MoveConnected) { // The Bulb and rumble values, has to be send at approximately every 5th second for it to stay on - if(millis() - timer > 4000) { // Send at least every 4th second + if((int32_t)(millis() - timer) > 4000) { // Send at least every 4th second HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on timer = millis(); } @@ -510,7 +510,7 @@ void PS3BT::Run() { // Playstation Sixaxis Dualshock and Navigation Controller commands void PS3BT::HID_Command(uint8_t* data, uint8_t nbytes) { - if(millis() - timerHID <= 150) // Check if is has been more than 150ms since last command + if((int32_t)(millis() - timerHID) <= 150) // Check if is has been more than 150ms since last command delay((uint32_t)(150 - (millis() - timerHID))); // There have to be a delay between commands pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]); // Both the Navigation and Dualshock controller sends data via the control channel timerHID = millis(); @@ -595,7 +595,7 @@ void PS3BT::enable_sixaxis() { // Command used to enable the Dualshock 3 and Nav // Playstation Move Controller commands void PS3BT::HIDMove_Command(uint8_t* data, uint8_t nbytes) { - if(millis() - timerHID <= 150)// Check if is has been less than 150ms since last command + if((int32_t)(millis() - timerHID) <= 150)// Check if is has been less than 150ms since last command delay((uint32_t)(150 - (millis() - timerHID))); // There have to be a delay between commands pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // The Move controller sends it's data via the intterrupt channel timerHID = millis(); diff --git a/PS3USB.cpp b/PS3USB.cpp index b14e67c7..fe54ea5f 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -276,14 +276,14 @@ uint8_t PS3USB::Poll() { if(PS3Connected || PS3NavigationConnected) { uint16_t BUFFER_SIZE = EP_MAXPKTSIZE; pUsb->inTransfer(bAddress, epInfo[ PS3_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1 - if(millis() - timer > 100) { // Loop 100ms before processing data + if((int32_t)(millis() - timer) > 100) { // Loop 100ms before processing data readReport(); #ifdef PRINTREPORT printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers #endif } } else if(PS3MoveConnected) { // One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB - if(millis() - timer > 4000) { // Send at least every 4th second + if((int32_t)(millis() - timer) > 4000) { // Send at least every 4th second Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on timer = millis(); } diff --git a/SPP.cpp b/SPP.cpp index 0f4ee5e9..89a98fe1 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -421,7 +421,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { } void SPP::Run() { - if(waitForLastCommand && (millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it + if(waitForLastCommand && (int32_t)(millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80); #endif diff --git a/Usb.cpp b/Usb.cpp index d6755c9d..bc700971 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -313,7 +313,7 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 if(maxpktsize < 1 || maxpktsize > 64) return USB_ERROR_INVALID_MAX_PKT_SIZE; - unsigned long timeout = millis() + USB_XFER_TIMEOUT; + uint32_t timeout = millis() + USB_XFER_TIMEOUT; regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value @@ -328,7 +328,7 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ rcode = (regRd(rHRSL) & 0x0f); - while(rcode && ((long)(millis() - timeout) < 0L)) { + while(rcode && ((int32_t)(millis() - timeout) < 0L)) { switch(rcode) { case hrNAK: nak_count++; @@ -375,17 +375,17 @@ breakout: /* return codes 0x00-0x0f are HRSLT( 0x00 being success ), 0xff means timeout */ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { - unsigned long timeout = millis() + USB_XFER_TIMEOUT; + uint32_t timeout = millis() + USB_XFER_TIMEOUT; uint8_t tmpdata; uint8_t rcode = hrSUCCESS; uint8_t retry_count = 0; uint16_t nak_count = 0; - while((long)(millis() - timeout) < 0L) { + while((int32_t)(millis() - timeout) < 0L) { regWr(rHXFR, (token | ep)); //launch the transfer rcode = USB_ERROR_TRANSFER_TIMEOUT; - while((long)(millis() - timeout) < 0L) //wait for transfer completion + while((int32_t)(millis() - timeout) < 0L) //wait for transfer completion { tmpdata = regRd(rHIRQ); @@ -476,7 +476,7 @@ void USB::Task(void) //USB state machine case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here break; case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device - if((long)(millis() - delay) >= 0L) + if((int32_t)(millis() - delay) >= 0L) usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE; else break; // don't fall through case USB_ATTACHED_SUBSTATE_RESET_DEVICE: @@ -503,7 +503,7 @@ void USB::Task(void) //USB state machine } break; case USB_ATTACHED_SUBSTATE_WAIT_RESET: - if((long)(millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING; + if((int32_t)(millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING; else break; // don't fall through case USB_STATE_CONFIGURING: diff --git a/Wii.cpp b/Wii.cpp index 460e4b23..2692a854 100644 --- a/Wii.cpp +++ b/Wii.cpp @@ -545,7 +545,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { Notify(wiimotePitch, 0x80); */ } else { - if((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values + if((int32_t)(micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nThe gyro values has been reset"), 0x80); #endif @@ -698,7 +698,7 @@ void WII::L2CAP_task() { /* The next states are in run() */ case L2CAP_INTERRUPT_DISCONNECT: - if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) && ((long)(millis() - timer) >= 0L)) { + if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) && ((int32_t)(millis() - timer) >= 0L)) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); #endif @@ -723,7 +723,7 @@ void WII::L2CAP_task() { } void WII::Run() { - if(l2cap_state == L2CAP_INTERRUPT_DISCONNECT && ((long)(millis() - timer) >= 0L)) + if(l2cap_state == L2CAP_INTERRUPT_DISCONNECT && ((int32_t)(millis() - timer) >= 0L)) L2CAP_task(); // Call the rest of the disconnection routine after we have waited long enough switch(l2cap_state) { diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index 7431fa43..b3c3f730 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -293,7 +293,7 @@ uint8_t XBOXRECV::Release() { uint8_t XBOXRECV::Poll() { if(!bPollEnable) return 0; - if(!checkStatusTimer || ((millis() - checkStatusTimer) > 3000)) { // Run checkStatus every 3 seconds + if(!checkStatusTimer || ((int32_t)(millis() - checkStatusTimer) > 3000)) { // Run checkStatus every 3 seconds checkStatusTimer = millis(); checkStatus(); } diff --git a/examples/HID/SRWS1/SRWS1.ino b/examples/HID/SRWS1/SRWS1.ino index c83936fd..fb160316 100644 --- a/examples/HID/SRWS1/SRWS1.ino +++ b/examples/HID/SRWS1/SRWS1.ino @@ -33,7 +33,7 @@ void loop() { Serial.println(srw1.srws1Data.tilt); } else { // Show strobe light effect static uint32_t timer; - if (millis() - timer > 12) { + if ((int32_t)(millis() - timer) > 12) { timer = millis(); // Reset timer static uint16_t leds = 0; diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index acfe57d3..dd9c5b22 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -17,8 +17,6 @@ USB Usb; //USBHub Hub6(&Usb); //USBHub Hub7(&Usb); -uint32_t next_time; - void PrintAllAddresses(UsbDevice *pdev) { UsbDeviceAddress adr; @@ -60,8 +58,6 @@ void setup() Serial.println("OSC did not start."); delay( 200 ); - - next_time = millis() + 10000; } byte getdevdescr( byte addr, byte &num_conf ); @@ -105,13 +101,10 @@ void loop() if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { - //if (millis() >= next_time) - { - Usb.ForEachUsbDevice(&PrintAllDescriptors); - Usb.ForEachUsbDevice(&PrintAllAddresses); + Usb.ForEachUsbDevice(&PrintAllDescriptors); + Usb.ForEachUsbDevice(&PrintAllAddresses); - while ( 1 ); //stop - } + while ( 1 ); //stop } } diff --git a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino index d59b9bb3..710a6d1f 100644 --- a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino +++ b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino @@ -68,7 +68,7 @@ void loop() { digitalWrite(LED, msg[0] ? HIGH : LOW); } - if (millis() - timer >= 1000) { // Send data every 1s + if ((int32_t)(millis() - timer) >= 1000) { // Send data every 1s timer = millis(); rcode = adk.SndData(sizeof(timer), (uint8_t*)&timer); if (rcode && rcode != hrNAK) { diff --git a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino index 5be7adc2..b7d51a4c 100644 --- a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino +++ b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino @@ -39,8 +39,6 @@ USB Usb; FTDIAsync FtdiAsync; FTDI Ftdi(&Usb, &FtdiAsync); -uint32_t next_time; - void setup() { Serial.begin( 115200 ); @@ -53,8 +51,6 @@ void setup() Serial.println("OSC did not start."); delay( 200 ); - - next_time = millis() + 5000; } void loop() diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index ab77c345..68bf0727 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -96,7 +96,7 @@ void loop() Usb.Task(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { - if ((long)(millis() - next_time) >= 0L) { + if ((int32_t)(millis() - next_time) >= 0L) { Usb.ForEachUsbDevice(&PrintAllDescriptors); Usb.ForEachUsbDevice(&PrintAllAddresses); diff --git a/examples/pl2303/pl2303_gps/pl2303_gps.ino b/examples/pl2303/pl2303_gps/pl2303_gps.ino index e8c8a022..efb1b523 100644 --- a/examples/pl2303/pl2303_gps/pl2303_gps.ino +++ b/examples/pl2303/pl2303_gps/pl2303_gps.ino @@ -71,7 +71,7 @@ void loop() { if(Pl.isReady()) { /* reading the GPS */ - if((long)(millis() - read_delay) >= 0L) { + if((int32_t)(millis() - read_delay) >= 0L) { read_delay += READ_DELAY; rcode = Pl.RcvData(&rcvd, buf); if(rcode && rcode != hrNAK) diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index d527eabe..9af3b57b 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -94,10 +94,10 @@ void loop() if( Pl.isReady()) { bool newdata = false; - unsigned long start = millis(); + uint32_t start = millis(); // Every 5 seconds we print an update - while (millis() - start < 5000) { + while ((int32_t)(millis() - start) < 5000) { if( feedgps()) { newdata = true; } diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino index e8b9cd35..7deb16bc 100644 --- a/examples/testusbhostFAT/testusbhostFAT.ino +++ b/examples/testusbhostFAT/testusbhostFAT.ino @@ -371,7 +371,7 @@ void serialEvent() { // ALL teensy versions LACK PWM ON LED ISR(TIMER3_COMPA_vect) { - if((long)(millis() - LEDnext_time) >= 0L) { + if((int32_t)(millis() - LEDnext_time) >= 0L) { LEDnext_time = millis() + 30; // set the brightness of LED @@ -407,7 +407,7 @@ void loop() { #if defined(__AVR__) // Print a heap status report about every 10 seconds. - if((long)(millis() - HEAPnext_time) >= 0L) { + if((int32_t)(millis() - HEAPnext_time) >= 0L) { if(UsbDEBUGlvl > 0x50) { printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap()); } @@ -421,7 +421,7 @@ void loop() { #endif // Horrid! This sort of thing really belongs in an ISR, not here! // We also will be needing to test each hub port, we don't do this yet! - if(!change && !usbon && (long)(millis() - usbon_time) >= 0L) { + if(!change && !usbon && (int32_t)(millis() - usbon_time) >= 0L) { change = true; usbon = true; } diff --git a/hidboot.h b/hidboot.h index 61d63b59..a25d0390 100644 --- a/hidboot.h +++ b/hidboot.h @@ -578,7 +578,7 @@ template uint8_t HIDBoot::Poll() { uint8_t rcode = 0; - if(bPollEnable && ((long)(millis() - qNextPollTime) >= 0L)) { + if(bPollEnable && ((int32_t)(millis() - qNextPollTime) >= 0L)) { // To-do: optimize manually, using the for loop only if needed. for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) { diff --git a/hidcomposite.cpp b/hidcomposite.cpp index a22aaa02..f4047690 100644 --- a/hidcomposite.cpp +++ b/hidcomposite.cpp @@ -360,7 +360,7 @@ uint8_t HIDComposite::Poll() { if(!bPollEnable) return 0; - if((long)(millis() - qNextPollTime) >= 0L) { + if((int32_t)(millis() - qNextPollTime) >= 0L) { qNextPollTime = millis() + pollInterval; uint8_t buf[constBuffLen]; diff --git a/hiduniversal.cpp b/hiduniversal.cpp index 1cc92521..1e87b04b 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -372,7 +372,7 @@ uint8_t HIDUniversal::Poll() { if(!bPollEnable) return 0; - if((long)(millis() - qNextPollTime) >= 0L) { + if((int32_t)(millis() - qNextPollTime) >= 0L) { qNextPollTime = millis() + pollInterval; uint8_t buf[constBuffLen]; @@ -424,4 +424,4 @@ uint8_t HIDUniversal::Poll() { // Send a report to interrupt out endpoint. This is NOT SetReport() request! uint8_t HIDUniversal::SndRpt(uint16_t nbytes, uint8_t *dataptr) { return pUsb->outTransfer(bAddress, epInfo[epInterruptOutIndex].epAddr, nbytes, dataptr); -} \ No newline at end of file +} diff --git a/masstorage.cpp b/masstorage.cpp index b528bb80..a2394419 100644 --- a/masstorage.cpp +++ b/masstorage.cpp @@ -673,7 +673,7 @@ uint8_t BulkOnly::Poll() { if(!bPollEnable) return 0; - if((long)(millis() - qNextPollTime) >= 0L) { + if((int32_t)(millis() - qNextPollTime) >= 0L) { CheckMedia(); } //rcode = 0; diff --git a/usbhub.cpp b/usbhub.cpp index 6ead8bd0..d9e4e83d 100644 --- a/usbhub.cpp +++ b/usbhub.cpp @@ -232,7 +232,7 @@ uint8_t USBHub::Poll() { if(!bPollEnable) return 0; - if(((long)(millis() - qNextPollTime) >= 0L)) { + if(((int32_t)(millis() - qNextPollTime) >= 0L)) { rcode = CheckHubStatus(); qNextPollTime = millis() + 100; } From 42948831ce92c51a94c5175c063946cf61d04ea5 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 12 Feb 2017 16:58:14 +0100 Subject: [PATCH 203/220] Explicit cast millis() and micros() to uint32_t, as it is uint64_t on the Arduino 101 --- BTD.cpp | 4 +-- PS3BT.cpp | 28 ++++++++--------- PS3USB.cpp | 8 ++--- SPP.cpp | 4 +-- Usb.cpp | 22 +++++++------- Wii.cpp | 26 ++++++++-------- XBOXRECV.cpp | 4 +-- cdcftdi.cpp | 4 +-- cdcprolific.cpp | 4 +-- examples/HID/SRWS1/SRWS1.ino | 4 +-- examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino | 4 --- .../USBHIDBootKbdAndMouse.ino | 4 --- .../HID/USBHIDBootMouse/USBHIDBootMouse.ino | 4 --- .../USBH_MIDI_dump/USBH_MIDI_dump.ino | 11 +------ .../USB_MIDI_converter/USB_MIDI_converter.ino | 7 ++--- .../USB_MIDI_converter_multi.ino | 7 ++--- .../bidrectional_converter.ino | 6 ++-- .../adk/ArduinoBlinkLED/ArduinoBlinkLED.ino | 4 +-- examples/adk/term_time/term_time.ino | 2 +- examples/hub_demo/hub_demo.ino | 4 +-- examples/max_LCD/max_LCD.ino | 2 +- examples/pl2303/pl2303_gps/pl2303_gps.ino | 2 +- .../pl2303/pl2303_tinygps/pl2303_tinygps.ino | 4 +-- examples/testusbhostFAT/testusbhostFAT.ino | 30 +++++++++---------- hidboot.h | 4 +-- hidcomposite.cpp | 4 +-- hiduniversal.cpp | 4 +-- masstorage.cpp | 4 +-- usbhub.cpp | 4 +-- 29 files changed, 95 insertions(+), 124 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index dd575fac..df1de1b8 100644 --- a/BTD.cpp +++ b/BTD.cpp @@ -384,8 +384,8 @@ uint8_t BTD::Release() { uint8_t BTD::Poll() { if(!bPollEnable) return 0; - if((int32_t)(millis() - qNextPollTime) >= 0L) { // Don't poll if shorter than polling interval - qNextPollTime = millis() + pollInterval; // Set new poll time + if((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L) { // Don't poll if shorter than polling interval + qNextPollTime = (uint32_t)millis() + pollInterval; // Set new poll time HCI_event_task(); // Poll the HCI event pipe HCI_task(); // HCI state machine ACL_event_task(); // Poll the ACL input pipe too diff --git a/PS3BT.cpp b/PS3BT.cpp index 3204125c..1e4e7f41 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -339,7 +339,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { if(PS3Connected || PS3MoveConnected || PS3NavigationConnected) { /* Read Report */ if(l2capinbuf[8] == 0xA1) { // HID_THDR_DATA_INPUT - lastMessageTime = millis(); // Store the last message time + lastMessageTime = (uint32_t)millis(); // Store the last message time if(PS3Connected || PS3NavigationConnected) ButtonState = (uint32_t)(l2capinbuf[11] | ((uint16_t)l2capinbuf[12] << 8) | ((uint32_t)l2capinbuf[13] << 16)); @@ -420,7 +420,7 @@ void PS3BT::L2CAP_task() { l2cap_state = TURN_ON_LED; } else l2cap_state = PS3_ENABLE_SIXAXIS; - timer = millis(); + timer = (uint32_t)millis(); } break; @@ -454,18 +454,18 @@ void PS3BT::L2CAP_task() { void PS3BT::Run() { switch(l2cap_state) { case PS3_ENABLE_SIXAXIS: - if((int32_t)(millis() - timer) > 1000) { // loop 1 second before sending the command + if((int32_t)((uint32_t)millis() - timer) > 1000) { // loop 1 second before sending the command memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed for(uint8_t i = 15; i < 19; i++) l2capinbuf[i] = 0x7F; // Set the analog joystick values to center position enable_sixaxis(); l2cap_state = TURN_ON_LED; - timer = millis(); + timer = (uint32_t)millis(); } break; case TURN_ON_LED: - if((int32_t)(millis() - timer) > 1000) { // loop 1 second before sending the command + if((int32_t)((uint32_t)millis() - timer) > 1000) { // loop 1 second before sending the command if(remote_name_first == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P') #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80); @@ -477,7 +477,7 @@ void PS3BT::Run() { #endif PS3NavigationConnected = true; } else if(remote_name_first == 'M') { // First letter in Motion Controller ('M') - timer = millis(); + timer = (uint32_t)millis(); #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80); #endif @@ -494,9 +494,9 @@ void PS3BT::Run() { case L2CAP_DONE: if(PS3MoveConnected) { // The Bulb and rumble values, has to be send at approximately every 5th second for it to stay on - if((int32_t)(millis() - timer) > 4000) { // Send at least every 4th second + if((int32_t)((uint32_t)millis() - timer) > 4000) { // Send at least every 4th second HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on - timer = millis(); + timer = (uint32_t)millis(); } } break; @@ -510,10 +510,10 @@ void PS3BT::Run() { // Playstation Sixaxis Dualshock and Navigation Controller commands void PS3BT::HID_Command(uint8_t* data, uint8_t nbytes) { - if((int32_t)(millis() - timerHID) <= 150) // Check if is has been more than 150ms since last command - delay((uint32_t)(150 - (millis() - timerHID))); // There have to be a delay between commands + if((int32_t)((uint32_t)millis() - timerHID) <= 150) // Check if is has been more than 150ms since last command + delay((uint32_t)(150 - ((uint32_t)millis() - timerHID))); // There have to be a delay between commands pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]); // Both the Navigation and Dualshock controller sends data via the control channel - timerHID = millis(); + timerHID = (uint32_t)millis(); } void PS3BT::setAllOff() { @@ -595,10 +595,10 @@ void PS3BT::enable_sixaxis() { // Command used to enable the Dualshock 3 and Nav // Playstation Move Controller commands void PS3BT::HIDMove_Command(uint8_t* data, uint8_t nbytes) { - if((int32_t)(millis() - timerHID) <= 150)// Check if is has been less than 150ms since last command - delay((uint32_t)(150 - (millis() - timerHID))); // There have to be a delay between commands + if((int32_t)((uint32_t)millis() - timerHID) <= 150)// Check if is has been less than 150ms since last command + delay((uint32_t)(150 - ((uint32_t)millis() - timerHID))); // There have to be a delay between commands pBtd->L2CAP_Command(hci_handle, data, nbytes, interrupt_scid[0], interrupt_scid[1]); // The Move controller sends it's data via the intterrupt channel - timerHID = millis(); + timerHID = (uint32_t)millis(); } void PS3BT::moveSetBulb(uint8_t r, uint8_t g, uint8_t b) { // Use this to set the Color using RGB values diff --git a/PS3USB.cpp b/PS3USB.cpp index fe54ea5f..081a7a20 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -221,7 +221,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { bPollEnable = true; Notify(PSTR("\r\n"), 0x80); - timer = millis(); + timer = (uint32_t)millis(); return 0; // Successful configuration /* Diagnostic messages */ @@ -276,16 +276,16 @@ uint8_t PS3USB::Poll() { if(PS3Connected || PS3NavigationConnected) { uint16_t BUFFER_SIZE = EP_MAXPKTSIZE; pUsb->inTransfer(bAddress, epInfo[ PS3_INPUT_PIPE ].epAddr, &BUFFER_SIZE, readBuf); // input on endpoint 1 - if((int32_t)(millis() - timer) > 100) { // Loop 100ms before processing data + if((int32_t)((uint32_t)millis() - timer) > 100) { // Loop 100ms before processing data readReport(); #ifdef PRINTREPORT printReport(); // Uncomment "#define PRINTREPORT" to print the report send by the PS3 Controllers #endif } } else if(PS3MoveConnected) { // One can only set the color of the bulb, set the rumble, set and get the bluetooth address and calibrate the magnetometer via USB - if((int32_t)(millis() - timer) > 4000) { // Send at least every 4th second + if((int32_t)((uint32_t)millis() - timer) > 4000) { // Send at least every 4th second Move_Command(writeBuf, MOVE_REPORT_BUFFER_SIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on - timer = millis(); + timer = (uint32_t)millis(); } } return 0; diff --git a/SPP.cpp b/SPP.cpp index 89a98fe1..009ea7bc 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -370,7 +370,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { #endif sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send credit creditSent = true; - timer = millis(); + timer = (uint32_t)millis(); waitForLastCommand = true; } } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit @@ -421,7 +421,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { } void SPP::Run() { - if(waitForLastCommand && (int32_t)(millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it + if(waitForLastCommand && (int32_t)((uint32_t)millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80); #endif diff --git a/Usb.cpp b/Usb.cpp index bc700971..4f554c8b 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -313,7 +313,7 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 if(maxpktsize < 1 || maxpktsize > 64) return USB_ERROR_INVALID_MAX_PKT_SIZE; - uint32_t timeout = millis() + USB_XFER_TIMEOUT; + uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT; regWr(rHCTL, (pep->bmSndToggle) ? bmSNDTOG1 : bmSNDTOG0); //set toggle value @@ -328,7 +328,7 @@ uint8_t USB::OutTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t nbytes, uint8 regWr(rHIRQ, bmHXFRDNIRQ); //clear IRQ rcode = (regRd(rHRSL) & 0x0f); - while(rcode && ((int32_t)(millis() - timeout) < 0L)) { + while(rcode && ((int32_t)((uint32_t)millis() - timeout) < 0L)) { switch(rcode) { case hrNAK: nak_count++; @@ -375,17 +375,17 @@ breakout: /* return codes 0x00-0x0f are HRSLT( 0x00 being success ), 0xff means timeout */ uint8_t USB::dispatchPkt(uint8_t token, uint8_t ep, uint16_t nak_limit) { - uint32_t timeout = millis() + USB_XFER_TIMEOUT; + uint32_t timeout = (uint32_t)millis() + USB_XFER_TIMEOUT; uint8_t tmpdata; uint8_t rcode = hrSUCCESS; uint8_t retry_count = 0; uint16_t nak_count = 0; - while((int32_t)(millis() - timeout) < 0L) { + while((int32_t)((uint32_t)millis() - timeout) < 0L) { regWr(rHXFR, (token | ep)); //launch the transfer rcode = USB_ERROR_TRANSFER_TIMEOUT; - while((int32_t)(millis() - timeout) < 0L) //wait for transfer completion + while((int32_t)((uint32_t)millis() - timeout) < 0L) //wait for transfer completion { tmpdata = regRd(rHIRQ); @@ -451,7 +451,7 @@ void USB::Task(void) //USB state machine //intentional fallthrough case FSHOST: //attached if((usb_task_state & USB_STATE_MASK) == USB_STATE_DETACHED) { - delay = millis() + USB_SETTLE_DELAY; + delay = (uint32_t)millis() + USB_SETTLE_DELAY; usb_task_state = USB_ATTACHED_SUBSTATE_SETTLE; } break; @@ -476,7 +476,7 @@ void USB::Task(void) //USB state machine case USB_DETACHED_SUBSTATE_ILLEGAL: //just sit here break; case USB_ATTACHED_SUBSTATE_SETTLE: //settle time for just attached device - if((int32_t)(millis() - delay) >= 0L) + if((int32_t)((uint32_t)millis() - delay) >= 0L) usb_task_state = USB_ATTACHED_SUBSTATE_RESET_DEVICE; else break; // don't fall through case USB_ATTACHED_SUBSTATE_RESET_DEVICE: @@ -488,22 +488,22 @@ void USB::Task(void) //USB state machine tmpdata = regRd(rMODE) | bmSOFKAENAB; //start SOF generation regWr(rMODE, tmpdata); usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_SOF; - //delay = millis() + 20; //20ms wait after reset per USB spec + //delay = (uint32_t)millis() + 20; //20ms wait after reset per USB spec } break; case USB_ATTACHED_SUBSTATE_WAIT_SOF: //todo: change check order if(regRd(rHIRQ) & bmFRAMEIRQ) { //when first SOF received _and_ 20ms has passed we can continue /* - if (delay < millis()) //20ms passed + if (delay < (uint32_t)millis()) //20ms passed usb_task_state = USB_STATE_CONFIGURING; */ usb_task_state = USB_ATTACHED_SUBSTATE_WAIT_RESET; - delay = millis() + 20; + delay = (uint32_t)millis() + 20; } break; case USB_ATTACHED_SUBSTATE_WAIT_RESET: - if((int32_t)(millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING; + if((int32_t)((uint32_t)millis() - delay) >= 0L) usb_task_state = USB_STATE_CONFIGURING; else break; // don't fall through case USB_STATE_CONFIGURING: diff --git a/Wii.cpp b/Wii.cpp index 2692a854..5f79104c 100644 --- a/Wii.cpp +++ b/Wii.cpp @@ -121,9 +121,9 @@ void WII::disconnect() { // Use this void to disconnect any of the controllers #endif initExtension1(); // This will disable the Motion Plus extension } - timer = millis() + 1000; // We have to wait for the message before the rest of the channels can be deactivated + timer = (uint32_t)millis() + 1000; // We have to wait for the message before the rest of the channels can be deactivated } else - timer = millis(); // Don't wait + timer = (uint32_t)millis(); // Don't wait // First the HID interrupt channel has to be disconnected, then the HID control channel and finally the HCI connection pBtd->l2cap_disconnection_request(hci_handle, ++identifier, interrupt_scid, interrupt_dcid); Reset(); @@ -522,13 +522,13 @@ void WII::ACLData(uint8_t* l2capinbuf) { if(!(l2capinbuf[19] & 0x02)) // Check if fast mode is used rollGyroSpeed *= 4.545; - compPitch = (0.93f * (compPitch + (pitchGyroSpeed * (float)(micros() - timer) / 1000000.0f)))+(0.07f * getWiimotePitch()); // Use a complimentary filter to calculate the angle - compRoll = (0.93f * (compRoll + (rollGyroSpeed * (float)(micros() - timer) / 1000000.0f)))+(0.07f * getWiimoteRoll()); + compPitch = (0.93f * (compPitch + (pitchGyroSpeed * (float)((uint32_t)micros() - timer) / 1000000.0f)))+(0.07f * getWiimotePitch()); // Use a complimentary filter to calculate the angle + compRoll = (0.93f * (compRoll + (rollGyroSpeed * (float)((uint32_t)micros() - timer) / 1000000.0f)))+(0.07f * getWiimoteRoll()); - gyroYaw += (yawGyroSpeed * ((float)(micros() - timer) / 1000000.0f)); - gyroRoll += (rollGyroSpeed * ((float)(micros() - timer) / 1000000.0f)); - gyroPitch += (pitchGyroSpeed * ((float)(micros() - timer) / 1000000.0f)); - timer = micros(); + gyroYaw += (yawGyroSpeed * ((float)((uint32_t)micros() - timer) / 1000000.0f)); + gyroRoll += (rollGyroSpeed * ((float)((uint32_t)micros() - timer) / 1000000.0f)); + gyroPitch += (pitchGyroSpeed * ((float)((uint32_t)micros() - timer) / 1000000.0f)); + timer = (uint32_t)micros(); /* // Uncomment these lines to tune the gyro scale variabels Notify(PSTR("\r\ngyroYaw: "), 0x80); @@ -545,7 +545,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { Notify(wiimotePitch, 0x80); */ } else { - if((int32_t)(micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values + if((int32_t)((uint32_t)micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nThe gyro values has been reset"), 0x80); #endif @@ -562,7 +562,7 @@ void WII::ACLData(uint8_t* l2capinbuf) { gyroPitch = 0; motionValuesReset = true; - timer = micros(); + timer = (uint32_t)micros(); } } } else { @@ -698,7 +698,7 @@ void WII::L2CAP_task() { /* The next states are in run() */ case L2CAP_INTERRUPT_DISCONNECT: - if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) && ((int32_t)(millis() - timer) >= 0L)) { + if(l2cap_check_flag(L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE) && ((int32_t)((uint32_t)millis() - timer) >= 0L)) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); #endif @@ -723,7 +723,7 @@ void WII::L2CAP_task() { } void WII::Run() { - if(l2cap_state == L2CAP_INTERRUPT_DISCONNECT && ((int32_t)(millis() - timer) >= 0L)) + if(l2cap_state == L2CAP_INTERRUPT_DISCONNECT && ((int32_t)((uint32_t)millis() - timer) >= 0L)) L2CAP_task(); // Call the rest of the disconnection routine after we have waited long enough switch(l2cap_state) { @@ -765,7 +765,7 @@ void WII::Run() { if(wii_check_flag(WII_FLAG_MOTION_PLUS_CONNECTED)) { stateCounter = 0; l2cap_state = WII_INIT_MOTION_PLUS_STATE; - timer = micros(); + timer = (uint32_t)micros(); if(unknownExtensionConnected) { #ifdef DEBUG_USB_HOST diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index b3c3f730..39346b12 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -293,8 +293,8 @@ uint8_t XBOXRECV::Release() { uint8_t XBOXRECV::Poll() { if(!bPollEnable) return 0; - if(!checkStatusTimer || ((int32_t)(millis() - checkStatusTimer) > 3000)) { // Run checkStatus every 3 seconds - checkStatusTimer = millis(); + if(!checkStatusTimer || ((int32_t)((uint32_t)millis() - checkStatusTimer) > 3000)) { // Run checkStatus every 3 seconds + checkStatusTimer = (uint32_t)millis(); checkStatus(); } diff --git a/cdcftdi.cpp b/cdcftdi.cpp index 98d7da70..91f189d2 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -261,11 +261,11 @@ uint8_t FTDI::Poll() { //if (!bPollEnable) // return 0; - //if (qNextPollTime <= millis()) + //if (qNextPollTime <= (uint32_t)millis()) //{ // USB_HOST_SERIAL.println(bAddress, HEX); - // qNextPollTime = millis() + 100; + // qNextPollTime = (uint32_t)millis() + 100; //} return rcode; } diff --git a/cdcprolific.cpp b/cdcprolific.cpp index eceb1df9..90d41e67 100644 --- a/cdcprolific.cpp +++ b/cdcprolific.cpp @@ -237,11 +237,11 @@ Fail: // //if (!bPollEnable) // // return 0; // -// //if (qNextPollTime <= millis()) +// //if (qNextPollTime <= (uint32_t)millis()) // //{ // // USB_HOST_SERIAL.println(bAddress, HEX); // -// // qNextPollTime = millis() + 100; +// // qNextPollTime = (uint32_t)millis() + 100; // //} // return rcode; //} diff --git a/examples/HID/SRWS1/SRWS1.ino b/examples/HID/SRWS1/SRWS1.ino index fb160316..41ffc743 100644 --- a/examples/HID/SRWS1/SRWS1.ino +++ b/examples/HID/SRWS1/SRWS1.ino @@ -33,8 +33,8 @@ void loop() { Serial.println(srw1.srws1Data.tilt); } else { // Show strobe light effect static uint32_t timer; - if ((int32_t)(millis() - timer) > 12) { - timer = millis(); // Reset timer + if ((int32_t)((uint32_t)millis() - timer) > 12) { + timer = (uint32_t)millis(); // Reset timer static uint16_t leds = 0; //PrintHex (leds, 0x80); Serial.println(); diff --git a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino index d7f7d60d..ed475887 100644 --- a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino +++ b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino @@ -100,8 +100,6 @@ USB Usb; //USBHub Hub(&Usb); HIDBoot HidKeyboard(&Usb); -uint32_t next_time; - KbdRptParser Prs; void setup() @@ -117,8 +115,6 @@ void setup() delay( 200 ); - next_time = millis() + 5000; - HidKeyboard.SetReportParser(0, &Prs); } diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino index 95963444..9644d343 100644 --- a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -145,8 +145,6 @@ HIDBoot < USB_HID_PROTOCOL_KEYBOARD | USB_HID_PROTOCOL_MOUSE > HidComposite(&Usb HIDBoot HidKeyboard(&Usb); HIDBoot HidMouse(&Usb); -//uint32_t next_time; - KbdRptParser KbdPrs; MouseRptParser MousePrs; @@ -163,8 +161,6 @@ void setup() delay( 200 ); - //next_time = millis() + 5000; - HidComposite.SetReportParser(0, &KbdPrs); HidComposite.SetReportParser(1, &MousePrs); HidKeyboard.SetReportParser(0, &KbdPrs); diff --git a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino index 9816bcb5..df5f2844 100644 --- a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino +++ b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino @@ -54,8 +54,6 @@ USB Usb; USBHub Hub(&Usb); HIDBoot HidMouse(&Usb); -uint32_t next_time; - MouseRptParser Prs; void setup() @@ -71,8 +69,6 @@ void setup() delay( 200 ); - next_time = millis() + 5000; - HidMouse.SetReportParser(0, &Prs); } 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 d5e3f1db..524447f3 100644 --- a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -43,16 +43,11 @@ void setup() void loop() { - //unsigned long t1; - Usb.Task(); - //t1 = micros(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); } - //delay(1ms) - //doDelay(t1, micros(), 1000); } // Poll USB MIDI Controler and send to serial MIDI @@ -69,11 +64,7 @@ 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 + sprintf(buf, "%08lX: ", (uint32_t)millis()); Serial.print(buf); Serial.print(rcvd); Serial.print(':'); diff --git a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino index 38547a1b..ddc803dd 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino @@ -49,16 +49,13 @@ void setup() void loop() { - unsigned long t1; - Usb.Task(); - t1 = micros(); + uint32_t t1 = (uint32_t)micros(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); } - //delay(1ms) - doDelay(t1, micros(), 1000); + doDelay(t1, (uint32_t)micros(), 1000); } // Poll USB MIDI Controler and send to serial MIDI diff --git a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino index a4ddd333..76421ca4 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino @@ -51,16 +51,13 @@ void setup() void loop() { - unsigned long t1; - Usb.Task(); - t1 = micros(); + uint32_t t1 = (uint32_t)micros(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); } - //delay(1ms) - doDelay(t1, micros(), 1000); + doDelay(t1, (uint32_t)micros(), 1000); } // Poll USB MIDI Controler and send to serial MIDI diff --git a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino index 78f62385..ce1efc4f 100644 --- a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino +++ b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino @@ -70,11 +70,10 @@ void setup() void loop() { - unsigned long t1; uint8_t msg[4]; Usb.Task(); - t1 = micros(); + uint32_t t1 = (uint32_t)micros(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); @@ -94,8 +93,7 @@ void loop() } } } - //delay(1ms) - doDelay(t1, micros(), 1000); + doDelay(t1, (uint32_t)micros(), 1000); } // Poll USB MIDI Controler and send to serial MIDI diff --git a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino index 710a6d1f..08fc6c80 100644 --- a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino +++ b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino @@ -68,8 +68,8 @@ void loop() { digitalWrite(LED, msg[0] ? HIGH : LOW); } - if ((int32_t)(millis() - timer) >= 1000) { // Send data every 1s - timer = millis(); + if ((int32_t)((uint32_t)millis() - timer) >= 1000) { // Send data every 1s + timer = (uint32_t)millis(); rcode = adk.SndData(sizeof(timer), (uint8_t*)&timer); if (rcode && rcode != hrNAK) { Serial.print(F("\r\nData send: ")); diff --git a/examples/adk/term_time/term_time.ino b/examples/adk/term_time/term_time.ino index 778fb28f..0f479a60 100644 --- a/examples/adk/term_time/term_time.ino +++ b/examples/adk/term_time/term_time.ino @@ -41,7 +41,7 @@ void loop() return; } - ultoa( millis() / 1000, (char *)buf, 10 ); + ultoa((uint32_t)millis() / 1000, (char *)buf, 10 ); rcode = adk.SndData( strlen((char *)buf), buf ); if (rcode && rcode != hrNAK) { diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index 68bf0727..fb3bd69f 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -57,7 +57,7 @@ void setup() delay( 200 ); - next_time = millis() + 10000; + next_time = (uint32_t)millis() + 10000; } void PrintDescriptors(uint8_t addr) @@ -96,7 +96,7 @@ void loop() Usb.Task(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { - if ((int32_t)(millis() - next_time) >= 0L) { + if ((int32_t)((uint32_t)millis() - next_time) >= 0L) { Usb.ForEachUsbDevice(&PrintAllDescriptors); Usb.ForEachUsbDevice(&PrintAllAddresses); diff --git a/examples/max_LCD/max_LCD.ino b/examples/max_LCD/max_LCD.ino index 6603ab90..d1526330 100644 --- a/examples/max_LCD/max_LCD.ino +++ b/examples/max_LCD/max_LCD.ino @@ -25,5 +25,5 @@ void loop() { // Set the cursor to column 0, line 1 (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // Print the number of seconds since reset: - lcd.print(millis() / 1000); + lcd.print((uint32_t)millis() / 1000); } diff --git a/examples/pl2303/pl2303_gps/pl2303_gps.ino b/examples/pl2303/pl2303_gps/pl2303_gps.ino index efb1b523..73cc2375 100644 --- a/examples/pl2303/pl2303_gps/pl2303_gps.ino +++ b/examples/pl2303/pl2303_gps/pl2303_gps.ino @@ -71,7 +71,7 @@ void loop() { if(Pl.isReady()) { /* reading the GPS */ - if((int32_t)(millis() - read_delay) >= 0L) { + if((int32_t)((uint32_t)millis() - read_delay) >= 0L) { read_delay += READ_DELAY; rcode = Pl.RcvData(&rcvd, buf); if(rcode && rcode != hrNAK) diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index 9af3b57b..cc5ef4de 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -94,10 +94,10 @@ void loop() if( Pl.isReady()) { bool newdata = false; - uint32_t start = millis(); + uint32_t start = (uint32_t)millis(); // Every 5 seconds we print an update - while ((int32_t)(millis() - start) < 5000) { + while ((int32_t)((uint32_t)millis() - start) < 5000) { if( feedgps()) { newdata = true; } diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino index 7deb16bc..4e9e2ef6 100644 --- a/examples/testusbhostFAT/testusbhostFAT.ino +++ b/examples/testusbhostFAT/testusbhostFAT.ino @@ -284,7 +284,7 @@ void setup() { analogWrite(LED_BUILTIN, 0); delay(500); - LEDnext_time = millis() + 1; + LEDnext_time = (uint32_t)millis() + 1; #if EXT_RAM printf_P(PSTR("Total EXT RAM banks %i\r\n"), xmem::getTotalBanks()); #endif @@ -321,10 +321,10 @@ void setup() { TIMSK3 |= (1 << OCIE1A); sei(); - HEAPnext_time = millis() + 10000; + HEAPnext_time = (uint32_t)millis() + 10000; #endif #if defined(__AVR__) - HEAPnext_time = millis() + 10000; + HEAPnext_time = (uint32_t)millis() + 10000; #endif } @@ -371,8 +371,8 @@ void serialEvent() { // ALL teensy versions LACK PWM ON LED ISR(TIMER3_COMPA_vect) { - if((int32_t)(millis() - LEDnext_time) >= 0L) { - LEDnext_time = millis() + 30; + if((int32_t)((uint32_t)millis() - LEDnext_time) >= 0L) { + LEDnext_time = (uint32_t)millis() + 30; // set the brightness of LED analogWrite(LED_BUILTIN, brightness); @@ -407,11 +407,11 @@ void loop() { #if defined(__AVR__) // Print a heap status report about every 10 seconds. - if((int32_t)(millis() - HEAPnext_time) >= 0L) { + if((int32_t)((uint32_t)millis() - HEAPnext_time) >= 0L) { if(UsbDEBUGlvl > 0x50) { printf_P(PSTR("Available heap: %u Bytes\r\n"), freeHeap()); } - HEAPnext_time = millis() + 10000; + HEAPnext_time = (uint32_t)millis() + 10000; } TCCR3B = 0; #endif @@ -421,7 +421,7 @@ void loop() { #endif // Horrid! This sort of thing really belongs in an ISR, not here! // We also will be needing to test each hub port, we don't do this yet! - if(!change && !usbon && (int32_t)(millis() - usbon_time) >= 0L) { + if(!change && !usbon && (int32_t)((uint32_t)millis() - usbon_time) >= 0L) { change = true; usbon = true; } @@ -433,7 +433,7 @@ void loop() { printf_P(PSTR("VBUS on\r\n")); } else { Usb.vbusPower(vbus_off); - usbon_time = millis() + 2000; + usbon_time = (uint32_t)millis() + 2000; } } Usb.Task(); @@ -700,27 +700,27 @@ out: if(rc) goto failed; for(bw = 0; bw < mbxs; bw++) My_Buff_x[bw] = bw & 0xff; fflush(stdout); - start = millis(); - while(start == millis()); + start = (uint32_t)millis(); + while(start == (uint32_t)millis()); for(ii = 10485760LU / mbxs; ii > 0LU; ii--) { rc = f_write(&My_File_Object_x, My_Buff_x, mbxs, &bw); if(rc || !bw) goto failed; } rc = f_close(&My_File_Object_x); if(rc) goto failed; - end = millis(); + end = (uint32_t)millis(); wt = (end - start) - 1; printf_P(PSTR("Time to write 10485760 bytes: %lu ms (%lu sec) \r\n"), wt, (500 + wt) / 1000UL); rc = f_open(&My_File_Object_x, "0:/10MB.bin", FA_READ); fflush(stdout); - start = millis(); - while(start == millis()); + start = (uint32_t)millis(); + while(start == (uint32_t)millis()); if(rc) goto failed; for(;;) { rc = f_read(&My_File_Object_x, My_Buff_x, mbxs, &bw); /* Read a chunk of file */ if(rc || !bw) break; /* Error or end of file */ } - end = millis(); + end = (uint32_t)millis(); if(rc) goto failed; rc = f_close(&My_File_Object_x); if(rc) goto failed; diff --git a/hidboot.h b/hidboot.h index a25d0390..6c192dac 100644 --- a/hidboot.h +++ b/hidboot.h @@ -578,7 +578,7 @@ template uint8_t HIDBoot::Poll() { uint8_t rcode = 0; - if(bPollEnable && ((int32_t)(millis() - qNextPollTime) >= 0L)) { + if(bPollEnable && ((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L)) { // To-do: optimize manually, using the for loop only if needed. for(int i = 0; i < epMUL(BOOT_PROTOCOL); i++) { @@ -619,7 +619,7 @@ uint8_t HIDBoot::Poll() { } } - qNextPollTime = millis() + bInterval; + qNextPollTime = (uint32_t)millis() + bInterval; } return rcode; } diff --git a/hidcomposite.cpp b/hidcomposite.cpp index f4047690..65cbb6ef 100644 --- a/hidcomposite.cpp +++ b/hidcomposite.cpp @@ -360,8 +360,8 @@ uint8_t HIDComposite::Poll() { if(!bPollEnable) return 0; - if((int32_t)(millis() - qNextPollTime) >= 0L) { - qNextPollTime = millis() + pollInterval; + if((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L) { + qNextPollTime = (uint32_t)millis() + pollInterval; uint8_t buf[constBuffLen]; diff --git a/hiduniversal.cpp b/hiduniversal.cpp index 1e87b04b..cef4b329 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -372,8 +372,8 @@ uint8_t HIDUniversal::Poll() { if(!bPollEnable) return 0; - if((int32_t)(millis() - qNextPollTime) >= 0L) { - qNextPollTime = millis() + pollInterval; + if((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L) { + qNextPollTime = (uint32_t)millis() + pollInterval; uint8_t buf[constBuffLen]; diff --git a/masstorage.cpp b/masstorage.cpp index a2394419..4c0c37ad 100644 --- a/masstorage.cpp +++ b/masstorage.cpp @@ -659,7 +659,7 @@ void BulkOnly::CheckMedia() { } printf("\r\n"); #endif - qNextPollTime = millis() + 2000; + qNextPollTime = (uint32_t)millis() + 2000; } /** @@ -673,7 +673,7 @@ uint8_t BulkOnly::Poll() { if(!bPollEnable) return 0; - if((int32_t)(millis() - qNextPollTime) >= 0L) { + if((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L) { CheckMedia(); } //rcode = 0; diff --git a/usbhub.cpp b/usbhub.cpp index d9e4e83d..e994fadb 100644 --- a/usbhub.cpp +++ b/usbhub.cpp @@ -232,9 +232,9 @@ uint8_t USBHub::Poll() { if(!bPollEnable) return 0; - if(((int32_t)(millis() - qNextPollTime) >= 0L)) { + if(((int32_t)((uint32_t)millis() - qNextPollTime) >= 0L)) { rcode = CheckHubStatus(); - qNextPollTime = millis() + 100; + qNextPollTime = (uint32_t)millis() + 100; } return rcode; } From 5ba28d186f3021132cde4bf6c9dfb856a68dda85 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 12 Feb 2017 17:14:01 +0100 Subject: [PATCH 204/220] Used fixed width integer types, so it is not architecture dependent --- Usb.cpp | 2 +- cdcftdi.cpp | 4 ++-- .../USBH_MIDI_dump/USBH_MIDI_dump.ino | 6 ++--- .../USB_MIDI_converter/USB_MIDI_converter.ino | 6 ++--- .../USB_MIDI_converter_multi.ino | 6 ++--- .../bidrectional_converter.ino | 6 ++--- examples/USB_desc/USB_desc.ino | 24 +++++++++---------- .../pl2303/pl2303_tinygps/pl2303_tinygps.ino | 8 +++---- usbh_midi.cpp | 14 +++++------ usbh_midi.h | 4 ++-- 10 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Usb.cpp b/Usb.cpp index 4f554c8b..c46ea5b3 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -426,7 +426,7 @@ void USB::Task(void) //USB state machine { uint8_t rcode; uint8_t tmpdata; - static unsigned long delay = 0; + static uint32_t delay = 0; //USB_DEVICE_DESCRIPTOR buf; bool lowspeed = false; diff --git a/cdcftdi.cpp b/cdcftdi.cpp index 91f189d2..5d1688c8 100644 --- a/cdcftdi.cpp +++ b/cdcftdi.cpp @@ -290,8 +290,8 @@ uint8_t FTDI::SetBaudRate(uint32_t baud) { if(divisor3 != 0) baud_value |= 0x8000; // 0.25 if(baud_value == 1) baud_value = 0; /* special case for maximum baud rate */ } else { - static const unsigned char divfrac [8] = {0, 3, 2, 0, 1, 1, 2, 3}; - static const unsigned char divindex[8] = {0, 0, 0, 1, 0, 1, 1, 1}; + static const uint8_t divfrac [8] = {0, 3, 2, 0, 1, 1, 2, 3}; + static const uint8_t divindex[8] = {0, 0, 0, 1, 0, 1, 1, 1}; baud_value = divisor3 >> 3; baud_value |= divfrac [divisor3 & 0x7] << 14; 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 524447f3..08428381 100644 --- a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -24,7 +24,7 @@ USB Usb; USBH_MIDI Midi(&Usb); void MIDI_poll(); -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); boolean bFirst; uint16_t pid, vid; @@ -77,9 +77,9 @@ void MIDI_poll() } // Delay time (max 16383 us) -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) { - unsigned long t3; + uint32_t t3; if ( t1 > t2 ) { t3 = (0xFFFFFFFF - t1 + t2); diff --git a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino index ddc803dd..32bd4cc5 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino @@ -35,7 +35,7 @@ USB Usb; USBH_MIDI Midi(&Usb); void MIDI_poll(); -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); void setup() { @@ -73,9 +73,9 @@ void MIDI_poll() } // Delay time (max 16383 us) -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) { - unsigned long t3; + uint32_t t3; if ( t1 > t2 ) { t3 = (0xFFFFFFFF - t1 + t2); diff --git a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino index 76421ca4..a118e7a9 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino @@ -37,7 +37,7 @@ USBH_MIDI Midi1(&Usb); USBH_MIDI Midi2(&Usb); void MIDI_poll(); -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); void setup() { @@ -81,9 +81,9 @@ void MIDI_poll() } // Delay time (max 16383 us) -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) { - unsigned long t3; + uint32_t t3; if ( t1 > t2 ) { t3 = (0xFFFFFFFF - t1 + t2); diff --git a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino index ce1efc4f..99b486fd 100644 --- a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino +++ b/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino @@ -43,7 +43,7 @@ USB Usb; USBH_MIDI Midi(&Usb); void MIDI_poll(); -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); //If you want handle System Exclusive message, enable this #define otherwise comment out it. #define USBH_MIDI_SYSEX_ENABLE @@ -149,9 +149,9 @@ void MIDI_poll() } // Delay time (max 16383 us) -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) { - unsigned long t3; + uint32_t t3; if ( t1 > t2 ) { t3 = (0xFFFFFFFF - t1 + t2); diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index dd9c5b22..cda8505c 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -60,14 +60,14 @@ void setup() delay( 200 ); } -byte getdevdescr( byte addr, byte &num_conf ); +uint8_t getdevdescr( uint8_t addr, uint8_t &num_conf ); void PrintDescriptors(uint8_t addr) { uint8_t rcode = 0; - byte num_conf = 0; + uint8_t num_conf = 0; - rcode = getdevdescr( (byte)addr, num_conf ); + rcode = getdevdescr( (uint8_t)addr, num_conf ); if ( rcode ) { printProgStr(Gen_Error_str); @@ -108,10 +108,10 @@ void loop() } } -byte getdevdescr( byte addr, byte &num_conf ) +uint8_t getdevdescr( uint8_t addr, uint8_t &num_conf ) { USB_DEVICE_DESCRIPTOR buf; - byte rcode; + uint8_t rcode; rcode = Usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf ); if ( rcode ) { return ( rcode ); @@ -195,14 +195,14 @@ void printhubdescr(uint8_t *descrptr, uint8_t addr) // PrintHubPortStatus(&Usb, addr, i, 1); } -byte getconfdescr( byte addr, byte conf ) +uint8_t getconfdescr( uint8_t addr, uint8_t conf ) { uint8_t buf[ BUFSIZE ]; uint8_t* buf_ptr = buf; - byte rcode; - byte descr_length; - byte descr_type; - unsigned int total_length; + uint8_t rcode; + uint8_t descr_length; + uint8_t descr_type; + uint16_t total_length; rcode = Usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length LOBYTE( total_length ) = buf[ 2 ]; HIBYTE( total_length ) = buf[ 3 ]; @@ -316,8 +316,8 @@ void printepdescr( uint8_t* descr_ptr ) /*function to print unknown descriptor */ void printunkdescr( uint8_t* descr_ptr ) { - byte length = *descr_ptr; - byte i; + uint8_t length = *descr_ptr; + uint8_t i; printProgStr(Unk_Header_str); printProgStr(Unk_Length_str); print_hex( *descr_ptr, 8 ); diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index cc5ef4de..d6c79895 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -130,7 +130,7 @@ void printFloat(double number, int digits) number += rounding; // Extract the integer part of the number and print it - unsigned long int_part = (unsigned long)number; + uint32_t int_part = (uint32_t)number; double remainder = number - (double)int_part; Serial.print(int_part); @@ -150,12 +150,12 @@ void printFloat(double number, int digits) void gpsdump(TinyGPS &gps) { - long lat, lon; + int32_t lat, lon; float flat, flon; - unsigned long age, date, time, chars; + uint32_t age, date, time, chars; int year; byte month, day, hour, minute, second, hundredths; - unsigned short sentences, failed; + uint16_t sentences, failed; gps.get_position(&lat, &lon, &age); Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon); diff --git a/usbh_midi.cpp b/usbh_midi.cpp index 54231387..945c7c68 100644 --- a/usbh_midi.cpp +++ b/usbh_midi.cpp @@ -243,9 +243,9 @@ void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf ) uint8_t rcode; uint8_t descr_length; uint8_t descr_type; - unsigned int total_length; + uint16_t total_length; USB_ENDPOINT_DESCRIPTOR *epDesc; - boolean isMidi = false; + bool isMidi = false; // get configuration descriptor (get descriptor size only) rcode = pUsb->getConfDescr( addr, 0, 4, conf, buf ); @@ -486,9 +486,9 @@ uint8_t USBH_MIDI::lookupMsgSize(uint8_t midiMsg) } /* SysEx data size counter */ -unsigned int USBH_MIDI::countSysExDataSize(uint8_t *dataptr) +uint16_t USBH_MIDI::countSysExDataSize(uint8_t *dataptr) { - unsigned int c = 1; + uint16_t c = 1; if( *dataptr != 0xf0 ){ //not SysEx return 0; @@ -510,12 +510,12 @@ unsigned int USBH_MIDI::countSysExDataSize(uint8_t *dataptr) } /* Send SysEx message to MIDI device */ -uint8_t USBH_MIDI::SendSysEx(uint8_t *dataptr, unsigned int datasize, uint8_t nCable) +uint8_t USBH_MIDI::SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable) { uint8_t buf[64]; uint8_t rc; - unsigned int n = datasize; - unsigned int pktSize = (n*10/3+7)/10*4; //Calculate total USB MIDI packet size + uint16_t n = datasize; + uint16_t pktSize = (n*10/3+7)/10*4; //Calculate total USB MIDI packet size uint8_t wptr = 0; uint8_t maxpkt = epInfo[epDataInIndex].maxPktSize; diff --git a/usbh_midi.h b/usbh_midi.h index 70973d0a..f689ea11 100644 --- a/usbh_midi.h +++ b/usbh_midi.h @@ -58,7 +58,7 @@ protected: uint8_t readPtr; void parseConfigDescr(uint8_t addr, uint8_t conf); - unsigned int countSysExDataSize(uint8_t *dataptr); + uint16_t countSysExDataSize(uint8_t *dataptr); #ifdef DEBUG_USB_HOST void PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ); #endif @@ -70,7 +70,7 @@ public: uint8_t RecvData(uint8_t *outBuf); uint8_t SendData(uint8_t *dataptr, uint8_t nCable=0); uint8_t lookupMsgSize(uint8_t midiMsg); - uint8_t SendSysEx(uint8_t *dataptr, unsigned int datasize, uint8_t nCable=0); + uint8_t SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable=0); uint8_t SendRawData(uint16_t bytes_send, uint8_t *dataptr); // backward compatibility functions inline uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr){ return RecvData(bytes_rcvd, dataptr); }; From 2f46665ee4914c223d23d540ab7d6664f3230293 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 12 Feb 2017 20:43:26 +0100 Subject: [PATCH 205/220] Fixed warning on avr See: https://travis-ci.org/felis/USB_Host_Shield_2.0/jobs/200893091 --- examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index d6c79895..8b30622d 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -64,7 +64,7 @@ TinyGPS gps; void gpsdump(TinyGPS &gps); bool feedgps(); -void printFloat(double f, int digits = 2); +void printFloat(double f, int16_t digits = 2); void setup() { @@ -113,7 +113,7 @@ void loop() }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING... } -void printFloat(double number, int digits) +void printFloat(double number, int16_t digits) { // Handle negative numbers if (number < 0.0) @@ -153,8 +153,8 @@ void gpsdump(TinyGPS &gps) int32_t lat, lon; float flat, flon; uint32_t age, date, time, chars; - int year; - byte month, day, hour, minute, second, hundredths; + int16_t year; + uint8_t month, day, hour, minute, second, hundredths; uint16_t sentences, failed; gps.get_position(&lat, &lon, &age); @@ -175,7 +175,7 @@ void gpsdump(TinyGPS &gps) feedgps(); - gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age); + gps.crack_datetime((int*)&year, &month, &day, &hour, &minute, &second, &hundredths, &age); Serial.print("Date: "); Serial.print(static_cast(month)); Serial.print("/"); Serial.print(static_cast(day)); Serial.print("/"); Serial.print(year); Serial.print(" Time: "); Serial.print(static_cast(hour)); Serial.print(":"); Serial.print(static_cast(minute)); Serial.print(":"); Serial.print(static_cast(second)); Serial.print("."); Serial.print(static_cast(hundredths)); Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms."); @@ -189,7 +189,7 @@ void gpsdump(TinyGPS &gps) feedgps(); - gps.stats(&chars, &sentences, &failed); + gps.stats(&chars, (unsigned short*)&sentences, (unsigned short*)&failed); Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed); } From 3952d900ff3381f9562da8a07b29eb3cfa23f788 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 14 Feb 2017 00:27:35 +0100 Subject: [PATCH 206/220] Reset the watchdog timer on the ESP8266 See: https://github.com/felis/USB_Host_Shield_2.0/pull/263#issuecomment-279222338 --- examples/board_qc/board_qc.ino | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index 573c3ce0..12d70c6c 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -60,6 +60,9 @@ void setup() { uint8_t sample_rd = 0; uint8_t gpinpol_copy = Usb.regRd(rGPINPOL); for(uint8_t i = 0; i < 16; i++) { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif for(uint16_t j = 0; j < 65535; j++) { Usb.regWr(rGPINPOL, sample_wr); sample_rd = Usb.regRd(rGPINPOL); @@ -206,7 +209,11 @@ void loop() { print_hex(buf.bNumConfigurations, 8); /**/ E_Notify(PSTR("\r\n\nAll tests passed. Press RESET to restart test"), 0x80); - while(1); + while(1) { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif + } } break; case( USB_STATE_ERROR): @@ -228,6 +235,9 @@ void halt55() { while(1) { Usb.regWr(0x55, 0x55); +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif } } @@ -253,7 +263,11 @@ void print_hex(int v, int num_places) { /* prints "Press any key" and returns when key is pressed */ void press_any_key() { E_Notify(PSTR("\r\nPress any key to continue..."), 0x80); - while(Serial.available() <= 0); //wait for input + while(Serial.available() <= 0) { // wait for input +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif + } Serial.read(); //empty input buffer return; } From 43f423e15d3b992e692f5e6a627970b9a3492c47 Mon Sep 17 00:00:00 2001 From: Yuuichi Akagawa Date: Sun, 26 Feb 2017 23:01:08 +0900 Subject: [PATCH 207/220] Update MIDI driver v0.3.2 --- .travis.yml | 2 +- .../USBH_MIDI_dump/USBH_MIDI_dump.ino | 18 +-- .../USB_MIDI_converter/USB_MIDI_converter.ino | 14 +- .../USB_MIDI_converter_multi.ino | 14 +- .../bidirectional_converter.ino} | 43 +++--- usbh_midi.cpp | 146 +++++++++--------- usbh_midi.h | 38 ++--- 7 files changed, 121 insertions(+), 154 deletions(-) rename examples/USBH_MIDI/{bidrectional_converter/bidrectional_converter.ino => bidirectional_converter/bidirectional_converter.ino} (76%) diff --git a/.travis.yml b/.travis.yml index 8d04757c..1c7ecaef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,7 +51,7 @@ env: - PLATFORMIO_CI_SRC=examples/PSBuzz # - PLATFORMIO_CI_SRC=examples/testusbhostFAT - PLATFORMIO_CI_SRC=examples/USB_desc - - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidrectional_converter + - PLATFORMIO_CI_SRC=examples/USBH_MIDI/bidirectional_converter - PLATFORMIO_CI_SRC=examples/USBH_MIDI/eVY1_sample - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter - PLATFORMIO_CI_SRC=examples/USBH_MIDI/USB_MIDI_converter_multi 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 d5e3f1db..397acdcb 100644 --- a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -1,7 +1,7 @@ /* ******************************************************************************* * USB-MIDI dump utility - * Copyright (C) 2013-2016 Yuuichi Akagawa + * Copyright (C) 2013-2017 Yuuichi Akagawa * * for use with USB Host Shield 2.0 from Circuitsathome.com * https://github.com/felis/USB_Host_Shield_2.0 @@ -24,7 +24,7 @@ USB Usb; USBH_MIDI Midi(&Usb); void MIDI_poll(); -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); boolean bFirst; uint16_t pid, vid; @@ -46,13 +46,13 @@ void loop() //unsigned long t1; Usb.Task(); - //t1 = micros(); + //uint32_t t1 = (uint32_t)micros(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); } //delay(1ms) - //doDelay(t1, micros(), 1000); + //doDelay(t1, (uint32_t)micros(), 1000); } // Poll USB MIDI Controler and send to serial MIDI @@ -69,11 +69,7 @@ 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 + sprintf(buf, "%08lX: ", (uint32_t)millis()); Serial.print(buf); Serial.print(rcvd); Serial.print(':'); @@ -86,9 +82,9 @@ void MIDI_poll() } // Delay time (max 16383 us) -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) { - unsigned long t3; + uint32_t t3; if ( t1 > t2 ) { t3 = (0xFFFFFFFF - t1 + t2); diff --git a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino index 38547a1b..18e6363e 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino @@ -1,7 +1,7 @@ /* ******************************************************************************* * USB-MIDI to Legacy Serial MIDI converter - * Copyright (C) 2012-2016 Yuuichi Akagawa + * Copyright (C) 2012-2017 Yuuichi Akagawa * * Idea from LPK25 USB-MIDI to Serial MIDI converter * by Collin Cunningham - makezine.com, narbotic.com @@ -35,7 +35,7 @@ USB Usb; USBH_MIDI Midi(&Usb); void MIDI_poll(); -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); void setup() { @@ -49,16 +49,14 @@ void setup() void loop() { - unsigned long t1; - Usb.Task(); - t1 = micros(); + uint32_t t1 = (uint32_t)micros(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); } //delay(1ms) - doDelay(t1, micros(), 1000); + doDelay(t1, (uint32_t)micros(), 1000); } // Poll USB MIDI Controler and send to serial MIDI @@ -76,9 +74,9 @@ void MIDI_poll() } // Delay time (max 16383 us) -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) { - unsigned long t3; + uint32_t t3; if ( t1 > t2 ) { t3 = (0xFFFFFFFF - t1 + t2); diff --git a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino index a4ddd333..d84fcaba 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino @@ -1,7 +1,7 @@ /* ******************************************************************************* * USB-MIDI to Legacy Serial MIDI converter - * Copyright (C) 2012-2016 Yuuichi Akagawa + * Copyright (C) 2012-2017 Yuuichi Akagawa * * Idea from LPK25 USB-MIDI to Serial MIDI converter * by Collin Cunningham - makezine.com, narbotic.com @@ -37,7 +37,7 @@ USBH_MIDI Midi1(&Usb); USBH_MIDI Midi2(&Usb); void MIDI_poll(); -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); void setup() { @@ -51,16 +51,14 @@ void setup() void loop() { - unsigned long t1; - Usb.Task(); - t1 = micros(); + uint32_t t1 = (uint32_t)micros(); if ( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { MIDI_poll(); } //delay(1ms) - doDelay(t1, micros(), 1000); + doDelay(t1, (uint32_t)micros(), 1000); } // Poll USB MIDI Controler and send to serial MIDI @@ -84,9 +82,9 @@ void MIDI_poll() } // Delay time (max 16383 us) -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) { - unsigned long t3; + uint32_t t3; if ( t1 > t2 ) { t3 = (0xFFFFFFFF - t1 + t2); diff --git a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino b/examples/USBH_MIDI/bidirectional_converter/bidirectional_converter.ino similarity index 76% rename from examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino rename to examples/USBH_MIDI/bidirectional_converter/bidirectional_converter.ino index 78f62385..72b010aa 100644 --- a/examples/USBH_MIDI/bidrectional_converter/bidrectional_converter.ino +++ b/examples/USBH_MIDI/bidirectional_converter/bidirectional_converter.ino @@ -1,7 +1,7 @@ /* ******************************************************************************* * Legacy Serial MIDI and USB Host bidirectional converter - * Copyright (C) 2013-2016 Yuuichi Akagawa + * Copyright (C) 2013-2017 Yuuichi Akagawa * * for use with Arduino MIDI library * https://github.com/FortySevenEffects/arduino_midi_library/ @@ -43,13 +43,12 @@ USB Usb; USBH_MIDI Midi(&Usb); void MIDI_poll(); -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime); +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime); //If you want handle System Exclusive message, enable this #define otherwise comment out it. #define USBH_MIDI_SYSEX_ENABLE #ifdef USBH_MIDI_SYSEX_ENABLE -MidiSysEx sysExData; //SysEx: void handle_sysex( byte* sysexmsg, unsigned sizeofsysex) { Midi.SendSysEx(sysexmsg, sizeofsysex); @@ -70,7 +69,7 @@ void setup() void loop() { - unsigned long t1; + uint32_t t1; uint8_t msg[4]; Usb.Task(); @@ -95,7 +94,7 @@ void loop() } } //delay(1ms) - doDelay(t1, micros(), 1000); + doDelay(t1, (uint32_t)micros(), 1000); } // Poll USB MIDI Controler and send to serial MIDI @@ -119,28 +118,22 @@ void MIDI_poll() uint8_t *p = recvBuf; while (readPtr < MIDI_EVENT_PACKET_SIZE) { if (*p == 0 && *(p + 1) == 0) break; //data end - MidiSysEx::Status rc = sysExData.set(p); - switch (rc) { - case MidiSysEx::nonsysex : //No SysEx message send data to Serial MIDI - p++; - size = Midi.lookupMsgSize(*p); - _MIDI_SERIAL_PORT.write(p, size); - p += 3; - break; - case MidiSysEx::done : //SysEx end. send data to Serial MIDI - _MIDI_SERIAL_PORT.write(sysExData.get(), sysExData.getSize()); - /* FALLTHROUGH */ - case MidiSysEx::overflow : //SysEx buffer over. ignore and flush buffer. - sysExData.clear(); - /* FALLTHROUGH */ - default: - p += 4; - break; + + uint8_t outbuf[3]; + uint8_t rc = Midi.extractSysExData(p, outbuf); + if ( rc == 0 ) { + p++; + size = Midi.lookupMsgSize(*p); + _MIDI_SERIAL_PORT.write(p, size); + p += 3; + } else { + _MIDI_SERIAL_PORT.write(outbuf, rc); + p += 4; } readPtr += 4; } #else - uint8_t outBuf[ 3 ]; + uint8_t outBuf[3]; do { if ( (size = Midi.RecvData(outBuf)) > 0 ) { //MIDI Output @@ -151,9 +144,9 @@ void MIDI_poll() } // Delay time (max 16383 us) -void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime) +void doDelay(uint32_t t1, uint32_t t2, uint32_t delayTime) { - unsigned long t3; + uint32_t t3; if ( t1 > t2 ) { t3 = (0xFFFFFFFF - t1 + t2); diff --git a/usbh_midi.cpp b/usbh_midi.cpp index 54231387..b254ff4d 100644 --- a/usbh_midi.cpp +++ b/usbh_midi.cpp @@ -1,7 +1,7 @@ /* ******************************************************************************* * USB-MIDI class driver for USB Host Shield 2.0 Library - * Copyright (c) 2012-2016 Yuuichi Akagawa + * Copyright (c) 2012-2017 Yuuichi Akagawa * * Idea from LPK25 USB-MIDI to Serial MIDI converter * by Collin Cunningham - makezine.com, narbotic.com @@ -93,11 +93,9 @@ isMidiFound(false), readPtr(0) { // initialize endpoint data structures for(uint8_t i=0; i(buf); uint8_t rcode; UsbDevice *p = NULL; @@ -117,6 +115,15 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) uint8_t num_of_conf; // number of configurations USBTRACE("\rMIDI Init\r\n"); + + //for reconnect + for(uint8_t i=epDataInIndex; i<=epDataOutIndex; i++) { + epInfo[i].epAddr = (i==epDataInIndex) ? 0x81 : 0x01; + epInfo[i].maxPktSize = 0; + epInfo[i].bmSndToggle = 0; + epInfo[i].bmRcvToggle = 0; + } + // get memory address of USB device address pool AddressPool &addrPool = pUsb->GetAddressPool(); @@ -192,15 +199,18 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) USBTRACE(" PID:"), D_PrintHex(pid, 0x80); USBTRACE2(" #Conf:", num_of_conf); + isMidiFound = false; for (uint8_t i=0; i 1) break; } // for USBTRACE2("\r\nNumEP:", bNumEP); - if( bNumEP < 3 ){ //Device not found. + if( bNumEP < 2 ){ //Device not found. rcode = 0xff; goto FailGetConfDescr; } @@ -214,7 +224,7 @@ uint8_t USBH_MIDI::Init(uint8_t parent, uint8_t port, bool lowspeed) } // Assign epInfo to epinfo pointer - rcode = pUsb->setEpInfoEntry(bAddress, bNumEP, epInfo); + rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo); USBTRACE2("Conf:", bConfNum); USBTRACE2("EPin :", (uint8_t)(epInfo[epDataInIndex].epAddr + 0x80)); USBTRACE2("EPout:", epInfo[epDataOutIndex].epAddr); @@ -236,7 +246,7 @@ FailSetConfDescr: } /* get and parse config descriptor */ -void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf ) +uint8_t USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf ) { uint8_t buf[ DESC_BUFF_SIZE ]; uint8_t* buf_ptr = buf; @@ -245,12 +255,12 @@ void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf ) uint8_t descr_type; unsigned int total_length; USB_ENDPOINT_DESCRIPTOR *epDesc; - boolean isMidi = false; + bool isMidi = false; // get configuration descriptor (get descriptor size only) rcode = pUsb->getConfDescr( addr, 0, 4, conf, buf ); if( rcode ){ - return; + return rcode; } total_length = buf[2] | ((int)buf[3] << 8); if( total_length > DESC_BUFF_SIZE ) { //check if total length is larger than buffer @@ -260,7 +270,7 @@ void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf ) // get configuration descriptor (all) rcode = pUsb->getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor if( rcode ){ - return; + return rcode; } //parsing descriptors @@ -313,6 +323,7 @@ void USBH_MIDI::parseConfigDescr( uint8_t addr, uint8_t conf ) }//switch( descr_type buf_ptr += descr_length; //advance buffer pointer }//while( buf_ptr <=... + return 0; } /* Performs a cleanup after failed Init() attempt */ @@ -340,12 +351,12 @@ uint8_t USBH_MIDI::RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr) } /* Receive data from MIDI device */ -uint8_t USBH_MIDI::RecvData(uint8_t *outBuf) +uint8_t USBH_MIDI::RecvData(uint8_t *outBuf, bool isRaw) { uint8_t rcode = 0; //return code uint16_t rcvd; - if( bPollEnable == false ) return false; + if( bPollEnable == false ) return 0; //Checking unprocessed message in buffer. if( readPtr != 0 && readPtr < MIDI_EVENT_PACKET_SIZE ){ @@ -368,14 +379,22 @@ uint8_t USBH_MIDI::RecvData(uint8_t *outBuf) } RecvData_return_from_buffer: + uint8_t m; + uint8_t cin = recvBuf[readPtr]; + if( isRaw == true ) { + *(outBuf++) = cin; + } readPtr++; - outBuf[0] = recvBuf[readPtr]; - readPtr++; - outBuf[1] = recvBuf[readPtr]; - readPtr++; - outBuf[2] = recvBuf[readPtr]; - readPtr++; - return lookupMsgSize(outBuf[0]); + *(outBuf++) = m = recvBuf[readPtr++]; + *(outBuf++) = recvBuf[readPtr++]; + *(outBuf++) = recvBuf[readPtr++]; + return lookupMsgSize(m, cin); +} + +/* Receive raw data from MIDI device */ +uint8_t USBH_MIDI::RecvRawData(uint8_t *outBuf) +{ + return RecvData(outBuf, true); } /* Send data to MIDI device */ @@ -443,10 +462,18 @@ void USBH_MIDI::PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ) /*Return */ /* 0 : undefined message */ /* 0<: Vaild message size(1-3) */ -uint8_t USBH_MIDI::lookupMsgSize(uint8_t midiMsg) +uint8_t USBH_MIDI::lookupMsgSize(uint8_t midiMsg, uint8_t cin) { uint8_t msgSize = 0; + //SysEx message? + cin = cin & 0x0f; + if( (cin & 0xc) == 4 ) { + if( cin == 4 || cin == 7 ) return 3; + if( cin == 6 ) return 2; + if( cin == 5 ) return 1; + } + if( midiMsg < 0xf0 ) midiMsg &= 0xf0; switch(midiMsg) { //3 bytes messages @@ -486,7 +513,7 @@ uint8_t USBH_MIDI::lookupMsgSize(uint8_t midiMsg) } /* SysEx data size counter */ -unsigned int USBH_MIDI::countSysExDataSize(uint8_t *dataptr) +uint16_t USBH_MIDI::countSysExDataSize(uint8_t *dataptr) { unsigned int c = 1; @@ -500,8 +527,8 @@ unsigned int USBH_MIDI::countSysExDataSize(uint8_t *dataptr) dataptr++; c++; - //Limiter (upto 256 bytes) - if(c > 256){ + //Limiter (default: 256 bytes) + if(c > MIDI_MAX_SYSEX_SIZE){ c = 0; break; } @@ -510,15 +537,17 @@ unsigned int USBH_MIDI::countSysExDataSize(uint8_t *dataptr) } /* Send SysEx message to MIDI device */ -uint8_t USBH_MIDI::SendSysEx(uint8_t *dataptr, unsigned int datasize, uint8_t nCable) +uint8_t USBH_MIDI::SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable) { - uint8_t buf[64]; - uint8_t rc; - unsigned int n = datasize; - unsigned int pktSize = (n*10/3+7)/10*4; //Calculate total USB MIDI packet size + uint8_t buf[MIDI_EVENT_PACKET_SIZE]; + uint8_t rc = 0; + uint16_t n = datasize; + uint16_t pktSize = (n*10/3+7)/10*4; //Calculate total USB MIDI packet size uint8_t wptr = 0; uint8_t maxpkt = epInfo[epDataInIndex].maxPktSize; + if( maxpkt > MIDI_EVENT_PACKET_SIZE ) maxpkt = MIDI_EVENT_PACKET_SIZE; + USBTRACE("SendSysEx:\r\t"); USBTRACE2(" Length:\t", datasize); USBTRACE2(" Total pktSize:\t", pktSize); @@ -571,60 +600,33 @@ uint8_t USBH_MIDI::SendRawData(uint16_t bytes_send, uint8_t *dataptr) } -// -// System Exclusive packet data management class -// -MidiSysEx::MidiSysEx() +uint8_t USBH_MIDI::extractSysExData(uint8_t *p, uint8_t *buf) { - clear(); -} - -void MidiSysEx::clear() -{ - pos = 0; - buf[0] = 0; -} - -MidiSysEx::Status MidiSysEx::set(uint8_t *p) -{ - MidiSysEx::Status rc = MidiSysEx::ok; + uint8_t rc = 0; uint8_t cin = *(p) & 0x0f; //SysEx message? - if( (cin & 0xc) != 4 ) return MidiSysEx::nonsysex; + if( (cin & 0xc) != 4 ) return rc; switch(cin) { case 4: case 7: - if( pos+2 < MIDI_EVENT_PACKET_SIZE ) { - buf[pos++] = *(p+1); - buf[pos++] = *(p+2); - buf[pos++] = *(p+3); - }else{ - rc = MidiSysEx::overflow; - } - break; - case 5: - if( pos+1 < MIDI_EVENT_PACKET_SIZE ) { - buf[pos++] = *(p+1); - buf[pos++] = *(p+2); - }else{ - rc = MidiSysEx::overflow; - } + *buf++ = *(p+1); + *buf++ = *(p+2); + *buf++ = *(p+3); + rc = 3; break; case 6: - if( pos < MIDI_EVENT_PACKET_SIZE ) { - buf[pos++] = *(p+1); - }else{ - rc = MidiSysEx::overflow; - } + *buf++ = *(p+1); + *buf++ = *(p+2); + rc = 2; + break; + case 5: + *buf++ = *(p+1); + rc = 1; break; default: break; } - //SysEx end? - if((cin & 0x3) != 0) { - rc = MidiSysEx::done; - } return(rc); } diff --git a/usbh_midi.h b/usbh_midi.h index 70973d0a..a673dc63 100644 --- a/usbh_midi.h +++ b/usbh_midi.h @@ -1,7 +1,7 @@ /* ******************************************************************************* * USB-MIDI class driver for USB Host Shield 2.0 Library - * Copyright (c) 2012-2016 Yuuichi Akagawa + * Copyright (c) 2012-2017 Yuuichi Akagawa * * Idea from LPK25 USB-MIDI to Serial MIDI converter * by Collin Cunningham - makezine.com, narbotic.com @@ -33,6 +33,7 @@ #define USB_SUBCLASS_MIDISTREAMING 3 #define DESC_BUFF_SIZE 256 #define MIDI_EVENT_PACKET_SIZE 64 +#define MIDI_MAX_SYSEX_SIZE 256 class USBH_MIDI; class USBH_MIDI : public USBDeviceConfig @@ -57,8 +58,8 @@ protected: uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE]; uint8_t readPtr; - void parseConfigDescr(uint8_t addr, uint8_t conf); - unsigned int countSysExDataSize(uint8_t *dataptr); + uint8_t parseConfigDescr(uint8_t addr, uint8_t conf); + uint16_t countSysExDataSize(uint8_t *dataptr); #ifdef DEBUG_USB_HOST void PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ); #endif @@ -67,10 +68,12 @@ public: USBH_MIDI(USB *p); // Methods for recieving and sending data uint8_t RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr); - uint8_t RecvData(uint8_t *outBuf); + uint8_t RecvData(uint8_t *outBuf, bool isRaw=false); + uint8_t RecvRawData(uint8_t *outBuf); uint8_t SendData(uint8_t *dataptr, uint8_t nCable=0); - uint8_t lookupMsgSize(uint8_t midiMsg); - uint8_t SendSysEx(uint8_t *dataptr, unsigned int datasize, uint8_t nCable=0); + uint8_t lookupMsgSize(uint8_t midiMsg, uint8_t cin=0); + uint8_t SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable=0); + uint8_t extractSysExData(uint8_t *p, uint8_t *buf); uint8_t SendRawData(uint16_t bytes_send, uint8_t *dataptr); // backward compatibility functions inline uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr){ return RecvData(bytes_rcvd, dataptr); }; @@ -81,27 +84,4 @@ public: virtual uint8_t Release(); virtual uint8_t GetAddress() { return bAddress; }; }; - -// -// System Exclusive packet data management class -// -class MidiSysEx { -private: - uint8_t pos; - uint8_t buf[MIDI_EVENT_PACKET_SIZE]; -public: - typedef enum { - nonsysex = 0, - ok = 1, - done = 0xfe, - overflow = 0xff - } Status; - - MidiSysEx(); - void clear(); - MidiSysEx::Status set(uint8_t *p); - inline uint8_t *get(){return buf;}; - inline uint8_t getSize(){return pos;}; -}; - #endif //_USBH_MIDI_H_ From 9de76a07dca539a238f6739328dd603d324689b3 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 22 Mar 2017 14:10:39 +0100 Subject: [PATCH 208/220] 14cf737d7d4c1ca77e85a8946ad147a6da5457e4 is no longer needed --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b9c00915..5d8ffb65 100644 --- a/.travis.yml +++ b/.travis.yml @@ -74,6 +74,4 @@ install: - platformio lib install 62 416 417 script: - - platformio ci --lib="." --board=uno --board=due --board=genuino101 --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc - - export PLATFORMIO_BUILD_FLAGS="$PLATFORMIO_BUILD_FLAGS -Wno-unused-function" # Workaround https://github.com/esp8266/Arduino/pull/2881 - - platformio ci --lib="." --board=esp12e --board=nodemcu + - platformio ci --lib="." --board=uno --board=due --board=genuino101 --board=teensy30 --board=teensy31 --board=teensy35 --board=teensy36 --board=teensylc --board=esp12e --board=nodemcu From 18a36f8627f0f3ed80d34e5a4171ee773d679028 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 11 May 2017 17:55:13 +0200 Subject: [PATCH 209/220] Split variable to prevent warnings on the ESP8266 platform See: https://travis-ci.org/felis/USB_Host_Shield_2.0/jobs/230952435#L1149 --- examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 397acdcb..5706b992 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,8 @@ void MIDI_poll() pid = Midi.pid; } if (Midi.RecvData( &rcvd, bufMidi) == 0 ) { - sprintf(buf, "%08lX: ", (uint32_t)millis()); + uint32_t time = (uint32_t)millis(); + sprintf(buf, "%04X%04X: ", (uint16_t)(time >> 16), (uint16_t)(time & 0xFFFF)); // Split variable to prevent warnings on the ESP8266 platform Serial.print(buf); Serial.print(rcvd); Serial.print(':'); From a057d83d5e5a5dd3129edd3b793dbbef3462087e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 6 Jun 2017 23:38:38 +0200 Subject: [PATCH 210/220] Do not use fixed width integer types for the TinyGPS example, as this causes issues on the ESP8266 platform --- examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index 8b30622d..af13b6bc 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -150,12 +150,12 @@ void printFloat(double number, int16_t digits) void gpsdump(TinyGPS &gps) { - int32_t lat, lon; + long lat, lon; float flat, flon; - uint32_t age, date, time, chars; - int16_t year; + unsigned long age, date, time, chars; + int year; uint8_t month, day, hour, minute, second, hundredths; - uint16_t sentences, failed; + unsigned short sentences, failed; gps.get_position(&lat, &lon, &age); Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon); @@ -175,7 +175,7 @@ void gpsdump(TinyGPS &gps) feedgps(); - gps.crack_datetime((int*)&year, &month, &day, &hour, &minute, &second, &hundredths, &age); + gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age); Serial.print("Date: "); Serial.print(static_cast(month)); Serial.print("/"); Serial.print(static_cast(day)); Serial.print("/"); Serial.print(year); Serial.print(" Time: "); Serial.print(static_cast(hour)); Serial.print(":"); Serial.print(static_cast(minute)); Serial.print(":"); Serial.print(static_cast(second)); Serial.print("."); Serial.print(static_cast(hundredths)); Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms."); @@ -189,7 +189,7 @@ void gpsdump(TinyGPS &gps) feedgps(); - gps.stats(&chars, (unsigned short*)&sentences, (unsigned short*)&failed); + gps.stats(&chars, &sentences, &failed); Serial.print("Stats: characters: "); Serial.print(chars); Serial.print(" sentences: "); Serial.print(sentences); Serial.print(" failed checksum: "); Serial.println(failed); } From a68614a2e8466a663505025abde6dd4e4344fbf6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 11:55:05 +0200 Subject: [PATCH 211/220] The data needs to be aligned to 32-bit when sending using SPI.writeBytes and SPI.transferBytes for the ESP8266 --- usbhost.h | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/usbhost.h b/usbhost.h index 62e4fbb2..e5eecbb1 100644 --- a/usbhost.h +++ b/usbhost.h @@ -177,12 +177,15 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { c[1] = data; spi4teensy3::send(c, 2); #elif defined(SPI_HAS_TRANSACTION) +#ifdef ESP8266 + uint32_t c[2]; // The data needs to be aligned to 32-bit + c[0] = reg | 0x02; + c[1] = data; + SPI.writeBytes(c, 2); +#else uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; -#ifdef ESP8266 - SPI.writeBytes(c, 2); -#else SPI.transfer(c, 2); #endif #elif defined(STM32F4) @@ -222,13 +225,9 @@ 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(SPI_HAS_TRANSACTION) +#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) SPI.transfer(reg | 0x02); -#ifdef ESP8266 - SPI.writeBytes(data_p, nbytes); -#else SPI.transfer(data_p, nbytes); -#endif data_p += nbytes; #elif defined(__ARDUINO_X86__) SPI.transfer(reg | 0x02); @@ -239,7 +238,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* HAL_SPI_Transmit(&SPI_Handle, &data, 1, HAL_MAX_DELAY); HAL_SPI_Transmit(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY); data_p += nbytes; -#elif !defined(SPDR) +#elif !defined(SPDR) // ESP8266 SPI.transfer(reg | 0x02); while(nbytes) { SPI.transfer(*data_p); @@ -328,15 +327,11 @@ 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(SPI_HAS_TRANSACTION) +#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) SPI.transfer(reg); memset(data_p, 0, nbytes); // Make sure we send out empty bytes -#ifdef ESP8266 - SPI.transferBytes(data_p, data_p, nbytes); -#else SPI.transfer(data_p, nbytes); data_p += nbytes; -#endif #elif defined(__ARDUINO_X86__) SPI.transfer(reg); SPI.transferBuffer(NULL, data_p, nbytes); @@ -346,7 +341,7 @@ uint8_t* MAX3421e< SPI_SS, INTR >::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* memset(data_p, 0, nbytes); // Make sure we send out empty bytes HAL_SPI_Receive(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY); data_p += nbytes; -#elif !defined(SPDR) +#elif !defined(SPDR) // ESP8266 SPI.transfer(reg); while(nbytes) { *data_p++ = SPI.transfer(0); From 453a4e1f7f1211d3c04dd1823135163b89c8de5f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 12:18:40 +0200 Subject: [PATCH 212/220] Explicit cast the data to an uint8_t pointer It is then cast back to uint32_t in the SPI library: https://github.com/esp8266/Arduino/blob/40c159fcf5c5ecf9edec8e7ada49c82ece19e6d0/libraries/SPI/SPI.cpp#L402 --- usbhost.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/usbhost.h b/usbhost.h index e5eecbb1..e434ed7d 100644 --- a/usbhost.h +++ b/usbhost.h @@ -181,7 +181,7 @@ void MAX3421e< SPI_SS, INTR >::regWr(uint8_t reg, uint8_t data) { uint32_t c[2]; // The data needs to be aligned to 32-bit c[0] = reg | 0x02; c[1] = data; - SPI.writeBytes(c, 2); + SPI.writeBytes((uint8_t*)c, 2); #else uint8_t c[2]; c[0] = reg | 0x02; From 84bab2d74849ef32fe14b9c2b748439a8002628e Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 12:40:07 +0200 Subject: [PATCH 213/220] Do not use SPI.writeBytes on the ESP8266 --- usbhost.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/usbhost.h b/usbhost.h index e434ed7d..8f97121e 100644 --- a/usbhost.h +++ b/usbhost.h @@ -176,24 +176,17 @@ 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(SPI_HAS_TRANSACTION) -#ifdef ESP8266 - uint32_t c[2]; // The data needs to be aligned to 32-bit - c[0] = reg | 0x02; - c[1] = data; - SPI.writeBytes((uint8_t*)c, 2); -#else +#elif defined(SPI_HAS_TRANSACTION) && !defined(ESP8266) uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; SPI.transfer(c, 2); -#endif #elif defined(STM32F4) uint8_t c[2]; c[0] = reg | 0x02; c[1] = data; HAL_SPI_Transmit(&SPI_Handle, c, 2, HAL_MAX_DELAY); -#elif !defined(SPDR) +#elif !defined(SPDR) // ESP8266 SPI.transfer(reg | 0x02); SPI.transfer(data); #else From c2b6dbf94300ae70d1230a266ba3df1255ecb300 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 12:57:27 +0200 Subject: [PATCH 214/220] Use pin 5 for INT on the ESP8266 --- README.md | 2 +- UsbCore.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3246f733..9a42558e 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ Currently the following boards are supported by the library: * STM32F4 * Currently the [NUCLEO-F446RE](http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063) is supported featuring the STM32F446. Take a look at the following example code: . * ESP8266 is supported using the [ESP8266 Arduino core](https://github.com/esp8266/Arduino) - * Note it uses pin 15 and 0 for SS and INT respectively + * Note it uses pin 15 and 5 for SS and INT respectively * Also please be aware that: * GPIO16 is **NOT** usable, as it will be used for some other purposes. For example, reset the SoC itself from sleep mode. * GPIO6 to 11 is also **NOT** usable, as they are used to connect SPI flash chip and it is used for storing the executable binary content. diff --git a/UsbCore.h b/UsbCore.h index 3374b640..f78300ca 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -40,7 +40,7 @@ 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 #elif defined(ESP8266) -typedef MAX3421e MAX3421E; // ESP8266 boards +typedef MAX3421e MAX3421E; // ESP8266 boards #else typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo, Due etc.), Intel Edison, Intel Galileo 2 or Teensy 2.0 and 3.x #endif From da253b25bc2e77424df217622ea46c99e9033ca5 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 12:57:56 +0200 Subject: [PATCH 215/220] Reset the watchdog timer on the ESP8266 when the sketch is done --- examples/USB_desc/USB_desc.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index cda8505c..8341c503 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -104,7 +104,11 @@ void loop() Usb.ForEachUsbDevice(&PrintAllDescriptors); Usb.ForEachUsbDevice(&PrintAllAddresses); - while ( 1 ); //stop + while ( 1 ) { // stop +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif + } } } From c8b7c9a0180500c89caac5a7804c17f47e6b14e9 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 13 Jun 2017 13:02:15 +0200 Subject: [PATCH 216/220] Added yield() inside the for-loops as well --- examples/board_qc/board_qc.ino | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index 12d70c6c..8ff41dda 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -88,6 +88,9 @@ void setup() { uint8_t tmpbyte; E_Notify(PSTR("\r\nGPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on"), 0x80); for(uint8_t sample_gpio = 0; sample_gpio < 255; sample_gpio++) { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif Usb.gpioWr(sample_gpio); tmpbyte = Usb.gpioRd(); /* bit reversing code copied vetbatim from http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious */ @@ -115,6 +118,9 @@ void setup() { /* Restart oscillator */ E_Notify(PSTR("\r\nResetting oscillator\r\n"), 0x80); for(uint16_t i = 0; i < 100; i++) { +#ifdef ESP8266 + yield(); // needed in order to reset the watchdog timer on the ESP8266 +#endif E_Notify(PSTR("\rReset number "), 0x80); Serial.print(i, DEC); Usb.regWr(rUSBCTL, bmCHIPRES); //reset From f286114ac9c90bf50b5bb46ca7ebf9f91322860b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 15 Jun 2017 12:03:02 +0200 Subject: [PATCH 217/220] Newer Xbox One controllers requires a longer initialisation command Fixes #216 --- XBOXONE.cpp | 5 ++++- XBOXONE.h | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/XBOXONE.cpp b/XBOXONE.cpp index d3f1fd77..8411140d 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -179,7 +179,10 @@ uint8_t XBOXONE::Init(uint8_t parent, uint8_t port, bool lowspeed) { // initialize the controller for input writeBuf[0] = 0x05; writeBuf[1] = 0x20; - rcode = XboxCommand(writeBuf, 2); + writeBuf[2] = 0x00; + writeBuf[3] = 0x01; + writeBuf[4] = 0x00; + rcode = XboxCommand(writeBuf, 5); if (rcode) goto Fail; diff --git a/XBOXONE.h b/XBOXONE.h index 11710fcf..60c2806d 100644 --- a/XBOXONE.h +++ b/XBOXONE.h @@ -36,7 +36,8 @@ // PID and VID of the different devices #define XBOX_VID 0x045E // Microsoft Corporation -#define XBOX_ONE_PID 0x02D1 // Microsoft One Wired controller +#define XBOX_ONE_PID1 0x02D1 // Microsoft One Wired controller +#define XBOX_ONE_PID2 0x02DD // Microsoft One Wired controller #define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer @@ -94,7 +95,7 @@ public: * @return Returns true if the device's VID and PID matches this driver. */ virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) { - return (vid == XBOX_VID && pid == XBOX_ONE_PID); + return (vid == XBOX_VID && (pid == XBOX_ONE_PID1 || pid == XBOX_ONE_PID2)); }; /**@}*/ From e7d0695616c9f8f1d845737e04140f0495cbba18 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 15 Jun 2017 12:50:17 +0200 Subject: [PATCH 218/220] Added support for all known Xbox One controllers See: https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c --- XBOXONE.h | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/XBOXONE.h b/XBOXONE.h index 60c2806d..ab309d34 100644 --- a/XBOXONE.h +++ b/XBOXONE.h @@ -34,10 +34,30 @@ #define XBOX_OUTPUT_PIPE 1 #define XBOX_INPUT_PIPE 2 -// PID and VID of the different devices -#define XBOX_VID 0x045E // Microsoft Corporation -#define XBOX_ONE_PID1 0x02D1 // Microsoft One Wired controller -#define XBOX_ONE_PID2 0x02DD // Microsoft One Wired controller +// PID and VID of the different devices - see: https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c + +// Official controllers +#define XBOX_VID1 0x045E // Microsoft Corporation +#define XBOX_ONE_PID1 0x02D1 // Microsoft X-Box One pad +#define XBOX_ONE_PID2 0x02DD // Microsoft X-Box One pad (Firmware 2015) +#define XBOX_ONE_PID3 0x02E3 // Microsoft X-Box One Elite pad +#define XBOX_ONE_PID4 0x02EA // Microsoft X-Box One S pad + +// Unofficial controllers +#define XBOX_VID2 0x0738 // Mad Catz +#define XBOX_VID3 0x0E6F // Afterglow +#define XBOX_VID4 0x0F0D // HORIPAD ONE +#define XBOX_VID5 0x1532 // Razer +#define XBOX_VID6 0x24C6 // PowerA + +#define XBOX_ONE_PID5 0x4A01 // Mad Catz FightStick TE 2 - might have different mapping for triggers? +#define XBOX_ONE_PID6 0x0139 // Afterglow Prismatic Wired Controller +#define XBOX_ONE_PID7 0x0146 // Rock Candy Wired Controller for Xbox One +#define XBOX_ONE_PID8 0x0067 // HORIPAD ONE +#define XBOX_ONE_PID9 0x0A03 // Razer Wildcat +#define XBOX_ONE_PID10 0x541A // PowerA Xbox One Mini Wired Controller +#define XBOX_ONE_PID11 0x542A // Xbox ONE spectra +#define XBOX_ONE_PID12 0x543A // PowerA Xbox One wired controller #define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer @@ -95,7 +115,10 @@ public: * @return Returns true if the device's VID and PID matches this driver. */ virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) { - return (vid == XBOX_VID && (pid == XBOX_ONE_PID1 || pid == XBOX_ONE_PID2)); + return ((vid == XBOX_VID1 || vid == XBOX_VID2 || vid == XBOX_VID3 || vid == XBOX_VID4 || vid == XBOX_VID5 || vid == XBOX_VID6) && + (pid == XBOX_ONE_PID1 || pid == XBOX_ONE_PID2 || pid == XBOX_ONE_PID3 || pid == XBOX_ONE_PID4 || + pid == XBOX_ONE_PID5 || pid == XBOX_ONE_PID6 || pid == XBOX_ONE_PID7 || pid == XBOX_ONE_PID8 || + pid == XBOX_ONE_PID9 || pid == XBOX_ONE_PID10 || pid == XBOX_ONE_PID11 || pid == XBOX_ONE_PID12)); }; /**@}*/ From 39150a15ea86557ce8360301fe1b539824fefb00 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 18 Jun 2017 18:02:43 +0200 Subject: [PATCH 219/220] Also update the ButtonClickState variable when the Xbox button is pressed Fixes #299 --- XBOXONE.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/XBOXONE.cpp b/XBOXONE.cpp index 8411140d..9c5b388f 100644 --- a/XBOXONE.cpp +++ b/XBOXONE.cpp @@ -266,6 +266,11 @@ void XBOXONE::readReport() { ButtonState |= pgm_read_word(&XBOX_BUTTONS[XBOX]); else ButtonState &= ~pgm_read_word(&XBOX_BUTTONS[XBOX]); + + if(ButtonState != OldButtonState) { + ButtonClickState = ButtonState & ~OldButtonState; // Update click state variable + OldButtonState = ButtonState; + } } if(readBuf[0] != 0x20) { // Check if it's the correct report, otherwise return - the controller also sends different status reports #ifdef EXTRADEBUG From 13950453c9c59acc92fab71cd8603d2ec4df8870 Mon Sep 17 00:00:00 2001 From: "Andrew J. Kroll" Date: Mon, 14 Aug 2017 03:39:38 -0400 Subject: [PATCH 220/220] Fixes for spi4teensy3 on 3.5/3.6. Be sure to update your spi4teensy3 library as well. --- examples/Bluetooth/BTHID/BTHID.ino | 2 +- examples/Bluetooth/PS3BT/PS3BT.ino | 2 +- examples/Bluetooth/PS3Multi/PS3Multi.ino | 2 +- examples/Bluetooth/PS3SPP/PS3SPP.ino | 2 +- examples/Bluetooth/PS4BT/PS4BT.ino | 2 +- examples/Bluetooth/SPP/SPP.ino | 2 +- examples/Bluetooth/SPPMulti/SPPMulti.ino | 2 +- examples/Bluetooth/Wii/Wii.ino | 2 +- examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino | 2 +- examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino | 2 +- examples/Bluetooth/WiiMulti/WiiMulti.ino | 2 +- examples/Bluetooth/WiiUProController/WiiUProController.ino | 2 +- examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino | 2 +- .../HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino | 2 +- examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino | 2 +- examples/HID/USBHIDJoystick/USBHIDJoystick.ino | 2 +- examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino | 2 +- examples/HID/USBHID_desc/USBHID_desc.ino | 2 +- examples/HID/le3dp/le3dp.ino | 2 +- examples/HID/scale/scale.ino | 2 +- examples/PS3USB/PS3USB.ino | 2 +- examples/PS4USB/PS4USB.ino | 2 +- examples/PSBuzz/PSBuzz.ino | 2 +- examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino | 2 +- .../USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino | 2 +- .../USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino | 2 +- .../bidirectional_converter/bidirectional_converter.ino | 2 +- examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino | 2 +- examples/USB_desc/USB_desc.ino | 2 +- examples/Xbox/XBOXOLD/XBOXOLD.ino | 2 +- examples/Xbox/XBOXONE/XBOXONE.ino | 2 +- examples/Xbox/XBOXRECV/XBOXRECV.ino | 2 +- examples/Xbox/XBOXUSB/XBOXUSB.ino | 2 +- examples/acm/acm_terminal/acm_terminal.ino | 2 +- examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino | 2 +- examples/adk/adk_barcode/adk_barcode.ino | 2 +- examples/adk/demokit_20/demokit_20.ino | 2 +- examples/adk/term_test/term_test.ino | 2 +- examples/adk/term_time/term_time.ino | 2 +- examples/board_qc/board_qc.ino | 2 +- examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino | 2 +- examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino | 2 +- examples/hub_demo/hub_demo.ino | 2 +- examples/max_LCD/max_LCD.ino | 2 +- .../pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino | 2 +- examples/pl2303/pl2303_gps/pl2303_gps.ino | 2 +- examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino | 2 +- .../pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino | 2 +- examples/testusbhostFAT/testusbhostFAT.ino | 2 +- settings.h | 6 +++--- 50 files changed, 52 insertions(+), 52 deletions(-) diff --git a/examples/Bluetooth/BTHID/BTHID.ino b/examples/Bluetooth/BTHID/BTHID.ino index 33ee96c5..58a2f92f 100644 --- a/examples/Bluetooth/BTHID/BTHID.ino +++ b/examples/Bluetooth/BTHID/BTHID.ino @@ -12,8 +12,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index 610269bb..d7a13331 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -10,8 +10,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/PS3Multi/PS3Multi.ino b/examples/Bluetooth/PS3Multi/PS3Multi.ino index 5ebfd781..600b3d87 100644 --- a/examples/Bluetooth/PS3Multi/PS3Multi.ino +++ b/examples/Bluetooth/PS3Multi/PS3Multi.ino @@ -11,8 +11,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/PS3SPP/PS3SPP.ino b/examples/Bluetooth/PS3SPP/PS3SPP.ino index 8f234cbd..f619c519 100644 --- a/examples/Bluetooth/PS3SPP/PS3SPP.ino +++ b/examples/Bluetooth/PS3SPP/PS3SPP.ino @@ -16,8 +16,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/PS4BT/PS4BT.ino b/examples/Bluetooth/PS4BT/PS4BT.ino index 9cac6cdc..71c13171 100644 --- a/examples/Bluetooth/PS4BT/PS4BT.ino +++ b/examples/Bluetooth/PS4BT/PS4BT.ino @@ -10,8 +10,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/SPP/SPP.ino b/examples/Bluetooth/SPP/SPP.ino index 8fb9c4ec..35586ccd 100644 --- a/examples/Bluetooth/SPP/SPP.ino +++ b/examples/Bluetooth/SPP/SPP.ino @@ -10,8 +10,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/SPPMulti/SPPMulti.ino b/examples/Bluetooth/SPPMulti/SPPMulti.ino index df521d8e..697eb505 100644 --- a/examples/Bluetooth/SPPMulti/SPPMulti.ino +++ b/examples/Bluetooth/SPPMulti/SPPMulti.ino @@ -10,8 +10,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/Wii/Wii.ino b/examples/Bluetooth/Wii/Wii.ino index b1935681..25c39c73 100644 --- a/examples/Bluetooth/Wii/Wii.ino +++ b/examples/Bluetooth/Wii/Wii.ino @@ -10,8 +10,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino index 18c5b411..95928eb5 100644 --- a/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino +++ b/examples/Bluetooth/WiiBalanceBoard/WiiBalanceBoard.ino @@ -10,8 +10,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino index 573b8bd4..1fd2f3aa 100644 --- a/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino +++ b/examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino @@ -17,8 +17,8 @@ Otherwise, wire up a IR LED yourself. // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include #ifndef WIICAMERA // Used to check if WIICAMERA is defined #error "Please set ENABLE_WII_IR_CAMERA to 1 in settings.h" diff --git a/examples/Bluetooth/WiiMulti/WiiMulti.ino b/examples/Bluetooth/WiiMulti/WiiMulti.ino index 07c6f13d..1d6bc410 100644 --- a/examples/Bluetooth/WiiMulti/WiiMulti.ino +++ b/examples/Bluetooth/WiiMulti/WiiMulti.ino @@ -11,8 +11,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/Bluetooth/WiiUProController/WiiUProController.ino b/examples/Bluetooth/WiiUProController/WiiUProController.ino index ab35a274..2cb86300 100644 --- a/examples/Bluetooth/WiiUProController/WiiUProController.ino +++ b/examples/Bluetooth/WiiUProController/WiiUProController.ino @@ -10,8 +10,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); // Some dongles have a hub inside diff --git a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino index ed475887..774c8d7d 100644 --- a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino +++ b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino @@ -4,8 +4,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include class KbdRptParser : public KeyboardReportParser { diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino index 9644d343..de906a6e 100644 --- a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -4,8 +4,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include class MouseRptParser : public MouseReportParser { diff --git a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino index df5f2844..05267ecb 100644 --- a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino +++ b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino @@ -4,8 +4,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include class MouseRptParser : public MouseReportParser { diff --git a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino index dff9cd50..153fca2e 100644 --- a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino +++ b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino @@ -5,8 +5,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include #include "hidjoystickrptparser.h" diff --git a/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino index f3b79dce..73f81e55 100644 --- a/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino +++ b/examples/HID/USBHIDMultimediaKbd/USBHIDMultimediaKbd.ino @@ -4,8 +4,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include // Override HIDComposite to be able to select which interface we want to hook into class HIDSelector : public HIDComposite diff --git a/examples/HID/USBHID_desc/USBHID_desc.ino b/examples/HID/USBHID_desc/USBHID_desc.ino index cd7ced23..fb9c333b 100644 --- a/examples/HID/USBHID_desc/USBHID_desc.ino +++ b/examples/HID/USBHID_desc/USBHID_desc.ino @@ -7,8 +7,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include class HIDUniversal2 : public HIDUniversal { diff --git a/examples/HID/le3dp/le3dp.ino b/examples/HID/le3dp/le3dp.ino index 07a1da04..a57ba221 100644 --- a/examples/HID/le3dp/le3dp.ino +++ b/examples/HID/le3dp/le3dp.ino @@ -9,8 +9,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; USBHub Hub(&Usb); diff --git a/examples/HID/scale/scale.ino b/examples/HID/scale/scale.ino index 0163df1e..51880100 100644 --- a/examples/HID/scale/scale.ino +++ b/examples/HID/scale/scale.ino @@ -10,8 +10,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; USBHub Hub(&Usb); diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index 9d033ea6..5d21a551 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -9,8 +9,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; /* You can create the instance of the class in two ways */ diff --git a/examples/PS4USB/PS4USB.ino b/examples/PS4USB/PS4USB.ino index d0d76790..74c44ce0 100644 --- a/examples/PS4USB/PS4USB.ino +++ b/examples/PS4USB/PS4USB.ino @@ -9,8 +9,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; PS4USB PS4(&Usb); diff --git a/examples/PSBuzz/PSBuzz.ino b/examples/PSBuzz/PSBuzz.ino index 6ee462c1..a356596e 100644 --- a/examples/PSBuzz/PSBuzz.ino +++ b/examples/PSBuzz/PSBuzz.ino @@ -9,8 +9,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; PSBuzz Buzz(&Usb); 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 34955914..689daf6f 100644 --- a/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino +++ b/examples/USBH_MIDI/USBH_MIDI_dump/USBH_MIDI_dump.ino @@ -16,8 +16,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub(&Usb); diff --git a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino index 18e6363e..ddd86074 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino @@ -16,8 +16,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include #ifdef USBCON #define _MIDI_SERIAL_PORT Serial1 diff --git a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino index d84fcaba..af57b746 100644 --- a/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino +++ b/examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino @@ -16,8 +16,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include #ifdef USBCON #define _MIDI_SERIAL_PORT Serial1 diff --git a/examples/USBH_MIDI/bidirectional_converter/bidirectional_converter.ino b/examples/USBH_MIDI/bidirectional_converter/bidirectional_converter.ino index 4c0a3dba..6923d78d 100644 --- a/examples/USBH_MIDI/bidirectional_converter/bidirectional_converter.ino +++ b/examples/USBH_MIDI/bidirectional_converter/bidirectional_converter.ino @@ -19,8 +19,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include //Arduino MIDI library v4.2 compatibility #ifdef MIDI_CREATE_DEFAULT_INSTANCE diff --git a/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino index 45d23c9f..eb2a6262 100644 --- a/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino +++ b/examples/USBH_MIDI/eVY1_sample/eVY1_sample.ino @@ -12,8 +12,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub(&Usb); diff --git a/examples/USB_desc/USB_desc.ino b/examples/USB_desc/USB_desc.ino index 8341c503..e5e15f22 100644 --- a/examples/USB_desc/USB_desc.ino +++ b/examples/USB_desc/USB_desc.ino @@ -5,8 +5,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub1(&Usb); diff --git a/examples/Xbox/XBOXOLD/XBOXOLD.ino b/examples/Xbox/XBOXOLD/XBOXOLD.ino index 64a3ed61..086c3290 100644 --- a/examples/Xbox/XBOXOLD/XBOXOLD.ino +++ b/examples/Xbox/XBOXOLD/XBOXOLD.ino @@ -10,8 +10,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; USBHub Hub1(&Usb); // The controller has a built in hub, so this instance is needed diff --git a/examples/Xbox/XBOXONE/XBOXONE.ino b/examples/Xbox/XBOXONE/XBOXONE.ino index 20d94a42..218f4918 100644 --- a/examples/Xbox/XBOXONE/XBOXONE.ino +++ b/examples/Xbox/XBOXONE/XBOXONE.ino @@ -8,8 +8,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; XBOXONE Xbox(&Usb); diff --git a/examples/Xbox/XBOXRECV/XBOXRECV.ino b/examples/Xbox/XBOXRECV/XBOXRECV.ino index 491b287e..4b10a63a 100644 --- a/examples/Xbox/XBOXRECV/XBOXRECV.ino +++ b/examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -10,8 +10,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; XBOXRECV Xbox(&Usb); diff --git a/examples/Xbox/XBOXUSB/XBOXUSB.ino b/examples/Xbox/XBOXUSB/XBOXUSB.ino index 8a5691c6..29dfbccb 100644 --- a/examples/Xbox/XBOXUSB/XBOXUSB.ino +++ b/examples/Xbox/XBOXUSB/XBOXUSB.ino @@ -9,8 +9,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; XBOXUSB Xbox(&Usb); diff --git a/examples/acm/acm_terminal/acm_terminal.ino b/examples/acm/acm_terminal/acm_terminal.ino index f509cda8..7be1dd7e 100644 --- a/examples/acm/acm_terminal/acm_terminal.ino +++ b/examples/acm/acm_terminal/acm_terminal.ino @@ -6,8 +6,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include class ACMAsyncOper : public CDCAsyncOper { diff --git a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino index 08fc6c80..75eaae4e 100644 --- a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino +++ b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino @@ -20,8 +20,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; ADK adk(&Usb, "TKJElectronics", // Manufacturer Name diff --git a/examples/adk/adk_barcode/adk_barcode.ino b/examples/adk/adk_barcode/adk_barcode.ino index 9417617d..407624b7 100644 --- a/examples/adk/adk_barcode/adk_barcode.ino +++ b/examples/adk/adk_barcode/adk_barcode.ino @@ -8,8 +8,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; USBHub Hub1(&Usb); diff --git a/examples/adk/demokit_20/demokit_20.ino b/examples/adk/demokit_20/demokit_20.ino index f65adf57..95113087 100644 --- a/examples/adk/demokit_20/demokit_20.ino +++ b/examples/adk/demokit_20/demokit_20.ino @@ -4,8 +4,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; USBHub hub0(&Usb); diff --git a/examples/adk/term_test/term_test.ino b/examples/adk/term_test/term_test.ino index 2dea73fd..5f856a12 100644 --- a/examples/adk/term_test/term_test.ino +++ b/examples/adk/term_test/term_test.ino @@ -4,8 +4,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; //USBHub Hub(&Usb); diff --git a/examples/adk/term_time/term_time.ino b/examples/adk/term_time/term_time.ino index 0f479a60..0f2c2c4b 100644 --- a/examples/adk/term_time/term_time.ino +++ b/examples/adk/term_time/term_time.ino @@ -4,8 +4,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index 8ff41dda..20df028d 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -9,8 +9,8 @@ #ifdef dobogusinclude #include #include <../../../../hardware/pic32/libraries/SPI/SPI.h> // Hack to use the SPI library -#include // Hack to use the SPI library #endif +#include // Hack to use the SPI library /* variables */ uint8_t rcode; diff --git a/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino b/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino index 0173a08b..e78d98b2 100644 --- a/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino +++ b/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino @@ -3,8 +3,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include class ACMAsyncOper : public CDCAsyncOper { diff --git a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino index b7d51a4c..aac8106e 100644 --- a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino +++ b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino @@ -6,8 +6,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include class FTDIAsync : public FTDIAsyncOper { diff --git a/examples/hub_demo/hub_demo.ino b/examples/hub_demo/hub_demo.ino index fb3bd69f..ca0a3705 100644 --- a/examples/hub_demo/hub_demo.ino +++ b/examples/hub_demo/hub_demo.ino @@ -4,8 +4,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; USBHub Hub1(&Usb); diff --git a/examples/max_LCD/max_LCD.ino b/examples/max_LCD/max_LCD.ino index d1526330..eff935af 100644 --- a/examples/max_LCD/max_LCD.ino +++ b/examples/max_LCD/max_LCD.ino @@ -8,8 +8,8 @@ // Satisfy IDE, which only needs to see the include statment in the ino. #ifdef dobogusinclude #include -#include #endif +#include USB Usb; Max_LCD lcd(&Usb); diff --git a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino index 7c4c9f6c..5890e332 100644 --- a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino +++ b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino @@ -8,8 +8,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include class PLAsyncOper : public CDCAsyncOper { diff --git a/examples/pl2303/pl2303_gps/pl2303_gps.ino b/examples/pl2303/pl2303_gps/pl2303_gps.ino index 73cc2375..de5443db 100644 --- a/examples/pl2303/pl2303_gps/pl2303_gps.ino +++ b/examples/pl2303/pl2303_gps/pl2303_gps.ino @@ -9,8 +9,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include class PLAsyncOper : public CDCAsyncOper { public: diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index af13b6bc..55b4b0fa 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -15,8 +15,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include /* This sample code demonstrates the normal use of a TinyGPS object. Modified to be used with USB Host Shield Library r2.0 diff --git a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino index 67b7dab6..116f7d91 100644 --- a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino +++ b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino @@ -9,8 +9,8 @@ // Satisfy the IDE, which needs to see the include statment in the ino too. #ifdef dobogusinclude #include -#include #endif +#include class PLAsyncOper : public CDCAsyncOper { diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino index 4e9e2ef6..0277b693 100644 --- a/examples/testusbhostFAT/testusbhostFAT.ino +++ b/examples/testusbhostFAT/testusbhostFAT.ino @@ -58,11 +58,11 @@ #if defined(CORE_TEENSY) && !defined(_AVR_) #include #include +#include #endif #if defined(__AVR__) #include -#include #elif defined(ARDUINO_ARCH_SAM) #include #endif diff --git a/settings.h b/settings.h index 804725a4..ad407f8a 100644 --- a/settings.h +++ b/settings.h @@ -71,8 +71,8 @@ e-mail : support@circuitsathome.com #define USE_SPI4TEENSY3 1 #endif -// Disabled on the Teensy LC, Teensy 3.5, and Teensy 3.6 as it is incompatible for now -#if defined(__MKL26Z64__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) +// Disabled on the Teensy LC, as it is incompatible for now +#if defined(__MKL26Z64__) #undef USE_SPI4TEENSY3 #define USE_SPI4TEENSY3 0 #endif @@ -129,7 +129,7 @@ e-mail : support@circuitsathome.com #define EXT_RAM 0 #endif -#if defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) || defined(__MKL26Z64__)) +#if defined(CORE_TEENSY) && defined(KINETISK) #define USING_SPI4TEENSY3 USE_SPI4TEENSY3 #else #define USING_SPI4TEENSY3 0