From 70f366367348195fc1f64dacf1ebadd33b68378c Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 1 Oct 2013 23:50:19 +0200 Subject: [PATCH 01/10] Use list for different boards --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a2391e58..79543b17 100644 --- a/README.md +++ b/README.md @@ -63,9 +63,19 @@ By default serial debugging is disabled. To turn it on simply change ```ENABLE_U ### Boards -Currently the following boards are supported by the library: All official Arduino AVR boards (Uno, Duemilanove, Mega, Mega 2560, Mega ADK, Leonardo etc.), Teensy (Teensy 1.0, Teensy 2.0 and Teensy++ 2.0), Balanduino, Sanguino and Black Widdow. +Currently the following boards are supported by the library: -The following boards need to be activated manually in [settings.h](settings.h): Arduino ADK, Sanguino, Teeny 2.0, and Black Widdow. Simply set the corresponding value to 1 instead of 0. +* All official Arduino AVR boards (Uno, Duemilanove, Mega, Mega 2560, Mega ADK, Leonardo etc.) +* Teensy (Teensy 1.0, Teensy 2.0 and Teensy++ 2.0) +* Balanduino +* Sanguino +* Black Widdow. + +The following boards need to be activated manually in [settings.h](settings.h): + +* Arduino ADK, Sanguino, Teensy 2.0, and Black Widdow. + +Simply set the corresponding value to 1 instead of 0. ### [Bluetooth libraries](BTD.cpp) From f21f70c0b9a0f51c7b63dfbc2b9fd75e43802f7b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 1 Oct 2013 23:52:34 +0200 Subject: [PATCH 02/10] Minor --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 79543b17..590a9413 100644 --- a/README.md +++ b/README.md @@ -69,11 +69,11 @@ Currently the following boards are supported by the library: * Teensy (Teensy 1.0, Teensy 2.0 and Teensy++ 2.0) * Balanduino * Sanguino -* Black Widdow. +* Black Widdow The following boards need to be activated manually in [settings.h](settings.h): -* Arduino ADK, Sanguino, Teensy 2.0, and Black Widdow. +* Arduino Mega ADK, Teensy 2.0, Sanguino, and Black Widdow. Simply set the corresponding value to 1 instead of 0. From 45c1297a9179c82d1047d20daaadc30a080b4f1d Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 2 Oct 2013 00:49:46 +0200 Subject: [PATCH 03/10] Removed all unnecessary includes since there is no need to do that anymore Also renamed all example extensions to .ino --- examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino | 16 +------------- .../USBHIDBootKbdAndMouse.ino | 2 +- ...SBHIDBootMouse.pde => USBHIDBootMouse.ino} | 14 +----------- .../HID/USBHIDJoystick/USBHIDJoystick.ino | 4 +--- .../HID/USBHIDJoystick/hidjoystickrptparser.h | 1 - .../{USBHID_desc.pde => USBHID_desc.ino} | 16 +------------- examples/HID/le3dp/le3dp.ino | 16 +------------- examples/HID/le3dp/le3dp_rptparser.h | 20 +---------------- examples/HID/scale/scale.ino | 16 +------------- examples/HID/scale/scale_rptparser.h | 22 ++----------------- examples/PS3USB/PS3USB.ino | 1 + .../USB_desc/{USB_desc.pde => USB_desc.ino} | 7 ------ examples/Xbox/XBOXRECV/XBOXRECV.ino | 1 + examples/Xbox/XBOXUSB/XBOXUSB.ino | 1 + .../{acm_terminal.pde => acm_terminal.ino} | 15 +------------ .../adk/ArduinoBlinkLED/ArduinoBlinkLED.ino | 2 -- .../{adk_barcode.pde => adk_barcode.ino} | 11 +--------- .../{demokit_20.pde => demokit_20.ino} | 15 +------------ .../{term_test.pde => term_test.ino} | 10 +-------- .../{term_time.pde => term_time.ino} | 10 +-------- examples/board_qc/board_qc.ino | 12 ---------- ...SBFTDILoopback.pde => USBFTDILoopback.ino} | 15 +------------ .../hub_demo/{hub_demo.pde => hub_demo.ino} | 7 ------ ..._terminal.pde => pl2303_gprs_terminal.ino} | 12 ---------- .../{pl2303_gps.pde => pl2303_gps.ino} | 12 ---------- ...{pl2303_tinygps.pde => pl2303_tinygps.ino} | 13 ----------- ..._terminal.pde => pl2303_xbee_terminal.ino} | 12 ---------- examples/testusbhostFAT/testusbhostFAT.ino | 0 28 files changed, 19 insertions(+), 264 deletions(-) rename examples/HID/USBHIDBootMouse/{USBHIDBootMouse.pde => USBHIDBootMouse.ino} (85%) rename examples/HID/USBHID_desc/{USBHID_desc.pde => USBHID_desc.ino} (83%) rename examples/USB_desc/{USB_desc.pde => USB_desc.ino} (98%) rename examples/acm/acm_terminal/{acm_terminal.pde => acm_terminal.ino} (89%) rename examples/adk/adk_barcode/{adk_barcode.pde => adk_barcode.ino} (91%) rename examples/adk/demokit_20/{demokit_20.pde => demokit_20.ino} (88%) rename examples/adk/term_test/{term_test.pde => term_test.ino} (88%) rename examples/adk/term_time/{term_time.pde => term_time.ino} (85%) rename examples/ftdi/USBFTDILoopback/{USBFTDILoopback.pde => USBFTDILoopback.ino} (89%) rename examples/hub_demo/{hub_demo.pde => hub_demo.ino} (98%) rename examples/pl2303/pl2303_gprs_terminal/{pl2303_gprs_terminal.pde => pl2303_gprs_terminal.ino} (89%) rename examples/pl2303/pl2303_gps/{pl2303_gps.pde => pl2303_gps.ino} (88%) rename examples/pl2303/pl2303_tinygps/{pl2303_tinygps.pde => pl2303_tinygps.ino} (96%) rename examples/pl2303/pl2303_xbee_terminal/{pl2303_xbee_terminal.pde => pl2303_xbee_terminal.ino} (91%) mode change 100755 => 100644 examples/testusbhostFAT/testusbhostFAT.ino diff --git a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino index 3820eb5c..f990a1eb 100644 --- a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino +++ b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino @@ -1,19 +1,5 @@ -#include - -#include -#include -#include -#include -#include -#include -#include -#include #include - -#include -#include -#include -#include +#include class KbdRptParser : public KeyboardReportParser { diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino index 586d4132..cd136cb0 100644 --- a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -1,5 +1,5 @@ -#include #include +#include class MouseRptParser : public MouseReportParser { diff --git a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.pde b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino similarity index 85% rename from examples/HID/USBHIDBootMouse/USBHIDBootMouse.pde rename to examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino index 2227a29b..decf15df 100644 --- a/examples/HID/USBHIDBootMouse/USBHIDBootMouse.pde +++ b/examples/HID/USBHIDBootMouse/USBHIDBootMouse.ino @@ -1,17 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include +#include class MouseRptParser : public MouseReportParser { diff --git a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino index 79497b52..b8160635 100644 --- a/examples/HID/USBHIDJoystick/USBHIDJoystick.ino +++ b/examples/HID/USBHIDJoystick/USBHIDJoystick.ino @@ -1,11 +1,9 @@ - -#include #include #include +#include #include "hidjoystickrptparser.h" - USB Usb; USBHub Hub(&Usb); HIDUniversal Hid(&Usb); diff --git a/examples/HID/USBHIDJoystick/hidjoystickrptparser.h b/examples/HID/USBHIDJoystick/hidjoystickrptparser.h index 028d6c89..733b8f8d 100644 --- a/examples/HID/USBHIDJoystick/hidjoystickrptparser.h +++ b/examples/HID/USBHIDJoystick/hidjoystickrptparser.h @@ -1,7 +1,6 @@ #if !defined(__HIDJOYSTICKRPTPARSER_H__) #define __HIDJOYSTICKRPTPARSER_H__ -#include #include struct GamePadEventData { diff --git a/examples/HID/USBHID_desc/USBHID_desc.pde b/examples/HID/USBHID_desc/USBHID_desc.ino similarity index 83% rename from examples/HID/USBHID_desc/USBHID_desc.pde rename to examples/HID/USBHID_desc/USBHID_desc.ino index 0870d077..d7510c5f 100644 --- a/examples/HID/USBHID_desc/USBHID_desc.pde +++ b/examples/HID/USBHID_desc/USBHID_desc.ino @@ -1,21 +1,7 @@ - -#include - -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include -#include -#include -#include -#include +#include #include "pgmstrings.h" diff --git a/examples/HID/le3dp/le3dp.ino b/examples/HID/le3dp/le3dp.ino index b52bb28d..4414f60c 100644 --- a/examples/HID/le3dp/le3dp.ino +++ b/examples/HID/le3dp/le3dp.ino @@ -1,25 +1,11 @@ /* Simplified Logitech Extreme 3D Pro Joystick Report Parser */ -#include - -#include -#include -#include -#include -#include -#include -#include -#include #include #include +#include #include "le3dp_rptparser.h" -#include -#include -#include -#include - USB Usb; USBHub Hub(&Usb); HIDUniversal Hid(&Usb); diff --git a/examples/HID/le3dp/le3dp_rptparser.h b/examples/HID/le3dp/le3dp_rptparser.h index dfb89271..2400364e 100644 --- a/examples/HID/le3dp/le3dp_rptparser.h +++ b/examples/HID/le3dp/le3dp_rptparser.h @@ -1,25 +1,7 @@ #if !defined(__HIDJOYSTICKRPTPARSER_H__) #define __HIDJOYSTICKRPTPARSER_H__ -#include -#include -#include "avrpins.h" -#include "max3421e.h" -#include "usbhost.h" -#include "usb_ch9.h" -#include "Usb.h" - -#if defined(ARDUINO) && ARDUINO >=100 -#include "Arduino.h" -#else -#include -#endif - -#include "printhex.h" -#include "hexdump.h" -#include "message.h" -#include "confdescparser.h" -#include "hid.h" +#include struct GamePadEventData { diff --git a/examples/HID/scale/scale.ino b/examples/HID/scale/scale.ino index dcc8ded8..a88e7196 100644 --- a/examples/HID/scale/scale.ino +++ b/examples/HID/scale/scale.ino @@ -1,26 +1,12 @@ /* 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 -#include -#include -#include -#include -#include #include #include +#include #include "scale_rptparser.h" -#include -#include -#include -#include - USB Usb; USBHub Hub(&Usb); HIDUniversal Hid(&Usb); diff --git a/examples/HID/scale/scale_rptparser.h b/examples/HID/scale/scale_rptparser.h index 277ea66e..db69e656 100644 --- a/examples/HID/scale/scale_rptparser.h +++ b/examples/HID/scale/scale_rptparser.h @@ -1,26 +1,8 @@ #if !defined(__SCALERPTPARSER_H__) #define __SCALERPTPARSER_H__ -#include -#include -#include "avrpins.h" -#include "max3421e.h" -#include "usbhost.h" -#include "usb_ch9.h" -#include "Usb.h" -#include "Max_LCD.h" - -#if defined(ARDUINO) && ARDUINO >=100 -#include "Arduino.h" -#else -#include -#endif - -#include "printhex.h" -#include "hexdump.h" -#include "message.h" -#include "confdescparser.h" -#include "hid.h" +#include +#include /* Scale status constants */ #define REPORT_FAULT 0x01 diff --git a/examples/PS3USB/PS3USB.ino b/examples/PS3USB/PS3USB.ino index c4f32187..65569187 100644 --- a/examples/PS3USB/PS3USB.ino +++ b/examples/PS3USB/PS3USB.ino @@ -5,6 +5,7 @@ */ #include + USB Usb; /* You can create the instance of the class in two ways */ PS3USB PS3(&Usb); // This will just create the instance diff --git a/examples/USB_desc/USB_desc.pde b/examples/USB_desc/USB_desc.ino similarity index 98% rename from examples/USB_desc/USB_desc.pde rename to examples/USB_desc/USB_desc.ino index 770e421c..75fbaa25 100644 --- a/examples/USB_desc/USB_desc.pde +++ b/examples/USB_desc/USB_desc.ino @@ -1,11 +1,4 @@ -#include -#include -#include -#include -#include #include -#include -#include #include "pgmstrings.h" diff --git a/examples/Xbox/XBOXRECV/XBOXRECV.ino b/examples/Xbox/XBOXRECV/XBOXRECV.ino index 8490800f..eb98e19a 100644 --- a/examples/Xbox/XBOXRECV/XBOXRECV.ino +++ b/examples/Xbox/XBOXRECV/XBOXRECV.ino @@ -6,6 +6,7 @@ */ #include + USB Usb; XBOXRECV Xbox(&Usb); diff --git a/examples/Xbox/XBOXUSB/XBOXUSB.ino b/examples/Xbox/XBOXUSB/XBOXUSB.ino index 2f209ce3..f78d1d06 100644 --- a/examples/Xbox/XBOXUSB/XBOXUSB.ino +++ b/examples/Xbox/XBOXUSB/XBOXUSB.ino @@ -5,6 +5,7 @@ */ #include + USB Usb; XBOXUSB Xbox(&Usb); diff --git a/examples/acm/acm_terminal/acm_terminal.pde b/examples/acm/acm_terminal/acm_terminal.ino similarity index 89% rename from examples/acm/acm_terminal/acm_terminal.pde rename to examples/acm/acm_terminal/acm_terminal.ino index a60115c6..782a51a4 100644 --- a/examples/acm/acm_terminal/acm_terminal.pde +++ b/examples/acm/acm_terminal/acm_terminal.ino @@ -1,18 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include -#include - #include - -#include -#include -#include -#include +#include #include "pgmstrings.h" diff --git a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino index 5a1e38e5..14f29b38 100644 --- a/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino +++ b/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino @@ -1,7 +1,5 @@ // The source for the Android application can be found at the following link: https://github.com/Lauszus/ArduinoBlinkLED // 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 #include USB Usb; diff --git a/examples/adk/adk_barcode/adk_barcode.pde b/examples/adk/adk_barcode/adk_barcode.ino similarity index 91% rename from examples/adk/adk_barcode/adk_barcode.pde rename to examples/adk/adk_barcode/adk_barcode.ino index 02d68728..481d35b6 100644 --- a/examples/adk/adk_barcode/adk_barcode.pde +++ b/examples/adk/adk_barcode/adk_barcode.ino @@ -1,18 +1,9 @@ /**/ /* A sketch demonstrating data exchange between two USB devices - a HID barcode scanner and ADK-compatible Android phone */ /**/ -#include -#include -#include -#include -#include -#include -#include -#include - #include - #include +#include USB Usb; USBHub Hub1(&Usb); diff --git a/examples/adk/demokit_20/demokit_20.pde b/examples/adk/demokit_20/demokit_20.ino similarity index 88% rename from examples/adk/demokit_20/demokit_20.pde rename to examples/adk/demokit_20/demokit_20.ino index b1f47294..a92097c6 100644 --- a/examples/adk/demokit_20/demokit_20.pde +++ b/examples/adk/demokit_20/demokit_20.ino @@ -1,18 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include -#include - #include - -#include -#include -#include -#include +#include USB Usb; USBHub hub0(&Usb); diff --git a/examples/adk/term_test/term_test.pde b/examples/adk/term_test/term_test.ino similarity index 88% rename from examples/adk/term_test/term_test.pde rename to examples/adk/term_test/term_test.ino index fa863337..492dfb15 100644 --- a/examples/adk/term_test/term_test.pde +++ b/examples/adk/term_test/term_test.ino @@ -1,13 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include -#include - #include +#include USB Usb; //USBHub Hub(&Usb); diff --git a/examples/adk/term_time/term_time.pde b/examples/adk/term_time/term_time.ino similarity index 85% rename from examples/adk/term_time/term_time.pde rename to examples/adk/term_time/term_time.ino index 071d5c6b..c9657561 100644 --- a/examples/adk/term_time/term_time.pde +++ b/examples/adk/term_time/term_time.ino @@ -1,13 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include -#include - #include +#include USB Usb; diff --git a/examples/board_qc/board_qc.ino b/examples/board_qc/board_qc.ino index b99d6a31..71e14f82 100644 --- a/examples/board_qc/board_qc.ino +++ b/examples/board_qc/board_qc.ino @@ -3,19 +3,7 @@ /* for GPIO test to pass you need to connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, etc. */ /* otherwise press any key after getting GPIO error to complete the test */ /**/ -#include -#include -#include -#include -#include #include -#include -#include - -#include -#include -#include -#include /* variables */ uint8_t rcode; diff --git a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.pde b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino similarity index 89% rename from examples/ftdi/USBFTDILoopback/USBFTDILoopback.pde rename to examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino index 8e305754..27dc1df6 100644 --- a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.pde +++ b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino @@ -1,18 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include -#include - #include - -#include -#include -#include -#include +#include #include "pgmstrings.h" diff --git a/examples/hub_demo/hub_demo.pde b/examples/hub_demo/hub_demo.ino similarity index 98% rename from examples/hub_demo/hub_demo.pde rename to examples/hub_demo/hub_demo.ino index 0a8665ba..10078b95 100644 --- a/examples/hub_demo/hub_demo.pde +++ b/examples/hub_demo/hub_demo.ino @@ -1,11 +1,4 @@ -#include -#include -#include -#include -#include #include -#include -#include #include "pgmstrings.h" USB Usb; diff --git a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.pde b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino similarity index 89% rename from examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.pde rename to examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino index d6ce279a..97718214 100644 --- a/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.pde +++ b/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_terminal.ino @@ -1,21 +1,9 @@ /* Arduino terminal for PL2303 USB to serial converter and DealeXtreme GPRS modem. */ /* USB support */ -#include -#include -#include -#include -#include #include -#include -#include /* CDC support */ #include #include -/* Debug support */ -#include -#include -#include -#include class PLAsyncOper : public CDCAsyncOper { diff --git a/examples/pl2303/pl2303_gps/pl2303_gps.pde b/examples/pl2303/pl2303_gps/pl2303_gps.ino similarity index 88% rename from examples/pl2303/pl2303_gps/pl2303_gps.pde rename to examples/pl2303/pl2303_gps/pl2303_gps.ino index 8cf26fd5..5c8548fc 100644 --- a/examples/pl2303/pl2303_gps/pl2303_gps.pde +++ b/examples/pl2303/pl2303_gps/pl2303_gps.ino @@ -1,22 +1,10 @@ /* USB Host to PL2303-based USB GPS unit interface */ /* Navibee GM720 receiver - Sirf Star III */ /* USB support */ -#include -#include -#include -#include -#include #include -#include -#include /* CDC support */ #include #include -/* Debug support */ -#include -#include -#include -#include class PLAsyncOper : public CDCAsyncOper { diff --git a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.pde b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino similarity index 96% rename from examples/pl2303/pl2303_tinygps/pl2303_tinygps.pde rename to examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino index 85798192..6724141c 100644 --- a/examples/pl2303/pl2303_tinygps/pl2303_tinygps.pde +++ b/examples/pl2303/pl2303_tinygps/pl2303_tinygps.ino @@ -4,25 +4,12 @@ /* test_with_gps_device library example modified for PL2302 access */ /* USB support */ -#include -#include -#include -#include -#include #include -#include -#include /* CDC support */ #include #include -/* Debug support */ -#include -#include -#include -#include - #include /* This sample code demonstrates the normal use of a TinyGPS object. diff --git a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.pde b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino similarity index 91% rename from examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.pde rename to examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino index 1cf3ac57..741a2f2c 100644 --- a/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.pde +++ b/examples/pl2303/pl2303_xbee_terminal/pl2303_xbee_terminal.ino @@ -1,22 +1,10 @@ /* Arduino terminal for PL2303 USB to serial converter and XBee radio. */ /* Inserts linefeed after carriage return in data sent to and received from Xbee */ /* USB support */ -#include -#include -#include -#include -#include #include -#include -#include /* CDC support */ #include #include -/* Debug support */ -#include -#include -#include -#include class PLAsyncOper : public CDCAsyncOper { diff --git a/examples/testusbhostFAT/testusbhostFAT.ino b/examples/testusbhostFAT/testusbhostFAT.ino old mode 100755 new mode 100644 From 822519b2ce05c26c6a73936467c9ce0e3d677c48 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 5 Oct 2013 00:18:12 +0200 Subject: [PATCH 04/10] There is no need to manually activate Sanguino anymore as users will be forced to use Arduino 1.5.x for the Balanduino --- README.md | 2 +- UsbCore.h | 2 +- avrpins.h | 84 ++++++++++++++++++++++++++---------------------------- settings.h | 3 -- 4 files changed, 42 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 590a9413..6a237763 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Currently the following boards are supported by the library: The following boards need to be activated manually in [settings.h](settings.h): -* Arduino Mega ADK, Teensy 2.0, Sanguino, and Black Widdow. +* Arduino Mega ADK, Teensy 2.0 and Black Widdow. Simply set the corresponding value to 1 instead of 0. diff --git a/UsbCore.h b/UsbCore.h index 79e0da38..dd4bb370 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -21,7 +21,7 @@ typedef MAX3421e MAX3421E; // Black Widow typedef MAX3421e MAX3421E; // Teensy++ 2.0 & 1.0 #elif defined(BOARD_MEGA_ADK) typedef MAX3421e MAX3421E; // Arduino Mega ADK -#elif defined(BOARD_BALANDUINO) +#elif defined(ARDUINO_AVR_BALANDUINO) typedef MAX3421e MAX3421E; // Balanduino #else typedef MAX3421e MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo etc.) diff --git a/avrpins.h b/avrpins.h index cea85d3c..ae878c43 100644 --- a/avrpins.h +++ b/avrpins.h @@ -27,8 +27,6 @@ e-mail : support@circuitsathome.com #define BOARD_MEGA_ADK #elif !defined(BOARD_TEENSY) && USE_UHS_TEENSY #define BOARD_TEENSY -#elif !defined(BOARD_SANGUINO) && (USE_UHS_SANGUINO || defined(ARDUINO_AVR_SANGUINO)) -#define BOARD_SANGUINO #elif !defined(BOARD_BLACK_WIDDOW) && USE_UHS_BLACK_WIDDOW #define BOARD_BLACK_WIDDOW #endif @@ -451,8 +449,7 @@ public: /* Arduino pin definitions */ #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) - -// "Mega" Arduino pin numbers +// "Mega" Arduino pin numbers #define P0 Pe0 #define P1 Pe1 @@ -517,7 +514,7 @@ public: // "Mega" pin numbers #elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) -//"Classic" Arduino pin numbers +// "Classic" Arduino pin numbers #define P0 Pd0 #define P1 Pd1 @@ -665,7 +662,44 @@ public: #define P45 Pf7 // Teensy++ 2.0 -#elif defined(BOARD_SANGUINO) && (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) +#elif defined(ARDUINO_AVR_BALANDUINO) && (defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284P__)) +// Balanduino pin numbers +// http://balanduino.net/ +#define P0 Pd0 /* 0 - PD0 */ +#define P1 Pd1 /* 1 - PD1 */ +#define P2 Pb2 /* 2 - PB2 */ +#define P3 Pd6 /* 3 - PD6 */ +#define P4 Pd7 /* 4 - PD7 */ +#define P5 Pb3 /* 5 - PB3 */ +#define P6 Pb4 /* 6 - PB4 */ +#define P7 Pa0 /* 7 - PA0 */ +#define P8 Pa1 /* 8 - PA1 */ +#define P9 Pa2 /* 9 - PA2 */ +#define P10 Pa3 /* 10 - PA3 */ +#define P11 Pa4 /* 11 - PA4 */ +#define P12 Pa5 /* 12 - PA5 */ +#define P13 Pc1 /* 13 - PC1 */ +#define P14 Pc0 /* 14 - PC0 */ +#define P15 Pd2 /* 15 - PD2 */ +#define P16 Pd3 /* 16 - PD3 */ +#define P17 Pd4 /* 17 - PD4 */ +#define P18 Pd5 /* 18 - PD5 */ +#define P19 Pc2 /* 19 - PC2 */ +#define P20 Pc3 /* 20 - PC3 */ +#define P21 Pc4 /* 21 - PC4 */ +#define P22 Pc5 /* 22 - PC5 */ +#define P23 Pc6 /* 23 - PC6 */ +#define P24 Pc7 /* 24 - PC7 */ +#define P25 Pb0 /* 25 - PB0 */ +#define P26 Pb1 /* 26 - PB1 */ +#define P27 Pb5 /* 27 - PB5 */ +#define P28 Pb6 /* 28 - PB6 */ +#define P29 Pb7 /* 29 - PB7 */ +#define P30 Pa6 /* 30 - PA6 */ +#define P31 Pa7 /* 31 - PA7 */ +// Balanduino + +#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) // Sanguino pin numbers // Homepage: http://sanguino.cc/hardware // Hardware add-on: https://github.com/Lauszus/Sanguino @@ -703,44 +737,6 @@ public: #define P31 Pa7 // Sanguino -#elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega1284P__) -#define BOARD_BALANDUINO -// Balanduino pin numbers -// http://balanduino.net/ -#define P0 Pd0 /* 0 - PD0 */ -#define P1 Pd1 /* 1 - PD1 */ -#define P2 Pb2 /* 2 - PB2 */ -#define P3 Pd6 /* 3 - PD6 */ -#define P4 Pd7 /* 4 - PD7 */ -#define P5 Pb3 /* 5 - PB3 */ -#define P6 Pb4 /* 6 - PB4 */ -#define P7 Pa0 /* 7 - PA0 */ -#define P8 Pa1 /* 8 - PA1 */ -#define P9 Pa2 /* 9 - PA2 */ -#define P10 Pa3 /* 10 - PA3 */ -#define P11 Pa4 /* 11 - PA4 */ -#define P12 Pa5 /* 12 - PA5 */ -#define P13 Pc1 /* 13 - PC1 */ -#define P14 Pc0 /* 14 - PC0 */ -#define P15 Pd2 /* 15 - PD2 */ -#define P16 Pd3 /* 16 - PD3 */ -#define P17 Pd4 /* 17 - PD4 */ -#define P18 Pd5 /* 18 - PD5 */ -#define P19 Pc2 /* 19 - PC2 */ -#define P20 Pc3 /* 20 - PC3 */ -#define P21 Pc4 /* 21 - PC4 */ -#define P22 Pc5 /* 22 - PC5 */ -#define P23 Pc6 /* 23 - PC6 */ -#define P24 Pc7 /* 24 - PC7 */ -#define P25 Pb0 /* 25 - PB0 */ -#define P26 Pb1 /* 26 - PB1 */ -#define P27 Pb5 /* 27 - PB5 */ -#define P28 Pb6 /* 28 - PB6 */ -#define P29 Pb7 /* 29 - PB7 */ -#define P30 Pa6 /* 30 - PA6 */ -#define P31 Pa7 /* 31 - PA7 */ -// Balanduino - #endif // Arduino pin definitions #endif //_avrpins_h_ \ No newline at end of file diff --git a/settings.h b/settings.h index ba5da5c5..3da06781 100644 --- a/settings.h +++ b/settings.h @@ -34,9 +34,6 @@ /* Set this to 1 if you are using a Teensy 1.0 or 2.0 */ #define USE_UHS_TEENSY 0 -/* Set this to 1 if you are using a Sanguino */ -#define USE_UHS_SANGUINO 0 - /* Set this to 1 if you are using a Black Widdow */ #define USE_UHS_BLACK_WIDDOW 0 From 86f88e53330f99defa0d132b9b4babb3900dcb3b Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 5 Oct 2013 00:21:16 +0200 Subject: [PATCH 05/10] Automatically detect if a Teensy is connected --- README.md | 3 ++- UsbCore.h | 2 +- avrpins.h | 8 ++------ settings.h | 7 ------- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 6a237763..e2ce776a 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,8 @@ Currently the following boards are supported by the library: The following boards need to be activated manually in [settings.h](settings.h): -* Arduino Mega ADK, Teensy 2.0 and Black Widdow. +* Arduino Mega ADK +* Black Widdow Simply set the corresponding value to 1 instead of 0. diff --git a/UsbCore.h b/UsbCore.h index dd4bb370..6d1c205d 100644 --- a/UsbCore.h +++ b/UsbCore.h @@ -17,7 +17,7 @@ /* shield pins. First parameter - SS pin, second parameter - INT pin */ #ifdef BOARD_BLACK_WIDDOW typedef MAX3421e MAX3421E; // Black Widow -#elif defined(BOARD_TEENSY_PLUS_PLUS) +#elif defined(CORE_TEENSY) && (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)) typedef MAX3421e MAX3421E; // Teensy++ 2.0 & 1.0 #elif defined(BOARD_MEGA_ADK) typedef MAX3421e MAX3421E; // Arduino Mega ADK diff --git a/avrpins.h b/avrpins.h index ae878c43..17f832b5 100644 --- a/avrpins.h +++ b/avrpins.h @@ -25,14 +25,10 @@ e-mail : support@circuitsathome.com // Support for these boards needs to be manually activated in settings.h or in a makefile #if !defined(BOARD_MEGA_ADK) && defined(__AVR_ATmega2560__) && USE_UHS_MEGA_ADK #define BOARD_MEGA_ADK -#elif !defined(BOARD_TEENSY) && USE_UHS_TEENSY -#define BOARD_TEENSY #elif !defined(BOARD_BLACK_WIDDOW) && USE_UHS_BLACK_WIDDOW #define BOARD_BLACK_WIDDOW #endif -//#include - #ifdef PORTA #define USE_PORTA #endif @@ -541,7 +537,7 @@ public: // "Classic" Arduino pin numbers -#elif defined(BOARD_TEENSY) && defined(__AVR_ATmega32U4__) +#elif defined(CORE_TEENSY) && defined(__AVR_ATmega32U4__) // Teensy 2.0 pin numbers // http://www.pjrc.com/teensy/pinout.html #define P0 Pb0 @@ -611,7 +607,7 @@ public: // Arduino Leonardo pin numbers -#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) +#elif defined(CORE_TEENSY) && (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)) // Teensy++ 2.0 pin numbers // http://www.pjrc.com/teensy/pinout.html #define P0 Pd0 diff --git a/settings.h b/settings.h index 3da06781..d22361a0 100644 --- a/settings.h +++ b/settings.h @@ -31,9 +31,6 @@ /* Set this to 1 if you are using an Arduino Mega ADK board with MAX3421e built-in */ #define USE_UHS_MEGA_ADK 0 -/* Set this to 1 if you are using a Teensy 1.0 or 2.0 */ -#define USE_UHS_TEENSY 0 - /* Set this to 1 if you are using a Black Widdow */ #define USE_UHS_BLACK_WIDDOW 0 @@ -58,10 +55,6 @@ #define DEBUG_USB_HOST #endif -#if !defined(BOARD_TEENSY_PLUS_PLUS) && (defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)) -#define BOARD_TEENSY_PLUS_PLUS -#endif - // When will we drop support for the older bug-ridden stuff? #if defined(ARDUINO) && ARDUINO >=100 #include From 7abee0b545577025434acc555cd9bf9b18318973 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 6 Oct 2013 15:46:15 +0200 Subject: [PATCH 06/10] Include pins_arduino.h manually if the old Arduino IDE is used --- settings.h | 1 + 1 file changed, 1 insertion(+) diff --git a/settings.h b/settings.h index d22361a0..29904b13 100644 --- a/settings.h +++ b/settings.h @@ -61,6 +61,7 @@ #else #include // I am not sure what WProgram.h does not include, so these are here. --xxxajk +#include #include #include #endif From 47ff8e55c55d84404222313ba857c96d5e069d5f Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 7 Oct 2013 00:41:49 +0200 Subject: [PATCH 07/10] Retry if device returns hrJERR --- Usb.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Usb.cpp b/Usb.cpp index 122420bc..d1a3592c 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -581,7 +581,12 @@ uint8_t USB::AttemptConfig(uint8_t driver, uint8_t parent, uint8_t port, bool lo } } rcode = devConfig[driver]->Init(parent, port, lowspeed); - if(rcode) { + if (rcode == hrJERR) { // Some devices returns this when plugged in - trying to initialize the device again usually works + delay(100); + devConfig[driver]->ConfigureDevice(parent, port, lowspeed); // Just ignore the returned value + rcode = devConfig[driver]->Init(parent, port, lowspeed); + } + if (rcode) { // Issue a bus reset, because the device may be in a limbo state if (parent == 0) { // Send a bus reset on the root interface. From b76ddedd59fade5ca82eca0122cf4ec82211c2bd Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 7 Oct 2013 00:47:53 +0200 Subject: [PATCH 08/10] Implement ConfigureDevice() before Init() Also added clearAllVariables() - see: https://github.com/felis/USB_Host_Shield_2.0/pull/63 --- BTD.cpp | 160 +++++++++++++++++++++++++++++++++++--------------------- BTD.h | 9 ++++ 2 files changed, 108 insertions(+), 61 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 254f104e..8c846303 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -34,45 +34,37 @@ qNextPollTime(0), // Reset NextPollTime pollInterval(0), bPollEnable(false) // Don't start polling before dongle is connected { - uint8_t i; - for (i = 0; i < BTD_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; - } - for (i = 0; i < BTD_NUMSERVICES; i++) + for (uint8_t i = 0; i < BTD_NUMSERVICES; i++) btService[i] = NULL; - if (pUsb) // register in USB subsystem - pUsb->RegisterDeviceClass(this); //set devConfig[] entry + clearAllVariables(); // Set all variables, endpoint structs etc. to default values + + if (pUsb) // Register in USB subsystem + pUsb->RegisterDeviceClass(this); // Set devConfig[] entry } -uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { - uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; +uint8_t BTD::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) { + const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR); + uint8_t buf[constBufSize]; uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; - uint8_t num_of_conf; // number of configurations - uint16_t PID; - uint16_t VID; - // get memory address of USB device address pool - AddressPool &addrPool = pUsb->GetAddressPool(); + clearAllVariables(); // Set all variables, endpoint structs etc. to default values + + AddressPool &addrPool = pUsb->GetAddressPool(); // Get memory address of USB device address pool #ifdef EXTRADEBUG - Notify(PSTR("\r\nBTD Init"), 0x80); + Notify(PSTR("\r\nBTD ConfigureDevice"), 0x80); #endif - // check if address has already been assigned to an instance - if (bAddress) { + + if (bAddress) { // Check if address has already been assigned to an instance #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); - + p = addrPool.GetUsbDevicePtr(0); // Get pointer to pseudo device with address 0 assigned if (!p) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nAddress not found"), 0x80); @@ -87,66 +79,97 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { 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; - + oldep_ptr = p->epinfo; // Save old pointer to EP_RECORD of address 0 + p->epinfo = epInfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->lowspeed = lowspeed; + rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data - // 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; + p->epinfo = oldep_ptr; // Restore p->epinfo if (rcode) goto FailGetDevDescr; - // Allocate new address according to device class - bAddress = addrPool.AllocAddress(parent, false, port); + bAddress = addrPool.AllocAddress(parent, false, port); // Allocate new address according to device class - if (!bAddress) + if (!bAddress) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nOut of address space"), 0x80); +#endif return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; + } - // Extract Max Packet Size from device descriptor - epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; + epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Extract Max Packet Size from device descriptor + epInfo[1].epAddr = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Steal and abuse from epInfo structure to save memory - // Assign new address to the device - rcode = pUsb->setAddr(0, 0, bAddress); + return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; + +FailGetDevDescr: +#ifdef DEBUG_USB_HOST + NotifyFailGetDevDescr(rcode); +#endif + rcode = USB_ERROR_FailGetDevDescr; + Release(); + return rcode; +}; + +uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { + uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; + uint8_t rcode; + uint8_t num_of_conf = epInfo[1].epAddr; // Number of configurations + epInfo[1].epAddr = 0; + uint16_t PID; + uint16_t VID; + + AddressPool &addrPool = pUsb->GetAddressPool(); +#ifdef EXTRADEBUG + Notify(PSTR("\r\nBTD Init"), 0x80); +#endif + UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record + + if (!p) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nAddress not found"), 0x80); +#endif + return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; + } + + delay(300); // Assign new address to the device + + rcode = pUsb->setAddr(0, 0, bAddress); // Assign new address to the device if (rcode) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nsetAddr: "), 0x80); D_PrintHex (rcode, 0x80); #endif + p->lowspeed = false; goto Fail; } #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) + p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record + if (!p) { +#ifdef DEBUG_USB_HOST + Notify(PSTR("\r\nAddress not found"), 0x80); +#endif 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); + rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); // Assign epInfo to epinfo pointer - only EP0 is known if (rcode) goto FailSetDevTblEntry; + VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor; PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct; if (VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) { - /* We only need the Control endpoint, so we don't have to initialize the other endpoints of device */ - rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1); + rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1); // We only need the Control endpoint, so we don't have to initialize the other endpoints of device if (rcode) goto FailSetConfDescr; @@ -184,8 +207,6 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { Release(); // Release device return USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; // Return } else { - num_of_conf = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; - // Check if attached device is a Bluetooth dongle and fill endpoint data structure // First interface in the configuration must have Bluetooth assigned Class/Subclass/Protocol // And 3 endpoints - interrupt-IN, bulk-IN, bulk-OUT, not necessarily in this order @@ -211,8 +232,6 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetDevTblEntry; - delay(200); // Give time for address change - // Set Configuration Value rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, bConfNum); if (rcode) @@ -270,6 +289,28 @@ Fail: return rcode; } +void BTD::clearAllVariables() { + uint8_t i; + for (i = 0; i < BTD_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; + } + for (i = 0; i < BTD_NUMSERVICES; i++) { + if (btService[i]) + btService[i]->Reset(); // Reset all Bluetooth services + } + + connectToWii = false; + pairWithWii = false; + bAddress = 0; // Clear device address + bNumEP = 1; // Must have to be reset to 1 + qNextPollTime = 0; // Reset next poll time + pollInterval = 0; + bPollEnable = false; // Don't start polling before dongle is connected +} + /* Extracts interrupt-IN, bulk-IN, bulk-OUT endpoint information from config descriptor */ void BTD::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *pep) { //ErrorMessage(PSTR("Conf.Val"),conf); @@ -323,15 +364,8 @@ void BTD::PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr) { /* Performs a cleanup after failed Init() attempt */ uint8_t BTD::Release() { - for (uint8_t i = 0; i < BTD_NUMSERVICES; i++) { - if (btService[i]) - btService[i]->Reset(); // Reset all Bluetooth services - } - + clearAllVariables(); // Set all variables, endpoint structs etc. to default values pUsb->GetAddressPool().FreeAddress(bAddress); - bAddress = 0; - bPollEnable = false; - bNumEP = 1; // must have to be reset to 1 return 0; } @@ -780,6 +814,10 @@ void BTD::HCI_task() { for (uint8_t i = 0; i < BULK_MAXPKTSIZE; i++) l2capinbuf[i] = 0; + connectToWii = false; + incomingWii = false; + pairWithWii = false; + hci_state = HCI_SCANNING_STATE; } break; diff --git a/BTD.h b/BTD.h index 097b66f6..7927380f 100755 --- a/BTD.h +++ b/BTD.h @@ -162,6 +162,14 @@ public: BTD(USB *p); /** @name USBDeviceConfig implementation */ + /** + * Address assignment and basic initilization is done here. + * @param parent Hub number. + * @param port Port number on the hub. + * @param lowspeed Speed of the device. + * @return 0 on success. + */ + virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed); /** * Initialize the Bluetooth dongle. * @param parent Hub number. @@ -455,6 +463,7 @@ protected: void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); private: + void clearAllVariables(); // Set all variables, endpoint structs etc. to default values BluetoothService* btService[BTD_NUMSERVICES]; bool bPollEnable; From 90dba7193740d568b2efaf290c735c2cd42f3b94 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 7 Oct 2013 01:45:21 +0200 Subject: [PATCH 09/10] Moved PID and VID readings --- BTD.cpp | 9 +++------ BTD.h | 2 ++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 8c846303..993e2540 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -101,6 +101,9 @@ uint8_t BTD::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) { epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Extract Max Packet Size from device descriptor epInfo[1].epAddr = ((USB_DEVICE_DESCRIPTOR*)buf)->bNumConfigurations; // Steal and abuse from epInfo structure to save memory + VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor; + PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct; + return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; FailGetDevDescr: @@ -113,12 +116,9 @@ FailGetDevDescr: }; uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { - uint8_t buf[sizeof (USB_DEVICE_DESCRIPTOR)]; uint8_t rcode; uint8_t num_of_conf = epInfo[1].epAddr; // Number of configurations epInfo[1].epAddr = 0; - uint16_t PID; - uint16_t VID; AddressPool &addrPool = pUsb->GetAddressPool(); #ifdef EXTRADEBUG @@ -165,9 +165,6 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) { if (rcode) goto FailSetDevTblEntry; - VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor; - PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct; - if (VID == PS3_VID && (PID == PS3_PID || PID == PS3NAVIGATION_PID || PID == PS3MOVE_PID)) { rcode = pUsb->setConf(bAddress, epInfo[ BTD_CONTROL_PIPE ].epAddr, 1); // We only need the Control endpoint, so we don't have to initialize the other endpoints of device if (rcode) diff --git a/BTD.h b/BTD.h index 7927380f..a2e3d62d 100755 --- a/BTD.h +++ b/BTD.h @@ -466,6 +466,8 @@ private: void clearAllVariables(); // Set all variables, endpoint structs etc. to default values BluetoothService* btService[BTD_NUMSERVICES]; + uint16_t PID, VID; // PID and VID of device connected + bool bPollEnable; uint8_t pollInterval; From 332f56f46d76e57bf12425ba9b589dee9e28a574 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 8 Oct 2013 16:02:20 +0200 Subject: [PATCH 10/10] Fixed getButtonClick for analog buttons --- XBOXOLD.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/XBOXOLD.cpp b/XBOXOLD.cpp index f766e329..4c9bcb20 100644 --- a/XBOXOLD.cpp +++ b/XBOXOLD.cpp @@ -299,9 +299,11 @@ bool XBOXOLD::getButtonClick(Button b) { uint8_t button; if (b == A || b == B || b == X || b == Y || b == BLACK || b == WHITE || b == L1 || b == R1) { // A, B, X, Y, BLACK, WHITE, L1, and R1 are analog buttons button = pgm_read_byte(&XBOXOLDBUTTONS[(uint8_t)b]); - if (buttonClicked[button]) + if (buttonClicked[button]) { buttonClicked[button] = false; - return buttonClicked[button]; + return true; + } + return false; } button = pgm_read_byte(&XBOXOLDBUTTONS[(uint8_t)b]); // Digital buttons