USBHost library. NOTE: This library is only officially supported on the LPC1768 platform. For more information, please see the handbook page.

Dependencies:   FATFileSystem mbed-rtos

Dependents:   BTstack WallbotWii SD to Flash Data Transfer USBHost-MSD_HelloWorld ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Pull requests against this repository are no longer supported. Please raise against mbed OS 5 as documented above.

Committer:
Anna Bridge
Date:
Thu Aug 17 18:12:22 2017 +0100
Revision:
40:7c3b59bb364e
Parent:
37:f1e388e7b752
DISCO_L475VG_IOT01A: Add support of USBHost

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 8:93da8ea2708b 1 /* mbed USBHost Library
samux 8:93da8ea2708b 2 * Copyright (c) 2006-2013 ARM Limited
samux 8:93da8ea2708b 3 *
samux 8:93da8ea2708b 4 * Licensed under the Apache License, Version 2.0 (the "License");
samux 8:93da8ea2708b 5 * you may not use this file except in compliance with the License.
samux 8:93da8ea2708b 6 * You may obtain a copy of the License at
samux 8:93da8ea2708b 7 *
samux 8:93da8ea2708b 8 * http://www.apache.org/licenses/LICENSE-2.0
samux 8:93da8ea2708b 9 *
samux 8:93da8ea2708b 10 * Unless required by applicable law or agreed to in writing, software
samux 8:93da8ea2708b 11 * distributed under the License is distributed on an "AS IS" BASIS,
samux 8:93da8ea2708b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
samux 8:93da8ea2708b 13 * See the License for the specific language governing permissions and
samux 8:93da8ea2708b 14 * limitations under the License.
samux 8:93da8ea2708b 15 */
mbed_official 0:a554658735bf 16
mbed_official 0:a554658735bf 17 #ifndef USB_INC_H
mbed_official 0:a554658735bf 18 #define USB_INC_H
mbed_official 0:a554658735bf 19
mbed_official 0:a554658735bf 20 #include "mbed.h"
Kojto 37:f1e388e7b752 21 #include "mbed_toolchain.h"
mbed_official 0:a554658735bf 22
mbed_official 0:a554658735bf 23 enum USB_TYPE {
mbed_official 0:a554658735bf 24 USB_TYPE_OK = 0,
mbed_official 0:a554658735bf 25
mbed_official 0:a554658735bf 26 // completion code
mbed_official 0:a554658735bf 27 USB_TYPE_CRC_ERROR = 1,
mbed_official 0:a554658735bf 28 USB_TYPE_BIT_STUFFING_ERROR = 2,
mbed_official 0:a554658735bf 29 USB_TYPE_DATA_TOGGLE_MISMATCH_ERROR = 3,
mbed_official 0:a554658735bf 30 USB_TYPE_STALL_ERROR = 4,
mbed_official 0:a554658735bf 31 USB_TYPE_DEVICE_NOT_RESPONDING_ERROR = 5,
mbed_official 0:a554658735bf 32 USB_TYPE_PID_CHECK_FAILURE_ERROR = 6,
mbed_official 0:a554658735bf 33 USB_TYPE_UNEXPECTED_PID_ERROR = 7,
mbed_official 0:a554658735bf 34 USB_TYPE_DATA_OVERRUN_ERROR = 8,
mbed_official 0:a554658735bf 35 USB_TYPE_DATA_UNDERRUN_ERROR = 9,
mbed_official 0:a554658735bf 36 USB_TYPE_RESERVED = 9,
mbed_official 0:a554658735bf 37 USB_TYPE_RESERVED_ = 10,
mbed_official 0:a554658735bf 38 USB_TYPE_BUFFER_OVERRUN_ERROR = 12,
mbed_official 0:a554658735bf 39 USB_TYPE_BUFFER_UNDERRUN_ERROR = 13,
mbed_official 0:a554658735bf 40
mbed_official 0:a554658735bf 41 // general usb state
mbed_official 0:a554658735bf 42 USB_TYPE_DISCONNECTED = 14,
mbed_official 0:a554658735bf 43 USB_TYPE_FREE = 15,
mbed_official 0:a554658735bf 44 USB_TYPE_IDLE = 16,
mbed_official 0:a554658735bf 45 USB_TYPE_PROCESSING = 17,
mbed_official 0:a554658735bf 46
mbed_official 0:a554658735bf 47 USB_TYPE_ERROR = 18,
mbed_official 0:a554658735bf 48 };
mbed_official 0:a554658735bf 49
mbed_official 0:a554658735bf 50
mbed_official 0:a554658735bf 51 enum ENDPOINT_DIRECTION {
mbed_official 0:a554658735bf 52 OUT = 1,
mbed_official 0:a554658735bf 53 IN
mbed_official 0:a554658735bf 54 };
mbed_official 0:a554658735bf 55
mbed_official 0:a554658735bf 56 enum ENDPOINT_TYPE {
mbed_official 0:a554658735bf 57 CONTROL_ENDPOINT = 0,
mbed_official 0:a554658735bf 58 ISOCHRONOUS_ENDPOINT,
mbed_official 0:a554658735bf 59 BULK_ENDPOINT,
mbed_official 0:a554658735bf 60 INTERRUPT_ENDPOINT
mbed_official 0:a554658735bf 61 };
mbed_official 0:a554658735bf 62
mbed_official 0:a554658735bf 63 #define AUDIO_CLASS 0x01
mbed_official 0:a554658735bf 64 #define CDC_CLASS 0x02
mbed_official 0:a554658735bf 65 #define HID_CLASS 0x03
mbed_official 0:a554658735bf 66 #define MSD_CLASS 0x08
mbed_official 0:a554658735bf 67 #define HUB_CLASS 0x09
mbed_official 0:a554658735bf 68 #define SERIAL_CLASS 0x0A
mbed_official 0:a554658735bf 69
Kojto 37:f1e388e7b752 70 #if !defined(USBHOST_OTHER)
mbed_official 24:868cbfe611a7 71 // ------------------ HcControl Register ---------------------
mbed_official 0:a554658735bf 72 #define OR_CONTROL_PLE 0x00000004
mbed_official 0:a554658735bf 73 #define OR_CONTROL_CLE 0x00000010
mbed_official 0:a554658735bf 74 #define OR_CONTROL_BLE 0x00000020
mbed_official 0:a554658735bf 75 #define OR_CONTROL_HCFS 0x000000C0
Kojto 37:f1e388e7b752 76 #define OR_CONTROL_HC_RSET 0x00000000
Kojto 37:f1e388e7b752 77 #define OR_CONTROL_HC_RES 0x00000040
mbed_official 0:a554658735bf 78 #define OR_CONTROL_HC_OPER 0x00000080
Kojto 37:f1e388e7b752 79 #define OR_CONTROL_HC_SUSP 0x000000C0
mbed_official 24:868cbfe611a7 80 // ----------------- HcCommandStatus Register -----------------
mbed_official 0:a554658735bf 81 #define OR_CMD_STATUS_HCR 0x00000001
mbed_official 0:a554658735bf 82 #define OR_CMD_STATUS_CLF 0x00000002
mbed_official 0:a554658735bf 83 #define OR_CMD_STATUS_BLF 0x00000004
mbed_official 24:868cbfe611a7 84 // --------------- HcInterruptStatus Register -----------------
mbed_official 0:a554658735bf 85 #define OR_INTR_STATUS_WDH 0x00000002
mbed_official 0:a554658735bf 86 #define OR_INTR_STATUS_RHSC 0x00000040
mbed_official 0:a554658735bf 87 #define OR_INTR_STATUS_UE 0x00000010
mbed_official 24:868cbfe611a7 88 // --------------- HcInterruptEnable Register -----------------
mbed_official 0:a554658735bf 89 #define OR_INTR_ENABLE_WDH 0x00000002
mbed_official 0:a554658735bf 90 #define OR_INTR_ENABLE_RHSC 0x00000040
mbed_official 0:a554658735bf 91 #define OR_INTR_ENABLE_MIE 0x80000000
mbed_official 24:868cbfe611a7 92 // ---------------- HcRhDescriptorA Register ------------------
mbed_official 0:a554658735bf 93 #define OR_RH_STATUS_LPSC 0x00010000
mbed_official 0:a554658735bf 94 #define OR_RH_STATUS_DRWE 0x00008000
mbed_official 24:868cbfe611a7 95 // -------------- HcRhPortStatus[1:NDP] Register --------------
mbed_official 0:a554658735bf 96 #define OR_RH_PORT_CCS 0x00000001
mbed_official 0:a554658735bf 97 #define OR_RH_PORT_PRS 0x00000010
mbed_official 0:a554658735bf 98 #define OR_RH_PORT_CSC 0x00010000
mbed_official 0:a554658735bf 99 #define OR_RH_PORT_PRSC 0x00100000
mbed_official 0:a554658735bf 100 #define OR_RH_PORT_LSDA 0x00000200
Kojto 37:f1e388e7b752 101 #define OR_RH_PORT_PESC 0x00020000
Kojto 37:f1e388e7b752 102 #define OR_RH_PORT_OCIC 0x00080000
mbed_official 0:a554658735bf 103
mbed_official 0:a554658735bf 104 #define FI 0x2EDF // 12000 bits per frame (-1)
mbed_official 0:a554658735bf 105 #define DEFAULT_FMINTERVAL ((((6 * (FI - 210)) / 7) << 16) | FI)
mbed_official 0:a554658735bf 106
mbed_official 0:a554658735bf 107 #define ED_SKIP (uint32_t) (0x00001000) // Skip this ep in queue
mbed_official 0:a554658735bf 108
mbed_official 24:868cbfe611a7 109 #define TD_ROUNDING (uint32_t) (0x00040000) // Buffer Rounding
mbed_official 24:868cbfe611a7 110 #define TD_SETUP (uint32_t)(0) // Direction of Setup Packet
mbed_official 24:868cbfe611a7 111 #define TD_IN (uint32_t)(0x00100000) // Direction In
mbed_official 24:868cbfe611a7 112 #define TD_OUT (uint32_t)(0x00080000) // Direction Out
mbed_official 24:868cbfe611a7 113 #define TD_DELAY_INT(x) (uint32_t)((x) << 21) // Delay Interrupt
mbed_official 24:868cbfe611a7 114 #define TD_TOGGLE_0 (uint32_t)(0x02000000) // Toggle 0
mbed_official 24:868cbfe611a7 115 #define TD_TOGGLE_1 (uint32_t)(0x03000000) // Toggle 1
mbed_official 24:868cbfe611a7 116 #define TD_CC (uint32_t)(0xF0000000) // Completion Code
mbed_official 0:a554658735bf 117
Kojto 37:f1e388e7b752 118 #else
Kojto 37:f1e388e7b752 119
Kojto 37:f1e388e7b752 120 #define TD_TIMEOUT_CTRL 100
Kojto 37:f1e388e7b752 121 #define TD_TIMEOUT 2000
Kojto 37:f1e388e7b752 122 #define TD_SETUP (uint32_t)(0) // Direction of Setup Packet
Kojto 37:f1e388e7b752 123 #define TD_IN (uint32_t)(0x00100000) // Direction In
Kojto 37:f1e388e7b752 124 #define TD_OUT (uint32_t)(0x00080000) // Direction Out
Kojto 37:f1e388e7b752 125
Kojto 37:f1e388e7b752 126 #endif
mbed_official 0:a554658735bf 127 #define DEVICE_DESCRIPTOR (1)
mbed_official 0:a554658735bf 128 #define CONFIGURATION_DESCRIPTOR (2)
mbed_official 0:a554658735bf 129 #define INTERFACE_DESCRIPTOR (4)
mbed_official 0:a554658735bf 130 #define ENDPOINT_DESCRIPTOR (5)
mbed_official 0:a554658735bf 131 #define HID_DESCRIPTOR (33)
mbed_official 0:a554658735bf 132
mbed_official 24:868cbfe611a7 133 // ----------- Control RequestType Fields -----------
mbed_official 0:a554658735bf 134 #define USB_DEVICE_TO_HOST 0x80
mbed_official 0:a554658735bf 135 #define USB_HOST_TO_DEVICE 0x00
mbed_official 0:a554658735bf 136 #define USB_REQUEST_TYPE_CLASS 0x20
mbed_official 0:a554658735bf 137 #define USB_REQUEST_TYPE_STANDARD 0x00
mbed_official 0:a554658735bf 138 #define USB_RECIPIENT_DEVICE 0x00
mbed_official 0:a554658735bf 139 #define USB_RECIPIENT_INTERFACE 0x01
mbed_official 0:a554658735bf 140 #define USB_RECIPIENT_ENDPOINT 0x02
mbed_official 0:a554658735bf 141
mbed_official 24:868cbfe611a7 142 // -------------- USB Standard Requests --------------
mbed_official 0:a554658735bf 143 #define SET_ADDRESS 0x05
mbed_official 0:a554658735bf 144 #define GET_DESCRIPTOR 0x06
mbed_official 0:a554658735bf 145 #define SET_CONFIGURATION 0x09
mbed_official 0:a554658735bf 146 #define SET_INTERFACE 0x0b
mbed_official 0:a554658735bf 147 #define CLEAR_FEATURE 0x01
mbed_official 0:a554658735bf 148
mbed_official 24:868cbfe611a7 149 // -------------- USB Descriptor Length --------------
mbed_official 0:a554658735bf 150 #define DEVICE_DESCRIPTOR_LENGTH 0x12
mbed_official 0:a554658735bf 151 #define CONFIGURATION_DESCRIPTOR_LENGTH 0x09
mbed_official 0:a554658735bf 152
mbed_official 0:a554658735bf 153 // ------------ HostController Transfer Descriptor ------------
Kojto 37:f1e388e7b752 154 #if defined(USBHOST_OTHER)
Kojto 37:f1e388e7b752 155
Kojto 37:f1e388e7b752 156 typedef struct hcTd {
Kojto 37:f1e388e7b752 157 __IO uint32_t state;
Kojto 37:f1e388e7b752 158 __IO uint8_t * currBufPtr; // Physical address of current buffer pointer
Kojto 37:f1e388e7b752 159 __IO hcTd * nextTD; // Physical pointer to next Transfer Descriptor
Kojto 37:f1e388e7b752 160 __IO uint32_t size; // size of buffer
Kojto 37:f1e388e7b752 161 void * ep; // ep address where a td is linked in
Kojto 37:f1e388e7b752 162 __IO uint32_t retry;
Kojto 37:f1e388e7b752 163 __IO uint32_t setup;
Kojto 37:f1e388e7b752 164 } PACKED HCTD;
Kojto 37:f1e388e7b752 165 // ----------- HostController EndPoint Descriptor -------------
Kojto 37:f1e388e7b752 166 typedef struct hcEd {
Kojto 37:f1e388e7b752 167 uint8_t ch_num;
Kojto 37:f1e388e7b752 168 void *hhcd;
Kojto 37:f1e388e7b752 169 } PACKED HCED;
Kojto 37:f1e388e7b752 170 // ----------- Host Controller Communication Area ------------
Kojto 37:f1e388e7b752 171 #define HCCA void
Kojto 37:f1e388e7b752 172
Kojto 37:f1e388e7b752 173
Kojto 37:f1e388e7b752 174 #else
Kojto 37:f1e388e7b752 175 // -------------OHCI register --------------------------------
Kojto 37:f1e388e7b752 176 // ------------ HostController Transfer Descriptor ------------
mbed_official 34:028508fd50fa 177 typedef struct hcTd {
samux 4:b320d68e98e7 178 __IO uint32_t control; // Transfer descriptor control
mbed_official 0:a554658735bf 179 __IO uint8_t * currBufPtr; // Physical address of current buffer pointer
mbed_official 34:028508fd50fa 180 __IO hcTd * nextTD; // Physical pointer to next Transfer Descriptor
mbed_official 0:a554658735bf 181 __IO uint8_t * bufEnd; // Physical address of end of buffer
mbed_official 0:a554658735bf 182 void * ep; // ep address where a td is linked in
mbed_official 0:a554658735bf 183 uint32_t dummy[3]; // padding
mbed_official 13:b58a2204422f 184 } PACKED HCTD;
mbed_official 24:868cbfe611a7 185 // ----------- HostController EndPoint Descriptor -------------
mbed_official 13:b58a2204422f 186 typedef struct hcEd {
mbed_official 0:a554658735bf 187 __IO uint32_t control; // Endpoint descriptor control
mbed_official 0:a554658735bf 188 __IO HCTD * tailTD; // Physical address of tail in Transfer descriptor list
mbed_official 0:a554658735bf 189 __IO HCTD * headTD; // Physcial address of head in Transfer descriptor list
samux 4:b320d68e98e7 190 __IO hcEd * nextED; // Physical address of next Endpoint descriptor
mbed_official 13:b58a2204422f 191 } PACKED HCED;
mbed_official 24:868cbfe611a7 192 // ----------- Host Controller Communication Area ------------
mbed_official 13:b58a2204422f 193 typedef struct hcca {
mbed_official 0:a554658735bf 194 __IO uint32_t IntTable[32]; // Interrupt Table
mbed_official 0:a554658735bf 195 __IO uint32_t FrameNumber; // Frame Number
mbed_official 0:a554658735bf 196 __IO uint32_t DoneHead; // Done Head
mbed_official 24:868cbfe611a7 197 volatile uint8_t Reserved[116]; // Reserved for future use
mbed_official 24:868cbfe611a7 198 volatile uint8_t Unknown[4]; // Unused
mbed_official 13:b58a2204422f 199 } PACKED HCCA;
Kojto 37:f1e388e7b752 200 #endif
mbed_official 0:a554658735bf 201
mbed_official 13:b58a2204422f 202 typedef struct {
mbed_official 24:868cbfe611a7 203 uint8_t bLength;
mbed_official 24:868cbfe611a7 204 uint8_t bDescriptorType;
mbed_official 24:868cbfe611a7 205 uint16_t bcdUSB;
mbed_official 24:868cbfe611a7 206 uint8_t bDeviceClass;
mbed_official 24:868cbfe611a7 207 uint8_t bDeviceSubClass;
mbed_official 24:868cbfe611a7 208 uint8_t bDeviceProtocol;
mbed_official 24:868cbfe611a7 209 uint8_t bMaxPacketSize;
mbed_official 24:868cbfe611a7 210 uint16_t idVendor;
mbed_official 24:868cbfe611a7 211 uint16_t idProduct;
mbed_official 24:868cbfe611a7 212 uint16_t bcdDevice;
mbed_official 24:868cbfe611a7 213 uint8_t iManufacturer;
mbed_official 24:868cbfe611a7 214 uint8_t iProduct;
mbed_official 24:868cbfe611a7 215 uint8_t iSerialNumber;
mbed_official 24:868cbfe611a7 216 uint8_t bNumConfigurations;
mbed_official 13:b58a2204422f 217 } PACKED DeviceDescriptor;
mbed_official 0:a554658735bf 218
mbed_official 13:b58a2204422f 219 typedef struct {
mbed_official 24:868cbfe611a7 220 uint8_t bLength;
mbed_official 24:868cbfe611a7 221 uint8_t bDescriptorType;
mbed_official 24:868cbfe611a7 222 uint16_t wTotalLength;
mbed_official 24:868cbfe611a7 223 uint8_t bNumInterfaces;
mbed_official 24:868cbfe611a7 224 uint8_t bConfigurationValue;
mbed_official 24:868cbfe611a7 225 uint8_t iConfiguration;
mbed_official 24:868cbfe611a7 226 uint8_t bmAttributes;
mbed_official 24:868cbfe611a7 227 uint8_t bMaxPower;
mbed_official 24:868cbfe611a7 228 } PACKED ConfigurationDescriptor;
mbed_official 0:a554658735bf 229
mbed_official 0:a554658735bf 230 typedef struct {
mbed_official 24:868cbfe611a7 231 uint8_t bLength;
mbed_official 24:868cbfe611a7 232 uint8_t bDescriptorType;
mbed_official 24:868cbfe611a7 233 uint8_t bInterfaceNumber;
mbed_official 24:868cbfe611a7 234 uint8_t bAlternateSetting;
mbed_official 24:868cbfe611a7 235 uint8_t bNumEndpoints;
mbed_official 24:868cbfe611a7 236 uint8_t bInterfaceClass;
mbed_official 0:a554658735bf 237 uint8_t bInterfaceSubClass;
mbed_official 0:a554658735bf 238 uint8_t bInterfaceProtocol;
mbed_official 24:868cbfe611a7 239 uint8_t iInterface;
mbed_official 24:868cbfe611a7 240 } InterfaceDescriptor;
mbed_official 0:a554658735bf 241
mbed_official 0:a554658735bf 242 typedef struct {
mbed_official 24:868cbfe611a7 243 uint8_t bLength;
mbed_official 24:868cbfe611a7 244 uint8_t bDescriptorType;
mbed_official 24:868cbfe611a7 245 uint8_t bEndpointAddress;
mbed_official 24:868cbfe611a7 246 uint8_t bmAttributes;
mbed_official 24:868cbfe611a7 247 uint16_t wMaxPacketSize;
mbed_official 24:868cbfe611a7 248 uint8_t bInterval;
mbed_official 0:a554658735bf 249 } EndpointDescriptor;
mbed_official 0:a554658735bf 250
mbed_official 0:a554658735bf 251 typedef struct {
mbed_official 24:868cbfe611a7 252 uint8_t bDescLength;
mbed_official 24:868cbfe611a7 253 uint8_t bDescriptorType;
mbed_official 24:868cbfe611a7 254 uint8_t bNbrPorts;
mbed_official 0:a554658735bf 255 uint16_t wHubCharacteristics;
mbed_official 24:868cbfe611a7 256 uint8_t bPwrOn2PwrGood;
mbed_official 24:868cbfe611a7 257 uint8_t bHubContrCurrent;
mbed_official 24:868cbfe611a7 258 uint8_t DeviceRemovable;
mbed_official 24:868cbfe611a7 259 uint8_t PortPweCtrlMak;
mbed_official 24:868cbfe611a7 260 } HubDescriptor;
mbed_official 0:a554658735bf 261
mbed_official 0:a554658735bf 262 #endif