--- /dev/null
+/*\r
+ LUFA Library\r
+ Copyright (C) Dean Camera, 2009.\r
+ \r
+ dean [at] fourwalledcubicle [dot] com\r
+ www.fourwalledcubicle.com\r
+*/\r
+\r
+/*\r
+ Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+\r
+ Permission to use, copy, modify, and distribute this software\r
+ and its documentation for any purpose and without fee is hereby\r
+ granted, provided that the above copyright notice appear in all\r
+ copies and that both that the copyright notice and this\r
+ permission notice and warranty disclaimer appear in supporting\r
+ documentation, and that the name of the author not be used in\r
+ advertising or publicity pertaining to distribution of the\r
+ software without specific, written prior permission.\r
+\r
+ The author disclaim all warranties with regard to this\r
+ software, including all implied warranties of merchantability\r
+ and fitness. In no event shall the author be liable for any\r
+ special, indirect or consequential damages or any damages\r
+ whatsoever resulting from loss of use, data or profits, whether\r
+ in an action of contract, negligence or other tortious action,\r
+ arising out of or in connection with the use or performance of\r
+ this software.\r
+*/\r
+\r
+/** \file\r
+ *\r
+ * This file contains dummy handlers for all the possible USB events passed to the\r
+ * application by the library (see Events.h documentation for more details on USB events).\r
+ *\r
+ * Each event is caught and printed to the USART so that they may be monitored.\r
+ */\r
+ \r
+#define INCLUDE_FROM_TESTEVENTS_C\r
+#include "TestEvents.h"\r
+\r
+/** Simple routine which aborts the program execution when a fatal error occurs, and is passed to the\r
+ * application via an event. When run, this function shuts down the USB interface, indicates an error\r
+ * via the board LEDs, prints an error message to the USART and then enters an infinite loop, preventing\r
+ * any more application code (other than interrupts) from executing.\r
+ */\r
+static void Abort_Program(void)\r
+{\r
+ USB_ShutDown();\r
+\r
+ LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED3);\r
+\r
+ puts_P(PSTR(ESC_INVERSE_ON "\r\n**PROGRAM ABORT**"));\r
+ for (;;);\r
+}\r
+\r
+/** Event handler for the USB_VBUSChange event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_VBUSChange)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX "VBUS Change\r\n"));\r
+}\r
+\r
+/** Event handler for the USB_VBUSConnect event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_VBUSConnect)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX "VBUS +\r\n"));\r
+}\r
+\r
+/** Event handler for the USB_VBUSDisconnect event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_VBUSDisconnect)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX "VBUS -\r\n"));\r
+}\r
+\r
+/**\r
+ * Event handler for the USB_Connect event. When fired, the event is logged to the USART and the\r
+ * USB task started.\r
+ */\r
+EVENT_HANDLER(USB_Connect)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX "USB +\r\n"));\r
+ LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3 | LEDS_LED4);\r
+ \r
+ Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+}\r
+\r
+/**\r
+ * Event handler for the USB_Disconnect event. When fired, the event is logged to the USART and the\r
+ * USB task stopped.\r
+ */\r
+EVENT_HANDLER(USB_Disconnect)\r
+{\r
+ Scheduler_SetTaskMode(USB_USBTask, TASK_STOP);\r
+\r
+ puts_P(PSTR(EVENT_PREFIX "USB -\r\n"));\r
+ LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3 | LEDS_LED3);\r
+}\r
+\r
+/** Event handler for the USB_Suspend event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_Suspend)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW "USB Sleep\r\n"));\r
+ LEDs_SetAllLEDs(LEDS_ALL_LEDS);\r
+}\r
+\r
+/** Event handler for the USB_WakeUp event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_WakeUp)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN "USB Wakeup\r\n"));\r
+ LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED4);\r
+}\r
+\r
+/** Event handler for the USB_Reset event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_Reset)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX "USB Reset\r\n"));\r
+}\r
+\r
+/** Event handler for the USB_UIDChange event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_UIDChange)\r
+{\r
+ char* ModeStrPtr;\r
+\r
+ puts_P(PSTR(EVENT_PREFIX "UID Change\r\n"));\r
+\r
+ if (USB_CurrentMode == USB_MODE_DEVICE)\r
+ ModeStrPtr = PSTR("HOST");\r
+ else if (USB_CurrentMode == USB_MODE_HOST)\r
+ ModeStrPtr = PSTR("DEVICE");\r
+ else\r
+ ModeStrPtr = PSTR("N/A");\r
+ \r
+ LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3);\r
+\r
+ printf_P(PSTR(" -- New Mode %S\r\n"), ModeStrPtr);\r
+}\r
+\r
+/**\r
+ * Event handler for the USB_PowerOnFail event. When fired, the event is logged to the USART and the program\r
+ * execution aborted.\r
+ */\r
+EVENT_HANDLER(USB_PowerOnFail)\r
+{\r
+ char* ModeStrPtr;\r
+ \r
+ puts_P(PSTR(EVENT_PREFIX ESC_BG_RED "Power On Fail\r\n"));\r
+\r
+ if (USB_CurrentMode == USB_MODE_DEVICE)\r
+ ModeStrPtr = PSTR("DEVICE");\r
+ else if (USB_CurrentMode == USB_MODE_HOST)\r
+ ModeStrPtr = PSTR("HOST");\r
+ else\r
+ ModeStrPtr = PSTR("N/A");\r
+ \r
+ printf_P(PSTR(" -- Mode %S\r\n"), ModeStrPtr);\r
+ printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
+\r
+ Abort_Program();\r
+}\r
+\r
+/**\r
+ * Event handler for the USB_HostError event. When fired, the event is logged to the USART and the program\r
+ * execution aborted.\r
+ */\r
+EVENT_HANDLER(USB_HostError)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX ESC_BG_RED "Host Mode Error\r\n"));\r
+ printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
+\r
+ Abort_Program();\r
+}\r
+\r
+/** Event handler for the USB_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_DeviceEnumerationFailed)\r
+{\r
+ puts_P(PSTR(ESC_BG_RED "Dev Enum Error\r\n"));\r
+ printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
+}\r
+\r
+/**\r
+ * Event handler for the USB_DeviceError event. When fired, the event is logged to the USART and the program\r
+ * execution aborted.\r
+ */\r
+EVENT_HANDLER(USB_DeviceError)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX ESC_BG_RED "Device Mode Error\r\n"));\r
+ printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
+\r
+ Abort_Program();\r
+}\r
+\r
+/** Event handler for the USB_UnhandledControlPacket event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_UnhandledControlPacket)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX "Ctrl Request\r\n"));\r
+ printf_P(PSTR(" -- Req Data %d\r\n"), bRequest);\r
+ printf_P(PSTR(" -- Req Type %d\r\n"), bmRequestType);\r
+}\r
+\r
+/** Event handler for the USB_ConfigurationChanged event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_ConfigurationChanged)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX "Configuration Number Changed\r\n"));\r
+\r
+ LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED4);\r
+}\r
+\r
+/** Event handler for the USB_DeviceAttached event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_DeviceAttached)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN "Device +\r\n"));\r
+\r
+ Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+}\r
+\r
+/** Event handler for the USB_DeviceUnattached event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_DeviceUnattached)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW "Device -\r\n"));\r
+}\r
+\r
+/** Event handler for the USB_DeviceEnumerationComplete event. When fired, the event is logged to the USART. */\r
+EVENT_HANDLER(USB_DeviceEnumerationComplete)\r
+{\r
+ puts_P(PSTR(EVENT_PREFIX "Device Enumeration Complete\r\n"));\r
+}\r