BlackOneとAndroidの連携デモプログラム AndroidAccessoryを改造してBlackOneとAndroidが連携できるようにしました。 サポートしているのは、デモアプリの ”Buttons” B1-SW1, B2-SW2, B3-SW3 ”LED2” RGB-LED のみです。 LCDに表示するイメージをマイクロSDカードに入れてLCDのソケットに挿入しておく必要があります。 イメージは、320X240ドットで”\Image”という名前のフォルダの直下に”10.jpg”という名前で入れてください。

Dependencies:   TextLCD mbed

Committer:
techand
Date:
Fri Dec 23 04:33:33 2011 +0000
Revision:
0:7b556109fd46

        

Who changed what in which revision?

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