modified to compile for me
Fork of USBHostXpad by
USBHostXpad.h@3:53ce7778a155, 2013-12-13 (annotated)
- Committer:
- okini3939
- Date:
- Fri Dec 13 07:36:09 2013 +0000
- Revision:
- 3:53ce7778a155
- Parent:
- 2:2749f4e649db
- Child:
- 6:954ecd99709c
fix
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, |
okini3939 | 3:53ce7778a155 | 69 | }; |
okini3939 | 3:53ce7778a155 | 70 | |
okini3939 | 0:bd0f6bf72a8b | 71 | /** |
okini3939 | 0:bd0f6bf72a8b | 72 | * Constructor |
okini3939 | 0:bd0f6bf72a8b | 73 | * |
okini3939 | 0:bd0f6bf72a8b | 74 | * @param rootdir mount name |
okini3939 | 0:bd0f6bf72a8b | 75 | */ |
okini3939 | 0:bd0f6bf72a8b | 76 | USBHostXpad(); |
okini3939 | 0:bd0f6bf72a8b | 77 | |
okini3939 | 0:bd0f6bf72a8b | 78 | /** |
okini3939 | 0:bd0f6bf72a8b | 79 | * Check if a MSD device is connected |
okini3939 | 0:bd0f6bf72a8b | 80 | * |
okini3939 | 0:bd0f6bf72a8b | 81 | * @return true if a MSD device is connected |
okini3939 | 0:bd0f6bf72a8b | 82 | */ |
okini3939 | 0:bd0f6bf72a8b | 83 | bool connected(); |
okini3939 | 0:bd0f6bf72a8b | 84 | |
okini3939 | 0:bd0f6bf72a8b | 85 | /** |
okini3939 | 0:bd0f6bf72a8b | 86 | * Try to connect to a MSD device |
okini3939 | 0:bd0f6bf72a8b | 87 | * |
okini3939 | 0:bd0f6bf72a8b | 88 | * @return true if connection was successful |
okini3939 | 0:bd0f6bf72a8b | 89 | */ |
okini3939 | 0:bd0f6bf72a8b | 90 | bool connect(); |
okini3939 | 0:bd0f6bf72a8b | 91 | |
okini3939 | 0:bd0f6bf72a8b | 92 | /** |
okini3939 | 0:bd0f6bf72a8b | 93 | * Attach a callback called when a mouse event is received |
okini3939 | 0:bd0f6bf72a8b | 94 | * |
okini3939 | 0:bd0f6bf72a8b | 95 | * @param ptr function pointer |
okini3939 | 0:bd0f6bf72a8b | 96 | */ |
okini3939 | 0:bd0f6bf72a8b | 97 | 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 | 98 | if (ptr != NULL) { |
okini3939 | 0:bd0f6bf72a8b | 99 | onUpdate = ptr; |
okini3939 | 0:bd0f6bf72a8b | 100 | } |
okini3939 | 0:bd0f6bf72a8b | 101 | } |
okini3939 | 0:bd0f6bf72a8b | 102 | |
okini3939 | 3:53ce7778a155 | 103 | int read (PAD pad); |
okini3939 | 2:2749f4e649db | 104 | bool led (LED cmd); |
okini3939 | 2:2749f4e649db | 105 | bool rumble (uint8_t large, uint8_t small); |
okini3939 | 0:bd0f6bf72a8b | 106 | |
okini3939 | 3:53ce7778a155 | 107 | bool restart (); |
okini3939 | 3:53ce7778a155 | 108 | bool stop(); |
okini3939 | 0:bd0f6bf72a8b | 109 | |
okini3939 | 0:bd0f6bf72a8b | 110 | protected: |
okini3939 | 0:bd0f6bf72a8b | 111 | //From IUSBEnumerator |
okini3939 | 0:bd0f6bf72a8b | 112 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
okini3939 | 0:bd0f6bf72a8b | 113 | 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 | 114 | 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 | 115 | |
okini3939 | 0:bd0f6bf72a8b | 116 | private: |
okini3939 | 0:bd0f6bf72a8b | 117 | USBHost * host; |
okini3939 | 0:bd0f6bf72a8b | 118 | USBDeviceConnected * dev; |
okini3939 | 3:53ce7778a155 | 119 | volatile bool dev_connected; |
okini3939 | 3:53ce7778a155 | 120 | TYPE dev_type; |
okini3939 | 3:53ce7778a155 | 121 | volatile bool dev_started; |
okini3939 | 0:bd0f6bf72a8b | 122 | |
okini3939 | 0:bd0f6bf72a8b | 123 | USBEndpoint * int_in; |
okini3939 | 0:bd0f6bf72a8b | 124 | USBEndpoint * int_out; |
okini3939 | 0:bd0f6bf72a8b | 125 | uint8_t nb_ep; |
okini3939 | 0:bd0f6bf72a8b | 126 | int xpad_intf; |
okini3939 | 0:bd0f6bf72a8b | 127 | bool xpad_device_found; |
okini3939 | 0:bd0f6bf72a8b | 128 | uint8_t report[32]; |
okini3939 | 0:bd0f6bf72a8b | 129 | |
okini3939 | 0:bd0f6bf72a8b | 130 | uint32_t buttons; |
okini3939 | 0:bd0f6bf72a8b | 131 | int16_t stick_lx, stick_ly, stick_rx, stick_ry; |
okini3939 | 0:bd0f6bf72a8b | 132 | uint8_t trigger_l, trigger_r; |
okini3939 | 3:53ce7778a155 | 133 | uint8_t battery; |
okini3939 | 0:bd0f6bf72a8b | 134 | |
okini3939 | 0:bd0f6bf72a8b | 135 | void rxHandler(); |
okini3939 | 3:53ce7778a155 | 136 | void parseMessage(); |
okini3939 | 0:bd0f6bf72a8b | 137 | 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 | 138 | void init(); |
okini3939 | 3:53ce7778a155 | 139 | bool start(); |
okini3939 | 0:bd0f6bf72a8b | 140 | |
okini3939 | 0:bd0f6bf72a8b | 141 | }; |
okini3939 | 0:bd0f6bf72a8b | 142 | |
okini3939 | 0:bd0f6bf72a8b | 143 | #endif |
okini3939 | 0:bd0f6bf72a8b | 144 | |
okini3939 | 0:bd0f6bf72a8b | 145 | #endif |