TestEvents.c 7.08 KB
 Dean Camera committed Feb 23, 2009 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 /* LUFA Library Copyright (C) Dean Camera, 2009. dean [at] fourwalledcubicle [dot] com www.fourwalledcubicle.com */ /* Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com) Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that the copyright notice and this permission notice and warranty disclaimer appear in supporting documentation, and that the name of the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. The author disclaim all warranties with regard to this software, including all implied warranties of merchantability and fitness. In no event shall the author be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software. */ /** \file * * This file contains dummy handlers for all the possible USB events passed to the  Dean Camera committed May 04, 2009 34  * application by the library (see \ref Group_Events documentation for more details on USB events).  Dean Camera committed Feb 23, 2009 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57  * * Each event is caught and printed to the USART so that they may be monitored. */ #define INCLUDE_FROM_TESTEVENTS_C #include "TestEvents.h" /** Simple routine which aborts the program execution when a fatal error occurs, and is passed to the * application via an event. When run, this function shuts down the USB interface, indicates an error * via the board LEDs, prints an error message to the USART and then enters an infinite loop, preventing * any more application code (other than interrupts) from executing. */ static void Abort_Program(void) { USB_ShutDown(); LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED3); puts_P(PSTR(ESC_INVERSE_ON "\r\n**PROGRAM ABORT**")); for (;;); } /** Event handler for the USB_VBUSChange event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 58 void EVENT_USB_VBUSChange(void)  Dean Camera committed Feb 23, 2009 59 60 61 62 63 { puts_P(PSTR(EVENT_PREFIX "VBUS Change\r\n")); } /** Event handler for the USB_VBUSConnect event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 64 void EVENT_USB_VBUSConnect(void)  Dean Camera committed Feb 23, 2009 65 66 67 68 69 { puts_P(PSTR(EVENT_PREFIX "VBUS +\r\n")); } /** Event handler for the USB_VBUSDisconnect event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 70 void EVENT_USB_VBUSDisconnect(void)  Dean Camera committed Feb 23, 2009 71 72 73 74 75 76 77 78 { puts_P(PSTR(EVENT_PREFIX "VBUS -\r\n")); } /** * Event handler for the USB_Connect event. When fired, the event is logged to the USART and the * USB task started. */  Dean Camera committed May 18, 2009 79 void EVENT_USB_Connect(void)  Dean Camera committed Feb 23, 2009 80 81 82 83 84 85 86 87 88 89 90 { puts_P(PSTR(EVENT_PREFIX "USB +\r\n")); LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3 | LEDS_LED4); Scheduler_SetTaskMode(USB_USBTask, TASK_RUN); } /** * Event handler for the USB_Disconnect event. When fired, the event is logged to the USART and the * USB task stopped. */  Dean Camera committed May 18, 2009 91 void EVENT_USB_Disconnect(void)  Dean Camera committed Feb 23, 2009 92 93 94 95 96 97 98 99 { Scheduler_SetTaskMode(USB_USBTask, TASK_STOP); puts_P(PSTR(EVENT_PREFIX "USB -\r\n")); LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3 | LEDS_LED3); } /** Event handler for the USB_Suspend event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 100 void EVENT_USB_Suspend(void)  Dean Camera committed Feb 23, 2009 101 102 103 104 105 106 { puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW "USB Sleep\r\n")); LEDs_SetAllLEDs(LEDS_ALL_LEDS); } /** Event handler for the USB_WakeUp event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 107 void EVENT_USB_WakeUp(void)  Dean Camera committed Feb 23, 2009 108 109 110 111 112 113 { puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN "USB Wakeup\r\n")); LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED4); } /** Event handler for the USB_Reset event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 114 void EVENT_USB_Reset(void)  Dean Camera committed Feb 23, 2009 115 116 117 118 119 { puts_P(PSTR(EVENT_PREFIX "USB Reset\r\n")); } /** Event handler for the USB_UIDChange event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 120 void EVENT_USB_UIDChange(void)  Dean Camera committed Feb 23, 2009 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 { char* ModeStrPtr; puts_P(PSTR(EVENT_PREFIX "UID Change\r\n")); if (USB_CurrentMode == USB_MODE_DEVICE) ModeStrPtr = PSTR("HOST"); else if (USB_CurrentMode == USB_MODE_HOST) ModeStrPtr = PSTR("DEVICE"); else ModeStrPtr = PSTR("N/A"); LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3); printf_P(PSTR(" -- New Mode %S\r\n"), ModeStrPtr); } /** * Event handler for the USB_PowerOnFail event. When fired, the event is logged to the USART and the program * execution aborted. */  Dean Camera committed May 18, 2009 142 void EVENT_USB_InitFailure(const uint8_t ErrorCode)  Dean Camera committed Feb 23, 2009 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 { char* ModeStrPtr; puts_P(PSTR(EVENT_PREFIX ESC_BG_RED "Power On Fail\r\n")); if (USB_CurrentMode == USB_MODE_DEVICE) ModeStrPtr = PSTR("DEVICE"); else if (USB_CurrentMode == USB_MODE_HOST) ModeStrPtr = PSTR("HOST"); else ModeStrPtr = PSTR("N/A"); printf_P(PSTR(" -- Mode %S\r\n"), ModeStrPtr); printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode); Abort_Program(); } /** * Event handler for the USB_HostError event. When fired, the event is logged to the USART and the program * execution aborted. */  Dean Camera committed May 18, 2009 165 void EVENT_USB_HostError(const uint8_t ErrorCode)  Dean Camera committed Feb 23, 2009 166 167 168 169 170 171 172 173 { puts_P(PSTR(EVENT_PREFIX ESC_BG_RED "Host Mode Error\r\n")); printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode); Abort_Program(); } /** Event handler for the USB_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 174 void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)  Dean Camera committed Feb 23, 2009 175 176 177 { puts_P(PSTR(ESC_BG_RED "Dev Enum Error\r\n")); printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);  Dean Camera committed May 12, 2009 178 179  printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode); printf_P(PSTR(" -- In State %d\r\n"), USB_HostState);  Dean Camera committed Feb 23, 2009 180 181 182 } /** Event handler for the USB_UnhandledControlPacket event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 183 void EVENT_USB_UnhandledControlPacket(void)  Dean Camera committed Feb 23, 2009 184 185 { puts_P(PSTR(EVENT_PREFIX "Ctrl Request\r\n"));  Dean Camera committed Apr 22, 2009 186 187 188  printf_P(PSTR(" -- Req Data %d\r\n"), USB_ControlRequest.bRequest); printf_P(PSTR(" -- Req Type %d\r\n"), USB_ControlRequest.bmRequestType); printf_P(PSTR(" -- Req Length %d\r\n"), USB_ControlRequest.wLength);  Dean Camera committed Feb 23, 2009 189 190 191 } /** Event handler for the USB_ConfigurationChanged event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 192 void EVENT_USB_ConfigurationChanged(void)  Dean Camera committed Feb 23, 2009 193 194 195 196 197 198 199 { puts_P(PSTR(EVENT_PREFIX "Configuration Number Changed\r\n")); LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED4); } /** Event handler for the USB_DeviceAttached event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 200 void EVENT_USB_DeviceAttached(void)  Dean Camera committed Feb 23, 2009 201 202 203 204 205 206 207 { puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN "Device +\r\n")); Scheduler_SetTaskMode(USB_USBTask, TASK_RUN); } /** Event handler for the USB_DeviceUnattached event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 208 void EVENT_USB_DeviceUnattached(void)  Dean Camera committed Feb 23, 2009 209 210 211 212 213 { puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW "Device -\r\n")); } /** Event handler for the USB_DeviceEnumerationComplete event. When fired, the event is logged to the USART. */  Dean Camera committed May 18, 2009 214 void EVENT_USB_DeviceEnumerationComplete(void)  Dean Camera committed Feb 23, 2009 215 216 217 { puts_P(PSTR(EVENT_PREFIX "Device Enumeration Complete\r\n")); }