modified to compile for me
Fork of USBHostXpad by
USBHostXpad.h@1:5bb153989f33, 2013-12-11 (annotated)
- Committer:
- okini3939
- Date:
- Wed Dec 11 04:11:04 2013 +0000
- Revision:
- 1:5bb153989f33
- Parent:
- 0:bd0f6bf72a8b
- Child:
- 2:2749f4e649db
fix led, rumble
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 | 1:5bb153989f33 | 18 | #define XPAD_HAT_UP 0x0001 |
okini3939 | 1:5bb153989f33 | 19 | #define XPAD_HAT_DOWN 0x0002 |
okini3939 | 0:bd0f6bf72a8b | 20 | #define XPAD_HAT_LEFT 0x0004 |
okini3939 | 0:bd0f6bf72a8b | 21 | #define XPAD_HAT_RIGHT 0x0008 |
okini3939 | 0:bd0f6bf72a8b | 22 | #define XPAD_START 0x0010 |
okini3939 | 0:bd0f6bf72a8b | 23 | #define XPAD_BACK 0x0020 |
okini3939 | 1:5bb153989f33 | 24 | #define XPAD_STICK_L 0x0040 |
okini3939 | 1:5bb153989f33 | 25 | #define XPAD_STICK_R 0x0080 |
okini3939 | 0:bd0f6bf72a8b | 26 | #define XPAD_PAD_LB 0x0100 |
okini3939 | 0:bd0f6bf72a8b | 27 | #define XPAD_PAD_RB 0x0200 |
okini3939 | 0:bd0f6bf72a8b | 28 | #define XPAD_XLOGO 0x0400 |
okini3939 | 0:bd0f6bf72a8b | 29 | #define XPAD_PAD_A 0x1000 |
okini3939 | 0:bd0f6bf72a8b | 30 | #define XPAD_PAD_B 0x2000 |
okini3939 | 0:bd0f6bf72a8b | 31 | #define XPAD_PAD_X 0x4000 |
okini3939 | 0:bd0f6bf72a8b | 32 | #define XPAD_PAD_Y 0x8000 |
okini3939 | 0:bd0f6bf72a8b | 33 | |
okini3939 | 1:5bb153989f33 | 34 | #define XPAD_LED_OFF 0x00 |
okini3939 | 1:5bb153989f33 | 35 | #define XPAD_LED_BLINK 0x01 |
okini3939 | 1:5bb153989f33 | 36 | #define XPAD_LED1_FLASH 0x02 |
okini3939 | 1:5bb153989f33 | 37 | #define XPAD_LED2_FLASH 0x03 |
okini3939 | 1:5bb153989f33 | 38 | #define XPAD_LED3_FLASH 0x04 |
okini3939 | 1:5bb153989f33 | 39 | #define XPAD_LED4_FLASH 0x05 |
okini3939 | 1:5bb153989f33 | 40 | #define XPAD_LED1_ON 0x06 |
okini3939 | 1:5bb153989f33 | 41 | #define XPAD_LED2_ON 0x07 |
okini3939 | 1:5bb153989f33 | 42 | #define XPAD_LED3_ON 0x08 |
okini3939 | 1:5bb153989f33 | 43 | #define XPAD_LED4_ON 0x09 |
okini3939 | 1:5bb153989f33 | 44 | #define XPAD_LED_ROTATE 0x0a |
okini3939 | 1:5bb153989f33 | 45 | #define XPAD_LED_ALTERNATE 0x0d |
okini3939 | 1:5bb153989f33 | 46 | |
okini3939 | 1:5bb153989f33 | 47 | |
okini3939 | 0:bd0f6bf72a8b | 48 | /** |
okini3939 | 0:bd0f6bf72a8b | 49 | * A class to communicate a USB flash disk |
okini3939 | 0:bd0f6bf72a8b | 50 | */ |
okini3939 | 0:bd0f6bf72a8b | 51 | class USBHostXpad : public IUSBEnumerator { |
okini3939 | 0:bd0f6bf72a8b | 52 | public: |
okini3939 | 0:bd0f6bf72a8b | 53 | /** |
okini3939 | 0:bd0f6bf72a8b | 54 | * Constructor |
okini3939 | 0:bd0f6bf72a8b | 55 | * |
okini3939 | 0:bd0f6bf72a8b | 56 | * @param rootdir mount name |
okini3939 | 0:bd0f6bf72a8b | 57 | */ |
okini3939 | 0:bd0f6bf72a8b | 58 | USBHostXpad(); |
okini3939 | 0:bd0f6bf72a8b | 59 | |
okini3939 | 0:bd0f6bf72a8b | 60 | /** |
okini3939 | 0:bd0f6bf72a8b | 61 | * Check if a MSD device is connected |
okini3939 | 0:bd0f6bf72a8b | 62 | * |
okini3939 | 0:bd0f6bf72a8b | 63 | * @return true if a MSD device is connected |
okini3939 | 0:bd0f6bf72a8b | 64 | */ |
okini3939 | 0:bd0f6bf72a8b | 65 | bool connected(); |
okini3939 | 0:bd0f6bf72a8b | 66 | |
okini3939 | 0:bd0f6bf72a8b | 67 | /** |
okini3939 | 0:bd0f6bf72a8b | 68 | * Try to connect to a MSD device |
okini3939 | 0:bd0f6bf72a8b | 69 | * |
okini3939 | 0:bd0f6bf72a8b | 70 | * @return true if connection was successful |
okini3939 | 0:bd0f6bf72a8b | 71 | */ |
okini3939 | 0:bd0f6bf72a8b | 72 | bool connect(); |
okini3939 | 0:bd0f6bf72a8b | 73 | |
okini3939 | 0:bd0f6bf72a8b | 74 | /** |
okini3939 | 0:bd0f6bf72a8b | 75 | * Attach a callback called when a mouse event is received |
okini3939 | 0:bd0f6bf72a8b | 76 | * |
okini3939 | 0:bd0f6bf72a8b | 77 | * @param ptr function pointer |
okini3939 | 0:bd0f6bf72a8b | 78 | */ |
okini3939 | 0:bd0f6bf72a8b | 79 | 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 | 80 | if (ptr != NULL) { |
okini3939 | 0:bd0f6bf72a8b | 81 | onUpdate = ptr; |
okini3939 | 0:bd0f6bf72a8b | 82 | } |
okini3939 | 0:bd0f6bf72a8b | 83 | } |
okini3939 | 0:bd0f6bf72a8b | 84 | |
okini3939 | 1:5bb153989f33 | 85 | bool led(int cmd); |
okini3939 | 1:5bb153989f33 | 86 | bool rumble(uint8_t large, uint8_t small); |
okini3939 | 0:bd0f6bf72a8b | 87 | |
okini3939 | 1:5bb153989f33 | 88 | void restart (); |
okini3939 | 0:bd0f6bf72a8b | 89 | |
okini3939 | 0:bd0f6bf72a8b | 90 | protected: |
okini3939 | 0:bd0f6bf72a8b | 91 | //From IUSBEnumerator |
okini3939 | 0:bd0f6bf72a8b | 92 | virtual void setVidPid(uint16_t vid, uint16_t pid); |
okini3939 | 0:bd0f6bf72a8b | 93 | 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 | 94 | 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 | 95 | |
okini3939 | 0:bd0f6bf72a8b | 96 | private: |
okini3939 | 0:bd0f6bf72a8b | 97 | USBHost * host; |
okini3939 | 0:bd0f6bf72a8b | 98 | USBDeviceConnected * dev; |
okini3939 | 0:bd0f6bf72a8b | 99 | bool dev_connected; |
okini3939 | 0:bd0f6bf72a8b | 100 | |
okini3939 | 0:bd0f6bf72a8b | 101 | USBEndpoint * int_in; |
okini3939 | 0:bd0f6bf72a8b | 102 | USBEndpoint * int_out; |
okini3939 | 0:bd0f6bf72a8b | 103 | uint8_t nb_ep; |
okini3939 | 0:bd0f6bf72a8b | 104 | int xpad_intf; |
okini3939 | 0:bd0f6bf72a8b | 105 | bool xpad_device_found; |
okini3939 | 0:bd0f6bf72a8b | 106 | uint8_t report[32]; |
okini3939 | 0:bd0f6bf72a8b | 107 | |
okini3939 | 0:bd0f6bf72a8b | 108 | uint32_t buttons; |
okini3939 | 0:bd0f6bf72a8b | 109 | int16_t stick_lx, stick_ly, stick_rx, stick_ry; |
okini3939 | 0:bd0f6bf72a8b | 110 | uint8_t trigger_l, trigger_r; |
okini3939 | 0:bd0f6bf72a8b | 111 | |
okini3939 | 0:bd0f6bf72a8b | 112 | void rxHandler(); |
okini3939 | 0:bd0f6bf72a8b | 113 | 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 | 114 | void init(); |
okini3939 | 1:5bb153989f33 | 115 | bool send(int val1, int val2, int val3, int val4); |
okini3939 | 0:bd0f6bf72a8b | 116 | |
okini3939 | 0:bd0f6bf72a8b | 117 | }; |
okini3939 | 0:bd0f6bf72a8b | 118 | |
okini3939 | 0:bd0f6bf72a8b | 119 | #endif |
okini3939 | 0:bd0f6bf72a8b | 120 | |
okini3939 | 0:bd0f6bf72a8b | 121 | #endif |