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,36 +132,6 @@ void CDC_Host_Task(void) ...@@ -132,36 +132,6 @@ void CDC_Host_Task(void)
switch (USB_HostState) switch (USB_HostState)
{ {
case HOST_STATE_Addressed: 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("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n")); puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */ /* Get and process the configuration descriptor data */
...@@ -181,7 +151,24 @@ void CDC_Host_Task(void) ...@@ -181,7 +151,24 @@ void CDC_Host_Task(void)
while (USB_IsConnected); while (USB_IsConnected);
break; break;
} }
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("CDC Device Enumerated.\r\n")); puts_P(PSTR("CDC Device Enumerated.\r\n"));
USB_HostState = HOST_STATE_Ready; USB_HostState = HOST_STATE_Ready;
......
...@@ -233,36 +233,6 @@ void HID_Host_Task(void) ...@@ -233,36 +233,6 @@ void HID_Host_Task(void)
switch (USB_HostState) switch (USB_HostState)
{ {
case HOST_STATE_Addressed: 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("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n")); puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */ /* Get and process the configuration descriptor data */
...@@ -282,7 +252,24 @@ void HID_Host_Task(void) ...@@ -282,7 +252,24 @@ void HID_Host_Task(void)
while (USB_IsConnected); while (USB_IsConnected);
break; break;
} }
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("HID Device Enumerated.\r\n")); puts_P(PSTR("HID Device Enumerated.\r\n"));
USB_HostState = HOST_STATE_Ready; USB_HostState = HOST_STATE_Ready;
......
...@@ -197,36 +197,6 @@ void Keyboard_HID_Task(void) ...@@ -197,36 +197,6 @@ void Keyboard_HID_Task(void)
switch (USB_HostState) switch (USB_HostState)
{ {
case HOST_STATE_Addressed: 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("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n")); puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */ /* Get and process the configuration descriptor data */
...@@ -247,6 +217,23 @@ void Keyboard_HID_Task(void) ...@@ -247,6 +217,23 @@ void Keyboard_HID_Task(void)
break; break;
} }
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
/* HID class request to set the keyboard protocol to the Boot Protocol */ /* HID class request to set the keyboard protocol to the Boot Protocol */
USB_ControlRequest = (USB_Request_Header_t) USB_ControlRequest = (USB_Request_Header_t)
{ {
......
...@@ -132,36 +132,6 @@ void Keyboard_HID_Task(void) ...@@ -132,36 +132,6 @@ void Keyboard_HID_Task(void)
switch (USB_HostState) switch (USB_HostState)
{ {
case HOST_STATE_Addressed: 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("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n")); puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */ /* Get and process the configuration descriptor data */
...@@ -181,7 +151,25 @@ void Keyboard_HID_Task(void) ...@@ -181,7 +151,25 @@ void Keyboard_HID_Task(void)
while (USB_IsConnected); while (USB_IsConnected);
break; break;
} }
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Processing HID Report.\r\n")); puts_P(PSTR("Processing HID Report.\r\n"));
/* Get and process the device's first HID report descriptor */ /* Get and process the device's first HID report descriptor */
......
...@@ -138,36 +138,6 @@ void MassStorage_Task(void) ...@@ -138,36 +138,6 @@ void MassStorage_Task(void)
switch (USB_HostState) switch (USB_HostState)
{ {
case HOST_STATE_Addressed: 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("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n")); puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */ /* Get and process the configuration descriptor data */
...@@ -188,6 +158,23 @@ void MassStorage_Task(void) ...@@ -188,6 +158,23 @@ void MassStorage_Task(void)
break; break;
} }
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Mass Storage Disk Enumerated.\r\n")); puts_P(PSTR("Mass Storage Disk Enumerated.\r\n"));
USB_HostState = HOST_STATE_Ready; USB_HostState = HOST_STATE_Ready;
......
...@@ -193,36 +193,6 @@ void Mouse_HID_Task(void) ...@@ -193,36 +193,6 @@ void Mouse_HID_Task(void)
switch (USB_HostState) switch (USB_HostState)
{ {
case HOST_STATE_Addressed: 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("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n")); puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */ /* Get and process the configuration descriptor data */
...@@ -242,7 +212,24 @@ void Mouse_HID_Task(void) ...@@ -242,7 +212,24 @@ void Mouse_HID_Task(void)
while (USB_IsConnected); while (USB_IsConnected);
break; break;
} }
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error status */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
/* HID class request to set the mouse protocol to the Boot Protocol */ /* HID class request to set the mouse protocol to the Boot Protocol */
USB_ControlRequest = (USB_Request_Header_t) USB_ControlRequest = (USB_Request_Header_t)
{ {
......
...@@ -132,37 +132,7 @@ void Mouse_HID_Task(void) ...@@ -132,37 +132,7 @@ void Mouse_HID_Task(void)
/* Switch to determine what user-application handled host state the host state machine is in */ /* Switch to determine what user-application handled host state the host state machine is in */
switch (USB_HostState) switch (USB_HostState)
{ {
case HOST_STATE_Addressed: 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("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n")); puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */ /* Get and process the configuration descriptor data */
...@@ -183,6 +153,23 @@ void Mouse_HID_Task(void) ...@@ -183,6 +153,23 @@ void Mouse_HID_Task(void)
break; break;
} }
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR("Control Error (Set Configuration).\r\n"));
printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Processing HID Report.\r\n")); puts_P(PSTR("Processing HID Report.\r\n"));
/* Get and process the device's first HID report descriptor */ /* Get and process the device's first HID report descriptor */
......
...@@ -133,35 +133,6 @@ void StillImage_Task(void) ...@@ -133,35 +133,6 @@ void StillImage_Task(void)
switch (USB_HostState) switch (USB_HostState)
{ {
case HOST_STATE_Addressed: 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 (USB_Host_SendControlRequest(NULL) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR("Control error.\r\n"));
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Getting Config Data.\r\n")); puts_P(PSTR("Getting Config Data.\r\n"));
/* Get and process the configuration descriptor data */ /* Get and process the configuration descriptor data */
...@@ -182,6 +153,22 @@ void StillImage_Task(void) ...@@ -182,6 +153,22 @@ void StillImage_Task(void)
break; break;
} }
/* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */
if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)
{
puts_P(PSTR("Control error.\r\n"));
/* Indicate error via status LEDs */
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
/* Wait until USB device disconnected */
while (USB_IsConnected);
break;
}
USB_HostState = HOST_STATE_Configured;
break;
case HOST_STATE_Configured:
puts_P(PSTR("Still Image Device Enumerated.\r\n")); puts_P(PSTR("Still Image Device Enumerated.\r\n"));
USB_HostState = HOST_STATE_Ready; USB_HostState = HOST_STATE_Ready;
......
This diff is collapsed.
...@@ -285,4 +285,21 @@ static void USB_Host_ResetDevice(void) ...@@ -285,4 +285,21 @@ static void USB_Host_ResetDevice(void)
USB_INT_Enable(USB_INT_DDISCI); 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 #endif
...@@ -173,6 +173,19 @@ ...@@ -173,6 +173,19 @@
#define USB_Host_IsResumeFromWakeupRequestSent() ((UHCON & (1 << RESUME)) ? false : true) #define USB_Host_IsResumeFromWakeupRequestSent() ((UHCON & (1 << RESUME)) ? false : true)
#endif #endif
/* Function Prototypes: */
/** Convenience function. This routine sends a SetConfiguration standard request to the attached