this software.\r
*/\r
\r
-/*\r
- USB Printer host demo application.\r
- \r
- ** NOT CURRENTLY FUNCTIONAL - DO NOT USE **\r
-*/\r
+/** \file\r
+ *\r
+ * Main source file for the PrinterHost demo. This file contains the main tasks of\r
+ * the demo and is responsible for the initial application hardware configuration.\r
+ */\r
\r
#include "PrinterHost.h"\r
\r
-\r
+/** Main program entry point. This routine configures the hardware required by the application, then\r
+ * starts the scheduler to run the application tasks.\r
+ */\r
int main(void)\r
{\r
SetupHardware();\r
}\r
}\r
\r
+/** Configures the board hardware and chip peripherals for the demo's functionality. */\r
void SetupHardware(void)\r
{\r
/* Disable watchdog if enabled by bootloader/fuses */\r
USB_Init();\r
}\r
\r
-void EVENT_USB_DeviceAttached(void)\r
+/** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and\r
+ * starts the library USB task to begin the enumeration and USB management process.\r
+ */\r
+void EVENT_USB_Host_DeviceAttached(void)\r
{\r
puts_P(PSTR(ESC_FG_GREEN "Device Attached.\r\n" ESC_FG_WHITE));\r
LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);\r
}\r
\r
-void EVENT_USB_DeviceUnattached(void)\r
+/** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and\r
+ * stops the library USB task management process.\r
+ */\r
+void EVENT_USB_Host_DeviceUnattached(void)\r
{\r
puts_P(PSTR(ESC_FG_GREEN "\r\nDevice Unattached.\r\n" ESC_FG_WHITE));\r
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
}\r
\r
-void EVENT_USB_HostError(uint8_t ErrorCode)\r
+/** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully\r
+ * enumerated by the host and is now ready to be used by the application.\r
+ */\r
+void EVENT_USB_Host_DeviceEnumerationComplete(void)\r
+{\r
+ LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
+}\r
+\r
+/** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */\r
+void EVENT_USB_Host_HostError(uint8_t ErrorCode)\r
{\r
USB_ShutDown();\r
\r
- puts_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"));\r
- printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);\r
+ printf_P(PSTR(ESC_FG_RED "Host Mode Error\r\n"\r
+ " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);\r
\r
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
for(;;);\r
}\r
\r
-void EVENT_USB_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorCode)\r
+/** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while\r
+ * enumerating an attached USB device.\r
+ */\r
+void EVENT_USB_Host_DeviceEnumerationFailed(uint8_t ErrorCode, uint8_t SubErrorCode)\r
{\r
- puts_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"));\r
- printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
- printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE), USB_HostState);\r
+ printf_P(PSTR(ESC_FG_RED "Dev Enum Error\r\n"\r
+ " -- Error Code %d\r\n"\r
+ " -- Sub Error Code %d\r\n"\r
+ " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);\r
\r
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
}\r
\r
-void EVENT_USB_DeviceEnumerationComplete(void)\r
-{\r
- LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
-}\r
-\r
+/** Task to set the configuration of the attached device after it has been enumerated, and to send some test page\r
+ * data to the attached printer.\r
+ */\r
void USB_Printer_Host(void)\r
{\r
uint8_t ErrorCode;\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(ESC_FG_RED "Control Error (Set Configuration).\r\n"));\r
- printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
+ printf_P(PSTR(ESC_FG_RED "Control Error (Set Configuration).\r\n"\r
+ " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
\r
/* Indicate error via status LEDs */\r
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
\r
if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
{\r
- puts_P(PSTR(ESC_FG_RED "Control Error (Set Interface).\r\n"));\r
- printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
+ printf_P(PSTR(ESC_FG_RED "Control Error (Set Interface).\r\n"\r
+ " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
\r
/* Indicate error via status LEDs */\r
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
}\r
}\r
\r
- USB_HostState = HOST_STATE_Configured;\r
- break;\r
- case HOST_STATE_Configured:\r
puts_P(PSTR("Retrieving Device ID...\r\n"));\r
\r
- char DeviceIDString[256];\r
+ char DeviceIDString[300];\r
if ((ErrorCode = Printer_GetDeviceID(DeviceIDString, sizeof(DeviceIDString))) != HOST_SENDCONTROL_Successful)\r
{\r
- puts_P(PSTR(ESC_FG_RED "Control Error (Get DeviceID).\r\n"));\r
- printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
+ printf_P(PSTR(ESC_FG_RED "Control Error (Get Device ID).\r\n"\r
+ " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
\r
/* Indicate error via status LEDs */\r
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
printf_P(PSTR("Printer Device ID: %s\r\n"), DeviceIDString);\r
\r
puts_P(PSTR("Printer Enumerated.\r\n"));\r
- \r
- USB_HostState = HOST_STATE_Ready;\r
+\r
+ USB_HostState = HOST_STATE_Configured;\r
break;\r
- case HOST_STATE_Ready:\r
+ case HOST_STATE_Configured:\r
/* Indicate device busy via the status LEDs */\r
LEDs_SetAllLEDs(LEDMASK_USB_BUSY);\r
\r
- Printer_Data_t TestPageData =\r
- {\r
-// "\033%-12345X\033E LUFA PCL Test Page \033E\033%-12345X",\r
- "\033@\033i\001\033X\001\060\000\r\nLUFA ESCP/2 Test Page\r\n",\r
- (sizeof(TestPageData.Data) - 1)\r
- };\r
+ char TestPageData[] = "\033%-12345X\033E" "LUFA PCL Test Page" "\033E\033%-12345X";\r
+ uint16_t TestPageLength = strlen(TestPageData);\r
\r
- printf_P(PSTR("Sending Test Page (%d bytes)...\r\n"), TestPageData.Length);\r
+ printf_P(PSTR("Sending Test Page (%d bytes)...\r\n"), TestPageLength);\r
\r
- if ((ErrorCode = Printer_SendData(&TestPageData)) != PIPE_RWSTREAM_NoError)\r
+ if ((ErrorCode = Printer_SendData(&TestPageData, TestPageLength)) != PIPE_RWSTREAM_NoError)\r
{\r
- puts_P(PSTR(ESC_FG_RED "Error Sending Test Page.\r\n"));\r
- printf_P(PSTR(" -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
+ printf_P(PSTR(ESC_FG_RED "Error Sending Test Page.\r\n"\r
+ " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode);\r
\r
/* Indicate error via status LEDs */\r
LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r