USB device stack - Added support for the logo/windows key to USB keyboard.

Dependents:   randomSearch

Fork of USBDevice by mbed official

Committer:
mbed_official
Date:
Thu Aug 13 15:46:06 2015 +0100
Revision:
59:2af474687369
Synchronized with git revision 376d6a73e345b728a788041adb166b08cd8d2b95

Full URL: https://github.com/mbedmicro/mbed/commit/376d6a73e345b728a788041adb166b08cd8d2b95/

Silicon Labs - Add support for USBDevice

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