USB device stack

Dependents:   mbed-mX-USB-TEST1 USBMSD_SD_HID_HelloWorld HidTest MIDI_usb_bridge ... 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:
Kojto
Date:
Thu Jul 20 10:14:36 2017 +0100
Revision:
70:2c525a50f1b6
Parent:
59:2af474687369
Update libraries (ed9d1da)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 59:2af474687369 1 /***************************************************************************//**
mbed_official 59:2af474687369 2 * @file em_usb.h
mbed_official 59:2af474687369 3 * @brief USB protocol stack library API for EFM32.
mbed_official 59:2af474687369 4 * @version 3.20.14
mbed_official 59:2af474687369 5 *******************************************************************************
mbed_official 59:2af474687369 6 * @section License
mbed_official 59:2af474687369 7 * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b>
mbed_official 59:2af474687369 8 *******************************************************************************
mbed_official 59:2af474687369 9 *
mbed_official 59:2af474687369 10 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 59:2af474687369 11 * you may not use this file except in compliance with the License.
mbed_official 59:2af474687369 12 * You may obtain a copy of the License at
mbed_official 59:2af474687369 13 *
mbed_official 59:2af474687369 14 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 59:2af474687369 15 *
mbed_official 59:2af474687369 16 * Unless required by applicable law or agreed to in writing, software
mbed_official 59:2af474687369 17 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 59:2af474687369 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 59:2af474687369 19 * See the License for the specific language governing permissions and
mbed_official 59:2af474687369 20 * limitations under the License.
mbed_official 59:2af474687369 21 *
mbed_official 59:2af474687369 22 ******************************************************************************/
mbed_official 59:2af474687369 23
mbed_official 59:2af474687369 24 #ifndef __EM_USB_H
mbed_official 59:2af474687369 25 #define __EM_USB_H
mbed_official 59:2af474687369 26
mbed_official 59:2af474687369 27 #include "em_device.h"
mbed_official 59:2af474687369 28 #include "em_assert.h"
mbed_official 59:2af474687369 29 #if defined( USB_PRESENT ) && ( USB_COUNT == 1 )
mbed_official 59:2af474687369 30 #include "usbconfig.h"
mbed_official 59:2af474687369 31 #if defined( USB_DEVICE ) || defined( USB_HOST )
mbed_official 59:2af474687369 32
mbed_official 59:2af474687369 33 #include <string.h>
mbed_official 59:2af474687369 34 #include <stddef.h>
mbed_official 59:2af474687369 35 #include "em_common.h"
Kojto 70:2c525a50f1b6 36 /* Workaround for em_common naming change so that we don't need to rework the
Kojto 70:2c525a50f1b6 37 entire USB HAL */
Kojto 70:2c525a50f1b6 38 #define EFM32_PACK_START(x) SL_PACK_START(x)
Kojto 70:2c525a50f1b6 39 #define EFM32_PACK_END() SL_PACK_END()
Kojto 70:2c525a50f1b6 40 #define EFM32_MIN(a, b) SL_MIN(a, b)
Kojto 70:2c525a50f1b6 41 #define EFM32_MAX(a, b) SL_MAX(a, b)
Kojto 70:2c525a50f1b6 42 #define EFM32_ATTRIBUTE_PACKED SL_ATTRIBUTE_PACKED
Kojto 70:2c525a50f1b6 43 #define EFM32_ATTRIBUTE_ALIGN(X) SL_ATTRIBUTE_ALIGN(X)
Kojto 70:2c525a50f1b6 44 #define EFM32_ALIGN(X) SL_ALIGN(X)
Kojto 70:2c525a50f1b6 45 #define EFM32_WEAK SL_WEAK
Kojto 70:2c525a50f1b6 46 #define EFM32_ATTRIBUTE_SECTION(X) SL_ATTRIBUTE_SECTION(X)
Kojto 70:2c525a50f1b6 47
mbed_official 59:2af474687369 48 #include "em_int.h"
mbed_official 59:2af474687369 49
mbed_official 59:2af474687369 50 #if defined( USB_USE_PRINTF )
mbed_official 59:2af474687369 51 #include <stdio.h>
mbed_official 59:2af474687369 52 #endif
mbed_official 59:2af474687369 53
mbed_official 59:2af474687369 54 #ifdef __cplusplus
mbed_official 59:2af474687369 55 extern "C" {
mbed_official 59:2af474687369 56 #endif
mbed_official 59:2af474687369 57
mbed_official 59:2af474687369 58 #ifdef __CC_ARM
mbed_official 59:2af474687369 59 #pragma anon_unions
mbed_official 59:2af474687369 60 #endif
mbed_official 59:2af474687369 61
mbed_official 59:2af474687369 62 /***************************************************************************//**
mbed_official 59:2af474687369 63 * @addtogroup USB
mbed_official 59:2af474687369 64 * @brief USB HOST and DEVICE protocol stacks.
mbed_official 59:2af474687369 65 * @{
mbed_official 59:2af474687369 66 ******************************************************************************/
mbed_official 59:2af474687369 67
mbed_official 59:2af474687369 68 /***************************************************************************//**
mbed_official 59:2af474687369 69 * @addtogroup USB_COMMON
mbed_official 59:2af474687369 70 * @brief Common parts for both HOST and DEVICE USB stacks, see @ref usb_device
mbed_official 59:2af474687369 71 * and @ref usb_host pages for device and host library documentation.
mbed_official 59:2af474687369 72 * @{
mbed_official 59:2af474687369 73 ******************************************************************************/
mbed_official 59:2af474687369 74
mbed_official 59:2af474687369 75 #define SILABS_USB_VID 0x10C4 /**< Silicon Labs Vendor ID, supplied by USB-IF. */
mbed_official 59:2af474687369 76
mbed_official 59:2af474687369 77 /* SETUP request, direction of data stage */
mbed_official 59:2af474687369 78 #define USB_SETUP_DIR_OUT 0 /**< Setup request data stage OUT direction value. */
mbed_official 59:2af474687369 79 #define USB_SETUP_DIR_IN 1 /**< Setup request data stage IN direction value. */
mbed_official 59:2af474687369 80 #define USB_SETUP_DIR_MASK 0x80 /**< Setup request data stage direction mask. */
mbed_official 59:2af474687369 81 #define USB_SETUP_DIR_D2H 0x80 /**< Setup request data stage IN direction mask. */
mbed_official 59:2af474687369 82 #define USB_SETUP_DIR_H2D 0x00 /**< Setup request data stage OUT direction mask. */
mbed_official 59:2af474687369 83
mbed_official 59:2af474687369 84 /* SETUP request type */
mbed_official 59:2af474687369 85 #define USB_SETUP_TYPE_STANDARD 0 /**< Standard setup request value. */
mbed_official 59:2af474687369 86 #define USB_SETUP_TYPE_CLASS 1 /**< Class setup request value. */
mbed_official 59:2af474687369 87 #define USB_SETUP_TYPE_VENDOR 2 /**< Vendor setup request value. */
mbed_official 59:2af474687369 88 #define USB_SETUP_TYPE_STANDARD_MASK 0x00 /**< Standard setup request mask. */
mbed_official 59:2af474687369 89 #define USB_SETUP_TYPE_CLASS_MASK 0x20 /**< Class setup request mask. */
mbed_official 59:2af474687369 90 #define USB_SETUP_TYPE_VENDOR_MASK 0x40 /**< Vendor setup request mask. */
mbed_official 59:2af474687369 91
mbed_official 59:2af474687369 92 /* SETUP request recipient */
mbed_official 59:2af474687369 93 #define USB_SETUP_RECIPIENT_DEVICE 0 /**< Setup request device recipient value. */
mbed_official 59:2af474687369 94 #define USB_SETUP_RECIPIENT_INTERFACE 1 /**< Setup request interface recipient value. */
mbed_official 59:2af474687369 95 #define USB_SETUP_RECIPIENT_ENDPOINT 2 /**< Setup request endpoint recipient value. */
mbed_official 59:2af474687369 96 #define USB_SETUP_RECIPIENT_OTHER 3 /**< Setup request other recipient value. */
mbed_official 59:2af474687369 97
mbed_official 59:2af474687369 98 /* SETUP standard request codes for Full Speed devices */
mbed_official 59:2af474687369 99 #define GET_STATUS 0 /**< Standard setup request GET_STATUS. */
mbed_official 59:2af474687369 100 #define CLEAR_FEATURE 1 /**< Standard setup request CLEAR_FEATURE. */
mbed_official 59:2af474687369 101 #define SET_FEATURE 3 /**< Standard setup request SET_FEATURE. */
mbed_official 59:2af474687369 102 #define SET_ADDRESS 5 /**< Standard setup request SET_ADDRESS. */
mbed_official 59:2af474687369 103 #define GET_DESCRIPTOR 6 /**< Standard setup request GET_DESCRIPTOR. */
mbed_official 59:2af474687369 104 #define SET_DESCRIPTOR 7 /**< Standard setup request SET_DESCRIPTOR. */
mbed_official 59:2af474687369 105 #define GET_CONFIGURATION 8 /**< Standard setup request GET_CONFIGURATION. */
mbed_official 59:2af474687369 106 #define SET_CONFIGURATION 9 /**< Standard setup request SET_CONFIGURATION. */
mbed_official 59:2af474687369 107 #define GET_INTERFACE 10 /**< Standard setup request GET_INTERFACE. */
mbed_official 59:2af474687369 108 #define SET_INTERFACE 11 /**< Standard setup request SET_INTERFACE. */
mbed_official 59:2af474687369 109 #define SYNCH_FRAME 12 /**< Standard setup request SYNCH_FRAME. */
mbed_official 59:2af474687369 110
mbed_official 59:2af474687369 111 /* SETUP class request codes */
mbed_official 59:2af474687369 112 #define USB_HID_GET_REPORT 0x01 /**< HID class setup request GET_REPORT. */
mbed_official 59:2af474687369 113 #define USB_HID_GET_IDLE 0x02 /**< HID class setup request GET_IDLE. */
mbed_official 59:2af474687369 114 #define USB_HID_SET_REPORT 0x09 /**< HID class setup request SET_REPORT. */
mbed_official 59:2af474687369 115 #define USB_HID_SET_IDLE 0x0A /**< HID class setup request SET_IDLE. */
mbed_official 59:2af474687369 116 #define USB_HID_SET_PROTOCOL 0x0B /**< HID class setup request SET_PROTOCOL. */
mbed_official 59:2af474687369 117 #define USB_CDC_SETLINECODING 0x20 /**< CDC class setup request SET_LINE_CODING. */
mbed_official 59:2af474687369 118 #define USB_CDC_GETLINECODING 0x21 /**< CDC class setup request GET_LINE_CODING. */
mbed_official 59:2af474687369 119 #define USB_CDC_SETCTRLLINESTATE 0x22 /**< CDC class setup request SET_CONTROL_LINE_STATE. */
mbed_official 59:2af474687369 120 #define USB_MSD_BOTRESET 0xFF /**< MSD class setup request Bulk only transfer reset. */
mbed_official 59:2af474687369 121 #define USB_MSD_GETMAXLUN 0xFE /**< MSD class setup request Get Max LUN. */
mbed_official 59:2af474687369 122 #define USB_AUDIO_GET_CUR 0x81 /**< Audio class setup request GET_CUR. */
mbed_official 59:2af474687369 123 #define USB_AUDIO_SET_CUR 0x01 /**< Audio class setup request SET_CUR. */
mbed_official 59:2af474687369 124 #define USB_AUDIO_GET_CUR 0x81 /**< Audio class setup request GET_CUR. */
mbed_official 59:2af474687369 125 #define USB_AUDIO_SET_MIN 0x02 /**< Audio class setup request SET_MIN. */
mbed_official 59:2af474687369 126 #define USB_AUDIO_GET_MIN 0x82 /**< Audio class setup request GET_MIN. */
mbed_official 59:2af474687369 127 #define USB_AUDIO_SET_MAX 0x03 /**< Audio class setup request SET_MAX. */
mbed_official 59:2af474687369 128 #define USB_AUDIO_GET_MAX 0x83 /**< Audio class setup request GET_MAX. */
mbed_official 59:2af474687369 129 #define USB_AUDIO_SET_RES 0x04 /**< Audio class setup request SET_RES. */
mbed_official 59:2af474687369 130 #define USB_AUDIO_GET_RES 0x84 /**< Audio class setup request GET_RES. */
mbed_official 59:2af474687369 131 #define USB_AUDIO_SET_MEM 0x05 /**< Audio class setup request SET_MEM. */
mbed_official 59:2af474687369 132 #define USB_AUDIO_GET_MEM 0x85 /**< Audio class setup request GET_MEM. */
mbed_official 59:2af474687369 133 #define USB_AUDIO_GET_STAT 0xFF /**< Audio class setup request GET_STAT. */
mbed_official 59:2af474687369 134
mbed_official 59:2af474687369 135 /* SETUP command GET/SET_DESCRIPTOR decriptor types */
mbed_official 59:2af474687369 136 #define USB_DEVICE_DESCRIPTOR 1 /**< DEVICE descriptor value. */
mbed_official 59:2af474687369 137 #define USB_CONFIG_DESCRIPTOR 2 /**< CONFIGURATION descriptor value. */
mbed_official 59:2af474687369 138 #define USB_STRING_DESCRIPTOR 3 /**< STRING descriptor value. */
mbed_official 59:2af474687369 139 #define USB_MAX_STRING_DESCRIPTOR_CHARS 126 /**< Maximum STRING descriptor bString length. */
mbed_official 59:2af474687369 140 #define USB_INTERFACE_DESCRIPTOR 4 /**< INTERFACE descriptor value. */
mbed_official 59:2af474687369 141 #define USB_ENDPOINT_DESCRIPTOR 5 /**< ENDPOINT descriptor value. */
mbed_official 59:2af474687369 142 #define USB_DEVICE_QUALIFIER_DESCRIPTOR 6 /**< DEVICE_QUALIFIER descriptor value. */
mbed_official 59:2af474687369 143 #define USB_OTHER_SPEED_CONFIG_DESCRIPTOR 7 /**< OTHER_SPEED_CONFIGURATION descriptor value. */
mbed_official 59:2af474687369 144 #define USB_INTERFACE_POWER_DESCRIPTOR 8 /**< INTERFACE_POWER descriptor value. */
mbed_official 59:2af474687369 145 #define USB_INTERFACE_ASSOCIATION_DESCRIPTOR 11 /**< INTERFACE_ASSOCIATION descriptor value. */
mbed_official 59:2af474687369 146 #define USB_HID_DESCRIPTOR 0x21 /**< HID descriptor value. */
mbed_official 59:2af474687369 147 #define USB_SMARTCARD_DESCRIPTOR 0x21 /**< Smartcard usb-ccid-specific Descriptor Type. */
mbed_official 59:2af474687369 148 #define USB_HID_REPORT_DESCRIPTOR 0x22 /**< HID REPORT descriptor value. */
mbed_official 59:2af474687369 149 #define USB_CS_INTERFACE_DESCRIPTOR 0x24 /**< Audio Class-specific interface Descriptor Type. */
mbed_official 59:2af474687369 150 #define USB_CS_ENDPOINT_DESCRIPTOR 0x25 /**< Audio Class-specific endpoint Descriptor Type. */
mbed_official 59:2af474687369 151 #define USB_HUB_DESCRIPTOR 0x29 /**< HUB descriptor value. */
mbed_official 59:2af474687369 152 #define USB_CA_HEADER_DESCRIPTOR 1 /**< Audio Class-Specific AC Interface Header descriptor.*/
mbed_official 59:2af474687369 153 #define USB_CA_INPUT_TERMINAL_DESCRIPTOR 2 /**< Audio Class-Specific AC Interface Input Terminal desc. */
mbed_official 59:2af474687369 154 #define USB_CA_OUTPUT_TERMINAL_DESCRIPTOR 3 /**< Audio Class-Specific AC Interface Output Terminal desc.*/
mbed_official 59:2af474687369 155 #define USB_CA_MIXER_UNIT_DESCRIPTOR 4 /**< Audio Class-Specific AC Interface Mixer descriptor.*/
mbed_official 59:2af474687369 156 #define USB_CA_SELECTOR_UNIT_DESCRIPTOR 5 /**< Audio Class-Specific AC Interface Selector desc. */
mbed_official 59:2af474687369 157 #define USB_CA_FEATURE_UNIT_DESCRIPTOR 6 /**< Audio Class-Specific AC Interface Feature desc. */
mbed_official 59:2af474687369 158 #define USB_CA_PROCESSING_UNIT_DESCRIPTOR 7 /**< Audio Class-Specific AC Interface Processing desc.*/
mbed_official 59:2af474687369 159 #define USB_CA_EXTENSION_UNIT_DESCRIPTOR 8 /**< Audio Class-Specific AC Interface Extension desc. */
mbed_official 59:2af474687369 160 #define USB_CA_EP_GENERAL_DESCRIPTOR 1 /**< Audio Class-Specific general descriptor subtype code.*/
mbed_official 59:2af474687369 161 #define USB_CA_AS_GENERAL_DESCRIPTOR 1 /**< Audio Class-Specific AS Interface General descriptor.*/
mbed_official 59:2af474687369 162 #define USB_CA_FORMAT_TYPE_DESCRIPTOR 2 /**< Audio Class-Specific AS Interface Format Type desc. */
mbed_official 59:2af474687369 163
mbed_official 59:2af474687369 164 #define USB_DEVICE_DESCSIZE 18 /**< Device descriptor size. */
mbed_official 59:2af474687369 165 #define USB_CONFIG_DESCSIZE 9 /**< Configuration descriptor size. */
mbed_official 59:2af474687369 166 #define USB_INTERFACE_DESCSIZE 9 /**< Interface descriptor size. */
mbed_official 59:2af474687369 167 #define USB_ENDPOINT_DESCSIZE 7 /**< Endpoint descriptor size. */
mbed_official 59:2af474687369 168 #define USB_DEVICE_QUALIFIER_DESCSIZE 10 /**< Device qualifier descriptor size. */
mbed_official 59:2af474687369 169 #define USB_OTHER_SPEED_CONFIG_DESCSIZE 9 /**< Device other speed configuration descriptor size. */
mbed_official 59:2af474687369 170 #define USB_INTERFACE_ASSOCIATION_DESCSIZE 8 /**< INTERFACE_ASSOCIATION descriptor size. */
mbed_official 59:2af474687369 171 #define USB_HID_DESCSIZE 9 /**< HID descriptor size. */
mbed_official 59:2af474687369 172 #define USB_SMARTCARD_DESCSIZE 54 /**< CCID descriptor size. */
mbed_official 59:2af474687369 173 #define USB_CDC_HEADER_FND_DESCSIZE 5 /**< CDC Header functional descriptor size. */
mbed_official 59:2af474687369 174 #define USB_CDC_CALLMNG_FND_DESCSIZE 5 /**< CDC Call Management functional descriptor size. */
mbed_official 59:2af474687369 175 #define USB_CDC_ACM_FND_DESCSIZE 4 /**< CDC Abstract Control Management functional descriptor size.*/
mbed_official 59:2af474687369 176 #define USB_CA_INPUT_TERMINAL_DESCSIZE 12 /**< Audio Input Terminal descriptor size. */
mbed_official 59:2af474687369 177 #define USB_CA_OUTPUT_TERMINAL_DESCSIZE 9 /**< Audio Output Terminal descriptor size. */
mbed_official 59:2af474687369 178 #define USB_CA_EP_GENERAL_DESCSIZE 7 /**< Audio Class-Specific general descriptor subtype size.*/
mbed_official 59:2af474687369 179 #define USB_CA_AS_GENERAL_DESCSIZE 7 /**< Audio Class-Specific AS Interface General desc size.*/
mbed_official 59:2af474687369 180 #define USB_CA_STD_AS_ENDPOINT_DESCSZIE 9 /**< Audio-class standard audio stream descriptor size.*/
mbed_official 59:2af474687369 181
mbed_official 59:2af474687369 182 /* Misc. USB definitions */
mbed_official 59:2af474687369 183 #define USB_LS_CTRL_EP_MAXSIZE 8 /**< The max size of low speed control endpoints. */
mbed_official 59:2af474687369 184 #define USB_LS_INTR_EP_MAXSIZE 8 /**< The max size of low speed interrupt endpoints. */
mbed_official 59:2af474687369 185 #define USB_FS_CTRL_EP_MAXSIZE 64 /**< The max size of full speed control endpoints. */
mbed_official 59:2af474687369 186 #define USB_FS_INTR_EP_MAXSIZE 64 /**< The max size of full speed interrupt endpoints. */
mbed_official 59:2af474687369 187 #define USB_FS_BULK_EP_MAXSIZE 64 /**< The max size of full speed bulk endpoints. */
mbed_official 59:2af474687369 188 #define USB_FS_ISOC_EP_MAXSIZE 1023 /**< The max size of full speed isochronous endpoints. */
mbed_official 59:2af474687369 189 #define USB_EPTYPE_CTRL 0 /**< Endpoint type control. */
mbed_official 59:2af474687369 190 #define USB_EPTYPE_ISOC 1 /**< Endpoint type isochron. */
mbed_official 59:2af474687369 191 #define USB_EPTYPE_BULK 2 /**< Endpoint type bulk. */
mbed_official 59:2af474687369 192 #define USB_EPTYPE_INTR 3 /**< Endpoint type interrupt. */
mbed_official 59:2af474687369 193 #define USB_EPSYNC_NO (0 << 2) /**< Endpoint synchronization type, none. */
mbed_official 59:2af474687369 194 #define USB_EPSYNC_ASYNC (1 << 2) /**< Endpoint synchronization type, asynchronous. */
mbed_official 59:2af474687369 195 #define USB_EPSYNC_ADAPTIVE (2 << 2) /**< Endpoint synchronization type, adaptive. */
mbed_official 59:2af474687369 196 #define USB_EPSYNC_SYNC (3 << 2) /**< Endpoint synchronization type, synchronous. */
mbed_official 59:2af474687369 197 #define USB_EP_DIR_IN 0x80 /**< Endpoint direction mask. */
mbed_official 59:2af474687369 198 #define USB_SETUP_PKT_SIZE 8 /**< Setup request packet size. */
mbed_official 59:2af474687369 199 #define USB_EPNUM_MASK 0x0F /**< Endpoint number mask. */
mbed_official 59:2af474687369 200 #define USB_LANGID_ENUS 0x0409 /**< English-United States language id. */
mbed_official 59:2af474687369 201 #define USB_MAX_DEVICE_ADDRESS 127 /**< Maximum allowable device address. */
mbed_official 59:2af474687369 202
mbed_official 59:2af474687369 203 #define CONFIG_DESC_BM_REMOTEWAKEUP 0x20 /**< Configuration descriptor attribute macro. */
mbed_official 59:2af474687369 204 #define CONFIG_DESC_BM_SELFPOWERED 0x40 /**< Configuration descriptor attribute macro. */
mbed_official 59:2af474687369 205 #define CONFIG_DESC_BM_RESERVED_D7 0x80 /**< Configuration descriptor attribute macro. */
mbed_official 59:2af474687369 206 #define CONFIG_DESC_BM_TRANSFERTYPE 0x03 /**< Configuration descriptor transfer type bitmask. */
mbed_official 59:2af474687369 207 #define CONFIG_DESC_MAXPOWER_mA(x) (((x)+1)/2) /**< Configuration descriptor power macro. */
mbed_official 59:2af474687369 208
mbed_official 59:2af474687369 209 #define DEVICE_IS_SELFPOWERED 0x0001 /**< Standard request GET_STATUS bitmask. */
mbed_official 59:2af474687369 210 #define REMOTE_WAKEUP_ENABLED 0x0002 /**< Standard request GET_STATUS bitmask. */
mbed_official 59:2af474687369 211 #define USB_FEATURE_ENDPOINT_HALT 0 /**< Standard request CLEAR/SET_FEATURE bitmask. */
mbed_official 59:2af474687369 212 #define USB_FEATURE_DEVICE_REMOTE_WAKEUP 1 /**< Standard request CLEAR/SET_FEATURE bitmask. */
mbed_official 59:2af474687369 213
mbed_official 59:2af474687369 214 #define HUB_FEATURE_PORT_RESET 4 /**< HUB class request CLEAR/SET_PORT_FEATURE feature selector. */
mbed_official 59:2af474687369 215 #define HUB_FEATURE_PORT_POWER 8 /**< HUB class request CLEAR/SET_PORT_FEATURE feature selector. */
mbed_official 59:2af474687369 216 #define HUB_FEATURE_C_PORT_CONNECTION 16 /**< HUB class request CLEAR/SET_PORT_FEATURE feature selector. */
mbed_official 59:2af474687369 217 #define HUB_FEATURE_C_PORT_RESET 20 /**< HUB class request CLEAR/SET_PORT_FEATURE feature selector. */
mbed_official 59:2af474687369 218 #define HUB_FEATURE_PORT_INDICATOR 22 /**< HUB class request CLEAR/SET_PORT_FEATURE feature selector. */
mbed_official 59:2af474687369 219
mbed_official 59:2af474687369 220 #define USB_CLASS_CDC 2 /**< CDC device/interface class code. */
mbed_official 59:2af474687369 221 #define USB_CLASS_CDC_DATA 0x0A /**< CDC Data interface class code. */
mbed_official 59:2af474687369 222 #define USB_CLASS_CDC_ACM 2 /**< CDC Abstract Control Model interface subclass code. */
mbed_official 59:2af474687369 223 #define USB_CLASS_CDC_HFN 0 /**< CDC class Header Functional Descriptor subtype. */
mbed_official 59:2af474687369 224 #define USB_CLASS_CDC_CMNGFN 1 /**< CDC class Call Management Functional Descriptor subtype.*/
mbed_official 59:2af474687369 225 #define USB_CLASS_CDC_ACMFN 2 /**< CDC class Abstract Control Management Functional Descriptor subtype.*/
mbed_official 59:2af474687369 226 #define USB_CLASS_CDC_UNIONFN 6 /**< CDC class Union Functional Descriptor subtype. */
mbed_official 59:2af474687369 227
mbed_official 59:2af474687369 228 #define USB_CLASS_HID 3 /**< HID device/interface class code. */
mbed_official 59:2af474687369 229 #define USB_CLASS_HID_KEYBOARD 1 /**< HID keyboard interface protocol code. */
mbed_official 59:2af474687369 230 #define USB_CLASS_HID_MOUSE 2 /**< HID mouse interface protocol code. */
mbed_official 59:2af474687369 231
mbed_official 59:2af474687369 232 #define USB_CLASS_HUB 9 /**< HUB device/interface class code. */
mbed_official 59:2af474687369 233
mbed_official 59:2af474687369 234 #define USB_CLASS_MSD 8 /**< MSD device/interface class code. */
mbed_official 59:2af474687369 235 #define USB_CLASS_MSD_BOT_TRANSPORT 0x50 /**< MSD Bulk Only Transport protocol. */
mbed_official 59:2af474687369 236 #define USB_CLASS_MSD_SCSI_CMDSET 6 /**< MSD Subclass SCSI transparent command set. */
mbed_official 59:2af474687369 237 #define USB_CLASS_MSD_CSW_CMDPASSED 0 /**< MSD BOT Command status wrapper command passed code. */
mbed_official 59:2af474687369 238 #define USB_CLASS_MSD_CSW_CMDFAILED 1 /**< MSD BOT Command status wrapper command failed code. */
mbed_official 59:2af474687369 239 #define USB_CLASS_MSD_CSW_PHASEERROR 2 /**< MSD BOT Command status wrapper cmd phase error code.*/
mbed_official 59:2af474687369 240
mbed_official 59:2af474687369 241 #define USB_CLASS_AUDIO 1 /**< Audio interface class code. */
mbed_official 59:2af474687369 242 #define USB_CLASS_AUDIO_CONTROL 1 /**< Audio subclass code for control interface. */
mbed_official 59:2af474687369 243 #define USB_CLASS_AUDIO_STREAMING 2 /**< Audio subclass code for streaming interface. */
mbed_official 59:2af474687369 244 #define USB_CLASS_AUDIO_MIDISTREAMING 3 /**< Audio subclass code for midi streaming interface. */
mbed_official 59:2af474687369 245
mbed_official 59:2af474687369 246 /*** Triplet for the device descriptor of a composite device using IAD descriptors. ***/
mbed_official 59:2af474687369 247 #define USB_CLASS_MISCELLANEOUS 0xEF /**< MISCELLANEOUS device class code. */
mbed_official 59:2af474687369 248 #define USB_CLASS_MISC_COMMON_SUBCLASS 2 /**< MISCELLANEOUS Common sub class code. */
mbed_official 59:2af474687369 249 #define USB_CLASS_MISC_IAD_PROTOCOL 1 /**< MISCELLANEOUS Interface Association Descriptor protocol code. */
mbed_official 59:2af474687369 250
mbed_official 59:2af474687369 251 #define PORT_FULL_SPEED 1 /**< Full speed return value for USBH_GetPortSpeed(). */
mbed_official 59:2af474687369 252 #define PORT_LOW_SPEED 2 /**< Low speed return value for USBH_GetPortSpeed(). */
mbed_official 59:2af474687369 253
mbed_official 59:2af474687369 254 #if defined( __GNUC__ ) /* GCC compilers */
mbed_official 59:2af474687369 255 #if defined( __CHAR16_TYPE__ )
mbed_official 59:2af474687369 256 typedef __CHAR16_TYPE__ char16_t;
mbed_official 59:2af474687369 257 #else
mbed_official 59:2af474687369 258 typedef unsigned short char16_t;
mbed_official 59:2af474687369 259 #endif
mbed_official 59:2af474687369 260
mbed_official 59:2af474687369 261 #elif defined( __ICCARM__ ) /* IAR compiler */
mbed_official 59:2af474687369 262 #include <uchar.h>
mbed_official 59:2af474687369 263
mbed_official 59:2af474687369 264 #elif defined( __CC_ARM ) /* MDK-ARM compiler */
mbed_official 59:2af474687369 265 typedef unsigned short char16_t;
mbed_official 59:2af474687369 266 #endif
mbed_official 59:2af474687369 267
mbed_official 59:2af474687369 268 /** Macro for creating USB compliant UTF-16LE UNICODE string descriptors.
mbed_official 59:2af474687369 269 * @n Example: STATIC_CONST_STRING_DESC( iManufacturer, 'E','n','e','r','g','y',' ','M','i','c','r','o',' ','A','S' );
mbed_official 59:2af474687369 270 * @note The size of the resulting struct will be two byte larger than a USB string
mbed_official 59:2af474687369 271 * descriptor. This is to accommodate a terminating null char for the string.
mbed_official 59:2af474687369 272 * The value assigned to the 'len' member does not take this into account
mbed_official 59:2af474687369 273 * and is therefore correct usb wise.
mbed_official 59:2af474687369 274 */
mbed_official 59:2af474687369 275 #define STATIC_CONST_STRING_DESC( _name, ... ) \
mbed_official 59:2af474687369 276 EFM32_PACK_START( 1 ) \
mbed_official 59:2af474687369 277 typedef struct \
mbed_official 59:2af474687369 278 { \
mbed_official 59:2af474687369 279 uint8_t len; \
mbed_official 59:2af474687369 280 uint8_t type; \
mbed_official 59:2af474687369 281 char16_t name[ 1 + sizeof( (char16_t[]){__VA_ARGS__} ) / 2]; \
mbed_official 59:2af474687369 282 } __attribute__ ((packed)) _##_name; \
mbed_official 59:2af474687369 283 EFM32_PACK_END() \
mbed_official 59:2af474687369 284 EFM32_ALIGN( 4 ) \
mbed_official 59:2af474687369 285 EFM32_PACK_START( 1 ) \
mbed_official 59:2af474687369 286 static const _##_name _name __attribute__ ((aligned(4)))= \
mbed_official 59:2af474687369 287 { \
mbed_official 59:2af474687369 288 .len = sizeof( _##_name ) - 2, \
mbed_official 59:2af474687369 289 .type = USB_STRING_DESCRIPTOR, \
mbed_official 59:2af474687369 290 .name = {__VA_ARGS__}, \
mbed_official 59:2af474687369 291 .name[ ( ( sizeof( _##_name ) - 2 ) / 2 ) - 1 ] = '\0' \
mbed_official 59:2af474687369 292 } \
mbed_official 59:2af474687369 293 EFM32_PACK_END()
mbed_official 59:2af474687369 294
mbed_official 59:2af474687369 295 /** Macro for creating USB compliant language string descriptors.
mbed_official 59:2af474687369 296 * @n Example: STATIC_CONST_STRING_DESC_LANGID( langID, 0x04, 0x09 );
mbed_official 59:2af474687369 297 */
mbed_official 59:2af474687369 298 #define STATIC_CONST_STRING_DESC_LANGID( _name, x, y ) \
mbed_official 59:2af474687369 299 EFM32_PACK_START( 1 ) \
mbed_official 59:2af474687369 300 typedef struct \
mbed_official 59:2af474687369 301 { \
mbed_official 59:2af474687369 302 uint8_t len; \
mbed_official 59:2af474687369 303 uint8_t type; \
mbed_official 59:2af474687369 304 uint8_t name[ 2 ]; \
mbed_official 59:2af474687369 305 } __attribute__ ((packed)) _##_name; \
mbed_official 59:2af474687369 306 EFM32_PACK_END() \
mbed_official 59:2af474687369 307 EFM32_ALIGN( 4 ) \
mbed_official 59:2af474687369 308 EFM32_PACK_START( 1 ) \
mbed_official 59:2af474687369 309 static const _##_name _name __attribute__ ((aligned(4)))= \
mbed_official 59:2af474687369 310 { \
mbed_official 59:2af474687369 311 .len = 4, \
mbed_official 59:2af474687369 312 .type = USB_STRING_DESCRIPTOR, \
mbed_official 59:2af474687369 313 .name = { y, x } \
mbed_official 59:2af474687369 314 } \
mbed_official 59:2af474687369 315 EFM32_PACK_END()
mbed_official 59:2af474687369 316
mbed_official 59:2af474687369 317 /** Macro for creating WORD (4 byte) aligned uint8_t array with size which
mbed_official 59:2af474687369 318 * is a multiple of WORD size.
mbed_official 59:2af474687369 319 * @n Example: @n UBUF( rxBuffer, 37 ); => uint8_t rxBuffer[ 40 ];
mbed_official 59:2af474687369 320 */
mbed_official 59:2af474687369 321 #if !defined(__GNUC__)
mbed_official 59:2af474687369 322 #define UBUF( x, y ) EFM32_ALIGN( 4 ) uint8_t x[((y)+3)&~3]
mbed_official 59:2af474687369 323 #define STATIC_UBUF( x, y ) EFM32_ALIGN( 4 ) static uint8_t x[((y)+3)&~3]
mbed_official 59:2af474687369 324 #else
mbed_official 59:2af474687369 325 #define UBUF( x, y ) uint8_t x[((y)+3)&~3] __attribute__ ((aligned(4)))
mbed_official 59:2af474687369 326
mbed_official 59:2af474687369 327 /** Macro for creating WORD (4 byte) aligned static uint8_t arrays with size which
mbed_official 59:2af474687369 328 * is a multiple of WORD size.
mbed_official 59:2af474687369 329 * @n Example: @n STATIC_UBUF( rxBuffer, 37 ); => static uint8_t rxBuffer[ 40 ];
mbed_official 59:2af474687369 330 */
mbed_official 59:2af474687369 331 #define STATIC_UBUF( x, y ) static uint8_t x[((y)+3)&~3] __attribute__ ((aligned(4)))
mbed_official 59:2af474687369 332 #endif
mbed_official 59:2af474687369 333
mbed_official 59:2af474687369 334
mbed_official 59:2af474687369 335 /** @brief USB transfer status enumerator. */
mbed_official 59:2af474687369 336 typedef enum
mbed_official 59:2af474687369 337 {
mbed_official 59:2af474687369 338 /* NOTE: Please keep in sync with table errMsg[] in em_usbhal.c */
mbed_official 59:2af474687369 339 USB_STATUS_OK = 0, /**< No errors detected. */
mbed_official 59:2af474687369 340 USB_STATUS_REQ_ERR = -1, /**< Setup request error. */
mbed_official 59:2af474687369 341 USB_STATUS_EP_BUSY = -2, /**< Endpoint is busy. */
mbed_official 59:2af474687369 342 USB_STATUS_REQ_UNHANDLED = -3, /**< Setup request not handled. */
mbed_official 59:2af474687369 343 USB_STATUS_ILLEGAL = -4, /**< Illegal operation attempted. */
mbed_official 59:2af474687369 344 USB_STATUS_EP_STALLED = -5, /**< Endpoint is stalled. */
mbed_official 59:2af474687369 345 USB_STATUS_EP_ABORTED = -6, /**< Endpoint transfer was aborted. */
mbed_official 59:2af474687369 346 USB_STATUS_EP_ERROR = -7, /**< Endpoint transfer error. */
mbed_official 59:2af474687369 347 USB_STATUS_EP_NAK = -8, /**< Endpoint NAK'ed transfer request. */
mbed_official 59:2af474687369 348 USB_STATUS_DEVICE_UNCONFIGURED = -9, /**< Device is unconfigured. */
mbed_official 59:2af474687369 349 USB_STATUS_DEVICE_SUSPENDED = -10, /**< Device is suspended. */
mbed_official 59:2af474687369 350 USB_STATUS_DEVICE_RESET = -11, /**< Device is/was reset. */
mbed_official 59:2af474687369 351 USB_STATUS_TIMEOUT = -12, /**< Transfer timeout. */
mbed_official 59:2af474687369 352 USB_STATUS_DEVICE_REMOVED = -13, /**< Device was removed. */
mbed_official 59:2af474687369 353 USB_STATUS_HC_BUSY = -14, /**< Host channel is busy. */
mbed_official 59:2af474687369 354 USB_STATUS_DEVICE_MALFUNCTION = -15, /**< Malfunctioning device attached. */
mbed_official 59:2af474687369 355 USB_STATUS_PORT_OVERCURRENT = -16, /**< VBUS shortcircuit/overcurrent failure. */
mbed_official 59:2af474687369 356 } USB_Status_TypeDef;
mbed_official 59:2af474687369 357 /** @} (end addtogroup USB_COMMON) */
mbed_official 59:2af474687369 358
mbed_official 59:2af474687369 359
mbed_official 59:2af474687369 360 #if defined( USB_DEVICE )
mbed_official 59:2af474687369 361 /***************************************************************************//**
mbed_official 59:2af474687369 362 * @addtogroup USB_DEVICE
mbed_official 59:2af474687369 363 * @brief USB DEVICE protocol stack, see @ref usb_device page for detailed documentation.
mbed_official 59:2af474687369 364 * @{
mbed_official 59:2af474687369 365 ******************************************************************************/
mbed_official 59:2af474687369 366
mbed_official 59:2af474687369 367 #define USB_PWRSAVE_MODE_OFF 0 /**< No energy saving mode selected. */
mbed_official 59:2af474687369 368 #define USB_PWRSAVE_MODE_ONSUSPEND 1 /**< Enter USB power-save mode on suspend. */
mbed_official 59:2af474687369 369 #define USB_PWRSAVE_MODE_ONVBUSOFF 2 /**< Enter USB power-save mode when not attached to host. */
mbed_official 59:2af474687369 370 #define USB_PWRSAVE_MODE_ENTEREM2 4 /**< Enter EM2 while in power-save mode. */
mbed_official 59:2af474687369 371
mbed_official 59:2af474687369 372 #define USB_USBC_32kHz_CLK_LFXO 0 /**< Use 32kHz LFXO clock while in powersave mode. */
mbed_official 59:2af474687369 373 #define USB_USBC_32kHz_CLK_LFRCO 1 /**< Use 32kHz LFRCO clock while in powersave mode. */
mbed_official 59:2af474687369 374
mbed_official 59:2af474687369 375 /** @brief USB device state enumerator. */
mbed_official 59:2af474687369 376 typedef enum
mbed_official 59:2af474687369 377 {
mbed_official 59:2af474687369 378 USBD_STATE_NONE = 0, /**< Device state is undefined/unknown. */
mbed_official 59:2af474687369 379 USBD_STATE_ATTACHED = 1, /**< Device state is ATTACHED. */
mbed_official 59:2af474687369 380 USBD_STATE_POWERED = 2, /**< Device state is POWERED. */
mbed_official 59:2af474687369 381 USBD_STATE_DEFAULT = 3, /**< Device state is DEFAULT. */
mbed_official 59:2af474687369 382 USBD_STATE_ADDRESSED = 4, /**< Device state is ADDRESSED. */
mbed_official 59:2af474687369 383 USBD_STATE_CONFIGURED = 5, /**< Device state is CONFIGURED. */
mbed_official 59:2af474687369 384 USBD_STATE_SUSPENDED = 6, /**< Device state is SUSPENDED. */
mbed_official 59:2af474687369 385 USBD_STATE_LASTMARKER = 7, /**< Device state enum end marker. */
mbed_official 59:2af474687369 386 } USBD_State_TypeDef;
mbed_official 59:2af474687369 387 /** @} (end addtogroup USB_DEVICE) */
mbed_official 59:2af474687369 388 #endif /* defined( USB_DEVICE ) */
mbed_official 59:2af474687369 389
mbed_official 59:2af474687369 390 /** @addtogroup USB_COMMON
mbed_official 59:2af474687369 391 * @{*/
mbed_official 59:2af474687369 392
mbed_official 59:2af474687369 393 /** @brief USB Setup request package. */
mbed_official 59:2af474687369 394 EFM32_PACK_START( 1 )
mbed_official 59:2af474687369 395 typedef struct
mbed_official 59:2af474687369 396 {
mbed_official 59:2af474687369 397 union
mbed_official 59:2af474687369 398 {
mbed_official 59:2af474687369 399 struct
mbed_official 59:2af474687369 400 {
mbed_official 59:2af474687369 401 union
mbed_official 59:2af474687369 402 {
mbed_official 59:2af474687369 403 struct
mbed_official 59:2af474687369 404 {
mbed_official 59:2af474687369 405 uint8_t Recipient : 5; /**< Request recipient (device, interface, endpoint or other).*/
mbed_official 59:2af474687369 406 uint8_t Type : 2; /**< Request type (standard, class or vendor). */
mbed_official 59:2af474687369 407 uint8_t Direction : 1; /**< Transfer direction of SETUP data phase. */
mbed_official 59:2af474687369 408 };
mbed_official 59:2af474687369 409 uint8_t bmRequestType; /**< Request characteristics. */
mbed_official 59:2af474687369 410 };
mbed_official 59:2af474687369 411 uint8_t bRequest; /**< Request code. */
mbed_official 59:2af474687369 412 uint16_t wValue; /**< Varies according to request. */
mbed_official 59:2af474687369 413 uint16_t wIndex; /**< Index or offset, varies according to request. */
mbed_official 59:2af474687369 414 uint16_t wLength; /**< Number of bytes to transfer if there is a data stage.*/
mbed_official 59:2af474687369 415 };
mbed_official 59:2af474687369 416 uint32_t dw[2];
mbed_official 59:2af474687369 417 };
mbed_official 59:2af474687369 418 } __attribute__ ((packed)) USB_Setup_TypeDef;
mbed_official 59:2af474687369 419 EFM32_PACK_END()
mbed_official 59:2af474687369 420
mbed_official 59:2af474687369 421
mbed_official 59:2af474687369 422 /** @brief USB Device Descriptor. */
mbed_official 59:2af474687369 423 EFM32_PACK_START( 1 )
mbed_official 59:2af474687369 424 typedef struct
mbed_official 59:2af474687369 425 {
mbed_official 59:2af474687369 426 uint8_t bLength; /**< Size of this descriptor in bytes */
mbed_official 59:2af474687369 427 uint8_t bDescriptorType; /**< Constant DEVICE Descriptor Type */
mbed_official 59:2af474687369 428 uint16_t bcdUSB; /**< USB Specification Release Number in Binary-Coded
mbed_official 59:2af474687369 429 Decimal */
mbed_official 59:2af474687369 430 uint8_t bDeviceClass; /**< Class code (assigned by the USB-IF) */
mbed_official 59:2af474687369 431 uint8_t bDeviceSubClass; /**< Subclass code (assigned by the USB-IF) */
mbed_official 59:2af474687369 432 uint8_t bDeviceProtocol; /**< Protocol code (assigned by the USB-IF) */
mbed_official 59:2af474687369 433 uint8_t bMaxPacketSize0; /**< Maximum packet size for endpoint zero */
mbed_official 59:2af474687369 434 uint16_t idVendor; /**< Vendor ID (assigned by the USB-IF) */
mbed_official 59:2af474687369 435 uint16_t idProduct; /**< Product ID (assigned by the manufacturer) */
mbed_official 59:2af474687369 436 uint16_t bcdDevice; /**< Device release number in binary-coded decimal */
mbed_official 59:2af474687369 437 uint8_t iManufacturer; /**< Index of string descriptor describing manufacturer*/
mbed_official 59:2af474687369 438 uint8_t iProduct; /**< Index of string descriptor describing product */
mbed_official 59:2af474687369 439 uint8_t iSerialNumber; /**< Index of string descriptor describing the device
mbed_official 59:2af474687369 440 serialnumber */
mbed_official 59:2af474687369 441 uint8_t bNumConfigurations; /**< Number of possible configurations */
mbed_official 59:2af474687369 442 } __attribute__ ((packed)) USB_DeviceDescriptor_TypeDef;
mbed_official 59:2af474687369 443 EFM32_PACK_END()
mbed_official 59:2af474687369 444
mbed_official 59:2af474687369 445
mbed_official 59:2af474687369 446 /** @brief USB Configuration Descriptor. */
mbed_official 59:2af474687369 447 EFM32_PACK_START( 1 )
mbed_official 59:2af474687369 448 typedef struct
mbed_official 59:2af474687369 449 {
mbed_official 59:2af474687369 450 uint8_t bLength; /**< Size of this descriptor in bytes */
mbed_official 59:2af474687369 451 uint8_t bDescriptorType; /**< Constant CONFIGURATION Descriptor Type */
mbed_official 59:2af474687369 452 uint16_t wTotalLength; /**< Total length of data returned for this
mbed_official 59:2af474687369 453 configuration. Includes the combined length of all
mbed_official 59:2af474687369 454 descriptors (configuration, interface, endpoint,
mbed_official 59:2af474687369 455 and class- or vendor-specific) returned for this
mbed_official 59:2af474687369 456 configuration. */
mbed_official 59:2af474687369 457 uint8_t bNumInterfaces; /**< Number of interfaces supported by this
mbed_official 59:2af474687369 458 configuration */
mbed_official 59:2af474687369 459 uint8_t bConfigurationValue; /**< Value to use as an argument to the
mbed_official 59:2af474687369 460 SetConfiguration request to select this
mbed_official 59:2af474687369 461 configuration. */
mbed_official 59:2af474687369 462 uint8_t iConfiguration; /**< Index of string descriptor describing this
mbed_official 59:2af474687369 463 configuration. */
mbed_official 59:2af474687369 464 uint8_t bmAttributes; /**< Configuration characteristics.
mbed_official 59:2af474687369 465 @n D7: Reserved (set to one)
mbed_official 59:2af474687369 466 @n D6: Self-powered
mbed_official 59:2af474687369 467 @n D5: Remote Wakeup
mbed_official 59:2af474687369 468 @n D4...0: Reserved (reset to zero) */
mbed_official 59:2af474687369 469 uint8_t bMaxPower; /**< Maximum power consumption of the USB device, unit
mbed_official 59:2af474687369 470 is 2mA per LSB */
mbed_official 59:2af474687369 471 } __attribute__ ((packed)) USB_ConfigurationDescriptor_TypeDef;
mbed_official 59:2af474687369 472 EFM32_PACK_END()
mbed_official 59:2af474687369 473
mbed_official 59:2af474687369 474
mbed_official 59:2af474687369 475 /** @brief USB Interface Descriptor. */
mbed_official 59:2af474687369 476 EFM32_PACK_START( 1 )
mbed_official 59:2af474687369 477 typedef struct
mbed_official 59:2af474687369 478 {
mbed_official 59:2af474687369 479 uint8_t bLength; /**< Size of this descriptor in bytes. */
mbed_official 59:2af474687369 480 uint8_t bDescriptorType; /**< Constant INTERFACE Descriptor Type. */
mbed_official 59:2af474687369 481 uint8_t bInterfaceNumber; /**< Number of this interface. Zero-based value
mbed_official 59:2af474687369 482 identifying the index in the array of concurrent
mbed_official 59:2af474687369 483 interfaces supported by this configuration. */
mbed_official 59:2af474687369 484 uint8_t bAlternateSetting; /**< Value used to select this alternate setting for
mbed_official 59:2af474687369 485 the interface identified in the prior field. */
mbed_official 59:2af474687369 486 uint8_t bNumEndpoints; /**< Number of endpoints used by this interface
mbed_official 59:2af474687369 487 (excluding endpoint zero). If this value is zero,
mbed_official 59:2af474687369 488 this interface only uses the Default Control Pipe.*/
mbed_official 59:2af474687369 489 uint8_t bInterfaceClass; /**< Class code (assigned by the USB-IF). A value
mbed_official 59:2af474687369 490 of zero is reserved for future standardization. If
mbed_official 59:2af474687369 491 this field is set to FFH, the interface class is
mbed_official 59:2af474687369 492 vendor-specific. All other values are reserved for
mbed_official 59:2af474687369 493 assignment by the USB-IF. */
mbed_official 59:2af474687369 494 uint8_t bInterfaceSubClass; /**< Subclass code (assigned by the USB-IF). These codes
mbed_official 59:2af474687369 495 are qualified by the value of the bInterfaceClass
mbed_official 59:2af474687369 496 field. If the bInterfaceClass field is reset to
mbed_official 59:2af474687369 497 zero, this field must also be reset to zero. If
mbed_official 59:2af474687369 498 the bInterfaceClass field is not set to FFH, all
mbed_official 59:2af474687369 499 values are reserved forassignment by the USB-IF. */
mbed_official 59:2af474687369 500 uint8_t bInterfaceProtocol; /**< Protocol code (assigned by the USB). These codes
mbed_official 59:2af474687369 501 are qualified by the value of the bInterfaceClass
mbed_official 59:2af474687369 502 and the bInterfaceSubClass fields. If an interface
mbed_official 59:2af474687369 503 supports class-specific requests, this code
mbed_official 59:2af474687369 504 identifies the protocols that the device uses as
mbed_official 59:2af474687369 505 defined by the specification of the device class.
mbed_official 59:2af474687369 506 If this field is reset to zero, the device does
mbed_official 59:2af474687369 507 not use a class-specific protocol on this
mbed_official 59:2af474687369 508 interface. If this field is set to FFH, the device
mbed_official 59:2af474687369 509 uses a vendor-specific protocol for this interface*/
mbed_official 59:2af474687369 510 uint8_t iInterface; /**< Index of string descriptor describing this
mbed_official 59:2af474687369 511 interface. */
mbed_official 59:2af474687369 512 } __attribute__ ((packed)) USB_InterfaceDescriptor_TypeDef;
mbed_official 59:2af474687369 513 EFM32_PACK_END()
mbed_official 59:2af474687369 514
mbed_official 59:2af474687369 515
mbed_official 59:2af474687369 516 /** @brief USB Endpoint Descriptor. */
mbed_official 59:2af474687369 517 EFM32_PACK_START( 1 )
mbed_official 59:2af474687369 518 typedef struct
mbed_official 59:2af474687369 519 {
mbed_official 59:2af474687369 520 uint8_t bLength; /**< Size of this descriptor in bytes */
mbed_official 59:2af474687369 521 uint8_t bDescriptorType; /**< Constant ENDPOINT Descriptor Type */
mbed_official 59:2af474687369 522 uint8_t bEndpointAddress; /**< The address of the endpoint */
mbed_official 59:2af474687369 523 uint8_t bmAttributes; /**< This field describes the endpoint attributes */
mbed_official 59:2af474687369 524 uint16_t wMaxPacketSize; /**< Maximum packet size for the endpoint */
mbed_official 59:2af474687369 525 uint8_t bInterval; /**< Interval for polling EP for data transfers */
mbed_official 59:2af474687369 526 } __attribute__ ((packed)) USB_EndpointDescriptor_TypeDef;
mbed_official 59:2af474687369 527 EFM32_PACK_END()
mbed_official 59:2af474687369 528
mbed_official 59:2af474687369 529
mbed_official 59:2af474687369 530 /** @brief USB String Descriptor. */
mbed_official 59:2af474687369 531 EFM32_PACK_START( 1 )
mbed_official 59:2af474687369 532 typedef struct
mbed_official 59:2af474687369 533 {
mbed_official 59:2af474687369 534 uint8_t len; /**< Size of this descriptor in bytes. */
mbed_official 59:2af474687369 535 uint8_t type; /**< Constant STRING Descriptor Type. */
mbed_official 59:2af474687369 536 char16_t name[]; /**< The string encoded with UTF-16LE UNICODE charset. */
mbed_official 59:2af474687369 537 } __attribute__ ((packed)) USB_StringDescriptor_TypeDef;
mbed_official 59:2af474687369 538 EFM32_PACK_END()
mbed_official 59:2af474687369 539
mbed_official 59:2af474687369 540 /** @} (end addtogroup USB_COMMON) */
mbed_official 59:2af474687369 541
mbed_official 59:2af474687369 542 /*** -------------------- Serial port debug configuration ---------------- ***/
mbed_official 59:2af474687369 543
mbed_official 59:2af474687369 544 #if defined( DOXY_DOC_ONLY )
mbed_official 59:2af474687369 545 /** @addtogroup USB_COMMON
mbed_official 59:2af474687369 546 * @{*/
mbed_official 59:2af474687369 547
mbed_official 59:2af474687369 548 /***************************************************************************//**
mbed_official 59:2af474687369 549 * @brief
mbed_official 59:2af474687369 550 * Transmit a single char on the debug serial port.
mbed_official 59:2af474687369 551 *
mbed_official 59:2af474687369 552 * @note
mbed_official 59:2af474687369 553 * This function is enabled with \#define DEBUG_USB_API when configuring the
mbed_official 59:2af474687369 554 * protocol stack in "usbconfig.h".
mbed_official 59:2af474687369 555 * This is convenient when debugging code, no need to remove use of this
mbed_official 59:2af474687369 556 * function when debugging has completed.
mbed_official 59:2af474687369 557 *
mbed_official 59:2af474687369 558 * @param[in] c
mbed_official 59:2af474687369 559 * Char to transmit.
mbed_official 59:2af474687369 560 *
mbed_official 59:2af474687369 561 * @return
mbed_official 59:2af474687369 562 * The char transmitted.
mbed_official 59:2af474687369 563 ******************************************************************************/
mbed_official 59:2af474687369 564 int USB_PUTCHAR( char c );
mbed_official 59:2af474687369 565
mbed_official 59:2af474687369 566 /***************************************************************************//**
mbed_official 59:2af474687369 567 * @brief
mbed_official 59:2af474687369 568 * Transmit a zero terminated string on the debug serial port.
mbed_official 59:2af474687369 569 *
mbed_official 59:2af474687369 570 * @note
mbed_official 59:2af474687369 571 * This function is enabled with \#define DEBUG_USB_API when configuring the
mbed_official 59:2af474687369 572 * protocol stack in "usbconfig.h".
mbed_official 59:2af474687369 573 * This is convenient when debugging code, no need to remove use of this
mbed_official 59:2af474687369 574 * function when debugging has completed.
mbed_official 59:2af474687369 575 *
mbed_official 59:2af474687369 576 * @param[in] p
mbed_official 59:2af474687369 577 * Pointer to string to transmit.
mbed_official 59:2af474687369 578 ******************************************************************************/
mbed_official 59:2af474687369 579 void USB_PUTS( const char *p );
mbed_official 59:2af474687369 580
mbed_official 59:2af474687369 581 /***************************************************************************//**
mbed_official 59:2af474687369 582 * @brief
mbed_official 59:2af474687369 583 * Transmit "printf" formated data on the debug serial port.
mbed_official 59:2af474687369 584 *
mbed_official 59:2af474687369 585 * @note
mbed_official 59:2af474687369 586 * This function is enabled with \#define USB_USE_PRINTF when configuring the
mbed_official 59:2af474687369 587 * protocol stack in "usbconfig.h".
mbed_official 59:2af474687369 588 * This is convenient when debugging code, no need to remove use of this
mbed_official 59:2af474687369 589 * function when debugging has completed.
mbed_official 59:2af474687369 590 *
mbed_official 59:2af474687369 591 * @param[in] format
mbed_official 59:2af474687369 592 * Format string (as in printf). No floating point format support.
mbed_official 59:2af474687369 593 ******************************************************************************/
mbed_official 59:2af474687369 594 int USB_PRINTF( const char *format, ... );
mbed_official 59:2af474687369 595
mbed_official 59:2af474687369 596 /** @} (end addtogroup USB_COMMON) */
mbed_official 59:2af474687369 597 #endif /* defined( DOXY_DOC_ONLY ) */
mbed_official 59:2af474687369 598
mbed_official 59:2af474687369 599 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
mbed_official 59:2af474687369 600
mbed_official 59:2af474687369 601 /* Hardware constraint, do not change. */
mbed_official 59:2af474687369 602 #define MAX_NUM_HOSTCHANNELS 14
mbed_official 59:2af474687369 603
mbed_official 59:2af474687369 604 /* The DMA engine use one FIFO ram word for each host channel. */
mbed_official 59:2af474687369 605 #define MAX_HOST_FIFO_SIZE_INWORDS (512-MAX_NUM_HOSTCHANNELS)/*Unit is 4 bytes*/
mbed_official 59:2af474687369 606
mbed_official 59:2af474687369 607 #if defined ( USER_PUTCHAR )
mbed_official 59:2af474687369 608 void USB_Puts( const char *p );
mbed_official 59:2af474687369 609 #define USB_PUTS( s ) USB_Puts( s )
mbed_official 59:2af474687369 610 #define USB_PUTCHAR( c ) USER_PUTCHAR( c )
mbed_official 59:2af474687369 611 #else
mbed_official 59:2af474687369 612 #define USB_PUTS( s )
mbed_official 59:2af474687369 613 #define USB_PUTCHAR( c )
mbed_official 59:2af474687369 614 #endif
mbed_official 59:2af474687369 615
mbed_official 59:2af474687369 616 #if defined( USB_USE_PRINTF )
mbed_official 59:2af474687369 617 /* Use a printf which don't support floating point formatting */
mbed_official 59:2af474687369 618 #if defined(__ICCARM__) || defined (__CC_ARM) || defined (__CROSSWORKS_ARM)
mbed_official 59:2af474687369 619 #define USB_PRINTF printf
mbed_official 59:2af474687369 620 #else
mbed_official 59:2af474687369 621 #define USB_PRINTF iprintf
mbed_official 59:2af474687369 622 #endif
mbed_official 59:2af474687369 623 #else
mbed_official 59:2af474687369 624 #define USB_PRINTF(...)
mbed_official 59:2af474687369 625 #endif /* defined( USB_USE_PRINTF ) */
mbed_official 59:2af474687369 626
mbed_official 59:2af474687369 627 #if defined( DEBUG_USB_API )
mbed_official 59:2af474687369 628 #define DEBUG_USB_API_PUTS( s ) USB_PUTS( s )
mbed_official 59:2af474687369 629 #define DEBUG_USB_API_PUTCHAR( c ) USB_PUTCHAR( c )
mbed_official 59:2af474687369 630 #else
mbed_official 59:2af474687369 631 #define DEBUG_USB_API_PUTS( s )
mbed_official 59:2af474687369 632 #define DEBUG_USB_API_PUTCHAR( c )
mbed_official 59:2af474687369 633 #endif /* defined( DEBUG_USB_API ) */
mbed_official 59:2af474687369 634
mbed_official 59:2af474687369 635 /** @endcond */
mbed_official 59:2af474687369 636
mbed_official 59:2af474687369 637 /*** -------------------- Common API definitions ------------------------- ***/
mbed_official 59:2af474687369 638
mbed_official 59:2af474687369 639 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
mbed_official 59:2af474687369 640
mbed_official 59:2af474687369 641 #if defined( USB_HOST )
mbed_official 59:2af474687369 642 #if defined( NUM_APP_TIMERS )
mbed_official 59:2af474687369 643 #define NUM_QTIMERS ( NUM_HC_USED + 2 + NUM_APP_TIMERS + 1 )
mbed_official 59:2af474687369 644 #else
mbed_official 59:2af474687369 645 #define NUM_QTIMERS ( NUM_HC_USED + 2 + 1 )
mbed_official 59:2af474687369 646 #endif
mbed_official 59:2af474687369 647 /* + 2 for default ctrl. host ch. 0 & 1, + 1 for host port timer */
mbed_official 59:2af474687369 648 #else
mbed_official 59:2af474687369 649 #if defined( NUM_APP_TIMERS )
mbed_official 59:2af474687369 650 #define NUM_QTIMERS ( NUM_APP_TIMERS )
mbed_official 59:2af474687369 651 #else
mbed_official 59:2af474687369 652 #define NUM_QTIMERS 0
mbed_official 59:2af474687369 653 #endif
mbed_official 59:2af474687369 654 #endif /* defined( USB_HOST ) */
mbed_official 59:2af474687369 655 /** @endcond */
mbed_official 59:2af474687369 656
mbed_official 59:2af474687369 657 /** @addtogroup USB_COMMON
mbed_official 59:2af474687369 658 * @{*/
mbed_official 59:2af474687369 659
mbed_official 59:2af474687369 660 /***************************************************************************//**
mbed_official 59:2af474687369 661 * @brief
mbed_official 59:2af474687369 662 * USB transfer callback function.
mbed_official 59:2af474687369 663 *
mbed_official 59:2af474687369 664 * @details
mbed_official 59:2af474687369 665 * The callback function is called when a transfer has completed. An application
mbed_official 59:2af474687369 666 * should check the status, xferred and optionally the remaining parameters
mbed_official 59:2af474687369 667 * before deciding if the transfer is usable. In the case where the transfer
mbed_official 59:2af474687369 668 * is part of a control request data stage, the callback function should
mbed_official 59:2af474687369 669 * return an appropriate @ref USB_Status_TypeDef status.
mbed_official 59:2af474687369 670 *
mbed_official 59:2af474687369 671 * @param[in] status
mbed_official 59:2af474687369 672 * The transfer status. See @ref USB_Status_TypeDef.
mbed_official 59:2af474687369 673 *
mbed_official 59:2af474687369 674 * @param[in] xferred
mbed_official 59:2af474687369 675 * Number of bytes actually transferred.
mbed_official 59:2af474687369 676 *
mbed_official 59:2af474687369 677 * @param[in] remaining
mbed_official 59:2af474687369 678 * Number of bytes not transferred.
mbed_official 59:2af474687369 679 *
mbed_official 59:2af474687369 680 * @return
mbed_official 59:2af474687369 681 * @ref USB_STATUS_OK on success, else an appropriate error code.
mbed_official 59:2af474687369 682 ******************************************************************************/
mbed_official 59:2af474687369 683 typedef int (*USB_XferCompleteCb_TypeDef)( USB_Status_TypeDef status, uint32_t xferred, uint32_t remaining );
mbed_official 59:2af474687369 684
mbed_official 59:2af474687369 685 /***************************************************************************//**
mbed_official 59:2af474687369 686 * @brief
mbed_official 59:2af474687369 687 * USBTIMER callback function.
mbed_official 59:2af474687369 688 *
mbed_official 59:2af474687369 689 * @details
mbed_official 59:2af474687369 690 * The callback function is called when an USBTIMER has expired. The callback
mbed_official 59:2af474687369 691 * is done with interrupts disabled.
mbed_official 59:2af474687369 692 ******************************************************************************/
mbed_official 59:2af474687369 693 typedef void (*USBTIMER_Callback_TypeDef)( void );
mbed_official 59:2af474687369 694
mbed_official 59:2af474687369 695 char *USB_GetErrorMsgString( int error );
mbed_official 59:2af474687369 696
mbed_official 59:2af474687369 697 #if defined( USB_USE_PRINTF )
mbed_official 59:2af474687369 698 void USB_PrintErrorMsgString( char *pre, int error );
mbed_official 59:2af474687369 699 #else
mbed_official 59:2af474687369 700 #define USB_PrintErrorMsgString( pre, error )
mbed_official 59:2af474687369 701 #endif
mbed_official 59:2af474687369 702
mbed_official 59:2af474687369 703 void USBTIMER_DelayMs( uint32_t msec );
mbed_official 59:2af474687369 704 void USBTIMER_DelayUs( uint32_t usec );
mbed_official 59:2af474687369 705 void USBTIMER_Init( void );
mbed_official 59:2af474687369 706
mbed_official 59:2af474687369 707 #if ( NUM_QTIMERS > 0 )
mbed_official 59:2af474687369 708 void USBTIMER_Start( uint32_t id, uint32_t timeout, USBTIMER_Callback_TypeDef callback );
mbed_official 59:2af474687369 709 void USBTIMER_Stop( uint32_t id );
mbed_official 59:2af474687369 710 #endif /* ( NUM_QTIMERS > 0 ) */
mbed_official 59:2af474687369 711 /** @} (end addtogroup USB_COMMON) */
mbed_official 59:2af474687369 712
mbed_official 59:2af474687369 713 #if defined( USB_DEVICE )
mbed_official 59:2af474687369 714 /** @addtogroup USB_DEVICE
mbed_official 59:2af474687369 715 * @{*/
mbed_official 59:2af474687369 716 /*** -------------------- DEVICE mode API definitions -------------------- ***/
mbed_official 59:2af474687369 717
mbed_official 59:2af474687369 718 /***************************************************************************//**
mbed_official 59:2af474687369 719 * @brief
mbed_official 59:2af474687369 720 * USB Reset callback function.
mbed_official 59:2af474687369 721 * @details
mbed_official 59:2af474687369 722 * Called whenever USB reset signalling is detected on the USB port.
mbed_official 59:2af474687369 723 ******************************************************************************/
mbed_official 59:2af474687369 724 typedef void (*USBD_UsbResetCb_TypeDef)( void );
mbed_official 59:2af474687369 725
mbed_official 59:2af474687369 726 /***************************************************************************//**
mbed_official 59:2af474687369 727 * @brief
mbed_official 59:2af474687369 728 * USB Start Of Frame (SOF) interrupt callback function.
mbed_official 59:2af474687369 729 *
mbed_official 59:2af474687369 730 * @details
mbed_official 59:2af474687369 731 * Called at each SOF interrupt (if enabled),
mbed_official 59:2af474687369 732 *
mbed_official 59:2af474687369 733 * @param[in] sofNr
mbed_official 59:2af474687369 734 * Current frame number. The value rolls over to 0 after 16383 (0x3FFF).
mbed_official 59:2af474687369 735 ******************************************************************************/
mbed_official 59:2af474687369 736 typedef void (*USBD_SofIntCb_TypeDef)( uint16_t sofNr );
mbed_official 59:2af474687369 737
mbed_official 59:2af474687369 738 /***************************************************************************//**
mbed_official 59:2af474687369 739 * @brief
mbed_official 59:2af474687369 740 * USB State change callback function.
mbed_official 59:2af474687369 741 *
mbed_official 59:2af474687369 742 * @details
mbed_official 59:2af474687369 743 * Called whenever the device change state.
mbed_official 59:2af474687369 744 *
mbed_official 59:2af474687369 745 * @param[in] oldState
mbed_official 59:2af474687369 746 * The device USB state just leaved. See @ref USBD_State_TypeDef.
mbed_official 59:2af474687369 747 *
mbed_official 59:2af474687369 748 * @param[in] newState
mbed_official 59:2af474687369 749 * New (the current) USB device state. See @ref USBD_State_TypeDef.
mbed_official 59:2af474687369 750 ******************************************************************************/
mbed_official 59:2af474687369 751 typedef void (*USBD_DeviceStateChangeCb_TypeDef)( USBD_State_TypeDef oldState, USBD_State_TypeDef newState );
mbed_official 59:2af474687369 752
mbed_official 59:2af474687369 753 /***************************************************************************//**
mbed_official 59:2af474687369 754 * @brief
mbed_official 59:2af474687369 755 * USB power mode callback function.
mbed_official 59:2af474687369 756 *
mbed_official 59:2af474687369 757 * @details
mbed_official 59:2af474687369 758 * Called whenever the device stack needs to query if the device is currently
mbed_official 59:2af474687369 759 * self- or bus-powered. Typically when host has issued an @ref GET_STATUS
mbed_official 59:2af474687369 760 * setup command.
mbed_official 59:2af474687369 761 *
mbed_official 59:2af474687369 762 * @return
mbed_official 59:2af474687369 763 * True if self-powered, false otherwise.
mbed_official 59:2af474687369 764 ******************************************************************************/
mbed_official 59:2af474687369 765 typedef bool (*USBD_IsSelfPoweredCb_TypeDef)( void );
mbed_official 59:2af474687369 766
mbed_official 59:2af474687369 767 /***************************************************************************//**
mbed_official 59:2af474687369 768 * @brief
mbed_official 59:2af474687369 769 * USB setup request callback function.
mbed_official 59:2af474687369 770 *
mbed_official 59:2af474687369 771 * @details
mbed_official 59:2af474687369 772 * Called on each setup request received from host. This gives the application a
mbed_official 59:2af474687369 773 * possibility to extend or override standard requests, and to implement class
mbed_official 59:2af474687369 774 * or vendor specific requests. Return @ref USB_STATUS_OK if the request is
mbed_official 59:2af474687369 775 * handled, return @ref USB_STATUS_REQ_ERR if it is an illegal request or
mbed_official 59:2af474687369 776 * return @ref USB_STATUS_REQ_UNHANDLED to pass the request on to the default
mbed_official 59:2af474687369 777 * request handler.
mbed_official 59:2af474687369 778 *
mbed_official 59:2af474687369 779 * @param[in] setup
mbed_official 59:2af474687369 780 * Pointer to an USB setup packet. See @ref USB_Setup_TypeDef.
mbed_official 59:2af474687369 781 *
mbed_official 59:2af474687369 782 * @return
mbed_official 59:2af474687369 783 * An appropriate status/error code. See @ref USB_Status_TypeDef.
mbed_official 59:2af474687369 784 ******************************************************************************/
mbed_official 59:2af474687369 785 typedef int (*USBD_SetupCmdCb_TypeDef)( const USB_Setup_TypeDef *setup );
mbed_official 59:2af474687369 786
mbed_official 59:2af474687369 787 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
mbed_official 59:2af474687369 788 struct USBD_Callbacks_TypeDef;
mbed_official 59:2af474687369 789 typedef struct USBD_Callbacks_TypeDef const *USBD_Callbacks_TypeDef_Pointer;
mbed_official 59:2af474687369 790 /** @endcond */
mbed_official 59:2af474687369 791
mbed_official 59:2af474687369 792
mbed_official 59:2af474687369 793 /** @brief USB Device stack initialization structure.
mbed_official 59:2af474687369 794 * @details This structure is passed to @ref USBD_Init() when starting up
mbed_official 59:2af474687369 795 * the device. */
mbed_official 59:2af474687369 796 typedef struct
mbed_official 59:2af474687369 797 {
mbed_official 59:2af474687369 798 const USB_DeviceDescriptor_TypeDef *deviceDescriptor; /**< Pointer to a device descriptor. */
mbed_official 59:2af474687369 799 const uint8_t *configDescriptor; /**< Pointer to a configuration descriptor. */
mbed_official 59:2af474687369 800 const void * const *stringDescriptors; /**< Pointer to an array of string descriptor pointers.*/
mbed_official 59:2af474687369 801 const uint8_t numberOfStrings; /**< Number of strings in string descriptor array. */
mbed_official 59:2af474687369 802 const uint8_t *bufferingMultiplier; /**< Pointer to an array defining the size of the
mbed_official 59:2af474687369 803 endpoint buffers. The size is given in
mbed_official 59:2af474687369 804 multiples of endpoint size. Generally a value
mbed_official 59:2af474687369 805 of 1 (single) or 2 (double) buffering should be
mbed_official 59:2af474687369 806 used. */
mbed_official 59:2af474687369 807 USBD_Callbacks_TypeDef_Pointer callbacks; /**< Pointer to struct with callbacks
mbed_official 59:2af474687369 808 (@ref USBD_Callbacks_TypeDef). These callbacks
mbed_official 59:2af474687369 809 are used by the device stack to signal events
mbed_official 59:2af474687369 810 to or query the application. */
mbed_official 59:2af474687369 811 const uint32_t reserved; /**< Reserved for future use. */
mbed_official 59:2af474687369 812 } USBD_Init_TypeDef;
mbed_official 59:2af474687369 813
mbed_official 59:2af474687369 814
mbed_official 59:2af474687369 815 /** @brief USB Device stack callback structure.
mbed_official 59:2af474687369 816 * @details Callback functions used by the device stack to signal events or
mbed_official 59:2af474687369 817 * query status to/from the application. See @ref USBD_Init_TypeDef. Assign
mbed_official 59:2af474687369 818 * members to NULL if your application don't need a specific callback. */
mbed_official 59:2af474687369 819 typedef struct USBD_Callbacks_TypeDef
mbed_official 59:2af474687369 820 {
mbed_official 59:2af474687369 821 const USBD_UsbResetCb_TypeDef usbReset; /**< Called whenever USB reset signalling is detected
mbed_official 59:2af474687369 822 on the USB port. */
mbed_official 59:2af474687369 823 const USBD_DeviceStateChangeCb_TypeDef usbStateChange; /**< Called whenever the device change state. */
mbed_official 59:2af474687369 824 const USBD_SetupCmdCb_TypeDef setupCmd; /**< Called on each setup request received from host.*/
mbed_official 59:2af474687369 825 const USBD_IsSelfPoweredCb_TypeDef isSelfPowered; /**< Called whenever the device stack needs to query
mbed_official 59:2af474687369 826 if the device is currently self- or bus-powered.
mbed_official 59:2af474687369 827 Applies to devices which can operate in both modes.*/
mbed_official 59:2af474687369 828 const USBD_SofIntCb_TypeDef sofInt; /**< Called at each SOF interrupt. If NULL, the device
mbed_official 59:2af474687369 829 stack will not enable the SOF interrupt. */
mbed_official 59:2af474687369 830 } USBD_Callbacks_TypeDef;
mbed_official 59:2af474687369 831
mbed_official 59:2af474687369 832
mbed_official 59:2af474687369 833 /*** -------------------- DEVICE mode API -------------------------------- ***/
mbed_official 59:2af474687369 834
mbed_official 59:2af474687369 835 void USBD_AbortAllTransfers( void );
mbed_official 59:2af474687369 836 int USBD_AbortTransfer( int epAddr );
mbed_official 59:2af474687369 837 void USBD_Connect( void );
mbed_official 59:2af474687369 838 void USBD_Disconnect( void );
mbed_official 59:2af474687369 839 bool USBD_EpIsBusy( int epAddr );
mbed_official 59:2af474687369 840 USBD_State_TypeDef USBD_GetUsbState( void );
mbed_official 59:2af474687369 841 const char * USBD_GetUsbStateName( USBD_State_TypeDef state );
mbed_official 59:2af474687369 842 int USBD_Init( const USBD_Init_TypeDef *p );
mbed_official 59:2af474687369 843 int USBD_Read( int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback );
mbed_official 59:2af474687369 844 int USBD_RemoteWakeup( void );
mbed_official 59:2af474687369 845 bool USBD_SafeToEnterEM2( void );
mbed_official 59:2af474687369 846 int USBD_StallEp( int epAddr );
mbed_official 59:2af474687369 847 void USBD_Stop( void );
mbed_official 59:2af474687369 848 int USBD_UnStallEp( int epAddr );
mbed_official 59:2af474687369 849 int USBD_Write( int epAddr, void *data, int byteCount, USB_XferCompleteCb_TypeDef callback );
mbed_official 59:2af474687369 850
mbed_official 59:2af474687369 851 #ifdef __MBED__
mbed_official 59:2af474687369 852 int USBD_SetAddress( uint8_t addr );
mbed_official 59:2af474687369 853 int USBD_AddEndpoint( int epAddr, int transferType, int maxPacketSize, int bufferMult );
mbed_official 59:2af474687369 854 int USBD_EpIsStalled( int epAddr );
mbed_official 59:2af474687369 855 void USBD_StallEp0( void );
mbed_official 59:2af474687369 856 #endif
mbed_official 59:2af474687369 857
mbed_official 59:2af474687369 858 /** @} (end addtogroup USB_DEVICE) */
mbed_official 59:2af474687369 859 #endif /* defined( USB_DEVICE ) */
mbed_official 59:2af474687369 860
mbed_official 59:2af474687369 861
mbed_official 59:2af474687369 862 #if defined( USB_HOST )
mbed_official 59:2af474687369 863 /***************************************************************************//**
mbed_official 59:2af474687369 864 * @addtogroup USB_HOST
mbed_official 59:2af474687369 865 * @brief USB HOST protocol stack, see @ref usb_host page for detailed documentation.
mbed_official 59:2af474687369 866 * @{
mbed_official 59:2af474687369 867 ******************************************************************************/
mbed_official 59:2af474687369 868 /*** -------------------- HOST mode API definitions ---------------------- ***/
mbed_official 59:2af474687369 869
mbed_official 59:2af474687369 870 #define USB_VBUSOVRCUR_PORT_NONE -1 /**< No overcurrent flag functionality. */
mbed_official 59:2af474687369 871 #define USB_VBUSOVRCUR_POLARITY_LOW 0 /**< Overcurrent flag pin polarity is low. */
mbed_official 59:2af474687369 872 #define USB_VBUSOVRCUR_POLARITY_HIGH 1 /**< Overcurrent flag pin polarity is high. */
mbed_official 59:2af474687369 873
mbed_official 59:2af474687369 874 /** USB HOST endpoint status enumerator. */
mbed_official 59:2af474687369 875 typedef enum
mbed_official 59:2af474687369 876 {
mbed_official 59:2af474687369 877 H_EP_IDLE = 0, /**< The endpoint is idle. */
mbed_official 59:2af474687369 878 H_EP_SETUP = 1, /**< The endpoint is in SETUP stage. */
mbed_official 59:2af474687369 879 H_EP_DATA_IN = 2, /**< The endpoint is in DATA IN stage. */
mbed_official 59:2af474687369 880 H_EP_DATA_OUT = 3, /**< The endpoint is in DATA OUT stage. */
mbed_official 59:2af474687369 881 H_EP_STATUS_IN = 4, /**< The endpoint is in STATUS IN stage. */
mbed_official 59:2af474687369 882 H_EP_STATUS_OUT = 5, /**< The endpoint is in STATUS OUT stage. */
mbed_official 59:2af474687369 883 } USBH_EpState_TypeDef;
mbed_official 59:2af474687369 884
mbed_official 59:2af474687369 885
mbed_official 59:2af474687369 886 /** @brief USB HOST endpoint status data.
mbed_official 59:2af474687369 887 * @details A host application should not manipulate the contents of
mbed_official 59:2af474687369 888 * this struct. */
mbed_official 59:2af474687369 889 typedef struct
mbed_official 59:2af474687369 890 {
mbed_official 59:2af474687369 891 USB_Setup_TypeDef setup; /**< A SETUP package. */
mbed_official 59:2af474687369 892 uint8_t setupErrCnt; /**< Error counter for SETUP transfers. */
mbed_official 59:2af474687369 893 USB_EndpointDescriptor_TypeDef epDesc; /**< Endpoint descriptor. */
mbed_official 59:2af474687369 894 struct USBH_Device_TypeDef *parentDevice; /**< The device the endpoint belongs to. */
mbed_official 59:2af474687369 895 uint8_t type; /**< Endpoint type. */
mbed_official 59:2af474687369 896 uint16_t packetSize; /**< Packet size, current transfer. */
mbed_official 59:2af474687369 897 uint8_t hcOut; /**< Host channel number assigned for OUT transfers. */
mbed_official 59:2af474687369 898 uint8_t hcIn; /**< Host channel number assigned for IN transfers. */
mbed_official 59:2af474687369 899 bool in; /**< Endpoint direction. */
mbed_official 59:2af474687369 900 uint8_t toggle; /**< Endpoint data toggle. */
mbed_official 59:2af474687369 901 USBH_EpState_TypeDef state; /**< Endpoint state. */
mbed_official 59:2af474687369 902 uint8_t addr; /**< Endpoint address. */
mbed_official 59:2af474687369 903 uint8_t *buf; /**< Transfer buffer. */
mbed_official 59:2af474687369 904 volatile bool xferCompleted; /**< Transfer completion flag. */
mbed_official 59:2af474687369 905 USB_Status_TypeDef xferStatus; /**< Transfer status. */
mbed_official 59:2af474687369 906 USB_XferCompleteCb_TypeDef xferCompleteCb; /**< Transfer completion callback function. */
mbed_official 59:2af474687369 907 uint32_t xferred; /**< Number of bytes transferred. */
mbed_official 59:2af474687369 908 uint32_t remaining; /**< Number of bytes remaining. */
mbed_official 59:2af474687369 909 uint32_t timeout; /**< Transfer timeout. */
mbed_official 59:2af474687369 910 } USBH_Ep_TypeDef;
mbed_official 59:2af474687369 911
mbed_official 59:2af474687369 912
mbed_official 59:2af474687369 913 /** @brief USB HOST device definition.
mbed_official 59:2af474687369 914 * @details A host application should not manipulate the contents of
mbed_official 59:2af474687369 915 * this struct. */
mbed_official 59:2af474687369 916 typedef struct USBH_Device_TypeDef
mbed_official 59:2af474687369 917 {
mbed_official 59:2af474687369 918 USB_DeviceDescriptor_TypeDef devDesc; /**< The device device descriptor. */
mbed_official 59:2af474687369 919 USB_ConfigurationDescriptor_TypeDef confDesc; /**< The device configuration descriptor. */
mbed_official 59:2af474687369 920 USB_InterfaceDescriptor_TypeDef itfDesc; /**< The device interface descriptor. */
mbed_official 59:2af474687369 921 USBH_Ep_TypeDef ep0; /**< Endpoint 0 status data. */
mbed_official 59:2af474687369 922 USBH_Ep_TypeDef *ep; /**< Array of endpoint status data. */
mbed_official 59:2af474687369 923 int numEp; /**< Number of endpoints. */
mbed_official 59:2af474687369 924 uint8_t addr; /**< The device address. */
mbed_official 59:2af474687369 925 uint8_t speed; /**< The device speed (low or full speed). */
mbed_official 59:2af474687369 926 } USBH_Device_TypeDef;
mbed_official 59:2af474687369 927
mbed_official 59:2af474687369 928
mbed_official 59:2af474687369 929 /** @brief USB Host stack initialization structure.
mbed_official 59:2af474687369 930 * @details This structure is passed to @ref USBH_Init() when starting up the
mbed_official 59:2af474687369 931 * device. Max accumulated FIFO size is 2K bytes. */
mbed_official 59:2af474687369 932 typedef struct
mbed_official 59:2af474687369 933 {
mbed_official 59:2af474687369 934 uint32_t rxFifoSize; /**< Number of FIFO bytes set aside for IN endpoints. */
mbed_official 59:2af474687369 935 uint32_t nptxFifoSize; /**< Number of FIFO bytes set aside for OUT CTRL/BULK endoints. */
mbed_official 59:2af474687369 936 uint32_t ptxFifoSize; /**< Number of FIFO bytes set aside for OUT INTR/ISO endoints. */
mbed_official 59:2af474687369 937 uint32_t reserved; /**< Reserved for future use. */
mbed_official 59:2af474687369 938 } USBH_Init_TypeDef;
mbed_official 59:2af474687369 939
mbed_official 59:2af474687369 940
mbed_official 59:2af474687369 941 /** Default @ref USBH_Init_TypeDef values, provides reasonable Tx/Rx FIFO
mbed_official 59:2af474687369 942 * partitioning. */
mbed_official 59:2af474687369 943 /* In DMA mode the total available FIFO space is smaller. */
mbed_official 59:2af474687369 944 /* The DMA controller use one FIFO word pr. channel for status. */
mbed_official 59:2af474687369 945 /* The unit in the table is byte. */
mbed_official 59:2af474687369 946 #define USBH_INIT_DEFAULT \
mbed_official 59:2af474687369 947 { \
mbed_official 59:2af474687369 948 MAX_HOST_FIFO_SIZE_INWORDS * 2,/* 1024 bytes Rx FIFO size. */ \
mbed_official 59:2af474687369 949 MAX_HOST_FIFO_SIZE_INWORDS, /* 512 bytes non-periodic Tx FIFO size. */ \
mbed_official 59:2af474687369 950 MAX_HOST_FIFO_SIZE_INWORDS, /* 512 bytes periodic Tx FIFO size. */ \
mbed_official 59:2af474687369 951 0 /* Reserved. */ \
mbed_official 59:2af474687369 952 }
mbed_official 59:2af474687369 953
mbed_official 59:2af474687369 954 /*** -------------------- HOST mode API ---------------------------------- ***/
mbed_official 59:2af474687369 955
mbed_official 59:2af474687369 956 int USBH_AssignHostChannel( USBH_Ep_TypeDef *ep, uint8_t hcnum );
mbed_official 59:2af474687369 957 int USBH_ControlMsg( USBH_Ep_TypeDef *ep, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, void *data, int timeout, USB_XferCompleteCb_TypeDef callback );
mbed_official 59:2af474687369 958 int USBH_ControlMsgB( USBH_Ep_TypeDef *ep, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint16_t wLength, void *data, int timeout );
mbed_official 59:2af474687369 959 bool USBH_DeviceConnected( void );
mbed_official 59:2af474687369 960 int USBH_GetConfigurationDescriptorB( USBH_Device_TypeDef *device, void *buf, int len, uint8_t configIndex );
mbed_official 59:2af474687369 961 int USBH_GetDeviceDescriptorB( USBH_Device_TypeDef *device, void *buf, int len );
mbed_official 59:2af474687369 962 uint8_t USBH_GetPortSpeed( void );
mbed_official 59:2af474687369 963 int USBH_GetStringB( USBH_Device_TypeDef *device, uint8_t *buf, int bufLen, uint8_t stringIndex, uint16_t langID );
mbed_official 59:2af474687369 964 int USBH_Init( const USBH_Init_TypeDef *p );
mbed_official 59:2af474687369 965 int USBH_InitDeviceData( USBH_Device_TypeDef *device, const uint8_t *buf, USBH_Ep_TypeDef *ep, int numEp, uint8_t deviceSpeed );
mbed_official 59:2af474687369 966 int USBH_PortReset( void );
mbed_official 59:2af474687369 967 int USBH_PortResume( void );
mbed_official 59:2af474687369 968 void USBH_PortSuspend( void );
mbed_official 59:2af474687369 969 void USBH_PrintString( const char *pre, const USB_StringDescriptor_TypeDef *s, const char *post );
mbed_official 59:2af474687369 970
mbed_official 59:2af474687369 971 #if defined( USB_USE_PRINTF )
mbed_official 59:2af474687369 972 int USBH_PrintConfigurationDescriptor( const USB_ConfigurationDescriptor_TypeDef *config, int maxLen );
mbed_official 59:2af474687369 973 int USBH_PrintDeviceDescriptor( const USB_DeviceDescriptor_TypeDef *device );
mbed_official 59:2af474687369 974 int USBH_PrintEndpointDescriptor( const USB_EndpointDescriptor_TypeDef *endpoint );
mbed_official 59:2af474687369 975 int USBH_PrintInterfaceDescriptor( const USB_InterfaceDescriptor_TypeDef *interface );
mbed_official 59:2af474687369 976 #else
mbed_official 59:2af474687369 977 #define USBH_PrintConfigurationDescriptor( config, maxLen )
mbed_official 59:2af474687369 978 #define USBH_PrintDeviceDescriptor( device )
mbed_official 59:2af474687369 979 #define USBH_PrintEndpointDescriptor( endpoint )
mbed_official 59:2af474687369 980 #define USBH_PrintInterfaceDescriptor( interface )
mbed_official 59:2af474687369 981 #endif /* defined( USB_USE_PRINTF ) */
mbed_official 59:2af474687369 982
mbed_official 59:2af474687369 983 int USBH_QueryDeviceB( uint8_t *buf, size_t bufsize, uint8_t deviceSpeed );
mbed_official 59:2af474687369 984 USB_ConfigurationDescriptor_TypeDef* USBH_QGetConfigurationDescriptor( const uint8_t *buf, int configIndex );
mbed_official 59:2af474687369 985 USB_DeviceDescriptor_TypeDef* USBH_QGetDeviceDescriptor( const uint8_t *buf );
mbed_official 59:2af474687369 986 USB_EndpointDescriptor_TypeDef* USBH_QGetEndpointDescriptor( const uint8_t *buf, int configIndex, int interfaceIndex, int endpointIndex );
mbed_official 59:2af474687369 987 USB_InterfaceDescriptor_TypeDef* USBH_QGetInterfaceDescriptor( const uint8_t *buf, int configIndex, int interfaceIndex );
mbed_official 59:2af474687369 988
mbed_official 59:2af474687369 989 int USBH_Read( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout, USB_XferCompleteCb_TypeDef callback );
mbed_official 59:2af474687369 990 int USBH_ReadB( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout );
mbed_official 59:2af474687369 991 int USBH_SetAddressB( USBH_Device_TypeDef *device, uint8_t deviceAddress );
mbed_official 59:2af474687369 992 int USBH_SetAltInterfaceB( USBH_Device_TypeDef *device, uint8_t interfaceIndex, uint8_t alternateSetting );
mbed_official 59:2af474687369 993 int USBH_SetConfigurationB( USBH_Device_TypeDef *device, uint8_t configValue );
mbed_official 59:2af474687369 994 int USBH_StallEpB( USBH_Ep_TypeDef *ep );
mbed_official 59:2af474687369 995 void USBH_Stop( void );
mbed_official 59:2af474687369 996 int USBH_UnStallEpB( USBH_Ep_TypeDef *ep );
mbed_official 59:2af474687369 997 int USBH_WaitForDeviceConnectionB( uint8_t *buf, int timeoutInSeconds );
mbed_official 59:2af474687369 998 int USBH_Write( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout, USB_XferCompleteCb_TypeDef callback );
mbed_official 59:2af474687369 999 int USBH_WriteB( USBH_Ep_TypeDef *ep, void *data, int byteCount, int timeout );
mbed_official 59:2af474687369 1000
mbed_official 59:2af474687369 1001 /** @} (end addtogroup USB_HOST) */
mbed_official 59:2af474687369 1002 #endif /* defined( USB_HOST ) */
mbed_official 59:2af474687369 1003 /** @} (end addtogroup USB) */
mbed_official 59:2af474687369 1004
mbed_official 59:2af474687369 1005 #ifdef __cplusplus
mbed_official 59:2af474687369 1006 }
mbed_official 59:2af474687369 1007 #endif
mbed_official 59:2af474687369 1008
mbed_official 59:2af474687369 1009 #endif /* defined( USB_DEVICE ) || defined( USB_HOST ) */
mbed_official 59:2af474687369 1010 #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */
mbed_official 59:2af474687369 1011 #endif /* __EM_USB_H */