X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/6380d057f8911f5d09bdffff4220aa9602df49e2..2ee9fc707784e115d744dbc229bdc893f4bb6bc1:/Demos/Device/CDC/CDC.c diff --git a/Demos/Device/CDC/CDC.c b/Demos/Device/CDC/CDC.c index 29bc00373..d7ebb9e6b 100644 --- a/Demos/Device/CDC/CDC.c +++ b/Demos/Device/CDC/CDC.c @@ -39,8 +39,8 @@ /* Scheduler Task List */ TASK_LIST { - { Task: USB_USBTask , TaskStatus: TASK_STOP }, - { Task: CDC_Task , TaskStatus: TASK_STOP }, + { .Task = USB_USBTask , .TaskStatus = TASK_STOP }, + { .Task = CDC_Task , .TaskStatus = TASK_STOP }, }; /* Globals: */ @@ -52,10 +52,10 @@ TASK_LIST * It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical * serial link characteristics and instead sends and receives data in endpoint streams. */ -CDC_Line_Coding_t LineCoding = { BaudRateBPS: 9600, - CharFormat: OneStopBit, - ParityType: Parity_None, - DataBits: 8 }; +CDC_Line_Coding_t LineCoding = { .BaudRateBPS = 9600, + .CharFormat = OneStopBit, + .ParityType = Parity_None, + .DataBits = 8 }; /** String to print through the virtual serial port when the joystick is pressed upwards. */ char JoystickUpString[] = "Joystick Up\r\n"; @@ -104,7 +104,7 @@ int main(void) /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and * starts the library USB task to begin the enumeration and USB management process. */ -EVENT_HANDLER(USB_Connect) +void EVENT_USB_Connect(void) { /* Start USB management task */ Scheduler_SetTaskMode(USB_USBTask, TASK_RUN); @@ -116,7 +116,7 @@ EVENT_HANDLER(USB_Connect) /** Event handler for the USB_Disconnect event. This indicates that the device is no longer connected to a host via * the status LEDs and stops the USB management and CDC management tasks. */ -EVENT_HANDLER(USB_Disconnect) +void EVENT_USB_Disconnect(void) { /* Stop running CDC and USB management tasks */ Scheduler_SetTaskMode(CDC_Task, TASK_STOP); @@ -129,7 +129,7 @@ EVENT_HANDLER(USB_Disconnect) /** Event handler for the USB_ConfigurationChanged event. This is fired when the host set the current configuration * of the USB device after enumeration - the device endpoints are configured and the CDC management task started. */ -EVENT_HANDLER(USB_ConfigurationChanged) +void EVENT_USB_ConfigurationChanged(void) { /* Setup CDC Notification, Rx and Tx Endpoints */ Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, @@ -155,61 +155,55 @@ EVENT_HANDLER(USB_ConfigurationChanged) * control requests that are not handled internally by the USB library (including the CDC control commands, * which are all issued via the control endpoint), so that they can be handled appropriately for the application. */ -EVENT_HANDLER(USB_UnhandledControlPacket) +void EVENT_USB_UnhandledControlPacket(void) { uint8_t* LineCodingData = (uint8_t*)&LineCoding; /* Process CDC specific control requests */ - switch (bRequest) + switch (USB_ControlRequest.bRequest) { case REQ_GetLineEncoding: - if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) + if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { /* Acknowledge the SETUP packet, ready for data transfer */ - Endpoint_ClearControlSETUP(); + Endpoint_ClearSETUP(); /* Write the line coding data to the control endpoint */ Endpoint_Write_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t)); /* Finalize the stream transfer to send the last packet or clear the host abort */ - Endpoint_ClearControlOUT(); + Endpoint_ClearOUT(); } break; case REQ_SetLineEncoding: - if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { /* Acknowledge the SETUP packet, ready for data transfer */ - Endpoint_ClearControlSETUP(); + Endpoint_ClearSETUP(); /* Read the line coding data in from the host into the global struct */ Endpoint_Read_Control_Stream_LE(LineCodingData, sizeof(CDC_Line_Coding_t)); /* Finalize the stream transfer to clear the last packet from the host */ - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); } break; case REQ_SetControlLineState: - if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { -#if 0 + /* Acknowledge the SETUP packet, ready for data transfer */ + Endpoint_ClearSETUP(); + /* NOTE: Here you can read in the line state mask from the host, to get the current state of the output handshake - lines. The mask is read in from the wValue parameter, and can be masked against the CONTROL_LINE_OUT_* masks - to determine the RTS and DTR line states using the following code: + lines. The mask is read in from the wValue parameter in USB_ControlRequest, and can be masked against the + CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code: */ - - uint16_t wIndex = Endpoint_Read_Word_LE(); - - // Do something with the given line states in wIndex -#endif - - /* Acknowledge the SETUP packet, ready for data transfer */ - Endpoint_ClearControlSETUP(); /* Acknowledge status stage */ while (!(Endpoint_IsINReady())); - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); } break; @@ -256,11 +250,11 @@ TASK(CDC_Task) */ USB_Notification_Header_t Notification = (USB_Notification_Header_t) { - NotificationType: (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE), - Notification: NOTIF_SerialState, - wValue: 0, - wIndex: 0, - wLength: sizeof(uint16_t), + .NotificationType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE), + .Notification = NOTIF_SerialState, + .wValue = 0, + .wIndex = 0, + .wLength = sizeof(uint16_t), }; uint16_t LineStateMask;