USBHost library

Dependencies:   FATFileSystem mbed-rtos

Fork of USBHost by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHostTypes.h Source File

USBHostTypes.h

00001 /* mbed USBHost Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef USB_INC_H
00018 #define USB_INC_H
00019 
00020 #include "mbed.h"
00021 #include "toolchain.h"
00022 
00023 enum USB_TYPE {
00024     USB_TYPE_OK = 0,
00025 
00026     // completion code
00027     USB_TYPE_CRC_ERROR = 1,
00028     USB_TYPE_BIT_STUFFING_ERROR = 2,
00029     USB_TYPE_DATA_TOGGLE_MISMATCH_ERROR = 3,
00030     USB_TYPE_STALL_ERROR = 4,
00031     USB_TYPE_DEVICE_NOT_RESPONDING_ERROR = 5,
00032     USB_TYPE_PID_CHECK_FAILURE_ERROR = 6,
00033     USB_TYPE_UNEXPECTED_PID_ERROR = 7,
00034     USB_TYPE_DATA_OVERRUN_ERROR = 8,
00035     USB_TYPE_DATA_UNDERRUN_ERROR = 9,
00036     USB_TYPE_RESERVED = 9,
00037     USB_TYPE_RESERVED_ = 10,
00038     USB_TYPE_BUFFER_OVERRUN_ERROR = 12,
00039     USB_TYPE_BUFFER_UNDERRUN_ERROR = 13,
00040 
00041     // general usb state
00042     USB_TYPE_DISCONNECTED = 14,
00043     USB_TYPE_FREE = 15,
00044     USB_TYPE_IDLE = 16,
00045     USB_TYPE_PROCESSING = 17,
00046 
00047     USB_TYPE_ERROR = 18,
00048 };
00049 
00050 
00051 enum ENDPOINT_DIRECTION {
00052     OUT = 1,
00053     IN
00054 };
00055 
00056 enum ENDPOINT_TYPE {
00057     CONTROL_ENDPOINT = 0,
00058     ISOCHRONOUS_ENDPOINT,
00059     BULK_ENDPOINT,
00060     INTERRUPT_ENDPOINT
00061 };
00062 
00063 #define AUDIO_CLASS     0x01
00064 #define CDC_CLASS       0x02
00065 #define HID_CLASS       0x03
00066 #define MSD_CLASS       0x08
00067 #define HUB_CLASS       0x09
00068 #define SERIAL_CLASS    0x0A
00069 
00070 // ------------------ HcControl Register ---------------------  
00071 #define  OR_CONTROL_PLE                 0x00000004
00072 #define  OR_CONTROL_CLE                 0x00000010
00073 #define  OR_CONTROL_BLE                 0x00000020
00074 #define  OR_CONTROL_HCFS                0x000000C0
00075 #define  OR_CONTROL_HC_OPER             0x00000080
00076 // ----------------- HcCommandStatus Register ----------------- 
00077 #define  OR_CMD_STATUS_HCR              0x00000001
00078 #define  OR_CMD_STATUS_CLF              0x00000002
00079 #define  OR_CMD_STATUS_BLF              0x00000004
00080 // --------------- HcInterruptStatus Register ----------------- 
00081 #define  OR_INTR_STATUS_WDH             0x00000002
00082 #define  OR_INTR_STATUS_RHSC            0x00000040
00083 #define  OR_INTR_STATUS_UE              0x00000010
00084 // --------------- HcInterruptEnable Register ----------------- 
00085 #define  OR_INTR_ENABLE_WDH             0x00000002
00086 #define  OR_INTR_ENABLE_RHSC            0x00000040
00087 #define  OR_INTR_ENABLE_MIE             0x80000000
00088 // ---------------- HcRhDescriptorA Register ------------------ 
00089 #define  OR_RH_STATUS_LPSC              0x00010000
00090 #define  OR_RH_STATUS_DRWE              0x00008000
00091 // -------------- HcRhPortStatus[1:NDP] Register -------------- 
00092 #define  OR_RH_PORT_CCS                 0x00000001
00093 #define  OR_RH_PORT_PRS                 0x00000010
00094 #define  OR_RH_PORT_CSC                 0x00010000
00095 #define  OR_RH_PORT_PRSC                0x00100000
00096 #define  OR_RH_PORT_LSDA                0x00000200
00097 
00098 #define  FI                     0x2EDF           // 12000 bits per frame (-1)
00099 #define  DEFAULT_FMINTERVAL     ((((6 * (FI - 210)) / 7) << 16) | FI)
00100 
00101 #define  ED_SKIP            (uint32_t) (0x00001000)        // Skip this ep in queue
00102 
00103 #define  TD_ROUNDING        (uint32_t) (0x00040000)        // Buffer Rounding                             
00104 #define  TD_SETUP           (uint32_t)(0)                  // Direction of Setup Packet                   
00105 #define  TD_IN              (uint32_t)(0x00100000)         // Direction In                                
00106 #define  TD_OUT             (uint32_t)(0x00080000)         // Direction Out                               
00107 #define  TD_DELAY_INT(x)    (uint32_t)((x) << 21)          // Delay Interrupt                             
00108 #define  TD_TOGGLE_0        (uint32_t)(0x02000000)         // Toggle 0                                    
00109 #define  TD_TOGGLE_1        (uint32_t)(0x03000000)         // Toggle 1                                    
00110 #define  TD_CC              (uint32_t)(0xF0000000)         // Completion Code                             
00111 
00112 #define  DEVICE_DESCRIPTOR                     (1)
00113 #define  CONFIGURATION_DESCRIPTOR              (2)
00114 #define  INTERFACE_DESCRIPTOR                  (4)
00115 #define  ENDPOINT_DESCRIPTOR                   (5)
00116 #define  HID_DESCRIPTOR                        (33)
00117 
00118 //  ----------- Control RequestType Fields  ----------- 
00119 #define  USB_DEVICE_TO_HOST         0x80
00120 #define  USB_HOST_TO_DEVICE         0x00
00121 #define  USB_REQUEST_TYPE_CLASS     0x20
00122 #define  USB_REQUEST_TYPE_STANDARD  0x00
00123 #define  USB_RECIPIENT_DEVICE       0x00
00124 #define  USB_RECIPIENT_INTERFACE    0x01
00125 #define  USB_RECIPIENT_ENDPOINT     0x02
00126 
00127 // -------------- USB Standard Requests  -------------- 
00128 #define  SET_ADDRESS                0x05
00129 #define  GET_DESCRIPTOR             0x06
00130 #define  SET_CONFIGURATION          0x09
00131 #define  SET_INTERFACE              0x0b
00132 #define  CLEAR_FEATURE              0x01
00133 
00134 // -------------- USB Descriptor Length  -------------- 
00135 #define DEVICE_DESCRIPTOR_LENGTH            0x12
00136 #define CONFIGURATION_DESCRIPTOR_LENGTH     0x09
00137 
00138 // ------------ HostController Transfer Descriptor ------------
00139 typedef struct HCTD {
00140     __IO  uint32_t   control;        // Transfer descriptor control
00141     __IO  uint8_t *  currBufPtr;    // Physical address of current buffer pointer
00142     __IO  HCTD *     nextTD;         // Physical pointer to next Transfer Descriptor
00143     __IO  uint8_t *  bufEnd;        // Physical address of end of buffer
00144     void * ep;                      // ep address where a td is linked in
00145     uint32_t dummy[3];              // padding
00146 } PACKED HCTD;
00147 
00148 // ----------- HostController EndPoint Descriptor ------------- 
00149 typedef struct hcEd {
00150     __IO  uint32_t  control;        // Endpoint descriptor control
00151     __IO  HCTD *  tailTD;           // Physical address of tail in Transfer descriptor list
00152     __IO  HCTD *  headTD;           // Physcial address of head in Transfer descriptor list
00153     __IO  hcEd *  nextED;         // Physical address of next Endpoint descriptor
00154 } PACKED HCED;
00155 
00156 
00157 // ----------- Host Controller Communication Area ------------  
00158 typedef struct hcca {
00159     __IO  uint32_t  IntTable[32];   // Interrupt Table
00160     __IO  uint32_t  FrameNumber;    // Frame Number
00161     __IO  uint32_t  DoneHead;       // Done Head
00162     volatile  uint8_t   Reserved[116];  // Reserved for future use                                  
00163     volatile  uint8_t   Unknown[4];     // Unused                                                   
00164 } PACKED HCCA;
00165 
00166 typedef struct {
00167     uint8_t bLength;            
00168     uint8_t bDescriptorType;    
00169     uint16_t bcdUSB;            
00170     uint8_t bDeviceClass;       
00171     uint8_t bDeviceSubClass;    
00172     uint8_t bDeviceProtocol;    
00173     uint8_t bMaxPacketSize;     
00174     uint16_t idVendor;          
00175     uint16_t idProduct;         
00176     uint16_t bcdDevice;         
00177     uint8_t iManufacturer;      
00178     uint8_t iProduct;           
00179     uint8_t iSerialNumber;      
00180     uint8_t bNumConfigurations; 
00181 } PACKED DeviceDescriptor;
00182 
00183 typedef struct {
00184     uint8_t bLength;               
00185     uint8_t bDescriptorType;       
00186     uint16_t wTotalLength;         
00187     uint8_t bNumInterfaces;        
00188     uint8_t bConfigurationValue;   
00189     uint8_t iConfiguration;        
00190     uint8_t bmAttributes;          
00191     uint8_t bMaxPower;             
00192 } PACKED ConfigurationDescriptor; 
00193 
00194 typedef struct {
00195     uint8_t bLength;                 
00196     uint8_t bDescriptorType;   
00197     uint8_t bInterfaceNumber;  
00198     uint8_t bAlternateSetting; 
00199     uint8_t bNumEndpoints;     
00200     uint8_t bInterfaceClass;   
00201     uint8_t bInterfaceSubClass;
00202     uint8_t bInterfaceProtocol;
00203     uint8_t iInterface;        
00204 } InterfaceDescriptor; 
00205 
00206 typedef struct {
00207     uint8_t bLength;          
00208     uint8_t bDescriptorType;  
00209     uint8_t bEndpointAddress; 
00210     uint8_t bmAttributes;     
00211     uint16_t wMaxPacketSize;  
00212     uint8_t bInterval;        
00213 } EndpointDescriptor;
00214 
00215 typedef struct {
00216     uint8_t bDescLength;      
00217     uint8_t bDescriptorType;  
00218     uint8_t bNbrPorts;        
00219     uint16_t wHubCharacteristics;
00220     uint8_t bPwrOn2PwrGood;   
00221     uint8_t bHubContrCurrent; 
00222     uint8_t DeviceRemovable;  
00223     uint8_t PortPweCtrlMak;   
00224 } HubDescriptor;              
00225 
00226 #endif