Added return values to the CDC and MIDI class driver transmit functions.
[pub/USBasp.git] / Demos / OTG / TestApp / TestEvents.c
index b153012..a81c5b8 100644 (file)
@@ -31,7 +31,7 @@
 /** \file\r
  *\r
  *  This file contains dummy handlers for all the possible USB events passed to the\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
+ *  application by the library (see library 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
  *  Each event is caught and printed to the USART so that they may be monitored.\r
  */\r
@@ -50,100 +50,36 @@ static void Abort_Program(void)
 \r
        LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED3);\r
 \r
 \r
        LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED3);\r
 \r
-       puts_P(PSTR(ESC_INVERSE_ON "\r\n**PROGRAM ABORT**"));\r
+       puts_P(PSTR(ESC_FG_RED ESC_INVERSE_ON "\r\n**PROGRAM ABORT**" ESC_FG_WHITE));\r
        for (;;);\r
 }\r
 \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 for the USB_UIDChange event. When fired, the event is logged to the USART. */\r
-EVENT_HANDLER(USB_UIDChange)\r
+void EVENT_USB_UIDChange(void)\r
 {\r
        char* ModeStrPtr;\r
 \r
 {\r
        char* ModeStrPtr;\r
 \r
-       puts_P(PSTR(EVENT_PREFIX "UID Change\r\n"));\r
+       puts_P(PSTR(ESC_FG_RED EVENT_PREFIX "UID Change\r\n"));\r
 \r
        if (USB_CurrentMode == USB_MODE_DEVICE)\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
          ModeStrPtr = PSTR("DEVICE");\r
+       else if (USB_CurrentMode == USB_MODE_HOST)\r
+         ModeStrPtr = PSTR("HOST");\r
        else\r
          ModeStrPtr = PSTR("N/A");\r
        else\r
          ModeStrPtr = PSTR("N/A");\r
-       \r
-       LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3);\r
 \r
 \r
-       printf_P(PSTR(" -- New Mode %S\r\n"), ModeStrPtr);\r
+       printf_P(PSTR(" -- New Mode %S\r\n" ESC_FG_WHITE), ModeStrPtr);\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
- *  Event handler for the USB_PowerOnFail event. When fired, the event is logged to the USART and the program\r
+ *  Event handler for the USB_InitFailure event. When fired, the event is logged to the USART and the program\r
  *  execution aborted.\r
  */\r
  *  execution aborted.\r
  */\r
-EVENT_HANDLER(USB_InitFailure)\r
+void EVENT_USB_InitFailure(const uint8_t ErrorCode)\r
 {\r
        char* ModeStrPtr;\r
        \r
 {\r
        char* ModeStrPtr;\r
        \r
-       puts_P(PSTR(EVENT_PREFIX ESC_BG_RED "Power On Fail\r\n"));\r
+       puts_P(PSTR(ESC_FG_RED EVENT_PREFIX "Power On Fail\r\n"));\r
 \r
        if (USB_CurrentMode == USB_MODE_DEVICE)\r
          ModeStrPtr = PSTR("DEVICE");\r
 \r
        if (USB_CurrentMode == USB_MODE_DEVICE)\r
          ModeStrPtr = PSTR("DEVICE");\r
@@ -152,76 +88,94 @@ EVENT_HANDLER(USB_InitFailure)
        else\r
          ModeStrPtr = PSTR("N/A");\r
        \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
+       printf_P(PSTR(" -- Mode %S\r\n"\r
+                     " -- Error Code %d\r\n" ESC_FG_WHITE), ModeStrPtr, ErrorCode);\r
 \r
        Abort_Program();\r
 }\r
 \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
+/** Event handler for the USB_Device_Connect event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Device_Connect(void)\r
 {\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
+       puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX "USB Connect\r\n" ESC_FG_WHITE));\r
+}\r
 \r
 \r
-       Abort_Program();\r
+/** Event handler for the USB_Device_Disconnect event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Device_Disconnect(void)\r
+{\r
+       puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX "USB Disconnect\r\n" ESC_FG_WHITE));\r
 }\r
 \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
+/** Event handler for the USB_Device_Suspend event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Device_Suspend(void)\r
 {\r
 {\r
-       puts_P(PSTR(ESC_BG_RED "Dev Enum Error\r\n"));\r
-       printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode);\r
+       puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "USB Sleep\r\n" ESC_FG_WHITE));\r
 }\r
 \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
+/** Event handler for the USB_Device_WakeUp event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Device_WakeUp(void)\r
 {\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
+       puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "USB Wakeup\r\n" ESC_FG_WHITE));\r
+}\r
 \r
 \r
-       Abort_Program();\r
+/** Event handler for the USB_Device_Reset event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Device_Reset(void)\r
+{\r
+       puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "USB Reset\r\n" ESC_FG_WHITE));\r
+}\r
+\r
+/** Event handler for the USB_Device_UnhandledControlRequest event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Device_UnhandledControlRequest(void)\r
+{\r
+       printf_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "Ctrl Request\r\n"\r
+                                                " -- Req Data %d\r\n"\r
+                                                " -- Req Type %d\r\n"\r
+                                                " -- Req Length %d\r\n" ESC_FG_WHITE), USB_ControlRequest.bRequest,\r
+                                                                                       USB_ControlRequest.bmRequestType,\r
+                                                                                       USB_ControlRequest.wLength);\r
 }\r
 \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
+/** Event handler for the USB_Device_ConfigurationChanged event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Device_ConfigurationChanged(void)\r
 {\r
 {\r
-       puts_P(PSTR(EVENT_PREFIX "Ctrl Request\r\n"));\r
-       printf_P(PSTR(" -- Req Data %d\r\n"), USB_ControlRequest.bRequest);\r
-       printf_P(PSTR(" -- Req Type %d\r\n"), USB_ControlRequest.bmRequestType);\r
-       printf_P(PSTR(" -- Req Length %d\r\n"), USB_ControlRequest.wLength);\r
+       puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "Configuration Number Changed\r\n" ESC_FG_WHITE));\r
 }\r
 \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
+ *  Event handler for the USB_Host_HostError event. When fired, the event is logged to the USART and the program\r
+ *  execution aborted.\r
+ */\r
+void EVENT_USB_Host_HostError(const uint8_t ErrorCode)\r
 {\r
 {\r
-       puts_P(PSTR(EVENT_PREFIX "Configuration Number Changed\r\n"));\r
+       printf_P(PSTR(ESC_FG_RED EVENT_PREFIX "Host Mode Error\r\n"\r
+                                             " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode);\r
 \r
 \r
-       LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED4);\r
+       Abort_Program();\r
 }\r
 \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
+/** Event handler for the USB_Host_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode)\r
 {\r
 {\r
-       puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN "Device +\r\n"));\r
+       printf_P(PSTR(ESC_FG_RED EVENT_PREFIX "Dev Enum Error\r\n"\r
+                                             " -- Error Code %d\r\n"\r
+                                             " -- Sub Error Code %d\r\n"\r
+                                             " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState);\r
+}\r
 \r
 \r
-       Scheduler_SetTaskMode(USB_USBTask, TASK_RUN);\r
+/** Event handler for the USB_Host_DeviceEnumerationComplete event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Host_DeviceEnumerationComplete(void)\r
+{\r
+       puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "Device Enumeration Complete\r\n" ESC_FG_WHITE));\r
 }\r
 \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
+/** Event handler for the USB_Host_DeviceAttached event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Host_DeviceAttached(void)\r
 {\r
 {\r
-       puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW "Device -\r\n"));\r
+       puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX "Device Attached\r\n" ESC_FG_WHITE));\r
 }\r
 \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
+/** Event handler for the USB_Host_DeviceUnattached event. When fired, the event is logged to the USART. */\r
+void EVENT_USB_Host_DeviceUnattached(void)\r
 {\r
 {\r
-       puts_P(PSTR(EVENT_PREFIX "Device Enumeration Complete\r\n"));\r
+       puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX "Device Unattached\r\n" ESC_FG_WHITE));\r
 }\r
 }\r