100 #ifdef DEBUG_USB_HOST
120 goto FailGetDevDescr;
123 PID = udd->idProduct;
126 goto FailUnknownDevice;
143 #ifdef DEBUG_USB_HOST
145 D_PrintHex<uint8_t > (rcode, 0x80);
151 D_PrintHex<uint8_t > (
bAddress, 0x80);
167 goto FailSetDevTblEntry;
177 num_of_conf = udd->bNumConfigurations;
182 for(uint8_t i = 0; i < num_of_conf; i++) {
186 goto FailGetConfDescr;
192 goto FailUnknownDevice;
196 goto FailSetDevTblEntry;
202 goto FailSetConfDescr;
204 #ifdef DEBUG_USB_HOST
205 Notify(
PSTR(
"\r\nXbox Controller Connected\r\n"), 0x80);
215 #ifdef DEBUG_USB_HOST
221 #ifdef DEBUG_USB_HOST
227 #ifdef DEBUG_USB_HOST
233 #ifdef DEBUG_USB_HOST
239 #ifdef DEBUG_USB_HOST
245 #ifdef DEBUG_USB_HOST
246 Notify(
PSTR(
"\r\nXbox Init Failed, error code: "), 0x80);
255 uint8_t iface __attribute__((unused)),
256 uint8_t alt __attribute__((unused)),
257 uint8_t proto __attribute__((unused)),
274 if(pollInterval < pep->bInterval)
280 __attribute__((unused)))
283 Notify(
PSTR(
"\r\nEndpoint descriptor:"), 0x80);
285 D_PrintHex<uint8_t > (ep_ptr->bLength, 0x80);
287 D_PrintHex<uint8_t > (ep_ptr->bDescriptorType, 0x80);
289 D_PrintHex<uint8_t > (ep_ptr->bEndpointAddress, 0x80);
291 D_PrintHex<uint8_t > (ep_ptr->bmAttributes, 0x80);
293 D_PrintHex<uint16_t > (ep_ptr->wMaxPacketSize, 0x80);
295 D_PrintHex<uint8_t > (ep_ptr->bInterval, 0x80);
308 #ifdef DEBUG_USB_HOST
309 Notify(
PSTR(
"\r\nXbox Controller Disconnected\r\n"), 0x80);
330 #ifdef DEBUG_USB_HOST
331 else if(rcode !=
hrNAK) {
332 Notify(
PSTR(
"\r\nXbox Poll Failed, error code: "), 0x80);
340 void XBOXOLD::readReport() {
341 ButtonState = readBuf[2];
343 for(uint8_t i = 0; i <
sizeof (buttonValues); i++)
344 buttonValues[i] = readBuf[i + 4];
346 hatValue[
LeftHatX] = (int16_t)(((uint16_t)readBuf[13] << 8) | readBuf[12]);
347 hatValue[
LeftHatY] = (int16_t)(((uint16_t)readBuf[15] << 8) | readBuf[14]);
348 hatValue[
RightHatX] = (int16_t)(((uint16_t)readBuf[17] << 8) | readBuf[16]);
349 hatValue[
RightHatY] = (int16_t)(((uint16_t)readBuf[19] << 8) | readBuf[18]);
354 if(ButtonState != OldButtonState || memcmp(buttonValues, oldButtonValues,
sizeof (buttonValues)) != 0) {
355 ButtonClickState = ButtonState & ~OldButtonState;
356 OldButtonState = ButtonState;
358 for(uint8_t i = 0; i <
sizeof (buttonValues); i++) {
359 if(oldButtonValues[i] == 0 && buttonValues[i] != 0)
360 buttonClicked[i] =
true;
361 oldButtonValues[i] = buttonValues[i];
366 void XBOXOLD::printReport(uint16_t length __attribute__((unused))) {
368 if(readBuf == NULL || !length)
370 for(uint8_t i = 0; i < length; i++) {
371 D_PrintHex<uint8_t > (readBuf[i], 0x80);
378 int8_t XBOXOLD::getAnalogIndex(
ButtonEnum b) {
385 case(
LT): b =
L1;
break;
386 case(
RT): b =
R1;
break;
411 int8_t XBOXOLD::getDigitalIndex(
ButtonEnum b) {
432 const int8_t analogIndex = getAnalogIndex(b);
433 if (analogIndex >= 0) {
435 return buttonValues[buttonIndex];
437 const int8_t digitalIndex = getDigitalIndex(b);
438 if (digitalIndex >= 0) {
440 return (ButtonState & buttonMask);
446 const int8_t analogIndex = getAnalogIndex(b);
447 if (analogIndex >= 0) {
449 if (buttonClicked[buttonIndex]) {
450 buttonClicked[buttonIndex] =
false;
455 const int8_t digitalIndex = getDigitalIndex(b);
456 if (digitalIndex >= 0) {
458 const bool click = (ButtonClickState & mask);
459 ButtonClickState &= ~mask;
470 void XBOXOLD::XboxCommand(uint8_t* data, uint16_t nbytes) {
472 pUsb->
ctrlReq(
bAddress,
epInfo[
XBOX_CONTROL_PIPE].epAddr,
bmREQ_HID_OUT,
HID_REQUEST_SET_REPORT, 0x00, 0x02, 0x00, nbytes, nbytes, data, NULL);
481 writeBuf[3] = rValue;
483 writeBuf[5] = lValue;
485 XboxCommand(writeBuf, 6);
#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
const uint8_t XBOXOLD_BUTTONS[]
#define XBOX_CONTROL_PIPE
#define XBOX_MAX_ENDPOINTS
#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)
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
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)
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
bool getButtonClick(ButtonEnum b)
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid)
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
uint8_t getButtonPress(ButtonEnum b)
void setRumbleOn(uint8_t lValue, uint8_t rValue)
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 HID_REQUEST_SET_REPORT
#define pgm_read_byte(addr)