49 Notify(PSTR(
"\r\nXBOXUSB Init"), 0x80);
54 Notify(PSTR(
"\r\nAddress in use"), 0x80);
64 Notify(PSTR(
"\r\nAddress not found"), 0x80);
71 Notify(PSTR(
"\r\nepinfo is null"), 0x80);
96 goto FailUnknownDevice;
99 Notify(PSTR(
"\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication"), 0x80);
101 goto FailUnknownDevice;
103 #ifdef DEBUG_USB_HOST
104 Notify(PSTR(
"\r\nThis library only supports Xbox 360 controllers via USB"), 0x80);
106 goto FailUnknownDevice;
108 goto FailUnknownDevice;
125 #ifdef DEBUG_USB_HOST
126 Notify(PSTR(
"\r\nsetAddr: "), 0x80);
127 D_PrintHex<uint8_t > (rcode, 0x80);
132 Notify(PSTR(
"\r\nAddr: "), 0x80);
133 D_PrintHex<uint8_t > (
bAddress, 0x80);
149 goto FailSetDevTblEntry;
171 goto FailSetDevTblEntry;
177 goto FailSetConfDescr;
179 #ifdef DEBUG_USB_HOST
180 Notify(PSTR(
"\r\nXbox 360 Controller Connected\r\n"), 0x80);
189 #ifdef DEBUG_USB_HOST
195 #ifdef DEBUG_USB_HOST
201 #ifdef DEBUG_USB_HOST
206 #ifdef DEBUG_USB_HOST
212 #ifdef DEBUG_USB_HOST
213 Notify(PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
241 void XBOXUSB::readReport() {
244 if (readBuf[0] != 0x00 || readBuf[1] != 0x14) {
248 ButtonState = (uint32_t)(readBuf[5] | ((uint16_t)readBuf[4] << 8) | ((uint32_t)readBuf[3] << 16) | ((uint32_t)readBuf[2] << 24));
250 hatValue[
LeftHatX] = (int16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]);
251 hatValue[
LeftHatY] = (int16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]);
252 hatValue[
RightHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
253 hatValue[
RightHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
258 if (ButtonState != OldButtonState) {
259 ButtonClickState = (ButtonState >> 16) & ((~OldButtonState) >> 16);
260 if (((uint8_t)OldButtonState) == 0 && ((uint8_t)ButtonState) != 0)
262 if ((uint8_t)(OldButtonState >> 8) == 0 && (uint8_t)(ButtonState >> 8) != 0)
264 OldButtonState = ButtonState;
268 void XBOXUSB::printReport() {
273 D_PrintHex<uint8_t > (readBuf[i], 0x80);
276 Notify(PSTR(
"\r\n"), 0x80);
282 return (uint8_t)(ButtonState >> 8);
284 return (uint8_t)ButtonState;
285 return (ButtonState & ((uint32_t)pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]) << 16));
295 }
else if (b ==
R2) {
302 uint16_t button = pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]);
303 bool click = (ButtonClickState & button);
304 ButtonClickState &= ~button;
313 void XBOXUSB::XboxCommand(uint8_t* data, uint16_t nbytes) {
315 pUsb->
ctrlReq(
bAddress,
epInfo[
XBOX_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
323 XboxCommand(writeBuf, 3);
343 writeBuf[3] = lValue;
344 writeBuf[4] = rValue;
349 XboxCommand(writeBuf, 8);
352 void XBOXUSB::onInit() {