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