ORTP-L_WiiRemoteTest

Dependencies:   Motordriver mbed FatFileSystem

Fork of WallbotTypeN by Junichi Katsu

Committer:
passionvirus
Date:
Fri Mar 29 09:05:28 2013 +0000
Revision:
1:df4118878dc4
Parent:
0:425791fe4b42
init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jksoft 0:425791fe4b42 1
jksoft 0:425791fe4b42 2 /*
jksoft 0:425791fe4b42 3 Copyright (c) 2010 Peter Barrett
jksoft 0:425791fe4b42 4
jksoft 0:425791fe4b42 5 Permission is hereby granted, free of charge, to any person obtaining a copy
jksoft 0:425791fe4b42 6 of this software and associated documentation files (the "Software"), to deal
jksoft 0:425791fe4b42 7 in the Software without restriction, including without limitation the rights
jksoft 0:425791fe4b42 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jksoft 0:425791fe4b42 9 copies of the Software, and to permit persons to whom the Software is
jksoft 0:425791fe4b42 10 furnished to do so, subject to the following conditions:
jksoft 0:425791fe4b42 11
jksoft 0:425791fe4b42 12 The above copyright notice and this permission notice shall be included in
jksoft 0:425791fe4b42 13 all copies or substantial portions of the Software.
jksoft 0:425791fe4b42 14
jksoft 0:425791fe4b42 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jksoft 0:425791fe4b42 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jksoft 0:425791fe4b42 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jksoft 0:425791fe4b42 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jksoft 0:425791fe4b42 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jksoft 0:425791fe4b42 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jksoft 0:425791fe4b42 21 THE SOFTWARE.
jksoft 0:425791fe4b42 22 */
jksoft 0:425791fe4b42 23
jksoft 0:425791fe4b42 24 #ifndef USBHOST_H
jksoft 0:425791fe4b42 25 #define USBHOST_H
jksoft 0:425791fe4b42 26
jksoft 0:425791fe4b42 27 #ifndef u8
jksoft 0:425791fe4b42 28 typedef unsigned char u8;
jksoft 0:425791fe4b42 29 typedef unsigned short u16;
jksoft 0:425791fe4b42 30 typedef unsigned long u32;
jksoft 0:425791fe4b42 31
jksoft 0:425791fe4b42 32 typedef char s8;
jksoft 0:425791fe4b42 33 typedef short s16;
jksoft 0:425791fe4b42 34 typedef char s32;
jksoft 0:425791fe4b42 35 #endif
jksoft 0:425791fe4b42 36
jksoft 0:425791fe4b42 37 #define ENDPOINT_CONTROL 0
jksoft 0:425791fe4b42 38 #define ENDPOINT_ISOCRONOUS 1
jksoft 0:425791fe4b42 39 #define ENDPOINT_BULK 2
jksoft 0:425791fe4b42 40 #define ENDPOINT_INTERRUPT 3
jksoft 0:425791fe4b42 41
jksoft 0:425791fe4b42 42 #define DESCRIPTOR_TYPE_DEVICE 1
jksoft 0:425791fe4b42 43 #define DESCRIPTOR_TYPE_CONFIGURATION 2
jksoft 0:425791fe4b42 44 #define DESCRIPTOR_TYPE_STRING 3
jksoft 0:425791fe4b42 45 #define DESCRIPTOR_TYPE_INTERFACE 4
jksoft 0:425791fe4b42 46 #define DESCRIPTOR_TYPE_ENDPOINT 5
jksoft 0:425791fe4b42 47
jksoft 0:425791fe4b42 48 #define DESCRIPTOR_TYPE_HID 0x21
jksoft 0:425791fe4b42 49 #define DESCRIPTOR_TYPE_REPORT 0x22
jksoft 0:425791fe4b42 50 #define DESCRIPTOR_TYPE_PHYSICAL 0x23
jksoft 0:425791fe4b42 51 #define DESCRIPTOR_TYPE_HUB 0x29
jksoft 0:425791fe4b42 52
jksoft 0:425791fe4b42 53 enum USB_CLASS_CODE
jksoft 0:425791fe4b42 54 {
jksoft 0:425791fe4b42 55 CLASS_DEVICE,
jksoft 0:425791fe4b42 56 CLASS_AUDIO,
jksoft 0:425791fe4b42 57 CLASS_COMM_AND_CDC_CONTROL,
jksoft 0:425791fe4b42 58 CLASS_HID,
jksoft 0:425791fe4b42 59 CLASS_PHYSICAL = 0x05,
jksoft 0:425791fe4b42 60 CLASS_STILL_IMAGING,
jksoft 0:425791fe4b42 61 CLASS_PRINTER,
jksoft 0:425791fe4b42 62 CLASS_MASS_STORAGE,
jksoft 0:425791fe4b42 63 CLASS_HUB,
jksoft 0:425791fe4b42 64 CLASS_CDC_DATA,
jksoft 0:425791fe4b42 65 CLASS_SMART_CARD,
jksoft 0:425791fe4b42 66 CLASS_CONTENT_SECURITY = 0x0D,
jksoft 0:425791fe4b42 67 CLASS_VIDEO = 0x0E,
jksoft 0:425791fe4b42 68 CLASS_DIAGNOSTIC_DEVICE = 0xDC,
jksoft 0:425791fe4b42 69 CLASS_WIRELESS_CONTROLLER = 0xE0,
jksoft 0:425791fe4b42 70 CLASS_MISCELLANEOUS = 0xEF,
jksoft 0:425791fe4b42 71 CLASS_APP_SPECIFIC = 0xFE,
jksoft 0:425791fe4b42 72 CLASS_VENDOR_SPECIFIC = 0xFF
jksoft 0:425791fe4b42 73 };
jksoft 0:425791fe4b42 74
jksoft 0:425791fe4b42 75 #define DEVICE_TO_HOST 0x80
jksoft 0:425791fe4b42 76 #define HOST_TO_DEVICE 0x00
jksoft 0:425791fe4b42 77 #define REQUEST_TYPE_CLASS 0x20
jksoft 0:425791fe4b42 78 #define RECIPIENT_DEVICE 0x00
jksoft 0:425791fe4b42 79 #define RECIPIENT_INTERFACE 0x01
jksoft 0:425791fe4b42 80 #define RECIPIENT_ENDPOINT 0x02
jksoft 0:425791fe4b42 81 #define RECIPIENT_OTHER 0x03
jksoft 0:425791fe4b42 82
jksoft 0:425791fe4b42 83 #define GET_STATUS 0
jksoft 0:425791fe4b42 84 #define CLEAR_FEATURE 1
jksoft 0:425791fe4b42 85 #define SET_FEATURE 3
jksoft 0:425791fe4b42 86 #define SET_ADDRESS 5
jksoft 0:425791fe4b42 87 #define GET_DESCRIPTOR 6
jksoft 0:425791fe4b42 88 #define SET_DESCRIPTOR 7
jksoft 0:425791fe4b42 89 #define GET_CONFIGURATION 8
jksoft 0:425791fe4b42 90 #define SET_CONFIGURATION 9
jksoft 0:425791fe4b42 91 #define GET_INTERFACE 10
jksoft 0:425791fe4b42 92 #define SET_INTERFACE 11
jksoft 0:425791fe4b42 93 #define SYNCH_FRAME 11
jksoft 0:425791fe4b42 94
jksoft 0:425791fe4b42 95 // -5 is nak
jksoft 0:425791fe4b42 96 /*
jksoft 0:425791fe4b42 97 0010 ACK Handshake
jksoft 0:425791fe4b42 98 1010 NAK Handshake
jksoft 0:425791fe4b42 99 1110 STALL Handshake
jksoft 0:425791fe4b42 100 0110 NYET (No Response Yet)
jksoft 0:425791fe4b42 101 */
jksoft 0:425791fe4b42 102
jksoft 0:425791fe4b42 103 #define IO_PENDING -100
jksoft 0:425791fe4b42 104 #define ERR_ENDPOINT_NONE_LEFT -101
jksoft 0:425791fe4b42 105 #define ERR_ENDPOINT_NOT_FOUND -102
jksoft 0:425791fe4b42 106 #define ERR_DEVICE_NOT_FOUND -103
jksoft 0:425791fe4b42 107 #define ERR_DEVICE_NONE_LEFT -104
jksoft 0:425791fe4b42 108 #define ERR_HUB_INIT_FAILED -105
jksoft 0:425791fe4b42 109 #define ERR_INTERFACE_NOT_FOUND -106
jksoft 0:425791fe4b42 110
jksoft 0:425791fe4b42 111 typedef struct
jksoft 0:425791fe4b42 112 {
jksoft 0:425791fe4b42 113 u8 bLength;
jksoft 0:425791fe4b42 114 u8 bDescriptorType;
jksoft 0:425791fe4b42 115 u16 bcdUSB;
jksoft 0:425791fe4b42 116 u8 bDeviceClass;
jksoft 0:425791fe4b42 117 u8 bDeviceSubClass;
jksoft 0:425791fe4b42 118 u8 bDeviceProtocol;
jksoft 0:425791fe4b42 119 u8 bMaxPacketSize;
jksoft 0:425791fe4b42 120 u16 idVendor;
jksoft 0:425791fe4b42 121 u16 idProduct;
jksoft 0:425791fe4b42 122 u16 bcdDevice; // version
jksoft 0:425791fe4b42 123 u8 iManufacturer;
jksoft 0:425791fe4b42 124 u8 iProduct;
jksoft 0:425791fe4b42 125 u8 iSerialNumber;
jksoft 0:425791fe4b42 126 u8 bNumConfigurations;
jksoft 0:425791fe4b42 127 } DeviceDescriptor; // 16 bytes
jksoft 0:425791fe4b42 128
jksoft 0:425791fe4b42 129 typedef struct
jksoft 0:425791fe4b42 130 {
jksoft 0:425791fe4b42 131 u8 bLength;
jksoft 0:425791fe4b42 132 u8 bDescriptorType;
jksoft 0:425791fe4b42 133 u16 wTotalLength;
jksoft 0:425791fe4b42 134 u8 bNumInterfaces;
jksoft 0:425791fe4b42 135 u8 bConfigurationValue; // Value to use as an argument to select this configuration
jksoft 0:425791fe4b42 136 u8 iConfiguration; // Index of String Descriptor describing this configuration
jksoft 0:425791fe4b42 137 u8 bmAttributes; // Bitmap D7 Reserved, set to 1. (USB 1.0 Bus Powered),D6 Self Powered,D5 Remote Wakeup,D4..0 = 0
jksoft 0:425791fe4b42 138 u8 bMaxPower; // Maximum Power Consumption in 2mA units
jksoft 0:425791fe4b42 139 } ConfigurationDescriptor;
jksoft 0:425791fe4b42 140
jksoft 0:425791fe4b42 141 typedef struct
jksoft 0:425791fe4b42 142 {
jksoft 0:425791fe4b42 143 u8 bLength;
jksoft 0:425791fe4b42 144 u8 bDescriptorType;
jksoft 0:425791fe4b42 145 u8 bInterfaceNumber;
jksoft 0:425791fe4b42 146 u8 bAlternateSetting;
jksoft 0:425791fe4b42 147 u8 bNumEndpoints;
jksoft 0:425791fe4b42 148 u8 bInterfaceClass;
jksoft 0:425791fe4b42 149 u8 bInterfaceSubClass;
jksoft 0:425791fe4b42 150 u8 bInterfaceProtocol;
jksoft 0:425791fe4b42 151 u8 iInterface; // Index of String Descriptor Describing this interface
jksoft 0:425791fe4b42 152 } InterfaceDescriptor;
jksoft 0:425791fe4b42 153
jksoft 0:425791fe4b42 154 typedef struct
jksoft 0:425791fe4b42 155 {
jksoft 0:425791fe4b42 156 u8 bLength;
jksoft 0:425791fe4b42 157 u8 bDescriptorType;
jksoft 0:425791fe4b42 158 u8 bEndpointAddress; // Bits 0:3 endpoint, Bits 7 Direction 0 = Out, 1 = In (Ignored for Control Endpoints)
jksoft 0:425791fe4b42 159 u8 bmAttributes; // Bits 0:1 00 = Control, 01 = Isochronous, 10 = Bulk, 11 = Interrupt
jksoft 0:425791fe4b42 160 u16 wMaxPacketSize;
jksoft 0:425791fe4b42 161 u8 bInterval; // Interval for polling endpoint data transfers.
jksoft 0:425791fe4b42 162 } EndpointDescriptor;
jksoft 0:425791fe4b42 163
jksoft 0:425791fe4b42 164 typedef struct {
jksoft 0:425791fe4b42 165 u8 bLength;
jksoft 0:425791fe4b42 166 u8 bDescriptorType;
jksoft 0:425791fe4b42 167 u16 bcdHID;
jksoft 0:425791fe4b42 168 u8 bCountryCode;
jksoft 0:425791fe4b42 169 u8 bNumDescriptors;
jksoft 0:425791fe4b42 170 u8 bDescriptorType2;
jksoft 0:425791fe4b42 171 u16 wDescriptorLength;
jksoft 0:425791fe4b42 172 } HIDDescriptor;
jksoft 0:425791fe4b42 173
jksoft 0:425791fe4b42 174 //============================================================================
jksoft 0:425791fe4b42 175 //============================================================================
jksoft 0:425791fe4b42 176
jksoft 0:425791fe4b42 177
jksoft 0:425791fe4b42 178 void USBInit();
jksoft 0:425791fe4b42 179 void USBLoop();
jksoft 0:425791fe4b42 180 u8* USBGetBuffer(u32* len);
jksoft 0:425791fe4b42 181
jksoft 0:425791fe4b42 182 // Optional callback for transfers, called at interrupt time
jksoft 0:425791fe4b42 183 typedef void (*USBCallback)(int device, int endpoint, int status, u8* data, int len, void* userData);
jksoft 0:425791fe4b42 184
jksoft 0:425791fe4b42 185 // Transfers
jksoft 0:425791fe4b42 186 int USBControlTransfer(int device, int request_type, int request, int value, int index, u8* data, int length, USBCallback callback = 0, void* userData = 0);
jksoft 0:425791fe4b42 187 int USBInterruptTransfer(int device, int ep, u8* data, int length, USBCallback callback = 0, void* userData = 0);
jksoft 0:425791fe4b42 188 int USBBulkTransfer(int device, int ep, u8* data, int length, USBCallback callback = 0, void* userData = 0);
jksoft 0:425791fe4b42 189
jksoft 0:425791fe4b42 190 // Standard Device methods
jksoft 0:425791fe4b42 191 int GetDescriptor(int device, int descType, int descIndex, u8* data, int length);
jksoft 0:425791fe4b42 192 int GetString(int device, int index, char* dst, int length);
jksoft 0:425791fe4b42 193 int SetAddress(int device, int new_addr);
jksoft 0:425791fe4b42 194 int SetConfiguration(int device, int configNum);
jksoft 0:425791fe4b42 195 int SetInterface(int device, int ifNum, int altNum);
jksoft 0:425791fe4b42 196
jksoft 0:425791fe4b42 197 // Implemented to notify app of the arrival of a device
jksoft 0:425791fe4b42 198 void OnLoadDevice(int device, DeviceDescriptor* deviceDesc, InterfaceDescriptor* interfaceDesc);
jksoft 0:425791fe4b42 199
jksoft 0:425791fe4b42 200 #endif