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;
124 #ifdef DEBUG_USB_HOST
125 Notify(PSTR(
"\r\nsetAddr: "), 0x80);
127 PrintHex<uint8_t > (rcode, 0x80);
131 Notify(PSTR(
"\r\nAddr: "), 0x80);
132 PrintHex<uint8_t > (
bAddress, 0x80);
146 goto FailSetDevTblEntry;
168 goto FailSetDevTblEntry;
174 goto FailSetConfDescr;
176 #ifdef DEBUG_USB_HOST
177 Notify(PSTR(
"\r\nXbox 360 Controller Connected\r\n"), 0x80);
186 #ifdef DEBUG_USB_HOST
192 #ifdef DEBUG_USB_HOST
198 #ifdef DEBUG_USB_HOST
203 #ifdef DEBUG_USB_HOST
209 #ifdef DEBUG_USB_HOST
210 Notify(PSTR(
"\r\nXbox 360 Init Failed, error code: "), 0x80);
238 void XBOXUSB::readReport() {
241 if (readBuf[0] != 0x00 || readBuf[1] != 0x14) {
245 ButtonState = (uint32_t)(readBuf[5] | ((uint16_t)readBuf[4] << 8) | ((uint32_t)readBuf[3] << 16) | ((uint32_t)readBuf[2] << 24));
247 hatValue[
LeftHatX] = (int16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]);
248 hatValue[
LeftHatY] = (int16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]);
249 hatValue[
RightHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
250 hatValue[
RightHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
255 if (ButtonState != OldButtonState) {
256 ButtonClickState = (ButtonState >> 16) & ((~OldButtonState) >> 16);
257 if (((uint8_t)OldButtonState) == 0 && ((uint8_t)ButtonState) != 0)
259 if ((uint8_t)(OldButtonState >> 8) == 0 && (uint8_t)(ButtonState >> 8) != 0)
261 OldButtonState = ButtonState;
265 void XBOXUSB::printReport() {
270 PrintHex<uint8_t > (readBuf[i], 0x80);
273 Notify(PSTR(
"\r\n"), 0x80);
279 return (uint8_t)(ButtonState >> 8);
281 return (uint8_t)ButtonState;
282 return (ButtonState & ((uint32_t)pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]) << 16));
292 }
else if (b ==
R2) {
299 uint16_t button = pgm_read_word(&
XBOXBUTTONS[(uint8_t)b]);
300 bool click = (ButtonClickState & button);
301 ButtonClickState &= ~button;
310 void XBOXUSB::XboxCommand(uint8_t* data, uint16_t nbytes) {
312 pUsb->
ctrlReq(
bAddress,
epInfo[
XBOX_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
320 XboxCommand(writeBuf, 3);
340 writeBuf[3] = lValue;
341 writeBuf[4] = rValue;
346 XboxCommand(writeBuf, 8);