USB Host Shield 2.0
XBOXRECV.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved.
2 
3  This software may be distributed and modified under the terms of the GNU
4  General Public License version 2 (GPL2) as published by the Free Software
5  Foundation and appearing in the file GPL2.TXT included in the packaging of
6  this file. Please note that GPL2 Section 2[b] requires that all works based
7  on this software must also be made publicly available under the terms of
8  the GPL2 ("Copyleft").
9 
10  Contact information
11  -------------------
12 
13  Kristian Lauszus, TKJ Electronics
14  Web : http://www.tkjelectronics.com
15  e-mail : kristianl@tkjelectronics.com
16 
17  getBatteryLevel and checkStatus functions made by timstamp.co.uk found using BusHound from Perisoft.net
18  */
19 
20 #include "XBOXRECV.h"
21 // To enable serial debugging see "settings.h"
22 //#define EXTRADEBUG // Uncomment to get even more debugging data
23 //#define PRINTREPORT // Uncomment to print the report send by the Xbox 360 Controller
24 
26 pUsb(p), // pointer to USB class instance - mandatory
27 bAddress(0), // device address - mandatory
28 bPollEnable(false) { // don't start polling before dongle is connected
29  for(uint8_t i = 0; i < XBOX_MAX_ENDPOINTS; i++) {
30  epInfo[i].epAddr = 0;
31  epInfo[i].maxPktSize = (i) ? 0 : 8;
32  epInfo[i].bmSndToggle = 0;
33  epInfo[i].bmRcvToggle = 0;
35  }
36 
37  if(pUsb) // register in USB subsystem
38  pUsb->RegisterDeviceClass(this); //set devConfig[] entry
39 }
40 
41 uint8_t XBOXRECV::ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed) {
42  const uint8_t constBufSize = sizeof (USB_DEVICE_DESCRIPTOR);
43  uint8_t buf[constBufSize];
44  USB_DEVICE_DESCRIPTOR * udd = reinterpret_cast<USB_DEVICE_DESCRIPTOR*>(buf);
45  uint8_t rcode;
46  UsbDevice *p = NULL;
47  EpInfo *oldep_ptr = NULL;
48  uint16_t PID, VID;
49 
50  AddressPool &addrPool = pUsb->GetAddressPool(); // Get memory address of USB device address pool
51 #ifdef EXTRADEBUG
52  Notify(PSTR("\r\nXBOXRECV Init"), 0x80);
53 #endif
54 
55  if(bAddress) { // Check if address has already been assigned to an instance
56 #ifdef DEBUG_USB_HOST
57  Notify(PSTR("\r\nAddress in use"), 0x80);
58 #endif
60  }
61 
62  p = addrPool.GetUsbDevicePtr(0); // Get pointer to pseudo device with address 0 assigned
63 
64  if(!p) {
65 #ifdef DEBUG_USB_HOST
66  Notify(PSTR("\r\nAddress not found"), 0x80);
67 #endif
69  }
70 
71  if(!p->epinfo) {
72 #ifdef DEBUG_USB_HOST
73  Notify(PSTR("\r\nepinfo is null"), 0x80);
74 #endif
76  }
77 
78  oldep_ptr = p->epinfo; // Save old pointer to EP_RECORD of address 0
79  p->epinfo = epInfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence
80  p->lowspeed = lowspeed;
81 
82  rcode = pUsb->getDevDescr(0, 0, constBufSize, (uint8_t*)buf); // Get device descriptor - addr, ep, nbytes, data
83 
84  p->epinfo = oldep_ptr; // Restore p->epinfo
85 
86  if(rcode)
87  goto FailGetDevDescr;
88 
89  VID = udd->idVendor;
90  PID = udd->idProduct;
91 
92  if((VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) || (PID != XBOX_WIRELESS_RECEIVER_PID_1 && PID != XBOX_WIRELESS_RECEIVER_PID_2 && PID != XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID)) { // Check if it's a Xbox receiver using the Vendor ID and Product ID
93 #ifdef DEBUG_USB_HOST
94  Notify(PSTR("\r\nYou'll need a wireless receiver for this libary to work"), 0x80);
95 #endif
96  goto FailUnknownDevice;
97  }
98 
99  bAddress = addrPool.AllocAddress(parent, false, port); // Allocate new address according to device class
100 
101  if(!bAddress) {
102 #ifdef DEBUG_USB_HOST
103  Notify(PSTR("\r\nOut of address space"), 0x80);
104 #endif
106  }
107 
108  epInfo[0].maxPktSize = udd->bMaxPacketSize0; // Extract Max Packet Size from device descriptor
109 
110  delay(20); // Wait a little before resetting device
111 
113 
114  /* Diagnostic messages */
115 FailGetDevDescr:
116 #ifdef DEBUG_USB_HOST
117  NotifyFailGetDevDescr(rcode);
118 #endif
119  if(rcode != hrJERR)
121  goto Fail;
122 
123 FailUnknownDevice:
124 #ifdef DEBUG_USB_HOST
125  NotifyFailUnknownDevice(VID, PID);
126 #endif
128 
129 Fail:
130 #ifdef DEBUG_USB_HOST
131  Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
132  NotifyFail(rcode);
133 #endif
134  Release();
135  return rcode;
136 };
137 
138 uint8_t XBOXRECV::Init(uint8_t parent __attribute__((unused)), uint8_t port __attribute__((unused)), bool lowspeed) {
139  uint8_t rcode;
140 
141  AddressPool &addrPool = pUsb->GetAddressPool();
142 #ifdef EXTRADEBUG
143  Notify(PSTR("\r\nBTD Init"), 0x80);
144 #endif
145  UsbDevice *p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
146 
147  if(!p) {
148 #ifdef DEBUG_USB_HOST
149  Notify(PSTR("\r\nAddress not found"), 0x80);
150 #endif
152  }
153 
154  delay(300); // Assign new address to the device
155 
156  rcode = pUsb->setAddr(0, 0, bAddress); // Assign new address to the device
157  if(rcode) {
158 #ifdef DEBUG_USB_HOST
159  Notify(PSTR("\r\nsetAddr: "), 0x80);
160  D_PrintHex<uint8_t > (rcode, 0x80);
161 #endif
162  p->lowspeed = false;
163  goto Fail;
164  }
165 #ifdef EXTRADEBUG
166  Notify(PSTR("\r\nAddr: "), 0x80);
167  D_PrintHex<uint8_t > (bAddress, 0x80);
168 #endif
169 
170  p->lowspeed = false;
171 
172  p = addrPool.GetUsbDevicePtr(bAddress); // Get pointer to assigned address record
173  if(!p) {
174 #ifdef DEBUG_USB_HOST
175  Notify(PSTR("\r\nAddress not found"), 0x80);
176 #endif
178  }
179 
180  p->lowspeed = lowspeed;
181 
182  rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); // Assign epInfo to epinfo pointer - only EP0 is known
183  if(rcode)
184  goto FailSetDevTblEntry;
185 
186  /* The application will work in reduced host mode, so we can save program and data
187  memory space. After verifying the VID we will use known values for the
188  configuration values for device, interface, endpoints and HID for the XBOX360 Wireless receiver */
189 
190  /* Initialize data structures for endpoints of device */
191  epInfo[ XBOX_INPUT_PIPE_1 ].epAddr = 0x01; // XBOX 360 report endpoint - poll interval 1ms
193  epInfo[ XBOX_INPUT_PIPE_1 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
197  epInfo[ XBOX_OUTPUT_PIPE_1 ].epAddr = 0x01; // XBOX 360 output endpoint - poll interval 8ms
199  epInfo[ XBOX_OUTPUT_PIPE_1 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
203 
204  epInfo[ XBOX_INPUT_PIPE_2 ].epAddr = 0x03; // XBOX 360 report endpoint - poll interval 1ms
206  epInfo[ XBOX_INPUT_PIPE_2 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
210  epInfo[ XBOX_OUTPUT_PIPE_2 ].epAddr = 0x03; // XBOX 360 output endpoint - poll interval 8ms
212  epInfo[ XBOX_OUTPUT_PIPE_2 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
216 
217  epInfo[ XBOX_INPUT_PIPE_3 ].epAddr = 0x05; // XBOX 360 report endpoint - poll interval 1ms
219  epInfo[ XBOX_INPUT_PIPE_3 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
223  epInfo[ XBOX_OUTPUT_PIPE_3 ].epAddr = 0x05; // XBOX 360 output endpoint - poll interval 8ms
225  epInfo[ XBOX_OUTPUT_PIPE_3 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
229 
230  epInfo[ XBOX_INPUT_PIPE_4 ].epAddr = 0x07; // XBOX 360 report endpoint - poll interval 1ms
232  epInfo[ XBOX_INPUT_PIPE_4 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
236  epInfo[ XBOX_OUTPUT_PIPE_4 ].epAddr = 0x07; // XBOX 360 output endpoint - poll interval 8ms
238  epInfo[ XBOX_OUTPUT_PIPE_4 ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints
242 
243  rcode = pUsb->setEpInfoEntry(bAddress, 9, epInfo);
244  if(rcode)
245  goto FailSetDevTblEntry;
246 
247  delay(200); //Give time for address change
248 
249  rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1);
250  if(rcode)
251  goto FailSetConfDescr;
252 
253 #ifdef DEBUG_USB_HOST
254  Notify(PSTR("\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
255 #endif
256  XboxReceiverConnected = true;
257  bPollEnable = true;
258  checkStatusTimer = 0; // Reset timer
259  return 0; // Successful configuration
260 
261  /* Diagnostic messages */
262 FailSetDevTblEntry:
263 #ifdef DEBUG_USB_HOST
265  goto Fail;
266 #endif
267 
268 FailSetConfDescr:
269 #ifdef DEBUG_USB_HOST
271 #endif
272 
273 Fail:
274 #ifdef DEBUG_USB_HOST
275  Notify(PSTR("\r\nXbox 360 Init Failed, error code: "), 0x80);
276  NotifyFail(rcode);
277 #endif
278  Release();
279  return rcode;
280 }
281 
282 /* Performs a cleanup after failed Init() attempt */
283 uint8_t XBOXRECV::Release() {
284  XboxReceiverConnected = false;
285  for(uint8_t i = 0; i < 4; i++)
286  Xbox360Connected[i] = 0x00;
288  bAddress = 0;
289  bPollEnable = false;
290  return 0;
291 }
292 
293 uint8_t XBOXRECV::Poll() {
294  if(!bPollEnable)
295  return 0;
296  if(!checkStatusTimer || ((int32_t)((uint32_t)millis() - checkStatusTimer) > 3000)) { // Run checkStatus every 3 seconds
297  checkStatusTimer = (uint32_t)millis();
298  checkStatus();
299  }
300 
301  uint8_t inputPipe;
302  uint16_t bufferSize;
303  for(uint8_t i = 0; i < 4; i++) {
304  if(i == 0)
305  inputPipe = XBOX_INPUT_PIPE_1;
306  else if(i == 1)
307  inputPipe = XBOX_INPUT_PIPE_2;
308  else if(i == 2)
309  inputPipe = XBOX_INPUT_PIPE_3;
310  else
311  inputPipe = XBOX_INPUT_PIPE_4;
312 
313  bufferSize = EP_MAXPKTSIZE; // This is the maximum number of bytes we want to receive
314  pUsb->inTransfer(bAddress, epInfo[ inputPipe ].epAddr, &bufferSize, readBuf);
315  if(bufferSize > 0) { // The number of received bytes
316 #ifdef EXTRADEBUG
317  Notify(PSTR("Bytes Received: "), 0x80);
318  D_PrintHex<uint16_t > (bufferSize, 0x80);
319  Notify(PSTR("\r\n"), 0x80);
320 #endif
321  readReport(i);
322 #ifdef PRINTREPORT
323  printReport(i, bufferSize); // Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
324 #endif
325  }
326  }
327  return 0;
328 }
329 
330 void XBOXRECV::readReport(uint8_t controller) {
331  if(readBuf == NULL)
332  return;
333  // This report is send when a controller is connected and disconnected
334  if(readBuf[0] == 0x08 && readBuf[1] != Xbox360Connected[controller]) {
335  Xbox360Connected[controller] = readBuf[1];
336 #ifdef DEBUG_USB_HOST
337  Notify(PSTR("Controller "), 0x80);
338  Notify(controller, 0x80);
339 #endif
340  if(Xbox360Connected[controller]) {
341 #ifdef DEBUG_USB_HOST
342  const char* str = 0;
343  switch(readBuf[1]) {
344  case 0x80: str = PSTR(" as controller\r\n");
345  break;
346  case 0x40: str = PSTR(" as headset\r\n");
347  break;
348  case 0xC0: str = PSTR(" as controller+headset\r\n");
349  break;
350  }
351  Notify(PSTR(": connected"), 0x80);
352  Notify(str, 0x80);
353 #endif
354  onInit(controller);
355  }
356 #ifdef DEBUG_USB_HOST
357  else
358  Notify(PSTR(": disconnected\r\n"), 0x80);
359 #endif
360  return;
361  }
362  // Controller status report
363  if(readBuf[1] == 0x00 && readBuf[3] & 0x13 && readBuf[4] >= 0x22) {
364  controllerStatus[controller] = ((uint16_t)readBuf[3] << 8) | readBuf[4];
365  return;
366  }
367  if(readBuf[1] != 0x01) // Check if it's the correct report - the receiver also sends different status reports
368  return;
369 
370  // A controller must be connected if it's sending data
371  if(!Xbox360Connected[controller])
372  Xbox360Connected[controller] |= 0x80;
373 
374  ButtonState[controller] = (uint32_t)(readBuf[9] | ((uint16_t)readBuf[8] << 8) | ((uint32_t)readBuf[7] << 16) | ((uint32_t)readBuf[6] << 24));
375 
376  hatValue[controller][LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
377  hatValue[controller][LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
378  hatValue[controller][RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
379  hatValue[controller][RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
380 
381  //Notify(PSTR("\r\nButtonState: "), 0x80);
382  //PrintHex<uint32_t>(ButtonState[controller], 0x80);
383 
384  if(ButtonState[controller] != OldButtonState[controller]) {
385  buttonStateChanged[controller] = true;
386  ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16); // Update click state variable, but don't include the two trigger buttons L2 and R2
387  if(((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0) // The L2 and R2 buttons are special as they are analog buttons
388  R2Clicked[controller] = true;
389  if((uint8_t)(OldButtonState[controller] >> 8) == 0 && (uint8_t)(ButtonState[controller] >> 8) != 0)
390  L2Clicked[controller] = true;
391  OldButtonState[controller] = ButtonState[controller];
392  }
393 }
394 
395 void XBOXRECV::printReport(uint8_t controller __attribute__((unused)), uint8_t nBytes __attribute__((unused))) { //Uncomment "#define PRINTREPORT" to print the report send by the Xbox 360 Controller
396 #ifdef PRINTREPORT
397  if(readBuf == NULL)
398  return;
399  Notify(PSTR("Controller "), 0x80);
400  Notify(controller, 0x80);
401  Notify(PSTR(": "), 0x80);
402  for(uint8_t i = 0; i < nBytes; i++) {
403  D_PrintHex<uint8_t > (readBuf[i], 0x80);
404  Notify(PSTR(" "), 0x80);
405  }
406  Notify(PSTR("\r\n"), 0x80);
407 #endif
408 }
409 
410 uint8_t XBOXRECV::getButtonPress(ButtonEnum b, uint8_t controller) {
411  const int8_t index = getButtonIndexXbox(b); if (index < 0) return 0;
412  if(index == ButtonIndex(L2)) // These are analog buttons
413  return (uint8_t)(ButtonState[controller] >> 8);
414  else if(index == ButtonIndex(R2))
415  return (uint8_t)ButtonState[controller];
416  return (bool)(ButtonState[controller] & ((uint32_t)pgm_read_word(&XBOX_BUTTONS[index]) << 16));
417 }
418 
419 bool XBOXRECV::getButtonClick(ButtonEnum b, uint8_t controller) {
420  const int8_t index = getButtonIndexXbox(b); if (index < 0) return 0;
421  if(index == ButtonIndex(L2)) {
422  if(L2Clicked[controller]) {
423  L2Clicked[controller] = false;
424  return true;
425  }
426  return false;
427  } else if(index == ButtonIndex(R2)) {
428  if(R2Clicked[controller]) {
429  R2Clicked[controller] = false;
430  return true;
431  }
432  return false;
433  }
434  uint16_t button = pgm_read_word(&XBOX_BUTTONS[index]);
435  bool click = (ButtonClickState[controller] & button);
436  ButtonClickState[controller] &= ~button; // clear "click" event
437  return click;
438 }
439 
440 int16_t XBOXRECV::getAnalogHat(AnalogHatEnum a, uint8_t controller) {
441  return hatValue[controller][a];
442 }
443 
444 bool XBOXRECV::buttonChanged(uint8_t controller) {
445  bool state = buttonStateChanged[controller];
446  buttonStateChanged[controller] = false;
447  return state;
448 }
449 
450 /*
451 ControllerStatus Breakdown
452 ControllerStatus[controller] & 0x0001 // 0
453 ControllerStatus[controller] & 0x0002 // normal batteries, no rechargeable battery pack
454 ControllerStatus[controller] & 0x0004 // controller starting up / settling
455 ControllerStatus[controller] & 0x0008 // headset adapter plugged in, but no headphones connected (mute?)
456 ControllerStatus[controller] & 0x0010 // 0
457 ControllerStatus[controller] & 0x0020 // 1
458 ControllerStatus[controller] & 0x0040 // battery level (high bit)
459 ControllerStatus[controller] & 0x0080 // battery level (low bit)
460 ControllerStatus[controller] & 0x0100 // 1
461 ControllerStatus[controller] & 0x0200 // 1
462 ControllerStatus[controller] & 0x0400 // headset adapter plugged in
463 ControllerStatus[controller] & 0x0800 // 0
464 ControllerStatus[controller] & 0x1000 // 1
465 ControllerStatus[controller] & 0x2000 // 0
466 ControllerStatus[controller] & 0x4000 // 0
467 ControllerStatus[controller] & 0x8000 // 0
468  */
469 uint8_t XBOXRECV::getBatteryLevel(uint8_t controller) {
470  return ((controllerStatus[controller] & 0x00C0) >> 6);
471 }
472 
473 void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
474 #ifdef EXTRADEBUG
475  uint8_t rcode;
476 #endif
477  uint8_t outputPipe;
478  switch(controller) {
479  case 0: outputPipe = XBOX_OUTPUT_PIPE_1;
480  break;
481  case 1: outputPipe = XBOX_OUTPUT_PIPE_2;
482  break;
483  case 2: outputPipe = XBOX_OUTPUT_PIPE_3;
484  break;
485  case 3: outputPipe = XBOX_OUTPUT_PIPE_4;
486  break;
487  default:
488  return;
489  }
490 #ifdef EXTRADEBUG
491  rcode =
492 #endif
493  pUsb->outTransfer(bAddress, epInfo[ outputPipe ].epAddr, nbytes, data);
494 #ifdef EXTRADEBUG
495  if(rcode)
496  Notify(PSTR("Error sending Xbox message\r\n"), 0x80);
497 #endif
498 }
499 
500 void XBOXRECV::disconnect(uint8_t controller) {
501  writeBuf[0] = 0x00;
502  writeBuf[1] = 0x00;
503  writeBuf[2] = 0x08;
504  writeBuf[3] = 0xC0;
505 
506  XboxCommand(controller, writeBuf, 4);
507 }
508 
509 void XBOXRECV::setLedRaw(uint8_t value, uint8_t controller) {
510  writeBuf[0] = 0x00;
511  writeBuf[1] = 0x00;
512  writeBuf[2] = 0x08;
513  writeBuf[3] = value | 0x40;
514 
515  XboxCommand(controller, writeBuf, 4);
516 }
517 
518 void XBOXRECV::setLedOn(LEDEnum led, uint8_t controller) {
519  if(led == OFF)
520  setLedRaw(0, controller);
521  else if(led != ALL) // All LEDs can't be on a the same time
522  setLedRaw(pgm_read_byte(&XBOX_LEDS[(uint8_t)led]) + 4, controller);
523 }
524 
525 void XBOXRECV::setLedBlink(LEDEnum led, uint8_t controller) {
526  setLedRaw(pgm_read_byte(&XBOX_LEDS[(uint8_t)led]), controller);
527 }
528 
529 void XBOXRECV::setLedMode(LEDModeEnum ledMode, uint8_t controller) { // This function is used to do some speciel LED stuff the controller supports
530  setLedRaw((uint8_t)ledMode, controller);
531 }
532 
533 /* PC runs this at interval of approx 2 seconds
534 Thanks to BusHound from Perisoft.net for the Windows USB Analysis output
535 Found by timstamp.co.uk
536  */
537 void XBOXRECV::checkStatus() {
538  if(!bPollEnable)
539  return;
540  // Get controller info
541  writeBuf[0] = 0x08;
542  writeBuf[1] = 0x00;
543  writeBuf[2] = 0x0f;
544  writeBuf[3] = 0xc0;
545  for(uint8_t i = 0; i < 4; i++) {
546  XboxCommand(i, writeBuf, 4);
547  }
548  // Get battery status
549  writeBuf[0] = 0x00;
550  writeBuf[1] = 0x00;
551  writeBuf[2] = 0x00;
552  writeBuf[3] = 0x40;
553  for(uint8_t i = 0; i < 4; i++) {
554  if(Xbox360Connected[i])
555  XboxCommand(i, writeBuf, 4);
556  }
557 }
558 
559 void XBOXRECV::setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller) {
560  writeBuf[0] = 0x00;
561  writeBuf[1] = 0x01;
562  writeBuf[2] = 0x0f;
563  writeBuf[3] = 0xc0;
564  writeBuf[4] = 0x00;
565  writeBuf[5] = lValue; // big weight
566  writeBuf[6] = rValue; // small weight
567 
568  XboxCommand(controller, writeBuf, 7);
569 }
570 
571 void XBOXRECV::onInit(uint8_t controller) {
572  if(pFuncOnInit)
573  pFuncOnInit(); // Call the user function
574  else {
575  LEDEnum led;
576  if(controller == 0)
577  led = static_cast<LEDEnum>(LED1);
578  else if(controller == 1)
579  led = static_cast<LEDEnum>(LED2);
580  else if(controller == 2)
581  led = static_cast<LEDEnum>(LED3);
582  else
583  led = static_cast<LEDEnum>(LED4);
584  setLedOn(led, controller);
585  }
586 }
#define EP_MAXPKTSIZE
Definition: PS3USB.h:26
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
Definition: UsbCore.h:95
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
Definition: UsbCore.h:100
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET
Definition: UsbCore.h:103
#define USB_ERROR_FailGetDevDescr
Definition: UsbCore.h:104
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
Definition: UsbCore.h:92
#define USB_ERROR_EPINFO_IS_NULL
Definition: UsbCore.h:98
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
Definition: UsbCore.h:97
#define MADCATZ_VID
Definition: XBOXOLD.h:35
#define XBOX_VID
Definition: XBOXOLD.h:34
#define XBOX_CONTROL_PIPE
Definition: XBOXOLD.h:29
#define JOYTECH_VID
Definition: XBOXOLD.h:36
#define XBOX_MAX_ENDPOINTS
Definition: XBOXOLD.h:45
#define XBOX_INPUT_PIPE_1
Definition: XBOXRECV.h:31
#define XBOX_INPUT_PIPE_4
Definition: XBOXRECV.h:37
#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
Definition: XBOXRECV.h:47
#define XBOX_OUTPUT_PIPE_4
Definition: XBOXRECV.h:38
#define XBOX_INPUT_PIPE_3
Definition: XBOXRECV.h:35
#define XBOX_OUTPUT_PIPE_2
Definition: XBOXRECV.h:34
#define XBOX_OUTPUT_PIPE_1
Definition: XBOXRECV.h:32
#define XBOX_WIRELESS_RECEIVER_PID_2
Definition: XBOXRECV.h:46
#define XBOX_INPUT_PIPE_2
Definition: XBOXRECV.h:33
#define XBOX_WIRELESS_RECEIVER_PID_1
Definition: XBOXRECV.h:45
#define XBOX_OUTPUT_PIPE_3
Definition: XBOXRECV.h:36
#define USB_NAK_MAX_POWER
Definition: address.h:34
#define USB_NAK_NOWAIT
Definition: address.h:36
virtual void FreeAddress(uint8_t addr)=0
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
Definition: UsbCore.h:212
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
Definition: Usb.cpp:801
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
Definition: Usb.cpp:845
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
Definition: Usb.cpp:836
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
Definition: UsbCore.h:232
AddressPool & GetAddressPool()
Definition: UsbCore.h:228
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
Definition: Usb.cpp:64
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
Definition: Usb.cpp:209
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
Definition: Usb.cpp:303
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXRECV.cpp:138
void setLedBlink(LEDEnum l, uint8_t controller=0)
Definition: XBOXRECV.cpp:525
uint8_t bAddress
Definition: XBOXRECV.h:238
int16_t getAnalogHat(AnalogHatEnum a, uint8_t controller=0)
Definition: XBOXRECV.cpp:440
uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXRECV.cpp:41
void setLedMode(LEDModeEnum lm, uint8_t controller=0)
Definition: XBOXRECV.cpp:529
USB * pUsb
Definition: XBOXRECV.h:236
bool XboxReceiverConnected
Definition: XBOXRECV.h:226
void setLedRaw(uint8_t value, uint8_t controller=0)
Definition: XBOXRECV.cpp:509
uint8_t getButtonPress(ButtonEnum b, uint8_t controller=0)
Definition: XBOXRECV.cpp:410
void setLedOn(LEDEnum l, uint8_t controller=0)
Definition: XBOXRECV.cpp:518
uint8_t getBatteryLevel(uint8_t controller=0)
Definition: XBOXRECV.cpp:469
uint8_t Poll()
Definition: XBOXRECV.cpp:293
uint8_t Xbox360Connected[4]
Definition: XBOXRECV.h:232
XBOXRECV(USB *pUsb)
Definition: XBOXRECV.cpp:25
void disconnect(uint8_t controller=0)
Definition: XBOXRECV.cpp:500
uint8_t Release()
Definition: XBOXRECV.cpp:283
void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller=0)
Definition: XBOXRECV.cpp:559
bool buttonChanged(uint8_t controller=0)
Definition: XBOXRECV.cpp:444
bool getButtonClick(ButtonEnum b, uint8_t controller=0)
Definition: XBOXRECV.cpp:419
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXRECV.h:240
constexpr int8_t ButtonIndex(ButtonEnum key)
AnalogHatEnum
@ LeftHatX
@ RightHatY
@ RightHatX
@ LeftHatY
LEDEnum
@ LED3
@ LED2
@ OFF
@ ALL
@ LED4
@ LED1
ButtonEnum
@ L2
@ R2
#define hrJERR
Definition: max3421e.h:227
#define NotifyFailSetConfDescr(...)
Definition: message.h:60
#define NotifyFailUnknownDevice(...)
Definition: message.h:61
#define NotifyFail(...)
Definition: message.h:62
#define Notify(...)
Definition: message.h:51
#define NotifyFailSetDevTblEntry(...)
Definition: message.h:58
#define NotifyFailGetDevDescr(...)
Definition: message.h:57
Definition: address.h:39
uint8_t epAttribs
Definition: address.h:44
uint8_t bmNakPower
Definition: address.h:49
uint8_t bmRcvToggle
Definition: address.h:48
uint8_t epAddr
Definition: address.h:40
uint8_t maxPktSize
Definition: address.h:41
uint8_t bmSndToggle
Definition: address.h:47
uint8_t bMaxPacketSize0
Definition: usb_ch9.h:112
uint16_t idProduct
Definition: usb_ch9.h:114
EpInfo * epinfo
Definition: address.h:83
bool lowspeed
Definition: address.h:86
#define USB_TRANSFER_TYPE_INTERRUPT
Definition: usb_ch9.h:93
#define pgm_read_byte(addr)
#define PSTR(str)
#define pgm_read_word(addr)
const uint8_t XBOX_LEDS[]
Definition: xboxEnums.h:32
const uint16_t XBOX_BUTTONS[]
Definition: xboxEnums.h:41
int8_t getButtonIndexXbox(ButtonEnum b)
Definition: xboxEnums.h:65
LEDModeEnum
Definition: xboxEnums.h:24