USB Host Shield 2.0
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 "usbhid.h"
23 #include "controllerEnums.h"
24 
25 /* Data Xbox taken from descriptors */
26 #define EP_MAXPKTSIZE 32 // Max size for data via USB
27 
28 /* Names we give to the 3 Xbox 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 
38 #define XBOX_OLD_PID1 0x0202 // Original Microsoft Xbox controller (US)
39 #define XBOX_OLD_PID2 0x0285 // Original Microsoft Xbox controller (Japan)
40 #define XBOX_OLD_PID3 0x0287 // Microsoft Microsoft Xbox Controller S
41 #define XBOX_OLD_PID4 0x0289 // Smaller Microsoft Xbox controller (US)
42 
43 #define XBOX_MAX_ENDPOINTS 3
44 
46 class XBOXOLD : public USBDeviceConfig {
47 public:
52  XBOXOLD(USB *pUsb);
53 
62  uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
67  uint8_t Release();
72  uint8_t Poll();
73 
78  virtual uint8_t GetAddress() {
79  return bAddress;
80  };
81 
86  virtual bool isReady() {
87  return bPollEnable;
88  };
89 
96  virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) {
97  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));
98  };
112  uint8_t getButtonPress(ButtonEnum b);
113  bool getButtonClick(ButtonEnum b);
122  int16_t getAnalogHat(AnalogHatEnum a);
123 
125  void setRumbleOff() {
126  setRumbleOn(0, 0);
127  };
133  void setRumbleOn(uint8_t lValue, uint8_t rValue);
134 
139  void attachOnInit(void (*funcOnInit)(void)) {
140  pFuncOnInit = funcOnInit;
141  };
145  bool XboxConnected;
146 
147 protected:
151  uint8_t bAddress;
154 
155 private:
156  static int8_t getAnalogIndex(ButtonEnum b);
157  static int8_t getDigitalIndex(ButtonEnum b);
158 
164  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
165 
166  bool bPollEnable;
167 
168  /* Variables to store the digital buttons */
169  uint8_t ButtonState;
170  uint8_t OldButtonState;
171  uint8_t ButtonClickState;
172 
173  /* Variables to store the analog buttons */
174  uint8_t buttonValues[8]; // A, B, X, Y, BLACK, WHITE, L1, and R1
175  uint8_t oldButtonValues[8];
176  bool buttonClicked[8];
177 
178  int16_t hatValue[4]; // Joystick values
179 
180  uint8_t readBuf[EP_MAXPKTSIZE]; // General purpose buffer for input data
181 
182  void readReport(); // Read incoming data
183  void printReport(uint16_t length); // Print incoming date
184 
185  /* Private commands */
186  void XboxCommand(uint8_t* data, uint16_t nbytes);
187 };
188 #endif
XBOXOLD::setRumbleOff
void setRumbleOff()
Definition: XBOXOLD.h:125
USBDeviceConfig
Definition: UsbCore.h:134
XBOXOLD::getAnalogHat
int16_t getAnalogHat(AnalogHatEnum a)
Definition: XBOXOLD.cpp:369
MADCATZ_VID
#define MADCATZ_VID
Definition: XBOXOLD.h:35
XBOXOLD::XboxConnected
bool XboxConnected
Definition: XBOXOLD.h:141
usbhid.h
XBOXOLD::getButtonPress
uint8_t getButtonPress(ButtonEnum b)
Definition: XBOXOLD.cpp:335
XBOX_OLD_PID1
#define XBOX_OLD_PID1
Definition: XBOXOLD.h:38
XBOXOLD::getButtonClick
bool getButtonClick(ButtonEnum b)
Definition: XBOXOLD.cpp:349
XBOXOLD::isReady
virtual bool isReady()
Definition: XBOXOLD.h:86
XBOXOLD::epInfo
EpInfo epInfo[XBOX_MAX_ENDPOINTS]
Definition: XBOXOLD.h:153
XBOX_OLD_PID3
#define XBOX_OLD_PID3
Definition: XBOXOLD.h:40
XBOXOLD::attachOnInit
void attachOnInit(void(*funcOnInit)(void))
Definition: XBOXOLD.h:139
XBOXOLD::VIDPIDOK
virtual bool VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: XBOXOLD.h:96
XBOXOLD::Release
uint8_t Release()
Definition: XBOXOLD.cpp:237
XBOXOLD::Poll
uint8_t Poll()
Definition: XBOXOLD.cpp:245
EpInfo
Definition: address.h:39
JOYTECH_VID
#define JOYTECH_VID
Definition: XBOXOLD.h:36
controllerEnums.h
XBOXOLD::XBOXOLD
XBOXOLD(USB *pUsb)
Definition: XBOXOLD.cpp:47
USB
Definition: UsbCore.h:210
XBOXOLD::Init
uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: XBOXOLD.cpp:63
XBOXOLD::GetAddress
virtual uint8_t GetAddress()
Definition: XBOXOLD.h:78
XBOXOLD::setRumbleOn
void setRumbleOn(uint8_t lValue, uint8_t rValue)
Definition: XBOXOLD.cpp:379
XBOXOLD
Definition: XBOXOLD.h:46
XBOX_OLD_PID4
#define XBOX_OLD_PID4
Definition: XBOXOLD.h:41
XBOXOLD::pUsb
USB * pUsb
Definition: XBOXOLD.h:149
XBOX_MAX_ENDPOINTS
#define XBOX_MAX_ENDPOINTS
Definition: XBOXOLD.h:43
XBOX_OLD_PID2
#define XBOX_OLD_PID2
Definition: XBOXOLD.h:39
XBOXOLD::bAddress
uint8_t bAddress
Definition: XBOXOLD.h:151
Usb.h
XBOX_VID
#define XBOX_VID
Definition: XBOXOLD.h:34
ButtonEnum
ButtonEnum
Definition: controllerEnums.h:78
EP_MAXPKTSIZE
#define EP_MAXPKTSIZE
Definition: XBOXOLD.h:26
AnalogHatEnum
AnalogHatEnum
Definition: controllerEnums.h:213