modified to compile for me

Dependents:   N64_Output_XPAD

Fork of USBHostXpad by Suga koubou

Committer:
okini3939
Date:
Wed Dec 11 05:03:05 2013 +0000
Revision:
2:2749f4e649db
Parent:
1:5bb153989f33
Child:
3:53ce7778a155
add read function

Who changed what in which revision?

UserRevisionLine numberNew 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 2:2749f4e649db 23 enum TYPE {
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 2:2749f4e649db 39 XPAD_STICK_LX = 0x10000,
okini3939 2:2749f4e649db 40 XPAD_STICK_LY = 0x10001,
okini3939 2:2749f4e649db 41 XPAD_STICK_RX = 0x10002,
okini3939 2:2749f4e649db 42 XPAD_STICK_RY = 0x10003,
okini3939 2:2749f4e649db 43 XPAD_TRIGGER_L = 0x10004,
okini3939 2:2749f4e649db 44 XPAD_TRIGGER_R = 0x10005,
okini3939 2:2749f4e649db 45 };
okini3939 2:2749f4e649db 46
okini3939 2:2749f4e649db 47 enum LED {
okini3939 2:2749f4e649db 48 LED_OFF = 0x00,
okini3939 2:2749f4e649db 49 LED_BLINK = 0x01,
okini3939 2:2749f4e649db 50 LED1_FLASH = 0x02,
okini3939 2:2749f4e649db 51 LED2_FLASH = 0x03,
okini3939 2:2749f4e649db 52 LED3_FLASH = 0x04,
okini3939 2:2749f4e649db 53 LED4_FLASH = 0x05,
okini3939 2:2749f4e649db 54 LED1_ON = 0x06,
okini3939 2:2749f4e649db 55 LED2_ON = 0x07,
okini3939 2:2749f4e649db 56 LED3_ON = 0x08,
okini3939 2:2749f4e649db 57 LED4_ON = 0x09,
okini3939 2:2749f4e649db 58 LED_ROTATE = 0x0a,
okini3939 2:2749f4e649db 59 LED_ALTERNATE = 0x0d,
okini3939 2:2749f4e649db 60 };
okini3939 2:2749f4e649db 61
okini3939 0:bd0f6bf72a8b 62 /**
okini3939 0:bd0f6bf72a8b 63 * Constructor
okini3939 0:bd0f6bf72a8b 64 *
okini3939 0:bd0f6bf72a8b 65 * @param rootdir mount name
okini3939 0:bd0f6bf72a8b 66 */
okini3939 0:bd0f6bf72a8b 67 USBHostXpad();
okini3939 0:bd0f6bf72a8b 68
okini3939 0:bd0f6bf72a8b 69 /**
okini3939 0:bd0f6bf72a8b 70 * Check if a MSD device is connected
okini3939 0:bd0f6bf72a8b 71 *
okini3939 0:bd0f6bf72a8b 72 * @return true if a MSD device is connected
okini3939 0:bd0f6bf72a8b 73 */
okini3939 0:bd0f6bf72a8b 74 bool connected();
okini3939 0:bd0f6bf72a8b 75
okini3939 0:bd0f6bf72a8b 76 /**
okini3939 0:bd0f6bf72a8b 77 * Try to connect to a MSD device
okini3939 0:bd0f6bf72a8b 78 *
okini3939 0:bd0f6bf72a8b 79 * @return true if connection was successful
okini3939 0:bd0f6bf72a8b 80 */
okini3939 0:bd0f6bf72a8b 81 bool connect();
okini3939 0:bd0f6bf72a8b 82
okini3939 0:bd0f6bf72a8b 83 /**
okini3939 0:bd0f6bf72a8b 84 * Attach a callback called when a mouse event is received
okini3939 0:bd0f6bf72a8b 85 *
okini3939 0:bd0f6bf72a8b 86 * @param ptr function pointer
okini3939 0:bd0f6bf72a8b 87 */
okini3939 0:bd0f6bf72a8b 88 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 89 if (ptr != NULL) {
okini3939 0:bd0f6bf72a8b 90 onUpdate = ptr;
okini3939 0:bd0f6bf72a8b 91 }
okini3939 0:bd0f6bf72a8b 92 }
okini3939 0:bd0f6bf72a8b 93
okini3939 2:2749f4e649db 94 int read (TYPE type);
okini3939 2:2749f4e649db 95 bool led (LED cmd);
okini3939 2:2749f4e649db 96 bool rumble (uint8_t large, uint8_t small);
okini3939 0:bd0f6bf72a8b 97
okini3939 1:5bb153989f33 98 void restart ();
okini3939 0:bd0f6bf72a8b 99
okini3939 0:bd0f6bf72a8b 100 protected:
okini3939 0:bd0f6bf72a8b 101 //From IUSBEnumerator
okini3939 0:bd0f6bf72a8b 102 virtual void setVidPid(uint16_t vid, uint16_t pid);
okini3939 0:bd0f6bf72a8b 103 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 104 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 105
okini3939 0:bd0f6bf72a8b 106 private:
okini3939 0:bd0f6bf72a8b 107 USBHost * host;
okini3939 0:bd0f6bf72a8b 108 USBDeviceConnected * dev;
okini3939 0:bd0f6bf72a8b 109 bool dev_connected;
okini3939 0:bd0f6bf72a8b 110
okini3939 0:bd0f6bf72a8b 111 USBEndpoint * int_in;
okini3939 0:bd0f6bf72a8b 112 USBEndpoint * int_out;
okini3939 0:bd0f6bf72a8b 113 uint8_t nb_ep;
okini3939 0:bd0f6bf72a8b 114 int xpad_intf;
okini3939 0:bd0f6bf72a8b 115 bool xpad_device_found;
okini3939 0:bd0f6bf72a8b 116 uint8_t report[32];
okini3939 0:bd0f6bf72a8b 117
okini3939 0:bd0f6bf72a8b 118 uint32_t buttons;
okini3939 0:bd0f6bf72a8b 119 int16_t stick_lx, stick_ly, stick_rx, stick_ry;
okini3939 0:bd0f6bf72a8b 120 uint8_t trigger_l, trigger_r;
okini3939 0:bd0f6bf72a8b 121
okini3939 0:bd0f6bf72a8b 122 void rxHandler();
okini3939 0:bd0f6bf72a8b 123 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 124 void init();
okini3939 1:5bb153989f33 125 bool send(int val1, int val2, int val3, int val4);
okini3939 0:bd0f6bf72a8b 126
okini3939 0:bd0f6bf72a8b 127 };
okini3939 0:bd0f6bf72a8b 128
okini3939 0:bd0f6bf72a8b 129 #endif
okini3939 0:bd0f6bf72a8b 130
okini3939 0:bd0f6bf72a8b 131 #endif