Advertisement
icis4

Untitled

Aug 8th, 2020
1,079
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.46 KB | None | 0 0
  1. /**
  2.   * @brief  Manage the CDC class requests
  3.   * @param  cmd: Command code
  4.   * @param  pbuf: Buffer containing command data (request parameters)
  5.   * @param  length: Number of data to be sent (in bytes)
  6.   * @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
  7.   */
  8. static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
  9. {
  10.   /* USER CODE BEGIN 10 */
  11.     USBD_CDC_LineCodingTypeDef linecoding = {
  12.             9600, /* baud rate*/
  13.             0x00,   /* stop bits-1*/
  14.             0x00,   /* parity - none*/
  15.             0x08    /* nb. of bits 8*/
  16.     };
  17.  
  18.     switch (cmd) {
  19.     case CDC_SET_LINE_CODING:
  20.         linecoding.bitrate = (uint32_t) (pbuf[0] | (pbuf[1] << 8)
  21.                 | (pbuf[2] << 16) | (pbuf[3] << 24));
  22.         linecoding.format = pbuf[4];
  23.         linecoding.paritytype = pbuf[5];
  24.         linecoding.datatype = pbuf[6];
  25.         break;
  26.  
  27.     case CDC_GET_LINE_CODING:
  28.         pbuf[0] = (uint8_t) (linecoding.bitrate);
  29.         pbuf[1] = (uint8_t) (linecoding.bitrate >> 8);
  30.         pbuf[2] = (uint8_t) (linecoding.bitrate >> 16);
  31.         pbuf[3] = (uint8_t) (linecoding.bitrate >> 24);
  32.         pbuf[4] = linecoding.format;
  33.         pbuf[5] = linecoding.paritytype;
  34.         pbuf[6] = linecoding.datatype;
  35.         break;
  36.  
  37.     /* case CDC_SEND_ENCAPSULATED_COMMAND:
  38.     case CDC_GET_ENCAPSULATED_RESPONSE:
  39.     case CDC_SET_COMM_FEATURE:
  40.     case CDC_GET_COMM_FEATURE:
  41.     case CDC_CLEAR_COMM_FEATURE:
  42.     case CDC_SET_CONTROL_LINE_STATE:
  43.     case CDC_SEND_BREAK: */
  44.     default:
  45.         break;
  46.     }
  47.  
  48.     return (USBD_OK);
  49.   /* USER CODE END 10 */
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement