USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
XBOXOLD.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 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 _xboxold_h_
19 #define _xboxold_h_
20 
21 #include "Usb.h"
22 #include "controllerEnums.h"
23 
24 /* Data Xbox taken from descriptors */
25 #define EP_MAXPKTSIZE 32 // Max size for data via USB
26 
27 /* Endpoint types */
28 #define EP_INTERRUPT 0x03
29 
30 /* Names we give to the 3 Xbox pipes */
31 #define XBOX_CONTROL_PIPE 0
32 #define XBOX_INPUT_PIPE 1
33 #define XBOX_OUTPUT_PIPE 2
34 
35 // PID and VID of the different devices
36 #define XBOX_VID 0x045E // Microsoft Corporation
37 #define MADCATZ_VID 0x1BAD // For unofficial Mad Catz controllers
38 #define JOYTECH_VID 0x162E // For unofficial Joytech controllers
39 
40 #define XBOX_OLD_PID1 0x0202 // Original Microsoft Xbox controller (US)
41 #define XBOX_OLD_PID2 0x0285 // Original Microsoft Xbox controller (Japan)
42 #define XBOX_OLD_PID3 0x0287 // Microsoft Microsoft Xbox Controller S
43 #define XBOX_OLD_PID4 0x0289 // Smaller Microsoft Xbox controller (US)
44 
45 // Used in control endpoint header for HID Commands
46 #define bmREQ_HID_OUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
47 #define HID_REQUEST_SET_REPORT 0x09
48 
49 #define XBOX_MAX_ENDPOINTS 3
50 
52 class XBOXOLD : public USBDeviceConfig {
53 public:
58  XBOXOLD(USB *pUsb);
59 
68  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
73  virtual uint8_t Release();
78  virtual uint8_t Poll();
79 
84  virtual uint8_t GetAddress() {
85  return bAddress;
86  };
87 
92  virtual bool isReady() {
93  return bPollEnable;
94  };
95 
102  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
103  return ((vid == XBOX_VID || vid == MADCATZ_VID || vid == JOYTECH_VID) && (pid == XBOX_OLD_PID1 || pid == XBOX_OLD_PID2 || pid == XBOX_OLD_PID3 || pid == XBOX_OLD_PID4));
104  };
119  uint8_t getButtonPress(Button b);
120  bool getButtonClick(Button b);
129  int16_t getAnalogHat(AnalogHat a);
130 
132  void setRumbleOff() {
133  setRumbleOn(0, 0);
134  };
140  void setRumbleOn(uint8_t lValue, uint8_t rValue);
141 
146  void attachOnInit(void (*funcOnInit)(void)) {
147  pFuncOnInit = funcOnInit;
148  };
152  bool XboxConnected;
153 
154 protected:
158  uint8_t bAddress;
161 
162 private:
168  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
169 
170  bool bPollEnable;
171 
172  /* Variables to store the digital buttons */
173  uint8_t ButtonState;
174  uint8_t OldButtonState;
175  uint8_t ButtonClickState;
176 
177  /* Variables to store the analog buttons */
178  uint8_t buttonValues[8]; // A, B, X, Y, BLACK, WHITE, L1, and R1
179  uint8_t oldButtonValues[8];
180  bool buttonClicked[8];
181 
182  int16_t hatValue[4]; // Joystick values
183 
184  uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
185 
186  void readReport(); // Read incoming data
187  void printReport(uint16_t length); // Print incoming date
188 
189  /* Private commands */
190  void XboxCommand(uint8_t* data, uint16_t nbytes);
191 };
192 #endif
virtual uint8_t Release()
Definition: XBOXOLD.cpp:234
void attachOnInit(void(*funcOnInit)(void))
Definition: XBOXOLD.h:146
virtual uint8_t GetAddress()
Definition: XBOXOLD.h:84
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXOLD.cpp:324
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: XBOXOLD.h:102
#define XBOX_OLD_PID4
Definition: XBOXOLD.h:43
virtual bool isReady()
Definition: XBOXOLD.h:92
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXOLD.h:160
#define XBOX_VID
Definition: XBOXOLD.h:36
XBOXOLD(USB *pUsb)
Definition: XBOXOLD.cpp:47
#define XBOX_OLD_PID1
Definition: XBOXOLD.h:40
Definition: address.h:32
#define JOYTECH_VID
Definition: XBOXOLD.h:38
uint8_t getButtonPress(Button b)
Definition: XBOXOLD.cpp:292
USB * pUsb
Definition: XBOXOLD.h:156
int16_t getAnalogHat(AnalogHat a)
Definition: XBOXOLD.cpp:314
virtual uint8_t Poll()
Definition: XBOXOLD.cpp:242
#define XBOX_OLD_PID2
Definition: XBOXOLD.h:41
#define MADCATZ_VID
Definition: XBOXOLD.h:37
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXOLD.cpp:62
#define XBOX_MAX_ENDPOINTS
Definition: XBOXOLD.h:49
bool getButtonClick(Button b)
Definition: XBOXOLD.cpp:299
#define XBOX_OLD_PID3
Definition: XBOXOLD.h:42
Button
bool XboxConnected
Definition: XBOXOLD.h:148
Definition: UsbCore.h:152
void setRumbleOff()
Definition: XBOXOLD.h:132
uint8_t bAddress
Definition: XBOXOLD.h:158
AnalogHat
#define EP_MAXPKTSIZE
Definition: XBOXOLD.h:25