modified to compile for me
Fork of USBHostXpad by
USBHostXpad.h@9:2b1ba1e2eb70, 2017-04-03 (annotated)
- Committer:
- Ownasaurus
- Date:
- Mon Apr 03 00:51:40 2017 +0000
- Revision:
- 9:2b1ba1e2eb70
- Parent:
- 6:954ecd99709c
Fixed support for Microsoft brand wired X360 controllers, which was not working (even though offbrands were)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 0:bd0f6bf72a8b | 1 | /* |
okini3939 | 0:bd0f6bf72a8b | 2 | * Xbox 360 Wireless Controller for Windows library |
okini3939 | 0:bd0f6bf72a8b | 3 | * for mbed USBHost library |
okini3939 | 0:bd0f6bf72a8b | 4 | * Copyright (c) 2013 Hiroshi Suga |
okini3939 | 0:bd0f6bf72a8b | 5 | * |
okini3939 | 0:bd0f6bf72a8b | 6 | * VID=0x045e PID=0x0719 |
okini3939 | 0:bd0f6bf72a8b | 7 | */ |
okini3939 | 0:bd0f6bf72a8b | 8 | |
okini3939 | 0:bd0f6bf72a8b | 9 | #ifndef USBHostXpad_H |
okini3939 | 0:bd0f6bf72a8b | 10 | #define USBHostXpad_H |
okini3939 | 0:bd0f6bf72a8b | 11 | |
okini3939 | 0:bd0f6bf72a8b | 12 | #include "USBHostConf.h" |
okini3939 | 0:bd0f6bf72a8b | 13 | |
okini3939 | 0:bd0f6bf72a8b | 14 | #if 1 or USBHOST_XPAD |
okini3939 | 0:bd0f6bf72a8b | 15 | |
okini3939 | 0:bd0f6bf72a8b | 16 | #include "USBHost.h" |
okini3939 | 0:bd0f6bf72a8b | 17 | |
okini3939 | 0:bd0f6bf72a8b | 18 | /** |
okini3939 | 0:bd0f6bf72a8b | 19 | * A class to communicate a USB flash disk |
okini3939 | 0:bd0f6bf72a8b | 20 | */ |
okini3939 | 0:bd0f6bf72a8b | 21 | class USBHostXpad : public IUSBEnumerator { |
okini3939 | 0:bd0f6bf72a8b | 22 | public: |
okini3939 | 3:53ce7778a155 | 23 | enum PAD { |
okini3939 | 2:2749f4e649db | 24 | XPAD_HAT_UP = 0x0001, |
okini3939 | 2:2749f4e649db | 25 | XPAD_HAT_DOWN = 0x0002, |
okini3939 | 2:2749f4e649db | 26 | XPAD_HAT_LEFT = 0x0004, |
okini3939 | 2:2749f4e649db | 27 | XPAD_HAT_RIGHT = 0x0008, |
okini3939 | 2:2749f4e649db | 28 | XPAD_START = 0x0010, |
okini3939 | 2:2749f4e649db | 29 | XPAD_BACK = 0x0020, |
okini3939 | 2:2749f4e649db | 30 | XPAD_STICK_L = 0x0040, |
okini3939 | 2:2749f4e649db | 31 | XPAD_STICK_R = 0x0080, |
okini3939 | 2:2749f4e649db | 32 | XPAD_PAD_LB = 0x0100, |
okini3939 | 2:2749f4e649db | 33 | XPAD_PAD_RB = 0x0200, |
okini3939 | 2:2749f4e649db | 34 | XPAD_XLOGO = 0x0400, |
okini3939 | 2:2749f4e649db | 35 | XPAD_PAD_A = 0x1000, |
okini3939 | 2:2749f4e649db | 36 | XPAD_PAD_B = 0x2000, |
okini3939 | 2:2749f4e649db | 37 | XPAD_PAD_X = 0x4000, |
okini3939 | 2:2749f4e649db | 38 | XPAD_PAD_Y = 0x8000, |
okini3939 | 3:53ce7778a155 | 39 | XPAD_BUTTONS = 0x10000, |
okini3939 | 3:53ce7778a155 | 40 | XPAD_STICK_LX, |
okini3939 | 3:53ce7778a155 | 41 | XPAD_STICK_LY, |
okini3939 | 3:53ce7778a155 | 42 | XPAD_STICK_RX, |
okini3939 | 3:53ce7778a155 | 43 | XPAD_STICK_RY, |
okini3939 | 3:53ce7778a155 | 44 | XPAD_TRIGGER_L, |
okini3939 | 3:53ce7778a155 | 45 | XPAD_TRIGGER_R, |
okini3939 | 3:53ce7778a155 | 46 | XPAD_BATTERY, |
okini3939 | 2:2749f4e649db | 47 | }; |
okini3939 | 2:2749f4e649db | 48 | |
okini3939 | 2:2749f4e649db | 49 | enum LED { |
okini3939 | 2:2749f4e649db | 50 | LED_OFF = 0x00, |
okini3939 | 2:2749f4e649db | 51 | LED_BLINK = 0x01, |
okini3939 | 2:2749f4e649db | 52 | LED1_FLASH = 0x02, |
okini3939 | 2:2749f4e649db | 53 | LED2_FLASH = 0x03, |
okini3939 | 2:2749f4e649db | 54 | LED3_FLASH = 0x04, |
okini3939 | 2:2749f4e649db | 55 | LED4_FLASH = 0x05, |
okini3939 | 2:2749f4e649db | 56 | LED1_ON = 0x06, |
okini3939 | 2:2749f4e649db | 57 | LED2_ON = 0x07, |
okini3939 | 2:2749f4e649db | 58 | LED3_ON = 0x08, |
okini3939 | 2:2749f4e649db | 59 | LED4_ON = 0x09, |
okini3939 | 2:2749f4e649db | 60 | LED_ROTATE = 0x0a, |
okini3939 | 2:2749f4e649db | 61 | LED_ALTERNATE = 0x0d, |
okini3939 | 2:2749f4e649db | 62 | }; |
okini3939 | 2:2749f4e649db | 63 | |
okini3939 | 3:53ce7778a155 | 64 | enum TYPE { |
okini3939 | 3:53ce7778a155 | 65 | TYPE_UNKNOWN, |
okini3939 | 3:53ce7778a155 | 66 | TYPE_XBOX, |
okini3939 | 3:53ce7778a155 | 67 | TYPE_XBOX360, |
okini3939 | 3:53ce7778a155 | 68 | TYPE_XBOX360W, |
Ownasaurus | 6:954ecd99709c | 69 | TYPE_XBOXONE, |
okini3939 | 3:53ce7778a155 | 70 | }; |
okini3939 | 3:53ce7778a155 | 71 | |
okini3939 | 0:bd0f6bf72a8b | 72 | /** |
okini3939 | 0:bd0f6bf72a8b | 73 | * Constructor |
okini3939 | 0:bd0f6bf72a8b | 74 | * |
okini3939 | 0:bd0f6bf72a8b | 75 | * @param rootdir mount name |
okini3939 | 0:bd0f6bf72a8b | 76 | */ |
okini3939 | 0:bd0f6bf72a8b | 77 | USBHostXpad(); |
okini3939 | 0:bd0f6bf72a8b | 78 | |
okini3939 | 0:bd0f6bf72a8b | 79 | /** |
okini3939 | 0:bd0f6bf72a8b | 80 | * Check if a MSD device is connected |
okini3939 | 0:bd0f6bf72a8b | 81 | * |
okini3939 | 0:bd0f6bf72a8b | 82 | * @return true if a MSD device is connected |
okini3939 | 0:bd0f6bf72a8b | 83 | */ |
okini3939 | 0:bd0f6bf72a8b | 84 | bool connected(); |
okini3939 | 0:bd0f6bf72a8b | 85 | |
okini3939 | 0:bd0f6bf72a8b | 86 | /** |
okini3939 | 0:bd0f6bf72a8b | 87 | * Try to connect to a MSD device |
okini3939 | 0:bd0f6bf72a8b | 88 | * |
okini3939 | 0:bd0f6bf72a8b | 89 | * @return true if connection was successful |
okini3939 | 0:bd0f6bf72a8b | 90 | */ |
okini3939 | 0:bd0f6bf72a8b | 91 | bool connect(); |
okini3939 | 0:bd0f6bf72a8b | 92 | |
okini3939 | 0:bd0f6bf72a8b | 93 | /** |
okini3939 | 0:bd0f6bf72a8b | 94 | * Attach a callback called when a mouse event is received |
okini3939 | 0:bd0f6bf72a8b | 95 | * |
okini3939 | 0:bd0f6bf72a8b | 96 | * @param ptr function pointer |
okini3939 | 0:bd0f6bf72a8b | 97 | */ |
okini3939 | 0:bd0f6bf72a8b | 98 | inline void attachEvent(void (*ptr)(int buttons, int stick_lx, int stick_ly, int stick_rx, int stick_ry, int trigger_l, int trigger_r)) { |
okini3939 | 0:bd0f6bf72a8b | 99 | if (ptr != NULL) { |
okini3939 | 0:bd0f6bf72a8b | 100 | onUpdate = ptr; |
okini3939 | 0:bd0f6bf72a8b | 101 | } |
okini3939 | 0:bd0f6bf72a8b | 102 | } |
okini3939 | 0:bd0f6bf72a8b | 103 | |
okini3939 | 3:53ce7778a155 | 104 | int read (PAD pad); |
okini3939 | 2:2749f4e649db | 105 | bool led (LED cmd); |
okini3939 | 2:2749f4e649db | 106 | bool rumble (uint8_t large, uint8_t small); |
okini3939 | 0:bd0f6bf72a8b | 107 | |
okini3939 | 3:53ce7778a155 | 108 | bool restart (); |
okini3939 | 3:53ce7778a155 | 109 | bool stop(); |
okini3939 | 0:bd0f6bf72a8b | 110 | |
okini3939 | 0:bd0f6bf72a8b | 111 | protected: |
okini3939 | 0:bd0f6bf72a8b | 112 | //From IUSBEnumerator |
okini3939 | 0:bd0f6bf72a8b | 113 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
okini3939 | 0:bd0f6bf72a8b | 114 | virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed |
okini3939 | 0:bd0f6bf72a8b | 115 | virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used |
okini3939 | 0:bd0f6bf72a8b | 116 | |
okini3939 | 0:bd0f6bf72a8b | 117 | private: |
okini3939 | 0:bd0f6bf72a8b | 118 | USBHost * host; |
okini3939 | 0:bd0f6bf72a8b | 119 | USBDeviceConnected * dev; |
okini3939 | 3:53ce7778a155 | 120 | volatile bool dev_connected; |
okini3939 | 3:53ce7778a155 | 121 | TYPE dev_type; |
okini3939 | 3:53ce7778a155 | 122 | volatile bool dev_started; |
okini3939 | 0:bd0f6bf72a8b | 123 | |
okini3939 | 0:bd0f6bf72a8b | 124 | USBEndpoint * int_in; |
okini3939 | 0:bd0f6bf72a8b | 125 | USBEndpoint * int_out; |
okini3939 | 0:bd0f6bf72a8b | 126 | uint8_t nb_ep; |
okini3939 | 0:bd0f6bf72a8b | 127 | int xpad_intf; |
okini3939 | 0:bd0f6bf72a8b | 128 | bool xpad_device_found; |
okini3939 | 0:bd0f6bf72a8b | 129 | uint8_t report[32]; |
okini3939 | 0:bd0f6bf72a8b | 130 | |
okini3939 | 0:bd0f6bf72a8b | 131 | uint32_t buttons; |
okini3939 | 0:bd0f6bf72a8b | 132 | int16_t stick_lx, stick_ly, stick_rx, stick_ry; |
okini3939 | 0:bd0f6bf72a8b | 133 | uint8_t trigger_l, trigger_r; |
okini3939 | 3:53ce7778a155 | 134 | uint8_t battery; |
okini3939 | 0:bd0f6bf72a8b | 135 | |
okini3939 | 0:bd0f6bf72a8b | 136 | void rxHandler(); |
okini3939 | 3:53ce7778a155 | 137 | void parseMessage(); |
okini3939 | 0:bd0f6bf72a8b | 138 | void (*onUpdate)(int buttons, int stick_lx, int stick_ly, int stick_rx, int stick_ry, int trigger_l, int trigger_r); |
okini3939 | 0:bd0f6bf72a8b | 139 | void init(); |
Ownasaurus | 6:954ecd99709c | 140 | unsigned char serial; |
okini3939 | 3:53ce7778a155 | 141 | bool start(); |
okini3939 | 0:bd0f6bf72a8b | 142 | |
okini3939 | 0:bd0f6bf72a8b | 143 | }; |
okini3939 | 0:bd0f6bf72a8b | 144 | |
okini3939 | 0:bd0f6bf72a8b | 145 | #endif |
okini3939 | 0:bd0f6bf72a8b | 146 | |
okini3939 | 0:bd0f6bf72a8b | 147 | #endif |