IOTON boards API using mbed SDK - http://ioton.cc/plataforma-ton
Dependents: ton-bot_teste ton-bot_seguidor_linha ton-bot_seguidor_parede
Fork of IOTON-API by
usbd_cdc.c@3:9c7195d31602, 2017-06-29 (annotated)
- Committer:
- krebyy
- Date:
- Thu Jun 29 20:20:49 2017 +0000
- Revision:
- 3:9c7195d31602
- Parent:
- 1:3a73d77c2cef
Update to TON Board V1.2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
krebyy | 1:3a73d77c2cef | 1 | /** |
krebyy | 1:3a73d77c2cef | 2 | ****************************************************************************** |
krebyy | 1:3a73d77c2cef | 3 | * @file usbd_cdc.c |
krebyy | 1:3a73d77c2cef | 4 | * @author MCD Application Team |
krebyy | 1:3a73d77c2cef | 5 | * @version V2.3.0 |
krebyy | 1:3a73d77c2cef | 6 | * @date 04-November-2014 |
krebyy | 1:3a73d77c2cef | 7 | * @brief This file provides the high layer firmware functions to manage the |
krebyy | 1:3a73d77c2cef | 8 | * following functionalities of the USB CDC Class: |
krebyy | 1:3a73d77c2cef | 9 | * - Initialization and Configuration of high and low layer |
krebyy | 1:3a73d77c2cef | 10 | * - Enumeration as CDC Device (and enumeration for each implemented memory interface) |
krebyy | 1:3a73d77c2cef | 11 | * - OUT/IN data transfer |
krebyy | 1:3a73d77c2cef | 12 | * - Command IN transfer (class requests management) |
krebyy | 1:3a73d77c2cef | 13 | * - Error management |
krebyy | 1:3a73d77c2cef | 14 | * |
krebyy | 1:3a73d77c2cef | 15 | * @verbatim |
krebyy | 1:3a73d77c2cef | 16 | * |
krebyy | 1:3a73d77c2cef | 17 | * =================================================================== |
krebyy | 1:3a73d77c2cef | 18 | * CDC Class Driver Description |
krebyy | 1:3a73d77c2cef | 19 | * =================================================================== |
krebyy | 1:3a73d77c2cef | 20 | * This driver manages the "Universal Serial Bus Class Definitions for Communications Devices |
krebyy | 1:3a73d77c2cef | 21 | * Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus |
krebyy | 1:3a73d77c2cef | 22 | * Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007" |
krebyy | 1:3a73d77c2cef | 23 | * This driver implements the following aspects of the specification: |
krebyy | 1:3a73d77c2cef | 24 | * - Device descriptor management |
krebyy | 1:3a73d77c2cef | 25 | * - Configuration descriptor management |
krebyy | 1:3a73d77c2cef | 26 | * - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN) |
krebyy | 1:3a73d77c2cef | 27 | * - Requests management (as described in section 6.2 in specification) |
krebyy | 1:3a73d77c2cef | 28 | * - Abstract Control Model compliant |
krebyy | 1:3a73d77c2cef | 29 | * - Union Functional collection (using 1 IN endpoint for control) |
krebyy | 1:3a73d77c2cef | 30 | * - Data interface class |
krebyy | 1:3a73d77c2cef | 31 | * |
krebyy | 1:3a73d77c2cef | 32 | * These aspects may be enriched or modified for a specific user application. |
krebyy | 1:3a73d77c2cef | 33 | * |
krebyy | 1:3a73d77c2cef | 34 | * This driver doesn't implement the following aspects of the specification |
krebyy | 1:3a73d77c2cef | 35 | * (but it is possible to manage these features with some modifications on this driver): |
krebyy | 1:3a73d77c2cef | 36 | * - Any class-specific aspect relative to communication classes should be managed by user application. |
krebyy | 1:3a73d77c2cef | 37 | * - All communication classes other than PSTN are not managed |
krebyy | 1:3a73d77c2cef | 38 | * |
krebyy | 1:3a73d77c2cef | 39 | * @endverbatim |
krebyy | 1:3a73d77c2cef | 40 | * |
krebyy | 1:3a73d77c2cef | 41 | ****************************************************************************** |
krebyy | 1:3a73d77c2cef | 42 | * @attention |
krebyy | 1:3a73d77c2cef | 43 | * |
krebyy | 1:3a73d77c2cef | 44 | * <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> |
krebyy | 1:3a73d77c2cef | 45 | * |
krebyy | 1:3a73d77c2cef | 46 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
krebyy | 1:3a73d77c2cef | 47 | * You may not use this file except in compliance with the License. |
krebyy | 1:3a73d77c2cef | 48 | * You may obtain a copy of the License at: |
krebyy | 1:3a73d77c2cef | 49 | * |
krebyy | 1:3a73d77c2cef | 50 | * http://www.st.com/software_license_agreement_liberty_v2 |
krebyy | 1:3a73d77c2cef | 51 | * |
krebyy | 1:3a73d77c2cef | 52 | * Unless required by applicable law or agreed to in writing, software |
krebyy | 1:3a73d77c2cef | 53 | * distributed under the License is distributed on an "AS IS" BASIS, |
krebyy | 1:3a73d77c2cef | 54 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
krebyy | 1:3a73d77c2cef | 55 | * See the License for the specific language governing permissions and |
krebyy | 1:3a73d77c2cef | 56 | * limitations under the License. |
krebyy | 1:3a73d77c2cef | 57 | * |
krebyy | 1:3a73d77c2cef | 58 | ****************************************************************************** |
krebyy | 1:3a73d77c2cef | 59 | */ |
krebyy | 1:3a73d77c2cef | 60 | |
krebyy | 1:3a73d77c2cef | 61 | /* Includes ------------------------------------------------------------------*/ |
krebyy | 1:3a73d77c2cef | 62 | #include "usbd_cdc.h" |
krebyy | 1:3a73d77c2cef | 63 | #include "usbd_desc.h" |
krebyy | 1:3a73d77c2cef | 64 | #include "usbd_ctlreq.h" |
krebyy | 1:3a73d77c2cef | 65 | |
krebyy | 1:3a73d77c2cef | 66 | |
krebyy | 1:3a73d77c2cef | 67 | /** @addtogroup STM32_USB_DEVICE_LIBRARY |
krebyy | 1:3a73d77c2cef | 68 | * @{ |
krebyy | 1:3a73d77c2cef | 69 | */ |
krebyy | 1:3a73d77c2cef | 70 | |
krebyy | 1:3a73d77c2cef | 71 | |
krebyy | 1:3a73d77c2cef | 72 | /** @defgroup USBD_CDC |
krebyy | 1:3a73d77c2cef | 73 | * @brief usbd core module |
krebyy | 1:3a73d77c2cef | 74 | * @{ |
krebyy | 1:3a73d77c2cef | 75 | */ |
krebyy | 1:3a73d77c2cef | 76 | |
krebyy | 1:3a73d77c2cef | 77 | /** @defgroup USBD_CDC_Private_TypesDefinitions |
krebyy | 1:3a73d77c2cef | 78 | * @{ |
krebyy | 1:3a73d77c2cef | 79 | */ |
krebyy | 1:3a73d77c2cef | 80 | /** |
krebyy | 1:3a73d77c2cef | 81 | * @} |
krebyy | 1:3a73d77c2cef | 82 | */ |
krebyy | 1:3a73d77c2cef | 83 | |
krebyy | 1:3a73d77c2cef | 84 | |
krebyy | 1:3a73d77c2cef | 85 | /** @defgroup USBD_CDC_Private_Defines |
krebyy | 1:3a73d77c2cef | 86 | * @{ |
krebyy | 1:3a73d77c2cef | 87 | */ |
krebyy | 1:3a73d77c2cef | 88 | /** |
krebyy | 1:3a73d77c2cef | 89 | * @} |
krebyy | 1:3a73d77c2cef | 90 | */ |
krebyy | 1:3a73d77c2cef | 91 | |
krebyy | 1:3a73d77c2cef | 92 | |
krebyy | 1:3a73d77c2cef | 93 | /** @defgroup USBD_CDC_Private_Macros |
krebyy | 1:3a73d77c2cef | 94 | * @{ |
krebyy | 1:3a73d77c2cef | 95 | */ |
krebyy | 1:3a73d77c2cef | 96 | |
krebyy | 1:3a73d77c2cef | 97 | /** |
krebyy | 1:3a73d77c2cef | 98 | * @} |
krebyy | 1:3a73d77c2cef | 99 | */ |
krebyy | 1:3a73d77c2cef | 100 | |
krebyy | 1:3a73d77c2cef | 101 | |
krebyy | 1:3a73d77c2cef | 102 | /** @defgroup USBD_CDC_Private_FunctionPrototypes |
krebyy | 1:3a73d77c2cef | 103 | * @{ |
krebyy | 1:3a73d77c2cef | 104 | */ |
krebyy | 1:3a73d77c2cef | 105 | |
krebyy | 1:3a73d77c2cef | 106 | |
krebyy | 1:3a73d77c2cef | 107 | static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 108 | uint8_t cfgidx); |
krebyy | 1:3a73d77c2cef | 109 | |
krebyy | 1:3a73d77c2cef | 110 | static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 111 | uint8_t cfgidx); |
krebyy | 1:3a73d77c2cef | 112 | |
krebyy | 1:3a73d77c2cef | 113 | static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 114 | USBD_SetupReqTypedef *req); |
krebyy | 1:3a73d77c2cef | 115 | |
krebyy | 1:3a73d77c2cef | 116 | static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 117 | uint8_t epnum); |
krebyy | 1:3a73d77c2cef | 118 | |
krebyy | 1:3a73d77c2cef | 119 | static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 120 | uint8_t epnum); |
krebyy | 1:3a73d77c2cef | 121 | |
krebyy | 1:3a73d77c2cef | 122 | static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev); |
krebyy | 1:3a73d77c2cef | 123 | |
krebyy | 1:3a73d77c2cef | 124 | static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length); |
krebyy | 1:3a73d77c2cef | 125 | |
krebyy | 1:3a73d77c2cef | 126 | static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length); |
krebyy | 1:3a73d77c2cef | 127 | |
krebyy | 1:3a73d77c2cef | 128 | static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); |
krebyy | 1:3a73d77c2cef | 129 | |
krebyy | 1:3a73d77c2cef | 130 | static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length); |
krebyy | 1:3a73d77c2cef | 131 | |
krebyy | 1:3a73d77c2cef | 132 | uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length); |
krebyy | 1:3a73d77c2cef | 133 | |
krebyy | 1:3a73d77c2cef | 134 | /* USB Standard Device Descriptor */ |
krebyy | 1:3a73d77c2cef | 135 | __ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END = |
krebyy | 1:3a73d77c2cef | 136 | { |
krebyy | 1:3a73d77c2cef | 137 | USB_LEN_DEV_QUALIFIER_DESC, |
krebyy | 1:3a73d77c2cef | 138 | USB_DESC_TYPE_DEVICE_QUALIFIER, |
krebyy | 1:3a73d77c2cef | 139 | 0x00, |
krebyy | 1:3a73d77c2cef | 140 | 0x02, |
krebyy | 1:3a73d77c2cef | 141 | 0x00, |
krebyy | 1:3a73d77c2cef | 142 | 0x00, |
krebyy | 1:3a73d77c2cef | 143 | 0x00, |
krebyy | 1:3a73d77c2cef | 144 | 0x40, |
krebyy | 1:3a73d77c2cef | 145 | 0x01, |
krebyy | 1:3a73d77c2cef | 146 | 0x00, |
krebyy | 1:3a73d77c2cef | 147 | }; |
krebyy | 1:3a73d77c2cef | 148 | |
krebyy | 1:3a73d77c2cef | 149 | /** |
krebyy | 1:3a73d77c2cef | 150 | * @} |
krebyy | 1:3a73d77c2cef | 151 | */ |
krebyy | 1:3a73d77c2cef | 152 | |
krebyy | 1:3a73d77c2cef | 153 | /** @defgroup USBD_CDC_Private_Variables |
krebyy | 1:3a73d77c2cef | 154 | * @{ |
krebyy | 1:3a73d77c2cef | 155 | */ |
krebyy | 1:3a73d77c2cef | 156 | |
krebyy | 1:3a73d77c2cef | 157 | |
krebyy | 1:3a73d77c2cef | 158 | /* CDC interface class callbacks structure */ |
krebyy | 1:3a73d77c2cef | 159 | USBD_ClassTypeDef USBD_CDC = |
krebyy | 1:3a73d77c2cef | 160 | { |
krebyy | 1:3a73d77c2cef | 161 | USBD_CDC_Init, |
krebyy | 1:3a73d77c2cef | 162 | USBD_CDC_DeInit, |
krebyy | 1:3a73d77c2cef | 163 | USBD_CDC_Setup, |
krebyy | 1:3a73d77c2cef | 164 | NULL, /* EP0_TxSent, */ |
krebyy | 1:3a73d77c2cef | 165 | USBD_CDC_EP0_RxReady, |
krebyy | 1:3a73d77c2cef | 166 | USBD_CDC_DataIn, |
krebyy | 1:3a73d77c2cef | 167 | USBD_CDC_DataOut, |
krebyy | 1:3a73d77c2cef | 168 | NULL, |
krebyy | 1:3a73d77c2cef | 169 | NULL, |
krebyy | 1:3a73d77c2cef | 170 | NULL, |
krebyy | 1:3a73d77c2cef | 171 | USBD_CDC_GetHSCfgDesc, |
krebyy | 1:3a73d77c2cef | 172 | USBD_CDC_GetFSCfgDesc, |
krebyy | 1:3a73d77c2cef | 173 | USBD_CDC_GetOtherSpeedCfgDesc, |
krebyy | 1:3a73d77c2cef | 174 | USBD_CDC_GetDeviceQualifierDescriptor, |
krebyy | 1:3a73d77c2cef | 175 | }; |
krebyy | 1:3a73d77c2cef | 176 | |
krebyy | 1:3a73d77c2cef | 177 | /* USB CDC device Configuration Descriptor */ |
krebyy | 1:3a73d77c2cef | 178 | __ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = |
krebyy | 1:3a73d77c2cef | 179 | { |
krebyy | 1:3a73d77c2cef | 180 | /*Configuration Descriptor*/ |
krebyy | 1:3a73d77c2cef | 181 | 0x09, /* bLength: Configuration Descriptor size */ |
krebyy | 1:3a73d77c2cef | 182 | USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ |
krebyy | 1:3a73d77c2cef | 183 | USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */ |
krebyy | 1:3a73d77c2cef | 184 | 0x00, |
krebyy | 1:3a73d77c2cef | 185 | 0x02, /* bNumInterfaces: 2 interface */ |
krebyy | 1:3a73d77c2cef | 186 | 0x01, /* bConfigurationValue: Configuration value */ |
krebyy | 1:3a73d77c2cef | 187 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ |
krebyy | 1:3a73d77c2cef | 188 | 0xC0, /* bmAttributes: self powered */ |
krebyy | 1:3a73d77c2cef | 189 | 0x32, /* MaxPower 0 mA */ |
krebyy | 1:3a73d77c2cef | 190 | |
krebyy | 1:3a73d77c2cef | 191 | /*---------------------------------------------------------------------------*/ |
krebyy | 1:3a73d77c2cef | 192 | |
krebyy | 1:3a73d77c2cef | 193 | /*Interface Descriptor */ |
krebyy | 1:3a73d77c2cef | 194 | 0x09, /* bLength: Interface Descriptor size */ |
krebyy | 1:3a73d77c2cef | 195 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ |
krebyy | 1:3a73d77c2cef | 196 | /* Interface descriptor type */ |
krebyy | 1:3a73d77c2cef | 197 | 0x00, /* bInterfaceNumber: Number of Interface */ |
krebyy | 1:3a73d77c2cef | 198 | 0x00, /* bAlternateSetting: Alternate setting */ |
krebyy | 1:3a73d77c2cef | 199 | 0x01, /* bNumEndpoints: One endpoints used */ |
krebyy | 1:3a73d77c2cef | 200 | 0x02, /* bInterfaceClass: Communication Interface Class */ |
krebyy | 1:3a73d77c2cef | 201 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ |
krebyy | 1:3a73d77c2cef | 202 | 0x01, /* bInterfaceProtocol: Common AT commands */ |
krebyy | 1:3a73d77c2cef | 203 | 0x00, /* iInterface: */ |
krebyy | 1:3a73d77c2cef | 204 | |
krebyy | 1:3a73d77c2cef | 205 | /*Header Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 206 | 0x05, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 207 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 208 | 0x00, /* bDescriptorSubtype: Header Func Desc */ |
krebyy | 1:3a73d77c2cef | 209 | 0x10, /* bcdCDC: spec release number */ |
krebyy | 1:3a73d77c2cef | 210 | 0x01, |
krebyy | 1:3a73d77c2cef | 211 | |
krebyy | 1:3a73d77c2cef | 212 | /*Call Management Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 213 | 0x05, /* bFunctionLength */ |
krebyy | 1:3a73d77c2cef | 214 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 215 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ |
krebyy | 1:3a73d77c2cef | 216 | 0x00, /* bmCapabilities: D0+D1 */ |
krebyy | 1:3a73d77c2cef | 217 | 0x01, /* bDataInterface: 1 */ |
krebyy | 1:3a73d77c2cef | 218 | |
krebyy | 1:3a73d77c2cef | 219 | /*ACM Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 220 | 0x04, /* bFunctionLength */ |
krebyy | 1:3a73d77c2cef | 221 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 222 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ |
krebyy | 1:3a73d77c2cef | 223 | 0x02, /* bmCapabilities */ |
krebyy | 1:3a73d77c2cef | 224 | |
krebyy | 1:3a73d77c2cef | 225 | /*Union Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 226 | 0x05, /* bFunctionLength */ |
krebyy | 1:3a73d77c2cef | 227 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 228 | 0x06, /* bDescriptorSubtype: Union func desc */ |
krebyy | 1:3a73d77c2cef | 229 | 0x00, /* bMasterInterface: Communication class interface */ |
krebyy | 1:3a73d77c2cef | 230 | 0x01, /* bSlaveInterface0: Data Class Interface */ |
krebyy | 1:3a73d77c2cef | 231 | |
krebyy | 1:3a73d77c2cef | 232 | /*Endpoint 2 Descriptor*/ |
krebyy | 1:3a73d77c2cef | 233 | 0x07, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 234 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
krebyy | 1:3a73d77c2cef | 235 | CDC_CMD_EP, /* bEndpointAddress */ |
krebyy | 1:3a73d77c2cef | 236 | 0x03, /* bmAttributes: Interrupt */ |
krebyy | 1:3a73d77c2cef | 237 | LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ |
krebyy | 1:3a73d77c2cef | 238 | HIBYTE(CDC_CMD_PACKET_SIZE), |
krebyy | 1:3a73d77c2cef | 239 | 0x10, /* bInterval: */ |
krebyy | 1:3a73d77c2cef | 240 | /*---------------------------------------------------------------------------*/ |
krebyy | 1:3a73d77c2cef | 241 | |
krebyy | 1:3a73d77c2cef | 242 | /*Data class interface descriptor*/ |
krebyy | 1:3a73d77c2cef | 243 | 0x09, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 244 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ |
krebyy | 1:3a73d77c2cef | 245 | 0x01, /* bInterfaceNumber: Number of Interface */ |
krebyy | 1:3a73d77c2cef | 246 | 0x00, /* bAlternateSetting: Alternate setting */ |
krebyy | 1:3a73d77c2cef | 247 | 0x02, /* bNumEndpoints: Two endpoints used */ |
krebyy | 1:3a73d77c2cef | 248 | 0x0A, /* bInterfaceClass: CDC */ |
krebyy | 1:3a73d77c2cef | 249 | 0x00, /* bInterfaceSubClass: */ |
krebyy | 1:3a73d77c2cef | 250 | 0x00, /* bInterfaceProtocol: */ |
krebyy | 1:3a73d77c2cef | 251 | 0x00, /* iInterface: */ |
krebyy | 1:3a73d77c2cef | 252 | |
krebyy | 1:3a73d77c2cef | 253 | /*Endpoint OUT Descriptor*/ |
krebyy | 1:3a73d77c2cef | 254 | 0x07, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 255 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
krebyy | 1:3a73d77c2cef | 256 | CDC_OUT_EP, /* bEndpointAddress */ |
krebyy | 1:3a73d77c2cef | 257 | 0x02, /* bmAttributes: Bulk */ |
krebyy | 1:3a73d77c2cef | 258 | LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ |
krebyy | 1:3a73d77c2cef | 259 | HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), |
krebyy | 1:3a73d77c2cef | 260 | 0x00, /* bInterval: ignore for Bulk transfer */ |
krebyy | 1:3a73d77c2cef | 261 | |
krebyy | 1:3a73d77c2cef | 262 | /*Endpoint IN Descriptor*/ |
krebyy | 1:3a73d77c2cef | 263 | 0x07, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 264 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
krebyy | 1:3a73d77c2cef | 265 | CDC_IN_EP, /* bEndpointAddress */ |
krebyy | 1:3a73d77c2cef | 266 | 0x02, /* bmAttributes: Bulk */ |
krebyy | 1:3a73d77c2cef | 267 | LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ |
krebyy | 1:3a73d77c2cef | 268 | HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), |
krebyy | 1:3a73d77c2cef | 269 | 0x00 /* bInterval: ignore for Bulk transfer */ |
krebyy | 1:3a73d77c2cef | 270 | } ; |
krebyy | 1:3a73d77c2cef | 271 | |
krebyy | 1:3a73d77c2cef | 272 | |
krebyy | 1:3a73d77c2cef | 273 | /* USB CDC device Configuration Descriptor */ |
krebyy | 1:3a73d77c2cef | 274 | __ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = |
krebyy | 1:3a73d77c2cef | 275 | { |
krebyy | 1:3a73d77c2cef | 276 | /*Configuration Descriptor*/ |
krebyy | 1:3a73d77c2cef | 277 | 0x09, /* bLength: Configuration Descriptor size */ |
krebyy | 1:3a73d77c2cef | 278 | USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */ |
krebyy | 1:3a73d77c2cef | 279 | USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */ |
krebyy | 1:3a73d77c2cef | 280 | 0x00, |
krebyy | 1:3a73d77c2cef | 281 | 0x02, /* bNumInterfaces: 2 interface */ |
krebyy | 1:3a73d77c2cef | 282 | 0x01, /* bConfigurationValue: Configuration value */ |
krebyy | 1:3a73d77c2cef | 283 | 0x00, /* iConfiguration: Index of string descriptor describing the configuration */ |
krebyy | 1:3a73d77c2cef | 284 | 0xC0, /* bmAttributes: self powered */ |
krebyy | 1:3a73d77c2cef | 285 | 0x32, /* MaxPower 0 mA */ |
krebyy | 1:3a73d77c2cef | 286 | |
krebyy | 1:3a73d77c2cef | 287 | /*---------------------------------------------------------------------------*/ |
krebyy | 1:3a73d77c2cef | 288 | |
krebyy | 1:3a73d77c2cef | 289 | /*Interface Descriptor */ |
krebyy | 1:3a73d77c2cef | 290 | 0x09, /* bLength: Interface Descriptor size */ |
krebyy | 1:3a73d77c2cef | 291 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ |
krebyy | 1:3a73d77c2cef | 292 | /* Interface descriptor type */ |
krebyy | 1:3a73d77c2cef | 293 | 0x00, /* bInterfaceNumber: Number of Interface */ |
krebyy | 1:3a73d77c2cef | 294 | 0x00, /* bAlternateSetting: Alternate setting */ |
krebyy | 1:3a73d77c2cef | 295 | 0x01, /* bNumEndpoints: One endpoints used */ |
krebyy | 1:3a73d77c2cef | 296 | 0x02, /* bInterfaceClass: Communication Interface Class */ |
krebyy | 1:3a73d77c2cef | 297 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ |
krebyy | 1:3a73d77c2cef | 298 | 0x01, /* bInterfaceProtocol: Common AT commands */ |
krebyy | 1:3a73d77c2cef | 299 | 0x00, /* iInterface: */ |
krebyy | 1:3a73d77c2cef | 300 | |
krebyy | 1:3a73d77c2cef | 301 | /*Header Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 302 | 0x05, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 303 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 304 | 0x00, /* bDescriptorSubtype: Header Func Desc */ |
krebyy | 1:3a73d77c2cef | 305 | 0x10, /* bcdCDC: spec release number */ |
krebyy | 1:3a73d77c2cef | 306 | 0x01, |
krebyy | 1:3a73d77c2cef | 307 | |
krebyy | 1:3a73d77c2cef | 308 | /*Call Management Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 309 | 0x05, /* bFunctionLength */ |
krebyy | 1:3a73d77c2cef | 310 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 311 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ |
krebyy | 1:3a73d77c2cef | 312 | 0x00, /* bmCapabilities: D0+D1 */ |
krebyy | 1:3a73d77c2cef | 313 | 0x01, /* bDataInterface: 1 */ |
krebyy | 1:3a73d77c2cef | 314 | |
krebyy | 1:3a73d77c2cef | 315 | /*ACM Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 316 | 0x04, /* bFunctionLength */ |
krebyy | 1:3a73d77c2cef | 317 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 318 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ |
krebyy | 1:3a73d77c2cef | 319 | 0x02, /* bmCapabilities */ |
krebyy | 1:3a73d77c2cef | 320 | |
krebyy | 1:3a73d77c2cef | 321 | /*Union Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 322 | 0x05, /* bFunctionLength */ |
krebyy | 1:3a73d77c2cef | 323 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 324 | 0x06, /* bDescriptorSubtype: Union func desc */ |
krebyy | 1:3a73d77c2cef | 325 | 0x00, /* bMasterInterface: Communication class interface */ |
krebyy | 1:3a73d77c2cef | 326 | 0x01, /* bSlaveInterface0: Data Class Interface */ |
krebyy | 1:3a73d77c2cef | 327 | |
krebyy | 1:3a73d77c2cef | 328 | /*Endpoint 2 Descriptor*/ |
krebyy | 1:3a73d77c2cef | 329 | 0x07, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 330 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
krebyy | 1:3a73d77c2cef | 331 | CDC_CMD_EP, /* bEndpointAddress */ |
krebyy | 1:3a73d77c2cef | 332 | 0x03, /* bmAttributes: Interrupt */ |
krebyy | 1:3a73d77c2cef | 333 | LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ |
krebyy | 1:3a73d77c2cef | 334 | HIBYTE(CDC_CMD_PACKET_SIZE), |
krebyy | 1:3a73d77c2cef | 335 | 0x10, /* bInterval: */ |
krebyy | 1:3a73d77c2cef | 336 | /*---------------------------------------------------------------------------*/ |
krebyy | 1:3a73d77c2cef | 337 | |
krebyy | 1:3a73d77c2cef | 338 | /*Data class interface descriptor*/ |
krebyy | 1:3a73d77c2cef | 339 | 0x09, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 340 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ |
krebyy | 1:3a73d77c2cef | 341 | 0x01, /* bInterfaceNumber: Number of Interface */ |
krebyy | 1:3a73d77c2cef | 342 | 0x00, /* bAlternateSetting: Alternate setting */ |
krebyy | 1:3a73d77c2cef | 343 | 0x02, /* bNumEndpoints: Two endpoints used */ |
krebyy | 1:3a73d77c2cef | 344 | 0x0A, /* bInterfaceClass: CDC */ |
krebyy | 1:3a73d77c2cef | 345 | 0x00, /* bInterfaceSubClass: */ |
krebyy | 1:3a73d77c2cef | 346 | 0x00, /* bInterfaceProtocol: */ |
krebyy | 1:3a73d77c2cef | 347 | 0x00, /* iInterface: */ |
krebyy | 1:3a73d77c2cef | 348 | |
krebyy | 1:3a73d77c2cef | 349 | /*Endpoint OUT Descriptor*/ |
krebyy | 1:3a73d77c2cef | 350 | 0x07, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 351 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
krebyy | 1:3a73d77c2cef | 352 | CDC_OUT_EP, /* bEndpointAddress */ |
krebyy | 1:3a73d77c2cef | 353 | 0x02, /* bmAttributes: Bulk */ |
krebyy | 1:3a73d77c2cef | 354 | LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ |
krebyy | 1:3a73d77c2cef | 355 | HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), |
krebyy | 1:3a73d77c2cef | 356 | 0x00, /* bInterval: ignore for Bulk transfer */ |
krebyy | 1:3a73d77c2cef | 357 | |
krebyy | 1:3a73d77c2cef | 358 | /*Endpoint IN Descriptor*/ |
krebyy | 1:3a73d77c2cef | 359 | 0x07, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 360 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
krebyy | 1:3a73d77c2cef | 361 | CDC_IN_EP, /* bEndpointAddress */ |
krebyy | 1:3a73d77c2cef | 362 | 0x02, /* bmAttributes: Bulk */ |
krebyy | 1:3a73d77c2cef | 363 | LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */ |
krebyy | 1:3a73d77c2cef | 364 | HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), |
krebyy | 1:3a73d77c2cef | 365 | 0x00 /* bInterval: ignore for Bulk transfer */ |
krebyy | 1:3a73d77c2cef | 366 | } ; |
krebyy | 1:3a73d77c2cef | 367 | |
krebyy | 1:3a73d77c2cef | 368 | __ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END = |
krebyy | 1:3a73d77c2cef | 369 | { |
krebyy | 1:3a73d77c2cef | 370 | 0x09, /* bLength: Configuation Descriptor size */ |
krebyy | 1:3a73d77c2cef | 371 | USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, |
krebyy | 1:3a73d77c2cef | 372 | USB_CDC_CONFIG_DESC_SIZ, |
krebyy | 1:3a73d77c2cef | 373 | 0x00, |
krebyy | 1:3a73d77c2cef | 374 | 0x02, /* bNumInterfaces: 2 interfaces */ |
krebyy | 1:3a73d77c2cef | 375 | 0x01, /* bConfigurationValue: */ |
krebyy | 1:3a73d77c2cef | 376 | 0x04, /* iConfiguration: */ |
krebyy | 1:3a73d77c2cef | 377 | 0xC0, /* bmAttributes: */ |
krebyy | 1:3a73d77c2cef | 378 | 0x32, /* MaxPower 100 mA */ |
krebyy | 1:3a73d77c2cef | 379 | |
krebyy | 1:3a73d77c2cef | 380 | /*Interface Descriptor */ |
krebyy | 1:3a73d77c2cef | 381 | 0x09, /* bLength: Interface Descriptor size */ |
krebyy | 1:3a73d77c2cef | 382 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */ |
krebyy | 1:3a73d77c2cef | 383 | /* Interface descriptor type */ |
krebyy | 1:3a73d77c2cef | 384 | 0x00, /* bInterfaceNumber: Number of Interface */ |
krebyy | 1:3a73d77c2cef | 385 | 0x00, /* bAlternateSetting: Alternate setting */ |
krebyy | 1:3a73d77c2cef | 386 | 0x01, /* bNumEndpoints: One endpoints used */ |
krebyy | 1:3a73d77c2cef | 387 | 0x02, /* bInterfaceClass: Communication Interface Class */ |
krebyy | 1:3a73d77c2cef | 388 | 0x02, /* bInterfaceSubClass: Abstract Control Model */ |
krebyy | 1:3a73d77c2cef | 389 | 0x01, /* bInterfaceProtocol: Common AT commands */ |
krebyy | 1:3a73d77c2cef | 390 | 0x00, /* iInterface: */ |
krebyy | 1:3a73d77c2cef | 391 | |
krebyy | 1:3a73d77c2cef | 392 | /*Header Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 393 | 0x05, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 394 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 395 | 0x00, /* bDescriptorSubtype: Header Func Desc */ |
krebyy | 1:3a73d77c2cef | 396 | 0x10, /* bcdCDC: spec release number */ |
krebyy | 1:3a73d77c2cef | 397 | 0x01, |
krebyy | 1:3a73d77c2cef | 398 | |
krebyy | 1:3a73d77c2cef | 399 | /*Call Management Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 400 | 0x05, /* bFunctionLength */ |
krebyy | 1:3a73d77c2cef | 401 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 402 | 0x01, /* bDescriptorSubtype: Call Management Func Desc */ |
krebyy | 1:3a73d77c2cef | 403 | 0x00, /* bmCapabilities: D0+D1 */ |
krebyy | 1:3a73d77c2cef | 404 | 0x01, /* bDataInterface: 1 */ |
krebyy | 1:3a73d77c2cef | 405 | |
krebyy | 1:3a73d77c2cef | 406 | /*ACM Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 407 | 0x04, /* bFunctionLength */ |
krebyy | 1:3a73d77c2cef | 408 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 409 | 0x02, /* bDescriptorSubtype: Abstract Control Management desc */ |
krebyy | 1:3a73d77c2cef | 410 | 0x02, /* bmCapabilities */ |
krebyy | 1:3a73d77c2cef | 411 | |
krebyy | 1:3a73d77c2cef | 412 | /*Union Functional Descriptor*/ |
krebyy | 1:3a73d77c2cef | 413 | 0x05, /* bFunctionLength */ |
krebyy | 1:3a73d77c2cef | 414 | 0x24, /* bDescriptorType: CS_INTERFACE */ |
krebyy | 1:3a73d77c2cef | 415 | 0x06, /* bDescriptorSubtype: Union func desc */ |
krebyy | 1:3a73d77c2cef | 416 | 0x00, /* bMasterInterface: Communication class interface */ |
krebyy | 1:3a73d77c2cef | 417 | 0x01, /* bSlaveInterface0: Data Class Interface */ |
krebyy | 1:3a73d77c2cef | 418 | |
krebyy | 1:3a73d77c2cef | 419 | /*Endpoint 2 Descriptor*/ |
krebyy | 1:3a73d77c2cef | 420 | 0x07, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 421 | USB_DESC_TYPE_ENDPOINT , /* bDescriptorType: Endpoint */ |
krebyy | 1:3a73d77c2cef | 422 | CDC_CMD_EP, /* bEndpointAddress */ |
krebyy | 1:3a73d77c2cef | 423 | 0x03, /* bmAttributes: Interrupt */ |
krebyy | 1:3a73d77c2cef | 424 | LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */ |
krebyy | 1:3a73d77c2cef | 425 | HIBYTE(CDC_CMD_PACKET_SIZE), |
krebyy | 1:3a73d77c2cef | 426 | 0xFF, /* bInterval: */ |
krebyy | 1:3a73d77c2cef | 427 | |
krebyy | 1:3a73d77c2cef | 428 | /*---------------------------------------------------------------------------*/ |
krebyy | 1:3a73d77c2cef | 429 | |
krebyy | 1:3a73d77c2cef | 430 | /*Data class interface descriptor*/ |
krebyy | 1:3a73d77c2cef | 431 | 0x09, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 432 | USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */ |
krebyy | 1:3a73d77c2cef | 433 | 0x01, /* bInterfaceNumber: Number of Interface */ |
krebyy | 1:3a73d77c2cef | 434 | 0x00, /* bAlternateSetting: Alternate setting */ |
krebyy | 1:3a73d77c2cef | 435 | 0x02, /* bNumEndpoints: Two endpoints used */ |
krebyy | 1:3a73d77c2cef | 436 | 0x0A, /* bInterfaceClass: CDC */ |
krebyy | 1:3a73d77c2cef | 437 | 0x00, /* bInterfaceSubClass: */ |
krebyy | 1:3a73d77c2cef | 438 | 0x00, /* bInterfaceProtocol: */ |
krebyy | 1:3a73d77c2cef | 439 | 0x00, /* iInterface: */ |
krebyy | 1:3a73d77c2cef | 440 | |
krebyy | 1:3a73d77c2cef | 441 | /*Endpoint OUT Descriptor*/ |
krebyy | 1:3a73d77c2cef | 442 | 0x07, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 443 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
krebyy | 1:3a73d77c2cef | 444 | CDC_OUT_EP, /* bEndpointAddress */ |
krebyy | 1:3a73d77c2cef | 445 | 0x02, /* bmAttributes: Bulk */ |
krebyy | 1:3a73d77c2cef | 446 | 0x40, /* wMaxPacketSize: */ |
krebyy | 1:3a73d77c2cef | 447 | 0x00, |
krebyy | 1:3a73d77c2cef | 448 | 0x00, /* bInterval: ignore for Bulk transfer */ |
krebyy | 1:3a73d77c2cef | 449 | |
krebyy | 1:3a73d77c2cef | 450 | /*Endpoint IN Descriptor*/ |
krebyy | 1:3a73d77c2cef | 451 | 0x07, /* bLength: Endpoint Descriptor size */ |
krebyy | 1:3a73d77c2cef | 452 | USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */ |
krebyy | 1:3a73d77c2cef | 453 | CDC_IN_EP, /* bEndpointAddress */ |
krebyy | 1:3a73d77c2cef | 454 | 0x02, /* bmAttributes: Bulk */ |
krebyy | 1:3a73d77c2cef | 455 | 0x40, /* wMaxPacketSize: */ |
krebyy | 1:3a73d77c2cef | 456 | 0x00, |
krebyy | 1:3a73d77c2cef | 457 | 0x00 /* bInterval */ |
krebyy | 1:3a73d77c2cef | 458 | }; |
krebyy | 1:3a73d77c2cef | 459 | |
krebyy | 1:3a73d77c2cef | 460 | /** |
krebyy | 1:3a73d77c2cef | 461 | * @} |
krebyy | 1:3a73d77c2cef | 462 | */ |
krebyy | 1:3a73d77c2cef | 463 | |
krebyy | 1:3a73d77c2cef | 464 | /** @defgroup USBD_CDC_Private_Functions |
krebyy | 1:3a73d77c2cef | 465 | * @{ |
krebyy | 1:3a73d77c2cef | 466 | */ |
krebyy | 1:3a73d77c2cef | 467 | |
krebyy | 1:3a73d77c2cef | 468 | /** |
krebyy | 1:3a73d77c2cef | 469 | * @brief USBD_CDC_Init |
krebyy | 1:3a73d77c2cef | 470 | * Initialize the CDC interface |
krebyy | 1:3a73d77c2cef | 471 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 472 | * @param cfgidx: Configuration index |
krebyy | 1:3a73d77c2cef | 473 | * @retval status |
krebyy | 1:3a73d77c2cef | 474 | */ |
krebyy | 1:3a73d77c2cef | 475 | static uint8_t USBD_CDC_Init (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 476 | uint8_t cfgidx) |
krebyy | 1:3a73d77c2cef | 477 | { |
krebyy | 1:3a73d77c2cef | 478 | uint8_t ret = 0; |
krebyy | 1:3a73d77c2cef | 479 | USBD_CDC_HandleTypeDef *hcdc; |
krebyy | 1:3a73d77c2cef | 480 | |
krebyy | 1:3a73d77c2cef | 481 | if(pdev->dev_speed == USBD_SPEED_HIGH ) |
krebyy | 1:3a73d77c2cef | 482 | { |
krebyy | 1:3a73d77c2cef | 483 | /* Open EP IN */ |
krebyy | 1:3a73d77c2cef | 484 | USBD_LL_OpenEP(pdev, |
krebyy | 1:3a73d77c2cef | 485 | CDC_IN_EP, |
krebyy | 1:3a73d77c2cef | 486 | USBD_EP_TYPE_BULK, |
krebyy | 1:3a73d77c2cef | 487 | CDC_DATA_HS_IN_PACKET_SIZE); |
krebyy | 1:3a73d77c2cef | 488 | |
krebyy | 1:3a73d77c2cef | 489 | /* Open EP OUT */ |
krebyy | 1:3a73d77c2cef | 490 | USBD_LL_OpenEP(pdev, |
krebyy | 1:3a73d77c2cef | 491 | CDC_OUT_EP, |
krebyy | 1:3a73d77c2cef | 492 | USBD_EP_TYPE_BULK, |
krebyy | 1:3a73d77c2cef | 493 | CDC_DATA_HS_OUT_PACKET_SIZE); |
krebyy | 1:3a73d77c2cef | 494 | |
krebyy | 1:3a73d77c2cef | 495 | } |
krebyy | 1:3a73d77c2cef | 496 | else |
krebyy | 1:3a73d77c2cef | 497 | { |
krebyy | 1:3a73d77c2cef | 498 | /* Open EP IN */ |
krebyy | 1:3a73d77c2cef | 499 | USBD_LL_OpenEP(pdev, |
krebyy | 1:3a73d77c2cef | 500 | CDC_IN_EP, |
krebyy | 1:3a73d77c2cef | 501 | USBD_EP_TYPE_BULK, |
krebyy | 1:3a73d77c2cef | 502 | CDC_DATA_FS_IN_PACKET_SIZE); |
krebyy | 1:3a73d77c2cef | 503 | |
krebyy | 1:3a73d77c2cef | 504 | /* Open EP OUT */ |
krebyy | 1:3a73d77c2cef | 505 | USBD_LL_OpenEP(pdev, |
krebyy | 1:3a73d77c2cef | 506 | CDC_OUT_EP, |
krebyy | 1:3a73d77c2cef | 507 | USBD_EP_TYPE_BULK, |
krebyy | 1:3a73d77c2cef | 508 | CDC_DATA_FS_OUT_PACKET_SIZE); |
krebyy | 1:3a73d77c2cef | 509 | } |
krebyy | 1:3a73d77c2cef | 510 | /* Open Command IN EP */ |
krebyy | 1:3a73d77c2cef | 511 | USBD_LL_OpenEP(pdev, |
krebyy | 1:3a73d77c2cef | 512 | CDC_CMD_EP, |
krebyy | 1:3a73d77c2cef | 513 | USBD_EP_TYPE_INTR, |
krebyy | 1:3a73d77c2cef | 514 | CDC_CMD_PACKET_SIZE); |
krebyy | 1:3a73d77c2cef | 515 | |
krebyy | 1:3a73d77c2cef | 516 | |
krebyy | 1:3a73d77c2cef | 517 | pdev->pClassData = USBD_malloc(sizeof (USBD_CDC_HandleTypeDef)); |
krebyy | 1:3a73d77c2cef | 518 | |
krebyy | 1:3a73d77c2cef | 519 | if(pdev->pClassData == NULL) |
krebyy | 1:3a73d77c2cef | 520 | { |
krebyy | 1:3a73d77c2cef | 521 | ret = 1; |
krebyy | 1:3a73d77c2cef | 522 | } |
krebyy | 1:3a73d77c2cef | 523 | else |
krebyy | 1:3a73d77c2cef | 524 | { |
krebyy | 1:3a73d77c2cef | 525 | hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
krebyy | 1:3a73d77c2cef | 526 | |
krebyy | 1:3a73d77c2cef | 527 | /* Init physical Interface components */ |
krebyy | 1:3a73d77c2cef | 528 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init(); |
krebyy | 1:3a73d77c2cef | 529 | |
krebyy | 1:3a73d77c2cef | 530 | /* Init Xfer states */ |
krebyy | 1:3a73d77c2cef | 531 | hcdc->TxState =0; |
krebyy | 1:3a73d77c2cef | 532 | hcdc->RxState =0; |
krebyy | 1:3a73d77c2cef | 533 | |
krebyy | 1:3a73d77c2cef | 534 | if(pdev->dev_speed == USBD_SPEED_HIGH ) |
krebyy | 1:3a73d77c2cef | 535 | { |
krebyy | 1:3a73d77c2cef | 536 | /* Prepare Out endpoint to receive next packet */ |
krebyy | 1:3a73d77c2cef | 537 | USBD_LL_PrepareReceive(pdev, |
krebyy | 1:3a73d77c2cef | 538 | CDC_OUT_EP, |
krebyy | 1:3a73d77c2cef | 539 | hcdc->RxBuffer, |
krebyy | 1:3a73d77c2cef | 540 | CDC_DATA_HS_OUT_PACKET_SIZE); |
krebyy | 1:3a73d77c2cef | 541 | } |
krebyy | 1:3a73d77c2cef | 542 | else |
krebyy | 1:3a73d77c2cef | 543 | { |
krebyy | 1:3a73d77c2cef | 544 | /* Prepare Out endpoint to receive next packet */ |
krebyy | 1:3a73d77c2cef | 545 | USBD_LL_PrepareReceive(pdev, |
krebyy | 1:3a73d77c2cef | 546 | CDC_OUT_EP, |
krebyy | 1:3a73d77c2cef | 547 | hcdc->RxBuffer, |
krebyy | 1:3a73d77c2cef | 548 | CDC_DATA_FS_OUT_PACKET_SIZE); |
krebyy | 1:3a73d77c2cef | 549 | } |
krebyy | 1:3a73d77c2cef | 550 | |
krebyy | 1:3a73d77c2cef | 551 | |
krebyy | 1:3a73d77c2cef | 552 | } |
krebyy | 1:3a73d77c2cef | 553 | return ret; |
krebyy | 1:3a73d77c2cef | 554 | } |
krebyy | 1:3a73d77c2cef | 555 | |
krebyy | 1:3a73d77c2cef | 556 | /** |
krebyy | 1:3a73d77c2cef | 557 | * @brief USBD_CDC_Init |
krebyy | 1:3a73d77c2cef | 558 | * DeInitialize the CDC layer |
krebyy | 1:3a73d77c2cef | 559 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 560 | * @param cfgidx: Configuration index |
krebyy | 1:3a73d77c2cef | 561 | * @retval status |
krebyy | 1:3a73d77c2cef | 562 | */ |
krebyy | 1:3a73d77c2cef | 563 | static uint8_t USBD_CDC_DeInit (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 564 | uint8_t cfgidx) |
krebyy | 1:3a73d77c2cef | 565 | { |
krebyy | 1:3a73d77c2cef | 566 | uint8_t ret = 0; |
krebyy | 1:3a73d77c2cef | 567 | |
krebyy | 1:3a73d77c2cef | 568 | /* Open EP IN */ |
krebyy | 1:3a73d77c2cef | 569 | USBD_LL_CloseEP(pdev, |
krebyy | 1:3a73d77c2cef | 570 | CDC_IN_EP); |
krebyy | 1:3a73d77c2cef | 571 | |
krebyy | 1:3a73d77c2cef | 572 | /* Open EP OUT */ |
krebyy | 1:3a73d77c2cef | 573 | USBD_LL_CloseEP(pdev, |
krebyy | 1:3a73d77c2cef | 574 | CDC_OUT_EP); |
krebyy | 1:3a73d77c2cef | 575 | |
krebyy | 1:3a73d77c2cef | 576 | /* Open Command IN EP */ |
krebyy | 1:3a73d77c2cef | 577 | USBD_LL_CloseEP(pdev, |
krebyy | 1:3a73d77c2cef | 578 | CDC_CMD_EP); |
krebyy | 1:3a73d77c2cef | 579 | |
krebyy | 1:3a73d77c2cef | 580 | |
krebyy | 1:3a73d77c2cef | 581 | /* DeInit physical Interface components */ |
krebyy | 1:3a73d77c2cef | 582 | if(pdev->pClassData != NULL) |
krebyy | 1:3a73d77c2cef | 583 | { |
krebyy | 1:3a73d77c2cef | 584 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit(); |
krebyy | 1:3a73d77c2cef | 585 | USBD_free(pdev->pClassData); |
krebyy | 1:3a73d77c2cef | 586 | pdev->pClassData = NULL; |
krebyy | 1:3a73d77c2cef | 587 | } |
krebyy | 1:3a73d77c2cef | 588 | |
krebyy | 1:3a73d77c2cef | 589 | return ret; |
krebyy | 1:3a73d77c2cef | 590 | } |
krebyy | 1:3a73d77c2cef | 591 | |
krebyy | 1:3a73d77c2cef | 592 | /** |
krebyy | 1:3a73d77c2cef | 593 | * @brief USBD_CDC_Setup |
krebyy | 1:3a73d77c2cef | 594 | * Handle the CDC specific requests |
krebyy | 1:3a73d77c2cef | 595 | * @param pdev: instance |
krebyy | 1:3a73d77c2cef | 596 | * @param req: usb requests |
krebyy | 1:3a73d77c2cef | 597 | * @retval status |
krebyy | 1:3a73d77c2cef | 598 | */ |
krebyy | 1:3a73d77c2cef | 599 | static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 600 | USBD_SetupReqTypedef *req) |
krebyy | 1:3a73d77c2cef | 601 | { |
krebyy | 1:3a73d77c2cef | 602 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
krebyy | 1:3a73d77c2cef | 603 | |
krebyy | 1:3a73d77c2cef | 604 | switch (req->bmRequest & USB_REQ_TYPE_MASK) |
krebyy | 1:3a73d77c2cef | 605 | { |
krebyy | 1:3a73d77c2cef | 606 | case USB_REQ_TYPE_CLASS : |
krebyy | 1:3a73d77c2cef | 607 | if (req->wLength) |
krebyy | 1:3a73d77c2cef | 608 | { |
krebyy | 1:3a73d77c2cef | 609 | if (req->bmRequest & 0x80) |
krebyy | 1:3a73d77c2cef | 610 | { |
krebyy | 1:3a73d77c2cef | 611 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, |
krebyy | 1:3a73d77c2cef | 612 | (uint8_t *)hcdc->data, |
krebyy | 1:3a73d77c2cef | 613 | req->wLength); |
krebyy | 1:3a73d77c2cef | 614 | USBD_CtlSendData (pdev, |
krebyy | 1:3a73d77c2cef | 615 | (uint8_t *)hcdc->data, |
krebyy | 1:3a73d77c2cef | 616 | req->wLength); |
krebyy | 1:3a73d77c2cef | 617 | } |
krebyy | 1:3a73d77c2cef | 618 | else |
krebyy | 1:3a73d77c2cef | 619 | { |
krebyy | 1:3a73d77c2cef | 620 | hcdc->CmdOpCode = req->bRequest; |
krebyy | 1:3a73d77c2cef | 621 | hcdc->CmdLength = req->wLength; |
krebyy | 1:3a73d77c2cef | 622 | |
krebyy | 1:3a73d77c2cef | 623 | USBD_CtlPrepareRx (pdev, |
krebyy | 1:3a73d77c2cef | 624 | (uint8_t *)hcdc->data, |
krebyy | 1:3a73d77c2cef | 625 | req->wLength); |
krebyy | 1:3a73d77c2cef | 626 | } |
krebyy | 1:3a73d77c2cef | 627 | |
krebyy | 1:3a73d77c2cef | 628 | } |
krebyy | 1:3a73d77c2cef | 629 | else |
krebyy | 1:3a73d77c2cef | 630 | { |
krebyy | 1:3a73d77c2cef | 631 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, |
krebyy | 1:3a73d77c2cef | 632 | NULL, |
krebyy | 1:3a73d77c2cef | 633 | 0); |
krebyy | 1:3a73d77c2cef | 634 | } |
krebyy | 1:3a73d77c2cef | 635 | break; |
krebyy | 1:3a73d77c2cef | 636 | |
krebyy | 1:3a73d77c2cef | 637 | default: |
krebyy | 1:3a73d77c2cef | 638 | break; |
krebyy | 1:3a73d77c2cef | 639 | } |
krebyy | 1:3a73d77c2cef | 640 | return USBD_OK; |
krebyy | 1:3a73d77c2cef | 641 | } |
krebyy | 1:3a73d77c2cef | 642 | |
krebyy | 1:3a73d77c2cef | 643 | /** |
krebyy | 1:3a73d77c2cef | 644 | * @brief usbd_audio_DataIn |
krebyy | 1:3a73d77c2cef | 645 | * Data sent on non-control IN endpoint |
krebyy | 1:3a73d77c2cef | 646 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 647 | * @param epnum: endpoint number |
krebyy | 1:3a73d77c2cef | 648 | * @retval status |
krebyy | 1:3a73d77c2cef | 649 | */ |
krebyy | 1:3a73d77c2cef | 650 | static uint8_t USBD_CDC_DataIn (USBD_HandleTypeDef *pdev, uint8_t epnum) |
krebyy | 1:3a73d77c2cef | 651 | { |
krebyy | 1:3a73d77c2cef | 652 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
krebyy | 1:3a73d77c2cef | 653 | |
krebyy | 1:3a73d77c2cef | 654 | if(pdev->pClassData != NULL) |
krebyy | 1:3a73d77c2cef | 655 | { |
krebyy | 1:3a73d77c2cef | 656 | |
krebyy | 1:3a73d77c2cef | 657 | hcdc->TxState = 0; |
krebyy | 1:3a73d77c2cef | 658 | |
krebyy | 1:3a73d77c2cef | 659 | return USBD_OK; |
krebyy | 1:3a73d77c2cef | 660 | } |
krebyy | 1:3a73d77c2cef | 661 | else |
krebyy | 1:3a73d77c2cef | 662 | { |
krebyy | 1:3a73d77c2cef | 663 | return USBD_FAIL; |
krebyy | 1:3a73d77c2cef | 664 | } |
krebyy | 1:3a73d77c2cef | 665 | } |
krebyy | 1:3a73d77c2cef | 666 | |
krebyy | 1:3a73d77c2cef | 667 | /** |
krebyy | 1:3a73d77c2cef | 668 | * @brief USBD_CDC_DataOut |
krebyy | 1:3a73d77c2cef | 669 | * Data received on non-control Out endpoint |
krebyy | 1:3a73d77c2cef | 670 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 671 | * @param epnum: endpoint number |
krebyy | 1:3a73d77c2cef | 672 | * @retval status |
krebyy | 1:3a73d77c2cef | 673 | */ |
krebyy | 1:3a73d77c2cef | 674 | static uint8_t USBD_CDC_DataOut (USBD_HandleTypeDef *pdev, uint8_t epnum) |
krebyy | 1:3a73d77c2cef | 675 | { |
krebyy | 1:3a73d77c2cef | 676 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
krebyy | 1:3a73d77c2cef | 677 | |
krebyy | 1:3a73d77c2cef | 678 | /* Get the received data length */ |
krebyy | 1:3a73d77c2cef | 679 | hcdc->RxLength = USBD_LL_GetRxDataSize (pdev, epnum); |
krebyy | 1:3a73d77c2cef | 680 | |
krebyy | 1:3a73d77c2cef | 681 | /* USB data will be immediately processed, this allow next USB traffic being |
krebyy | 1:3a73d77c2cef | 682 | NAKed till the end of the application Xfer */ |
krebyy | 1:3a73d77c2cef | 683 | if(pdev->pClassData != NULL) |
krebyy | 1:3a73d77c2cef | 684 | { |
krebyy | 1:3a73d77c2cef | 685 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength); |
krebyy | 1:3a73d77c2cef | 686 | |
krebyy | 1:3a73d77c2cef | 687 | return USBD_OK; |
krebyy | 1:3a73d77c2cef | 688 | } |
krebyy | 1:3a73d77c2cef | 689 | else |
krebyy | 1:3a73d77c2cef | 690 | { |
krebyy | 1:3a73d77c2cef | 691 | return USBD_FAIL; |
krebyy | 1:3a73d77c2cef | 692 | } |
krebyy | 1:3a73d77c2cef | 693 | } |
krebyy | 1:3a73d77c2cef | 694 | |
krebyy | 1:3a73d77c2cef | 695 | |
krebyy | 1:3a73d77c2cef | 696 | |
krebyy | 1:3a73d77c2cef | 697 | /** |
krebyy | 1:3a73d77c2cef | 698 | * @brief USBD_CDC_DataOut |
krebyy | 1:3a73d77c2cef | 699 | * Data received on non-control Out endpoint |
krebyy | 1:3a73d77c2cef | 700 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 701 | * @param epnum: endpoint number |
krebyy | 1:3a73d77c2cef | 702 | * @retval status |
krebyy | 1:3a73d77c2cef | 703 | */ |
krebyy | 1:3a73d77c2cef | 704 | static uint8_t USBD_CDC_EP0_RxReady (USBD_HandleTypeDef *pdev) |
krebyy | 1:3a73d77c2cef | 705 | { |
krebyy | 1:3a73d77c2cef | 706 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
krebyy | 1:3a73d77c2cef | 707 | |
krebyy | 1:3a73d77c2cef | 708 | if((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFF)) |
krebyy | 1:3a73d77c2cef | 709 | { |
krebyy | 1:3a73d77c2cef | 710 | ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode, |
krebyy | 1:3a73d77c2cef | 711 | (uint8_t *)hcdc->data, |
krebyy | 1:3a73d77c2cef | 712 | hcdc->CmdLength); |
krebyy | 1:3a73d77c2cef | 713 | hcdc->CmdOpCode = 0xFF; |
krebyy | 1:3a73d77c2cef | 714 | |
krebyy | 1:3a73d77c2cef | 715 | } |
krebyy | 1:3a73d77c2cef | 716 | return USBD_OK; |
krebyy | 1:3a73d77c2cef | 717 | } |
krebyy | 1:3a73d77c2cef | 718 | |
krebyy | 1:3a73d77c2cef | 719 | /** |
krebyy | 1:3a73d77c2cef | 720 | * @brief USBD_CDC_GetFSCfgDesc |
krebyy | 1:3a73d77c2cef | 721 | * Return configuration descriptor |
krebyy | 1:3a73d77c2cef | 722 | * @param speed : current device speed |
krebyy | 1:3a73d77c2cef | 723 | * @param length : pointer data length |
krebyy | 1:3a73d77c2cef | 724 | * @retval pointer to descriptor buffer |
krebyy | 1:3a73d77c2cef | 725 | */ |
krebyy | 1:3a73d77c2cef | 726 | static uint8_t *USBD_CDC_GetFSCfgDesc (uint16_t *length) |
krebyy | 1:3a73d77c2cef | 727 | { |
krebyy | 1:3a73d77c2cef | 728 | *length = sizeof (USBD_CDC_CfgFSDesc); |
krebyy | 1:3a73d77c2cef | 729 | return USBD_CDC_CfgFSDesc; |
krebyy | 1:3a73d77c2cef | 730 | } |
krebyy | 1:3a73d77c2cef | 731 | |
krebyy | 1:3a73d77c2cef | 732 | /** |
krebyy | 1:3a73d77c2cef | 733 | * @brief USBD_CDC_GetHSCfgDesc |
krebyy | 1:3a73d77c2cef | 734 | * Return configuration descriptor |
krebyy | 1:3a73d77c2cef | 735 | * @param speed : current device speed |
krebyy | 1:3a73d77c2cef | 736 | * @param length : pointer data length |
krebyy | 1:3a73d77c2cef | 737 | * @retval pointer to descriptor buffer |
krebyy | 1:3a73d77c2cef | 738 | */ |
krebyy | 1:3a73d77c2cef | 739 | static uint8_t *USBD_CDC_GetHSCfgDesc (uint16_t *length) |
krebyy | 1:3a73d77c2cef | 740 | { |
krebyy | 1:3a73d77c2cef | 741 | *length = sizeof (USBD_CDC_CfgHSDesc); |
krebyy | 1:3a73d77c2cef | 742 | return USBD_CDC_CfgHSDesc; |
krebyy | 1:3a73d77c2cef | 743 | } |
krebyy | 1:3a73d77c2cef | 744 | |
krebyy | 1:3a73d77c2cef | 745 | /** |
krebyy | 1:3a73d77c2cef | 746 | * @brief USBD_CDC_GetCfgDesc |
krebyy | 1:3a73d77c2cef | 747 | * Return configuration descriptor |
krebyy | 1:3a73d77c2cef | 748 | * @param speed : current device speed |
krebyy | 1:3a73d77c2cef | 749 | * @param length : pointer data length |
krebyy | 1:3a73d77c2cef | 750 | * @retval pointer to descriptor buffer |
krebyy | 1:3a73d77c2cef | 751 | */ |
krebyy | 1:3a73d77c2cef | 752 | static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc (uint16_t *length) |
krebyy | 1:3a73d77c2cef | 753 | { |
krebyy | 1:3a73d77c2cef | 754 | *length = sizeof (USBD_CDC_OtherSpeedCfgDesc); |
krebyy | 1:3a73d77c2cef | 755 | return USBD_CDC_OtherSpeedCfgDesc; |
krebyy | 1:3a73d77c2cef | 756 | } |
krebyy | 1:3a73d77c2cef | 757 | |
krebyy | 1:3a73d77c2cef | 758 | /** |
krebyy | 1:3a73d77c2cef | 759 | * @brief DeviceQualifierDescriptor |
krebyy | 1:3a73d77c2cef | 760 | * return Device Qualifier descriptor |
krebyy | 1:3a73d77c2cef | 761 | * @param length : pointer data length |
krebyy | 1:3a73d77c2cef | 762 | * @retval pointer to descriptor buffer |
krebyy | 1:3a73d77c2cef | 763 | */ |
krebyy | 1:3a73d77c2cef | 764 | uint8_t *USBD_CDC_GetDeviceQualifierDescriptor (uint16_t *length) |
krebyy | 1:3a73d77c2cef | 765 | { |
krebyy | 1:3a73d77c2cef | 766 | *length = sizeof (USBD_CDC_DeviceQualifierDesc); |
krebyy | 1:3a73d77c2cef | 767 | return USBD_CDC_DeviceQualifierDesc; |
krebyy | 1:3a73d77c2cef | 768 | } |
krebyy | 1:3a73d77c2cef | 769 | |
krebyy | 1:3a73d77c2cef | 770 | /** |
krebyy | 1:3a73d77c2cef | 771 | * @brief USBD_CDC_RegisterInterface |
krebyy | 1:3a73d77c2cef | 772 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 773 | * @param fops: CD Interface callback |
krebyy | 1:3a73d77c2cef | 774 | * @retval status |
krebyy | 1:3a73d77c2cef | 775 | */ |
krebyy | 1:3a73d77c2cef | 776 | uint8_t USBD_CDC_RegisterInterface (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 777 | USBD_CDC_ItfTypeDef *fops) |
krebyy | 1:3a73d77c2cef | 778 | { |
krebyy | 1:3a73d77c2cef | 779 | uint8_t ret = USBD_FAIL; |
krebyy | 1:3a73d77c2cef | 780 | |
krebyy | 1:3a73d77c2cef | 781 | if(fops != NULL) |
krebyy | 1:3a73d77c2cef | 782 | { |
krebyy | 1:3a73d77c2cef | 783 | pdev->pUserData= fops; |
krebyy | 1:3a73d77c2cef | 784 | ret = USBD_OK; |
krebyy | 1:3a73d77c2cef | 785 | } |
krebyy | 1:3a73d77c2cef | 786 | |
krebyy | 1:3a73d77c2cef | 787 | return ret; |
krebyy | 1:3a73d77c2cef | 788 | } |
krebyy | 1:3a73d77c2cef | 789 | |
krebyy | 1:3a73d77c2cef | 790 | /** |
krebyy | 1:3a73d77c2cef | 791 | * @brief USBD_CDC_SetTxBuffer |
krebyy | 1:3a73d77c2cef | 792 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 793 | * @param pbuff: Tx Buffer |
krebyy | 1:3a73d77c2cef | 794 | * @retval status |
krebyy | 1:3a73d77c2cef | 795 | */ |
krebyy | 1:3a73d77c2cef | 796 | uint8_t USBD_CDC_SetTxBuffer (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 797 | uint8_t *pbuff, |
krebyy | 1:3a73d77c2cef | 798 | uint16_t length) |
krebyy | 1:3a73d77c2cef | 799 | { |
krebyy | 1:3a73d77c2cef | 800 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
krebyy | 1:3a73d77c2cef | 801 | |
krebyy | 1:3a73d77c2cef | 802 | hcdc->TxBuffer = pbuff; |
krebyy | 1:3a73d77c2cef | 803 | hcdc->TxLength = length; |
krebyy | 1:3a73d77c2cef | 804 | |
krebyy | 1:3a73d77c2cef | 805 | return USBD_OK; |
krebyy | 1:3a73d77c2cef | 806 | } |
krebyy | 1:3a73d77c2cef | 807 | |
krebyy | 1:3a73d77c2cef | 808 | |
krebyy | 1:3a73d77c2cef | 809 | /** |
krebyy | 1:3a73d77c2cef | 810 | * @brief USBD_CDC_SetRxBuffer |
krebyy | 1:3a73d77c2cef | 811 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 812 | * @param pbuff: Rx Buffer |
krebyy | 1:3a73d77c2cef | 813 | * @retval status |
krebyy | 1:3a73d77c2cef | 814 | */ |
krebyy | 1:3a73d77c2cef | 815 | uint8_t USBD_CDC_SetRxBuffer (USBD_HandleTypeDef *pdev, |
krebyy | 1:3a73d77c2cef | 816 | uint8_t *pbuff) |
krebyy | 1:3a73d77c2cef | 817 | { |
krebyy | 1:3a73d77c2cef | 818 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
krebyy | 1:3a73d77c2cef | 819 | |
krebyy | 1:3a73d77c2cef | 820 | hcdc->RxBuffer = pbuff; |
krebyy | 1:3a73d77c2cef | 821 | |
krebyy | 1:3a73d77c2cef | 822 | return USBD_OK; |
krebyy | 1:3a73d77c2cef | 823 | } |
krebyy | 1:3a73d77c2cef | 824 | |
krebyy | 1:3a73d77c2cef | 825 | /** |
krebyy | 1:3a73d77c2cef | 826 | * @brief USBD_CDC_DataOut |
krebyy | 1:3a73d77c2cef | 827 | * Data received on non-control Out endpoint |
krebyy | 1:3a73d77c2cef | 828 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 829 | * @param epnum: endpoint number |
krebyy | 1:3a73d77c2cef | 830 | * @retval status |
krebyy | 1:3a73d77c2cef | 831 | */ |
krebyy | 1:3a73d77c2cef | 832 | uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev) |
krebyy | 1:3a73d77c2cef | 833 | { |
krebyy | 1:3a73d77c2cef | 834 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
krebyy | 1:3a73d77c2cef | 835 | |
krebyy | 1:3a73d77c2cef | 836 | if(pdev->pClassData != NULL) |
krebyy | 1:3a73d77c2cef | 837 | { |
krebyy | 1:3a73d77c2cef | 838 | if(hcdc->TxState == 0) |
krebyy | 1:3a73d77c2cef | 839 | { |
krebyy | 1:3a73d77c2cef | 840 | /* Tx Transfer in progress */ |
krebyy | 1:3a73d77c2cef | 841 | hcdc->TxState = 1; |
krebyy | 1:3a73d77c2cef | 842 | |
krebyy | 1:3a73d77c2cef | 843 | /* Transmit next packet */ |
krebyy | 1:3a73d77c2cef | 844 | USBD_LL_Transmit(pdev, |
krebyy | 1:3a73d77c2cef | 845 | CDC_IN_EP, |
krebyy | 1:3a73d77c2cef | 846 | hcdc->TxBuffer, |
krebyy | 1:3a73d77c2cef | 847 | hcdc->TxLength); |
krebyy | 1:3a73d77c2cef | 848 | |
krebyy | 1:3a73d77c2cef | 849 | return USBD_OK; |
krebyy | 1:3a73d77c2cef | 850 | } |
krebyy | 1:3a73d77c2cef | 851 | else |
krebyy | 1:3a73d77c2cef | 852 | { |
krebyy | 1:3a73d77c2cef | 853 | return USBD_BUSY; |
krebyy | 1:3a73d77c2cef | 854 | } |
krebyy | 1:3a73d77c2cef | 855 | } |
krebyy | 1:3a73d77c2cef | 856 | else |
krebyy | 1:3a73d77c2cef | 857 | { |
krebyy | 1:3a73d77c2cef | 858 | return USBD_FAIL; |
krebyy | 1:3a73d77c2cef | 859 | } |
krebyy | 1:3a73d77c2cef | 860 | } |
krebyy | 1:3a73d77c2cef | 861 | |
krebyy | 1:3a73d77c2cef | 862 | |
krebyy | 1:3a73d77c2cef | 863 | /** |
krebyy | 1:3a73d77c2cef | 864 | * @brief USBD_CDC_ReceivePacket |
krebyy | 1:3a73d77c2cef | 865 | * prepare OUT Endpoint for reception |
krebyy | 1:3a73d77c2cef | 866 | * @param pdev: device instance |
krebyy | 1:3a73d77c2cef | 867 | * @retval status |
krebyy | 1:3a73d77c2cef | 868 | */ |
krebyy | 1:3a73d77c2cef | 869 | uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev) |
krebyy | 1:3a73d77c2cef | 870 | { |
krebyy | 1:3a73d77c2cef | 871 | USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; |
krebyy | 1:3a73d77c2cef | 872 | |
krebyy | 1:3a73d77c2cef | 873 | /* Suspend or Resume USB Out process */ |
krebyy | 1:3a73d77c2cef | 874 | if(pdev->pClassData != NULL) |
krebyy | 1:3a73d77c2cef | 875 | { |
krebyy | 1:3a73d77c2cef | 876 | if(pdev->dev_speed == USBD_SPEED_HIGH ) |
krebyy | 1:3a73d77c2cef | 877 | { |
krebyy | 1:3a73d77c2cef | 878 | /* Prepare Out endpoint to receive next packet */ |
krebyy | 1:3a73d77c2cef | 879 | USBD_LL_PrepareReceive(pdev, |
krebyy | 1:3a73d77c2cef | 880 | CDC_OUT_EP, |
krebyy | 1:3a73d77c2cef | 881 | hcdc->RxBuffer, |
krebyy | 1:3a73d77c2cef | 882 | CDC_DATA_HS_OUT_PACKET_SIZE); |
krebyy | 1:3a73d77c2cef | 883 | } |
krebyy | 1:3a73d77c2cef | 884 | else |
krebyy | 1:3a73d77c2cef | 885 | { |
krebyy | 1:3a73d77c2cef | 886 | /* Prepare Out endpoint to receive next packet */ |
krebyy | 1:3a73d77c2cef | 887 | USBD_LL_PrepareReceive(pdev, |
krebyy | 1:3a73d77c2cef | 888 | CDC_OUT_EP, |
krebyy | 1:3a73d77c2cef | 889 | hcdc->RxBuffer, |
krebyy | 1:3a73d77c2cef | 890 | CDC_DATA_FS_OUT_PACKET_SIZE); |
krebyy | 1:3a73d77c2cef | 891 | } |
krebyy | 1:3a73d77c2cef | 892 | return USBD_OK; |
krebyy | 1:3a73d77c2cef | 893 | } |
krebyy | 1:3a73d77c2cef | 894 | else |
krebyy | 1:3a73d77c2cef | 895 | { |
krebyy | 1:3a73d77c2cef | 896 | return USBD_FAIL; |
krebyy | 1:3a73d77c2cef | 897 | } |
krebyy | 1:3a73d77c2cef | 898 | } |
krebyy | 1:3a73d77c2cef | 899 | /** |
krebyy | 1:3a73d77c2cef | 900 | * @} |
krebyy | 1:3a73d77c2cef | 901 | */ |
krebyy | 1:3a73d77c2cef | 902 | |
krebyy | 1:3a73d77c2cef | 903 | /** |
krebyy | 1:3a73d77c2cef | 904 | * @} |
krebyy | 1:3a73d77c2cef | 905 | */ |
krebyy | 1:3a73d77c2cef | 906 | |
krebyy | 1:3a73d77c2cef | 907 | /** |
krebyy | 1:3a73d77c2cef | 908 | * @} |
krebyy | 1:3a73d77c2cef | 909 | */ |
krebyy | 1:3a73d77c2cef | 910 | |
krebyy | 1:3a73d77c2cef | 911 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |