This commit is contained in:
Oleg Mazurov 2013-06-11 21:11:43 -06:00
parent 1c3b6b79eb
commit 261e5f1bd2
29 changed files with 317 additions and 484 deletions

3
.gitignore vendored
View file

@ -1,3 +1,4 @@
*.bak *.bak
*.zip *.zip
*.rar *.rar
build/

90
BTD.cpp
View file

@ -16,7 +16,7 @@
*/ */
#include "BTD.h" #include "BTD.h"
// #define DEBUG // Uncomment to print data for debugging -- NO! see message.h // To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data //#define EXTRADEBUG // Uncomment to get even more debugging data
const uint8_t BTD::BTD_CONTROL_PIPE = 0; const uint8_t BTD::BTD_CONTROL_PIPE = 0;
@ -58,7 +58,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
#endif #endif
// check if address has already been assigned to an instance // check if address has already been assigned to an instance
if (bAddress) { if (bAddress) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nAddress in use"), 0x80); Notify(PSTR("\r\nAddress in use"), 0x80);
#endif #endif
return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
@ -68,14 +68,14 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
p = addrPool.GetUsbDevicePtr(0); p = addrPool.GetUsbDevicePtr(0);
if (!p) { if (!p) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nAddress not found"), 0x80); Notify(PSTR("\r\nAddress not found"), 0x80);
#endif #endif
return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
} }
if (!p->epinfo) { if (!p->epinfo) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nepinfo is null"), 0x80); Notify(PSTR("\r\nepinfo is null"), 0x80);
#endif #endif
return USB_ERROR_EPINFO_IS_NULL; return USB_ERROR_EPINFO_IS_NULL;
@ -113,7 +113,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
p->lowspeed = false; p->lowspeed = false;
addrPool.FreeAddress(bAddress); addrPool.FreeAddress(bAddress);
bAddress = 0; bAddress = 0;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nsetAddr: "), 0x80); Notify(PSTR("\r\nsetAddr: "), 0x80);
#endif #endif
PrintHex<uint8_t > (rcode, 0x80); PrintHex<uint8_t > (rcode, 0x80);
@ -145,7 +145,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
if (rcode) if (rcode)
goto FailSetConfDescr; goto FailSetConfDescr;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
if (PID == PS3_PID || PID == PS3NAVIGATION_PID) { if (PID == PS3_PID || PID == PS3NAVIGATION_PID) {
if (PID == PS3_PID) if (PID == PS3_PID)
Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80); Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
@ -156,7 +156,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
#endif #endif
if (my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) { if (my_bdaddr[0] == 0x00 && my_bdaddr[1] == 0x00 && my_bdaddr[2] == 0x00 && my_bdaddr[3] == 0x00 && my_bdaddr[4] == 0x00 && my_bdaddr[5] == 0x00) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nPlease plug in the dongle before trying to pair with the PS3 Controller\n\rOr set the Bluetooth address in the constructor of the PS3BT class"), 0x80); Notify(PSTR("\r\nPlease plug in the dongle before trying to pair with the PS3 Controller\n\rOr set the Bluetooth address in the constructor of the PS3BT class"), 0x80);
#endif #endif
} else { } else {
@ -164,7 +164,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
setBdaddr(my_bdaddr); // Set internal Bluetooth address setBdaddr(my_bdaddr); // Set internal Bluetooth address
else else
setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address setMoveBdaddr(my_bdaddr); // Set internal Bluetooth address
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80); Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
for (int8_t i = 5; i > 0; i--) { for (int8_t i = 5; i > 0; i--) {
PrintHex<uint8_t > (my_bdaddr[i], 0x80); PrintHex<uint8_t > (my_bdaddr[i], 0x80);
@ -214,7 +214,7 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
watingForConnection = false; watingForConnection = false;
bPollEnable = true; bPollEnable = true;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80); Notify(PSTR("\r\nBluetooth Dongle Initialized"), 0x80);
#endif #endif
} }
@ -222,37 +222,37 @@ uint8_t BTD::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */ /* diagnostic messages */
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailGetConfDescr: FailGetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetConfDescr(); NotifyFailGetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
#endif #endif
goto Fail; goto Fail;
FailUnknownDevice: FailUnknownDevice:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailUnknownDevice(VID, PID); NotifyFailUnknownDevice(VID, PID);
#endif #endif
pUsb->setAddr(bAddress, 0, 0); // Reset address pUsb->setAddr(bAddress, 0, 0); // Reset address
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80); Notify(PSTR("\r\nBTD Init Failed, error code: "), 0x80);
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif
@ -272,10 +272,10 @@ void BTD::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto
bConfNum = conf; bConfNum = conf;
uint8_t index; uint8_t index;
if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) // Interrupt In endpoint found if ((pep->bmAttributes & 0x03) == 3 && (pep->bEndpointAddress & 0x80) == 0x80) { // Interrupt In endpoint found
index = BTD_EVENT_PIPE; index = BTD_EVENT_PIPE;
epInfo[index].bmNakPower = USB_NAK_NOWAIT;
else { } else {
if ((pep->bmAttributes & 0x02) == 2) // Bulk endpoint found if ((pep->bmAttributes & 0x02) == 2) // Bulk endpoint found
index = ((pep->bEndpointAddress & 0x80) == 0x80) ? BTD_DATAIN_PIPE : BTD_DATAOUT_PIPE; index = ((pep->bEndpointAddress & 0x80) == 0x80) ? BTD_DATAIN_PIPE : BTD_DATAOUT_PIPE;
else else
@ -360,7 +360,7 @@ void BTD::HCI_event_task() {
case EV_COMMAND_STATUS: case EV_COMMAND_STATUS:
if (hcibuf[2]) { // show status on serial if not OK if (hcibuf[2]) { // show status on serial if not OK
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHCI Command Failed: "), 0x80); Notify(PSTR("\r\nHCI Command Failed: "), 0x80);
PrintHex<uint8_t > (hcibuf[2], 0x80); PrintHex<uint8_t > (hcibuf[2], 0x80);
Notify(PSTR(" "), 0x80); Notify(PSTR(" "), 0x80);
@ -374,7 +374,7 @@ void BTD::HCI_event_task() {
case EV_INQUIRY_COMPLETE: case EV_INQUIRY_COMPLETE:
if (inquiry_counter >= 5) { if (inquiry_counter >= 5) {
inquiry_counter = 0; inquiry_counter = 0;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80); Notify(PSTR("\r\nCouldn't find Wiimote"), 0x80);
#endif #endif
connectToWii = false; connectToWii = false;
@ -468,18 +468,18 @@ void BTD::HCI_event_task() {
case EV_PIN_CODE_REQUEST: case EV_PIN_CODE_REQUEST:
if (pairWithWii) { if (pairWithWii) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nPairing with wiimote"), 0x80); Notify(PSTR("\r\nPairing with wiimote"), 0x80);
#endif #endif
hci_pin_code_request_reply(); hci_pin_code_request_reply();
} else if (btdPin != NULL) { } else if (btdPin != NULL) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80); Notify(PSTR("\r\nBluetooth pin is set too: "), 0x80);
NotifyStr(btdPin, 0x80); NotifyStr(btdPin, 0x80);
#endif #endif
hci_pin_code_request_reply(); hci_pin_code_request_reply();
} else { } else {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nNo pin was set"), 0x80); Notify(PSTR("\r\nNo pin was set"), 0x80);
#endif #endif
hci_pin_code_negative_request_reply(); hci_pin_code_negative_request_reply();
@ -487,7 +487,7 @@ void BTD::HCI_event_task() {
break; break;
case EV_LINK_KEY_REQUEST: case EV_LINK_KEY_REQUEST:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nReceived Key Request"), 0x80); Notify(PSTR("\r\nReceived Key Request"), 0x80);
#endif #endif
hci_link_key_request_negative_reply(); hci_link_key_request_negative_reply();
@ -495,7 +495,7 @@ void BTD::HCI_event_task() {
case EV_AUTHENTICATION_COMPLETE: case EV_AUTHENTICATION_COMPLETE:
if (pairWithWii && !connectToWii) { if (pairWithWii && !connectToWii) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nPairing successful"), 0x80); Notify(PSTR("\r\nPairing successful"), 0x80);
#endif #endif
connectToWii = true; // Only send the ACL data to the Wii service connectToWii = true; // Only send the ACL data to the Wii service
@ -549,7 +549,7 @@ void BTD::HCI_task() {
hci_counter++; hci_counter++;
if (hci_cmd_complete) { if (hci_cmd_complete) {
hci_counter = 0; hci_counter = 0;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHCI Reset complete"), 0x80); Notify(PSTR("\r\nHCI Reset complete"), 0x80);
#endif #endif
hci_state = HCI_CLASS_STATE; hci_state = HCI_CLASS_STATE;
@ -558,7 +558,7 @@ void BTD::HCI_task() {
hci_num_reset_loops *= 10; hci_num_reset_loops *= 10;
if (hci_num_reset_loops > 2000) if (hci_num_reset_loops > 2000)
hci_num_reset_loops = 2000; hci_num_reset_loops = 2000;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nNo response to HCI Reset"), 0x80); Notify(PSTR("\r\nNo response to HCI Reset"), 0x80);
#endif #endif
hci_state = HCI_INIT_STATE; hci_state = HCI_INIT_STATE;
@ -568,7 +568,7 @@ void BTD::HCI_task() {
case HCI_CLASS_STATE: case HCI_CLASS_STATE:
if (hci_cmd_complete) { if (hci_cmd_complete) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWrite class of device"), 0x80); Notify(PSTR("\r\nWrite class of device"), 0x80);
#endif #endif
hci_state = HCI_BDADDR_STATE; hci_state = HCI_BDADDR_STATE;
@ -578,7 +578,7 @@ void BTD::HCI_task() {
case HCI_BDADDR_STATE: case HCI_BDADDR_STATE:
if (hci_read_bdaddr_complete) { if (hci_read_bdaddr_complete) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80); Notify(PSTR("\r\nLocal Bluetooth Address: "), 0x80);
for (int8_t i = 5; i > 0; i--) { for (int8_t i = 5; i > 0; i--) {
PrintHex<uint8_t > (my_bdaddr[i], 0x80); PrintHex<uint8_t > (my_bdaddr[i], 0x80);
@ -603,7 +603,7 @@ void BTD::HCI_task() {
case HCI_SET_NAME_STATE: case HCI_SET_NAME_STATE:
if (hci_cmd_complete) { if (hci_cmd_complete) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nThe name is set to: "), 0x80); Notify(PSTR("\r\nThe name is set to: "), 0x80);
NotifyStr(btdName, 0x80); NotifyStr(btdName, 0x80);
#endif #endif
@ -613,7 +613,7 @@ void BTD::HCI_task() {
case HCI_CHECK_WII_SERVICE: case HCI_CHECK_WII_SERVICE:
if (pairWithWii) { // Check if it should try to connect to a wiimote if (pairWithWii) { // Check if it should try to connect to a wiimote
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80); Notify(PSTR("\r\nStarting inquiry\r\nPress 1 & 2 on the Wiimote\r\nOr press sync if you are using a Wii U Pro Controller"), 0x80);
#endif #endif
hci_inquiry(); hci_inquiry();
@ -625,7 +625,7 @@ void BTD::HCI_task() {
case HCI_INQUIRY_STATE: case HCI_INQUIRY_STATE:
if (hci_wii_found) { if (hci_wii_found) {
hci_inquiry_cancel(); // Stop inquiry hci_inquiry_cancel(); // Stop inquiry
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWiimote found"), 0x80); Notify(PSTR("\r\nWiimote found"), 0x80);
Notify(PSTR("\r\nNow just create the instance like so:"), 0x80); Notify(PSTR("\r\nNow just create the instance like so:"), 0x80);
Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80); Notify(PSTR("\r\nWII Wii(&Btd);"), 0x80);
@ -641,7 +641,7 @@ void BTD::HCI_task() {
case HCI_CONNECT_WII_STATE: case HCI_CONNECT_WII_STATE:
if (hci_cmd_complete) { if (hci_cmd_complete) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nConnecting to Wiimote"), 0x80); Notify(PSTR("\r\nConnecting to Wiimote"), 0x80);
#endif #endif
hci_connect(); hci_connect();
@ -652,13 +652,13 @@ void BTD::HCI_task() {
case HCI_CONNECTED_WII_STATE: case HCI_CONNECTED_WII_STATE:
if (hci_connect_event) { if (hci_connect_event) {
if (hci_connect_complete) { if (hci_connect_complete) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nConnected to Wiimote"), 0x80); Notify(PSTR("\r\nConnected to Wiimote"), 0x80);
#endif #endif
hci_authentication_request(); // This will start the pairing with the wiimote hci_authentication_request(); // This will start the pairing with the wiimote
hci_state = HCI_SCANNING_STATE; hci_state = HCI_SCANNING_STATE;
} else { } else {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nTrying to connect one more time..."), 0x80); Notify(PSTR("\r\nTrying to connect one more time..."), 0x80);
#endif #endif
hci_connect(); // Try to connect one more time hci_connect(); // Try to connect one more time
@ -668,7 +668,7 @@ void BTD::HCI_task() {
case HCI_SCANNING_STATE: case HCI_SCANNING_STATE:
if (!connectToWii && !pairWithWii) { if (!connectToWii && !pairWithWii) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80); Notify(PSTR("\r\nWait For Incoming Connection Request"), 0x80);
#endif #endif
hci_write_scan_enable(); hci_write_scan_enable();
@ -680,7 +680,7 @@ void BTD::HCI_task() {
case HCI_CONNECT_IN_STATE: case HCI_CONNECT_IN_STATE:
if (hci_incoming_connect_request) { if (hci_incoming_connect_request) {
watingForConnection = false; watingForConnection = false;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nIncoming Connection Request"), 0x80); Notify(PSTR("\r\nIncoming Connection Request"), 0x80);
#endif #endif
hci_remote_name(); hci_remote_name();
@ -691,7 +691,7 @@ void BTD::HCI_task() {
case HCI_REMOTE_NAME_STATE: case HCI_REMOTE_NAME_STATE:
if (hci_remote_name_complete) { if (hci_remote_name_complete) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nRemote Name: "), 0x80); Notify(PSTR("\r\nRemote Name: "), 0x80);
for (uint8_t i = 0; i < 30; i++) { for (uint8_t i = 0; i < 30; i++) {
if (remote_name[i] == NULL) if (remote_name[i] == NULL)
@ -701,16 +701,16 @@ void BTD::HCI_task() {
#endif #endif
if (strncmp((const char*)remote_name, "Nintendo", 8) == 0) { if (strncmp((const char*)remote_name, "Nintendo", 8) == 0) {
incomingWii = true; incomingWii = true;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWiimote is connecting"), 0x80); Notify(PSTR("\r\nWiimote is connecting"), 0x80);
#endif #endif
if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) { if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-TR", 22) == 0) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR(" with Motion Plus Inside"), 0x80); Notify(PSTR(" with Motion Plus Inside"), 0x80);
#endif #endif
motionPlusInside = true; motionPlusInside = true;
} else if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) { } else if (strncmp((const char*)remote_name, "Nintendo RVL-CNT-01-UC", 22) == 0) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR(" - Wii U Pro Controller"), 0x80); Notify(PSTR(" - Wii U Pro Controller"), 0x80);
#endif #endif
motionPlusInside = true; motionPlusInside = true;
@ -731,7 +731,7 @@ void BTD::HCI_task() {
case HCI_CONNECTED_STATE: case HCI_CONNECTED_STATE:
if (hci_connect_complete) { if (hci_connect_complete) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nConnected to Device: "), 0x80); Notify(PSTR("\r\nConnected to Device: "), 0x80);
for (int8_t i = 5; i > 0; i--) { for (int8_t i = 5; i > 0; i--) {
PrintHex<uint8_t > (disc_bdaddr[i], 0x80); PrintHex<uint8_t > (disc_bdaddr[i], 0x80);
@ -759,7 +759,7 @@ void BTD::HCI_task() {
case HCI_DISCONNECT_STATE: case HCI_DISCONNECT_STATE:
if (hci_disconnect_complete) { if (hci_disconnect_complete) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80); Notify(PSTR("\r\nHCI Disconnected from Device"), 0x80);
#endif #endif
hci_event_flag = 0; // Clear all flags hci_event_flag = 0; // Clear all flags
@ -957,7 +957,7 @@ void BTD::hci_pin_code_request_reply() {
if (pairWithWii) { if (pairWithWii) {
hcibuf[9] = 6; // Pin length is the length of the Bluetooth address hcibuf[9] = 6; // Pin length is the length of the Bluetooth address
if (wiiUProController) { if (wiiUProController) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80); Notify(PSTR("\r\nParing with Wii U Pro Controller"), 0x80);
#endif #endif
for (uint8_t i = 0; i < 6; i++) for (uint8_t i = 0; i < 6; i++)
@ -1083,7 +1083,7 @@ void BTD::L2CAP_Command(uint16_t handle, uint8_t* data, uint8_t nbytes, uint8_t
uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf); uint8_t rcode = pUsb->outTransfer(bAddress, epInfo[ BTD_DATAOUT_PIPE ].epAddr, (8 + nbytes), buf);
if (rcode) { if (rcode) {
delay(100); // This small delay prevents it from overflowing if it fails delay(100); // This small delay prevents it from overflowing if it fails
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80); Notify(PSTR("\r\nError sending L2CAP message: 0x"), 0x80);
PrintHex<uint8_t > (rcode, 0x80); PrintHex<uint8_t > (rcode, 0x80);
Notify(PSTR(" - Channel ID: "), 0x80); Notify(PSTR(" - Channel ID: "), 0x80);

2
BTD.h
View file

@ -129,7 +129,7 @@
#define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface #define WI_PROTOCOL_BT 0x01 // Bluetooth Programming Interface
#define BTD_MAX_ENDPOINTS 4 #define BTD_MAX_ENDPOINTS 4
#define BTD_NUMSERVICES 4 // Max number of Bluetooth services #define BTD_NUMSERVICES 4 // Max number of Bluetooth services - if you need more than four simply increase this number
/** All Bluetooth services should include this class. */ /** All Bluetooth services should include this class. */
class BluetoothService { class BluetoothService {

View file

@ -16,7 +16,7 @@
*/ */
#include "PS3BT.h" #include "PS3BT.h"
//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h // To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data //#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers
@ -255,7 +255,7 @@ void PS3BT::ACLData(uint8_t* ACLData) {
l2cap_state = L2CAP_WAIT; l2cap_state = L2CAP_WAIT;
for (uint8_t i = 0; i < 30; i++) for (uint8_t i = 0; i < 30; i++)
remote_name[i] = pBtd->remote_name[i]; // Store the remote name for the connection remote_name[i] = pBtd->remote_name[i]; // Store the remote name for the connection
#ifdef DEBUG #ifdef DEBUG_USB_HOST
if (pBtd->hci_version < 3) { // Check the HCI Version of the Bluetooth dongle 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); Notify(PSTR("\r\nYour dongle may not support reading the analog buttons, sensors and status\r\nYour HCI Version is: "), 0x80);
Notify(pBtd->hci_version, 0x80); Notify(pBtd->hci_version, 0x80);
@ -270,7 +270,7 @@ void PS3BT::ACLData(uint8_t* ACLData) {
l2capinbuf[i] = ACLData[i]; l2capinbuf[i] = ACLData[i];
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
PrintHex<uint8_t > (l2capinbuf[13], 0x80); PrintHex<uint8_t > (l2capinbuf[13], 0x80);
Notify(PSTR(" "), 0x80); Notify(PSTR(" "), 0x80);
@ -330,14 +330,14 @@ void PS3BT::ACLData(uint8_t* ACLData) {
} }
} else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) { } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80); Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
#endif #endif
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid); pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
Reset(); Reset();
} else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80); Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
#endif #endif
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
@ -397,7 +397,7 @@ void PS3BT::L2CAP_task() {
switch (l2cap_state) { switch (l2cap_state) {
case L2CAP_WAIT: case L2CAP_WAIT:
if (l2cap_connection_request_control_flag) { if (l2cap_connection_request_control_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80); Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80);
#endif #endif
pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING); pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING);
@ -411,7 +411,7 @@ void PS3BT::L2CAP_task() {
break; break;
case L2CAP_CONTROL_REQUEST: case L2CAP_CONTROL_REQUEST:
if (l2cap_config_request_control_flag) { if (l2cap_config_request_control_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Control Configuration Request"), 0x80); Notify(PSTR("\r\nHID Control Configuration Request"), 0x80);
#endif #endif
pBtd->l2cap_config_response(hci_handle, identifier, control_scid); pBtd->l2cap_config_response(hci_handle, identifier, control_scid);
@ -421,7 +421,7 @@ void PS3BT::L2CAP_task() {
case L2CAP_CONTROL_SUCCESS: case L2CAP_CONTROL_SUCCESS:
if (l2cap_config_success_control_flag) { if (l2cap_config_success_control_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80); Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
#endif #endif
l2cap_state = L2CAP_INTERRUPT_SETUP; l2cap_state = L2CAP_INTERRUPT_SETUP;
@ -429,7 +429,7 @@ void PS3BT::L2CAP_task() {
break; break;
case L2CAP_INTERRUPT_SETUP: case L2CAP_INTERRUPT_SETUP:
if (l2cap_connection_request_interrupt_flag) { if (l2cap_connection_request_interrupt_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80); Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
#endif #endif
pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING); pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
@ -444,7 +444,7 @@ void PS3BT::L2CAP_task() {
break; break;
case L2CAP_INTERRUPT_REQUEST: case L2CAP_INTERRUPT_REQUEST:
if (l2cap_config_request_interrupt_flag) { if (l2cap_config_request_interrupt_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80); Notify(PSTR("\r\nHID Interrupt Configuration Request"), 0x80);
#endif #endif
pBtd->l2cap_config_response(hci_handle, identifier, interrupt_scid); pBtd->l2cap_config_response(hci_handle, identifier, interrupt_scid);
@ -453,7 +453,7 @@ void PS3BT::L2CAP_task() {
break; break;
case L2CAP_INTERRUPT_SUCCESS: case L2CAP_INTERRUPT_SUCCESS:
if (l2cap_config_success_interrupt_flag) { if (l2cap_config_success_interrupt_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80); Notify(PSTR("\r\nHID Interrupt Successfully Configured"), 0x80);
#endif #endif
if (remote_name[0] == 'M') { // First letter in Motion Controller ('M') if (remote_name[0] == 'M') { // First letter in Motion Controller ('M')
@ -473,7 +473,7 @@ void PS3BT::L2CAP_task() {
case L2CAP_INTERRUPT_DISCONNECT: case L2CAP_INTERRUPT_DISCONNECT:
if (l2cap_disconnect_response_interrupt_flag) { if (l2cap_disconnect_response_interrupt_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
#endif #endif
identifier++; identifier++;
@ -484,7 +484,7 @@ void PS3BT::L2CAP_task() {
case L2CAP_CONTROL_DISCONNECT: case L2CAP_CONTROL_DISCONNECT:
if (l2cap_disconnect_response_control_flag) { if (l2cap_disconnect_response_control_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnected Control Channel"), 0x80); Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
#endif #endif
pBtd->hci_disconnect(hci_handle); pBtd->hci_disconnect(hci_handle);
@ -517,20 +517,20 @@ void PS3BT::Run() {
if (millis() - timer > 1000) { // loop 1 second before sending the command 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[0] == 'P') { // First letter in PLAYSTATION(R)3 Controller ('P')
setLedOn(LED1); setLedOn(LED1);
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80); Notify(PSTR("\r\nDualshock 3 Controller Enabled\r\n"), 0x80);
#endif #endif
PS3Connected = true; PS3Connected = true;
} else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N') } else if (remote_name[0] == 'N') { // First letter in Navigation Controller ('N')
setLedOn(LED1); // This just turns LED constantly on, on the Navigation controller setLedOn(LED1); // This just turns LED constantly on, on the Navigation controller
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80); Notify(PSTR("\r\nNavigation Controller Enabled\r\n"), 0x80);
#endif #endif
PS3NavigationConnected = true; PS3NavigationConnected = true;
} else if (remote_name[0] == 'M') { // First letter in Motion Controller ('M') } else if (remote_name[0] == 'M') { // First letter in Motion Controller ('M')
moveSetBulb(Red); moveSetBulb(Red);
timerBulbRumble = millis(); timerBulbRumble = millis();
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80); Notify(PSTR("\r\nMotion Controller Enabled\r\n"), 0x80);
#endif #endif
PS3MoveConnected = true; PS3MoveConnected = true;
@ -650,7 +650,7 @@ void PS3BT::moveSetBulb(Colors color) { //Use this to set the Color using the pr
} }
void PS3BT::moveSetRumble(uint8_t rumble) { void PS3BT::moveSetRumble(uint8_t rumble) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100) if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100)
Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80); Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
#endif #endif

View file

@ -16,7 +16,7 @@
*/ */
#include "PS3USB.h" #include "PS3USB.h"
//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h // To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data //#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers //#define PRINTREPORT // Uncomment to print the report send by the PS3 Controllers
@ -58,7 +58,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
#endif #endif
// check if address has already been assigned to an instance // check if address has already been assigned to an instance
if (bAddress) { if (bAddress) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nAddress in use"), 0x80); Notify(PSTR("\r\nAddress in use"), 0x80);
#endif #endif
return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
@ -68,14 +68,14 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
p = addrPool.GetUsbDevicePtr(0); p = addrPool.GetUsbDevicePtr(0);
if (!p) { if (!p) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nAddress not found"), 0x80); Notify(PSTR("\r\nAddress not found"), 0x80);
#endif #endif
return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
} }
if (!p->epinfo) { if (!p->epinfo) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nepinfo is null"), 0x80); Notify(PSTR("\r\nepinfo is null"), 0x80);
#endif #endif
return USB_ERROR_EPINFO_IS_NULL; return USB_ERROR_EPINFO_IS_NULL;
@ -118,7 +118,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
p->lowspeed = false; p->lowspeed = false;
addrPool.FreeAddress(bAddress); addrPool.FreeAddress(bAddress);
bAddress = 0; bAddress = 0;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nsetAddr: "), 0x80); Notify(PSTR("\r\nsetAddr: "), 0x80);
#endif #endif
PrintHex<uint8_t > (rcode, 0x80); PrintHex<uint8_t > (rcode, 0x80);
@ -173,12 +173,12 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
if (PID == PS3_PID || PID == PS3NAVIGATION_PID) { if (PID == PS3_PID || PID == PS3NAVIGATION_PID) {
if (PID == PS3_PID) { if (PID == PS3_PID) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80); Notify(PSTR("\r\nDualshock 3 Controller Connected"), 0x80);
#endif #endif
PS3Connected = true; PS3Connected = true;
} else { // must be a navigation controller } else { // must be a navigation controller
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nNavigation Controller Connected"), 0x80); Notify(PSTR("\r\nNavigation Controller Connected"), 0x80);
#endif #endif
PS3NavigationConnected = true; PS3NavigationConnected = true;
@ -195,7 +195,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
for (uint8_t i = 6; i < 10; i++) for (uint8_t i = 6; i < 10; i++)
readBuf[i] = 0x7F; // Set the analog joystick values to center position readBuf[i] = 0x7F; // Set the analog joystick values to center position
} else { // must be a Motion controller } else { // must be a Motion controller
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nMotion Controller Connected"), 0x80); Notify(PSTR("\r\nMotion Controller Connected"), 0x80);
#endif #endif
PS3MoveConnected = true; PS3MoveConnected = true;
@ -205,7 +205,7 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work writeBuf[0] = 0x02; // Set report ID, this is needed for Move commands to work
} }
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80); Notify(PSTR("\r\nBluetooth Address was set to: "), 0x80);
for (int8_t i = 5; i > 0; i--) { for (int8_t i = 5; i > 0; i--) {
PrintHex<uint8_t > (my_bdaddr[i], 0x80); PrintHex<uint8_t > (my_bdaddr[i], 0x80);
@ -221,29 +221,29 @@ uint8_t PS3USB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */ /* diagnostic messages */
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
#endif #endif
goto Fail; goto Fail;
FailUnknownDevice: FailUnknownDevice:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailUnknownDevice(VID, PID); NotifyFailUnknownDevice(VID, PID);
#endif #endif
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nPS3 Init Failed, error code: "), 0x80); Notify(PSTR("\r\nPS3 Init Failed, error code: "), 0x80);
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif
@ -513,7 +513,7 @@ void PS3USB::moveSetBulb(Colors color) { //Use this to set the Color using the p
} }
void PS3USB::moveSetRumble(uint8_t rumble) { void PS3USB::moveSetRumble(uint8_t rumble) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100) if (rumble < 64 && rumble != 0) // The rumble value has to at least 64, or approximately 25% (64/255*100)
Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80); Notify(PSTR("\r\nThe rumble value has to at least 64, or approximately 25%"), 0x80);
#endif #endif

50
SPP.cpp
View file

@ -16,7 +16,7 @@
*/ */
#include "SPP.h" #include "SPP.h"
#define DEBUG // Uncomment to print data for debugging // To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data //#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report sent to the Arduino //#define PRINTREPORT // Uncomment to print the report sent to the Arduino
@ -99,7 +99,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
if (((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000))) { // acl_handle_ok if (((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000))) { // acl_handle_ok
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
PrintHex<uint8_t > (l2capinbuf[13], 0x80); PrintHex<uint8_t > (l2capinbuf[13], 0x80);
Notify(PSTR(" "), 0x80); Notify(PSTR(" "), 0x80);
@ -178,7 +178,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE; l2cap_event_flag |= L2CAP_FLAG_DISCONNECT_RESPONSE;
} }
} else if (l2capinbuf[8] == L2CAP_CMD_INFORMATION_REQUEST) { } else if (l2capinbuf[8] == L2CAP_CMD_INFORMATION_REQUEST) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nInformation request"), 0x80); Notify(PSTR("\r\nInformation request"), 0x80);
#endif #endif
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
@ -252,7 +252,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
PrintHex<uint8_t > (rfcommPfBit, 0x80); PrintHex<uint8_t > (rfcommPfBit, 0x80);
#endif #endif
if (rfcommChannelType == RFCOMM_DISC) { if (rfcommChannelType == RFCOMM_DISC) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80); Notify(PSTR("\r\nReceived Disconnect RFCOMM Command on channel: "), 0x80);
PrintHex<uint8_t > (rfcommChannel >> 3, 0x80); PrintHex<uint8_t > (rfcommChannel >> 3, 0x80);
#endif #endif
@ -282,7 +282,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
Notifyc(l2capinbuf[i + 11 + offset], 0x80); Notifyc(l2capinbuf[i + 11 + offset], 0x80);
#endif #endif
} else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80); Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80);
#endif #endif
rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command
@ -297,7 +297,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
rfcommbuf[9] = l2capinbuf[20]; // Number of Frames rfcommbuf[9] = l2capinbuf[20]; // Number of Frames
sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response
} else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80); Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80);
#endif #endif
rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response
@ -308,12 +308,12 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
} }
} else { } else {
if (rfcommChannelType == RFCOMM_SABM) { // SABM Command - this is sent twice: once for channel 0 and then for the channel to establish if (rfcommChannelType == RFCOMM_SABM) { // SABM Command - this is sent twice: once for channel 0 and then for the channel to establish
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nReceived SABM Command"), 0x80); Notify(PSTR("\r\nReceived SABM Command"), 0x80);
#endif #endif
sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command sendRfcomm(rfcommChannel, rfcommDirection, rfcommCommandResponse, RFCOMM_UA, rfcommPfBit, rfcommbuf, 0x00); // UA Command
} else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_PN_CMD) { // UIH Parameter Negotiation Command } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_PN_CMD) { // UIH Parameter Negotiation Command
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nReceived UIH Parameter Negotiation Command"), 0x80); Notify(PSTR("\r\nReceived UIH Parameter Negotiation Command"), 0x80);
#endif #endif
rfcommbuf[0] = BT_RFCOMM_PN_RSP; // UIH Parameter Negotiation Response rfcommbuf[0] = BT_RFCOMM_PN_RSP; // UIH Parameter Negotiation Response
@ -328,7 +328,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
rfcommbuf[9] = 0x00; // Number of Frames rfcommbuf[9] = 0x00; // Number of Frames
sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A);
} else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_CMD) { // UIH Modem Status Command
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80); Notify(PSTR("\r\nSend UIH Modem Status Response"), 0x80);
#endif #endif
rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response rfcommbuf[0] = BT_RFCOMM_MSC_RSP; // UIH Modem Status Response
@ -338,7 +338,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04); sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04);
delay(1); delay(1);
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSend UIH Modem Status Command"), 0x80); Notify(PSTR("\r\nSend UIH Modem Status Command"), 0x80);
#endif #endif
rfcommbuf[0] = BT_RFCOMM_MSC_CMD; // UIH Modem Status Command rfcommbuf[0] = BT_RFCOMM_MSC_CMD; // UIH Modem Status Command
@ -349,7 +349,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04); sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x04);
} else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_RSP) { // UIH Modem Status Response } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_MSC_RSP) { // UIH Modem Status Response
if (!creditSent) { if (!creditSent) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSend UIH Command with credit"), 0x80); Notify(PSTR("\r\nSend UIH Command with credit"), 0x80);
#endif #endif
sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send credit sendRfcommCredit(rfcommChannelConnection, rfcommDirection, 0, RFCOMM_UIH, 0x10, sizeof (rfcommDataBuffer)); // Send credit
@ -358,11 +358,11 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
waitForLastCommand = true; waitForLastCommand = true;
} }
} else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nReceived UIH Command with credit"), 0x80); Notify(PSTR("\r\nReceived UIH Command with credit"), 0x80);
#endif #endif
} else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command } else if (rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80); Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command"), 0x80);
#endif #endif
rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command rfcommbuf[0] = BT_RFCOMM_RPN_RSP; // Command
@ -376,7 +376,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
rfcommbuf[8] = l2capinbuf[19]; // MaxRatransm. rfcommbuf[8] = l2capinbuf[19]; // MaxRatransm.
rfcommbuf[9] = l2capinbuf[20]; // Number of Frames rfcommbuf[9] = l2capinbuf[20]; // Number of Frames
sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response sendRfcomm(rfcommChannel, rfcommDirection, 0, RFCOMM_UIH, rfcommPfBit, rfcommbuf, 0x0A); // UIH Remote Port Negotiation Response
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"), 0x80); Notify(PSTR("\r\nRFCOMM Connection is now established\r\n"), 0x80);
#endif #endif
waitForLastCommand = false; waitForLastCommand = false;
@ -384,7 +384,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
connected = true; // The RFCOMM channel is now established connected = true; // The RFCOMM channel is now established
sppIndex = 0; sppIndex = 0;
} }
#ifdef DEBUG #ifdef DEBUG_USB_HOST
else if (rfcommChannelType != RFCOMM_DISC) { else if (rfcommChannelType != RFCOMM_DISC) {
Notify(PSTR("\r\nUnsupported RFCOMM Data - ChannelType: "), 0x80); Notify(PSTR("\r\nUnsupported RFCOMM Data - ChannelType: "), 0x80);
PrintHex<uint8_t > (rfcommChannelType, 0x80); PrintHex<uint8_t > (rfcommChannelType, 0x80);
@ -409,7 +409,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) {
void SPP::Run() { void SPP::Run() {
if (waitForLastCommand && (millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it if (waitForLastCommand && (millis() - timer) > 100) { // We will only wait 100ms and see if the UIH Remote Port Negotiation Command is send, as some deviced don't send it
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80); Notify(PSTR("\r\nRFCOMM Connection is now established - Automatic\r\n"), 0x80);
#endif #endif
creditSent = false; creditSent = false;
@ -425,7 +425,7 @@ void SPP::SDP_task() {
case L2CAP_SDP_WAIT: case L2CAP_SDP_WAIT:
if (l2cap_connection_request_sdp_flag) { if (l2cap_connection_request_sdp_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_SDP_REQUEST; // Clear flag l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_SDP_REQUEST; // Clear flag
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSDP Incoming Connection Request"), 0x80); Notify(PSTR("\r\nSDP Incoming Connection Request"), 0x80);
#endif #endif
pBtd->l2cap_connection_response(hci_handle, identifier, sdp_dcid, sdp_scid, PENDING); pBtd->l2cap_connection_response(hci_handle, identifier, sdp_dcid, sdp_scid, PENDING);
@ -440,7 +440,7 @@ void SPP::SDP_task() {
case L2CAP_SDP_REQUEST: case L2CAP_SDP_REQUEST:
if (l2cap_config_request_sdp_flag) { if (l2cap_config_request_sdp_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_REQUEST; // Clear flag l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_REQUEST; // Clear flag
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSDP Configuration Request"), 0x80); Notify(PSTR("\r\nSDP Configuration Request"), 0x80);
#endif #endif
pBtd->l2cap_config_response(hci_handle, identifier, sdp_scid); pBtd->l2cap_config_response(hci_handle, identifier, sdp_scid);
@ -450,7 +450,7 @@ void SPP::SDP_task() {
case L2CAP_SDP_SUCCESS: case L2CAP_SDP_SUCCESS:
if (l2cap_config_success_sdp_flag) { if (l2cap_config_success_sdp_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_SUCCESS; // Clear flag l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_SDP_SUCCESS; // Clear flag
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSDP Successfully Configured"), 0x80); Notify(PSTR("\r\nSDP Successfully Configured"), 0x80);
#endif #endif
firstMessage = true; // Reset bool firstMessage = true; // Reset bool
@ -462,7 +462,7 @@ void SPP::SDP_task() {
if (l2cap_disconnect_request_sdp_flag) { if (l2cap_disconnect_request_sdp_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_SDP_REQUEST; // Clear flag l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_SDP_REQUEST; // Clear flag
SDPConnected = false; SDPConnected = false;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnected SDP Channel"), 0x80); Notify(PSTR("\r\nDisconnected SDP Channel"), 0x80);
#endif #endif
pBtd->l2cap_disconnection_response(hci_handle, identifier, sdp_dcid, sdp_scid); pBtd->l2cap_disconnection_response(hci_handle, identifier, sdp_dcid, sdp_scid);
@ -472,7 +472,7 @@ void SPP::SDP_task() {
break; break;
case L2CAP_DISCONNECT_RESPONSE: // This is for both disconnection response from the RFCOMM and SDP channel if they were connected case L2CAP_DISCONNECT_RESPONSE: // This is for both disconnection response from the RFCOMM and SDP channel if they were connected
if (l2cap_disconnect_response_flag) { if (l2cap_disconnect_response_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnected L2CAP Connection"), 0x80); Notify(PSTR("\r\nDisconnected L2CAP Connection"), 0x80);
#endif #endif
RFCOMMConnected = false; RFCOMMConnected = false;
@ -492,7 +492,7 @@ void SPP::RFCOMM_task() {
case L2CAP_RFCOMM_WAIT: case L2CAP_RFCOMM_WAIT:
if (l2cap_connection_request_rfcomm_flag) { if (l2cap_connection_request_rfcomm_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST; // Clear flag l2cap_event_flag &= ~L2CAP_FLAG_CONNECTION_RFCOMM_REQUEST; // Clear flag
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nRFCOMM Incoming Connection Request"), 0x80); Notify(PSTR("\r\nRFCOMM Incoming Connection Request"), 0x80);
#endif #endif
pBtd->l2cap_connection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid, PENDING); pBtd->l2cap_connection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid, PENDING);
@ -507,7 +507,7 @@ void SPP::RFCOMM_task() {
case L2CAP_RFCOMM_REQUEST: case L2CAP_RFCOMM_REQUEST:
if (l2cap_config_request_rfcomm_flag) { if (l2cap_config_request_rfcomm_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_REQUEST; // Clear flag l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_REQUEST; // Clear flag
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80); Notify(PSTR("\r\nRFCOMM Configuration Request"), 0x80);
#endif #endif
pBtd->l2cap_config_response(hci_handle, identifier, rfcomm_scid); pBtd->l2cap_config_response(hci_handle, identifier, rfcomm_scid);
@ -517,7 +517,7 @@ void SPP::RFCOMM_task() {
case L2CAP_RFCOMM_SUCCESS: case L2CAP_RFCOMM_SUCCESS:
if (l2cap_config_success_rfcomm_flag) { if (l2cap_config_success_rfcomm_flag) {
l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS; // Clear flag l2cap_event_flag &= ~L2CAP_FLAG_CONFIG_RFCOMM_SUCCESS; // Clear flag
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nRFCOMM Successfully Configured"), 0x80); Notify(PSTR("\r\nRFCOMM Successfully Configured"), 0x80);
#endif #endif
rfcommAvailable = 0; // Reset number of bytes available rfcommAvailable = 0; // Reset number of bytes available
@ -531,7 +531,7 @@ void SPP::RFCOMM_task() {
l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST; // Clear flag l2cap_event_flag &= ~L2CAP_FLAG_DISCONNECT_RFCOMM_REQUEST; // Clear flag
RFCOMMConnected = false; RFCOMMConnected = false;
connected = false; connected = false;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnected RFCOMM Channel"), 0x80); Notify(PSTR("\r\nDisconnected RFCOMM Channel"), 0x80);
#endif #endif
pBtd->l2cap_disconnection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid); pBtd->l2cap_disconnection_response(hci_handle, identifier, rfcomm_dcid, rfcomm_scid);

2
Usb.h
View file

@ -58,7 +58,7 @@ typedef MAX3421e<P20, P19> MAX3421E; // Balanduino
typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo etc.) typedef MAX3421e<P10, P9> MAX3421E; // Official Arduinos (UNO, Duemilanove, Mega, 2560, Leonardo etc.)
#endif #endif
//Debug macros. In 1.0 it is possible to move strings to PROGMEM by defining USBTRACE (Serial.print(F(s))) //Debug macros. In 1.0 it is possible to move strings to PROGMEM by defining USBTRACE (USB_HOST_SERIAL.print(F(s)))
#define USBTRACE(s) (Notify(PSTR(s), 0x80)) #define USBTRACE(s) (Notify(PSTR(s), 0x80))
#define USBTRACE2(s,r) (Notify(PSTR(s), 0x80), PrintHex((r), 0x80), Notify(PSTR("\r\n"), 0x80)) #define USBTRACE2(s,r) (Notify(PSTR(s), 0x80), PrintHex((r), 0x80), Notify(PSTR("\r\n"), 0x80))

102
Wii.cpp
View file

@ -20,7 +20,7 @@
*/ */
#include "Wii.h" #include "Wii.h"
#define DEBUG // Uncomment to print data for debugging // To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data //#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report send by the Wii controllers //#define PRINTREPORT // Uncomment to print the report send by the Wii controllers
@ -118,7 +118,7 @@ void WII::Reset() {
void WII::disconnect() { // Use this void to disconnect any of the controllers void WII::disconnect() { // Use this void to disconnect any of the controllers
if (motionPlusConnected && !pBtd->motionPlusInside) { // Disable the Motion Plus extension if (motionPlusConnected && !pBtd->motionPlusInside) { // Disable the Motion Plus extension
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDeactivating Motion Plus"), 0x80); Notify(PSTR("\r\nDeactivating Motion Plus"), 0x80);
#endif #endif
initExtension1(); // This will disable the Motion Plus extension initExtension1(); // This will disable the Motion Plus extension
@ -144,7 +144,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection if ((l2capinbuf[0] | (l2capinbuf[1] << 8)) == (hci_handle | 0x2000)) { // acl_handle_ok or it's a new connection
if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U if ((l2capinbuf[6] | (l2capinbuf[7] << 8)) == 0x0001) { //l2cap_control - Channel ID for ACL-U
if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) { if (l2capinbuf[8] == L2CAP_CMD_COMMAND_REJECT) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80); Notify(PSTR("\r\nL2CAP Command Rejected - Reason: "), 0x80);
PrintHex<uint8_t > (l2capinbuf[13], 0x80); PrintHex<uint8_t > (l2capinbuf[13], 0x80);
Notify(PSTR(" "), 0x80); Notify(PSTR(" "), 0x80);
@ -220,14 +220,14 @@ void WII::ACLData(uint8_t* l2capinbuf) {
} }
} else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) { } else if (l2capinbuf[8] == L2CAP_CMD_DISCONNECT_REQUEST) {
if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) { if (l2capinbuf[12] == control_dcid[0] && l2capinbuf[13] == control_dcid[1]) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80); Notify(PSTR("\r\nDisconnect Request: Control Channel"), 0x80);
#endif #endif
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid); pBtd->l2cap_disconnection_response(hci_handle, identifier, control_dcid, control_scid);
Reset(); Reset();
} else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) { } else if (l2capinbuf[12] == interrupt_dcid[0] && l2capinbuf[13] == interrupt_dcid[1]) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80); Notify(PSTR("\r\nDisconnect Request: Interrupt Channel"), 0x80);
#endif #endif
identifier = l2capinbuf[9]; identifier = l2capinbuf[9];
@ -294,12 +294,12 @@ void WII::ACLData(uint8_t* l2capinbuf) {
wiiState = l2capinbuf[12]; // (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4) wiiState = l2capinbuf[12]; // (0x01: Battery is nearly empty), (0x02: An Extension Controller is connected), (0x04: Speaker enabled), (0x08: IR enabled), (0x10: LED1, 0x20: LED2, 0x40: LED3, 0x80: LED4)
batteryLevel = l2capinbuf[15]; // Update battery level batteryLevel = l2capinbuf[15]; // Update battery level
if (l2capinbuf[12] & 0x01) { if (l2capinbuf[12] & 0x01) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80); Notify(PSTR("\r\nWARNING: Battery is nearly empty"), 0x80);
#endif #endif
} }
if (l2capinbuf[12] & 0x02) { // Check if a extension is connected if (l2capinbuf[12] & 0x02) { // Check if a extension is connected
#ifdef DEBUG #ifdef DEBUG_USB_HOST
if (!unknownExtensionConnected) if (!unknownExtensionConnected)
Notify(PSTR("\r\nExtension connected"), 0x80); Notify(PSTR("\r\nExtension connected"), 0x80);
#endif #endif
@ -309,11 +309,11 @@ void WII::ACLData(uint8_t* l2capinbuf) {
#endif #endif
setReportMode(false, 0x35); // Also read the extension setReportMode(false, 0x35); // Also read the extension
} else { } else {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nExtension disconnected"), 0x80); Notify(PSTR("\r\nExtension disconnected"), 0x80);
#endif #endif
if (motionPlusConnected) { if (motionPlusConnected) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR(" - from Motion Plus"), 0x80); Notify(PSTR(" - from Motion Plus"), 0x80);
#endif #endif
l2cap_event_flag &= ~WII_FLAG_NUNCHUCK_CONNECTED; l2cap_event_flag &= ~WII_FLAG_NUNCHUCK_CONNECTED;
@ -321,7 +321,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
nunchuckConnected = false; nunchuckConnected = false;
//else if(classicControllerConnected) //else if(classicControllerConnected)
} else if (nunchuckConnected) { } else if (nunchuckConnected) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR(" - Nunchuck"), 0x80); Notify(PSTR(" - Nunchuck"), 0x80);
#endif #endif
nunchuckConnected = false; // It must be the Nunchuck controller then nunchuckConnected = false; // It must be the Nunchuck controller then
@ -337,40 +337,40 @@ void WII::ACLData(uint8_t* l2capinbuf) {
if ((l2capinbuf[12] & 0x0F) == 0) { // No error if ((l2capinbuf[12] & 0x0F) == 0) { // No error
// See: http://wiibrew.org/wiki/Wiimote/Extension_Controllers // See: http://wiibrew.org/wiki/Wiimote/Extension_Controllers
if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) { if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x00) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nNunchuck connected"), 0x80); Notify(PSTR("\r\nNunchuck connected"), 0x80);
#endif #endif
l2cap_event_flag |= WII_FLAG_NUNCHUCK_CONNECTED; l2cap_event_flag |= WII_FLAG_NUNCHUCK_CONNECTED;
} else if (l2capinbuf[16] == 0x00 && (l2capinbuf[17] == 0xA6 || l2capinbuf[17] == 0xA4) && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x05) { } else if (l2capinbuf[16] == 0x00 && (l2capinbuf[17] == 0xA6 || l2capinbuf[17] == 0xA4) && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x00 && l2capinbuf[20] == 0x05) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nMotion Plus connected"), 0x80); Notify(PSTR("\r\nMotion Plus connected"), 0x80);
#endif #endif
l2cap_event_flag |= WII_FLAG_MOTION_PLUS_CONNECTED; l2cap_event_flag |= WII_FLAG_MOTION_PLUS_CONNECTED;
} else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x05) { } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x04 && l2capinbuf[20] == 0x05) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nMotion Plus activated in normal mode"), 0x80); Notify(PSTR("\r\nMotion Plus activated in normal mode"), 0x80);
#endif #endif
motionPlusConnected = true; motionPlusConnected = true;
} else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x05 && l2capinbuf[20] == 0x05) { } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x05 && l2capinbuf[20] == 0x05) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nMotion Plus activated in Nunchuck pass-through mode"), 0x80); Notify(PSTR("\r\nMotion Plus activated in Nunchuck pass-through mode"), 0x80);
#endif #endif
activateNunchuck = false; activateNunchuck = false;
motionPlusConnected = true; motionPlusConnected = true;
nunchuckConnected = true; nunchuckConnected = true;
} else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA6 && l2capinbuf[18] == 0x20 && (l2capinbuf[19] == 0x00 || l2capinbuf[19] == 0x04 || l2capinbuf[19] == 0x05 || l2capinbuf[19] == 0x07) && l2capinbuf[20] == 0x05) { } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA6 && l2capinbuf[18] == 0x20 && (l2capinbuf[19] == 0x00 || l2capinbuf[19] == 0x04 || l2capinbuf[19] == 0x05 || l2capinbuf[19] == 0x07) && l2capinbuf[20] == 0x05) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nInactive Wii Motion Plus"), 0x80); Notify(PSTR("\r\nInactive Wii Motion Plus"), 0x80);
Notify(PSTR("\r\nPlease unplug the Motion Plus, disconnect the Wiimote and then replug the Motion Plus Extension"), 0x80); Notify(PSTR("\r\nPlease unplug the Motion Plus, disconnect the Wiimote and then replug the Motion Plus Extension"), 0x80);
#endif #endif
stateCounter = 300; // Skip the rest in "L2CAP_CHECK_MOTION_PLUS_STATE" stateCounter = 300; // Skip the rest in "L2CAP_CHECK_MOTION_PLUS_STATE"
} else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x01 && l2capinbuf[20] == 0x20) { } else if (l2capinbuf[16] == 0x00 && l2capinbuf[17] == 0xA4 && l2capinbuf[18] == 0x20 && l2capinbuf[19] == 0x01 && l2capinbuf[20] == 0x20) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWii U Pro Controller connected"), 0x80); Notify(PSTR("\r\nWii U Pro Controller connected"), 0x80);
#endif #endif
wiiUProControllerConnected = true; wiiUProControllerConnected = true;
} }
#ifdef DEBUG #ifdef DEBUG_USB_HOST
else { else {
Notify(PSTR("\r\nUnknown Device: "), 0x80); Notify(PSTR("\r\nUnknown Device: "), 0x80);
PrintHex<uint8_t > (l2capinbuf[13], 0x80); PrintHex<uint8_t > (l2capinbuf[13], 0x80);
@ -392,7 +392,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
#endif #endif
break; break;
case 0x22: // Acknowledge output report, return function result case 0x22: // Acknowledge output report, return function result
#ifdef DEBUG #ifdef DEBUG_USB_HOST
if (l2capinbuf[13] != 0x00) { // Check if there is an error if (l2capinbuf[13] != 0x00) { // Check if there is an error
Notify(PSTR("\r\nCommand failed: "), 0x80); Notify(PSTR("\r\nCommand failed: "), 0x80);
PrintHex<uint8_t > (l2capinbuf[12], 0x80); PrintHex<uint8_t > (l2capinbuf[12], 0x80);
@ -496,7 +496,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
*/ */
} else { } else {
if ((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values if ((micros() - timer) > 1000000) { // Loop for 1 sec before resetting the values
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nThe gyro values has been reset"), 0x80); Notify(PSTR("\r\nThe gyro values has been reset"), 0x80);
#endif #endif
gyroYawZero = (l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6)); gyroYawZero = (l2capinbuf[15] | ((l2capinbuf[18] & 0xFC) << 6));
@ -531,7 +531,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
if (!extensionConnected) { if (!extensionConnected) {
extensionConnected = true; extensionConnected = true;
unknownExtensionConnected = true; unknownExtensionConnected = true;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nExtension connected to Motion Plus"), 0x80); Notify(PSTR("\r\nExtension connected to Motion Plus"), 0x80);
#endif #endif
} }
@ -539,7 +539,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
if (extensionConnected && !unknownExtensionConnected) { if (extensionConnected && !unknownExtensionConnected) {
extensionConnected = false; extensionConnected = false;
unknownExtensionConnected = true; unknownExtensionConnected = true;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nExtension disconnected from Motion Plus"), 0x80); Notify(PSTR("\r\nExtension disconnected from Motion Plus"), 0x80);
#endif #endif
nunchuckConnected = false; // There is no extension connected to the Motion Plus if this report is sent nunchuckConnected = false; // There is no extension connected to the Motion Plus if this report is sent
@ -564,7 +564,7 @@ void WII::ACLData(uint8_t* l2capinbuf) {
hatValues[RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8); hatValues[RightHatY] = (l2capinbuf[21] | l2capinbuf[22] << 8);
} }
break; break;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
default: default:
Notify(PSTR("\r\nUnknown Report type: "), 0x80); Notify(PSTR("\r\nUnknown Report type: "), 0x80);
PrintHex<uint8_t > (l2capinbuf[9], 0x80); PrintHex<uint8_t > (l2capinbuf[9], 0x80);
@ -583,7 +583,7 @@ void WII::L2CAP_task() {
/* These states are used if the Wiimote is the host */ /* These states are used if the Wiimote is the host */
case L2CAP_CONTROL_SUCCESS: case L2CAP_CONTROL_SUCCESS:
if (l2cap_config_success_control_flag) { if (l2cap_config_success_control_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80); Notify(PSTR("\r\nHID Control Successfully Configured"), 0x80);
#endif #endif
l2cap_state = L2CAP_INTERRUPT_SETUP; l2cap_state = L2CAP_INTERRUPT_SETUP;
@ -592,7 +592,7 @@ void WII::L2CAP_task() {
case L2CAP_INTERRUPT_SETUP: case L2CAP_INTERRUPT_SETUP:
if (l2cap_connection_request_interrupt_flag) { if (l2cap_connection_request_interrupt_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80); Notify(PSTR("\r\nHID Interrupt Incoming Connection Request"), 0x80);
#endif #endif
pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING); pBtd->l2cap_connection_response(hci_handle, identifier, interrupt_dcid, interrupt_scid, PENDING);
@ -609,7 +609,7 @@ void WII::L2CAP_task() {
/* These states are used if the Arduino is the host */ /* These states are used if the Arduino is the host */
case L2CAP_CONTROL_CONNECT_REQUEST: case L2CAP_CONTROL_CONNECT_REQUEST:
if (l2cap_connected_control_flag) { if (l2cap_connected_control_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSend HID Control Config Request"), 0x80); Notify(PSTR("\r\nSend HID Control Config Request"), 0x80);
#endif #endif
identifier++; identifier++;
@ -620,7 +620,7 @@ void WII::L2CAP_task() {
case L2CAP_CONTROL_CONFIG_REQUEST: case L2CAP_CONTROL_CONFIG_REQUEST:
if (l2cap_config_success_control_flag) { if (l2cap_config_success_control_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80); Notify(PSTR("\r\nSend HID Interrupt Connection Request"), 0x80);
#endif #endif
identifier++; identifier++;
@ -631,7 +631,7 @@ void WII::L2CAP_task() {
case L2CAP_INTERRUPT_CONNECT_REQUEST: case L2CAP_INTERRUPT_CONNECT_REQUEST:
if (l2cap_connected_interrupt_flag) { if (l2cap_connected_interrupt_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80); Notify(PSTR("\r\nSend HID Interrupt Config Request"), 0x80);
#endif #endif
identifier++; identifier++;
@ -642,7 +642,7 @@ void WII::L2CAP_task() {
case L2CAP_INTERRUPT_CONFIG_REQUEST: case L2CAP_INTERRUPT_CONFIG_REQUEST:
if (l2cap_config_success_interrupt_flag) { // Now the HID channels is established if (l2cap_config_success_interrupt_flag) { // Now the HID channels is established
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Channels Established"), 0x80); Notify(PSTR("\r\nHID Channels Established"), 0x80);
#endif #endif
pBtd->connectToWii = false; pBtd->connectToWii = false;
@ -657,7 +657,7 @@ void WII::L2CAP_task() {
case L2CAP_INTERRUPT_DISCONNECT: case L2CAP_INTERRUPT_DISCONNECT:
if (l2cap_disconnect_response_interrupt_flag) { if (l2cap_disconnect_response_interrupt_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80); Notify(PSTR("\r\nDisconnected Interrupt Channel"), 0x80);
#endif #endif
identifier++; identifier++;
@ -668,7 +668,7 @@ void WII::L2CAP_task() {
case L2CAP_CONTROL_DISCONNECT: case L2CAP_CONTROL_DISCONNECT:
if (l2cap_disconnect_response_control_flag) { if (l2cap_disconnect_response_control_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nDisconnected Control Channel"), 0x80); Notify(PSTR("\r\nDisconnected Control Channel"), 0x80);
#endif #endif
pBtd->hci_disconnect(hci_handle); pBtd->hci_disconnect(hci_handle);
@ -686,7 +686,7 @@ void WII::Run() {
if (pBtd->connectToWii && !pBtd->l2capConnectionClaimed && !wiimoteConnected && !activeConnection) { if (pBtd->connectToWii && !pBtd->l2capConnectionClaimed && !wiimoteConnected && !activeConnection) {
pBtd->l2capConnectionClaimed = true; pBtd->l2capConnectionClaimed = true;
activeConnection = true; activeConnection = true;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSend HID Control Connection Request"), 0x80); Notify(PSTR("\r\nSend HID Control Connection Request"), 0x80);
#endif #endif
hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection hci_handle = pBtd->hci_handle; // Store the HCI Handle for the connection
@ -695,7 +695,7 @@ void WII::Run() {
pBtd->l2cap_connection_request(hci_handle, identifier, control_dcid, HID_CTRL_PSM); pBtd->l2cap_connection_request(hci_handle, identifier, control_dcid, HID_CTRL_PSM);
l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST; l2cap_state = L2CAP_CONTROL_CONNECT_REQUEST;
} else if (l2cap_connection_request_control_flag) { } else if (l2cap_connection_request_control_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80); Notify(PSTR("\r\nHID Control Incoming Connection Request"), 0x80);
#endif #endif
pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING); pBtd->l2cap_connection_response(hci_handle, identifier, control_dcid, control_scid, PENDING);
@ -709,7 +709,7 @@ void WII::Run() {
break; break;
case L2CAP_CHECK_MOTION_PLUS_STATE: case L2CAP_CHECK_MOTION_PLUS_STATE:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
if (stateCounter == 0) // Only print onnce if (stateCounter == 0) // Only print onnce
Notify(PSTR("\r\nChecking if a Motion Plus is connected"), 0x80); Notify(PSTR("\r\nChecking if a Motion Plus is connected"), 0x80);
#endif #endif
@ -722,14 +722,14 @@ void WII::Run() {
timer = micros(); timer = micros();
if (unknownExtensionConnected) { if (unknownExtensionConnected) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nA extension is also connected"), 0x80); Notify(PSTR("\r\nA extension is also connected"), 0x80);
#endif #endif
activateNunchuck = true; // For we will just set this to true as this the only extension supported so far activateNunchuck = true; // For we will just set this to true as this the only extension supported so far
} }
} else if (stateCounter == 601) { // We will try three times to check for the motion plus } else if (stateCounter == 601) { // We will try three times to check for the motion plus
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nNo Motion Plus was detected"), 0x80); Notify(PSTR("\r\nNo Motion Plus was detected"), 0x80);
#endif #endif
stateCounter = 0; stateCounter = 0;
@ -738,7 +738,7 @@ void WII::Run() {
break; break;
case L2CAP_CHECK_EXTENSION_STATE: // This is used to check if there is anything plugged in to the extension port case L2CAP_CHECK_EXTENSION_STATE: // This is used to check if there is anything plugged in to the extension port
#ifdef DEBUG #ifdef DEBUG_USB_HOST
if (stateCounter == 0) // Only print onnce if (stateCounter == 0) // Only print onnce
Notify(PSTR("\r\nChecking if there is any extension connected"), 0x80); Notify(PSTR("\r\nChecking if there is any extension connected"), 0x80);
#endif #endif
@ -785,7 +785,7 @@ void WII::Run() {
case L2CAP_DONE: case L2CAP_DONE:
if (unknownExtensionConnected) { if (unknownExtensionConnected) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
if (stateCounter == 0) // Only print once if (stateCounter == 0) // Only print once
Notify(PSTR("\r\nChecking extension port"), 0x80); Notify(PSTR("\r\nChecking extension port"), 0x80);
#endif #endif
@ -803,7 +803,7 @@ void WII::Run() {
readExtensionType(); readExtensionType();
else if (stateCounter == 250) { else if (stateCounter == 250) {
if (nunchuck_connected_flag) { if (nunchuck_connected_flag) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nNunchuck was reconnected"), 0x80); Notify(PSTR("\r\nNunchuck was reconnected"), 0x80);
#endif #endif
activateNunchuck = true; activateNunchuck = true;
@ -813,7 +813,7 @@ void WII::Run() {
stateCounter = 449; stateCounter = 449;
} else if (stateCounter == 300) { } else if (stateCounter == 300) {
if (motionPlusConnected) { if (motionPlusConnected) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nReactivating the Motion Plus"), 0x80); Notify(PSTR("\r\nReactivating the Motion Plus"), 0x80);
#endif #endif
initMotionPlus(); initMotionPlus();
@ -967,19 +967,19 @@ void WII::initMotionPlus() {
void WII::activateMotionPlus() { void WII::activateMotionPlus() {
uint8_t buf[1]; uint8_t buf[1];
if (pBtd->wiiUProController) { if (pBtd->wiiUProController) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nActivating Wii U Pro Controller"), 0x80); Notify(PSTR("\r\nActivating Wii U Pro Controller"), 0x80);
#endif #endif
buf[0] = 0x00; // It seems like you can send anything but 0x04, 0x05, and 0x07 buf[0] = 0x00; // It seems like you can send anything but 0x04, 0x05, and 0x07
} else if (activateNunchuck) { } else if (activateNunchuck) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nActivating Motion Plus in pass-through mode"), 0x80); Notify(PSTR("\r\nActivating Motion Plus in pass-through mode"), 0x80);
#endif #endif
buf[0] = 0x05; // Activate nunchuck pass-through mode buf[0] = 0x05; // Activate nunchuck pass-through mode
} //else if(classicControllerConnected && extensionConnected) } //else if(classicControllerConnected && extensionConnected)
//buf[0] = 0x07; //buf[0] = 0x07;
else { else {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nActivating Motion Plus in normal mode"), 0x80); Notify(PSTR("\r\nActivating Motion Plus in normal mode"), 0x80);
#endif #endif
buf[0] = 0x04; // Don't use any extension buf[0] = 0x04; // Don't use any extension
@ -1071,58 +1071,58 @@ uint16_t WII::getAnalogHat(AnalogHat a) {
void WII::IRinitialize() { // Turns on and initialises the IR camera void WII::IRinitialize() { // Turns on and initialises the IR camera
enableIRCamera1(); enableIRCamera1();
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nEnable IR Camera1 Complete"), 0x80); Notify(PSTR("\r\nEnable IR Camera1 Complete"), 0x80);
#endif #endif
delay(80); delay(80);
enableIRCamera2(); enableIRCamera2();
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nEnable IR Camera2 Complete"), 0x80); Notify(PSTR("\r\nEnable IR Camera2 Complete"), 0x80);
#endif #endif
delay(80); delay(80);
write0x08Value(); write0x08Value();
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWrote hex number 0x08"), 0x80); Notify(PSTR("\r\nWrote hex number 0x08"), 0x80);
#endif #endif
delay(80); delay(80);
writeSensitivityBlock1(); writeSensitivityBlock1();
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWrote Sensitivity Block 1"), 0x80); Notify(PSTR("\r\nWrote Sensitivity Block 1"), 0x80);
#endif #endif
delay(80); delay(80);
writeSensitivityBlock2(); writeSensitivityBlock2();
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWrote Sensitivity Block 2"), 0x80); Notify(PSTR("\r\nWrote Sensitivity Block 2"), 0x80);
#endif #endif
delay(80); delay(80);
uint8_t mode_num = 0x03; uint8_t mode_num = 0x03;
setWiiModeNumber(mode_num); // Change input for whatever mode you want i.e. 0x01, 0x03, or 0x05 setWiiModeNumber(mode_num); // Change input for whatever mode you want i.e. 0x01, 0x03, or 0x05
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSet Wii Mode Number To 0x"), 0x80); Notify(PSTR("\r\nSet Wii Mode Number To 0x"), 0x80);
PrintHex<uint8_t > (mode_num, 0x80); PrintHex<uint8_t > (mode_num, 0x80);
#endif #endif
delay(80); delay(80);
write0x08Value(); write0x08Value();
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nWrote Hex Number 0x08"), 0x80); Notify(PSTR("\r\nWrote Hex Number 0x08"), 0x80);
#endif #endif
delay(80); delay(80);
setReportMode(false, 0x33); setReportMode(false, 0x33);
//setReportMode(false, 0x3f); // For full reporting mode, doesn't work yet //setReportMode(false, 0x3f); // For full reporting mode, doesn't work yet
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nSet Report Mode to 0x33"), 0x80); Notify(PSTR("\r\nSet Report Mode to 0x33"), 0x80);
#endif #endif
delay(80); delay(80);
statusRequest(); // Used to update wiiState - call isIRCameraEnabled() afterwards to check if it actually worked statusRequest(); // Used to update wiiState - call isIRCameraEnabled() afterwards to check if it actually worked
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nIR Initialized"), 0x80); Notify(PSTR("\r\nIR Initialized"), 0x80);
#endif #endif
} }

View file

@ -18,7 +18,7 @@
*/ */
#include "XBOXRECV.h" #include "XBOXRECV.h"
//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h // To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data //#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
@ -52,7 +52,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
#endif #endif
// check if address has already been assigned to an instance // check if address has already been assigned to an instance
if (bAddress) { if (bAddress) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nAddress in use"), 0x80); Notify(PSTR("\r\nAddress in use"), 0x80);
#endif #endif
return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
@ -62,14 +62,14 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
p = addrPool.GetUsbDevicePtr(0); p = addrPool.GetUsbDevicePtr(0);
if (!p) { if (!p) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nAddress not found"), 0x80); Notify(PSTR("\r\nAddress not found"), 0x80);
#endif #endif
return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
} }
if (!p->epinfo) { if (!p->epinfo) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nepinfo is null"), 0x80); Notify(PSTR("\r\nepinfo is null"), 0x80);
#endif #endif
return USB_ERROR_EPINFO_IS_NULL; return USB_ERROR_EPINFO_IS_NULL;
@ -97,7 +97,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
if (VID != XBOX_VID && VID != MADCATZ_VID) // We just check if it's a xbox receiver using the Vendor ID if (VID != XBOX_VID && VID != MADCATZ_VID) // We just check if it's a xbox receiver using the Vendor ID
goto FailUnknownDevice; goto FailUnknownDevice;
else if (PID != XBOX_WIRELESS_RECEIVER_PID && PID != XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) { else if (PID != XBOX_WIRELESS_RECEIVER_PID && PID != XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nYou'll need a wireless receiver for this libary to work"), 0x80); Notify(PSTR("\r\nYou'll need a wireless receiver for this libary to work"), 0x80);
#endif #endif
goto FailUnknownDevice; goto FailUnknownDevice;
@ -118,7 +118,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
p->lowspeed = false; p->lowspeed = false;
addrPool.FreeAddress(bAddress); addrPool.FreeAddress(bAddress);
bAddress = 0; bAddress = 0;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nsetAddr: "), 0x80); Notify(PSTR("\r\nsetAddr: "), 0x80);
PrintHex<uint8_t > (rcode, 0x80); PrintHex<uint8_t > (rcode, 0x80);
#endif #endif
@ -209,7 +209,7 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
if (rcode) if (rcode)
goto FailSetConfDescr; goto FailSetConfDescr;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nXbox Wireless Receiver Connected\r\n"), 0x80); Notify(PSTR("\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
#endif #endif
XboxReceiverConnected = true; XboxReceiverConnected = true;
@ -218,31 +218,31 @@ uint8_t XBOXRECV::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */ /* diagnostic messages */
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
#endif #endif
goto Fail; goto Fail;
FailUnknownDevice: FailUnknownDevice:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailUnknownDevice(VID,PID); NotifyFailUnknownDevice(VID,PID);
#endif #endif
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80); Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif
@ -304,12 +304,12 @@ void XBOXRECV::readReport(uint8_t controller) {
// This report is send when a controller is connected and disconnected // This report is send when a controller is connected and disconnected
if (readBuf[0] == 0x08 && readBuf[1] != Xbox360Connected[controller]) { if (readBuf[0] == 0x08 && readBuf[1] != Xbox360Connected[controller]) {
Xbox360Connected[controller] = readBuf[1]; Xbox360Connected[controller] = readBuf[1];
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("Controller "), 0x80); Notify(PSTR("Controller "), 0x80);
Notify(controller, 0x80); Notify(controller, 0x80);
#endif #endif
if (Xbox360Connected[controller]) { if (Xbox360Connected[controller]) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
char* str = 0; char* str = 0;
switch (readBuf[1]) { switch (readBuf[1]) {
case 0x80: str = PSTR(" as controller\r\n"); case 0x80: str = PSTR(" as controller\r\n");
@ -335,7 +335,7 @@ void XBOXRECV::readReport(uint8_t controller) {
} }
setLedOn(led, controller); setLedOn(led, controller);
} }
#ifdef DEBUG #ifdef DEBUG_USB_HOST
else else
Notify(PSTR(": disconnected\r\n"), 0x80); Notify(PSTR(": disconnected\r\n"), 0x80);
#endif #endif

View file

@ -16,7 +16,7 @@
*/ */
#include "XBOXUSB.h" #include "XBOXUSB.h"
//#define DEBUG // Uncomment to print data for debugging -- NO! see message.h // To enable serial debugging uncomment "#define DEBUG_USB_HOST" in message.h
//#define EXTRADEBUG // Uncomment to get even more debugging data //#define EXTRADEBUG // Uncomment to get even more debugging data
//#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
@ -50,7 +50,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
#endif #endif
// check if address has already been assigned to an instance // check if address has already been assigned to an instance
if (bAddress) { if (bAddress) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nAddress in use"), 0x80); Notify(PSTR("\r\nAddress in use"), 0x80);
#endif #endif
return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE;
@ -60,14 +60,14 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
p = addrPool.GetUsbDevicePtr(0); p = addrPool.GetUsbDevicePtr(0);
if (!p) { if (!p) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nAddress not found"), 0x80); Notify(PSTR("\r\nAddress not found"), 0x80);
#endif #endif
return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL;
} }
if (!p->epinfo) { if (!p->epinfo) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nepinfo is null"), 0x80); Notify(PSTR("\r\nepinfo is null"), 0x80);
#endif #endif
return USB_ERROR_EPINFO_IS_NULL; return USB_ERROR_EPINFO_IS_NULL;
@ -95,12 +95,12 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
if (VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) // We just check if it's a xbox controller using the Vendor ID if (VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) // We just check if it's a xbox controller using the Vendor ID
goto FailUnknownDevice; goto FailUnknownDevice;
if (PID == XBOX_WIRELESS_PID) { if (PID == XBOX_WIRELESS_PID) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80); Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80);
#endif #endif
goto FailUnknownDevice; goto FailUnknownDevice;
} else if (PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) { } else if (PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"), 0x80); Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB"), 0x80);
#endif #endif
goto FailUnknownDevice; goto FailUnknownDevice;
@ -121,7 +121,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
p->lowspeed = false; p->lowspeed = false;
addrPool.FreeAddress(bAddress); addrPool.FreeAddress(bAddress);
bAddress = 0; bAddress = 0;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nsetAddr: "), 0x80); Notify(PSTR("\r\nsetAddr: "), 0x80);
#endif #endif
PrintHex<uint8_t > (rcode, 0x80); PrintHex<uint8_t > (rcode, 0x80);
@ -173,7 +173,7 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
if (rcode) if (rcode)
goto FailSetConfDescr; goto FailSetConfDescr;
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nXbox 360 Controller Connected\r\n"), 0x80); Notify(PSTR("\r\nXbox 360 Controller Connected\r\n"), 0x80);
#endif #endif
setLedOn(LED1); setLedOn(LED1);
@ -183,30 +183,30 @@ uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */ /* diagnostic messages */
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailUnknownDevice: FailUnknownDevice:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailUnknownDevice(VID, PID); NotifyFailUnknownDevice(VID, PID);
#endif #endif
rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED;
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80); Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif

View file

@ -194,7 +194,7 @@ public:
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub = false, uint8_t port = 0) { virtual uint8_t AllocAddress(uint8_t parent, bool is_hub = false, uint8_t port = 0) {
/* if (parent != 0 && port == 0) /* if (parent != 0 && port == 0)
Serial.println("PRT:0"); */ USB_HOST_SERIAL.println("PRT:0"); */
if(parent > 127 || port > 7) if(parent > 127 || port > 7)
return 0; return 0;
@ -231,12 +231,12 @@ public:
} }
thePool[index].address = *((uint8_t*) & addr); thePool[index].address = *((uint8_t*) & addr);
/* /*
Serial.print("Addr:"); USB_HOST_SERIAL.print("Addr:");
Serial.print(addr.bmHub, HEX); USB_HOST_SERIAL.print(addr.bmHub, HEX);
Serial.print("."); USB_HOST_SERIAL.print(".");
Serial.print(addr.bmParent, HEX); USB_HOST_SERIAL.print(addr.bmParent, HEX);
Serial.print("."); USB_HOST_SERIAL.print(".");
Serial.println(addr.bmAddress, HEX); USB_HOST_SERIAL.println(addr.bmAddress, HEX);
*/ */
return thePool[index].address; return thePool[index].address;
}; };

14
adk.cpp
View file

@ -227,43 +227,43 @@ uint8_t ADK::Init(uint8_t parent, uint8_t port, bool lowspeed) {
/* diagnostic messages */ /* diagnostic messages */
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailGetConfDescr: FailGetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetConfDescr(); NotifyFailGetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailGetProto: FailGetProto:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("\r\ngetProto:"); USBTRACE("\r\ngetProto:");
goto Fail; goto Fail;
#endif #endif
FailSwAcc: FailSwAcc:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("\r\nswAcc:"); USBTRACE("\r\nswAcc:");
goto Fail; goto Fail;
#endif #endif
SwAttempt: SwAttempt:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("\r\nAccessory mode switch attempt"); USBTRACE("\r\nAccessory mode switch attempt");
#endif #endif
//FailOnInit: //FailOnInit:

View file

@ -20,7 +20,7 @@ e-mail : support@circuitsathome.com
#ifndef _avrpins_h_ #ifndef _avrpins_h_
#define _avrpins_h_ #define _avrpins_h_
#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) #if defined(__AVR_ATmega2560__)
/* Uncomment the following if you have Arduino Mega ADK board with MAX3421e built-in */ /* Uncomment the following if you have Arduino Mega ADK board with MAX3421e built-in */
//#define BOARD_MEGA_ADK //#define BOARD_MEGA_ADK
#endif #endif
@ -448,7 +448,7 @@ public:
//typedef Tp_Tc<Pb3, Tc2a> P11; //Arduino pin 11 //typedef Tp_Tc<Pb3, Tc2a> P11; //Arduino pin 11
/* Arduino pin definitions */ /* Arduino pin definitions */
#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
// "Mega" Arduino pin numbers // "Mega" Arduino pin numbers
@ -512,7 +512,7 @@ public:
#define P53 Pb0 #define P53 Pb0
#define P54 Pe6 // INT on Arduino ADK #define P54 Pe6 // INT on Arduino ADK
#endif //"Mega" pin numbers #endif // "Mega" pin numbers
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
//"Classic" Arduino pin numbers //"Classic" Arduino pin numbers

View file

@ -183,36 +183,36 @@ uint8_t ACM::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0; return 0;
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailGetConfDescr: FailGetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetConfDescr(); NotifyFailGetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailOnInit: FailOnInit:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("OnInit:"); USBTRACE("OnInit:");
#endif #endif
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif
Release(); Release();
@ -288,7 +288,7 @@ uint8_t ACM::Poll() {
// for (uint8_t i=0; i<read; i++) // for (uint8_t i=0; i<read; i++)
// { // {
// PrintHex<uint8_t>(buf[i]); // PrintHex<uint8_t>(buf[i]);
// Serial.print(" "); // USB_HOST_SERIAL.print(" ");
// } // }
// USBTRACE("\r\n"); // USBTRACE("\r\n");
//} //}

View file

@ -178,36 +178,36 @@ uint8_t FTDI::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0; return 0;
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailGetConfDescr: FailGetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetConfDescr(); NotifyFailGetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailOnInit: FailOnInit:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("OnInit:"); USBTRACE("OnInit:");
#endif #endif
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif
Release(); Release();
@ -259,7 +259,7 @@ uint8_t FTDI::Poll() {
//if (qNextPollTime <= millis()) //if (qNextPollTime <= millis())
//{ //{
// Serial.println(bAddress, HEX); // USB_HOST_SERIAL.println(bAddress, HEX);
// qNextPollTime = millis() + 100; // qNextPollTime = millis() + 100;
//} //}

View file

@ -155,36 +155,36 @@ uint8_t PL2303::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0; return 0;
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailGetConfDescr: FailGetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetConfDescr(); NotifyFailGetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailOnInit: FailOnInit:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("OnInit:"); USBTRACE("OnInit:");
#endif #endif
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif
Release(); Release();
@ -200,7 +200,7 @@ Fail:
// //
// //if (qNextPollTime <= millis()) // //if (qNextPollTime <= millis())
// //{ // //{
// // Serial.println(bAddress, HEX); // // USB_HOST_SERIAL.println(bAddress, HEX);
// //
// // qNextPollTime = millis() + 100; // // qNextPollTime = millis() + 100;
// //} // //}

View file

@ -8,18 +8,13 @@
#include <PS3BT.h> #include <PS3BT.h>
USB Usb; USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
PS3BT PS3_1(&Btd); PS3BT* PS3[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
PS3BT PS3_2(&Btd);
//PS3BT PS3_3(&Btd); // You can create as many instances as you like, but it will take up a lot of RAM!!
PS3BT* PS3[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like
const uint8_t length = sizeof(PS3)/sizeof(PS3[0]); // Get the lenght of the array const uint8_t length = sizeof(PS3)/sizeof(PS3[0]); // Get the lenght of the array
boolean printAngle[length]; boolean printAngle[length];
void setup() { void setup() {
PS3[0] = &PS3_1; // This will point to the first controller for(uint8_t i=0;i<length;i++)
PS3[1] = &PS3_2; // This will point to the second controller PS3[i] = new PS3BT(&Btd); // Create the instances
//PS3[2] = &PS3_3; // You only need to uncomment this if you wanted to use another controller
Serial.begin(115200); Serial.begin(115200);
if (Usb.Init() == -1) { if (Usb.Init() == -1) {
@ -32,7 +27,6 @@ void loop() {
Usb.Task(); Usb.Task();
for(uint8_t i=0;i<length;i++) { for(uint8_t i=0;i<length;i++) {
if(!PS3[i]) continue; // Skip if it hasn't been defined
if(PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) { if(PS3[i]->PS3Connected || PS3[i]->PS3NavigationConnected) {
if(PS3[i]->getAnalogHat(LeftHatX) > 137 || PS3[i]->getAnalogHat(LeftHatX) < 117 || PS3[i]->getAnalogHat(LeftHatY) > 137 || PS3[i]->getAnalogHat(LeftHatY) < 117 || PS3[i]->getAnalogHat(RightHatX) > 137 || PS3[i]->getAnalogHat(RightHatX) < 117 || PS3[i]->getAnalogHat(RightHatY) > 137 || PS3[i]->getAnalogHat(RightHatY) < 117) { if(PS3[i]->getAnalogHat(LeftHatX) > 137 || PS3[i]->getAnalogHat(LeftHatX) < 117 || PS3[i]->getAnalogHat(LeftHatY) > 137 || PS3[i]->getAnalogHat(LeftHatY) < 117 || PS3[i]->getAnalogHat(RightHatX) > 137 || PS3[i]->getAnalogHat(RightHatX) < 117 || PS3[i]->getAnalogHat(RightHatY) > 137 || PS3[i]->getAnalogHat(RightHatY) < 117) {
Serial.print(F("\r\nLeftHatX: ")); Serial.print(F("\r\nLeftHatX: "));

View file

@ -7,24 +7,14 @@
#include <SPP.h> #include <SPP.h>
USB Usb; USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
SPP* SerialBT[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
// This will set the name to the defaults: "Arduino" and the pin to "1234" for both connections
SPP SPP_1(&Btd); // This will allow you to communicate with two SPP devices simultaneously
SPP SPP_2(&Btd);
//SPP SPP_3(&Btd); // You can create as many instances as you like, but it will take up a lot of RAM!!
// You can also set the name and pin like so
//SPP SerialBT(&Btd, "Lauszus's Arduino","0000");
SPP* SerialBT[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like
const uint8_t length = sizeof(SerialBT)/sizeof(SerialBT[0]); // Get the lenght of the array const uint8_t length = sizeof(SerialBT)/sizeof(SerialBT[0]); // Get the lenght of the array
boolean firstMessage[length] = { true }; // Set all to true boolean firstMessage[length] = { true }; // Set all to true
uint8_t buffer[50]; uint8_t buffer[50];
void setup() { void setup() {
SerialBT[0] = &SPP_1; // This will point to the first instance for(uint8_t i=0;i<length;i++)
SerialBT[1] = &SPP_2; // This will point to the second instance SerialBT[i] = new SPP(&Btd); // This will set the name to the default: "Arduino" and the pin to "1234" for all connections
//SerialBT[2] = &SPP_3; // You only need to uncomment this if you wanted to use another instance
Serial.begin(115200); Serial.begin(115200);
if (Usb.Init() == -1) { if (Usb.Init() == -1) {
@ -51,7 +41,7 @@ void loop() {
if(Serial.available()) { if(Serial.available()) {
delay(10); // Wait for the rest of the data to arrive delay(10); // Wait for the rest of the data to arrive
uint8_t i = 0; uint8_t i = 0;
while(Serial.available()) // Read the data while(Serial.available() && i < sizeof(buffer)) // Read the data
buffer[i++] = Serial.read(); buffer[i++] = Serial.read();
/* /*
Set the connection you want to send to using the first character Set the connection you want to send to using the first character

View file

@ -8,19 +8,13 @@
#include <Wii.h> #include <Wii.h>
USB Usb; USB Usb;
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
//WII Wii(&Btd,PAIR); // You will have to pair each controller with the dongle before you can define the instances like below WII* Wii[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like, but it will use a lot of RAM!
WII Wii_1(&Btd);
WII Wii_2(&Btd);
//WII Wii_3(&Btd); // You can create as many instances as you like, but it will take up a lot of RAM!!
WII* Wii[2]; // We will use this pointer to store the two instance, you can easily make it larger if you like
const uint8_t length = sizeof(Wii)/sizeof(Wii[0]); // Get the lenght of the array const uint8_t length = sizeof(Wii)/sizeof(Wii[0]); // Get the lenght of the array
bool printAngle[length]; bool printAngle[length];
void setup() { void setup() {
Wii[0] = &Wii_1; for(uint8_t i=0;i<length;i++)
Wii[1] = &Wii_2; Wii[i] = new WII(&Btd); // You will have to pair each controller with the dongle before you can define the instances like so, just add PAIR as the second argument
//Wii[2] = &Wii_3; // You only need to uncomment this if you wanted to use another controller
Serial.begin(115200); Serial.begin(115200);
if (Usb.Init() == -1) { if (Usb.Init() == -1) {
@ -33,7 +27,6 @@ void loop() {
Usb.Task(); Usb.Task();
for(uint8_t i=0;i<length;i++) { for(uint8_t i=0;i<length;i++) {
if(!Wii[i]) continue; // Skip if it hasn't been defined
if(Wii[i]->wiimoteConnected) { if(Wii[i]->wiimoteConnected) {
if(Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down if(Wii[i]->getButtonClick(HOME)) { // You can use getButtonPress to see if the button is held down
Serial.print(F("\r\nHOME")); Serial.print(F("\r\nHOME"));

View file

@ -1,64 +0,0 @@
/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
This software may be distributed and modified under the terms of the GNU
General Public License version 2 (GPL2) as published by the Free Software
Foundation and appearing in the file GPL2.TXT included in the packaging of
this file. Please note that GPL2 Section 2[b] requires that all works based
on this software must also be made publicly available under the terms of
the GPL2 ("Copyleft").
Contact information
-------------------
Circuits At Home, LTD
Web : http://www.circuitsathome.com
e-mail : support@circuitsathome.com
*/
#if !defined(__HEXDUMP_H__)
#define __HEXDUMP_H__
#include <inttypes.h>
#include <avr/pgmspace.h>
#include "printhex.h"
#include "message.h"
extern int UsbDEBUGlvl;
template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
class HexDumper : public BASE_CLASS {
uint8_t byteCount;
OFFSET_TYPE byteTotal;
public:
HexDumper() : byteCount(0), byteTotal(0) {
};
void Initialize() {
byteCount = 0;
byteTotal = 0;
};
virtual void Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset);
};
template <class BASE_CLASS, class LEN_TYPE, class OFFSET_TYPE>
void HexDumper<BASE_CLASS, LEN_TYPE, OFFSET_TYPE>::Parse(const LEN_TYPE len, const uint8_t *pbuf, const OFFSET_TYPE &offset) {
if(UsbDEBUGlvl >= 0x80) { // Fully bypass this block of code if we do not debug.
for(LEN_TYPE j = 0; j < len; j++, byteCount++, byteTotal++) {
if(!byteCount) {
PrintHex<OFFSET_TYPE > (byteTotal, 0x80);
E_Notify(PSTR(": "), 0x80);
}
PrintHex<uint8_t > (pbuf[j], 0x80);
E_Notify(PSTR(" "), 0x80);
if(byteCount == 15) {
E_Notify(PSTR("\r\n"), 0x80);
byteCount = 0xFF;
}
}
}
}
#endif // __HEXDUMP_H__

View file

@ -393,42 +393,42 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Init(uint8_t parent, uint8_t port, bool lowspeed
return 0; return 0;
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailGetConfDescr: FailGetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetConfDescr(); NotifyFailGetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailSetProtocol: FailSetProtocol:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("SetProto:"); USBTRACE("SetProto:");
goto Fail; goto Fail;
#endif #endif
FailSetIdle: FailSetIdle:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("SetIdle:"); USBTRACE("SetIdle:");
#endif #endif
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif
Release(); Release();
@ -497,7 +497,7 @@ uint8_t HIDBoot<BOOT_PROTOCOL>::Poll() {
//for (uint8_t i=0; i<read; i++) //for (uint8_t i=0; i<read; i++)
// PrintHex<uint8_t>(buf[i]); // PrintHex<uint8_t>(buf[i]);
//if (read) //if (read)
// Serial.println(""); // USB_HOST_SERIAL.println("");
if(pRptParser) if(pRptParser)
pRptParser->Parse((HID*)this, 0, (uint8_t) read, buf); pRptParser->Parse((HID*)this, 0, (uint8_t) read, buf);

View file

@ -981,9 +981,9 @@ void ReportDescParserBase::Parse(const uint16_t len, const uint8_t *pbuf, const
totalSize = 0; totalSize = 0;
while (cntdn) { while (cntdn) {
//Serial.println(""); //USB_HOST_SERIAL.println("");
//PrintHex<uint16_t>(offset + len - cntdn); //PrintHex<uint16_t>(offset + len - cntdn);
//Serial.print(":"); //USB_HOST_SERIAL.print(":");
ParseItem(&p, &cntdn); ParseItem(&p, &cntdn);
@ -1267,7 +1267,7 @@ void ReportDescParserBase::PrintButtonPageUsage(uint16_t usage) {
Notify(PSTR("Btn"), 0x80); Notify(PSTR("Btn"), 0x80);
PrintHex<uint16_t > (usage, 0x80); PrintHex<uint16_t > (usage, 0x80);
Notify(PSTR("\r\n"), 0x80); Notify(PSTR("\r\n"), 0x80);
//Serial.print(usage, HEX); //USB_HOST_SERIAL.print(usage, HEX);
} }
void ReportDescParserBase::PrintOrdinalPageUsage(uint16_t usage) { void ReportDescParserBase::PrintOrdinalPageUsage(uint16_t usage) {
@ -1276,7 +1276,7 @@ void ReportDescParserBase::PrintOrdinalPageUsage(uint16_t usage) {
// Sorry, HEX for now... // Sorry, HEX for now...
PrintHex<uint16_t > (usage, 0x80); PrintHex<uint16_t > (usage, 0x80);
Notify(PSTR("\r\n"), 0x80); Notify(PSTR("\r\n"), 0x80);
//Serial.print(usage, DEC); //USB_HOST_SERIAL.print(usage, DEC);
} }
void ReportDescParserBase::PrintGenericDesktopPageUsage(uint16_t usage) { void ReportDescParserBase::PrintGenericDesktopPageUsage(uint16_t usage) {

View file

@ -221,37 +221,37 @@ uint8_t HIDUniversal::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0; return 0;
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(); NotifyFailGetDevDescr();
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailGetConfDescr: FailGetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetConfDescr(); NotifyFailGetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailSetIdle: FailSetIdle:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("SetIdle:"); USBTRACE("SetIdle:");
#endif #endif
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif
Release(); Release();

View file

@ -174,7 +174,7 @@ uint8_t BulkOnly::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET; return USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET;
FailGetDevDescr: FailGetDevDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetDevDescr(rcode); NotifyFailGetDevDescr(rcode);
#endif #endif
rcode = USB_ERROR_FailGetDevDescr; rcode = USB_ERROR_FailGetDevDescr;
@ -362,42 +362,42 @@ uint8_t BulkOnly::Init(uint8_t parent, uint8_t port, bool lowspeed) {
return 0; return 0;
FailSetConfDescr: FailSetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetConfDescr(); NotifyFailSetConfDescr();
goto Fail; goto Fail;
#endif #endif
FailOnInit: FailOnInit:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("OnInit:"); USBTRACE("OnInit:");
goto Fail; goto Fail;
#endif #endif
FailGetMaxLUN: FailGetMaxLUN:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("GetMaxLUN:"); USBTRACE("GetMaxLUN:");
goto Fail; goto Fail;
#endif #endif
FailInvalidSectorSize: FailInvalidSectorSize:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
USBTRACE("Sector Size is NOT VALID: "); USBTRACE("Sector Size is NOT VALID: ");
goto Fail; goto Fail;
#endif #endif
FailSetDevTblEntry: FailSetDevTblEntry:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailSetDevTblEntry(); NotifyFailSetDevTblEntry();
goto Fail; goto Fail;
#endif #endif
FailGetConfDescr: FailGetConfDescr:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFailGetConfDescr(); NotifyFailGetConfDescr();
#endif #endif
Fail: Fail:
#ifdef DEBUG #ifdef DEBUG_USB_HOST
NotifyFail(rcode); NotifyFail(rcode);
#endif #endif
Release(); Release();
@ -498,14 +498,8 @@ uint8_t BulkOnly::ClearEpHalt(uint8_t index) {
} }
uint8_t BulkOnly::Reset() { uint8_t BulkOnly::Reset() {
uint8_t r;
while (pUsb->ctrlReq(bAddress, 0, bmREQ_MASSOUT, MASS_REQ_BOMSR, 0, 0, bIface, 0, 0, NULL, NULL) == 0x01) delay(6); while (pUsb->ctrlReq(bAddress, 0, bmREQ_MASSOUT, MASS_REQ_BOMSR, 0, 0, bIface, 0, 0, NULL, NULL) == 0x01) delay(6);
#if 0 return 0;
if (r) {
printf("Reset error %2.2X\r\n", r);
}
#endif
return r;
} }
uint8_t BulkOnly::ResetRecovery() { uint8_t BulkOnly::ResetRecovery() {

View file

@ -24,11 +24,11 @@ int UsbDEBUGlvl = 0x80;
void E_Notifyc(char c, int lvl) { void E_Notifyc(char c, int lvl) {
if (UsbDEBUGlvl < lvl) return; if (UsbDEBUGlvl < lvl) return;
#if defined(ARDUINO) && ARDUINO >=100 #if defined(ARDUINO) && ARDUINO >=100
Serial.print(c); USB_HOST_SERIAL.print(c);
#else #else
Serial.print(c, BYTE); USB_HOST_SERIAL.print(c, BYTE);
#endif #endif
Serial.flush(); //USB_HOST_SERIAL.flush();
} }
void E_Notify(char const * msg, int lvl) { void E_Notify(char const * msg, int lvl) {
@ -50,20 +50,20 @@ void E_NotifyStr(char const * msg, int lvl) {
void E_Notify(uint8_t b, int lvl) { void E_Notify(uint8_t b, int lvl) {
if (UsbDEBUGlvl < lvl) return; if (UsbDEBUGlvl < lvl) return;
#if defined(ARDUINO) && ARDUINO >=100 #if defined(ARDUINO) && ARDUINO >=100
Serial.print(b); USB_HOST_SERIAL.print(b);
#else #else
Serial.print(b, DEC); USB_HOST_SERIAL.print(b, DEC);
#endif #endif
Serial.flush(); //USB_HOST_SERIAL.flush();
} }
void E_Notify(double d, int lvl) { void E_Notify(double d, int lvl) {
if (UsbDEBUGlvl < lvl) return; if (UsbDEBUGlvl < lvl) return;
Serial.print(d); USB_HOST_SERIAL.print(d);
Serial.flush(); //USB_HOST_SERIAL.flush();
} }
#ifdef DEBUG #ifdef DEBUG_USB_HOST
void NotifyFailGetDevDescr(void) { void NotifyFailGetDevDescr(void) {
Notify(PSTR("\r\ngetDevDescr"), 0x80); Notify(PSTR("\r\ngetDevDescr"), 0x80);
} }

View file

@ -18,7 +18,12 @@ e-mail : support@circuitsathome.com
#define __MESSAGE_H__ #define __MESSAGE_H__
// uncomment to activate // uncomment to activate
//#define DEBUG //#define DEBUG_USB_HOST
#ifndef USB_HOST_SERIAL
#define USB_HOST_SERIAL Serial
#endif
#include <inttypes.h> #include <inttypes.h>
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
@ -31,7 +36,7 @@ void E_Notify(uint8_t b, int lvl);
void E_NotifyStr(char const * msg, int lvl); void E_NotifyStr(char const * msg, int lvl);
void E_Notifyc(char c, int lvl); void E_Notifyc(char c, int lvl);
#ifdef DEBUG #ifdef DEBUG_USB_HOST
#define Notify E_Notify #define Notify E_Notify
#define NotifyStr E_NotifyStr #define NotifyStr E_NotifyStr
#define Notifyc E_Notifyc #define Notifyc E_Notifyc
@ -61,7 +66,7 @@ void NotifyFail(uint8_t rcode);
template <class ERROR_TYPE> template <class ERROR_TYPE>
void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) { void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(msg, level); Notify(msg, level);
Notify(PSTR(": "), level); Notify(PSTR(": "), level);
PrintHex<ERROR_TYPE > (rcode, level); PrintHex<ERROR_TYPE > (rcode, level);
@ -71,7 +76,7 @@ void ErrorMessage(uint8_t level, char const * msg, ERROR_TYPE rcode = 0) {
template <class ERROR_TYPE> template <class ERROR_TYPE>
void ErrorMessage(char const * msg, ERROR_TYPE rcode = 0) { void ErrorMessage(char const * msg, ERROR_TYPE rcode = 0) {
#ifdef DEBUG #ifdef DEBUG_USB_HOST
Notify(msg, 0x80); Notify(msg, 0x80);
Notify(PSTR(": "), 0x80); Notify(PSTR(": "), 0x80);
PrintHex<ERROR_TYPE > (rcode, 0x80); PrintHex<ERROR_TYPE > (rcode, 0x80);

View file

@ -1,80 +0,0 @@
/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
This software may be distributed and modified under the terms of the GNU
General Public License version 2 (GPL2) as published by the Free Software
Foundation and appearing in the file GPL2.TXT included in the packaging of
this file. Please note that GPL2 Section 2[b] requires that all works based
on this software must also be made publicly available under the terms of
the GPL2 ("Copyleft").
Contact information
-------------------
Circuits At Home, LTD
Web : http://www.circuitsathome.com
e-mail : support@circuitsathome.com
*/
#if !defined(__PRINTHEX_H__)
#define __PRINTHEX_H__
#if defined(ARDUINO) && ARDUINO >=100
#include "Arduino.h"
#else
#include <WProgram.h>
#endif
void E_Notifyc(char c, int lvl);
template <class T>
void PrintHex(T val, int lvl) {
//#ifdef DEBUG
int num_nibbles = sizeof(T) * 2;
do {
char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f);
if(v > 57) v += 7;
E_Notifyc(v, lvl);
} while(--num_nibbles);
//#endif
}
template <class T>
void PrintBin(T val, int lvl) {
//#ifdef DEBUG
for(T mask = (((T) 1) << ((sizeof(T) << 3) - 1)); mask; mask >>= 1)
if(val & mask)
E_Notifyc('1', lvl);
else
E_Notifyc('0', lvl);
//#endif
}
template <class T>
void SerialPrintHex(T val) {
//#ifdef DEBUG
int num_nibbles = sizeof(T) * 2;
do {
char v = 48 + (((val >> (num_nibbles - 1) * 4)) & 0x0f);
if(v > 57) v += 7;
Serial.print(v);
} while(--num_nibbles);
//#endif
}
template <class T>
void PrintHex2(Print *prn, T val) {
//#ifdef DEBUG
T mask = (((T) 1) << (((sizeof(T) << 1) - 1) << 2));
while(mask > 1) {
if(val < mask)
prn->print("0");
mask >>= 4;
}
prn->print((T) val, HEX);
//#endif
}
#endif // __PRINTHEX_H__

View file

@ -273,8 +273,8 @@ template< typename SS, typename INTR >
uint8_t MAX3421e< SS, INTR >::Task(void) { uint8_t MAX3421e< SS, INTR >::Task(void) {
uint8_t rcode = 0; uint8_t rcode = 0;
uint8_t pinvalue; uint8_t pinvalue;
//Serial.print("Vbus state: "); //USB_HOST_SERIAL.print("Vbus state: ");
//Serial.println( vbusState, HEX ); //USB_HOST_SERIAL.println( vbusState, HEX );
pinvalue = INTR::IsSet(); //Read(); pinvalue = INTR::IsSet(); //Read();
//pinvalue = digitalRead( MAX_INT ); //pinvalue = digitalRead( MAX_INT );
if(pinvalue == 0) { if(pinvalue == 0) {

View file

@ -247,8 +247,8 @@ uint8_t USBHub::CheckHubStatus() {
//rcode = GetHubStatus(1, 0, 1, 4, buf); //rcode = GetHubStatus(1, 0, 1, 4, buf);
//if (rcode) //if (rcode)
//{ //{
// Serial.print("GetHubStatus Error"); // USB_HOST_SERIAL.print("GetHubStatus Error");
// Serial.println(rcode, HEX); // USB_HOST_SERIAL.println(rcode, HEX);
// return rcode; // return rcode;
//} //}
} }
@ -350,46 +350,46 @@ void PrintHubPortStatus(USBHub *hubptr, uint8_t addr, uint8_t port, bool print_c
rcode = hubptr->GetPortStatus(port, 4, evt.evtBuff); rcode = hubptr->GetPortStatus(port, 4, evt.evtBuff);
if (rcode) { if (rcode) {
Serial.println("ERROR!"); USB_HOST_SERIAL.println("ERROR!");
return; return;
} }
Serial.print("\r\nPort "); USB_HOST_SERIAL.print("\r\nPort ");
Serial.println(port, DEC); USB_HOST_SERIAL.println(port, DEC);
Serial.println("Status"); USB_HOST_SERIAL.println("Status");
Serial.print("CONNECTION:\t"); USB_HOST_SERIAL.print("CONNECTION:\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_CONNECTION) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_CONNECTION) > 0, DEC);
Serial.print("ENABLE:\t\t"); USB_HOST_SERIAL.print("ENABLE:\t\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_ENABLE) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_ENABLE) > 0, DEC);
Serial.print("SUSPEND:\t"); USB_HOST_SERIAL.print("SUSPEND:\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_SUSPEND) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_SUSPEND) > 0, DEC);
Serial.print("OVER_CURRENT:\t"); USB_HOST_SERIAL.print("OVER_CURRENT:\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_OVER_CURRENT) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_OVER_CURRENT) > 0, DEC);
Serial.print("RESET:\t\t"); USB_HOST_SERIAL.print("RESET:\t\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_RESET) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_RESET) > 0, DEC);
Serial.print("POWER:\t\t"); USB_HOST_SERIAL.print("POWER:\t\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_POWER) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_POWER) > 0, DEC);
Serial.print("LOW_SPEED:\t"); USB_HOST_SERIAL.print("LOW_SPEED:\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_LOW_SPEED) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_LOW_SPEED) > 0, DEC);
Serial.print("HIGH_SPEED:\t"); USB_HOST_SERIAL.print("HIGH_SPEED:\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_HIGH_SPEED) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_HIGH_SPEED) > 0, DEC);
Serial.print("TEST:\t\t"); USB_HOST_SERIAL.print("TEST:\t\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_TEST) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_TEST) > 0, DEC);
Serial.print("INDICATOR:\t"); USB_HOST_SERIAL.print("INDICATOR:\t");
Serial.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_INDICATOR) > 0, DEC); USB_HOST_SERIAL.println((evt.bmStatus & bmHUB_PORT_STATUS_PORT_INDICATOR) > 0, DEC);
if (!print_changes) if (!print_changes)
return; return;
Serial.println("\r\nChange"); USB_HOST_SERIAL.println("\r\nChange");
Serial.print("CONNECTION:\t"); USB_HOST_SERIAL.print("CONNECTION:\t");
Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_CONNECTION) > 0, DEC); USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_CONNECTION) > 0, DEC);
Serial.print("ENABLE:\t\t"); USB_HOST_SERIAL.print("ENABLE:\t\t");
Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_ENABLE) > 0, DEC); USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_ENABLE) > 0, DEC);
Serial.print("SUSPEND:\t"); USB_HOST_SERIAL.print("SUSPEND:\t");
Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_SUSPEND) > 0, DEC); USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_SUSPEND) > 0, DEC);
Serial.print("OVER_CURRENT:\t"); USB_HOST_SERIAL.print("OVER_CURRENT:\t");
Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_OVER_CURRENT) > 0, DEC); USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_OVER_CURRENT) > 0, DEC);
Serial.print("RESET:\t\t"); USB_HOST_SERIAL.print("RESET:\t\t");
Serial.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_RESET) > 0, DEC); USB_HOST_SERIAL.println((evt.bmChange & bmHUB_PORT_STATUS_C_PORT_RESET) > 0, DEC);
} }