Commit b5ca3990 authored by Dean Camera's avatar Dean Camera
Browse files

Added new USB_Host_SetDeviceConfiguration() convenience function. Change over...

Added new USB_Host_SetDeviceConfiguration() convenience function. Change over Low Level host demos to use the new routine.
parent ab76c52e
......@@ -132,23 +132,16 @@ void CDC_Host_Task(void)
switch (USB_HostState)
{
case HOST_STATE_Addressed:
/* Standard request to set the device configuration to configuration 1 */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = 1,
.wIndex = 0,
.wLength = 0,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
......@@ -159,19 +152,10 @@ void CDC_Host_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
......@@ -182,6 +166,9 @@ void CDC_Host_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("CDC Device Enumerated.\r\n"));
USB_HostState = HOST_STATE_Ready;
......
......@@ -233,23 +233,16 @@ void HID_Host_Task(void)
switch (USB_HostState)
{
case HOST_STATE_Addressed:
/* Standard request to set the device configuration to configuration 1 */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = 1,
.wIndex = 0,
.wLength = 0,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
puts_P(PSTR("Getting Config Data.\r\n"));
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
......@@ -260,19 +253,10 @@ void HID_Host_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
......@@ -283,6 +267,9 @@ void HID_Host_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("HID Device Enumerated.\r\n"));
USB_HostState = HOST_STATE_Ready;
......
......@@ -197,23 +197,16 @@ void Keyboard_HID_Task(void)
switch (USB_HostState)
{
case HOST_STATE_Addressed:
/* Standard request to set the device configuration to configuration 1 */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = 1,
.wIndex = 0,
.wLength = 0,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
puts_P(PSTR("Getting Config Data.\r\n"));
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
......@@ -224,19 +217,10 @@ void Keyboard_HID_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
......@@ -247,6 +231,9 @@ void Keyboard_HID_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
/* HID class request to set the keyboard protocol to the Boot Protocol */
USB_ControlRequest = (USB_Request_Header_t)
{
......
......@@ -132,23 +132,16 @@ void Keyboard_HID_Task(void)
switch (USB_HostState)
{
case HOST_STATE_Addressed:
/* Standard request to set the device configuration to configuration 1 */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = 1,
.wIndex = 0,
.wLength = 0,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
......@@ -159,19 +152,11 @@ void Keyboard_HID_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n"));
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
{
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
......@@ -182,6 +167,9 @@ void Keyboard_HID_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Processing HID Report.\r\n"));
/* Get and process the device's first HID report descriptor */
......
......@@ -138,23 +138,16 @@ void MassStorage_Task(void)
switch (USB_HostState)
{
case HOST_STATE_Addressed:
/* Standard request to set the device configuration to configuration 1 */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = 1,
.wIndex = 0,
.wLength = 0,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
puts_P(PSTR("Getting Config Data.\r\n"));
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
......@@ -165,19 +158,10 @@ void MassStorage_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
......@@ -188,6 +172,9 @@ void MassStorage_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Mass Storage Disk Enumerated.\r\n"));
USB_HostState = HOST_STATE_Ready;
......
......@@ -193,23 +193,16 @@ void Mouse_HID_Task(void)
switch (USB_HostState)
{
case HOST_STATE_Addressed:
/* Standard request to set the device configuration to configuration 1 */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = 1,
.wIndex = 0,
.wLength = 0,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
puts_P(PSTR("Getting Config Data.\r\n"));
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
......@@ -220,19 +213,10 @@ void Mouse_HID_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
......@@ -243,6 +227,9 @@ void Mouse_HID_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
/* HID class request to set the mouse protocol to the Boot Protocol */
USB_ControlRequest = (USB_Request_Header_t)
{
......
......@@ -133,23 +133,16 @@ void Mouse_HID_Task(void)
switch (USB_HostState)
{
case HOST_STATE_Addressed:
/* Standard request to set the device configuration to configuration 1 */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = 1,
.wIndex = 0,
.wLength = 0,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
/* Send the request, display error and wait for device detach if request fails */
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
......@@ -160,19 +153,10 @@ void Mouse_HID_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
......@@ -183,6 +167,9 @@ void Mouse_HID_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Processing HID Report.\r\n"));
/* Get and process the device's first HID report descriptor */
......
......@@ -133,23 +133,17 @@ void StillImage_Task(void)
switch (USB_HostState)
{
case HOST_STATE_Addressed:
/* Standard request to set the device configuration to configuration 1 */
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = 1,
.wIndex = 0,
.wLength = 0,
};
/* Select the control pipe for the request transfer */
Pipe_SelectPipe(PIPE_CONTROLPIPE);
puts_P(PSTR("Getting Config Data.\r\n"));
/* Send the request, display error and wait for device detach if request fails */
if (USB_Host_SendControlRequest(NULL) != HOST_SENDCONTROL_Successful)
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
{
puts_P(PSTR("Control error.\r\n"));
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
......@@ -159,20 +153,10 @@ void StillImage_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
if (ErrorCode == ControlError)
puts_P(PSTR("Control Error (Get Configuration).\r\n"));
else
puts_P(PSTR("Invalid Device.\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
puts_P(PSTR("Control error.\r\n"));
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
......@@ -182,6 +166,9 @@ void StillImage_Task(void)
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Still Image Device Enumerated.\r\n"));
USB_HostState = HOST_STATE_Ready;
......
This diff is collapsed.
......@@ -285,4 +285,21 @@ static void USB_Host_ResetDevice(void)
USB_INT_Enable(USB_INT_DDISCI);
}
uint8_t USB_Host_SetDeviceConfiguration(uint8_t ConfigNumber)
{
USB_ControlRequest = (USB_Request_Header_t)
{
.bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),
.bRequest = REQ_SetConfiguration,
.wValue = ConfigNumber,
.wIndex = 0,
.wLength = 0,
};
Pipe_SelectPipe(PIPE_CONTROLPIPE);
return USB_Host_SendControlRequest(NULL);
}
#endif
......@@ -173,6 +173,19 @@
#define USB_Host_IsResumeFromWakeupRequestSent() ((UHCON & (1 << RESUME)) ? false : true)
#endif
/* Function Prototypes: */
/** Convenience function. This routine sends a SetConfiguration standard request to the attached
* device, with the given configuration index. This can be used to easily set the device
* configuration without creating and sending the request manually.
*
* \note After this routine returns, the control pipe will be selected.
*
* \param ConfigNumber Configuration index to send to the device
*
* \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
*/
uint8_t USB_Host_SetDeviceConfiguration(uint8_t ConfigNumber);
/* Enums: */
/** Enum for the various states of the USB Host state machine. Only some states are
* implemented in the LUFA library - other states are left to the user to implement.
......
......@@ -18,6 +18,8 @@
* to only unfreeze and check one data pipe at a time)
* - Internal per-device preprocessing conditions changed to per-device series rather than per controller group for finer-grain
* internal control
* - Added new USB_Host_SetDeviceConfiguration() convenience function for easy configuration selection of devices while in USB
* host mode
*
*
* \section Sec_ChangeLog090605 Version 090605
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment