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 \ref Group_Events 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 EVENT_HANDLER(USB_VBUSChange
) 
  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 EVENT_HANDLER(USB_VBUSConnect
) 
  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 EVENT_HANDLER(USB_VBUSDisconnect
) 
  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 EVENT_HANDLER(USB_Connect
) 
  81         puts_P(PSTR(EVENT_PREFIX 
"USB  +\r\n")); 
  82         LEDs_SetAllLEDs(LEDS_LED2 
| LEDS_LED3 
| LEDS_LED4
); 
  84         Scheduler_SetTaskMode(USB_USBTask
, TASK_RUN
); 
  88  *  Event handler for the USB_Disconnect event. When fired, the event is logged to the USART and the 
  91 EVENT_HANDLER(USB_Disconnect
) 
  93         Scheduler_SetTaskMode(USB_USBTask
, TASK_STOP
); 
  95         puts_P(PSTR(EVENT_PREFIX 
"USB  -\r\n")); 
  96         LEDs_SetAllLEDs(LEDS_LED2 
| LEDS_LED3 
| LEDS_LED3
); 
  99 /** Event handler for the USB_Suspend event. When fired, the event is logged to the USART. */ 
 100 EVENT_HANDLER(USB_Suspend
) 
 102         puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW 
"USB Sleep\r\n")); 
 103         LEDs_SetAllLEDs(LEDS_ALL_LEDS
); 
 106 /** Event handler for the USB_WakeUp event. When fired, the event is logged to the USART. */ 
 107 EVENT_HANDLER(USB_WakeUp
) 
 109         puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN 
"USB Wakeup\r\n")); 
 110         LEDs_SetAllLEDs(LEDS_LED2 
| LEDS_LED4
); 
 113 /** Event handler for the USB_Reset event. When fired, the event is logged to the USART. */ 
 114 EVENT_HANDLER(USB_Reset
) 
 116         puts_P(PSTR(EVENT_PREFIX 
"USB Reset\r\n")); 
 119 /** Event handler for the USB_UIDChange event. When fired, the event is logged to the USART. */ 
 120 EVENT_HANDLER(USB_UIDChange
) 
 124         puts_P(PSTR(EVENT_PREFIX 
"UID Change\r\n")); 
 126         if (USB_CurrentMode 
== USB_MODE_DEVICE
) 
 127           ModeStrPtr 
= PSTR("HOST"); 
 128         else if (USB_CurrentMode 
== USB_MODE_HOST
) 
 129           ModeStrPtr 
= PSTR("DEVICE"); 
 131           ModeStrPtr 
= PSTR("N/A"); 
 133         LEDs_SetAllLEDs(LEDS_LED2 
| LEDS_LED3
); 
 135         printf_P(PSTR(" -- New Mode %S\r\n"), ModeStrPtr
); 
 139  *  Event handler for the USB_PowerOnFail event. When fired, the event is logged to the USART and the program 
 142 EVENT_HANDLER(USB_InitFailure
) 
 146         puts_P(PSTR(EVENT_PREFIX ESC_BG_RED 
"Power On Fail\r\n")); 
 148         if (USB_CurrentMode 
== USB_MODE_DEVICE
) 
 149           ModeStrPtr 
= PSTR("DEVICE"); 
 150         else if (USB_CurrentMode 
== USB_MODE_HOST
) 
 151           ModeStrPtr 
= PSTR("HOST"); 
 153           ModeStrPtr 
= PSTR("N/A"); 
 155         printf_P(PSTR(" -- Mode %S\r\n"), ModeStrPtr
); 
 156         printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
); 
 162  *  Event handler for the USB_HostError event. When fired, the event is logged to the USART and the program 
 165 EVENT_HANDLER(USB_HostError
) 
 167         puts_P(PSTR(EVENT_PREFIX ESC_BG_RED 
"Host Mode Error\r\n")); 
 168         printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
); 
 173 /** Event handler for the USB_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */ 
 174 EVENT_HANDLER(USB_DeviceEnumerationFailed
) 
 176         puts_P(PSTR(ESC_BG_RED 
"Dev Enum Error\r\n")); 
 177         printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
); 
 181  *  Event handler for the USB_DeviceError event. When fired, the event is logged to the USART and the program 
 184 EVENT_HANDLER(USB_DeviceError
) 
 186         puts_P(PSTR(EVENT_PREFIX ESC_BG_RED 
"Device Mode Error\r\n")); 
 187         printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode
); 
 192 /** Event handler for the USB_UnhandledControlPacket event. When fired, the event is logged to the USART. */ 
 193 EVENT_HANDLER(USB_UnhandledControlPacket
) 
 195         puts_P(PSTR(EVENT_PREFIX 
"Ctrl Request\r\n")); 
 196         printf_P(PSTR(" -- Req Data %d\r\n"), USB_ControlRequest
.bRequest
); 
 197         printf_P(PSTR(" -- Req Type %d\r\n"), USB_ControlRequest
.bmRequestType
); 
 198         printf_P(PSTR(" -- Req Length %d\r\n"), USB_ControlRequest
.wLength
); 
 201 /** Event handler for the USB_ConfigurationChanged event. When fired, the event is logged to the USART. */ 
 202 EVENT_HANDLER(USB_ConfigurationChanged
) 
 204         puts_P(PSTR(EVENT_PREFIX 
"Configuration Number Changed\r\n")); 
 206         LEDs_SetAllLEDs(LEDS_LED2 
| LEDS_LED4
); 
 209 /** Event handler for the USB_DeviceAttached event. When fired, the event is logged to the USART. */ 
 210 EVENT_HANDLER(USB_DeviceAttached
) 
 212         puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN 
"Device +\r\n")); 
 214         Scheduler_SetTaskMode(USB_USBTask
, TASK_RUN
); 
 217 /** Event handler for the USB_DeviceUnattached event. When fired, the event is logged to the USART. */ 
 218 EVENT_HANDLER(USB_DeviceUnattached
) 
 220         puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW 
"Device -\r\n")); 
 223 /** Event handler for the USB_DeviceEnumerationComplete event. When fired, the event is logged to the USART. */ 
 224 EVENT_HANDLER(USB_DeviceEnumerationComplete
) 
 226         puts_P(PSTR(EVENT_PREFIX 
"Device Enumeration Complete\r\n"));