Jason Engelman
/
USBCDC
Port of Keils USBCDC example, compiles ok. Gets stuck at init
usb.h@0:0b777ff85deb, 2010-07-05 (annotated)
- Committer:
- tecnosys
- Date:
- Mon Jul 05 10:16:57 2010 +0000
- Revision:
- 0:0b777ff85deb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tecnosys | 0:0b777ff85deb | 1 | /*---------------------------------------------------------------------------- |
tecnosys | 0:0b777ff85deb | 2 | * U S B - K e r n e l |
tecnosys | 0:0b777ff85deb | 3 | *---------------------------------------------------------------------------- |
tecnosys | 0:0b777ff85deb | 4 | * Name: usb.h |
tecnosys | 0:0b777ff85deb | 5 | * Purpose: USB Definitions |
tecnosys | 0:0b777ff85deb | 6 | * Version: V1.20 |
tecnosys | 0:0b777ff85deb | 7 | *---------------------------------------------------------------------------- |
tecnosys | 0:0b777ff85deb | 8 | * This software is supplied "AS IS" without any warranties, express, |
tecnosys | 0:0b777ff85deb | 9 | * implied or statutory, including but not limited to the implied |
tecnosys | 0:0b777ff85deb | 10 | * warranties of fitness for purpose, satisfactory quality and |
tecnosys | 0:0b777ff85deb | 11 | * noninfringement. Keil extends you a royalty-free right to reproduce |
tecnosys | 0:0b777ff85deb | 12 | * and distribute executable files created using this software for use |
tecnosys | 0:0b777ff85deb | 13 | * on NXP Semiconductors LPC family microcontroller devices only. Nothing |
tecnosys | 0:0b777ff85deb | 14 | * else gives you the right to use this software. |
tecnosys | 0:0b777ff85deb | 15 | * |
tecnosys | 0:0b777ff85deb | 16 | * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. |
tecnosys | 0:0b777ff85deb | 17 | *---------------------------------------------------------------------------*/ |
tecnosys | 0:0b777ff85deb | 18 | |
tecnosys | 0:0b777ff85deb | 19 | #ifndef __USB_H__ |
tecnosys | 0:0b777ff85deb | 20 | #define __USB_H__ |
tecnosys | 0:0b777ff85deb | 21 | |
tecnosys | 0:0b777ff85deb | 22 | |
tecnosys | 0:0b777ff85deb | 23 | typedef __packed union { |
tecnosys | 0:0b777ff85deb | 24 | uint16_t W; |
tecnosys | 0:0b777ff85deb | 25 | __packed struct { |
tecnosys | 0:0b777ff85deb | 26 | uint8_t L; |
tecnosys | 0:0b777ff85deb | 27 | uint8_t H; |
tecnosys | 0:0b777ff85deb | 28 | } WB; |
tecnosys | 0:0b777ff85deb | 29 | } WORD_BYTE; |
tecnosys | 0:0b777ff85deb | 30 | |
tecnosys | 0:0b777ff85deb | 31 | |
tecnosys | 0:0b777ff85deb | 32 | /* bmRequestType.Dir */ |
tecnosys | 0:0b777ff85deb | 33 | #define REQUEST_HOST_TO_DEVICE 0 |
tecnosys | 0:0b777ff85deb | 34 | #define REQUEST_DEVICE_TO_HOST 1 |
tecnosys | 0:0b777ff85deb | 35 | |
tecnosys | 0:0b777ff85deb | 36 | /* bmRequestType.Type */ |
tecnosys | 0:0b777ff85deb | 37 | #define REQUEST_STANDARD 0 |
tecnosys | 0:0b777ff85deb | 38 | #define REQUEST_CLASS 1 |
tecnosys | 0:0b777ff85deb | 39 | #define REQUEST_VENDOR 2 |
tecnosys | 0:0b777ff85deb | 40 | #define REQUEST_RESERVED 3 |
tecnosys | 0:0b777ff85deb | 41 | |
tecnosys | 0:0b777ff85deb | 42 | /* bmRequestType.Recipient */ |
tecnosys | 0:0b777ff85deb | 43 | #define REQUEST_TO_DEVICE 0 |
tecnosys | 0:0b777ff85deb | 44 | #define REQUEST_TO_INTERFACE 1 |
tecnosys | 0:0b777ff85deb | 45 | #define REQUEST_TO_ENDPOINT 2 |
tecnosys | 0:0b777ff85deb | 46 | #define REQUEST_TO_OTHER 3 |
tecnosys | 0:0b777ff85deb | 47 | |
tecnosys | 0:0b777ff85deb | 48 | /* bmRequestType Definition */ |
tecnosys | 0:0b777ff85deb | 49 | typedef __packed union _REQUEST_TYPE { |
tecnosys | 0:0b777ff85deb | 50 | __packed struct _BM { |
tecnosys | 0:0b777ff85deb | 51 | uint8_t Recipient : 5; |
tecnosys | 0:0b777ff85deb | 52 | uint8_t Type : 2; |
tecnosys | 0:0b777ff85deb | 53 | uint8_t Dir : 1; |
tecnosys | 0:0b777ff85deb | 54 | } BM; |
tecnosys | 0:0b777ff85deb | 55 | uint8_t B; |
tecnosys | 0:0b777ff85deb | 56 | } REQUEST_TYPE; |
tecnosys | 0:0b777ff85deb | 57 | |
tecnosys | 0:0b777ff85deb | 58 | /* USB Standard Request Codes */ |
tecnosys | 0:0b777ff85deb | 59 | #define USB_REQUEST_GET_STATUS 0 |
tecnosys | 0:0b777ff85deb | 60 | #define USB_REQUEST_CLEAR_FEATURE 1 |
tecnosys | 0:0b777ff85deb | 61 | #define USB_REQUEST_SET_FEATURE 3 |
tecnosys | 0:0b777ff85deb | 62 | #define USB_REQUEST_SET_ADDRESS 5 |
tecnosys | 0:0b777ff85deb | 63 | #define USB_REQUEST_GET_DESCRIPTOR 6 |
tecnosys | 0:0b777ff85deb | 64 | #define USB_REQUEST_SET_DESCRIPTOR 7 |
tecnosys | 0:0b777ff85deb | 65 | #define USB_REQUEST_GET_CONFIGURATION 8 |
tecnosys | 0:0b777ff85deb | 66 | #define USB_REQUEST_SET_CONFIGURATION 9 |
tecnosys | 0:0b777ff85deb | 67 | #define USB_REQUEST_GET_INTERFACE 10 |
tecnosys | 0:0b777ff85deb | 68 | #define USB_REQUEST_SET_INTERFACE 11 |
tecnosys | 0:0b777ff85deb | 69 | #define USB_REQUEST_SYNC_FRAME 12 |
tecnosys | 0:0b777ff85deb | 70 | |
tecnosys | 0:0b777ff85deb | 71 | /* USB GET_STATUS Bit Values */ |
tecnosys | 0:0b777ff85deb | 72 | #define USB_GETSTATUS_SELF_POWERED 0x01 |
tecnosys | 0:0b777ff85deb | 73 | #define USB_GETSTATUS_REMOTE_WAKEUP 0x02 |
tecnosys | 0:0b777ff85deb | 74 | #define USB_GETSTATUS_ENDPOINT_STALL 0x01 |
tecnosys | 0:0b777ff85deb | 75 | |
tecnosys | 0:0b777ff85deb | 76 | /* USB Standard Feature selectors */ |
tecnosys | 0:0b777ff85deb | 77 | #define USB_FEATURE_ENDPOINT_STALL 0 |
tecnosys | 0:0b777ff85deb | 78 | #define USB_FEATURE_REMOTE_WAKEUP 1 |
tecnosys | 0:0b777ff85deb | 79 | |
tecnosys | 0:0b777ff85deb | 80 | /* USB Default Control Pipe Setup Packet */ |
tecnosys | 0:0b777ff85deb | 81 | typedef __packed struct _USB_SETUP_PACKET { |
tecnosys | 0:0b777ff85deb | 82 | REQUEST_TYPE bmRequestType; |
tecnosys | 0:0b777ff85deb | 83 | uint8_t bRequest; |
tecnosys | 0:0b777ff85deb | 84 | WORD_BYTE wValue; |
tecnosys | 0:0b777ff85deb | 85 | WORD_BYTE wIndex; |
tecnosys | 0:0b777ff85deb | 86 | uint16_t wLength; |
tecnosys | 0:0b777ff85deb | 87 | } USB_SETUP_PACKET; |
tecnosys | 0:0b777ff85deb | 88 | |
tecnosys | 0:0b777ff85deb | 89 | |
tecnosys | 0:0b777ff85deb | 90 | /* USB Descriptor Types */ |
tecnosys | 0:0b777ff85deb | 91 | #define USB_DEVICE_DESCRIPTOR_TYPE 1 |
tecnosys | 0:0b777ff85deb | 92 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE 2 |
tecnosys | 0:0b777ff85deb | 93 | #define USB_STRING_DESCRIPTOR_TYPE 3 |
tecnosys | 0:0b777ff85deb | 94 | #define USB_INTERFACE_DESCRIPTOR_TYPE 4 |
tecnosys | 0:0b777ff85deb | 95 | #define USB_ENDPOINT_DESCRIPTOR_TYPE 5 |
tecnosys | 0:0b777ff85deb | 96 | #define USB_DEVICE_QUALIFIER_DESCRIPTOR_TYPE 6 |
tecnosys | 0:0b777ff85deb | 97 | #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR_TYPE 7 |
tecnosys | 0:0b777ff85deb | 98 | #define USB_INTERFACE_POWER_DESCRIPTOR_TYPE 8 |
tecnosys | 0:0b777ff85deb | 99 | #define USB_OTG_DESCRIPTOR_TYPE 9 |
tecnosys | 0:0b777ff85deb | 100 | #define USB_DEBUG_DESCRIPTOR_TYPE 10 |
tecnosys | 0:0b777ff85deb | 101 | #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE 11 |
tecnosys | 0:0b777ff85deb | 102 | |
tecnosys | 0:0b777ff85deb | 103 | /* USB Device Classes */ |
tecnosys | 0:0b777ff85deb | 104 | #define USB_DEVICE_CLASS_RESERVED 0x00 |
tecnosys | 0:0b777ff85deb | 105 | #define USB_DEVICE_CLASS_AUDIO 0x01 |
tecnosys | 0:0b777ff85deb | 106 | #define USB_DEVICE_CLASS_COMMUNICATIONS 0x02 |
tecnosys | 0:0b777ff85deb | 107 | #define USB_DEVICE_CLASS_HUMAN_INTERFACE 0x03 |
tecnosys | 0:0b777ff85deb | 108 | #define USB_DEVICE_CLASS_MONITOR 0x04 |
tecnosys | 0:0b777ff85deb | 109 | #define USB_DEVICE_CLASS_PHYSICAL_INTERFACE 0x05 |
tecnosys | 0:0b777ff85deb | 110 | #define USB_DEVICE_CLASS_POWER 0x06 |
tecnosys | 0:0b777ff85deb | 111 | #define USB_DEVICE_CLASS_PRINTER 0x07 |
tecnosys | 0:0b777ff85deb | 112 | #define USB_DEVICE_CLASS_STORAGE 0x08 |
tecnosys | 0:0b777ff85deb | 113 | #define USB_DEVICE_CLASS_HUB 0x09 |
tecnosys | 0:0b777ff85deb | 114 | #define USB_DEVICE_CLASS_MISCELLANEOUS 0xEF |
tecnosys | 0:0b777ff85deb | 115 | #define USB_DEVICE_CLASS_VENDOR_SPECIFIC 0xFF |
tecnosys | 0:0b777ff85deb | 116 | |
tecnosys | 0:0b777ff85deb | 117 | /* bmAttributes in Configuration Descriptor */ |
tecnosys | 0:0b777ff85deb | 118 | #define USB_CONFIG_POWERED_MASK 0x40 |
tecnosys | 0:0b777ff85deb | 119 | #define USB_CONFIG_BUS_POWERED 0x80 |
tecnosys | 0:0b777ff85deb | 120 | #define USB_CONFIG_SELF_POWERED 0xC0 |
tecnosys | 0:0b777ff85deb | 121 | #define USB_CONFIG_REMOTE_WAKEUP 0x20 |
tecnosys | 0:0b777ff85deb | 122 | |
tecnosys | 0:0b777ff85deb | 123 | /* bMaxPower in Configuration Descriptor */ |
tecnosys | 0:0b777ff85deb | 124 | #define USB_CONFIG_POWER_MA(mA) ((mA)/2) |
tecnosys | 0:0b777ff85deb | 125 | |
tecnosys | 0:0b777ff85deb | 126 | /* bEndpointAddress in Endpoint Descriptor */ |
tecnosys | 0:0b777ff85deb | 127 | #define USB_ENDPOINT_DIRECTION_MASK 0x80 |
tecnosys | 0:0b777ff85deb | 128 | #define USB_ENDPOINT_OUT(addr) ((addr) | 0x00) |
tecnosys | 0:0b777ff85deb | 129 | #define USB_ENDPOINT_IN(addr) ((addr) | 0x80) |
tecnosys | 0:0b777ff85deb | 130 | |
tecnosys | 0:0b777ff85deb | 131 | /* bmAttributes in Endpoint Descriptor */ |
tecnosys | 0:0b777ff85deb | 132 | #define USB_ENDPOINT_TYPE_MASK 0x03 |
tecnosys | 0:0b777ff85deb | 133 | #define USB_ENDPOINT_TYPE_CONTROL 0x00 |
tecnosys | 0:0b777ff85deb | 134 | #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01 |
tecnosys | 0:0b777ff85deb | 135 | #define USB_ENDPOINT_TYPE_BULK 0x02 |
tecnosys | 0:0b777ff85deb | 136 | #define USB_ENDPOINT_TYPE_INTERRUPT 0x03 |
tecnosys | 0:0b777ff85deb | 137 | #define USB_ENDPOINT_SYNC_MASK 0x0C |
tecnosys | 0:0b777ff85deb | 138 | #define USB_ENDPOINT_SYNC_NO_SYNCHRONIZATION 0x00 |
tecnosys | 0:0b777ff85deb | 139 | #define USB_ENDPOINT_SYNC_ASYNCHRONOUS 0x04 |
tecnosys | 0:0b777ff85deb | 140 | #define USB_ENDPOINT_SYNC_ADAPTIVE 0x08 |
tecnosys | 0:0b777ff85deb | 141 | #define USB_ENDPOINT_SYNC_SYNCHRONOUS 0x0C |
tecnosys | 0:0b777ff85deb | 142 | #define USB_ENDPOINT_USAGE_MASK 0x30 |
tecnosys | 0:0b777ff85deb | 143 | #define USB_ENDPOINT_USAGE_DATA 0x00 |
tecnosys | 0:0b777ff85deb | 144 | #define USB_ENDPOINT_USAGE_FEEDBACK 0x10 |
tecnosys | 0:0b777ff85deb | 145 | #define USB_ENDPOINT_USAGE_IMPLICIT_FEEDBACK 0x20 |
tecnosys | 0:0b777ff85deb | 146 | #define USB_ENDPOINT_USAGE_RESERVED 0x30 |
tecnosys | 0:0b777ff85deb | 147 | |
tecnosys | 0:0b777ff85deb | 148 | /* USB Standard Device Descriptor */ |
tecnosys | 0:0b777ff85deb | 149 | typedef __packed struct _USB_DEVICE_DESCRIPTOR { |
tecnosys | 0:0b777ff85deb | 150 | uint8_t bLength; |
tecnosys | 0:0b777ff85deb | 151 | uint8_t bDescriptorType; |
tecnosys | 0:0b777ff85deb | 152 | uint16_t bcdUSB; |
tecnosys | 0:0b777ff85deb | 153 | uint8_t bDeviceClass; |
tecnosys | 0:0b777ff85deb | 154 | uint8_t bDeviceSubClass; |
tecnosys | 0:0b777ff85deb | 155 | uint8_t bDeviceProtocol; |
tecnosys | 0:0b777ff85deb | 156 | uint8_t bMaxPacketSize0; |
tecnosys | 0:0b777ff85deb | 157 | uint16_t idVendor; |
tecnosys | 0:0b777ff85deb | 158 | uint16_t idProduct; |
tecnosys | 0:0b777ff85deb | 159 | uint16_t bcdDevice; |
tecnosys | 0:0b777ff85deb | 160 | uint8_t iManufacturer; |
tecnosys | 0:0b777ff85deb | 161 | uint8_t iProduct; |
tecnosys | 0:0b777ff85deb | 162 | uint8_t iSerialNumber; |
tecnosys | 0:0b777ff85deb | 163 | uint8_t bNumConfigurations; |
tecnosys | 0:0b777ff85deb | 164 | } USB_DEVICE_DESCRIPTOR; |
tecnosys | 0:0b777ff85deb | 165 | |
tecnosys | 0:0b777ff85deb | 166 | /* USB 2.0 Device Qualifier Descriptor */ |
tecnosys | 0:0b777ff85deb | 167 | typedef __packed struct _USB_DEVICE_QUALIFIER_DESCRIPTOR { |
tecnosys | 0:0b777ff85deb | 168 | uint8_t bLength; |
tecnosys | 0:0b777ff85deb | 169 | uint8_t bDescriptorType; |
tecnosys | 0:0b777ff85deb | 170 | uint16_t bcdUSB; |
tecnosys | 0:0b777ff85deb | 171 | uint8_t bDeviceClass; |
tecnosys | 0:0b777ff85deb | 172 | uint8_t bDeviceSubClass; |
tecnosys | 0:0b777ff85deb | 173 | uint8_t bDeviceProtocol; |
tecnosys | 0:0b777ff85deb | 174 | uint8_t bMaxPacketSize0; |
tecnosys | 0:0b777ff85deb | 175 | uint8_t bNumConfigurations; |
tecnosys | 0:0b777ff85deb | 176 | uint8_t bReserved; |
tecnosys | 0:0b777ff85deb | 177 | } USB_DEVICE_QUALIFIER_DESCRIPTOR; |
tecnosys | 0:0b777ff85deb | 178 | |
tecnosys | 0:0b777ff85deb | 179 | /* USB Standard Configuration Descriptor */ |
tecnosys | 0:0b777ff85deb | 180 | typedef __packed struct _USB_CONFIGURATION_DESCRIPTOR { |
tecnosys | 0:0b777ff85deb | 181 | uint8_t bLength; |
tecnosys | 0:0b777ff85deb | 182 | uint8_t bDescriptorType; |
tecnosys | 0:0b777ff85deb | 183 | uint16_t wTotalLength; |
tecnosys | 0:0b777ff85deb | 184 | uint8_t bNumInterfaces; |
tecnosys | 0:0b777ff85deb | 185 | uint8_t bConfigurationValue; |
tecnosys | 0:0b777ff85deb | 186 | uint8_t iConfiguration; |
tecnosys | 0:0b777ff85deb | 187 | uint8_t bmAttributes; |
tecnosys | 0:0b777ff85deb | 188 | uint8_t bMaxPower; |
tecnosys | 0:0b777ff85deb | 189 | } USB_CONFIGURATION_DESCRIPTOR; |
tecnosys | 0:0b777ff85deb | 190 | |
tecnosys | 0:0b777ff85deb | 191 | /* USB Standard Interface Descriptor */ |
tecnosys | 0:0b777ff85deb | 192 | typedef __packed struct _USB_INTERFACE_DESCRIPTOR { |
tecnosys | 0:0b777ff85deb | 193 | uint8_t bLength; |
tecnosys | 0:0b777ff85deb | 194 | uint8_t bDescriptorType; |
tecnosys | 0:0b777ff85deb | 195 | uint8_t bInterfaceNumber; |
tecnosys | 0:0b777ff85deb | 196 | uint8_t bAlternateSetting; |
tecnosys | 0:0b777ff85deb | 197 | uint8_t bNumEndpoints; |
tecnosys | 0:0b777ff85deb | 198 | uint8_t bInterfaceClass; |
tecnosys | 0:0b777ff85deb | 199 | uint8_t bInterfaceSubClass; |
tecnosys | 0:0b777ff85deb | 200 | uint8_t bInterfaceProtocol; |
tecnosys | 0:0b777ff85deb | 201 | uint8_t iInterface; |
tecnosys | 0:0b777ff85deb | 202 | } USB_INTERFACE_DESCRIPTOR; |
tecnosys | 0:0b777ff85deb | 203 | |
tecnosys | 0:0b777ff85deb | 204 | /* USB Standard Endpoint Descriptor */ |
tecnosys | 0:0b777ff85deb | 205 | typedef __packed struct _USB_ENDPOINT_DESCRIPTOR { |
tecnosys | 0:0b777ff85deb | 206 | uint8_t bLength; |
tecnosys | 0:0b777ff85deb | 207 | uint8_t bDescriptorType; |
tecnosys | 0:0b777ff85deb | 208 | uint8_t bEndpointAddress; |
tecnosys | 0:0b777ff85deb | 209 | uint8_t bmAttributes; |
tecnosys | 0:0b777ff85deb | 210 | uint16_t wMaxPacketSize; |
tecnosys | 0:0b777ff85deb | 211 | uint8_t bInterval; |
tecnosys | 0:0b777ff85deb | 212 | } USB_ENDPOINT_DESCRIPTOR; |
tecnosys | 0:0b777ff85deb | 213 | |
tecnosys | 0:0b777ff85deb | 214 | /* USB String Descriptor */ |
tecnosys | 0:0b777ff85deb | 215 | typedef __packed struct _USB_STRING_DESCRIPTOR { |
tecnosys | 0:0b777ff85deb | 216 | uint8_t bLength; |
tecnosys | 0:0b777ff85deb | 217 | uint8_t bDescriptorType; |
tecnosys | 0:0b777ff85deb | 218 | uint16_t bString/*[]*/; |
tecnosys | 0:0b777ff85deb | 219 | } USB_STRING_DESCRIPTOR; |
tecnosys | 0:0b777ff85deb | 220 | |
tecnosys | 0:0b777ff85deb | 221 | /* USB Common Descriptor */ |
tecnosys | 0:0b777ff85deb | 222 | typedef __packed struct _USB_COMMON_DESCRIPTOR { |
tecnosys | 0:0b777ff85deb | 223 | uint8_t bLength; |
tecnosys | 0:0b777ff85deb | 224 | uint8_t bDescriptorType; |
tecnosys | 0:0b777ff85deb | 225 | } USB_COMMON_DESCRIPTOR; |
tecnosys | 0:0b777ff85deb | 226 | |
tecnosys | 0:0b777ff85deb | 227 | |
tecnosys | 0:0b777ff85deb | 228 | #endif /* __USB_H__ */ |