Added EXTRADEBUG

This commit is contained in:
Kristian Lauszus 2012-04-11 16:48:55 +02:00
parent f6aef14619
commit a90c2ab4da
2 changed files with 63 additions and 41 deletions

View file

@ -17,6 +17,7 @@
#include "PS3BT.h" #include "PS3BT.h"
#define DEBUG // Uncomment to print data for debugging #define DEBUG // Uncomment to print data for debugging
//#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
const uint8_t PS3BT::BTD_EVENT_PIPE = 1; const uint8_t PS3BT::BTD_EVENT_PIPE = 1;
@ -74,9 +75,9 @@ uint8_t PS3BT::Init(uint8_t parent, uint8_t port, bool lowspeed)
// get memory address of USB device address pool // get memory address of USB device address pool
AddressPool &addrPool = pUsb->GetAddressPool(); AddressPool &addrPool = pUsb->GetAddressPool();
#ifdef EXTRADEBUG
//Notify(PSTR("\r\nPS3BT Init"); Notify(PSTR("\r\nPS3BT Init"));
#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)
{ {
@ -144,9 +145,10 @@ uint8_t PS3BT::Init(uint8_t parent, uint8_t port, bool lowspeed)
PrintHex<uint8_t>(rcode); PrintHex<uint8_t>(rcode);
return rcode; return rcode;
} }
//Notify(PSTR("\r\nAddr: ")); #ifdef EXTRADEBUG
//PrintHex<uint8_t>(bAddress); Notify(PSTR("\r\nAddr: "));
PrintHex<uint8_t>(bAddress);
#endif
p->lowspeed = false; p->lowspeed = false;
//get pointer to assigned address record //get pointer to assigned address record
@ -202,7 +204,9 @@ uint8_t PS3BT::Init(uint8_t parent, uint8_t port, bool lowspeed)
} // for (uint8_t i=0; i<num_of_conf; i++... } // for (uint8_t i=0; i<num_of_conf; i++...
if (bNumEP < PS3_MAX_ENDPOINTS) { if (bNumEP < PS3_MAX_ENDPOINTS) {
#ifdef DEBUG
Notify(PSTR("\r\nBluetooth dongle is not supported")); Notify(PSTR("\r\nBluetooth dongle is not supported"));
#endif
goto Fail; goto Fail;
} }
@ -254,7 +258,6 @@ uint8_t PS3BT::Init(uint8_t parent, uint8_t port, bool lowspeed)
delay(200);//Give time for address change delay(200);//Give time for address change
rcode = pUsb->setConf(bAddress, epInfo[ PS3_CONTROL_PIPE ].epAddr, 1); rcode = pUsb->setConf(bAddress, epInfo[ PS3_CONTROL_PIPE ].epAddr, 1);
if( rcode ) if( rcode )
goto FailSetConf; goto FailSetConf;
@ -349,7 +352,9 @@ void PS3BT::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t pro
//Fill the rest of endpoint data structure //Fill the rest of endpoint data structure
epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F); epInfo[index].epAddr = (pep->bEndpointAddress & 0x0F);
epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize; epInfo[index].maxPktSize = (uint8_t)pep->wMaxPacketSize;
//PrintEndpointDescriptor(pep); #ifdef EXTRADEBUG
PrintEndpointDescriptor(pep);
#endif
if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints if(pollInterval < pep->bInterval) // Set the polling interval as the largest polling interval obtained from endpoints
pollInterval = pep->bInterval; pollInterval = pep->bInterval;
bNumEP++; bNumEP++;
@ -357,7 +362,7 @@ void PS3BT::EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t pro
} }
void PS3BT::PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr ) void PS3BT::PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr )
{ {
Notify(PSTR("Endpoint descriptor:")); Notify(PSTR("\r\nEndpoint descriptor:"));
Notify(PSTR("\r\nLength:\t\t")); Notify(PSTR("\r\nLength:\t\t"));
PrintHex<uint8_t>(ep_ptr->bLength); PrintHex<uint8_t>(ep_ptr->bLength);
Notify(PSTR("\r\nType:\t\t")); Notify(PSTR("\r\nType:\t\t"));
@ -370,7 +375,6 @@ void PS3BT::PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr )
PrintHex<uint16_t>(ep_ptr->wMaxPacketSize); PrintHex<uint16_t>(ep_ptr->wMaxPacketSize);
Notify(PSTR("\r\nPoll Intrv:\t")); Notify(PSTR("\r\nPoll Intrv:\t"));
PrintHex<uint8_t>(ep_ptr->bInterval); PrintHex<uint8_t>(ep_ptr->bInterval);
Notify(PSTR("\r\n"));
} }
/* Performs a cleanup after failed Init() attempt */ /* Performs a cleanup after failed Init() attempt */
@ -715,31 +719,42 @@ void PS3BT::HCI_event_task()
hci_event_flag |= HCI_FLAG_INCOMING_REQUEST; hci_event_flag |= HCI_FLAG_INCOMING_REQUEST;
break; break;
/* We will just ignore the following events */
case EV_ROLE_CHANGED: case EV_ROLE_CHANGED:
/* break;
#ifdef DEBUG
Notify(PSTR("\r\nRole Changed")); case EV_PAGE_SCAN_REP_MODE:
#endif break;
*/
case EV_LOOPBACK_COMMAND:
break;
case EV_DATA_BUFFER_OVERFLOW:
break;
case EV_CHANGE_CONNECTION_LINK:
break;
case EV_AUTHENTICATION_COMPLETE:
break; break;
default: default:
/* #ifdef EXTRADEBUG
#ifdef DEBUG
if(hcibuf[0] != 0x00) if(hcibuf[0] != 0x00)
{ {
Notify(PSTR("\r\nUnmanaged Event: ")); Notify(PSTR("\r\nUnmanaged Event: "));
PrintHex<uint8_t>(hcibuf[0]); PrintHex<uint8_t>(hcibuf[0]);
} }
#endif #endif
*/
break; break;
} // switch } // switch
HCI_task(); HCI_task();
} }
else { else {
#ifdef EXTRADEBUG
Notify(PSTR("\r\nHCI event error: ")); Notify(PSTR("\r\nHCI event error: "));
PrintHex<uint8_t>(rcode); PrintHex<uint8_t>(rcode);
#endif
} }
} }
@ -888,8 +903,8 @@ void PS3BT::HCI_task()
for (uint8_t i = 0; i < OUTPUT_REPORT_BUFFER_SIZE; i++) for (uint8_t i = 0; i < OUTPUT_REPORT_BUFFER_SIZE; i++)
HIDBuffer[i + 2] = pgm_read_byte(&OUTPUT_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID HIDBuffer[i + 2] = pgm_read_byte(&OUTPUT_REPORT_BUFFER[i]); // First two bytes reserved for report type and ID
for (uint8_t i = 2; i < HID_BUFFERSIZE; i++) for (uint8_t i = 0; i < OUTPUT_REPORT_BUFFER_SIZE; i++)
HIDMoveBuffer[i] = 0; HIDMoveBuffer[i + 2] = 0; // First two bytes reserved for report type and ID
l2cap_state = L2CAP_EV_WAIT; l2cap_state = L2CAP_EV_WAIT;
hci_state = HCI_SCANNING_STATE; hci_state = HCI_SCANNING_STATE;
@ -937,7 +952,7 @@ void PS3BT::ACL_event_task()
else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST) else if (l2capinbuf[8] == L2CAP_CMD_CONNECTION_REQUEST)
{ {
/* /*
Notify(PSTR("\r\nPSM: ")); Notify(PSTR("\r\nL2CAP Connection Request - PSM: "));
PrintHex<uint8_t>(l2capinbuf[13]); PrintHex<uint8_t>(l2capinbuf[13]);
Serial.print(" "); Serial.print(" ");
PrintHex<uint8_t>(l2capinbuf[12]); PrintHex<uint8_t>(l2capinbuf[12]);
@ -1050,8 +1065,10 @@ void PS3BT::ACL_event_task()
} }
} }
else { else {
#ifdef EXTRADEBUG
Notify(PSTR("\r\nACL data in error: ")); Notify(PSTR("\r\nACL data in error: "));
PrintHex<uint8_t>(rcode); PrintHex<uint8_t>(rcode);
#endif
} }
} }
void PS3BT::L2CAP_task() void PS3BT::L2CAP_task()

View file

@ -101,6 +101,11 @@
#define EV_REMOTE_NAME_COMPLETE 0x07 #define EV_REMOTE_NAME_COMPLETE 0x07
#define EV_INCOMING_CONNECT 0x04 #define EV_INCOMING_CONNECT 0x04
#define EV_ROLE_CHANGED 0x12 #define EV_ROLE_CHANGED 0x12
#define EV_PAGE_SCAN_REP_MODE 0x20
#define EV_DATA_BUFFER_OVERFLOW 0x1A
#define EV_LOOPBACK_COMMAND 0x19
#define EV_CHANGE_CONNECTION_LINK 0x09
#define EV_AUTHENTICATION_COMPLETE 0x06
/* Bluetooth L2CAP states for L2CAP_task() */ /* Bluetooth L2CAP states for L2CAP_task() */
#define L2CAP_EV_WAIT 0 #define L2CAP_EV_WAIT 0