43 uint8_t buf[constBufSize];
94 Notify(
PSTR(
"\r\nYou'll need a wireless receiver for this libary to work"), 0x80);
96 goto FailUnknownDevice;
102 #ifdef DEBUG_USB_HOST
103 Notify(
PSTR(
"\r\nOut of address space"), 0x80);
116 #ifdef DEBUG_USB_HOST
124 #ifdef DEBUG_USB_HOST
130 #ifdef DEBUG_USB_HOST
131 Notify(
PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
138 uint8_t
XBOXRECV::Init(uint8_t parent __attribute__((unused)), uint8_t port __attribute__((unused)),
bool lowspeed) {
148 #ifdef DEBUG_USB_HOST
158 #ifdef DEBUG_USB_HOST
160 D_PrintHex<uint8_t > (rcode, 0x80);
167 D_PrintHex<uint8_t > (
bAddress, 0x80);
174 #ifdef DEBUG_USB_HOST
184 goto FailSetDevTblEntry;
245 goto FailSetDevTblEntry;
251 goto FailSetConfDescr;
253 #ifdef DEBUG_USB_HOST
254 Notify(
PSTR(
"\r\nXbox Wireless Receiver Connected\r\n"), 0x80);
258 checkStatusTimer = 0;
263 #ifdef DEBUG_USB_HOST
269 #ifdef DEBUG_USB_HOST
274 #ifdef DEBUG_USB_HOST
275 Notify(
PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
285 for(uint8_t i = 0; i < 4; i++)
296 if(!checkStatusTimer || ((int32_t)((uint32_t)millis() - checkStatusTimer) > 3000)) {
297 checkStatusTimer = (uint32_t)millis();
303 for(uint8_t i = 0; i < 4; i++) {
318 D_PrintHex<uint16_t > (bufferSize, 0x80);
323 printReport(i, bufferSize);
330 void XBOXRECV::readReport(uint8_t controller) {
336 #ifdef DEBUG_USB_HOST
341 #ifdef DEBUG_USB_HOST
344 case 0x80: str =
PSTR(
" as controller\r\n");
346 case 0x40: str =
PSTR(
" as headset\r\n");
348 case 0xC0: str =
PSTR(
" as controller+headset\r\n");
356 #ifdef DEBUG_USB_HOST
363 if(readBuf[1] == 0x00 && readBuf[3] & 0x13 && readBuf[4] >= 0x22) {
364 controllerStatus[controller] = ((uint16_t)readBuf[3] << 8) | readBuf[4];
367 if(readBuf[1] != 0x01)
374 ButtonState[controller] = (uint32_t)(readBuf[9] | ((uint16_t)readBuf[8] << 8) | ((uint32_t)readBuf[7] << 16) | ((uint32_t)readBuf[6] << 24));
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]);
384 if(ButtonState[controller] != OldButtonState[controller]) {
385 buttonStateChanged[controller] =
true;
386 ButtonClickState[controller] = (ButtonState[controller] >> 16) & ((~OldButtonState[controller]) >> 16);
387 if(((uint8_t)OldButtonState[controller]) == 0 && ((uint8_t)ButtonState[controller]) != 0)
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];
395 void XBOXRECV::printReport(uint8_t controller __attribute__((unused)), uint8_t nBytes __attribute__((unused))) {
402 for(uint8_t i = 0; i < nBytes; i++) {
403 D_PrintHex<uint8_t > (readBuf[i], 0x80);
412 return (uint8_t)(ButtonState[controller] >> 8);
414 return (uint8_t)ButtonState[controller];
420 if(L2Clicked[controller]) {
421 L2Clicked[controller] =
false;
426 if(R2Clicked[controller]) {
427 R2Clicked[controller] =
false;
433 bool click = (ButtonClickState[controller] & button);
434 ButtonClickState[controller] &= ~button;
439 return hatValue[controller][a];
443 bool state = buttonStateChanged[controller];
444 buttonStateChanged[controller] =
false;
468 return ((controllerStatus[controller] & 0x00C0) >> 6);
471 void XBOXRECV::XboxCommand(uint8_t controller, uint8_t* data, uint16_t nbytes) {
494 Notify(
PSTR(
"Error sending Xbox message\r\n"), 0x80);
504 XboxCommand(controller, writeBuf, 4);
511 writeBuf[3] = value | 0x40;
513 XboxCommand(controller, writeBuf, 4);
535 void XBOXRECV::checkStatus() {
543 for(uint8_t i = 0; i < 4; i++) {
544 XboxCommand(i, writeBuf, 4);
551 for(uint8_t i = 0; i < 4; i++) {
553 XboxCommand(i, writeBuf, 4);
563 writeBuf[5] = lValue;
564 writeBuf[6] = rValue;
566 XboxCommand(controller, writeBuf, 7);
569 void XBOXRECV::onInit(uint8_t controller) {
576 else if(controller == 1)
578 else if(controller == 2)
#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID
#define USB_ERROR_EPINFO_IS_NULL
void setRumbleOn(uint8_t lValue, uint8_t rValue, uint8_t controller=0)
#define XBOX_WIRELESS_RECEIVER_PID
#define pgm_read_word(addr)
uint8_t Xbox360Connected[4]
void setLedMode(LEDModeEnum lm, uint8_t controller=0)
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
bool buttonChanged(uint8_t controller=0)
#define XBOX_OUTPUT_PIPE_3
uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
#define USB_TRANSFER_TYPE_INTERRUPT
#define USB_ERROR_FailGetDevDescr
#define pgm_read_byte(addr)
#define NotifyFailGetDevDescr(...)
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
virtual void FreeAddress(uint8_t addr)=0
virtual UsbDevice * GetUsbDevicePtr(uint8_t addr)=0
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
#define XBOX_INPUT_PIPE_2
#define NotifyFailUnknownDevice(...)
#define USB_NAK_MAX_POWER
bool getButtonClick(ButtonEnum b, uint8_t controller=0)
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
void setLedOn(LEDEnum l, uint8_t controller=0)
uint8_t getButtonPress(ButtonEnum b, uint8_t controller=0)
bool XboxReceiverConnected
uint8_t getBatteryLevel(uint8_t controller=0)
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub=false, uint8_t port=0)=0
#define XBOX_OUTPUT_PIPE_1
int16_t getAnalogHat(AnalogHatEnum a, uint8_t controller=0)
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define XBOX_INPUT_PIPE_1
void setLedBlink(LEDEnum l, uint8_t controller=0)
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
void setLedRaw(uint8_t value, uint8_t controller=0)
const uint8_t XBOX_LEDS[]
#define XBOX_MAX_ENDPOINTS
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
AddressPool & GetAddressPool()
#define XBOX_INPUT_PIPE_3
#define XBOX_CONTROL_PIPE
#define XBOX_INPUT_PIPE_4
const uint16_t XBOX_BUTTONS[]
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
#define NotifyFailSetConfDescr(...)
void disconnect(uint8_t controller=0)
#define XBOX_OUTPUT_PIPE_4
#define XBOX_OUTPUT_PIPE_2
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
#define NotifyFailSetDevTblEntry(...)
#define USB_ERROR_CONFIG_REQUIRES_ADDITIONAL_RESET