Simon Ford / Mbed 2 deprecated WiiRacing

Dependencies:   mbed m3pi ID12RFIDIRQ

Committer:
simon
Date:
Mon Apr 11 23:03:22 2011 +0000
Revision:
0:e2ef12467862

        

Who changed what in which revision?

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