うおーるぼっと用プログラム Wiiリモコンからのダイレクト操作モードのみ BlueUSBをベースに使用しています。

Dependencies:   BD6211F mbed SimpleFilter

Committer:
jksoft
Date:
Fri Apr 29 15:50:23 2011 +0000
Revision:
0:4f749f62c6d7

        

Who changed what in which revision?

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