Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /** |
| 2 | ****************************************************************************** |
||
| 3 | * @file usbd_cdc_if_template.c |
||
| 4 | * @author MCD Application Team |
||
| 5 | * @version V2.4.1 |
||
| 6 | * @date 19-June-2015 |
||
| 7 | * @brief Generic media access Layer. |
||
| 8 | ****************************************************************************** |
||
| 9 | * @attention |
||
| 10 | * |
||
| 11 | * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> |
||
| 12 | * |
||
| 13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
||
| 14 | * You may not use this file except in compliance with the License. |
||
| 15 | * You may obtain a copy of the License at: |
||
| 16 | * |
||
| 17 | * http://www.st.com/software_license_agreement_liberty_v2 |
||
| 18 | * |
||
| 19 | * Unless required by applicable law or agreed to in writing, software |
||
| 20 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
| 21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
| 22 | * See the License for the specific language governing permissions and |
||
| 23 | * limitations under the License. |
||
| 24 | * |
||
| 25 | ****************************************************************************** |
||
| 26 | */ |
||
| 27 | |||
| 28 | /* Includes ------------------------------------------------------------------*/ |
||
| 29 | #include "usbd_cdc_if_template.h" |
||
| 30 | |||
| 31 | /** @addtogroup STM32_USB_DEVICE_LIBRARY |
||
| 32 | * @{ |
||
| 33 | */ |
||
| 34 | |||
| 35 | |||
| 36 | /** @defgroup USBD_CDC |
||
| 37 | * @brief usbd core module |
||
| 38 | * @{ |
||
| 39 | */ |
||
| 40 | |||
| 41 | /** @defgroup USBD_CDC_Private_TypesDefinitions |
||
| 42 | * @{ |
||
| 43 | */ |
||
| 44 | /** |
||
| 45 | * @} |
||
| 46 | */ |
||
| 47 | |||
| 48 | |||
| 49 | /** @defgroup USBD_CDC_Private_Defines |
||
| 50 | * @{ |
||
| 51 | */ |
||
| 52 | /** |
||
| 53 | * @} |
||
| 54 | */ |
||
| 55 | |||
| 56 | |||
| 57 | /** @defgroup USBD_CDC_Private_Macros |
||
| 58 | * @{ |
||
| 59 | */ |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @} |
||
| 63 | */ |
||
| 64 | |||
| 65 | |||
| 66 | /** @defgroup USBD_CDC_Private_FunctionPrototypes |
||
| 67 | * @{ |
||
| 68 | */ |
||
| 69 | |||
| 70 | static int8_t TEMPLATE_Init (void); |
||
| 71 | static int8_t TEMPLATE_DeInit (void); |
||
| 72 | static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length); |
||
| 73 | static int8_t TEMPLATE_Receive (uint8_t* pbuf, uint32_t *Len); |
||
| 74 | |||
| 75 | USBD_CDC_ItfTypeDef USBD_CDC_Template_fops = |
||
| 76 | { |
||
| 77 | TEMPLATE_Init, |
||
| 78 | TEMPLATE_DeInit, |
||
| 79 | TEMPLATE_Control, |
||
| 80 | TEMPLATE_Receive |
||
| 81 | }; |
||
| 82 | |||
| 83 | USBD_CDC_LineCodingTypeDef linecoding = |
||
| 84 | { |
||
| 85 | 115200, /* baud rate*/ |
||
| 86 | 0x00, /* stop bits-1*/ |
||
| 87 | 0x00, /* parity - none*/ |
||
| 88 | 0x08 /* nb. of bits 8*/ |
||
| 89 | }; |
||
| 90 | |||
| 91 | /* Private functions ---------------------------------------------------------*/ |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @brief TEMPLATE_Init |
||
| 95 | * Initializes the CDC media low layer |
||
| 96 | * @param None |
||
| 97 | * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL |
||
| 98 | */ |
||
| 99 | static int8_t TEMPLATE_Init(void) |
||
| 100 | { |
||
| 101 | /* |
||
| 102 | Add your initialization code here |
||
| 103 | */ |
||
| 104 | return (0); |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @brief TEMPLATE_DeInit |
||
| 109 | * DeInitializes the CDC media low layer |
||
| 110 | * @param None |
||
| 111 | * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL |
||
| 112 | */ |
||
| 113 | static int8_t TEMPLATE_DeInit(void) |
||
| 114 | { |
||
| 115 | /* |
||
| 116 | Add your deinitialization code here |
||
| 117 | */ |
||
| 118 | return (0); |
||
| 119 | } |
||
| 120 | |||
| 121 | |||
| 122 | /** |
||
| 123 | * @brief TEMPLATE_Control |
||
| 124 | * Manage the CDC class requests |
||
| 125 | * @param Cmd: Command code |
||
| 126 | * @param Buf: Buffer containing command data (request parameters) |
||
| 127 | * @param Len: Number of data to be sent (in bytes) |
||
| 128 | * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL |
||
| 129 | */ |
||
| 130 | static int8_t TEMPLATE_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length) |
||
| 131 | { |
||
| 132 | switch (cmd) |
||
| 133 | { |
||
| 134 | case CDC_SEND_ENCAPSULATED_COMMAND: |
||
| 135 | /* Add your code here */ |
||
| 136 | break; |
||
| 137 | |||
| 138 | case CDC_GET_ENCAPSULATED_RESPONSE: |
||
| 139 | /* Add your code here */ |
||
| 140 | break; |
||
| 141 | |||
| 142 | case CDC_SET_COMM_FEATURE: |
||
| 143 | /* Add your code here */ |
||
| 144 | break; |
||
| 145 | |||
| 146 | case CDC_GET_COMM_FEATURE: |
||
| 147 | /* Add your code here */ |
||
| 148 | break; |
||
| 149 | |||
| 150 | case CDC_CLEAR_COMM_FEATURE: |
||
| 151 | /* Add your code here */ |
||
| 152 | break; |
||
| 153 | |||
| 154 | case CDC_SET_LINE_CODING: |
||
| 155 | linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\ |
||
| 156 | (pbuf[2] << 16) | (pbuf[3] << 24)); |
||
| 157 | linecoding.format = pbuf[4]; |
||
| 158 | linecoding.paritytype = pbuf[5]; |
||
| 159 | linecoding.datatype = pbuf[6]; |
||
| 160 | |||
| 161 | /* Add your code here */ |
||
| 162 | break; |
||
| 163 | |||
| 164 | case CDC_GET_LINE_CODING: |
||
| 165 | pbuf[0] = (uint8_t)(linecoding.bitrate); |
||
| 166 | pbuf[1] = (uint8_t)(linecoding.bitrate >> 8); |
||
| 167 | pbuf[2] = (uint8_t)(linecoding.bitrate >> 16); |
||
| 168 | pbuf[3] = (uint8_t)(linecoding.bitrate >> 24); |
||
| 169 | pbuf[4] = linecoding.format; |
||
| 170 | pbuf[5] = linecoding.paritytype; |
||
| 171 | pbuf[6] = linecoding.datatype; |
||
| 172 | |||
| 173 | /* Add your code here */ |
||
| 174 | break; |
||
| 175 | |||
| 176 | case CDC_SET_CONTROL_LINE_STATE: |
||
| 177 | /* Add your code here */ |
||
| 178 | break; |
||
| 179 | |||
| 180 | case CDC_SEND_BREAK: |
||
| 181 | /* Add your code here */ |
||
| 182 | break; |
||
| 183 | |||
| 184 | default: |
||
| 185 | break; |
||
| 186 | } |
||
| 187 | |||
| 188 | return (0); |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @brief TEMPLATE_Receive |
||
| 193 | * Data received over USB OUT endpoint are sent over CDC interface |
||
| 194 | * through this function. |
||
| 195 | * |
||
| 196 | * @note |
||
| 197 | * This function will issue a NAK packet on any OUT packet received on |
||
| 198 | * USB endpoint untill exiting this function. If you exit this function |
||
| 199 | * before transfer is complete on CDC interface (ie. using DMA controller) |
||
| 200 | * it will result in receiving more data while previous ones are still |
||
| 201 | * not sent. |
||
| 202 | * |
||
| 203 | * @param Buf: Buffer of data to be received |
||
| 204 | * @param Len: Number of data received (in bytes) |
||
| 205 | * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL |
||
| 206 | */ |
||
| 207 | static int8_t TEMPLATE_Receive (uint8_t* Buf, uint32_t *Len) |
||
| 208 | { |
||
| 209 | |||
| 210 | return (0); |
||
| 211 | } |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @} |
||
| 215 | */ |
||
| 216 | |||
| 217 | /** |
||
| 218 | * @} |
||
| 219 | */ |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @} |
||
| 223 | */ |
||
| 224 | |||
| 225 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
||
| 226 |