USB_DEVICE_CDC_EVENT_RESPONSE APP_USBDeviceCDCEventHandler ( USB_DEVICE_CDC_INDEX index , USB_DEVICE_CDC_EVENT event , void * pData, uintptr_t userData ) { APP2_DATA * app2DataObject; app2DataObject = (APP2_DATA *)userData; USB_CDC_CONTROL_LINE_STATE * controlLineStateData; switch ( event ) { case USB_DEVICE_CDC_EVENT_GET_LINE_CODING: /* This means the host wants to know the current line * coding. This is a control transfer request. Use the * USB_DEVICE_ControlSend() function to send the data to * host. */ USB_DEVICE_ControlSend(app2DataObject->deviceHandle, &app2DataObject->getLineCodingData, sizeof(USB_CDC_LINE_CODING)); break; case USB_DEVICE_CDC_EVENT_SET_LINE_CODING: /* This means the host wants to set the line coding. * This is a control transfer request. Use the * USB_DEVICE_ControlReceive() function to receive the * data from the host */ USB_DEVICE_ControlReceive(app2DataObject->deviceHandle, &app2DataObject->setLineCodingData, sizeof(USB_CDC_LINE_CODING)); break; case USB_DEVICE_CDC_EVENT_SET_CONTROL_LINE_STATE: /* This means the host is setting the control line state. * Read the control line state. We will accept this request * for now. */ controlLineStateData = (USB_CDC_CONTROL_LINE_STATE *)pData; app2DataObject->controlLineStateData.dtr = controlLineStateData->dtr; app2DataObject->controlLineStateData.carrier = controlLineStateData->carrier; USB_DEVICE_ControlStatus(app2DataObject->deviceHandle, USB_DEVICE_CONTROL_STATUS_OK); break; case USB_DEVICE_CDC_EVENT_SEND_BREAK: /* This means that the host is requesting that a break of the * specified duration be sent. Read the break duration */ app2DataObject->breakData = ((USB_DEVICE_CDC_EVENT_DATA_SEND_BREAK *)pData)->breakDuration; /* Complete the control transfer by sending a ZLP */ USB_DEVICE_ControlStatus(app2DataObject->deviceHandle, USB_DEVICE_CONTROL_STATUS_OK); break; case USB_DEVICE_CDC_EVENT_READ_COMPLETE: /* This means that the host has sent some data*/ //SYS_CONSOLE_MESSAGE("Read flag set\n"); app2DataObject->isReadComplete = true; break; case USB_DEVICE_CDC_EVENT_CONTROL_TRANSFER_DATA_RECEIVED: /* The data stage of the last control transfer is * complete. For now we accept all the data */ USB_DEVICE_ControlStatus(app2DataObject->deviceHandle, USB_DEVICE_CONTROL_STATUS_OK); break; case USB_DEVICE_CDC_EVENT_CONTROL_TRANSFER_DATA_SENT: /* This means the GET LINE CODING function data is valid. We dont * do much with this data in this demo. */ break; case USB_DEVICE_CDC_EVENT_WRITE_COMPLETE: /* This means that the data write got completed. We can schedule * the next read. */ app2DataObject->isWriteComplete = true; break; default: break; } return USB_DEVICE_CDC_EVENT_RESPONSE_NONE; }
USB_DEVICE_CDC_EVENT_RESPONSE APP_USBDeviceCDCEventHandler ( USB_DEVICE_CDC_INDEX index , USB_DEVICE_CDC_EVENT event , void* pData, uintptr_t userData ) { APP_DATA * appDataObject; appDataObject = (APP_DATA *)userData; USB_CDC_CONTROL_LINE_STATE * controlLineStateData; uint16_t * breakData; switch ( event ) { case USB_DEVICE_CDC_EVENT_GET_LINE_CODING: /* This means the host wants to know the current line * coding. This is a control transfer request. Use the * USB_DEVICE_ControlSend() function to send the data to * host. */ USB_DEVICE_ControlSend(appDataObject->deviceHandle, &appDataObject->getLineCodingData, sizeof(USB_CDC_LINE_CODING)); break; case USB_DEVICE_CDC_EVENT_SET_LINE_CODING: /* This means the host wants to set the line coding. * This is a control transfer request. Use the * USB_DEVICE_ControlReceive() function to receive the * data from the host */ USB_DEVICE_ControlReceive(appDataObject->deviceHandle, &appDataObject->setLineCodingData, sizeof(USB_CDC_LINE_CODING)); break; case USB_DEVICE_CDC_EVENT_SET_CONTROL_LINE_STATE: /* This means the host is setting the control line state. * Read the control line state. We will accept this request * for now. */ controlLineStateData = (USB_CDC_CONTROL_LINE_STATE *)pData; appDataObject->controlLineStateData.dtr = controlLineStateData->dtr; appDataObject->controlLineStateData.carrier = controlLineStateData->carrier; USB_DEVICE_ControlStatus(appDataObject->deviceHandle, USB_DEVICE_CONTROL_STATUS_OK); break; case USB_DEVICE_CDC_EVENT_SEND_BREAK: /* This means that the host is requesting that a break of the * specified duration be sent. Read the break duration */ breakData = (uint16_t *)pData; appDataObject->breakData = *breakData; break; case USB_DEVICE_CDC_EVENT_READ_COMPLETE: /* This means that the host has sent some data*/ appDataObject->isReadComplete = true; appDataObject->readLength = ((USB_DEVICE_CDC_EVENT_DATA_READ_COMPLETE*)pData)->length; break; case USB_DEVICE_CDC_EVENT_CONTROL_TRANSFER_DATA_RECEIVED: /* The data stage of the last control transfer is * complete. We have received the line coding from the host. Call * the usart driver routine to change the baud. We can call this * function here as it is not blocking. */ DRV_USART_BaudSet(appDataObject->usartHandle, appDataObject->setLineCodingData.dwDTERate); USB_DEVICE_ControlStatus(appDataObject->deviceHandle, USB_DEVICE_CONTROL_STATUS_OK); break; case USB_DEVICE_CDC_EVENT_CONTROL_TRANSFER_DATA_SENT: /* This means the GET LINE CODING function data is valid. We dont * do much with this data in this demo. */ break; case USB_DEVICE_CDC_EVENT_WRITE_COMPLETE: /* This means that the data write got completed. We can schedule * the next read. */ break; default: break; } return USB_DEVICE_CDC_EVENT_RESPONSE_NONE; }