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