Simple USBHost library for Nucleo F446RE/F411RE/F401RE FRDM-KL46Z/KL25Z/F64F LPC4088/LPC1768

Dependencies:   FATFileSystem

Dependents:   F401RE-BTstack_example F401RE-USBHostMSD_HelloWorld

Fork of KL46Z-USBHost by Norimasa Okamoto

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 #define  DEVICE_DESCRIPTOR                     (1)
00071 #define  CONFIGURATION_DESCRIPTOR              (2)
00072 #define  INTERFACE_DESCRIPTOR                  (4)
00073 #define  ENDPOINT_DESCRIPTOR                   (5)
00074 #define  HID_DESCRIPTOR                        (33)
00075 
00076 //  ----------- Control RequestType Fields  ----------- 
00077 #define  USB_DEVICE_TO_HOST         0x80
00078 #define  USB_HOST_TO_DEVICE         0x00
00079 #define  USB_REQUEST_TYPE_CLASS     0x20
00080 #define  USB_REQUEST_TYPE_STANDARD  0x00
00081 #define  USB_RECIPIENT_DEVICE       0x00
00082 #define  USB_RECIPIENT_INTERFACE    0x01
00083 #define  USB_RECIPIENT_ENDPOINT     0x02
00084 
00085 // -------------- USB Standard Requests  -------------- 
00086 #define  GET_STATUS                 0x00
00087 #define  SET_FEATURE                0x03
00088 #define  SET_ADDRESS                0x05
00089 #define  GET_DESCRIPTOR             0x06
00090 #define  SET_CONFIGURATION          0x09
00091 #define  SET_INTERFACE              0x0b
00092 #define  CLEAR_FEATURE              0x01
00093 
00094 // -------------- USB Descriptor Length  -------------- 
00095 #define DEVICE_DESCRIPTOR_LENGTH            0x12
00096 #define CONFIGURATION_DESCRIPTOR_LENGTH     0x09
00097 
00098 // PID
00099 #define DATA0 0x03
00100 #define DATA1 0x0b
00101 #define ACK   0x02
00102 #define STALL 0x0e
00103 #define NAK   0x0a
00104 
00105 #pragma pack(push,1)
00106 typedef struct {
00107     uint8_t bLength;            
00108     uint8_t bDescriptorType;    
00109     uint16_t bcdUSB;            
00110     uint8_t bDeviceClass;       
00111     uint8_t bDeviceSubClass;    
00112     uint8_t bDeviceProtocol;    
00113     uint8_t bMaxPacketSize;     
00114     uint16_t idVendor;          
00115     uint16_t idProduct;         
00116     uint16_t bcdDevice;         
00117     uint8_t iManufacturer;      
00118     uint8_t iProduct;           
00119     uint8_t iSerialNumber;      
00120     uint8_t bNumConfigurations; 
00121 } PACKED DeviceDescriptor;
00122 
00123 typedef struct {
00124     uint8_t bLength;               
00125     uint8_t bDescriptorType;       
00126     uint16_t wTotalLength;         
00127     uint8_t bNumInterfaces;        
00128     uint8_t bConfigurationValue;   
00129     uint8_t iConfiguration;        
00130     uint8_t bmAttributes;          
00131     uint8_t bMaxPower;             
00132 } PACKED ConfigurationDescriptor; 
00133 
00134 typedef struct {
00135     uint8_t bLength;                 
00136     uint8_t bDescriptorType;   
00137     uint8_t bInterfaceNumber;  
00138     uint8_t bAlternateSetting; 
00139     uint8_t bNumEndpoints;     
00140     uint8_t bInterfaceClass;   
00141     uint8_t bInterfaceSubClass;
00142     uint8_t bInterfaceProtocol;
00143     uint8_t iInterface;        
00144 } InterfaceDescriptor; 
00145 
00146 typedef struct {
00147     uint8_t bLength;          
00148     uint8_t bDescriptorType;  
00149     uint8_t bEndpointAddress; 
00150     uint8_t bmAttributes;     
00151     uint16_t wMaxPacketSize;  
00152     uint8_t bInterval;        
00153 } EndpointDescriptor;
00154 
00155 typedef struct {
00156     uint8_t bDescLength;      
00157     uint8_t bDescriptorType;  
00158     uint8_t bNbrPorts;        
00159     uint16_t wHubCharacteristics;
00160     uint8_t bPwrOn2PwrGood;   
00161     uint8_t bHubContrCurrent; 
00162     uint8_t DeviceRemovable;  
00163     uint8_t PortPweCtrlMak;   
00164 } HubDescriptor;              
00165 #pragma pack(pop)
00166 
00167 #endif