aboutsummaryrefslogtreecommitdiffstats
path: root/Demos/Device/LowLevel
diff options
context:
space:
mode:
authorDean Camera <dean@fourwalledcubicle.com>2010-08-22 03:26:20 +0000
committerDean Camera <dean@fourwalledcubicle.com>2010-08-22 03:26:20 +0000
commit4cc7f5200beef90c39c8c8310ed7c8b849afb4d9 (patch)
treea8e2e56961f7e39b888e4ded0c38c5ab9cf6f5b6 /Demos/Device/LowLevel
parent1be3436e895c9937dcd4ebbec33ea199f3e26db2 (diff)
downloadlufa-4cc7f5200beef90c39c8c8310ed7c8b849afb4d9.tar.gz
lufa-4cc7f5200beef90c39c8c8310ed7c8b849afb4d9.tar.bz2
lufa-4cc7f5200beef90c39c8c8310ed7c8b849afb4d9.zip
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.
Diffstat (limited to 'Demos/Device/LowLevel')
-rw-r--r--Demos/Device/LowLevel/AudioInput/AudioInput.c7
-rw-r--r--Demos/Device/LowLevel/AudioOutput/AudioOutput.c5
-rw-r--r--Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c10
-rw-r--r--Demos/Device/LowLevel/GenericHID/GenericHID.c27
-rw-r--r--Demos/Device/LowLevel/Joystick/Joystick.c8
-rw-r--r--Demos/Device/LowLevel/Keyboard/Keyboard.c34
-rw-r--r--Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c13
-rw-r--r--Demos/Device/LowLevel/MassStorage/MassStorage.c6
-rw-r--r--Demos/Device/LowLevel/Mouse/Mouse.c28
-rw-r--r--Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c10
-rw-r--r--Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c12
11 files changed, 46 insertions, 114 deletions
diff --git a/Demos/Device/LowLevel/AudioInput/AudioInput.c b/Demos/Device/LowLevel/AudioInput/AudioInput.c
index eb29f34f7..4abc17422 100644
--- a/Demos/Device/LowLevel/AudioInput/AudioInput.c
+++ b/Demos/Device/LowLevel/AudioInput/AudioInput.c
@@ -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;
diff --git a/Demos/Device/LowLevel/AudioOutput/AudioOutput.c b/Demos/Device/LowLevel/AudioOutput/AudioOutput.c
index 2732afc13..fbadf8d0b 100644
--- a/Demos/Device/LowLevel/AudioOutput/AudioOutput.c
+++ b/Demos/Device/LowLevel/AudioOutput/AudioOutput.c
@@ -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;
diff --git a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c
index 84a329118..c9a2d9248 100644
--- a/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c
+++ b/Demos/Device/LowLevel/DualVirtualSerial/DualVirtualSerial.c
@@ -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();
}
diff --git a/Demos/Device/LowLevel/GenericHID/GenericHID.c b/Demos/Device/LowLevel/GenericHID/GenericHID.c
index 5146efdda..a72cecb45 100644
--- a/Demos/Device/LowLevel/GenericHID/GenericHID.c
+++ b/Demos/Device/LowLevel/GenericHID/GenericHID.c
@@ -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;
diff --git a/Demos/Device/LowLevel/Joystick/Joystick.c b/Demos/Device/LowLevel/Joystick/Joystick.c
index 08c4892ea..5aadb599c 100644
--- a/Demos/Device/LowLevel/Joystick/Joystick.c
+++ b/Demos/Device/LowLevel/Joystick/Joystick.c
@@ -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();
}
diff --git a/Demos/Device/LowLevel/Keyboard/Keyboard.c b/Demos/Device/LowLevel/Keyboard/Keyboard.c
index 12bf5ba63..b4d4c2137 100644
--- a/Demos/Device/LowLevel/Keyboard/Keyboard.c
+++ b/Demos/Device/LowLevel/Keyboard/Keyboard.c
@@ -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();
- /* Process the incoming LED report */
- ProcessLEDReport(LEDStatus);
-
- /* Clear the endpoint data */
Endpoint_ClearOUT();
-
Endpoint_ClearStatusStage();
+
+ /* Process the incoming LED report */
+ ProcessLEDReport(LEDStatus);
}
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();
}
diff --git a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c
index 687dc3123..2f4bd76cf 100644
--- a/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c
+++ b/Demos/Device/LowLevel/KeyboardMouse/KeyboardMouse.c
@@ -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;
diff --git a/Demos/Device/LowLevel/MassStorage/MassStorage.c b/Demos/Device/LowLevel/MassStorage/MassStorage.c
index 4b0b582dc..3bf2af16c 100644
--- a/Demos/Device/LowLevel/MassStorage/MassStorage.c
+++ b/Demos/Device/LowLevel/MassStorage/MassStorage.c
@@ -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();
}
diff --git a/Demos/Device/LowLevel/Mouse/Mouse.c b/Demos/Device/LowLevel/Mouse/Mouse.c
index 1cc6d8849..6aa258a00 100644
--- a/Demos/Device/LowLevel/Mouse/Mouse.c
+++ b/Demos/Device/LowLevel/Mouse/Mouse.c
@@ -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();
}
diff --git a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c
index 6b3e2c473..8a8d2142a 100644
--- a/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c
+++ b/Demos/Device/LowLevel/RNDISEthernet/RNDISEthernet.c
@@ -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 */
diff --git a/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c
index 633cdcf88..9189ef3e7 100644
--- a/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c
+++ b/Demos/Device/LowLevel/VirtualSerial/VirtualSerial.c
@@ -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;