|
52 | 52 | /* Private macro -------------------------------------------------------------*/ |
53 | 53 | /* Private variables ---------------------------------------------------------*/ |
54 | 54 |
|
| 55 | +static uint8_t dev_is_connected = 0; // indicates if we are connected |
| 56 | + |
55 | 57 | static uint8_t UserRxBuffer[APP_RX_DATA_SIZE]; // received data from USB OUT endpoint is stored in this buffer |
56 | 58 | static uint16_t UserRxBufCur = 0; // points to next available character in UserRxBuffer |
57 | 59 | static uint16_t UserRxBufLen = 0; // counts number of valid characters in UserRxBuffer |
@@ -174,76 +176,73 @@ static int8_t CDC_Itf_DeInit(void) |
174 | 176 | * @param Len: Number of data to be sent (in bytes) |
175 | 177 | * @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL |
176 | 178 | */ |
177 | | -static int8_t CDC_Itf_Control (uint8_t cmd, uint8_t* pbuf, uint16_t length) |
178 | | -{ |
179 | | - switch (cmd) |
180 | | - { |
181 | | - case CDC_SEND_ENCAPSULATED_COMMAND: |
182 | | - /* Add your code here */ |
183 | | - break; |
184 | | - |
185 | | - case CDC_GET_ENCAPSULATED_RESPONSE: |
186 | | - /* Add your code here */ |
187 | | - break; |
188 | | - |
189 | | - case CDC_SET_COMM_FEATURE: |
190 | | - /* Add your code here */ |
191 | | - break; |
192 | | - |
193 | | - case CDC_GET_COMM_FEATURE: |
194 | | - /* Add your code here */ |
195 | | - break; |
196 | | - |
197 | | - case CDC_CLEAR_COMM_FEATURE: |
198 | | - /* Add your code here */ |
199 | | - break; |
200 | | - |
201 | | - case CDC_SET_LINE_CODING: |
202 | | - #if 0 |
203 | | - LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\ |
204 | | - (pbuf[2] << 16) | (pbuf[3] << 24)); |
205 | | - LineCoding.format = pbuf[4]; |
206 | | - LineCoding.paritytype = pbuf[5]; |
207 | | - LineCoding.datatype = pbuf[6]; |
208 | | - |
209 | | - /* Set the new configuration */ |
210 | | - #endif |
211 | | - break; |
212 | | - |
213 | | - case CDC_GET_LINE_CODING: |
214 | | - #if 0 |
215 | | - pbuf[0] = (uint8_t)(LineCoding.bitrate); |
216 | | - pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8); |
217 | | - pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16); |
218 | | - pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24); |
219 | | - pbuf[4] = LineCoding.format; |
220 | | - pbuf[5] = LineCoding.paritytype; |
221 | | - pbuf[6] = LineCoding.datatype; |
222 | | - #endif |
223 | | - |
224 | | - /* Add your code here */ |
225 | | - pbuf[0] = (uint8_t)(115200); |
226 | | - pbuf[1] = (uint8_t)(115200 >> 8); |
227 | | - pbuf[2] = (uint8_t)(115200 >> 16); |
228 | | - pbuf[3] = (uint8_t)(115200 >> 24); |
229 | | - pbuf[4] = 0; // stop bits (1) |
230 | | - pbuf[5] = 0; // parity (none) |
231 | | - pbuf[6] = 8; // number of bits (8) |
232 | | - break; |
233 | | - |
234 | | - case CDC_SET_CONTROL_LINE_STATE: |
235 | | - /* Add your code here */ |
236 | | - break; |
237 | | - |
238 | | - case CDC_SEND_BREAK: |
239 | | - /* Add your code here */ |
240 | | - break; |
241 | | - |
242 | | - default: |
243 | | - break; |
244 | | - } |
245 | | - |
246 | | - return (USBD_OK); |
| 179 | +static int8_t CDC_Itf_Control(uint8_t cmd, uint8_t* pbuf, uint16_t length) { |
| 180 | + switch (cmd) { |
| 181 | + case CDC_SEND_ENCAPSULATED_COMMAND: |
| 182 | + /* Add your code here */ |
| 183 | + break; |
| 184 | + |
| 185 | + case CDC_GET_ENCAPSULATED_RESPONSE: |
| 186 | + /* Add your code here */ |
| 187 | + break; |
| 188 | + |
| 189 | + case CDC_SET_COMM_FEATURE: |
| 190 | + /* Add your code here */ |
| 191 | + break; |
| 192 | + |
| 193 | + case CDC_GET_COMM_FEATURE: |
| 194 | + /* Add your code here */ |
| 195 | + break; |
| 196 | + |
| 197 | + case CDC_CLEAR_COMM_FEATURE: |
| 198 | + /* Add your code here */ |
| 199 | + break; |
| 200 | + |
| 201 | + case CDC_SET_LINE_CODING: |
| 202 | + #if 0 |
| 203 | + LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) |\ |
| 204 | + (pbuf[2] << 16) | (pbuf[3] << 24)); |
| 205 | + LineCoding.format = pbuf[4]; |
| 206 | + LineCoding.paritytype = pbuf[5]; |
| 207 | + LineCoding.datatype = pbuf[6]; |
| 208 | + /* Set the new configuration */ |
| 209 | + #endif |
| 210 | + break; |
| 211 | + |
| 212 | + case CDC_GET_LINE_CODING: |
| 213 | + #if 0 |
| 214 | + pbuf[0] = (uint8_t)(LineCoding.bitrate); |
| 215 | + pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8); |
| 216 | + pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16); |
| 217 | + pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24); |
| 218 | + pbuf[4] = LineCoding.format; |
| 219 | + pbuf[5] = LineCoding.paritytype; |
| 220 | + pbuf[6] = LineCoding.datatype; |
| 221 | + #endif |
| 222 | + |
| 223 | + /* Add your code here */ |
| 224 | + pbuf[0] = (uint8_t)(115200); |
| 225 | + pbuf[1] = (uint8_t)(115200 >> 8); |
| 226 | + pbuf[2] = (uint8_t)(115200 >> 16); |
| 227 | + pbuf[3] = (uint8_t)(115200 >> 24); |
| 228 | + pbuf[4] = 0; // stop bits (1) |
| 229 | + pbuf[5] = 0; // parity (none) |
| 230 | + pbuf[6] = 8; // number of bits (8) |
| 231 | + break; |
| 232 | + |
| 233 | + case CDC_SET_CONTROL_LINE_STATE: |
| 234 | + dev_is_connected = length & 1; // wValue is passed in Len (bit of a hack) |
| 235 | + break; |
| 236 | + |
| 237 | + case CDC_SEND_BREAK: |
| 238 | + /* Add your code here */ |
| 239 | + break; |
| 240 | + |
| 241 | + default: |
| 242 | + break; |
| 243 | + } |
| 244 | + |
| 245 | + return USBD_OK; |
247 | 246 | } |
248 | 247 |
|
249 | 248 | /** |
@@ -339,6 +338,10 @@ static int8_t CDC_Itf_Receive(uint8_t* Buf, uint32_t *Len) { |
339 | 338 | return (USBD_OK); |
340 | 339 | } |
341 | 340 |
|
| 341 | +int USBD_CDC_IsConnected(void) { |
| 342 | + return dev_is_connected; |
| 343 | +} |
| 344 | + |
342 | 345 | void USBD_CDC_SetInterrupt(int chr, void *data) { |
343 | 346 | user_interrupt_char = chr; |
344 | 347 | user_interrupt_data = data; |
|
0 commit comments