Changed all Device mode LowLevel demos and Device Class drivers so that the control request is acknowledged and any data transferred as quickly as possible without any processing inbetween sections, so that long callbacks or event handlers will not break communications with the host by exceeding the maximum control request stage timeout period.
This commit is contained in:
parent
1be3436e89
commit
4cc7f5200b
18 changed files with 82 additions and 167 deletions
|
@ -133,12 +133,11 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
/* Set Interface is not handled by the library, as its function is application-specific */
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */
|
||||
StreamingAudioInterfaceSelected = ((USB_ControlRequest.wValue) != 0);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -161,11 +161,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */
|
||||
StreamingAudioInterfaceSelected = ((USB_ControlRequest.wValue) != 0);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -161,13 +161,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
case REQ_GetLineEncoding:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Acknowledge the SETUP packet, ready for data transfer */
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the line coding data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(LineEncodingData, sizeof(CDC_Line_Coding_t));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_Write_Control_Stream_LE(LineEncodingData, sizeof(CDC_Line_Coding_t));
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
|
@ -175,13 +172,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
case REQ_SetLineEncoding:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Acknowledge the SETUP packet, ready for data transfer */
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Read the line coding data in from the host into the global struct */
|
||||
Endpoint_Read_Control_Stream_LE(LineEncodingData, sizeof(CDC_Line_Coding_t));
|
||||
|
||||
/* Finalize the stream transfer to clear the last packet from the host */
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
|
||||
|
@ -189,9 +183,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
case REQ_SetControlLineState:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Acknowledge the SETUP packet, ready for data transfer */
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
|
|
|
@ -120,15 +120,12 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
uint8_t GenericData[GENERIC_REPORT_SIZE];
|
||||
CreateGenericHIDReport(GenericData);
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
CreateGenericHIDReport(GenericData);
|
||||
|
||||
/* Write the report data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(&GenericData, sizeof(GenericData));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
|
@ -139,30 +136,12 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
uint8_t GenericData[GENERIC_REPORT_SIZE];
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Wait until the generic report has been sent by the host */
|
||||
while (!(Endpoint_IsOUTReceived()))
|
||||
{
|
||||
if (USB_DeviceState == DEVICE_STATE_Unattached)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Read the report data from the control endpoint */
|
||||
Endpoint_Read_Control_Stream_LE(&GenericData, sizeof(GenericData));
|
||||
|
||||
ProcessGenericHIDReport(GenericData);
|
||||
|
||||
/* Clear the endpoint data */
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
/* Wait until the host is ready to receive the request confirmation */
|
||||
while (!(Endpoint_IsINReady()))
|
||||
{
|
||||
if (USB_DeviceState == DEVICE_STATE_Unattached)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Handshake the request by sending an empty IN packet */
|
||||
Endpoint_ClearIN();
|
||||
ProcessGenericHIDReport(GenericData);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -117,15 +117,13 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
{
|
||||
USB_JoystickReport_Data_t JoystickReportData;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Create the next HID report to send to the host */
|
||||
GetNextReport(&JoystickReportData);
|
||||
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the report data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(&JoystickReportData, sizeof(JoystickReportData));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
|
|
|
@ -143,15 +143,13 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
{
|
||||
USB_KeyboardReport_Data_t KeyboardReportData;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Create the next keyboard report for transmission to the host */
|
||||
CreateKeyboardReport(&KeyboardReportData);
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the report data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
|
@ -171,13 +169,11 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
/* Read in the LED report from the host */
|
||||
uint8_t LEDStatus = Endpoint_Read_Byte();
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* Process the incoming LED report */
|
||||
ProcessLEDReport(LEDStatus);
|
||||
|
||||
/* Clear the endpoint data */
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -188,10 +184,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
|
||||
/* Write the current protocol flag to the host */
|
||||
Endpoint_Write_Byte(UsingReportProtocol);
|
||||
|
||||
/* Send the flag to the host */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
|
@ -200,23 +194,21 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* Set or clear the flag depending on what the host indicates that the current Protocol should be */
|
||||
UsingReportProtocol = (USB_ControlRequest.wValue != 0);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
case REQ_SetIdle:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* Get idle period in MSB, IdleCount must be multiplied by 4 to get number of milliseconds */
|
||||
IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -226,11 +218,9 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the current idle duration to the host, must be divided by 4 before sent to host */
|
||||
Endpoint_Write_Byte(IdleCount >> 2);
|
||||
|
||||
/* Send the flag to the host */
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_Write_Byte(IdleCount >> 2);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
|
|
|
@ -148,12 +148,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
|
||||
/* Write the report data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(ReportData, ReportSize);
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
/* Clear the report data afterwards */
|
||||
memset(ReportData, 0, ReportSize);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -169,13 +167,14 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
return;
|
||||
}
|
||||
|
||||
/* Read in and process the LED report from the host */
|
||||
Keyboard_ProcessLEDReport(Endpoint_Read_Byte());
|
||||
/* Read in the LED report from the host */
|
||||
uint8_t LEDStatus = Endpoint_Read_Byte();
|
||||
|
||||
/* Clear the endpoint data */
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* Process the incoming LED report */
|
||||
Keyboard_ProcessLEDReport(LEDStatus);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -133,11 +133,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* Indicate that the current transfer should be aborted */
|
||||
IsMassStoreReset = true;
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -149,8 +148,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
/* Indicate to the host the number of supported LUNs (virtual disks) on the device */
|
||||
Endpoint_Write_Byte(TOTAL_LUNS - 1);
|
||||
|
||||
Endpoint_ClearIN();
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
|
|
|
@ -140,19 +140,17 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
{
|
||||
USB_MouseReport_Data_t MouseReportData;
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Create the next mouse report for transmission to the host */
|
||||
CreateMouseReport(&MouseReportData);
|
||||
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the report data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(&MouseReportData, sizeof(MouseReportData));
|
||||
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
/* Clear the report data afterwards */
|
||||
memset(&MouseReportData, 0, sizeof(MouseReportData));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -164,9 +162,7 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
/* Write the current protocol flag to the host */
|
||||
Endpoint_Write_Byte(UsingReportProtocol);
|
||||
|
||||
/* Send the flag to the host */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
|
@ -175,11 +171,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* Set or clear the flag depending on what the host indicates that the current Protocol should be */
|
||||
UsingReportProtocol = (USB_ControlRequest.wValue != 0);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -187,11 +182,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* Get idle period in MSB, must multiply by 4 to get the duration in milliseconds */
|
||||
IdleCount = ((USB_ControlRequest.wValue & 0xFF00) >> 6);
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -202,10 +196,8 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
|
||||
/* Write the current idle duration to the host, must be divided by 4 before sent to host */
|
||||
Endpoint_Write_Byte(IdleCount >> 2);
|
||||
|
||||
/* Send the flag to the host */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
Endpoint_ClearIN();
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
|
|
|
@ -124,13 +124,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
case REQ_SendEncapsulatedCommand:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Clear the SETUP packet, ready for data transfer */
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Read in the RNDIS message into the message buffer */
|
||||
Endpoint_Read_Control_Stream_LE(RNDISMessageBuffer, USB_ControlRequest.wLength);
|
||||
|
||||
/* Finalize the stream transfer to clear the last packet from the host */
|
||||
Endpoint_ClearIN();
|
||||
|
||||
/* Process the RNDIS message */
|
||||
|
@ -141,9 +138,6 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
case REQ_GetEncapsulatedResponse:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Clear the SETUP packet, ready for data transfer */
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Check if a response to the last message is ready */
|
||||
if (!(MessageHeader->MessageLength))
|
||||
{
|
||||
|
@ -152,10 +146,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
MessageHeader->MessageLength = 1;
|
||||
}
|
||||
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the message response data to the endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(RNDISMessageBuffer, MessageHeader->MessageLength);
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_ClearOUT();
|
||||
|
||||
/* Reset the message header once again after transmission */
|
||||
|
|
|
@ -134,13 +134,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
case REQ_GetLineEncoding:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Acknowledge the SETUP packet, ready for data transfer */
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Write the line coding data to the control endpoint */
|
||||
Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t));
|
||||
|
||||
/* Finalize the stream transfer to send the last packet or clear the host abort */
|
||||
Endpoint_ClearOUT();
|
||||
}
|
||||
|
||||
|
@ -148,13 +145,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
case REQ_SetLineEncoding:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Acknowledge the SETUP packet, ready for data transfer */
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
/* Read the line coding data in from the host into the global struct */
|
||||
Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t));
|
||||
|
||||
/* Finalize the stream transfer to clear the last packet from the host */
|
||||
Endpoint_ClearIN();
|
||||
}
|
||||
|
||||
|
@ -162,15 +156,13 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
|
|||
case REQ_SetControlLineState:
|
||||
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
|
||||
{
|
||||
/* Acknowledge the SETUP packet, ready for data transfer */
|
||||
Endpoint_ClearSETUP();
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
|
||||
/* 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 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:
|
||||
*/
|
||||
|
||||
Endpoint_ClearStatusStage();
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue