- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

# include/usb/usb_protocol.h

Go to the documentation of this file.

    00001
    00044 #ifndef USB_PROTOCOL_H_INCLUDED
    00045 #define USB_PROTOCOL_H_INCLUDED
    00046
    00047 #include <types.h>
    00048
    00053 enum usb_device_state {
    00054         USB_STATE_ATTACHED = 0,
    00055         USB_STATE_POWERED,
    00056         USB_STATE_DEFAULT,
    00057         USB_STATE_ADDRESS,
    00058         USB_STATE_CONFIGURED,
    00059         USB_STATE_SUSPENDED = 0x80,
    00060         USB_STATE_POWERED_SUSPENDED = USB_STATE_POWERED | USB_STATE_SUSPENDED,
    00061         USB_STATE_DEFAULT_SUSPENDED = USB_STATE_DEFAULT | USB_STATE_SUSPENDED,
    00062         USB_STATE_ADDRESS_SUSPENDED = USB_STATE_ADDRESS | USB_STATE_SUSPENDED,
    00063         USB_STATE_CONFIGURED_SUSPENDED = (USB_STATE_CONFIGURED
    00064                                           | USB_STATE_SUSPENDED),
    00065 };
    00066
    00072 enum usb_device_speed {
    00073         USB_SPEED_UNKNOWN = 0,
    00074         USB_SPEED_LOW,
    00075         USB_SPEED_FULL,
    00076         USB_SPEED_HIGH,
    00077 };
    00078
    00082 enum usb_reqtype {
    00083         USB_REQTYPE_STANDARD    = 0,
    00084         USB_REQTYPE_CLASS       = 1,
    00085         USB_REQTYPE_VENDOR      = 2,
    00086 };
    00087
    00091 enum usb_recipient {
    00092         USB_RECIP_DEVICE        = 0,
    00093         USB_RECIP_INTERFACE     = 1,
    00094         USB_RECIP_ENDPOINT      = 2,
    00095         USB_RECIP_OTHER         = 3,
    00096 };
    00097
    00101 enum usb_reqid {
    00102         USB_REQ_GET_STATUS              =  0,
    00103         USB_REQ_CLEAR_FEATURE           =  1,
    00104         USB_REQ_SET_FEATURE             =  3,
    00105         USB_REQ_SET_ADDRESS             =  5,
    00106         USB_REQ_GET_DESCRIPTOR          =  6,
    00107         USB_REQ_SET_DESCRIPTOR          =  7,
    00108         USB_REQ_GET_CONFIGURATION       =  8,
    00109         USB_REQ_SET_CONFIGURATION       =  9,
    00110         USB_REQ_GET_INTERFACE           = 10,
    00111         USB_REQ_SET_INTERFACE           = 11,
    00112         USB_REQ_SYNCH_FRAME             = 12,
    00113 };
    00114
    00118 enum usb_device_feature {
    00119         USB_DEV_FEATURE_REMOTE_WAKEUP   = 1,
    00120         USB_DEV_FEATURE_TEST_MODE       = 2,
    00121 };
    00122
    00126 enum usb_endpoint_feature {
    00127         USB_EP_FEATURE_HALT             = 0,
    00128 };
    00129
    00133 enum usb_test_mode_selector {
    00134         USB_TEST_J                      = 0x01,
    00135         USB_TEST_K                      = 0x02,
    00136         USB_TEST_SE0_NAK                = 0x03,
    00137         USB_TEST_PACKET                 = 0x04,
    00138         USB_TEST_FORCE_ENABLE           = 0x05,
    00139 };
    00140
    00144 enum usb_descriptor_type {
    00145         USB_DT_DEVICE                   = 1,
    00146         USB_DT_CONFIGURATION            = 2,
    00147         USB_DT_STRING                   = 3,
    00148         USB_DT_INTERFACE                = 4,
    00149         USB_DT_ENDPOINT                 = 5,
    00150         USB_DT_DEVICE_QUALIFIER         = 6,
    00151         USB_DT_OTHER_SPEED_CONFIGURATION = 7,
    00152         USB_DT_INTERFACE_POWER          = 8,
    00153 };
    00154
    00155 enum usb_ep_xfer_type {
    00156         USB_EP_XFER_CONTROL             = 0x00,
    00157         USB_EP_XFER_ISOCHRONOUS         = 0x01,
    00158         USB_EP_XFER_BULK                = 0x02,
    00159         USB_EP_XFER_INTERRUPT           = 0x03,
    00160 };
    00161
    00162 #define USB_EP_ADDR_MASK                0x0f
    00163 #define USB_DIR_IN                      0x80
    00164 #define USB_DIR_OUT                     0x00
    00165
    00170 struct usb_setup_req {
    00171         uint8_t bmRequestType;
    00172         uint8_t bRequest;
    00173         le16_t wValue;
    00174         le16_t wIndex;
    00175         le16_t wLength;
    00176 } __packed;
    00177
    00178 #define usb_req_is_in(req)      (!!((req)->bmRequestType & USB_DIR_IN))
    00179 #define usb_req_is_out(req)     (!((req)->bmRequestType & USB_DIR_IN))
    00180 #define usb_req_type(req)       (((req)->bmRequestType >> 5) & 3)
    00181 #define usb_req_recipient(req)  ((req)->bmRequestType & 0x1f)
    00182
    00183 #define USB_MAX_DESC_SIZE       255
    00184
    00188 struct usb_device_descriptor {
    00189         uint8_t bLength;
    00190         uint8_t bDescriptorType;
    00191         le16_t bcdUSB;
    00192         uint8_t bDeviceClass;
    00193         uint8_t bDeviceSubClass;
    00194         uint8_t bDeviceProtocol;
    00195         uint8_t bMaxPacketSize0;
    00196         le16_t idVendor;
    00197         le16_t idProduct;
    00198         le16_t bcdDevice;
    00199         uint8_t iManufacturer;
    00200         uint8_t iProduct;
    00201         uint8_t iSerialNumber;
    00202         uint8_t bNumConfigurations;
    00203 } __packed;
    00204
    00212 struct usb_device_qualifier_descriptor {
    00213         uint8_t bLength;
    00214         uint8_t bDescriptorType;
    00215         le16_t bcdUSB;
    00216         uint8_t bDeviceClass;
    00217         uint8_t bDeviceSubClass;
    00218         uint8_t bDeviceProtocol;
    00219         uint8_t bMaxPacketSize0;
    00220         uint8_t bNumConfigurations;
    00221         uint8_t bReserved;
    00222 } __packed;
    00223
    00227 struct usb_configuration_descriptor {
    00228         uint8_t bLength;
    00229         uint8_t bDescriptorType;
    00230         le16_t wTotalLength;
    00231         uint8_t bNumInterfaces;
    00232         uint8_t bConfigurationValue;
    00233         uint8_t iConfiguration;
    00234         uint8_t bmAttributes;
    00235         uint8_t bMaxPower;
    00236 } __packed;
    00237
    00238 #define USB_CONFIG_ATTR_MUST_SET        (1U << 7)
    00239 #define USB_CONFIG_ATTR_SELF_POWERED    (1U << 6)
    00240 #define USB_CONFIG_ATTR_REMOTE_WAKEUP   (1U << 5)
    00241 #define USB_CONFIG_MAX_POWER(ma)        (((ma) + 1) / 2)
    00242
    00243
    00246 struct usb_interface_descriptor {
    00247         uint8_t bLength;
    00248         uint8_t bDescriptorType;
    00249         uint8_t bInterfaceNumber;
    00250         uint8_t bAlternateSetting;
    00251         uint8_t bNumEndpoints;
    00252         uint8_t bInterfaceClass;
    00253         uint8_t bInterfaceSubClass;
    00254         uint8_t bInterfaceProtocol;
    00255         uint8_t iInterface;
    00256 } __packed;
    00257
    00261 struct usb_endpoint_descriptor {
    00262         uint8_t bLength;
    00263         uint8_t bDescriptorType;
    00264         uint8_t bEndpointAddress;
    00265         uint8_t bmAttributes;
    00266         le16_t wMaxPacketSize;
    00267         uint8_t bInterval;
    00268 } __packed;
    00269
    00270 #define usb_ep_index(desc)      ((desc)->bEndpointAddress & USB_EP_ADDR_MASK)
    00271 #define usb_ep_is_in(desc)      (!!((desc)->bEndpointAddress & USB_DIR_IN))
    00272 #define usb_ep_is_out(desc)     (!((desc)->bEndpointAddress & USB_DIR_IN))
    00273 #define usb_ep_xfer(desc)       ((desc)->bmAttributes & 0x03)
    00274
    00275 struct usb_string_descriptor {
    00276         uint8_t bLength;
    00277         uint8_t bDescriptorType;
    00278         le16_t  bString[0];
    00279 };
    00280
    00281 #endif /* USB_PROTOCOL_H_INCLUDED */