USB Host Shield 2.0
Loading...
Searching...
No Matches
XBOXUSB.h
Go to the documentation of this file.
1/* Copyright (C) 2012 Kristian Lauszus, TKJ Electronics. All rights reserved.
2
3 This software may be distributed and modified under the terms of the GNU
4 General Public License version 2 (GPL2) as published by the Free Software
5 Foundation and appearing in the file GPL2.TXT included in the packaging of
6 this file. Please note that GPL2 Section 2[b] requires that all works based
7 on this software must also be made publicly available under the terms of
8 the GPL2 ("Copyleft").
9
10 Contact information
11 -------------------
12
13 Kristian Lauszus, TKJ Electronics
14 Web : http://www.tkjelectronics.com
15 e-mail : kristianl@tkjelectronics.com
16 */
17
18#ifndef _xboxusb_h_
19#define _xboxusb_h_
20
21#include "Usb.h"
22#include "usbhid.h"
23#include "xboxEnums.h"
24
25/* Data Xbox 360 taken from descriptors */
26#define EP_MAXPKTSIZE 32 // max size for data via USB
27
28/* Names we give to the 3 Xbox360 pipes */
29#define XBOX_CONTROL_PIPE 0
30#define XBOX_INPUT_PIPE 1
31#define XBOX_OUTPUT_PIPE 2
32
33// PID and VID of the different devices
34#define XBOX_VID 0x045E // Microsoft Corporation
35#define MADCATZ_VID 0x1BAD // For unofficial Mad Catz controllers
36#define JOYTECH_VID 0x162E // For unofficial Joytech controllers
37#define GAMESTOP_VID 0x0E6F // Gamestop controller
38
39#define XBOX_WIRED_PID 0x028E // Microsoft 360 Wired controller
40#define XBOX_WIRELESS_PID 0x028F // Wireless controller only support charging
41#define XBOX_WIRELESS_RECEIVER_PID 0x0719 // Microsoft Wireless Gaming Receiver
42#define XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID 0x0291 // Third party Wireless Gaming Receiver
43#define MADCATZ_WIRED_PID 0xF016 // Mad Catz wired controller
44#define JOYTECH_WIRED_PID 0xBEEF // For Joytech wired controller
45#define GAMESTOP_WIRED_PID 0x0401 // Gamestop wired controller
46#define AFTERGLOW_WIRED_PID 0x0213 // Afterglow wired controller - it uses the same VID as a Gamestop controller
47
48#define XBOX_REPORT_BUFFER_SIZE 14 // Size of the input report buffer
49
50#define XBOX_MAX_ENDPOINTS 3
51
53class XBOXUSB : public USBDeviceConfig {
54public:
60
69 uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
79 uint8_t Poll();
80
85 virtual uint8_t GetAddress() {
86 return bAddress;
87 };
88
93 virtual bool isReady() {
94 return bPollEnable;
95 };
96
103 virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) {
104 return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID || vid == GAMESTOP_VID) && (pid == XBOX_WIRED_PID || pid == MADCATZ_WIRED_PID || pid == GAMESTOP_WIRED_PID || pid == AFTERGLOW_WIRED_PID || pid == JOYTECH_WIRED_PID));
105 };
130
132 void setAllOff() {
133 setRumbleOn(0, 0);
134 setLedRaw(0);
135 };
136
139 setRumbleOn(0, 0);
140 };
153 void setLedRaw(uint8_t value);
154
156 void setLedOff() {
157 setLedRaw(0);
158 };
163 void setLedOn(LEDEnum l);
168 void setLedBlink(LEDEnum l);
174
179 void attachOnInit(void (*funcOnInit)(void)) {
180 pFuncOnInit = funcOnInit;
181 };
186
187protected:
194
195private:
201 void onInit();
202 void (*pFuncOnInit)(void); // Pointer to function called in onInit()
203
204 bool bPollEnable;
205
206 /* Variables to store the buttons */
207 uint32_t ButtonState;
208 uint32_t OldButtonState;
209 uint16_t ButtonClickState;
210 int16_t hatValue[4];
211 uint16_t controllerStatus;
212
213 bool L2Clicked; // These buttons are analog, so we use we use these bools to check if they where clicked or not
214 bool R2Clicked;
215
216 uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
217 uint8_t writeBuf[8]; // General purpose buffer for output data
218
219 void readReport(); // read incoming data
220 void printReport(); // print incoming date - Uncomment for debugging
221
222 /* Private commands */
223 void XboxCommand(uint8_t* data, uint16_t nbytes);
224};
225#endif
#define MADCATZ_VID
Definition XBOXUSB.h:35
#define JOYTECH_WIRED_PID
Definition XBOXUSB.h:44
#define GAMESTOP_WIRED_PID
Definition XBOXUSB.h:45
#define MADCATZ_WIRED_PID
Definition XBOXUSB.h:43
#define AFTERGLOW_WIRED_PID
Definition XBOXUSB.h:46
#define XBOX_VID
Definition XBOXUSB.h:34
#define JOYTECH_VID
Definition XBOXUSB.h:36
#define EP_MAXPKTSIZE
Definition XBOXUSB.h:26
#define GAMESTOP_VID
Definition XBOXUSB.h:37
#define XBOX_WIRED_PID
Definition XBOXUSB.h:39
#define XBOX_MAX_ENDPOINTS
Definition XBOXUSB.h:50
Definition UsbCore.h:220
void setLedMode(LEDModeEnum lm)
Definition XBOXUSB.cpp:342
void setLedOff()
Definition XBOXUSB.h:156
uint8_t getButtonPress(ButtonEnum b)
Definition XBOXUSB.cpp:283
bool Xbox360Connected
Definition XBOXUSB.h:185
void setLedRaw(uint8_t value)
Definition XBOXUSB.cpp:323
uint8_t Poll()
Definition XBOXUSB.cpp:232
void setLedBlink(LEDEnum l)
Definition XBOXUSB.cpp:338
virtual uint8_t GetAddress()
Definition XBOXUSB.h:85
void setRumbleOff()
Definition XBOXUSB.h:138
uint8_t bAddress
Definition XBOXUSB.h:191
void setAllOff()
Definition XBOXUSB.h:132
void attachOnInit(void(*funcOnInit)(void))
Definition XBOXUSB.h:179
void setLedOn(LEDEnum l)
Definition XBOXUSB.cpp:331
bool getButtonClick(ButtonEnum b)
Definition XBOXUSB.cpp:292
uint8_t Release()
Definition XBOXUSB.cpp:224
USB * pUsb
Definition XBOXUSB.h:189
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition XBOXUSB.cpp:39
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid)
Definition XBOXUSB.h:103
int16_t getAnalogHat(AnalogHatEnum a)
Definition XBOXUSB.cpp:313
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition XBOXUSB.h:193
virtual bool isReady()
Definition XBOXUSB.h:93
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition XBOXUSB.cpp:346
AnalogHatEnum
LEDEnum
ButtonEnum
LEDModeEnum
Definition xboxEnums.h:24