X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/6380d057f8911f5d09bdffff4220aa9602df49e2..938f86d06321c1a29cf87201000a9dae4e5a7c25:/Demos/Device/USBtoSerial/USBtoSerial.c diff --git a/Demos/Device/USBtoSerial/USBtoSerial.c b/Demos/Device/USBtoSerial/USBtoSerial.c index 1d238aa11..ea8dcd599 100644 --- a/Demos/Device/USBtoSerial/USBtoSerial.c +++ b/Demos/Device/USBtoSerial/USBtoSerial.c @@ -33,8 +33,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: */ @@ -43,10 +43,10 @@ TASK_LIST * These values are set by the host via a class-specific request, and the physical USART should be reconfigured to match the * new settings each time they are changed by the host. */ -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 }; /** Ring (circular) buffer to hold the RX data - data from the host to the attached device on the serial port. */ RingBuff_t Rx_Buffer; @@ -153,33 +153,33 @@ EVENT_HANDLER(USB_UnhandledControlPacket) 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(LineCoding)); /* 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(LineCoding)); /* Finalize the stream transfer to clear the last packet from the host */ - Endpoint_ClearControlIN(); + Endpoint_ClearIN(); /* Reconfigure the USART with the new settings */ ReconfigureUSART(); @@ -187,25 +187,19 @@ EVENT_HANDLER(USB_UnhandledControlPacket) break; case REQ_SetControlLineState: - if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) - { -#if 0 + if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) + { + /* 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; @@ -224,11 +218,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; @@ -244,6 +238,7 @@ TASK(CDC_Task) /* Select the Serial Rx Endpoint */ Endpoint_SelectEndpoint(CDC_RX_EPNUM); + /* Check to see if a packet has been received from the host */ if (Endpoint_IsOUTReceived()) { /* Read the bytes in from the endpoint into the buffer while space is available */