102 PID = udd->idProduct;
105 goto FailUnknownDevice;
122 #ifdef DEBUG_USB_HOST
124 D_PrintHex<uint8_t > (rcode, 0x80);
130 D_PrintHex<uint8_t > (
bAddress, 0x80);
146 goto FailSetDevTblEntry;
148 num_of_conf = udd->bNumConfigurations;
153 for(uint8_t i = 0; i < num_of_conf; i++) {
157 goto FailGetConfDescr;
163 goto FailUnknownDevice;
167 goto FailSetDevTblEntry;
173 goto FailSetConfDescr;
175 #ifdef DEBUG_USB_HOST
176 Notify(
PSTR(
"\r\nXbox One Controller Connected\r\n"), 0x80);
189 rcode = XboxCommand(writeBuf, 5);
200 #ifdef DEBUG_USB_HOST
206 #ifdef DEBUG_USB_HOST
212 #ifdef DEBUG_USB_HOST
218 #ifdef DEBUG_USB_HOST
224 #ifdef DEBUG_USB_HOST
230 #ifdef DEBUG_USB_HOST
231 Notify(
PSTR(
"\r\nXbox One Init Failed, error code: "), 0x80);
240 uint8_t iface __attribute__((unused)),
241 uint8_t alt __attribute__((unused)),
242 uint8_t proto __attribute__((unused)),
260 if(pollInterval < pep->bInterval)
266 __attribute__((unused)))
269 Notify(
PSTR(
"\r\nEndpoint descriptor:"), 0x80);
271 D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
273 D_PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
275 D_PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
277 D_PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
279 D_PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
281 D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
294 #ifdef DEBUG_USB_HOST
295 Notify(
PSTR(
"\r\nXbox One Controller Disconnected\r\n"), 0x80);
313 for(uint8_t i = 0; i < length; i++) {
314 D_PrintHex<uint8_t > (readBuf[i], 0x80);
320 #ifdef DEBUG_USB_HOST
321 else if(rcode !=
hrNAK) {
322 Notify(
PSTR(
"\r\nXbox One Poll Failed, error code: "), 0x80);
330 void XBOXONE::readReport() {
331 if(readBuf[0] == 0x07) {
338 if(ButtonState != OldButtonState) {
339 ButtonClickState = ButtonState & ~OldButtonState;
340 OldButtonState = ButtonState;
343 if(readBuf[0] != 0x20) {
346 D_PrintHex<uint8_t > (readBuf[0], 0x80);
353 ButtonState = xbox | (((uint16_t)readBuf[5] & 0xF) << 8) | (readBuf[4] & 0xF0) | (((uint16_t)readBuf[4] & 0x0C) << 10) | ((readBuf[4] & 0x01) << 3) | (((uint16_t)readBuf[5] & 0xC0) << 8) | ((readBuf[5] & 0x30) >> 4);
355 triggerValue[0] = (uint16_t)(((uint16_t)readBuf[7] << 8) | readBuf[6]);
356 triggerValue[1] = (uint16_t)(((uint16_t)readBuf[9] << 8) | readBuf[8]);
358 hatValue[
LeftHatX] = (int16_t)(((uint16_t)readBuf[11] << 8) | readBuf[10]);
359 hatValue[
LeftHatY] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
360 hatValue[
RightHatX] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
361 hatValue[
RightHatY] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
364 const bool newShare = (readBuf[22] & 0x01) ? 1 : 0;
365 shareClicked = ((sharePressed != newShare) && newShare) ? 1 : 0;
366 sharePressed = newShare;
371 if(ButtonState != OldButtonState) {
372 ButtonClickState = ButtonState & ~OldButtonState;
373 OldButtonState = ButtonState;
377 if(triggerValue[0] != 0 && triggerValueOld[0] == 0)
379 triggerValueOld[0] = triggerValue[0];
380 if(triggerValue[1] != 0 && triggerValueOld[1] == 0)
382 triggerValueOld[1] = triggerValue[1];
389 if (b ==
SHARE)
return sharePressed;
393 return triggerValue[0];
395 return triggerValue[1];
403 shareClicked =
false;
424 bool click = (ButtonClickState & button);
425 ButtonClickState &= ~button;
434 uint8_t XBOXONE::XboxCommand(uint8_t* data, uint16_t nbytes) {
435 data[2] = cmdCounter++;
437 #ifdef DEBUG_USB_HOST
439 Notify(
PSTR(
"\r\nXboxCommand failed. Return: "), 0x80);
440 D_PrintHex<uint8_t > (rcode, 0x80);
447 void XBOXONE::onInit() {
449 uint8_t writeBuf[13];
467 XboxCommand(writeBuf, 13);
474 uint8_t writeBuf[13];
492 XboxCommand(writeBuf, 13);
496 uint8_t writeBuf[13];
507 writeBuf[6] = leftTrigger;
508 writeBuf[7] = rightTrigger;
509 writeBuf[8] = leftMotor;
510 writeBuf[9] = rightMotor;
514 XboxCommand(writeBuf, 13);
#define USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL
#define USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE
#define USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED
#define USB_ERROR_EPINFO_IS_NULL
#define USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL
#define XBOX_ONE_OUTPUT_PIPE
#define XBOX_ONE_MAX_ENDPOINTS
#define XBOX_ONE_CONTROL_PIPE
#define XBOX_ONE_INPUT_PIPE
#define USB_NAK_MAX_POWER
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
uint8_t getDevDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *dataptr)
defined(USB_METHODS_INLINE)
uint8_t setConf(uint8_t addr, uint8_t ep, uint8_t conf_value)
uint8_t setAddr(uint8_t oldaddr, uint8_t ep, uint8_t newaddr)
uint8_t RegisterDeviceClass(USBDeviceConfig *pdev)
uint8_t getConfDescr(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t conf, uint8_t *dataptr)
AddressPool & GetAddressPool()
uint8_t setEpInfoEntry(uint8_t addr, uint8_t epcount, EpInfo *eprecord_ptr)
uint8_t inTransfer(uint8_t addr, uint8_t ep, uint16_t *nbytesptr, uint8_t *data, uint8_t bInterval=0)
uint8_t outTransfer(uint8_t addr, uint8_t ep, uint16_t nbytes, uint8_t *data)
EpInfo epInfo[XBOX_ONE_MAX_ENDPOINTS]
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid)
void setRumbleOn(uint8_t leftTrigger, uint8_t rightTrigger, uint8_t leftMotor, uint8_t rightMotor)
bool getButtonClick(ButtonEnum b)
virtual uint8_t Release()
uint16_t getButtonPress(ButtonEnum b)
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
int16_t getAnalogHat(AnalogHatEnum a)
constexpr int8_t ButtonIndex(ButtonEnum key)
#define NotifyFailSetConfDescr(...)
#define NotifyFailUnknownDevice(...)
#define NotifyFailGetConfDescr(...)
#define NotifyFailSetDevTblEntry(...)
#define NotifyFailGetDevDescr(...)
#define bmUSB_TRANSFER_TYPE
#define USB_TRANSFER_TYPE_INTERRUPT
#define pgm_read_word(addr)
const uint16_t XBOX_BUTTONS[]
int8_t getButtonIndexXbox(ButtonEnum b)