3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
33 * This file contains dummy handlers for all the possible USB events passed to the
34 * application by the library (see library documentation for more details on USB events).
36 * Each event is caught and printed to the USART so that they may be monitored.
39 #define INCLUDE_FROM_TESTEVENTS_C
40 #include "TestEvents.h"
42 /** Simple routine which aborts the program execution when a fatal error occurs, and is passed to the
43 * application via an event. When run, this function shuts down the USB interface, indicates an error
44 * via the board LEDs, prints an error message to the USART and then enters an infinite loop, preventing
45 * any more application code (other than interrupts) from executing.
47 static void Abort_Program(void)
51 LEDs_SetAllLEDs(LEDS_LED1
| LEDS_LED3
);
53 puts_P(PSTR(ESC_INVERSE_ON
"\r\n**PROGRAM ABORT**"));
57 /** Event handler for the USB_VBUSChange event. When fired, the event is logged to the USART. */
58 void EVENT_USB_VBUSChange(void)
60 puts_P(PSTR(EVENT_PREFIX
"VBUS Change\r\n"));
63 /** Event handler for the USB_VBUSConnect event. When fired, the event is logged to the USART. */
64 void EVENT_USB_VBUSConnect(void)
66 puts_P(PSTR(EVENT_PREFIX
"VBUS +\r\n"));
69 /** Event handler for the USB_VBUSDisconnect event. When fired, the event is logged to the USART. */
70 void EVENT_USB_VBUSDisconnect(void)
72 puts_P(PSTR(EVENT_PREFIX
"VBUS -\r\n"));
76 * Event handler for the USB_Connect event. When fired, the event is logged to the USART and the
79 void EVENT_USB_Connect(void)
81 puts_P(PSTR(EVENT_PREFIX
"USB +\r\n"));
85 * Event handler for the USB_Disconnect event. When fired, the event is logged to the USART and the
88 void EVENT_USB_Disconnect(void)
90 puts_P(PSTR(EVENT_PREFIX
"USB -\r\n"));
93 /** Event handler for the USB_Suspend event. When fired, the event is logged to the USART. */
94 void EVENT_USB_Suspend(void)
96 puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW
"USB Sleep\r\n"));
99 /** Event handler for the USB_WakeUp event. When fired, the event is logged to the USART. */
100 void EVENT_USB_WakeUp(void)
102 puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN
"USB Wakeup\r\n"));
105 /** Event handler for the USB_Reset event. When fired, the event is logged to the USART. */
106 void EVENT_USB_Reset(void)
108 puts_P(PSTR(EVENT_PREFIX
"USB Reset\r\n"));
111 /** Event handler for the USB_UIDChange event. When fired, the event is logged to the USART. */
112 void EVENT_USB_UIDChange(void)
116 puts_P(PSTR(EVENT_PREFIX
"UID Change\r\n"));
118 if (USB_CurrentMode
== USB_MODE_DEVICE
)
119 ModeStrPtr
= PSTR("HOST");
120 else if (USB_CurrentMode
== USB_MODE_HOST
)
121 ModeStrPtr
= PSTR("DEVICE");
123 ModeStrPtr
= PSTR("N/A");
125 printf_P(PSTR(" -- New Mode %S\r\n"), ModeStrPtr
);
129 * Event handler for the USB_PowerOnFail event. When fired, the event is logged to the USART and the program
132 void EVENT_USB_InitFailure(const uint8_t ErrorCode
)
136 puts_P(PSTR(EVENT_PREFIX ESC_BG_RED
"Power On Fail\r\n"));
138 if (USB_CurrentMode
== USB_MODE_DEVICE
)
139 ModeStrPtr
= PSTR("DEVICE");
140 else if (USB_CurrentMode
== USB_MODE_HOST
)
141 ModeStrPtr
= PSTR("HOST");
143 ModeStrPtr
= PSTR("N/A");
145 printf_P(PSTR(" -- Mode %S\r\n"), ModeStrPtr
);
146 printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
);
152 * Event handler for the USB_HostError event. When fired, the event is logged to the USART and the program
155 void EVENT_USB_HostError(const uint8_t ErrorCode
)
157 puts_P(PSTR(EVENT_PREFIX ESC_BG_RED
"Host Mode Error\r\n"));
158 printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
);
163 /** Event handler for the USB_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */
164 void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode
, const uint8_t SubErrorCode
)
166 puts_P(PSTR(ESC_BG_RED
"Dev Enum Error\r\n"));
167 printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
);
168 printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode
);
169 printf_P(PSTR(" -- In State %d\r\n"), USB_HostState
);
172 /** Event handler for the USB_UnhandledControlPacket event. When fired, the event is logged to the USART. */
173 void EVENT_USB_UnhandledControlPacket(void)
175 puts_P(PSTR(EVENT_PREFIX
"Ctrl Request\r\n"));
176 printf_P(PSTR(" -- Req Data %d\r\n"), USB_ControlRequest
.bRequest
);
177 printf_P(PSTR(" -- Req Type %d\r\n"), USB_ControlRequest
.bmRequestType
);
178 printf_P(PSTR(" -- Req Length %d\r\n"), USB_ControlRequest
.wLength
);
181 /** Event handler for the USB_ConfigurationChanged event. When fired, the event is logged to the USART. */
182 void EVENT_USB_ConfigurationChanged(void)
184 puts_P(PSTR(EVENT_PREFIX
"Configuration Number Changed\r\n"));
187 /** Event handler for the USB_DeviceAttached event. When fired, the event is logged to the USART. */
188 void EVENT_USB_DeviceAttached(void)
190 puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN
"Device +\r\n"));
193 /** Event handler for the USB_DeviceUnattached event. When fired, the event is logged to the USART. */
194 void EVENT_USB_DeviceUnattached(void)
196 puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW
"Device -\r\n"));
199 /** Event handler for the USB_DeviceEnumerationComplete event. When fired, the event is logged to the USART. */
200 void EVENT_USB_DeviceEnumerationComplete(void)
202 puts_P(PSTR(EVENT_PREFIX
"Device Enumeration Complete\r\n"));