diff --git a/Src/usbd_cdc_if.c b/Src/usbd_cdc_if.c index a0a0ec8..5b34c26 100644 --- a/Src/usbd_cdc_if.c +++ b/Src/usbd_cdc_if.c @@ -51,6 +51,10 @@ #include "usbd_cdc_if.h" /* USER CODE BEGIN INCLUDE */ +#include "UsbPort.h" +#include "main.h" +#include "cmsis_os.h" +extern osMessageQId ioEventQueueHandle; /* USER CODE END INCLUDE */ @@ -93,8 +97,8 @@ /* USER CODE BEGIN PRIVATE_DEFINES */ /* Define size for the receive and transmit buffer over CDC */ /* It's up to user to redefine and/or remove those define */ -#define APP_RX_DATA_SIZE 1000 -#define APP_TX_DATA_SIZE 1000 +#define APP_RX_DATA_SIZE 64 +#define APP_TX_DATA_SIZE 64 /* USER CODE END PRIVATE_DEFINES */ /** @@ -127,6 +131,12 @@ uint8_t UserRxBufferFS[APP_RX_DATA_SIZE]; uint8_t UserTxBufferFS[APP_TX_DATA_SIZE]; /* USER CODE BEGIN PRIVATE_VARIABLES */ +USBD_CDC_LineCodingTypeDef LineCoding = { + 115200, // baud rate + 0x00, // stop bits: 1 + 0x00, // parity: none + 0x08 // number of bits: 8 +}; /* USER CODE END PRIVATE_VARIABLES */ @@ -251,16 +261,32 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) /* 6 | bDataBits | 1 | Number Data bits (5, 6, 7, 8 or 16). */ /*******************************************************************************/ case CDC_SET_LINE_CODING: - - break; + LineCoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | (pbuf[2] << 16) | (pbuf[3] << 24)); + LineCoding.format = pbuf[4]; + LineCoding.paritytype = pbuf[5]; + LineCoding.datatype = pbuf[6]; + break; case CDC_GET_LINE_CODING: - - break; + pbuf[0] = (uint8_t)(LineCoding.bitrate); + pbuf[1] = (uint8_t)(LineCoding.bitrate >> 8); + pbuf[2] = (uint8_t)(LineCoding.bitrate >> 16); + pbuf[3] = (uint8_t)(LineCoding.bitrate >> 24); + pbuf[4] = LineCoding.format; + pbuf[5] = LineCoding.paritytype; + pbuf[6] = LineCoding.datatype; + break; case CDC_SET_CONTROL_LINE_STATE: - - break; + if (length == 0) { + USBD_SetupReqTypedef* req = (USBD_SetupReqTypedef*) pbuf; + if (req->wValue & 1) { + osMessagePut(ioEventQueueHandle, CMD_USB_CDC_CONNECT, 0); + } else { + osMessagePut(ioEventQueueHandle, CMD_USB_CDC_DISCONNECT, 0); + } + } + break; case CDC_SEND_BREAK: @@ -291,6 +317,7 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length) static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len) { /* USER CODE BEGIN 6 */ + cdc_receive(Buf, *Len); USBD_CDC_SetRxBuffer(&hUsbDeviceFS, &Buf[0]); USBD_CDC_ReceivePacket(&hUsbDeviceFS); return (USBD_OK);