\r
#include "PrinterHost.h"\r
\r
-/* Globals */\r
uint8_t PrinterProtocol;\r
\r
\r
switch (USB_HostState)\r
{\r
case HOST_STATE_Addressed:\r
- /* Standard request to set the device configuration to configuration 1 */\r
- USB_ControlRequest = (USB_Request_Header_t)\r
- {\r
- bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
- bRequest: REQ_SetConfiguration,\r
- wValue: 1,\r
- wIndex: 0,\r
- wLength: 0,\r
- };\r
- \r
- /* Send the request, display error and wait for device detatch if request fails */\r
- if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
- {\r
- puts_P(PSTR("Control Error (Set Configuration).\r\n"));\r
- printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
-\r
- /* Indicate error via status LEDs */\r
- LEDs_SetAllLEDs(LEDS_LED1);\r
-\r
- /* Wait until USB device disconnected */\r
- while (USB_IsConnected);\r
- break;\r
- }\r
- \r
- USB_HostState = HOST_STATE_Configured;\r
- break;\r
- case HOST_STATE_Configured:\r
puts_P(PSTR("Getting Config Data.\r\n"));\r
+ \r
+ /* Select the control pipe for the request transfer */\r
+ Pipe_SelectPipe(PIPE_CONTROLPIPE); \r
\r
/* Get and process the configuration descriptor data */\r
if ((ErrorCode = ProcessConfigurationDescriptor()) != SuccessfulConfigRead)\r
while (USB_IsConnected);\r
break;\r
}\r
+ \r
+ /* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */\r
+ if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)\r
+ {\r
+ puts_P(PSTR("Control Error (Set Configuration).\r\n"));\r
+ printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
+\r
+ /* Indicate error via status LEDs */\r
+ LEDs_SetAllLEDs(LEDS_LED1);\r
+\r
+ /* Wait until USB device disconnected */\r
+ while (USB_IsConnected);\r
+ break;\r
+ }\r
\r
+ USB_HostState = HOST_STATE_Configured;\r
+ break;\r
+ case HOST_STATE_Configured:\r
puts_P(PSTR("Printer Enumerated.\r\n"));\r
- \r
+ \r
USB_HostState = HOST_STATE_Ready;\r
break;\r
case HOST_STATE_Ready:\r
/* Indicate device busy via the status LEDs */\r
LEDs_SetAllLEDs(LEDS_LED3 | LEDS_LED4);\r
\r
- if (!(GetDeviceID()))\r
+ printf_P(PSTR("Printer Protocol: %d\r\n"), PrinterProtocol);\r
+ \r
+ puts_P(PSTR("Retrieving Device ID...\r\n"));\r
+ \r
+ Device_ID_String_t DeviceIDString;\r
+ if (Printer_GetDeviceID(&DeviceIDString) != HOST_SENDCONTROL_Successful)\r
{\r
/* Indicate error via status LEDs */\r
LEDs_SetAllLEDs(LEDS_LED1);\r
while (USB_IsConnected);\r
break;\r
}\r
+\r
+ printf_P(PSTR("Printer Device ID: %s\r\n"), DeviceIDString.String);\r
\r
/* Indicate device no longer busy */\r
LEDs_SetAllLEDs(LEDS_LED4);\r
break;\r
}\r
}\r
-\r
-bool GetDeviceID(void)\r
-{\r
- Device_ID_String_t DeviceIDString;\r
-\r
- /* Request to retrieve the device ID string */\r
- USB_ControlRequest = (USB_Request_Header_t)\r
- {\r
- bmRequestType: (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),\r
- bRequest: GET_DEVICE_ID,\r
- wValue: 0,\r
- wIndex: 0,\r
- wLength: sizeof(DeviceIDString),\r
- };\r
-\r
- printf("Error Code: %d", USB_Host_SendControlRequest(&DeviceIDString));\r
-\r
- /* Send the request, display error and wait for device detatch if request fails */\r
- if (USB_Host_SendControlRequest(&DeviceIDString) != HOST_SENDCONTROL_Successful)\r
- return false;\r
-\r
- /* Reverse the order of the string length as it is sent in big-endian format */\r
- DeviceIDString.Length = SwapEndian_16(DeviceIDString.Length);\r
- \r
- printf("%s", DeviceIDString.String);\r
- \r
- return true;\r
-}\r