From e0b9ea89cb8daf11442f38d2cfb615bf8a155956 Mon Sep 17 00:00:00 2001 From: Oleg Mazurov Date: Wed, 18 Dec 2013 15:04:13 -0700 Subject: [PATCH 01/36] dec18 --- examples/testusbhostFAT/Arduino_Makefile_master | 2 +- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- settings.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master index 7f1fe2f8..f379bae0 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit 7f1fe2f8ec3db4d1bd0a5c516dd379e2539d1303 +Subproject commit f379bae02aa3d9c3da558ba2041558b88db95bbb diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index db5de2fe..071b65b9 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit db5de2fe3c2e0d2d96de98864b1b6e00e172f727 +Subproject commit 071b65b923b2656bb1e1b622de5272b4ed9a4996 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index 16374f68..8bcf5f90 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit 16374f681b31d411661b7bd9ff5e578b2dff6843 +Subproject commit 8bcf5f90f8bd967378b6eeebd7fd943f125fbc18 diff --git a/settings.h b/settings.h index add3ee03..e47b1c43 100644 --- a/settings.h +++ b/settings.h @@ -14,7 +14,7 @@ //////////////////////////////////////////////////////////////////////////////// /* Set this to 1 to activate serial debugging */ -#define ENABLE_UHS_DEBUGGING 0 +#define ENABLE_UHS_DEBUGGING 1 /* This can be used to select which serial port to use for debugging if * multiple serial ports are available. From d35b83e5a536499d52cd33c27ba610847066bf3d Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 19 Aug 2014 22:57:18 -0700 Subject: [PATCH 02/36] Support new revision of Balanduino PCB --- avrpins.h | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/avrpins.h b/avrpins.h index c59e9c52..da80349d 100644 --- a/avrpins.h +++ b/avrpins.h @@ -672,10 +672,19 @@ public: // 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 */ + +#if BALANDUINO_REVISION < 13 + #define P2 Pb2 /* 2 - PB2 */ + #define P3 Pd6 /* 3 - PD6 */ + #define P4 Pd7 /* 4 - PD7 */ + #define P5 Pb3 /* 5 - PB3 */ +#else + #define P2 Pd2 /* 2 - PD2 */ + #define P3 Pd3 /* 3 - PD3 */ + #define P4 Pd6 /* 4 - PD6 */ + #define P5 Pd7 /* 5 - PD7 */ +#endif + #define P6 Pb4 /* 6 - PB4 */ #define P7 Pa0 /* 7 - PA0 */ #define P8 Pa1 /* 8 - PA1 */ @@ -685,8 +694,15 @@ public: #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 */ + +#if BALANDUINO_REVISION < 13 + #define P15 Pd2 /* 15 - PD2 */ + #define P16 Pd3 /* 16 - PD3 */ +#else + #define P15 Pb2 /* 15 - PB2 */ + #define P16 Pb3 /* 16 - PB2 */ +#endif + #define P17 Pd4 /* 17 - PD4 */ #define P18 Pd5 /* 18 - PD5 */ #define P19 Pc2 /* 19 - PC2 */ From 8cf054cd616603551864cca7f97dce041f0b6a70 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 24 Aug 2014 00:37:46 -0700 Subject: [PATCH 03/36] Disable debugging again and updated submodules --- examples/testusbhostFAT/Arduino_Makefile_master | 2 +- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- settings.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master index f379bae0..7ada91a9 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit f379bae02aa3d9c3da558ba2041558b88db95bbb +Subproject commit 7ada91a90027ccb7558b74087fb68d3940ecf64d diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index 071b65b9..72b5bf46 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit 071b65b923b2656bb1e1b622de5272b4ed9a4996 +Subproject commit 72b5bf467a1c2479ba7354ee4d864e382c167425 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index 8bcf5f90..2bf8f633 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit 8bcf5f90f8bd967378b6eeebd7fd943f125fbc18 +Subproject commit 2bf8f633e7f9bc5a7bf4c00f3f45c7b79484198e diff --git a/settings.h b/settings.h index 3ab12541..e3d0ed1d 100644 --- a/settings.h +++ b/settings.h @@ -24,7 +24,7 @@ e-mail : support@circuitsathome.com //////////////////////////////////////////////////////////////////////////////// /* Set this to 1 to activate serial debugging */ -#define ENABLE_UHS_DEBUGGING 1 +#define ENABLE_UHS_DEBUGGING 0 /* This can be used to select which serial port to use for debugging if * multiple serial ports are available. From 980109f756f46c7b632af591d207a81ca1ac12a4 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Sun, 24 Aug 2014 17:26:49 -0700 Subject: [PATCH 04/36] Disable some of the functions in PS3BT and Wii library examples so it always compile on Arduino Uno --- examples/Bluetooth/PS3BT/PS3BT.ino | 4 ++++ examples/Bluetooth/Wii/Wii.ino | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/examples/Bluetooth/PS3BT/PS3BT.ino b/examples/Bluetooth/PS3BT/PS3BT.ino index 982eb384..2878b504 100644 --- a/examples/Bluetooth/PS3BT/PS3BT.ino +++ b/examples/Bluetooth/PS3BT/PS3BT.ino @@ -118,13 +118,16 @@ void loop() { printAngle = !printAngle; } } +#if 0 // Set this to 1 in order to see the angle of the controller if (printAngle) { Serial.print(F("\r\nPitch: ")); Serial.print(PS3.getAngle(Pitch)); Serial.print(F("\tRoll: ")); Serial.print(PS3.getAngle(Roll)); } +#endif } +#if 0 // Set this to 1 in order to enable support for the Playstation Move controller else if (PS3.PS3MoveConnected) { if (PS3.getAnalogButton(T)) { Serial.print(F("\r\nT: ")); @@ -177,4 +180,5 @@ void loop() { Serial.print(PS3.getTemperature()); } } +#endif } diff --git a/examples/Bluetooth/Wii/Wii.ino b/examples/Bluetooth/Wii/Wii.ino index f4d68a62..bbd5dc03 100644 --- a/examples/Bluetooth/Wii/Wii.ino +++ b/examples/Bluetooth/Wii/Wii.ino @@ -78,6 +78,7 @@ void loop() { Serial.print(F("\r\nB")); } } +#if 0 // Set this to 1 in order to see the angle of the controllers if (printAngle) { Serial.print(F("\r\nPitch: ")); Serial.print(Wii.getPitch()); @@ -94,7 +95,9 @@ void loop() { Serial.print(Wii.getNunchuckRoll()); } } +#endif } +#if 0 // Set this to 1 if you are using a Nunchuck controller if (Wii.nunchuckConnected) { if (Wii.getButtonClick(Z)) Serial.print(F("\r\nZ")); @@ -107,4 +110,5 @@ void loop() { Serial.print(Wii.getAnalogHat(HatY)); } } +#endif } From e851f0d7ae25077bef9a82660ecb569639e1c087 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Thu, 28 Aug 2014 18:20:36 -0700 Subject: [PATCH 05/36] Added donate button --- README.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index edb440a2..0ba90aa9 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,27 @@ For more information about the hardware see the [Hardware Manual](http://www.cir * __Oleg Mazurov, Circuits@Home__ - * __Alexei Glushchenko, Circuits@Home__ - - * Developers of the USB Core, HID, FTDI, ADK, ACM, and PL2303 libraries + * Developers of the USB Core, HID, FTDI, ADK, ACM, and PL2303 libraries * __Kristian Lauszus, TKJ Electronics__ - - * 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 + * 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 + * Major contributor to mass storage code + +# Donate + +Help yourself by helping us support you! Many thousands of hours have been spent developing the USB Host Shield library. Since you find it useful, please consider donating via the button below. Donations will allow us to support you by ensuring hardware that you have can be acquired in order to add support for your microcontroller board. + +
+ + + + + + + + + +
# Table of Contents @@ -58,8 +74,8 @@ Now move the "USB\_Host\_Shield\_20" directory to the "libraries" directory. The final structure should look like this: * Arduino/ - * libraries/ - * USB\_Host\_Shield\_20/ + * libraries/ + * USB\_Host\_Shield\_20/ Now quit the Arduino IDE and reopen it. @@ -89,7 +105,7 @@ Currently the following boards are supported by the library: * Arduino Due * If you are using the Arduino Due, 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. + * 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 * Black Widdow @@ -97,7 +113,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 - * If you are using Arduino 1.5.5 or newer there is no need to activate the Arduino Mega ADK manually + * If you are using Arduino 1.5.5 or newer there is no need to activate the Arduino Mega ADK manually * Black Widdow Simply set the corresponding value to 1 instead of 0. From bf9fa2c5ecfd923872edec1c50b477427e1e8593 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Thu, 28 Aug 2014 18:31:38 -0700 Subject: [PATCH 06/36] Fixed donate button --- README.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/README.md b/README.md index 0ba90aa9..e2abe20a 100644 --- a/README.md +++ b/README.md @@ -30,17 +30,7 @@ For more information about the hardware see the [Hardware Manual](http://www.cir Help yourself by helping us support you! Many thousands of hours have been spent developing the USB Host Shield library. Since you find it useful, please consider donating via the button below. Donations will allow us to support you by ensuring hardware that you have can be acquired in order to add support for your microcontroller board. -
- - - - - - - - - -
+PayPal - The safer, easier way to pay online! # Table of Contents From a932871f3476dd1742e41ad7f03c3263d27dcdf8 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Thu, 28 Aug 2014 18:32:51 -0700 Subject: [PATCH 07/36] Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e2abe20a..58599d42 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ For more information about the hardware see the [Hardware Manual](http://www.cir Help yourself by helping us support you! Many thousands of hours have been spent developing the USB Host Shield library. Since you find it useful, please consider donating via the button below. Donations will allow us to support you by ensuring hardware that you have can be acquired in order to add support for your microcontroller board. -PayPal - The safer, easier way to pay online! +PayPal - The safer, easier way to pay online! # Table of Contents From bde11036a97268ae53ebd2bd00b089cd4d3eebd2 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 2 Sep 2014 00:16:48 -0700 Subject: [PATCH 08/36] Endpoints types where already defined in usb_ch9.h, so no need to redefine them --- PS3USB.cpp | 4 ++-- PS3USB.h | 3 --- XBOXOLD.cpp | 4 ++-- XBOXOLD.h | 3 --- XBOXRECV.cpp | 16 ++++++++-------- XBOXRECV.h | 3 --- XBOXUSB.cpp | 4 ++-- XBOXUSB.h | 3 --- 8 files changed, 14 insertions(+), 26 deletions(-) diff --git a/PS3USB.cpp b/PS3USB.cpp index 7e6285a2..c3217538 100644 --- a/PS3USB.cpp +++ b/PS3USB.cpp @@ -152,13 +152,13 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* Initialize data structures for endpoints of device */ epInfo[ PS3_OUTPUT_PIPE ].epAddr = 0x02; // PS3 output endpoint - epInfo[ PS3_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT; + epInfo[ PS3_OUTPUT_PIPE ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ PS3_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ PS3_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE; epInfo[ PS3_OUTPUT_PIPE ].bmSndToggle = 0; epInfo[ PS3_OUTPUT_PIPE ].bmRcvToggle = 0; epInfo[ PS3_INPUT_PIPE ].epAddr = 0x01; // PS3 report endpoint - epInfo[ PS3_INPUT_PIPE ].epAttribs = EP_INTERRUPT; + epInfo[ PS3_INPUT_PIPE ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ PS3_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ PS3_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE; epInfo[ PS3_INPUT_PIPE ].bmSndToggle = 0; diff --git a/PS3USB.h b/PS3USB.h index 5bbbdf2e..ca343a81 100644 --- a/PS3USB.h +++ b/PS3USB.h @@ -24,9 +24,6 @@ /* PS3 data taken from descriptors */ #define EP_MAXPKTSIZE 64 // max size for data via USB -/* Endpoint types */ -#define EP_INTERRUPT 0x03 - /* Names we give to the 3 ps3 pipes - this is only used for setting the bluetooth address into the ps3 controllers */ #define PS3_CONTROL_PIPE 0 #define PS3_OUTPUT_PIPE 1 diff --git a/XBOXOLD.cpp b/XBOXOLD.cpp index 298d5ab1..78e6e9a5 100644 --- a/XBOXOLD.cpp +++ b/XBOXOLD.cpp @@ -167,13 +167,13 @@ uint8_t XBOXOLD::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* Initialize data structures for endpoints of device */ epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01; // XBOX report endpoint - epInfo[ XBOX_INPUT_PIPE ].epAttribs = EP_INTERRUPT; + 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; epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x02; // XBOX output endpoint - epInfo[ XBOX_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT; + 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; diff --git a/XBOXOLD.h b/XBOXOLD.h index b3c0ccb2..f5f95dce 100644 --- a/XBOXOLD.h +++ b/XBOXOLD.h @@ -24,9 +24,6 @@ /* Data Xbox taken from descriptors */ #define EP_MAXPKTSIZE 32 // Max size for data via USB -/* Endpoint types */ -#define EP_INTERRUPT 0x03 - /* Names we give to the 3 Xbox pipes */ #define XBOX_CONTROL_PIPE 0 #define XBOX_INPUT_PIPE 1 diff --git a/XBOXRECV.cpp b/XBOXRECV.cpp index 144a4aa4..41f1ff58 100644 --- a/XBOXRECV.cpp +++ b/XBOXRECV.cpp @@ -188,52 +188,52 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* Initialize data structures for endpoints of device */ epInfo[ XBOX_INPUT_PIPE_1 ].epAddr = 0x01; // XBOX 360 report endpoint - poll interval 1ms - epInfo[ XBOX_INPUT_PIPE_1 ].epAttribs = EP_INTERRUPT; + epInfo[ XBOX_INPUT_PIPE_1 ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ XBOX_INPUT_PIPE_1 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_INPUT_PIPE_1 ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_INPUT_PIPE_1 ].bmSndToggle = 0; epInfo[ XBOX_INPUT_PIPE_1 ].bmRcvToggle = 0; epInfo[ XBOX_OUTPUT_PIPE_1 ].epAddr = 0x01; // XBOX 360 output endpoint - poll interval 8ms - epInfo[ XBOX_OUTPUT_PIPE_1 ].epAttribs = EP_INTERRUPT; + epInfo[ XBOX_OUTPUT_PIPE_1 ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ XBOX_OUTPUT_PIPE_1 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_OUTPUT_PIPE_1 ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_OUTPUT_PIPE_1 ].bmSndToggle = 0; epInfo[ XBOX_OUTPUT_PIPE_1 ].bmRcvToggle = 0; epInfo[ XBOX_INPUT_PIPE_2 ].epAddr = 0x03; // XBOX 360 report endpoint - poll interval 1ms - epInfo[ XBOX_INPUT_PIPE_2 ].epAttribs = EP_INTERRUPT; + epInfo[ XBOX_INPUT_PIPE_2 ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ XBOX_INPUT_PIPE_2 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_INPUT_PIPE_2 ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_INPUT_PIPE_2 ].bmSndToggle = 0; epInfo[ XBOX_INPUT_PIPE_2 ].bmRcvToggle = 0; epInfo[ XBOX_OUTPUT_PIPE_2 ].epAddr = 0x03; // XBOX 360 output endpoint - poll interval 8ms - epInfo[ XBOX_OUTPUT_PIPE_2 ].epAttribs = EP_INTERRUPT; + epInfo[ XBOX_OUTPUT_PIPE_2 ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ XBOX_OUTPUT_PIPE_2 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_OUTPUT_PIPE_2 ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_OUTPUT_PIPE_2 ].bmSndToggle = 0; epInfo[ XBOX_OUTPUT_PIPE_2 ].bmRcvToggle = 0; epInfo[ XBOX_INPUT_PIPE_3 ].epAddr = 0x05; // XBOX 360 report endpoint - poll interval 1ms - epInfo[ XBOX_INPUT_PIPE_3 ].epAttribs = EP_INTERRUPT; + epInfo[ XBOX_INPUT_PIPE_3 ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ XBOX_INPUT_PIPE_3 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_INPUT_PIPE_3 ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_INPUT_PIPE_3 ].bmSndToggle = 0; epInfo[ XBOX_INPUT_PIPE_3 ].bmRcvToggle = 0; epInfo[ XBOX_OUTPUT_PIPE_3 ].epAddr = 0x05; // XBOX 360 output endpoint - poll interval 8ms - epInfo[ XBOX_OUTPUT_PIPE_3 ].epAttribs = EP_INTERRUPT; + epInfo[ XBOX_OUTPUT_PIPE_3 ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ XBOX_OUTPUT_PIPE_3 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_OUTPUT_PIPE_3 ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_OUTPUT_PIPE_3 ].bmSndToggle = 0; epInfo[ XBOX_OUTPUT_PIPE_3 ].bmRcvToggle = 0; epInfo[ XBOX_INPUT_PIPE_4 ].epAddr = 0x07; // XBOX 360 report endpoint - poll interval 1ms - epInfo[ XBOX_INPUT_PIPE_4 ].epAttribs = EP_INTERRUPT; + epInfo[ XBOX_INPUT_PIPE_4 ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ XBOX_INPUT_PIPE_4 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_INPUT_PIPE_4 ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_INPUT_PIPE_4 ].bmSndToggle = 0; epInfo[ XBOX_INPUT_PIPE_4 ].bmRcvToggle = 0; epInfo[ XBOX_OUTPUT_PIPE_4 ].epAddr = 0x07; // XBOX 360 output endpoint - poll interval 8ms - epInfo[ XBOX_OUTPUT_PIPE_4 ].epAttribs = EP_INTERRUPT; + epInfo[ XBOX_OUTPUT_PIPE_4 ].epAttribs = USB_TRANSFER_TYPE_INTERRUPT; epInfo[ XBOX_OUTPUT_PIPE_4 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_OUTPUT_PIPE_4 ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_OUTPUT_PIPE_4 ].bmSndToggle = 0; diff --git a/XBOXRECV.h b/XBOXRECV.h index c3964991..0c259217 100644 --- a/XBOXRECV.h +++ b/XBOXRECV.h @@ -26,9 +26,6 @@ /* Data Xbox 360 taken from descriptors */ #define EP_MAXPKTSIZE 32 // max size for data via USB -/* Endpoint types */ -#define EP_INTERRUPT 0x03 - /* Names we give to the 9 Xbox360 pipes */ #define XBOX_CONTROL_PIPE 0 #define XBOX_INPUT_PIPE_1 1 diff --git a/XBOXUSB.cpp b/XBOXUSB.cpp index 4128d231..3cd9cde9 100644 --- a/XBOXUSB.cpp +++ b/XBOXUSB.cpp @@ -155,13 +155,13 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { /* Initialize data structures for endpoints of device */ epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01; // XBOX 360 report endpoint - epInfo[ XBOX_INPUT_PIPE ].epAttribs = EP_INTERRUPT; + 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; epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x02; // XBOX 360 output endpoint - epInfo[ XBOX_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT; + 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; diff --git a/XBOXUSB.h b/XBOXUSB.h index aed330a2..8d5ecb2a 100644 --- a/XBOXUSB.h +++ b/XBOXUSB.h @@ -24,9 +24,6 @@ /* Data Xbox 360 taken from descriptors */ #define EP_MAXPKTSIZE 32 // max size for data via USB -/* Endpoint types */ -#define EP_INTERRUPT 0x03 - /* Names we give to the 3 Xbox360 pipes */ #define XBOX_CONTROL_PIPE 0 #define XBOX_INPUT_PIPE 1 From 4a1940b99b278e71377d22f5fdab16a4364ac76d Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 2 Sep 2014 01:26:17 -0700 Subject: [PATCH 09/36] Don't redefine HID parameters - just include Hid.h --- BTD.h | 4 +--- PS3USB.h | 8 +------- PSBuzz.cpp | 2 +- XBOXOLD.h | 5 +---- XBOXUSB.h | 5 +---- hid.cpp | 16 ++++++++-------- hid.h | 6 +++--- 7 files changed, 16 insertions(+), 30 deletions(-) diff --git a/BTD.h b/BTD.h index 3a639abb..33d5e8d7 100755 --- a/BTD.h +++ b/BTD.h @@ -19,6 +19,7 @@ #define _btd_h_ #include "Usb.h" +#include "Hid.h" //PID and VID of the Sony PS3 devices #define PS3_VID 0x054C // Sony Corporation @@ -34,9 +35,6 @@ // Used in control endpoint header for HCI Commands #define bmREQ_HCI_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_DEVICE -// 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 /* Bluetooth HCI states for hci_task() */ #define HCI_INIT_STATE 0 diff --git a/PS3USB.h b/PS3USB.h index ca343a81..d2d7d14e 100644 --- a/PS3USB.h +++ b/PS3USB.h @@ -19,6 +19,7 @@ #define _ps3usb_h_ #include "Usb.h" +#include "Hid.h" #include "PS3Enums.h" /* PS3 data taken from descriptors */ @@ -35,13 +36,6 @@ #define PS3NAVIGATION_PID 0x042F // Navigation controller #define PS3MOVE_PID 0x03D5 // Motion controller -// 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 bmREQ_HID_IN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE - -#define HID_REQUEST_GET_REPORT 0x01 -#define HID_REQUEST_SET_REPORT 0x09 - #define PS3_MAX_ENDPOINTS 3 /** diff --git a/PSBuzz.cpp b/PSBuzz.cpp index 56ae618d..4efd2b55 100644 --- a/PSBuzz.cpp +++ b/PSBuzz.cpp @@ -78,5 +78,5 @@ void PSBuzz::setLedRaw(bool value, uint8_t controller) { void PSBuzz::PSBuzz_Command(uint8_t *data, uint16_t nbytes) { // bmRequest = Host to device (0x00) | Class (0x20) | Interface (0x01) = 0x21, bRequest = Set Report (0x09), Report ID (0x00), Report Type (Output 0x02), interface (0x00), datalength, datalength, data) - pUsb->ctrlReq(bAddress, epInfo[0].epAddr, bmREQ_HIDOUT, HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL); + pUsb->ctrlReq(bAddress, epInfo[0].epAddr, bmREQ_HID_OUT, HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL); }; \ No newline at end of file diff --git a/XBOXOLD.h b/XBOXOLD.h index f5f95dce..dfb06df6 100644 --- a/XBOXOLD.h +++ b/XBOXOLD.h @@ -19,6 +19,7 @@ #define _xboxold_h_ #include "Usb.h" +#include "Hid.h" #include "controllerEnums.h" /* Data Xbox taken from descriptors */ @@ -39,10 +40,6 @@ #define XBOX_OLD_PID3 0x0287 // Microsoft Microsoft Xbox Controller S #define XBOX_OLD_PID4 0x0289 // Smaller Microsoft Xbox controller (US) -// 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 the original Xbox controller via USB. */ diff --git a/XBOXUSB.h b/XBOXUSB.h index 8d5ecb2a..f79523c1 100644 --- a/XBOXUSB.h +++ b/XBOXUSB.h @@ -19,6 +19,7 @@ #define _xboxusb_h_ #include "Usb.h" +#include "Hid.h" #include "xboxEnums.h" /* Data Xbox 360 taken from descriptors */ @@ -45,10 +46,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/hid.cpp b/hid.cpp index c3c425b8..174215df 100644 --- a/hid.cpp +++ b/hid.cpp @@ -24,7 +24,7 @@ uint8_t HID::GetReportDescr(uint8_t ep, USBReadParser *parser) { const uint8_t constBufLen = 64; uint8_t buf[constBufLen]; - uint8_t rcode = pUsb->ctrlReq(bAddress, ep, bmREQ_HIDREPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00, + uint8_t rcode = pUsb->ctrlReq(bAddress, ep, bmREQ_HID_REPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_REPORT, 0x0000, 128, constBufLen, buf, (USBReadParser*)parser); //return ((rcode != hrSTALL) ? rcode : 0); @@ -35,7 +35,7 @@ uint8_t HID::GetReportDescr(uint16_t wIndex, USBReadParser *parser) { const uint8_t constBufLen = 64; uint8_t buf[constBufLen]; - uint8_t rcode = pUsb->ctrlReq(bAddress, 0x00, bmREQ_HIDREPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00, + uint8_t rcode = pUsb->ctrlReq(bAddress, 0x00, bmREQ_HID_REPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_REPORT, wIndex, 128, constBufLen, buf, (USBReadParser*)parser); //return ((rcode != hrSTALL) ? rcode : 0); @@ -48,27 +48,27 @@ uint8_t HID::GetReportDescr(uint16_t wIndex, USBReadParser *parser) { //} uint8_t HID::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_HIDOUT, HID_REQUEST_SET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL)); + 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) { - return ( pUsb->ctrlReq(bAddress, ep, bmREQ_HIDIN, HID_REQUEST_GET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL)); + 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) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HIDIN, HID_REQUEST_GET_IDLE, reportID, 0, iface, 0x0001, 0x0001, dataptr, NULL)); + 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) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HIDOUT, HID_REQUEST_SET_IDLE, reportID, duration, iface, 0x0000, 0x0000, NULL, NULL)); + 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) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HIDOUT, HID_REQUEST_SET_PROTOCOL, protocol, 0x00, iface, 0x0000, 0x0000, NULL, NULL)); + 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) { - return ( pUsb->ctrlReq(bAddress, 0, bmREQ_HIDIN, HID_REQUEST_GET_PROTOCOL, 0x00, 0x00, iface, 0x0001, 0x0001, dataptr, NULL)); + 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) { diff --git a/hid.h b/hid.h index a61cfb90..88b8ad3f 100644 --- a/hid.h +++ b/hid.h @@ -60,9 +60,9 @@ e-mail : support@circuitsathome.com #define TAG_LOCAL_USAGEMAX 0x20 /* HID requests */ -#define bmREQ_HIDOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE -#define bmREQ_HIDIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE -#define bmREQ_HIDREPORT USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_INTERFACE +#define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE +#define bmREQ_HID_IN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE +#define bmREQ_HID_REPORT USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_STANDARD|USB_SETUP_RECIPIENT_INTERFACE /* HID constants. Not part of chapter 9 */ /* Class-Specific Requests */ From efb9bb73c5be9c8f3ca3ed52082ddf76979e5a0e Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 2 Sep 2014 01:34:39 -0700 Subject: [PATCH 10/36] Use shift operators for flags --- BTD.h | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/BTD.h b/BTD.h index 33d5e8d7..e0000ee4 100755 --- a/BTD.h +++ b/BTD.h @@ -58,15 +58,15 @@ #define HCI_DISCONNECT_STATE 16 /* HCI event flags*/ -#define HCI_FLAG_CMD_COMPLETE 0x01 -#define HCI_FLAG_CONNECT_COMPLETE 0x02 -#define HCI_FLAG_DISCONNECT_COMPLETE 0x04 -#define HCI_FLAG_REMOTE_NAME_COMPLETE 0x08 -#define HCI_FLAG_INCOMING_REQUEST 0x10 -#define HCI_FLAG_READ_BDADDR 0x20 -#define HCI_FLAG_READ_VERSION 0x40 -#define HCI_FLAG_DEVICE_FOUND 0x80 -#define HCI_FLAG_CONNECT_EVENT 0x100 +#define HCI_FLAG_CMD_COMPLETE (1UL << 0) +#define HCI_FLAG_CONNECT_COMPLETE (1UL << 1) +#define HCI_FLAG_DISCONNECT_COMPLETE (1UL << 2) +#define HCI_FLAG_REMOTE_NAME_COMPLETE (1UL << 3) +#define HCI_FLAG_INCOMING_REQUEST (1UL << 4) +#define HCI_FLAG_READ_BDADDR (1UL << 5) +#define HCI_FLAG_READ_VERSION (1UL << 6) +#define HCI_FLAG_DEVICE_FOUND (1UL << 7) +#define HCI_FLAG_CONNECT_EVENT (1UL << 8) /* Macros for HCI event flag tests */ #define hci_check_flag(flag) (hci_event_flag & (flag)) @@ -131,28 +131,28 @@ #define WII_INIT_MOTION_PLUS_STATE 21 /* L2CAP event flags for HID Control channel */ -#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST 0x00000001 -#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS 0x00000002 -#define L2CAP_FLAG_CONTROL_CONNECTED 0x00000004 -#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE 0x00000008 +#define L2CAP_FLAG_CONNECTION_CONTROL_REQUEST (1UL << 0) +#define L2CAP_FLAG_CONFIG_CONTROL_SUCCESS (1UL << 1) +#define L2CAP_FLAG_CONTROL_CONNECTED (1UL << 2) +#define L2CAP_FLAG_DISCONNECT_CONTROL_RESPONSE (1UL << 3) /* L2CAP event flags for HID Interrupt channel */ -#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST 0x00000010 -#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS 0x00000020 -#define L2CAP_FLAG_INTERRUPT_CONNECTED 0x00000040 -#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE 0x00000080 +#define L2CAP_FLAG_CONNECTION_INTERRUPT_REQUEST (1UL << 4) +#define L2CAP_FLAG_CONFIG_INTERRUPT_SUCCESS (1UL << 5) +#define L2CAP_FLAG_INTERRUPT_CONNECTED (1UL << 6) +#define L2CAP_FLAG_DISCONNECT_INTERRUPT_RESPONSE (1UL << 7) /* L2CAP event flags for SDP channel */ -#define L2CAP_FLAG_CONNECTION_SDP_REQUEST 0x00000100 -#define L2CAP_FLAG_CONFIG_SDP_SUCCESS 0x00000200 -#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST 0x00000400 +#define L2CAP_FLAG_CONNECTION_SDP_REQUEST (1UL << 8) +#define L2CAP_FLAG_CONFIG_SDP_SUCCESS (1UL << 9) +#define L2CAP_FLAG_DISCONNECT_SDP_REQUEST (1UL << 10) /* L2CAP event flags for RFCOMM channel */ -#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST 0x00000800 -#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS 0x00001000 -#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST 0x00002000 +#define L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST (1UL << 11) +#define L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS (1UL << 12) +#define L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST (1UL << 13) -#define L2CAP_FLAG_DISCONNECT_RESPONSE 0x00004000 +#define L2CAP_FLAG_DISCONNECT_RESPONSE (1UL << 14) /* Macros for L2CAP event flag tests */ #define l2cap_check_flag(flag) (l2cap_event_flag & (flag)) From 25c8d87ba2a63a8198492aaec6b49a340fd24d32 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 2 Sep 2014 02:02:17 -0700 Subject: [PATCH 11/36] Added several variables to BluetoothService class Also moved attachOnInit function into BluetoothService class, but this really belong somewhere else --- BTD.cpp | 1 + BTD.h | 44 ++++++++++++++++++++++++++++++++++++---- BTHID.cpp | 2 +- BTHID.h | 60 ++++++++++++++++++++----------------------------------- PS3BT.cpp | 2 +- PS3BT.h | 43 +++++++++++++++------------------------ PS4BT.h | 10 ---------- SPP.cpp | 22 +++++++++++--------- SPP.h | 47 +++++++++++++++++++++++-------------------- Wii.cpp | 2 +- Wii.h | 42 +++++++++++++++----------------------- 11 files changed, 136 insertions(+), 139 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index de83da95..0bc8591f 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -511,6 +511,7 @@ void BTD::HCI_event_task() { if(remote_name[i] == '\0') // End of string break; } + // TODO: Altid sæt '\0' i remote name! hci_set_flag(HCI_FLAG_REMOTE_NAME_COMPLETE); } break; diff --git a/BTD.h b/BTD.h index e0000ee4..37191827 100755 --- a/BTD.h +++ b/BTD.h @@ -205,20 +205,56 @@ #define UHS_ACL_HANDLE_OK(x, y) ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20))) #endif +class BTD; + /** All Bluetooth services should inherit this class. */ class BluetoothService { public: + BluetoothService(BTD *p) : pBtd(p) {}; /** * 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; + + /** + * Used to call your own function when the device is successfully initialized. + * @param funcOnInit Function to call. + */ + void attachOnInit(void (*funcOnInit)(void)) { + pFuncOnInit = funcOnInit; // TODO: This really belong in a class of it's own as it is repeated several times + }; + +protected: + /** + * Called when a device is successfully initialized. + * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. + * This is useful for instance if you want to set the LEDs in a specific way. + */ + virtual void onInit() = 0; + + // TODO: Implement "UHS_ACL_HANDLE_OK" function + + /** Pointer to function called in onInit(). */ + void (*pFuncOnInit)(void); + + /** Pointer to BTD instance. */ + BTD *pBtd; + + /** The HCI Handle for the connection. */ + uint16_t hci_handle; + + /** L2CAP flags of received Bluetooth events. */ + uint32_t l2cap_event_flag; + + /** Identifier for L2CAP commands. */ + uint8_t identifier; }; /** diff --git a/BTHID.cpp b/BTHID.cpp index 01f190a7..3a625b2d 100644 --- a/BTHID.cpp +++ b/BTHID.cpp @@ -21,7 +21,7 @@ //#define PRINTREPORT // Uncomment to print the report send by the HID device BTHID::BTHID(BTD *p, bool pair, const char *pin) : -pBtd(p), // pointer to USB class instance - mandatory +BluetoothService(p), // Pointer to USB class instance - mandatory protocolMode(HID_BOOT_PROTOCOL) { for(uint8_t i = 0; i < NUM_PARSERS; i++) pRptParser[i] = NULL; diff --git a/BTHID.h b/BTHID.h index 2419e58b..799c59a8 100644 --- a/BTHID.h +++ b/BTHID.h @@ -37,15 +37,6 @@ public: BTHID(BTD *p, bool pair = false, const char *pin = "0000"); /** @name BluetoothService implementation */ - /** - * Used to pass acldata to the services. - * @param ACLData Incoming acldata. - */ - virtual void ACLData(uint8_t* ACLData); - /** Used to run part of the state machine. */ - virtual void Run(); - /** Use this to reset the service. */ - virtual void Reset(); /** Used this to disconnect the devices. */ virtual void disconnect(); /**@}*/ @@ -97,15 +88,29 @@ public: pBtd->pairWithHID(); }; - /** - * Used to call your own function when the device is successfully initialized. - * @param funcOnInit Function to call. - */ - void attachOnInit(void (*funcOnInit)(void)) { - pFuncOnInit = funcOnInit; - }; - protected: + /** @name BluetoothService implementation */ + /** + * Used to pass acldata to the services. + * @param ACLData Incoming acldata. + */ + virtual void ACLData(uint8_t* ACLData); + /** Used to run part of the state machine. */ + virtual void Run(); + /** Use this to reset the service. */ + virtual void Reset(); + /** + * Called when a device is successfully initialized. + * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. + * This is useful for instance if you want to set the LEDs in a specific way. + */ + virtual void onInit() { + if(pFuncOnInit) + pFuncOnInit(); // Call the user function + OnInitBTHID(); + }; + /**@}*/ + /** @name Overridable functions */ /** * Used to parse Bluetooth HID data to any class that inherits this class. @@ -125,14 +130,7 @@ protected: } /**@}*/ - /** Pointer to BTD instance */ - BTD *pBtd; - - /** HCI Handle for connection */ - uint16_t hci_handle; - /** L2CAP source CID for HID_Control */ - uint8_t control_scid[2]; /** L2CAP source CID for HID_Interrupt */ @@ -145,18 +143,6 @@ private: void setProtocol(); uint8_t protocolMode; - /** - * Called when a device is successfully initialized. - * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. - * This is useful for instance if you want to set the LEDs in a specific way. - */ - void onInit() { - if(pFuncOnInit) - pFuncOnInit(); // Call the user function - OnInitBTHID(); - }; - void (*pFuncOnInit)(void); // Pointer to function called in onInit() - void L2CAP_task(); // L2CAP state machine bool activeConnection; // Used to indicate if it already has established a connection @@ -164,8 +150,6 @@ private: /* Variables used for L2CAP communication */ uint8_t control_dcid[2]; // L2CAP device CID for HID_Control - Always 0x0070 uint8_t interrupt_dcid[2]; // L2CAP device CID for HID_Interrupt - Always 0x0071 - uint8_t identifier; // Identifier for connection uint8_t l2cap_state; - uint32_t l2cap_event_flag; // l2cap flags of received Bluetooth events }; #endif diff --git a/PS3BT.cpp b/PS3BT.cpp index 38d6c3dc..74928ca7 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -21,7 +21,7 @@ //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers PS3BT::PS3BT(BTD *p, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0) : -pBtd(p) // pointer to USB class instance - mandatory +BluetoothService(p) // Pointer to USB class instance - mandatory { if(pBtd) pBtd->registerServiceClass(this); // Register it as a Bluetooth service diff --git a/PS3BT.h b/PS3BT.h index d07a4577..17b7b0c9 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -41,15 +41,6 @@ public: PS3BT(BTD *pBtd, uint8_t btadr5 = 0, uint8_t btadr4 = 0, uint8_t btadr3 = 0, uint8_t btadr2 = 0, uint8_t btadr1 = 0, uint8_t btadr0 = 0); /** @name BluetoothService implementation */ - /** - * Used to pass acldata to the services. - * @param ACLData Incoming acldata. - */ - virtual void ACLData(uint8_t* ACLData); - /** Used to run part of the state machine. */ - virtual void Run(); - /** Use this to reset the service. */ - virtual void Reset(); /** Used this to disconnect any of the controllers. */ virtual void disconnect(); /**@}*/ @@ -183,14 +174,6 @@ public: uint32_t getLastMessageTime() { return lastMessageTime; }; - - /** - * Used to call your own function when the controller is successfully initialized. - * @param funcOnInit Function to call. - */ - void attachOnInit(void (*funcOnInit)(void)) { - pFuncOnInit = funcOnInit; - }; /**@}*/ /** Variable used to indicate if the normal Playstation controller is successfully connected. */ @@ -200,32 +183,39 @@ public: /** Variable used to indicate if the Navigation controller is successfully connected. */ bool PS3NavigationConnected; -private: - /* Mandatory members */ - BTD *pBtd; - +protected: + /** @name BluetoothService implementation */ + /** + * Used to pass acldata to the services. + * @param ACLData Incoming acldata. + */ + virtual void ACLData(uint8_t* ACLData); + /** Used to run part of the state machine. */ + virtual void Run(); + /** Use this to reset the service. */ + virtual void Reset(); /** * Called when the controller is successfully initialized. * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. * This is useful for instance if you want to set the LEDs in a specific way. */ - void onInit(); - void (*pFuncOnInit)(void); // Pointer to function called in onInit() + virtual void onInit(); + /**@}*/ + +private: void L2CAP_task(); // L2CAP state machine /* Variables filled from HCI event management */ - int16_t hci_handle; uint8_t remote_name[30]; // First 30 chars of remote name bool activeConnection; // Used to indicate if it's already has established a connection /* Variables used by high level L2CAP task */ uint8_t l2cap_state; - uint32_t l2cap_event_flag; // L2CAP flags of received Bluetooth events uint32_t lastMessageTime; // Variable used to store the millis value of the last message. - unsigned long timer; + uint32_t timer; uint32_t ButtonState; uint32_t OldButtonState; @@ -243,7 +233,6 @@ private: uint8_t control_dcid[2]; // 0x0040 uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt uint8_t interrupt_dcid[2]; // 0x0041 - uint8_t identifier; // Identifier for connection /* HID Commands */ void HID_Command(uint8_t* data, uint8_t nbytes); diff --git a/PS4BT.h b/PS4BT.h index ff3168a3..6be6463e 100644 --- a/PS4BT.h +++ b/PS4BT.h @@ -46,14 +46,6 @@ public: return BTHID::connected; }; - /** - * Used to call your own function when the device is successfully initialized. - * @param funcOnInit Function to call. - */ - void attachOnInit(void (*funcOnInit)(void)) { - pFuncOnInit = funcOnInit; - }; - protected: /** @name BTHID implementation */ /** @@ -125,7 +117,5 @@ private: void HID_Command(uint8_t *data, uint8_t nbytes) { pBtd->L2CAP_Command(hci_handle, data, nbytes, control_scid[0], control_scid[1]); }; - - void (*pFuncOnInit)(void); // Pointer to function called in onInit() }; #endif \ No newline at end of file diff --git a/SPP.cpp b/SPP.cpp index 562a68ca..3262a3e3 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -43,7 +43,7 @@ const uint8_t rfcomm_crc_table[256] PROGMEM = {/* reversed, 8-bit, poly=0x07 */ }; SPP::SPP(BTD *p, const char* name, const char* pin) : -pBtd(p) // Pointer to BTD class instance - mandatory +BluetoothService(p) // Pointer to BTD class instance - mandatory { if(pBtd) pBtd->registerServiceClass(this); // Register it as a Bluetooth service @@ -69,6 +69,7 @@ void SPP::Reset() { l2cap_rfcomm_state = L2CAP_RFCOMM_WAIT; l2cap_event_flag = 0; sppIndex = 0; + creditSent = false; } void SPP::disconnect() { @@ -397,10 +398,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"), 0x80); #endif - waitForLastCommand = false; - creditSent = false; - connected = true; // The RFCOMM channel is now established - sppIndex = 0; + onInit(); } #ifdef EXTRADEBUG else if(rfcommChannelType != RFCOMM_DISC) { @@ -430,14 +428,20 @@ void SPP::Run() { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80); #endif - creditSent = false; - waitForLastCommand = false; - connected = true; // The RFCOMM channel is now established - sppIndex = 0; + onInit(); } send(); // Send all bytes currently in the buffer } +void SPP::onInit() { + creditSent = false; + waitForLastCommand = false; + connected = true; // The RFCOMM channel is now established + sppIndex = 0; + if(pFuncOnInit) + pFuncOnInit(); // Call the user function +}; + void SPP::SDP_task() { switch(l2cap_sdp_state) { case L2CAP_SDP_WAIT: diff --git a/SPP.h b/SPP.h index d9f6761c..b20e43e5 100644 --- a/SPP.h +++ b/SPP.h @@ -68,6 +68,11 @@ public: */ SPP(BTD *p, const char *name = "Arduino", const char *pin = "0000"); + /** @name BluetoothService implementation */ + /** Used this to disconnect the virtual serial port. */ + virtual void disconnect(); + /**@}*/ + /** * Used to provide Boolean tests for the class. * @return Return true if SPP communication is connected. @@ -78,20 +83,6 @@ public: /** Variable used to indicate if the connection is established. */ bool connected; - /** @name BluetoothService implementation */ - /** - * Used to pass acldata to the services. - * @param ACLData Incoming acldata. - */ - virtual void ACLData(uint8_t* ACLData); - /** Used to establish the connection automatically. */ - virtual void Run(); - /** Use this to reset the service. */ - virtual void Reset(); - /** Used this to disconnect the virtual serial port. */ - virtual void disconnect(); - /**@}*/ - /** @name Serial port profile (SPP) Print functions */ /** * Get number of bytes waiting to be read. @@ -154,20 +145,33 @@ public: void send(void); /**@}*/ -private: - /* Bluetooth dongle library pointer */ - BTD *pBtd; +protected: + /** @name BluetoothService implementation */ + /** + * Used to pass acldata to the services. + * @param ACLData Incoming acldata. + */ + virtual void ACLData(uint8_t* ACLData); + /** Used to establish the connection automatically. */ + virtual void Run(); + /** Use this to reset the service. */ + virtual void Reset(); + /** + * Called when a device is successfully initialized. + * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. + * This is useful for instance if you want to set the LEDs in a specific way. + */ + virtual void onInit(); + /**@}*/ +private: /* Set true when a channel is created */ bool SDPConnected; bool RFCOMMConnected; - uint16_t hci_handle; // The HCI Handle for the connection - /* Variables used by L2CAP state machines */ uint8_t l2cap_sdp_state; uint8_t l2cap_rfcomm_state; - uint32_t l2cap_event_flag; // l2cap flags of received Bluetooth events uint8_t l2capoutbuf[BULK_MAXPKTSIZE]; // General purpose buffer for l2cap out data uint8_t rfcommbuf[10]; // Buffer for RFCOMM Commands @@ -177,7 +181,6 @@ private: uint8_t sdp_dcid[2]; // 0x0050 uint8_t rfcomm_scid[2]; // L2CAP source CID for RFCOMM uint8_t rfcomm_dcid[2]; // 0x0051 - uint8_t identifier; // Identifier for command /* RFCOMM Variables */ uint8_t rfcommChannel; @@ -187,7 +190,7 @@ private: uint8_t rfcommChannelType; uint8_t rfcommPfBit; - unsigned long timer; + uint32_t timer; bool waitForLastCommand; bool creditSent; diff --git a/Wii.cpp b/Wii.cpp index 8106666b..25a760f7 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -83,7 +83,7 @@ const uint32_t WII_PROCONTROLLER_BUTTONS[] PROGMEM = { }; WII::WII(BTD *p, bool pair) : -pBtd(p) // pointer to USB class instance - mandatory +BluetoothService(p) // Pointer to USB class instance - mandatory { if(pBtd) pBtd->registerServiceClass(this); // Register it as a Bluetooth service diff --git a/Wii.h b/Wii.h index 848dec93..ed500dec 100755 --- a/Wii.h +++ b/Wii.h @@ -55,15 +55,6 @@ public: WII(BTD *p, bool pair = false); /** @name BluetoothService implementation */ - /** - * Used to pass acldata to the services. - * @param ACLData Incoming acldata. - */ - virtual void ACLData(uint8_t* ACLData); - /** Used to run part of the state machine. */ - virtual void Run(); - /** Use this to reset the service. */ - virtual void Reset(); /** Used this to disconnect any of the controllers. */ virtual void disconnect(); /**@}*/ @@ -189,14 +180,6 @@ public: uint8_t getWiiState() { return wiiState; }; - - /** - * Used to call your own function when the controller is successfully initialized. - * @param funcOnInit Function to call. - */ - void attachOnInit(void (*funcOnInit)(void)) { - pFuncOnInit = funcOnInit; - }; /**@}*/ /**@{*/ @@ -392,26 +375,34 @@ public: /**@}*/ #endif -private: - BTD *pBtd; // Pointer to BTD instance - +protected: + /** @name BluetoothService implementation */ + /** + * Used to pass acldata to the services. + * @param ACLData Incoming acldata. + */ + virtual void ACLData(uint8_t* ACLData); + /** Used to run part of the state machine. */ + virtual void Run(); + /** Use this to reset the service. */ + virtual void Reset(); /** * Called when the controller is successfully initialized. * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. * This is useful for instance if you want to set the LEDs in a specific way. */ - void onInit(); - void (*pFuncOnInit)(void); // Pointer to function called in onInit() + virtual void onInit(); + /**@}*/ + +private: void L2CAP_task(); // L2CAP state machine /* Variables filled from HCI event management */ - uint16_t hci_handle; bool activeConnection; // Used to indicate if it's already has established a connection /* Variables used by high level L2CAP task */ uint8_t l2cap_state; - uint32_t l2cap_event_flag; // L2CAP flags of received Bluetooth events uint8_t wii_event_flag; // Used for Wii flags uint32_t ButtonState; @@ -432,7 +423,6 @@ private: uint8_t control_dcid[2]; // 0x0060 uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt uint8_t interrupt_dcid[2]; // 0x0061 - uint8_t identifier; // Identifier for connection /* HID Commands */ void HID_Command(uint8_t* data, uint8_t nbytes); @@ -457,7 +447,7 @@ private: bool activateNunchuck; bool motionValuesReset; // This bool is true when the gyro values has been reset - unsigned long timer; + uint32_t timer; uint8_t wiiState; // Stores the value in 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) uint8_t batteryLevel; From 106aff64118dc83a89bb1974fe6ff83ee727ebef Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 9 Sep 2014 16:32:46 -0700 Subject: [PATCH 12/36] Call registerBluetoothService in BluetoothService constructor I needed to move the BluetoothService class down after the BTD class in order for it to work --- BTD.cpp | 6 +++ BTD.h | 115 ++++++++++++++++++++++++++---------------------------- BTHID.cpp | 3 -- PS3BT.cpp | 3 -- SPP.cpp | 3 -- Wii.cpp | 7 +--- 6 files changed, 64 insertions(+), 73 deletions(-) diff --git a/BTD.cpp b/BTD.cpp index 0bc8591f..42cf3d62 100755 --- a/BTD.cpp +++ b/BTD.cpp @@ -380,6 +380,12 @@ uint8_t BTD::Poll() { return 0; } +void BTD::disconnect() { + for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) + if(btService[i]) + btService[i]->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 diff --git a/BTD.h b/BTD.h index 37191827..806bb63e 100755 --- a/BTD.h +++ b/BTD.h @@ -204,58 +204,7 @@ */ #define UHS_ACL_HANDLE_OK(x, y) ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20))) #endif - -class BTD; - -/** All Bluetooth services should inherit this class. */ -class BluetoothService { -public: - BluetoothService(BTD *p) : pBtd(p) {}; - /** - * Used to pass acldata to the Bluetooth service. - * @param ACLData Pointer to the incoming acldata. - */ - virtual void ACLData(uint8_t* ACLData) = 0; - /** Used to run the different state machines in the Bluetooth service. */ - virtual void Run() = 0; - /** Used to reset the Bluetooth service. */ - virtual void Reset() = 0; - /** Used to disconnect both the L2CAP Channel and the HCI Connection for the Bluetooth service. */ - virtual void disconnect() = 0; - - /** - * Used to call your own function when the device is successfully initialized. - * @param funcOnInit Function to call. - */ - void attachOnInit(void (*funcOnInit)(void)) { - pFuncOnInit = funcOnInit; // TODO: This really belong in a class of it's own as it is repeated several times - }; - -protected: - /** - * Called when a device is successfully initialized. - * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. - * This is useful for instance if you want to set the LEDs in a specific way. - */ - virtual void onInit() = 0; - - // TODO: Implement "UHS_ACL_HANDLE_OK" function - - /** Pointer to function called in onInit(). */ - void (*pFuncOnInit)(void); - - /** Pointer to BTD instance. */ - BTD *pBtd; - - /** The HCI Handle for the connection. */ - uint16_t hci_handle; - - /** L2CAP flags of received Bluetooth events. */ - uint32_t l2cap_event_flag; - - /** Identifier for L2CAP commands. */ - uint8_t identifier; -}; +class BluetoothService; /** * The Bluetooth Dongle class will take care of all the USB communication @@ -353,25 +302,21 @@ public: /**@}*/ /** Disconnects both the L2CAP Channel and the HCI Connection for all Bluetooth services. */ - void disconnect() { - for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) - if(btService[i]) - btService[i]->disconnect(); - }; + void disconnect(); /** * Register Bluetooth dongle members/services. * @param pService Pointer to BluetoothService class instance. * @return The service ID on success or -1 on fail. */ - int8_t registerServiceClass(BluetoothService *pService) { + int8_t registerBluetoothService(BluetoothService *pService) { for(uint8_t i = 0; i < BTD_NUM_SERVICES; i++) { if(!btService[i]) { btService[i] = pService; return i; // Return ID } } - return -1; // ErrorregisterServiceClass + return -1; // Error registering BluetoothService }; /** @name HCI Commands */ @@ -628,4 +573,56 @@ private: void setBdaddr(uint8_t* BDADDR); void setMoveBdaddr(uint8_t* BDADDR); }; + +/** All Bluetooth services should inherit this class. */ +class BluetoothService { +public: + BluetoothService(BTD *p) : pBtd(p) { + if(pBtd) + pBtd->registerBluetoothService(this); // Register it as a Bluetooth service + }; + /** + * Used to pass acldata to the Bluetooth service. + * @param ACLData Pointer to the incoming acldata. + */ + virtual void ACLData(uint8_t* ACLData) = 0; + /** Used to run the different state machines in the Bluetooth service. */ + virtual void Run() = 0; + /** Used to reset the Bluetooth service. */ + virtual void Reset() = 0; + /** Used to disconnect both the L2CAP Channel and the HCI Connection for the Bluetooth service. */ + virtual void disconnect() = 0; + + /** + * Used to call your own function when the device is successfully initialized. + * @param funcOnInit Function to call. + */ + void attachOnInit(void (*funcOnInit)(void)) { + pFuncOnInit = funcOnInit; // TODO: This really belong in a class of it's own as it is repeated several times + }; + +protected: + /** + * Called when a device is successfully initialized. + * Use attachOnInit(void (*funcOnInit)(void)) to call your own function. + * This is useful for instance if you want to set the LEDs in a specific way. + */ + virtual void onInit() = 0; + + /** Pointer to function called in onInit(). */ + void (*pFuncOnInit)(void); + + /** Pointer to BTD instance. */ + BTD *pBtd; + + /** The HCI Handle for the connection. */ + uint16_t hci_handle; + + /** L2CAP flags of received Bluetooth events. */ + uint32_t l2cap_event_flag; + + /** Identifier for L2CAP commands. */ + uint8_t identifier; +}; + #endif diff --git a/BTHID.cpp b/BTHID.cpp index 3a625b2d..e5a86b47 100644 --- a/BTHID.cpp +++ b/BTHID.cpp @@ -26,9 +26,6 @@ protocolMode(HID_BOOT_PROTOCOL) { for(uint8_t i = 0; i < NUM_PARSERS; i++) pRptParser[i] = NULL; - if(pBtd) - pBtd->registerServiceClass(this); // Register it as a Bluetooth service - pBtd->pairWithHIDDevice = pair; pBtd->btdPin = pin; diff --git a/PS3BT.cpp b/PS3BT.cpp index 74928ca7..73e2c1e6 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -23,9 +23,6 @@ PS3BT::PS3BT(BTD *p, uint8_t btadr5, uint8_t btadr4, uint8_t btadr3, uint8_t btadr2, uint8_t btadr1, uint8_t btadr0) : BluetoothService(p) // Pointer to USB class instance - mandatory { - if(pBtd) - pBtd->registerServiceClass(this); // Register it as a Bluetooth service - pBtd->my_bdaddr[5] = btadr5; // Change to your dongle's Bluetooth address instead pBtd->my_bdaddr[4] = btadr4; pBtd->my_bdaddr[3] = btadr3; diff --git a/SPP.cpp b/SPP.cpp index 3262a3e3..cd5072da 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -45,9 +45,6 @@ const uint8_t rfcomm_crc_table[256] PROGMEM = {/* reversed, 8-bit, poly=0x07 */ SPP::SPP(BTD *p, const char* name, const char* pin) : BluetoothService(p) // Pointer to BTD class instance - mandatory { - if(pBtd) - pBtd->registerServiceClass(this); // Register it as a Bluetooth service - pBtd->btdName = name; pBtd->btdPin = pin; diff --git a/Wii.cpp b/Wii.cpp index 25a760f7..742a67b5 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -85,17 +85,14 @@ const uint32_t WII_PROCONTROLLER_BUTTONS[] PROGMEM = { WII::WII(BTD *p, bool pair) : BluetoothService(p) // Pointer to USB class instance - mandatory { - if(pBtd) - pBtd->registerServiceClass(this); // Register it as a Bluetooth service - pBtd->pairWithWii = pair; HIDBuffer[0] = 0xA2; // HID BT DATA_request (0xA0) | Report Type (Output 0x02) /* Set device cid for the control and intterrupt channelse - LSB */ - control_dcid[0] = 0x60; //0x0060 + control_dcid[0] = 0x60; // 0x0060 control_dcid[1] = 0x00; - interrupt_dcid[0] = 0x61; //0x0061 + interrupt_dcid[0] = 0x61; // 0x0061 interrupt_dcid[1] = 0x00; Reset(); From 285b21cdbc50edc540212fd7d8f3ac091e086c40 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 9 Sep 2014 16:38:42 -0700 Subject: [PATCH 13/36] Check HCI Handle using function in BluetoothService class --- BTD.h | 20 +++++--------------- BTHID.cpp | 4 ++-- PS3BT.cpp | 6 +++--- SPP.cpp | 6 +++--- Wii.cpp | 6 +++--- 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/BTD.h b/BTD.h index 806bb63e..37afb2ec 100755 --- a/BTD.h +++ b/BTD.h @@ -189,21 +189,6 @@ #define PAIR 1 -/* acl_handle_ok or it's a new connection */ -#if 0 -#define UHS_ACL_HANDLE_OK(x, y) ((uint16_t)(x[0]) | (uint16_t)(x[1] << 8)) == (y | 0x2000U) -#else -/* - * Better implementation. - * o One place for this code, it is reused four times in the source. - * Perhaps it is better as a function. - * o This should be faster since the && operation can early exit, this means - * the shift would only be performed if the first byte matches. - * o Casting is eliminated. - * o How does this compare in code size? No difference. It is a free optimization. - */ -#define UHS_ACL_HANDLE_OK(x, y) ((x[0] == (y & 0xff)) && (x[1] == ((y >> 8) | 0x20))) -#endif class BluetoothService; /** @@ -609,6 +594,11 @@ protected: */ virtual void onInit() = 0; + /** Used to check if the incoming L2CAP data matches the HCI Handle */ + bool checkHciHandle(uint8_t *buf, uint16_t handle) { + return (buf[0] == (handle & 0xFF)) && (buf[1] == ((handle >> 8) | 0x20)); + } + /** Pointer to function called in onInit(). */ void (*pFuncOnInit)(void); diff --git a/BTHID.cpp b/BTHID.cpp index e5a86b47..bfa9202c 100644 --- a/BTHID.cpp +++ b/BTHID.cpp @@ -65,8 +65,8 @@ void BTHID::ACLData(uint8_t* l2capinbuf) { } } } - //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection - if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok or it's a new connection + + if(checkHciHandle(l2capinbuf, hci_handle)) { // acl_handle_ok if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { #ifdef DEBUG_USB_HOST diff --git a/PS3BT.cpp b/PS3BT.cpp index 73e2c1e6..fbd4e5f0 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -241,10 +241,10 @@ void PS3BT::ACLData(uint8_t* ACLData) { } } } - //if((ACLData[0] | (uint16_t)ACLData[1] << 8) == (hci_handle | 0x2000U)) { //acl_handle_ok - if(UHS_ACL_HANDLE_OK(ACLData, hci_handle)) { //acl_handle_ok + + if(checkHciHandle(ACLData, hci_handle)) { // acl_handle_ok memcpy(l2capinbuf, ACLData, BULK_MAXPKTSIZE); - if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U + if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); diff --git a/SPP.cpp b/SPP.cpp index cd5072da..0f4ee5e9 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -95,9 +95,9 @@ void SPP::ACLData(uint8_t* l2capinbuf) { } } } - //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok - if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok - if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U + + if(checkHciHandle(l2capinbuf, hci_handle)) { // acl_handle_ok + if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); diff --git a/Wii.cpp b/Wii.cpp index 742a67b5..008e5329 100755 --- a/Wii.cpp +++ b/Wii.cpp @@ -142,9 +142,9 @@ void WII::ACLData(uint8_t* l2capinbuf) { } } } - //if((l2capinbuf[0] | (uint16_t)l2capinbuf[1] << 8) == (hci_handle | 0x2000U)) { // acl_handle_ok or it's a new connection - if(UHS_ACL_HANDLE_OK(l2capinbuf, hci_handle)) { // acl_handle_ok or it's a new connection - if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { //l2cap_control - Channel ID for ACL-U + + if(checkHciHandle(l2capinbuf, hci_handle)) { // acl_handle_ok + if((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001U) { // l2cap_control - Channel ID for ACL-U if(l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); From c5c761aec5e708cd1918d91eb634b8e0658aa0c6 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 9 Sep 2014 16:39:57 -0700 Subject: [PATCH 14/36] Reduced code size in PS3BT by removing some unnecessary variables --- PS3BT.cpp | 19 +++++++++---------- PS3BT.h | 6 ++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/PS3BT.cpp b/PS3BT.cpp index fbd4e5f0..235092e0 100644 --- a/PS3BT.cpp +++ b/PS3BT.cpp @@ -229,8 +229,7 @@ void PS3BT::ACLData(uint8_t* ACLData) { activeConnection = true; hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection l2cap_state = L2CAP_WAIT; - for(uint8_t i = 0; i < 30; i++) - remote_name[i] = pBtd->remote_name[i]; // Store the remote name for the connection + remote_name_first = pBtd->remote_name[0]; // Store the first letter in remote name for the connection #ifdef DEBUG_USB_HOST if(pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80); @@ -416,7 +415,7 @@ void PS3BT::L2CAP_task() { #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80); #endif - if(remote_name[0] == 'M') { // First letter in Motion Controller ('M') + if(remote_name_first == 'M') { // First letter in Motion Controller ('M') memset(l2capinbuf, 0, BULK_MAXPKTSIZE); // Reset l2cap in buffer as it sometimes read it as a button has been pressed l2cap_state = TURN_ON_LED; } else @@ -467,18 +466,18 @@ void PS3BT::Run() { case TURN_ON_LED: if(millis() - timer > 1000) { // loop 1 second before sending the command - if(remote_name[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P') + 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); #endif PS3Connected = true; - } else if(remote_name[0] == 'N') { // First letter in Navigation Controller ('N') + } else if(remote_name_first == 'N') { // First letter in Navigation Controller ('N') #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80); #endif PS3NavigationConnected = true; - } else if(remote_name[0] == 'M') { // First letter in Motion Controller ('M') - timerBulbRumble = millis(); + } else if(remote_name_first == 'M') { // First letter in Motion Controller ('M') + timer = millis(); #ifdef DEBUG_USB_HOST Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80); #endif @@ -494,10 +493,10 @@ void PS3BT::Run() { break; case L2CAP_DONE: - if(PS3MoveConnected) { // The Bulb and rumble values, has to be send at aproximatly every 5th second for it to stay on - if(millis() - timerBulbRumble > 4000) { // Send at least every 4th second + 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 HIDMove_Command(HIDMoveBuffer, HID_BUFFERSIZE); // The Bulb and rumble values, has to be written again and again, for it to stay turned on - timerBulbRumble = millis(); + timer = millis(); } } break; diff --git a/PS3BT.h b/PS3BT.h index 17b7b0c9..faec2ca1 100644 --- a/PS3BT.h +++ b/PS3BT.h @@ -207,7 +207,7 @@ private: void L2CAP_task(); // L2CAP state machine /* Variables filled from HCI event management */ - uint8_t remote_name[30]; // First 30 chars of remote name + char remote_name_first; // First letter in remote name bool activeConnection; // Used to indicate if it's already has established a connection /* Variables used by high level L2CAP task */ @@ -215,14 +215,12 @@ private: uint32_t lastMessageTime; // Variable used to store the millis value of the last message. - uint32_t timer; - uint32_t ButtonState; uint32_t OldButtonState; uint32_t ButtonClickState; + uint32_t timer; // Timer used to limit time between messages and also used to continuously set PS3 Move controller Bulb and rumble values uint32_t timerHID; // Timer used see if there has to be a delay before a new HID command - uint32_t timerBulbRumble; // used to continuously set PS3 Move controller Bulb and rumble values uint8_t l2capinbuf[BULK_MAXPKTSIZE]; // General purpose buffer for L2CAP in data uint8_t HIDBuffer[HID_BUFFERSIZE]; // Used to store HID commands From 961bf1c4aea41db27085251ce4e67f8f1fb34714 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Wed, 10 Sep 2014 00:27:55 -0700 Subject: [PATCH 15/36] 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 d35bb955..1edd5f46 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit d35bb955e3818f0c14e47c8a1998003da8dc1b5a +Subproject commit 1edd5f46188a6c4b68d6f9120fa72359a12e38f1 diff --git a/examples/testusbhostFAT/RTClib b/examples/testusbhostFAT/RTClib index 7fd6a306..b119b97e 160000 --- a/examples/testusbhostFAT/RTClib +++ b/examples/testusbhostFAT/RTClib @@ -1 +1 @@ -Subproject commit 7fd6a306ca53d08bf53b2bbfc1b80eb056f2c55b +Subproject commit b119b97e1484a08aebcf24e070113d78c82fb023 diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index 0b8e3076..72b5bf46 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit 0b8e3076b5a072251e01cfc6e6333b364d4e71e7 +Subproject commit 72b5bf467a1c2479ba7354ee4d864e382c167425 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index 2bf8f633..3b5455a2 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit 2bf8f633e7f9bc5a7bf4c00f3f45c7b79484198e +Subproject commit 3b5455a20526208ad84215dcb40a51c8e000b507 From 2ee76e29232c0077806eec37d1f7ca240210a1e3 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Wed, 10 Sep 2014 01:45:17 -0700 Subject: [PATCH 16/36] Fix include --- max_LCD.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/max_LCD.h b/max_LCD.h index 48946a1f..dc5e028a 100644 --- a/max_LCD.h +++ b/max_LCD.h @@ -22,7 +22,7 @@ e-mail : support@circuitsathome.com #define _Max_LCD_h_ #include "Usb.h" -#include "Print.h" +#include // commands #define LCD_CLEARDISPLAY 0x01 From 64e3f92700ed6bbd739f5ab7a75f0695cd950046 Mon Sep 17 00:00:00 2001 From: Oleg Mazurov Date: Mon, 22 Sep 2014 17:03:16 -0600 Subject: [PATCH 17/36] gh sync --- examples/testusbhostFAT/Arduino_Makefile_master | 2 +- examples/testusbhostFAT/generic_storage | 2 +- examples/testusbhostFAT/xmem2 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/testusbhostFAT/Arduino_Makefile_master b/examples/testusbhostFAT/Arduino_Makefile_master index 1edd5f46..f379bae0 160000 --- a/examples/testusbhostFAT/Arduino_Makefile_master +++ b/examples/testusbhostFAT/Arduino_Makefile_master @@ -1 +1 @@ -Subproject commit 1edd5f46188a6c4b68d6f9120fa72359a12e38f1 +Subproject commit f379bae02aa3d9c3da558ba2041558b88db95bbb diff --git a/examples/testusbhostFAT/generic_storage b/examples/testusbhostFAT/generic_storage index 72b5bf46..071b65b9 160000 --- a/examples/testusbhostFAT/generic_storage +++ b/examples/testusbhostFAT/generic_storage @@ -1 +1 @@ -Subproject commit 72b5bf467a1c2479ba7354ee4d864e382c167425 +Subproject commit 071b65b923b2656bb1e1b622de5272b4ed9a4996 diff --git a/examples/testusbhostFAT/xmem2 b/examples/testusbhostFAT/xmem2 index 3b5455a2..8bcf5f90 160000 --- a/examples/testusbhostFAT/xmem2 +++ b/examples/testusbhostFAT/xmem2 @@ -1 +1 @@ -Subproject commit 3b5455a20526208ad84215dcb40a51c8e000b507 +Subproject commit 8bcf5f90f8bd967378b6eeebd7fd943f125fbc18 From 4ccbea7f36c8dc562d3607a4218db390e6fbe55b Mon Sep 17 00:00:00 2001 From: Oleg Mazurov Date: Mon, 22 Sep 2014 17:48:40 -0600 Subject: [PATCH 18/36] Send Report added to hiduniversal --- hiduniversal.cpp | 6 ++++++ hiduniversal.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/hiduniversal.cpp b/hiduniversal.cpp index e7a65e39..3cca8cfb 100644 --- a/hiduniversal.cpp +++ b/hiduniversal.cpp @@ -418,3 +418,9 @@ uint8_t HIDUniversal::Poll() { } return rcode; } + + +//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/hiduniversal.h b/hiduniversal.h index 3e090aa7..5fd7e6b7 100644 --- a/hiduniversal.h +++ b/hiduniversal.h @@ -100,6 +100,9 @@ public: // UsbConfigXtracter implementation virtual 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); }; #endif // __HIDUNIVERSAL_H__ From 37d87903fa9dd1e66936b7a5e3d4e2e4cbb6404e Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Mon, 29 Sep 2014 16:50:02 -0700 Subject: [PATCH 19/36] Updated USBFTDILoopback example to compile after 2224dd96cbf64f1184b3d74649e0a5679f398c59 --- examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino index 26b5624d..49c8b483 100644 --- a/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino +++ b/examples/ftdi/USBFTDILoopback/USBFTDILoopback.ino @@ -11,6 +11,7 @@ class FTDIAsync : public FTDIAsyncOper { public: virtual uint8_t OnInit(FTDI *pftdi); + virtual uint8_t OnRelease(FTDI *pftdi) {}; }; uint8_t FTDIAsync::OnInit(FTDI *pftdi) From 6e31789f7f4a8a5eeb645a9cc2dcb9b99c9cd38f Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Wed, 1 Oct 2014 23:26:56 +0300 Subject: [PATCH 20/36] PlatformIO-based manifest file Web: http://platformio.ikravets.com/#!/lib/show/Arduino-USBHostShield20 Docs: http://docs.platformio.ikravets.com/en/latest/librarymanager/index.html --- library.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 library.json diff --git a/library.json b/library.json new file mode 100644 index 00000000..50a25857 --- /dev/null +++ b/library.json @@ -0,0 +1,15 @@ +{ + "name": "Arduino-USBHostShield20", + "keywords": "usb, hid", + "description": "Revision 2.0 of MAX3421E-based USB Host Shield Library for AVR's", + "repository": + { + "type": "git", + "url": "https://github.com/felis/USB_Host_Shield_2.0.git" + }, + "examples": + [ + "examples/*/*.ino", + "examples/*/*/*.ino" + ] +} From 8222d047f57149850386290b40d61d54344dc46d Mon Sep 17 00:00:00 2001 From: David Kemp Date: Thu, 23 Oct 2014 21:51:48 +1100 Subject: [PATCH 21/36] Make the right shift key work in OemToAscii (only the left shift key was working) --- hidboot.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hidboot.cpp b/hidboot.cpp index c32443bb..09290a4f 100644 --- a/hidboot.cpp +++ b/hidboot.cpp @@ -189,8 +189,8 @@ uint8_t KeyboardReportParser::OemToAscii(uint8_t mod, uint8_t key) { // [a-z] if (VALUE_WITHIN(key, 0x04, 0x1d)) { // Upper case letters - if ((kbdLockingKeys.kbdLeds.bmCapsLock == 0 && (mod & 2)) || - (kbdLockingKeys.kbdLeds.bmCapsLock == 1 && (mod & 2) == 0)) + if ((kbdLockingKeys.kbdLeds.bmCapsLock == 0 && shift) || + (kbdLockingKeys.kbdLeds.bmCapsLock == 1 && shift == 0)) return (key - 4 + 'A'); // Lower case letters From 65e85678c0421676c6fe44ad5e5ab7188b989879 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Thu, 23 Oct 2014 19:08:04 +0300 Subject: [PATCH 22/36] Avoid trademark issues with library name Added authors, frameworks and platforms fields Updated Library Registry: http://platformio.ikravets.com/#!/lib/show/59/USB-Host-Shield-20 --- library.json | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/library.json b/library.json index 50a25857..77f75346 100644 --- a/library.json +++ b/library.json @@ -1,7 +1,29 @@ { - "name": "Arduino-USBHostShield20", + "name": "USB-Host-Shield-20", "keywords": "usb, hid", - "description": "Revision 2.0 of MAX3421E-based USB Host Shield Library for AVR's", + "description": "Revision 2.0 of MAX3421E-based USB Host Shield Library", + "authors": + [ + { + "name": "Oleg Mazurov", + "email": "mazurov@circuitsathome.com", + "url": "http://www.circuitsathome.com", + "maintainer": true + }, + { + "name": "Alexei Glushchenko", + "email": "alex-gl@mail.ru" + }, + { + "name": "Kristian Lauszus", + "email": "kristianl@tkjelectronics.com", + "url": "http://tkjelectronics.com" + }, + { + "name": "Andrew Kroll", + "email": "xxxajk@gmail.com" + } + ], "repository": { "type": "git", @@ -11,5 +33,7 @@ [ "examples/*/*.ino", "examples/*/*/*.ino" - ] + ], + "frameworks": "arduino", + "platforms": "atmelavr" } From 6b096bf6ae3eaf2317ff78a5c3126d8195007a89 Mon Sep 17 00:00:00 2001 From: Lauszus Date: Sun, 26 Oct 2014 13:48:19 -0700 Subject: [PATCH 23/36] Added more keywords to library.json and set maintainer field for me and Andrew --- library.json | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/library.json b/library.json index 77f75346..b48643ec 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "USB-Host-Shield-20", - "keywords": "usb, hid", + "keywords": "usb, host, ftdi, adk, acm, pl2303, hid, bluetooth, spp, ps3, ps4, buzz, xbox, wii, mass storage", "description": "Revision 2.0 of MAX3421E-based USB Host Shield Library", "authors": [ @@ -17,12 +17,14 @@ { "name": "Kristian Lauszus", "email": "kristianl@tkjelectronics.com", - "url": "http://tkjelectronics.com" + "url": "http://tkjelectronics.com", + "maintainer": true }, { "name": "Andrew Kroll", - "email": "xxxajk@gmail.com" - } + "email": "xxxajk@gmail.com", + "maintainer": true + } ], "repository": { From 9806b7073b83afeec1fdc68be73e47c6185b945e Mon Sep 17 00:00:00 2001 From: Lauszus Date: Sun, 26 Oct 2014 14:33:45 -0700 Subject: [PATCH 24/36] Added teensy and atmelsam platforms --- library.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library.json b/library.json index b48643ec..6f7c5753 100644 --- a/library.json +++ b/library.json @@ -37,5 +37,10 @@ "examples/*/*/*.ino" ], "frameworks": "arduino", - "platforms": "atmelavr" + "platforms": + [ + "atmelavr", + "teensy", + "atmelsam" + ] } From 46dd720b8f6dde5d36c0635362e22c2251c70a13 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Wed, 29 Oct 2014 14:28:45 -0700 Subject: [PATCH 25/36] Added a link to Adafruit's library guide --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 58599d42..1a3163b3 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ Now quit the Arduino IDE and reopen it. Now you should be able to go open all the examples codes by navigating to "File>Examples>USB\_Host\_Shield\_20" and then select the example you will like to open. -For more information visit the following site: . +For more information visit the following sites: and . # How to use the library From d5e900f8339979bfecbbd8dbd5380815087dd142 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Fri, 31 Oct 2014 15:57:39 -0700 Subject: [PATCH 26/36] Added isReady function to HIDBoot Fixes #103 --- hidboot.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hidboot.h b/hidboot.h index b35df7cb..c5a46891 100644 --- a/hidboot.h +++ b/hidboot.h @@ -212,6 +212,10 @@ public: return bAddress; }; + virtual bool isReady() { + return bPollEnable; + }; + // UsbConfigXtracter implementation virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); From eb424a07acd3a5860576a0b3eefd2993c8422b93 Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Fri, 21 Nov 2014 22:45:57 +0100 Subject: [PATCH 27/36] nRF51822 Pins Creating pins for the RBL nRF51822 Board --- avrpins.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/avrpins.h b/avrpins.h index da80349d..262bb6e2 100644 --- a/avrpins.h +++ b/avrpins.h @@ -961,6 +961,58 @@ MAKE_PIN(P78, PIOB, PIO_PB23); // Unconnected #undef MAKE_PIN +#elif defined(RBL_NRF51822) + +#define MAKE_PIN(className, pin) \ +class className { \ +public: \ + static void Set() { \ + nrf_gpio_pin_set(pin); \ + } \ + static void Clear() { \ + nrf_gpio_pin_clear(pin); \ + } \ + static void SetDirRead() { \ + nrf_gpio_cfg_input(pin, NRF_GPIO_PIN_NOPULL); \ + } \ + static void SetDirWrite() { \ + nrf_gpio_cfg_output(pin); \ + } \ + static uint8_t IsSet() { \ + return (uint8_t)nrf_gpio_pin_read(pin); \ + } \ +}; + +// See: pin_transform.c in RBL nRF51822 SDK +MAKE_PIN(P0, Pin_nRF51822_to_Arduino(D0)); +MAKE_PIN(P1, Pin_nRF51822_to_Arduino(D1)); +MAKE_PIN(P2, Pin_nRF51822_to_Arduino(D2)); +MAKE_PIN(P3, Pin_nRF51822_to_Arduino(D3)); +MAKE_PIN(P4, Pin_nRF51822_to_Arduino(D4)); +MAKE_PIN(P5, Pin_nRF51822_to_Arduino(D5)); +MAKE_PIN(P6, Pin_nRF51822_to_Arduino(D6)); +MAKE_PIN(P7, Pin_nRF51822_to_Arduino(D7)); +MAKE_PIN(P8, Pin_nRF51822_to_Arduino(D8)); +MAKE_PIN(P9, Pin_nRF51822_to_Arduino(D9)); // INT +MAKE_PIN(P10, Pin_nRF51822_to_Arduino(D10)); // SS +MAKE_PIN(P11, Pin_nRF51822_to_Arduino(D11)); +MAKE_PIN(P12, Pin_nRF51822_to_Arduino(D12)); +MAKE_PIN(P13, Pin_nRF51822_to_Arduino(D13)); +MAKE_PIN(P14, Pin_nRF51822_to_Arduino(D14)); +MAKE_PIN(P15, Pin_nRF51822_to_Arduino(D15)); +MAKE_PIN(P17, Pin_nRF51822_to_Arduino(D17)); // MISO +MAKE_PIN(P18, Pin_nRF51822_to_Arduino(D18)); // MOSI +MAKE_PIN(P16, Pin_nRF51822_to_Arduino(D16)); // CLK +MAKE_PIN(P19, Pin_nRF51822_to_Arduino(D19)); +MAKE_PIN(P20, Pin_nRF51822_to_Arduino(D20)); +MAKE_PIN(P21, Pin_nRF51822_to_Arduino(D21)); +MAKE_PIN(P22, Pin_nRF51822_to_Arduino(D22)); +MAKE_PIN(P23, Pin_nRF51822_to_Arduino(D23)); +MAKE_PIN(P24, Pin_nRF51822_to_Arduino(D24)); + +#undef MAKE_PIN + + #else #error "Please define board in avrpins.h" From 3646c650b6cd67fa4b17eaec10900e08abd3250e Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Fri, 21 Nov 2014 22:58:54 +0100 Subject: [PATCH 28/36] Added RBL nRF51822 Support Added support for the nRF51822 Board by RedBearLab. --- usbhost.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/usbhost.h b/usbhost.h index cf26c1f0..46ef1346 100644 --- a/usbhost.h +++ b/usbhost.h @@ -27,6 +27,9 @@ e-mail : support@circuitsathome.com #include #endif +#if defined(RBL_NRF51822) +#include "SPI.H" +#endif /* SPI initialization */ template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_SS > class SPi { public: @@ -46,6 +49,13 @@ public: SPI.begin(); SPI.setClockDivider(4); // Set speed to 84MHz/4=21MHz - the MAX3421E can handle up to 26MHz } +#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; @@ -74,6 +84,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(RBL_NRF51822) +typedef SPi< P16, P18, P17, P10 > spi; #else #error "No SPI entry in usbhost.h" #endif @@ -135,7 +147,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(RBL_NRF51822) SPI.transfer(reg | 0x02); SPI.transfer(data); #else @@ -159,7 +171,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__)) || defined(RBL_NRF51822) SPI.transfer(reg | 0x02); while(nbytes) { SPI.transfer(*data_p); @@ -201,7 +213,7 @@ uint8_t MAX3421e< SPI_SS, INTR >::regRd(uint8_t reg) { spi4teensy3::send(reg); uint8_t rv = spi4teensy3::receive(); SPI_SS::Set(); -#elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) +#elif (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822) SPI.transfer(reg); uint8_t rv = SPI.transfer(0); SPI_SS::Set(); @@ -227,7 +239,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__)) || defined(RBL_NRF51822) SPI.transfer(reg); while(nbytes) { *data_p++ = SPI.transfer(0); From 4cf9f34228904acb4ebfae98fb34cf6bc17295a8 Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Sat, 22 Nov 2014 09:53:59 +0100 Subject: [PATCH 29/36] Moved include for nRF51822 Moved the include into the right file. --- settings.h | 2 +- usbhost.h | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/settings.h b/settings.h index e3d0ed1d..e6ed5cf1 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__) +#if (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822) #include // Use the Arduino SPI library for the Arduino Due #endif diff --git a/usbhost.h b/usbhost.h index 46ef1346..f35bc0f4 100644 --- a/usbhost.h +++ b/usbhost.h @@ -27,9 +27,7 @@ e-mail : support@circuitsathome.com #include #endif -#if defined(RBL_NRF51822) -#include "SPI.H" -#endif + /* SPI initialization */ template< typename SPI_CLK, typename SPI_MOSI, typename SPI_MISO, typename SPI_SS > class SPi { public: From a88e9b44e7402fcab292f37703756aa864e6f174 Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Sat, 22 Nov 2014 09:56:15 +0100 Subject: [PATCH 30/36] Added Board Added RedBearLab nRF51822 and instructions to the readme. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 1a3163b3..4d84061f 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,8 @@ Currently the following boards are supported by the library: * Balanduino * 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. The following boards need to be activated manually in [settings.h](settings.h): From 904569278d10d717a177dfc8eab1f6b385b96629 Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Sat, 22 Nov 2014 11:02:36 +0100 Subject: [PATCH 31/36] Updated instructions Added information about including SPI.h --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4d84061f..6d40b833 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ Now quit the Arduino IDE and reopen it. Now you should be able to go open all the examples codes by navigating to "File>Examples>USB\_Host\_Shield\_20" and then select the example you will like to open. +Please make sure to include the SPI library like so: ```#include ``` in your .ino file. + For more information visit the following sites: and . # How to use the library @@ -93,14 +95,12 @@ 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. * 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 * 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. The following boards need to be activated manually in [settings.h](settings.h): From e0ac4eedaddad62166f0d87bbd29886c7f927aa5 Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Mon, 24 Nov 2014 08:22:19 +0100 Subject: [PATCH 32/36] Revert "Updated instructions" This reverts commit 904569278d10d717a177dfc8eab1f6b385b96629. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6d40b833..4d84061f 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,6 @@ Now quit the Arduino IDE and reopen it. Now you should be able to go open all the examples codes by navigating to "File>Examples>USB\_Host\_Shield\_20" and then select the example you will like to open. -Please make sure to include the SPI library like so: ```#include ``` in your .ino file. - For more information visit the following sites: and . # How to use the library @@ -95,12 +93,14 @@ 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. * 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 * 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. The following boards need to be activated manually in [settings.h](settings.h): From 585e6b9df503374d625bcdbd23c3e5285693102a Mon Sep 17 00:00:00 2001 From: Matt Sieren Date: Mon, 24 Nov 2014 08:23:41 +0100 Subject: [PATCH 33/36] Updated comment Updated comment to reflect including SPI.h on the RBL nRF as well. --- settings.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.h b/settings.h index e6ed5cf1..cc02f583 100644 --- a/settings.h +++ b/settings.h @@ -138,7 +138,7 @@ e-mail : support@circuitsathome.com #endif #if (defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)) || defined(RBL_NRF51822) -#include // Use the Arduino SPI library for the Arduino Due +#include // Use the Arduino SPI library for the Arduino Due and RedBearLab nRF51822 #endif #endif /* SETTINGS_H */ From 2b4a56de3d090686f62d25ea34042759dc4352d6 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Tue, 2 Dec 2014 17:46:05 -0800 Subject: [PATCH 34/36] Added note about SPI pins used on Arduino Uno --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 4d84061f..e7f4ed56 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,8 @@ More information about the controller can be found at the following sites: 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. +Note this means that it uses pin 13, 12, 11 on an Arduino Uno, so these pins can not be used for anything else! + Furthermore it uses one pin as SS and one INT pin. These are by default located on pin 10 and 9 respectively. They can easily be reconfigured in case you need to use them for something else by cutting the jumper on the shield and then solder a wire from the pad to the new pin. After that you need modify the following entry in [UsbCore.h](UsbCore.h): From 96dfd7e37d395a70d3d8c1bf211eaa8323b2d857 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sat, 3 Jan 2015 10:52:17 +0100 Subject: [PATCH 35/36] Added support for Joytech wired controller See: https://github.com/felis/USB_Host_Shield_2.0/issues/128 --- XBOXUSB.cpp | 2 +- XBOXUSB.h | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/XBOXUSB.cpp b/XBOXUSB.cpp index 3cd9cde9..ddece21b 100644 --- a/XBOXUSB.cpp +++ b/XBOXUSB.cpp @@ -105,7 +105,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"), 0x80); #endif goto FailUnknownDevice; - } else if(PID != XBOX_WIRED_PID && PID != MADCATZ_WIRED_PID && PID != GAMESTOP_WIRED_PID && PID != AFTERGLOW_WIRED_PID) // Check PID + } else if(PID != XBOX_WIRED_PID && PID != MADCATZ_WIRED_PID && PID != GAMESTOP_WIRED_PID && PID != AFTERGLOW_WIRED_PID && PID != JOYTECH_WIRED_PID) // Check PID goto FailUnknownDevice; // Allocate new address according to device class diff --git a/XBOXUSB.h b/XBOXUSB.h index 8d5ecb2a..f7a657ba 100644 --- a/XBOXUSB.h +++ b/XBOXUSB.h @@ -40,6 +40,7 @@ #define XBOX_WIRELESS_RECEIVER_PID 0x0719 // Microsoft Wireless Gaming Receiver #define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID 0x0291 // Third party Wireless Gaming Receiver #define MADCATZ_WIRED_PID 0xF016 // Mad Catz wired controller +#define JOYTECH_WIRED_PID 0xBEEF // For Joytech wired controller #define GAMESTOP_WIRED_PID 0x0401 // Gamestop wired controller #define AFTERGLOW_WIRED_PID 0x0213 // Afterglow wired controller - it uses the same VID as a Gamestop controller @@ -103,7 +104,7 @@ public: * @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 || vid == MADCATZ_VID || vid == JOYTECH_VID || vid == GAMESTOP_VID) && (pid == XBOX_WIRED_PID || pid == MADCATZ_WIRED_PID || pid == GAMESTOP_WIRED_PID || pid == AFTERGLOW_WIRED_PID)); + return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID || vid == GAMESTOP_VID) && (pid == XBOX_WIRED_PID || pid == MADCATZ_WIRED_PID || pid == GAMESTOP_WIRED_PID || pid == AFTERGLOW_WIRED_PID || pid == JOYTECH_WIRED_PID)); }; /**@}*/ From 86cb7f38abcffc1e5f1df9495291ecebc87aa206 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Sun, 22 Feb 2015 18:27:30 +0100 Subject: [PATCH 36/36] Fixed some formatting --- examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino | 128 ++++++------- .../USBHIDBootKbdAndMouse.ino | 174 +++++++++--------- 2 files changed, 151 insertions(+), 151 deletions(-) diff --git a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino index 0c0a0fca..0dea99e9 100644 --- a/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino +++ b/examples/HID/USBHIDBootKbd/USBHIDBootKbd.ino @@ -8,91 +8,91 @@ class KbdRptParser : public KeyboardReportParser { - void PrintKey(uint8_t mod, uint8_t key); + void PrintKey(uint8_t mod, uint8_t key); -protected: - void OnControlKeysChanged(uint8_t before, uint8_t after); + protected: + void OnControlKeysChanged(uint8_t before, uint8_t after); - void OnKeyDown (uint8_t mod, uint8_t key); - void OnKeyUp (uint8_t mod, uint8_t key); - void OnKeyPressed(uint8_t key); + void OnKeyDown (uint8_t mod, uint8_t key); + void OnKeyUp (uint8_t mod, uint8_t key); + void OnKeyPressed(uint8_t key); }; void KbdRptParser::PrintKey(uint8_t m, uint8_t key) { - MODIFIERKEYS mod; - *((uint8_t*)&mod) = m; - Serial.print((mod.bmLeftCtrl == 1) ? "C" : " "); - Serial.print((mod.bmLeftShift == 1) ? "S" : " "); - Serial.print((mod.bmLeftAlt == 1) ? "A" : " "); - Serial.print((mod.bmLeftGUI == 1) ? "G" : " "); + MODIFIERKEYS mod; + *((uint8_t*)&mod) = m; + Serial.print((mod.bmLeftCtrl == 1) ? "C" : " "); + Serial.print((mod.bmLeftShift == 1) ? "S" : " "); + Serial.print((mod.bmLeftAlt == 1) ? "A" : " "); + Serial.print((mod.bmLeftGUI == 1) ? "G" : " "); - Serial.print(" >"); - PrintHex(key, 0x80); - Serial.print("< "); + Serial.print(" >"); + PrintHex(key, 0x80); + Serial.print("< "); - Serial.print((mod.bmRightCtrl == 1) ? "C" : " "); - Serial.print((mod.bmRightShift == 1) ? "S" : " "); - Serial.print((mod.bmRightAlt == 1) ? "A" : " "); - Serial.println((mod.bmRightGUI == 1) ? "G" : " "); + Serial.print((mod.bmRightCtrl == 1) ? "C" : " "); + Serial.print((mod.bmRightShift == 1) ? "S" : " "); + Serial.print((mod.bmRightAlt == 1) ? "A" : " "); + Serial.println((mod.bmRightGUI == 1) ? "G" : " "); }; void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) { - Serial.print("DN "); - PrintKey(mod, key); - uint8_t c = OemToAscii(mod, key); + Serial.print("DN "); + PrintKey(mod, key); + uint8_t c = OemToAscii(mod, key); - if (c) - OnKeyPressed(c); + if (c) + OnKeyPressed(c); } void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) { - MODIFIERKEYS beforeMod; - *((uint8_t*)&beforeMod) = before; + MODIFIERKEYS beforeMod; + *((uint8_t*)&beforeMod) = before; - MODIFIERKEYS afterMod; - *((uint8_t*)&afterMod) = after; + MODIFIERKEYS afterMod; + *((uint8_t*)&afterMod) = after; - if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) { - Serial.println("LeftCtrl changed"); - } - if (beforeMod.bmLeftShift != afterMod.bmLeftShift) { - Serial.println("LeftShift changed"); - } - if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) { - Serial.println("LeftAlt changed"); - } - if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) { - Serial.println("LeftGUI changed"); - } + if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) { + Serial.println("LeftCtrl changed"); + } + if (beforeMod.bmLeftShift != afterMod.bmLeftShift) { + Serial.println("LeftShift changed"); + } + if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) { + Serial.println("LeftAlt changed"); + } + if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) { + Serial.println("LeftGUI changed"); + } - if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) { - Serial.println("RightCtrl changed"); - } - if (beforeMod.bmRightShift != afterMod.bmRightShift) { - Serial.println("RightShift changed"); - } - if (beforeMod.bmRightAlt != afterMod.bmRightAlt) { - Serial.println("RightAlt changed"); - } - if (beforeMod.bmRightGUI != afterMod.bmRightGUI) { - Serial.println("RightGUI changed"); - } + if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) { + Serial.println("RightCtrl changed"); + } + if (beforeMod.bmRightShift != afterMod.bmRightShift) { + Serial.println("RightShift changed"); + } + if (beforeMod.bmRightAlt != afterMod.bmRightAlt) { + Serial.println("RightAlt changed"); + } + if (beforeMod.bmRightGUI != afterMod.bmRightGUI) { + Serial.println("RightGUI changed"); + } } void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) { - Serial.print("UP "); - PrintKey(mod, key); + Serial.print("UP "); + PrintKey(mod, key); } void KbdRptParser::OnKeyPressed(uint8_t key) { - Serial.print("ASCII: "); - Serial.println((char)key); + Serial.print("ASCII: "); + Serial.println((char)key); }; USB Usb; @@ -105,24 +105,24 @@ KbdRptParser Prs; 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("Start"); + Serial.println("Start"); - if (Usb.Init() == -1) - Serial.println("OSC did not start."); + if (Usb.Init() == -1) + Serial.println("OSC did not start."); - delay( 200 ); + delay( 200 ); - next_time = millis() + 5000; + next_time = millis() + 5000; - HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs); + HidKeyboard.SetReportParser(0, (HIDReportParser*)&Prs); } void loop() { - Usb.Task(); + Usb.Task(); } diff --git a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino index a664b4b5..848dac85 100644 --- a/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino +++ b/examples/HID/USBHIDBootKbdAndMouse/USBHIDBootKbdAndMouse.ino @@ -8,139 +8,139 @@ class MouseRptParser : public MouseReportParser { -protected: - void OnMouseMove(MOUSEINFO *mi); - void OnLeftButtonUp(MOUSEINFO *mi); - void OnLeftButtonDown(MOUSEINFO *mi); - void OnRightButtonUp(MOUSEINFO *mi); - void OnRightButtonDown(MOUSEINFO *mi); - void OnMiddleButtonUp(MOUSEINFO *mi); - void OnMiddleButtonDown(MOUSEINFO *mi); + protected: + void OnMouseMove(MOUSEINFO *mi); + void OnLeftButtonUp(MOUSEINFO *mi); + void OnLeftButtonDown(MOUSEINFO *mi); + void OnRightButtonUp(MOUSEINFO *mi); + void OnRightButtonDown(MOUSEINFO *mi); + void OnMiddleButtonUp(MOUSEINFO *mi); + void OnMiddleButtonDown(MOUSEINFO *mi); }; void MouseRptParser::OnMouseMove(MOUSEINFO *mi) { - Serial.print("dx="); - Serial.print(mi->dX, DEC); - Serial.print(" dy="); - Serial.println(mi->dY, DEC); + Serial.print("dx="); + Serial.print(mi->dX, DEC); + Serial.print(" dy="); + Serial.println(mi->dY, DEC); }; void MouseRptParser::OnLeftButtonUp (MOUSEINFO *mi) { - Serial.println("L Butt Up"); + Serial.println("L Butt Up"); }; void MouseRptParser::OnLeftButtonDown (MOUSEINFO *mi) { - Serial.println("L Butt Dn"); + Serial.println("L Butt Dn"); }; void MouseRptParser::OnRightButtonUp (MOUSEINFO *mi) { - Serial.println("R Butt Up"); + Serial.println("R Butt Up"); }; void MouseRptParser::OnRightButtonDown (MOUSEINFO *mi) { - Serial.println("R Butt Dn"); + Serial.println("R Butt Dn"); }; void MouseRptParser::OnMiddleButtonUp (MOUSEINFO *mi) { - Serial.println("M Butt Up"); + Serial.println("M Butt Up"); }; void MouseRptParser::OnMiddleButtonDown (MOUSEINFO *mi) { - Serial.println("M Butt Dn"); + Serial.println("M Butt Dn"); }; class KbdRptParser : public KeyboardReportParser { - void PrintKey(uint8_t mod, uint8_t key); + void PrintKey(uint8_t mod, uint8_t key); -protected: - void OnControlKeysChanged(uint8_t before, uint8_t after); - void OnKeyDown (uint8_t mod, uint8_t key); - void OnKeyUp (uint8_t mod, uint8_t key); - void OnKeyPressed(uint8_t key); + protected: + void OnControlKeysChanged(uint8_t before, uint8_t after); + void OnKeyDown (uint8_t mod, uint8_t key); + void OnKeyUp (uint8_t mod, uint8_t key); + void OnKeyPressed(uint8_t key); }; void KbdRptParser::PrintKey(uint8_t m, uint8_t key) { - MODIFIERKEYS mod; - *((uint8_t*)&mod) = m; - Serial.print((mod.bmLeftCtrl == 1) ? "C" : " "); - Serial.print((mod.bmLeftShift == 1) ? "S" : " "); - Serial.print((mod.bmLeftAlt == 1) ? "A" : " "); - Serial.print((mod.bmLeftGUI == 1) ? "G" : " "); + MODIFIERKEYS mod; + *((uint8_t*)&mod) = m; + Serial.print((mod.bmLeftCtrl == 1) ? "C" : " "); + Serial.print((mod.bmLeftShift == 1) ? "S" : " "); + Serial.print((mod.bmLeftAlt == 1) ? "A" : " "); + Serial.print((mod.bmLeftGUI == 1) ? "G" : " "); - Serial.print(" >"); - PrintHex(key, 0x80); - Serial.print("< "); + Serial.print(" >"); + PrintHex(key, 0x80); + Serial.print("< "); - Serial.print((mod.bmRightCtrl == 1) ? "C" : " "); - Serial.print((mod.bmRightShift == 1) ? "S" : " "); - Serial.print((mod.bmRightAlt == 1) ? "A" : " "); - Serial.println((mod.bmRightGUI == 1) ? "G" : " "); + Serial.print((mod.bmRightCtrl == 1) ? "C" : " "); + Serial.print((mod.bmRightShift == 1) ? "S" : " "); + Serial.print((mod.bmRightAlt == 1) ? "A" : " "); + Serial.println((mod.bmRightGUI == 1) ? "G" : " "); }; void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key) { - Serial.print("DN "); - PrintKey(mod, key); - uint8_t c = OemToAscii(mod, key); + Serial.print("DN "); + PrintKey(mod, key); + uint8_t c = OemToAscii(mod, key); - if (c) - OnKeyPressed(c); + if (c) + OnKeyPressed(c); } void KbdRptParser::OnControlKeysChanged(uint8_t before, uint8_t after) { - MODIFIERKEYS beforeMod; - *((uint8_t*)&beforeMod) = before; + MODIFIERKEYS beforeMod; + *((uint8_t*)&beforeMod) = before; - MODIFIERKEYS afterMod; - *((uint8_t*)&afterMod) = after; + MODIFIERKEYS afterMod; + *((uint8_t*)&afterMod) = after; - if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) { - Serial.println("LeftCtrl changed"); - } - if (beforeMod.bmLeftShift != afterMod.bmLeftShift) { - Serial.println("LeftShift changed"); - } - if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) { - Serial.println("LeftAlt changed"); - } - if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) { - Serial.println("LeftGUI changed"); - } + if (beforeMod.bmLeftCtrl != afterMod.bmLeftCtrl) { + Serial.println("LeftCtrl changed"); + } + if (beforeMod.bmLeftShift != afterMod.bmLeftShift) { + Serial.println("LeftShift changed"); + } + if (beforeMod.bmLeftAlt != afterMod.bmLeftAlt) { + Serial.println("LeftAlt changed"); + } + if (beforeMod.bmLeftGUI != afterMod.bmLeftGUI) { + Serial.println("LeftGUI changed"); + } - if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) { - Serial.println("RightCtrl changed"); - } - if (beforeMod.bmRightShift != afterMod.bmRightShift) { - Serial.println("RightShift changed"); - } - if (beforeMod.bmRightAlt != afterMod.bmRightAlt) { - Serial.println("RightAlt changed"); - } - if (beforeMod.bmRightGUI != afterMod.bmRightGUI) { - Serial.println("RightGUI changed"); - } + if (beforeMod.bmRightCtrl != afterMod.bmRightCtrl) { + Serial.println("RightCtrl changed"); + } + if (beforeMod.bmRightShift != afterMod.bmRightShift) { + Serial.println("RightShift changed"); + } + if (beforeMod.bmRightAlt != afterMod.bmRightAlt) { + Serial.println("RightAlt changed"); + } + if (beforeMod.bmRightGUI != afterMod.bmRightGUI) { + Serial.println("RightGUI changed"); + } } void KbdRptParser::OnKeyUp(uint8_t mod, uint8_t key) { - Serial.print("UP "); - PrintKey(mod, key); + Serial.print("UP "); + PrintKey(mod, key); } void KbdRptParser::OnKeyPressed(uint8_t key) { - Serial.print("ASCII: "); - Serial.println((char)key); + Serial.print("ASCII: "); + Serial.println((char)key); }; USB Usb; USBHub Hub(&Usb); -HIDBoot HidComposite(&Usb); +HIDBoot < HID_PROTOCOL_KEYBOARD | HID_PROTOCOL_MOUSE > HidComposite(&Usb); HIDBoot HidKeyboard(&Usb); HIDBoot HidMouse(&Usb); @@ -151,27 +151,27 @@ MouseRptParser MousePrs; 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 + 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"); + Serial.println("Start"); - if (Usb.Init() == -1) - Serial.println("OSC did not start."); + if (Usb.Init() == -1) + Serial.println("OSC did not start."); - delay( 200 ); + delay( 200 ); - //next_time = millis() + 5000; + //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, (HIDReportParser*)&KbdPrs); + HidComposite.SetReportParser(1, (HIDReportParser*)&MousePrs); + HidKeyboard.SetReportParser(0, (HIDReportParser*)&KbdPrs); + HidMouse.SetReportParser(0, (HIDReportParser*)&MousePrs); } void loop() { - Usb.Task(); + Usb.Task(); }