USBDevice with Nucleo 32L476RG support

Dependents:   ObCP_ENSMM_V2020_Test_Accelero

Committer:
Kojto
Date:
Thu Jul 27 12:14:04 2017 +0100
Revision:
71:53949e6131f6
Update libraries

Fixes the previous commmit, as some devices were not copied. USBDevice contains
now targets directory with all targets implementations

Who changed what in which revision?

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