The USB_UnhandledControlPacket event has had its parameters removed, in favour of accessing the new USB_ControlRequest structure.
The Endpoint control stream functions now correctly send a ZLP to the host when less data than requested is sent.
{\r
uint8_t* LineCodingData = (uint8_t*)&LineCoding;\r
\r
- Endpoint_Discard_Word();\r
-\r
/* Process CDC specific control requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetLineEncoding:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
\r
break;\r
case REQ_SetLineEncoding:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
\r
break;\r
case REQ_SetControlLineState:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
*/\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
- /* Discard unused wIndex value */\r
- Endpoint_Discard_Word();\r
- \r
- /* Discard unused wValue value */\r
- Endpoint_Discard_Word();\r
-\r
/* Get the size of the command and data from the wLength value */\r
- SentCommand.DataSize = Endpoint_Read_Word_LE();\r
+ SentCommand.DataSize = USB_ControlRequest.wLength;\r
\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case DFU_DNLOAD:\r
Endpoint_ClearSETUP();\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
/* Handle HID Class specific requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_SetReport:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
/* Process General and Audio specific control requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_SetInterface:\r
/* Set Interface is not handled by the library, as its function is application-specific */\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))\r
{\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- \r
Endpoint_ClearSETUP();\r
\r
/* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */\r
- if (wValue)\r
+ if (USB_ControlRequest.wValue)\r
{\r
/* Start audio task */\r
Scheduler_SetTaskMode(USB_Audio_Task, TASK_RUN);\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
/* Process General and Audio specific control requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_SetInterface:\r
/* Set Interface is not handled by the library, as its function is application-specific */\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))\r
{\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- \r
Endpoint_ClearSETUP();\r
\r
/* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */\r
- if (wValue)\r
+ if (USB_ControlRequest.wValue)\r
{\r
/* Start audio task */\r
Scheduler_SetTaskMode(USB_Audio_Task, TASK_RUN);\r
uint8_t* LineCodingData = (uint8_t*)&LineCoding;\r
\r
/* Process CDC specific control requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetLineEncoding:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{ \r
/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
\r
break;\r
case REQ_SetLineEncoding:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
\r
break;\r
case REQ_SetControlLineState:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
-#if 0\r
/* NOTE: Here you can read in the line state mask from the host, to get the current state of the output handshake\r
- lines. The mask is read in from the wValue parameter, and can be masked against the CONTROL_LINE_OUT_* masks\r
- to determine the RTS and DTR line states using the following code:\r
+ lines. The mask is read in from the wValue parameter in USB_ControlRequest, and can be masked against the\r
+ CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code:\r
*/\r
-\r
- uint16_t wIndex = Endpoint_Read_Word_LE();\r
- \r
- // Do something with the given line states in wIndex\r
-#endif\r
\r
/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
LineCodingData = (wIndex == 0) ? (uint8_t*)&LineCoding1 : (uint8_t*)&LineCoding2;\r
\r
/* Process CDC specific control requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetLineEncoding:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{ \r
/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
\r
break;\r
case REQ_SetLineEncoding:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
\r
break;\r
case REQ_SetControlLineState:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
/* Handle HID Class specific requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetReport:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
\r
break;\r
case REQ_SetReport:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
/* Handle HID Class specific requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetReport:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
USB_JoystickReport_Data_t JoystickReportData;\r
\r
/* Create the next HID report to send to the host */ \r
GetNextReport(&JoystickReportData);\r
-\r
- /* Ignore report type and ID number value */\r
- Endpoint_Discard_Word();\r
- \r
- /* Ignore unused Interface number value */\r
- Endpoint_Discard_Word();\r
-\r
- /* Read in the number of bytes in the report to send to the host */\r
- uint16_t wLength = Endpoint_Read_Word_LE();\r
\r
- /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
- if (wLength > sizeof(JoystickReportData))\r
- wLength = sizeof(JoystickReportData);\r
-\r
Endpoint_ClearSETUP();\r
\r
/* Write the report data to the control endpoint */\r
- Endpoint_Write_Control_Stream_LE(&JoystickReportData, wLength);\r
+ Endpoint_Write_Control_Stream_LE(&JoystickReportData, sizeof(JoystickReportData));\r
\r
/* Finalize the stream transfer to send the last packet or clear the host abort */\r
Endpoint_ClearOUT();\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
/* Handle HID Class specific requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetReport:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
USB_KeyboardReport_Data_t KeyboardReportData;\r
\r
/* Create the next keyboard report for transmission to the host */\r
CreateKeyboardReport(&KeyboardReportData);\r
\r
- /* Ignore report type and ID number value */\r
- Endpoint_Discard_Word();\r
- \r
- /* Ignore unused Interface number value */\r
- Endpoint_Discard_Word();\r
-\r
- /* Read in the number of bytes in the report to send to the host */\r
- uint16_t wLength = Endpoint_Read_Word_LE();\r
- \r
- /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
- if (wLength > sizeof(KeyboardReportData))\r
- wLength = sizeof(KeyboardReportData);\r
-\r
Endpoint_ClearSETUP();\r
\r
/* Write the report data to the control endpoint */\r
- Endpoint_Write_Control_Stream_LE(&KeyboardReportData, wLength);\r
+ Endpoint_Write_Control_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));\r
\r
/* Finalize the stream transfer to send the last packet or clear the host abort */\r
Endpoint_ClearOUT();\r
\r
break;\r
case REQ_SetReport:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
\r
break;\r
case REQ_GetProtocol:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
\r
break;\r
case REQ_SetProtocol:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
- /* Read in the wValue parameter containing the new protocol mode */\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- \r
Endpoint_ClearSETUP();\r
\r
/* Set or clear the flag depending on what the host indicates that the current Protocol should be */\r
- UsingReportProtocol = (wValue != 0x0000);\r
+ UsingReportProtocol = (USB_ControlRequest.wValue != 0x0000);\r
\r
/* Acknowledge status stage */\r
while (!(Endpoint_IsINReady()));\r
\r
break;\r
case REQ_SetIdle:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
- /* Read in the wValue parameter containing the idle period */\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- \r
Endpoint_ClearSETUP();\r
\r
/* Get idle period in MSB */\r
- IdleCount = (wValue >> 8);\r
+ IdleCount = (USB_ControlRequest.wValue >> 8);\r
\r
/* Acknowledge status stage */\r
while (!(Endpoint_IsINReady()));\r
\r
break;\r
case REQ_GetIdle:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{ \r
Endpoint_ClearSETUP();\r
\r
uint8_t ReportSize;\r
\r
/* Handle HID Class specific requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetReport:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
- Endpoint_Discard_Word();\r
- \r
- uint16_t wIndex = Endpoint_Read_Word_LE();\r
- \r
/* Determine if it is the mouse or the keyboard data that is being requested */\r
- if (!(wIndex))\r
+ if (!(USB_ControlRequest.wIndex))\r
{\r
ReportData = (uint8_t*)&KeyboardReportData;\r
ReportSize = sizeof(KeyboardReportData);\r
ReportSize = sizeof(MouseReportData);\r
}\r
\r
- /* Read in the number of bytes in the report to send to the host */\r
- uint16_t wLength = Endpoint_Read_Word_LE();\r
- \r
- /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
- if (wLength > ReportSize)\r
- wLength = ReportSize;\r
-\r
Endpoint_ClearSETUP();\r
\r
/* Write the report data to the control endpoint */\r
- Endpoint_Write_Control_Stream_LE(ReportData, wLength);\r
+ Endpoint_Write_Control_Stream_LE(ReportData, ReportSize);\r
\r
/* Clear the report data afterwards */\r
memset(ReportData, 0, ReportSize);\r
\r
break;\r
case REQ_SetReport:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
/* Process UFI specific control requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_MassStorageReset:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
\r
break;\r
case REQ_GetMaxLUN:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
/* Handle HID Class specific requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetReport:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
USB_MouseReport_Data_t MouseReportData;\r
\r
/* Create the next mouse report for transmission to the host */\r
CreateMouseReport(&MouseReportData);\r
\r
- /* Ignore report type and ID number value */\r
- Endpoint_Discard_Word();\r
- \r
- /* Ignore unused Interface number value */\r
- Endpoint_Discard_Word();\r
-\r
- /* Read in the number of bytes in the report to send to the host */\r
- uint16_t wLength = Endpoint_Read_Word_LE();\r
- \r
- /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
- if (wLength > sizeof(MouseReportData))\r
- wLength = sizeof(MouseReportData);\r
-\r
Endpoint_ClearSETUP();\r
\r
/* Write the report data to the control endpoint */\r
- Endpoint_Write_Control_Stream_LE(&MouseReportData, wLength);\r
+ Endpoint_Write_Control_Stream_LE(&MouseReportData, sizeof(MouseReportData));\r
\r
/* Clear the report data afterwards */\r
memset(&MouseReportData, 0, sizeof(MouseReportData));\r
\r
break;\r
case REQ_GetProtocol:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
\r
break;\r
case REQ_SetProtocol:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
- /* Read in the wValue parameter containing the new protocol mode */\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- \r
Endpoint_ClearSETUP();\r
\r
/* Set or clear the flag depending on what the host indicates that the current Protocol should be */\r
- UsingReportProtocol = (wValue != 0x0000);\r
+ UsingReportProtocol = (USB_ControlRequest.wValue != 0x0000);\r
\r
/* Acknowledge status stage */\r
while (!(Endpoint_IsINReady()));\r
\r
break;\r
case REQ_SetIdle:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
- /* Read in the wValue parameter containing the idle period */\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- \r
Endpoint_ClearSETUP();\r
\r
/* Get idle period in MSB */\r
- IdleCount = (wValue >> 8);\r
+ IdleCount = (USB_ControlRequest.wValue >> 8);\r
\r
/* Acknowledge status stage */\r
while (!(Endpoint_IsINReady()));\r
\r
break;\r
case REQ_GetIdle:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{ \r
Endpoint_ClearSETUP();\r
\r
uint16_t wLength = Endpoint_Read_Word_LE();\r
\r
/* Process RNDIS class commands */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_SendEncapsulatedCommand:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
/* Clear the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
\r
break;\r
case REQ_GetEncapsulatedResponse:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
/* Check if a response to the last message is ready */\r
if (!(MessageHeader->MessageLength))\r
MessageHeader->MessageLength = 1;\r
}\r
\r
- /* Check if less than the requested number of bytes to transfer */\r
- if (MessageHeader->MessageLength < wLength)\r
- wLength = MessageHeader->MessageLength;\r
-\r
/* Clear the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
\r
/* Write the message response data to the endpoint */\r
- Endpoint_Write_Control_Stream_LE(RNDISMessageBuffer, wLength);\r
+ Endpoint_Write_Control_Stream_LE(RNDISMessageBuffer, MessageHeader->MessageLength);\r
\r
/* Finalize the stream transfer to send the last packet or clear the host abort */\r
Endpoint_ClearOUT();\r
uint8_t* LineCodingData = (uint8_t*)&LineCoding;\r
\r
/* Process CDC specific control requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetLineEncoding:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{ \r
/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
\r
break;\r
case REQ_SetLineEncoding:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
\r
break;\r
case REQ_SetControlLineState:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
-#if 0\r
/* NOTE: Here you can read in the line state mask from the host, to get the current state of the output handshake\r
- lines. The mask is read in from the wValue parameter, and can be masked against the CONTROL_LINE_OUT_* masks\r
- to determine the RTS and DTR line states using the following code:\r
+ lines. The mask is read in from the wValue parameter in USB_ControlRequest, and can be masked against the\r
+ CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code:\r
*/\r
-\r
- uint16_t wIndex = Endpoint_Read_Word_LE();\r
- \r
- // Do something with the given line states in wIndex\r
-#endif\r
\r
/* Acknowledge the SETUP packet, ready for data transfer */\r
Endpoint_ClearSETUP();\r
{\r
case HOST_STATE_Addressed:\r
/* Standard request to set the device configuration to configuration 1 */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_SetConfiguration,\r
else\r
{\r
/* Class specific request to send a HID report to the device */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
.bRequest = REQ_SetReport,\r
{\r
case HOST_STATE_Addressed:\r
/* Standard request to set the device configuration to configuration 1 */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_SetConfiguration,\r
{\r
case HOST_STATE_Addressed:\r
/* Standard request to set the device configuration to configuration 1 */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_SetConfiguration,\r
}\r
\r
/* HID class request to set the keyboard protocol to the Boot Protocol */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
.bRequest = REQ_SetProtocol,\r
/* Create a buffer big enough to hold the entire returned HID report */\r
uint8_t HIDReportData[HIDReportSize];\r
\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),\r
.bRequest = REQ_GetDescriptor,\r
{\r
case HOST_STATE_Addressed:\r
/* Standard request to set the device configuration to configuration 1 */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_SetConfiguration,\r
{\r
case HOST_STATE_Addressed:\r
/* Standard request to set the device configuration to configuration 1 */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_SetConfiguration,\r
*/\r
uint8_t MassStore_ClearPipeStall(const uint8_t EndpointNum)\r
{\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),\r
.bRequest = REQ_ClearFeature,\r
*/\r
uint8_t MassStore_MassStorageReset(void)\r
{\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
.bRequest = REQ_MassStorageReset,\r
{\r
uint8_t ErrorCode;\r
\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),\r
.bRequest = REQ_GetMaxLUN,\r
{\r
case HOST_STATE_Addressed:\r
/* Standard request to set the device configuration to configuration 1 */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_SetConfiguration,\r
}\r
\r
/* HID class request to set the mouse protocol to the Boot Protocol */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
.bRequest = REQ_SetProtocol,\r
/* Create a buffer big enough to hold the entire returned HID report */\r
uint8_t HIDReportData[HIDReportSize];\r
\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),\r
.bRequest = REQ_GetDescriptor,\r
{\r
case HOST_STATE_Addressed: \r
/* Standard request to set the device configuration to configuration 1 */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_SetConfiguration,\r
*/\r
uint8_t SImage_ClearPipeStall(const uint8_t EndpointNum)\r
{\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),\r
.bRequest = REQ_ClearFeature,\r
{\r
case HOST_STATE_Addressed:\r
/* Standard request to set the device configuration to configuration 1 */\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_SetConfiguration,\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
puts_P(PSTR(EVENT_PREFIX "Ctrl Request\r\n"));\r
- printf_P(PSTR(" -- Req Data %d\r\n"), bRequest);\r
- printf_P(PSTR(" -- Req Type %d\r\n"), bmRequestType);\r
+ printf_P(PSTR(" -- Req Data %d\r\n"), USB_ControlRequest.bRequest);\r
+ printf_P(PSTR(" -- Req Type %d\r\n"), USB_ControlRequest.bmRequestType);\r
+ printf_P(PSTR(" -- Req Length %d\r\n"), USB_ControlRequest.wLength);\r
}\r
\r
/** Event handler for the USB_ConfigurationChanged event. When fired, the event is logged to the USART. */\r
* - Capitalised the "Descriptor_Search" and "Descriptor_Search_Comp" prefixes of the values in the DSearch_Return_ErrorCodes_t and\r
* DSearch_Comp_Return_ErrorCodes_t enums\r
* - Changed over all deprecated GCC structure tag initializers to the standardized C99 format (thanks to Mike Alexander)\r
+ * - USB_HostRequest renamed to USB_ControlRequest, entire control request header is now read into USB_ControlRequest in Device mode\r
+ * rather than having the library pass only partially read header data to the application\r
+ * - The USB_UnhandledControlPacket event has had its parameters removed, in favour of accessing the new USB_ControlRequest structure\r
+ * - The Endpoint control stream functions now correctly send a ZLP to the host when less data than requested is sent\r
* \r
*\r
* \section Sec_ChangeLog090401 Version 090401\r
{\r
uint8_t ErrorCode;\r
\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_GetDescriptor,\r
}\r
else\r
{\r
- USB_HostRequest.wLength = *ConfigSizePtr;\r
+ USB_ControlRequest.wLength = *ConfigSizePtr;\r
\r
ErrorCode = USB_Host_SendControlRequest(BufferPtr); \r
}\r
* parameters (wValue, wIndex, wLength, and Data) remain in the control endpoint bank until\r
* read out by the user application for processing.\r
*/\r
- void USB_UnhandledControlPacket(const uint8_t bRequest, const uint8_t bmRequestType);\r
+ void USB_UnhandledControlPacket(void);\r
\r
/** Event for USB configuration number changed. This event fires when a the USB host changes the\r
* selected configuration number while in device mode. This event should be hooked in device\r
#endif\r
\r
#if defined(USB_CAN_BE_DEVICE)\r
- #define USB_UnhandledControlPacket_P (const uint8_t bRequest, const uint8_t bmRequestType)\r
+ #define USB_UnhandledControlPacket_P (void)\r
#define USB_ConfigurationChanged_P (void)\r
#define USB_Suspend_P (void)\r
#define USB_WakeUp_P (void)\r
*/\r
#define FEATURE_REMOTE_WAKEUP 0x01\r
\r
+ /* Type Defines: */\r
+ /** Type define for a standard USB control request.\r
+ *\r
+ * \see The USB 2.0 specification for more information on standard control requests.\r
+ */\r
+ typedef struct\r
+ {\r
+ uint8_t bmRequestType; /**< Type of the request. */\r
+ uint8_t bRequest; /**< Request command code. */\r
+ uint16_t wValue; /**< wValue parameter of the request. */\r
+ uint16_t wIndex; /**< wIndex parameter of the request. */\r
+ uint16_t wLength; /**< Length of the data to transfer in bytes. */\r
+ } USB_Request_Header_t;\r
+\r
/* Enums: */\r
/** Enumeration for the various standard request commands. These commands are applicable when the\r
* request type is REQTYPE_STANDARD (with the exception of REQ_GetDescriptor, which is always\r
#define INCLUDE_FROM_USBTASK_C\r
#include "USBTask.h"\r
\r
-volatile bool USB_IsSuspended;\r
-volatile bool USB_IsConnected;\r
-volatile bool USB_IsInitialized;\r
+volatile bool USB_IsSuspended;\r
+volatile bool USB_IsConnected;\r
+volatile bool USB_IsInitialized;\r
+USB_Request_Header_t USB_ControlRequest;\r
\r
#if defined(USB_CAN_BE_HOST)\r
volatile uint8_t USB_HostState;\r
USB_HostState = HOST_STATE_Default;\r
break;\r
case HOST_STATE_Default:\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_GetDescriptor,\r
\r
Pipe_SetInfiniteINRequests();\r
\r
- USB_HostRequest = (USB_Host_Request_Header_t)\r
+ USB_ControlRequest = (USB_Request_Header_t)\r
{\r
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
.bRequest = REQ_SetAddress,\r
\r
#include "../../../Scheduler/Scheduler.h"\r
#include "../LowLevel/LowLevel.h"\r
+ #include "StdRequestType.h"\r
#include "USBMode.h"\r
#include "Events.h"\r
#include "StdDescriptors.h"\r
*/\r
extern volatile bool USB_IsInitialized;\r
\r
+ /** Structure containing the last received Control request when in Device mode (for use in user-applications\r
+ * inside of the USB_UnhandledControlPacket() event, or for filling up with a control request to issue when\r
+ * in Host mode before calling USB_Host_SendControlRequest().\r
+ *\r
+ * \ingroup Group_USBManagement\r
+ */\r
+ extern USB_Request_Header_t USB_ControlRequest;\r
+ \r
#if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)\r
/** Indicates if the USB interface is currently suspended by the host when in device mode. When suspended,\r
* the device should consume minimal power, and cannot communicate to the host. If Remote Wakeup is\r
\r
void USB_Device_ProcessControlPacket(void)\r
{\r
- uint8_t bmRequestType = Endpoint_Read_Byte();\r
- uint8_t bRequest = Endpoint_Read_Byte();\r
- bool RequestHandled = false; \r
+ bool RequestHandled = false;\r
+ uint8_t* RequestHeader = (uint8_t*)&USB_ControlRequest;\r
\r
- switch (bRequest)\r
+ for (uint8_t RequestHeaderByte = 0; RequestHeaderByte < sizeof(USB_Request_Header_t); RequestHeaderByte++)\r
+ *(RequestHeader++) = Endpoint_Read_Byte();\r
+ \r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetStatus:\r
- if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||\r
- (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT)))\r
+ if ((USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||\r
+ (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT)))\r
{\r
- USB_Device_GetStatus(bmRequestType);\r
+ USB_Device_GetStatus();\r
RequestHandled = true;\r
}\r
\r
#if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
case REQ_ClearFeature:\r
case REQ_SetFeature:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT))\r
{\r
- USB_Device_ClearSetFeature(bRequest, bmRequestType);\r
+ USB_Device_ClearSetFeature();\r
RequestHandled = true;\r
}\r
\r
break;\r
#endif\r
case REQ_SetAddress:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))\r
{\r
USB_Device_SetAddress();\r
RequestHandled = true;\r
\r
break;\r
case REQ_GetDescriptor:\r
- if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||\r
- (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE)))\r
+ if ((USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||\r
+ (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE)))\r
{\r
USB_Device_GetDescriptor();\r
RequestHandled = true;\r
\r
break;\r
case REQ_GetConfiguration:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE))\r
{\r
USB_Device_GetConfiguration();\r
RequestHandled = true;\r
\r
break;\r
case REQ_SetConfiguration:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))\r
{\r
USB_Device_SetConfiguration();\r
RequestHandled = true;\r
}\r
\r
if (!(RequestHandled))\r
- RAISE_EVENT(USB_UnhandledControlPacket, bRequest, bmRequestType);\r
+ RAISE_EVENT(USB_UnhandledControlPacket);\r
\r
if (Endpoint_IsSETUPReceived())\r
{\r
\r
static void USB_Device_SetAddress(void)\r
{\r
- uint8_t wValue_LSB = Endpoint_Read_Byte();\r
-\r
Endpoint_ClearSETUP();\r
\r
while (!(Endpoint_IsINReady()));\r
\r
while (!(Endpoint_IsINReady()));\r
\r
- UDADDR = ((1 << ADDEN) | (wValue_LSB & 0x7F));\r
+ UDADDR = ((1 << ADDEN) | (USB_ControlRequest.wValue & 0x7F));\r
\r
return;\r
}\r
\r
static void USB_Device_SetConfiguration(void)\r
{\r
- uint8_t wValue_LSB = Endpoint_Read_Byte();\r
bool AlreadyConfigured = (USB_ConfigurationNumber != 0);\r
\r
#if defined(USE_SINGLE_DEVICE_CONFIGURATION)\r
- if (wValue_LSB > 1)\r
+ if (USB_ControlRequest.wValue > 1)\r
#else\r
USB_Descriptor_Device_t* DevDescriptorPtr;\r
\r
if ((USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr) == NO_DESCRIPTOR) ||\r
#if defined(USE_RAM_DESCRIPTORS)\r
- (wValue_LSB > DevDescriptorPtr->NumberOfConfigurations))\r
+ (USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations))\r
#elif defined (USE_EEPROM_DESCRIPTORS)\r
- (wValue_LSB > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
+ (USB_ControlRequest.wValue > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
#else\r
- (wValue_LSB > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
+ (USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
#endif\r
#endif\r
{\r
\r
Endpoint_ClearSETUP();\r
\r
- USB_ConfigurationNumber = wValue_LSB;\r
+ USB_ConfigurationNumber = USB_ControlRequest.wValue;\r
\r
Endpoint_ClearIN();\r
\r
\r
static void USB_Device_GetDescriptor(void)\r
{\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- uint16_t wIndex = Endpoint_Read_Word_LE();\r
- uint16_t wLength = Endpoint_Read_Word_LE();\r
- \r
void* DescriptorPointer;\r
uint16_t DescriptorSize;\r
\r
- bool SendZLP;\r
- \r
- if ((DescriptorSize = USB_GetDescriptor(wValue, wIndex, &DescriptorPointer)) == NO_DESCRIPTOR)\r
+ if ((DescriptorSize = USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, &DescriptorPointer)) == NO_DESCRIPTOR)\r
return;\r
\r
- Endpoint_ClearSETUP(); \r
+ Endpoint_ClearSETUP();\r
+ \r
+ #if defined(USE_RAM_DESCRIPTORS)\r
+ Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);\r
+ #else\r
+ bool SendZLP;\r
\r
- if (wLength > DescriptorSize)\r
- wLength = DescriptorSize;\r
+ if (USB_ControlRequest.wLength > DescriptorSize)\r
+ USB_ControlRequest.wLength = DescriptorSize;\r
\r
- while (wLength)\r
+ while (USB_ControlRequest.wLength)\r
{\r
while (!(Endpoint_IsINReady()))\r
{\r
} \r
}\r
\r
- while (wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+ while (USB_ControlRequest.wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
{\r
- #if defined(USE_RAM_DESCRIPTORS)\r
- Endpoint_Write_Byte(*((uint8_t*)DescriptorPointer++));\r
- #elif defined (USE_EEPROM_DESCRIPTORS)\r
+ #if defined (USE_EEPROM_DESCRIPTORS)\r
Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++)); \r
#else\r
Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer++));\r
#endif\r
\r
- wLength--;\r
+ USB_ControlRequest.wLength--;\r
}\r
\r
SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
}\r
\r
while (!(Endpoint_IsOUTReceived()));\r
+ #endif\r
+ \r
Endpoint_ClearOUT();\r
}\r
\r
-static void USB_Device_GetStatus(const uint8_t bmRequestType)\r
+static void USB_Device_GetStatus(void)\r
{\r
uint8_t CurrentStatus = 0;\r
\r
- Endpoint_Discard_Word();\r
-\r
-#if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
- uint8_t wIndex_LSB = Endpoint_Read_Byte();\r
-#endif\r
- \r
- switch (bmRequestType)\r
+ switch (USB_ControlRequest.bmRequestType)\r
{\r
case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE):\r
if (USB_CurrentlySelfPowered)\r
break;\r
#if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT):\r
- Endpoint_SelectEndpoint(wIndex_LSB);\r
+ Endpoint_SelectEndpoint(USB_ControlRequest.wIndex);\r
\r
CurrentStatus = Endpoint_IsStalled();\r
\r
+ Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); \r
+\r
break;\r
#endif\r
}\r
- \r
- Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP); \r
+\r
Endpoint_ClearSETUP();\r
\r
Endpoint_Write_Word_LE(CurrentStatus);\r
}\r
\r
#if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
-static void USB_Device_ClearSetFeature(const uint8_t bRequest, const uint8_t bmRequestType)\r
-{\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- uint16_t wIndex = Endpoint_Read_Word_LE();\r
- \r
- switch (bmRequestType & CONTROL_REQTYPE_RECIPIENT)\r
+static void USB_Device_ClearSetFeature(void)\r
+{ \r
+ switch (USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT)\r
{\r
case REQREC_ENDPOINT:\r
- if (wValue == FEATURE_ENDPOINT_HALT)\r
+ if (USB_ControlRequest.wValue == FEATURE_ENDPOINT_HALT)\r
{\r
- uint8_t EndpointIndex = (wIndex & ENDPOINT_EPNUM_MASK);\r
+ uint8_t EndpointIndex = (USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);\r
\r
if (EndpointIndex != ENDPOINT_CONTROLEP)\r
{\r
\r
if (Endpoint_IsEnabled())\r
{ \r
- if (bRequest == REQ_ClearFeature)\r
+ if (USB_ControlRequest.bRequest == REQ_ClearFeature)\r
{\r
Endpoint_ClearStall();\r
Endpoint_ResetFIFO(EndpointIndex);\r
#include "../HighLevel/StdDescriptors.h"\r
#include "../HighLevel/Events.h"\r
#include "../HighLevel/StdRequestType.h"\r
+ #include "../HighLevel/USBTask.h"\r
#include "LowLevel.h"\r
\r
/* Enable C linkage for C++ Compilers: */\r
static void USB_Device_SetConfiguration(void);\r
static void USB_Device_GetConfiguration(void);\r
static void USB_Device_GetDescriptor(void);\r
- static void USB_Device_GetStatus(const uint8_t bmRequestType);\r
+ static void USB_Device_GetStatus(void);\r
#if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
- static void USB_Device_ClearSetFeature(const uint8_t bRequest, const uint8_t bmRequestType);\r
+ static void USB_Device_ClearSetFeature(void);\r
#endif\r
#endif\r
#endif\r
\r
uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)\r
{\r
- uint8_t* DataStream = (uint8_t*)Buffer;\r
- bool SendZLP = true;\r
+ uint8_t* DataStream = (uint8_t*)Buffer;\r
+ bool LastPacketFull = false;\r
+ bool ShortTransfer = (Length < USB_ControlRequest.wLength);\r
\r
while (Length && !(Endpoint_IsOUTReceived()))\r
{\r
Length--;\r
}\r
\r
- SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+ LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
Endpoint_ClearIN();\r
}\r
\r
if (Endpoint_IsOUTReceived())\r
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
\r
- if (SendZLP)\r
+ if (LastPacketFull || ShortTransfer)\r
{\r
while (!(Endpoint_IsINReady()));\r
Endpoint_ClearIN();\r
\r
uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)\r
{\r
- uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
- bool SendZLP = true;\r
+ uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
+ bool LastPacketFull = false;\r
+ bool ShortTransfer = (Length < USB_ControlRequest.wLength);\r
\r
while (Length && !(Endpoint_IsOUTReceived()))\r
{\r
Length--;\r
}\r
\r
- SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+ LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
Endpoint_ClearIN();\r
}\r
\r
if (Endpoint_IsOUTReceived())\r
return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
\r
- if (SendZLP)\r
+ if (LastPacketFull || ShortTransfer)\r
{\r
while (!(Endpoint_IsINReady()));\r
Endpoint_ClearIN();\r
#define INCLUDE_FROM_HOSTCHAPTER9_C\r
#include "HostChapter9.h"\r
\r
-USB_Host_Request_Header_t USB_HostRequest;\r
-\r
uint8_t USB_Host_SendControlRequest(void* BufferPtr)\r
{\r
- uint8_t* HeaderStream = (uint8_t*)&USB_HostRequest;\r
+ uint8_t* HeaderStream = (uint8_t*)&USB_ControlRequest;\r
uint8_t* DataStream = (uint8_t*)BufferPtr;\r
bool BusSuspended = USB_Host_IsBusSuspended();\r
uint8_t ReturnStatus = HOST_SENDCONTROL_Successful;\r
- uint16_t DataLen = USB_HostRequest.wLength;\r
+ uint16_t DataLen = USB_ControlRequest.wLength;\r
\r
USB_Host_ResumeBus();\r
\r
\r
Pipe_Unfreeze();\r
\r
- for (uint8_t HeaderByte = 0; HeaderByte < sizeof(USB_Host_Request_Header_t); HeaderByte++)\r
+ for (uint8_t HeaderByte = 0; HeaderByte < sizeof(USB_Request_Header_t); HeaderByte++)\r
Pipe_Write_Byte(*(HeaderStream++));\r
\r
Pipe_ClearSETUP();\r
if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)\r
goto End_Of_Control_Send;\r
\r
- if ((USB_HostRequest.bmRequestType & CONTROL_REQTYPE_DIRECTION) == REQDIR_DEVICETOHOST)\r
+ if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_DIRECTION) == REQDIR_DEVICETOHOST)\r
{\r
Pipe_SetToken(PIPE_TOKEN_IN);\r
\r
#endif\r
\r
/* Public Interface - May be used in end-application: */\r
- /* Type Defines: */\r
- /** Type define for a standard USB control request.\r
- *\r
- * \see StdRequestType.h for information on the request type and data.\r
- * \see The USB 2.0 specification for more information on standard control requests.\r
- *\r
- * \ingroup Group_PipeControlReq\r
- */\r
- typedef struct\r
- {\r
- uint8_t bmRequestType; /**< Type of the request. */\r
- uint8_t bRequest; /**< Request command code. */\r
- uint16_t wValue; /**< wValue parameter of the request. */\r
- uint16_t wIndex; /**< wIndex parameter of the request. */\r
- uint16_t wLength; /**< Length of the data to transfer in bytes. */\r
- } USB_Host_Request_Header_t;\r
-\r
/* Enums: */\r
/** Enum for the USB_Host_SendControlRequest() return code, indicating the reason for the error\r
* if the transfer of the request is unsuccessful.\r
HOST_SENDCONTROL_SoftwareTimeOut = 4, /**< The request or data transfer timed out. */\r
};\r
\r
- /* Global Variables: */\r
- /** Global for the request to send via the USB_Host_SendControlRequest() function. This\r
- * global should be filled with the correct control request data before sending the request to\r
- * the attached device while in host mode.\r
- *\r
- * \ingroup Group_PipeControlReq\r
- */\r
- extern USB_Host_Request_Header_t USB_HostRequest;\r
- \r
/* Function Prototypes: */\r
- /** Sends the request stored in the USB_HostRequest global structure to the attached device,\r
+ /** Sends the request stored in the USB_ControlRequest global structure to the attached device,\r
* and transfers the data stored in the buffer to the device, or from the device to the buffer\r
* as requested. The transfer is made on the currently selected pipe.\r
*\r
\r
uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;\r
\r
-bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,\r
+bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,\r
const uint16_t Size, const uint8_t Banks)\r
{\r
Pipe_SelectPipe(Number);\r
* is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT\r
* direction and the pipe bank is full.\r
*\r
+ * \note This function is not valid on CONTROL type pipes.\r
+ *\r
* \ingroup Group_PipePacketManagement\r
* \r
* \return Boolean true if the currently selected pipe may be read from or written to, depending on its direction\r
* - The Endpoint_ClearSetupReceived() macro has been renamed to Endpoint_ClearSETUP().\r
* - All endpoint read/write/discard aliases which did not have an explicitly endianness specifier (such as Endpoint_Read_Word()) have\r
* been removed for clarity. Existing projects should use the "_LE" suffix on such calls to use the explicit Little Endian versions.\r
+ * - The USB_UnhandledControlPacket event no longer has any parameters. User code should no longer attempt to read in the remainder of\r
+ * the Control Request header as all Control Request header data is now preloaded by the library and made available in the\r
+ * USB_ControlRequest structure.\r
*\r
* <b>Host Mode</b>\r
* - The USB_Host_SendControlRequest() function no longer automatically selects the Control pipe (pipe 0) to allow it to be used on\r
* and SetReportItemInfo() has been renamed to USB_GetHIDReportItemInfo().\r
* - The values of the DSearch_Return_ErrorCodes_t and DSearch_Comp_Return_ErrorCodes_t enums have had their respective "Descriptor_Search"\r
* and "Descriptor_Search_Comp" prefixes changed to all caps.\r
+ * - The USB_HostRequest global has been renamed to USB_ControlRequest, and is used in Device mode also. The USB_Host_Request_Header_t\r
+ * structure type has been renamed to USB_Request_Header_t.\r
*\r
* \section Sec_Migration090401 Migrating from 090209 to 090401\r
*\r
EVENT_HANDLER(USB_UnhandledControlPacket)\r
{\r
/* Handle HID Class specific requests */\r
- switch (bRequest)\r
+ switch (USB_ControlRequest.bRequest)\r
{\r
case REQ_GetReport:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
USB_KeyboardReport_Data_t KeyboardReportData;\r
\r
/* Create the next keyboard report for transmission to the host */\r
GetNextReport(&KeyboardReportData);\r
\r
- /* Ignore report type and ID number value */\r
- Endpoint_Discard_Word();\r
- \r
- /* Ignore unused Interface number value */\r
- Endpoint_Discard_Word();\r
-\r
- /* Read in the number of bytes in the report to send to the host */\r
- uint16_t wLength = Endpoint_Read_Word_LE();\r
- \r
- /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
- if (wLength > sizeof(KeyboardReportData))\r
- wLength = sizeof(KeyboardReportData);\r
-\r
Endpoint_ClearSETUP();\r
\r
/* Write the report data to the control endpoint */\r
- Endpoint_Write_Control_Stream_LE(&KeyboardReportData, wLength);\r
+ Endpoint_Write_Control_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));\r
\r
/* Finalize the stream transfer to send the last packet or clear the host abort */\r
Endpoint_ClearOUT();\r
\r
break;\r
case REQ_GetProtocol:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
Endpoint_ClearSETUP();\r
\r
\r
break;\r
case REQ_SetProtocol:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
- /* Read in the wValue parameter containing the new protocol mode */\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- \r
Endpoint_ClearSETUP();\r
\r
/* Set or clear the flag depending on what the host indicates that the current Protocol should be */\r
- UsingReportProtocol = (wValue != 0x0000);\r
+ UsingReportProtocol = (USB_ControlRequest.wValue != 0x0000);\r
\r
/* Acknowledge status stage */\r
while (!(Endpoint_IsINReady()));\r
\r
break;\r
case REQ_SetIdle:\r
- if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
{\r
- /* Read in the wValue parameter containing the idle period */\r
- uint16_t wValue = Endpoint_Read_Word_LE();\r
- \r
Endpoint_ClearSETUP();\r
\r
/* Get idle period in MSB */\r
- IdleCount = (wValue >> 8);\r
+ IdleCount = (USB_ControlRequest.wValue >> 8);\r
\r
/* Acknowledge status stage */\r
while (!(Endpoint_IsINReady()));\r
\r
break;\r
case REQ_GetIdle:\r
- if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+ if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
{ \r
Endpoint_ClearSETUP();\r
\r