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_FG_RED ESC_INVERSE_ON
"\r\n**PROGRAM ABORT**" ESC_FG_WHITE
));
57 /** Event handler for the USB_UIDChange event. When fired, the event is logged to the USART. */
58 void EVENT_USB_UIDChange(void)
62 puts_P(PSTR(ESC_FG_RED EVENT_PREFIX
"UID Change\r\n"));
64 if (USB_CurrentMode
== USB_MODE_DEVICE
)
65 ModeStrPtr
= PSTR("DEVICE");
66 else if (USB_CurrentMode
== USB_MODE_HOST
)
67 ModeStrPtr
= PSTR("HOST");
69 ModeStrPtr
= PSTR("N/A");
71 printf_P(PSTR(" -- New Mode %S\r\n" ESC_FG_WHITE
), ModeStrPtr
);
75 * Event handler for the USB_InitFailure event. When fired, the event is logged to the USART and the program
78 void EVENT_USB_InitFailure(const uint8_t ErrorCode
)
82 puts_P(PSTR(ESC_FG_RED EVENT_PREFIX
"Power On Fail\r\n"));
84 if (USB_CurrentMode
== USB_MODE_DEVICE
)
85 ModeStrPtr
= PSTR("DEVICE");
86 else if (USB_CurrentMode
== USB_MODE_HOST
)
87 ModeStrPtr
= PSTR("HOST");
89 ModeStrPtr
= PSTR("N/A");
91 printf_P(PSTR(" -- Mode %S\r\n"), ModeStrPtr
);
92 printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE
), ErrorCode
);
97 /** Event handler for the USB_Device_Connect event. When fired, the event is logged to the USART. */
98 void EVENT_USB_Device_Connect(void)
100 puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX
"USB Connect\r\n" ESC_FG_WHITE
));
103 /** Event handler for the USB_Device_Disconnect event. When fired, the event is logged to the USART. */
104 void EVENT_USB_Device_Disconnect(void)
106 puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX
"USB Disconnect\r\n" ESC_FG_WHITE
));
109 /** Event handler for the USB_Device_Suspend event. When fired, the event is logged to the USART. */
110 void EVENT_USB_Device_Suspend(void)
112 puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX
"USB Sleep\r\n" ESC_FG_WHITE
));
115 /** Event handler for the USB_Device_WakeUp event. When fired, the event is logged to the USART. */
116 void EVENT_USB_Device_WakeUp(void)
118 puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX
"USB Wakeup\r\n" ESC_FG_WHITE
));
121 /** Event handler for the USB_Device_Reset event. When fired, the event is logged to the USART. */
122 void EVENT_USB_Device_Reset(void)
124 puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX
"USB Reset\r\n" ESC_FG_WHITE
));
127 /** Event handler for the USB_Device_UnhandledControlRequest event. When fired, the event is logged to the USART. */
128 void EVENT_USB_Device_UnhandledControlRequest(void)
130 puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX
"Ctrl Request\r\n"));
131 printf_P(PSTR(" -- Req Data %d\r\n"), USB_ControlRequest
.bRequest
);
132 printf_P(PSTR(" -- Req Type %d\r\n"), USB_ControlRequest
.bmRequestType
);
133 printf_P(PSTR(" -- Req Length %d\r\n" ESC_FG_WHITE
), USB_ControlRequest
.wLength
);
136 /** Event handler for the USB_Device_ConfigurationChanged event. When fired, the event is logged to the USART. */
137 void EVENT_USB_Device_ConfigurationChanged(void)
139 puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX
"Configuration Number Changed\r\n" ESC_FG_WHITE
));
143 * Event handler for the USB_Host_HostError event. When fired, the event is logged to the USART and the program
146 void EVENT_USB_Host_HostError(const uint8_t ErrorCode
)
148 puts_P(PSTR(ESC_FG_RED EVENT_PREFIX
"Host Mode Error\r\n"));
149 printf_P(PSTR(" -- Error Code %d\r\n" ESC_FG_WHITE
), ErrorCode
);
154 /** Event handler for the USB_Host_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */
155 void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode
, const uint8_t SubErrorCode
)
157 puts_P(PSTR(ESC_FG_RED EVENT_PREFIX
"Dev Enum Error\r\n"));
158 printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
);
159 printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode
);
160 printf_P(PSTR(" -- In State %d\r\n" ESC_FG_WHITE
), USB_HostState
);
163 /** Event handler for the USB_Host_DeviceEnumerationComplete event. When fired, the event is logged to the USART. */
164 void EVENT_USB_Host_DeviceEnumerationComplete(void)
166 puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX
"Device Enumeration Complete\r\n" ESC_FG_WHITE
));
169 /** Event handler for the USB_Host_DeviceAttached event. When fired, the event is logged to the USART. */
170 void EVENT_USB_Host_DeviceAttached(void)
172 puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX
"Device Attached\r\n" ESC_FG_WHITE
));
175 /** Event handler for the USB_Host_DeviceUnattached event. When fired, the event is logged to the USART. */
176 void EVENT_USB_Host_DeviceUnattached(void)
178 puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX
"Device Unattached\r\n" ESC_FG_WHITE
));