X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/d0806c817cbf0c1b5c5362d1577eac6075c94dfc..09bedd6555a72c70f6d6bfb965225d44dec171cd:/Demos/OTG/TestApp/TestEvents.c diff --git a/Demos/OTG/TestApp/TestEvents.c b/Demos/OTG/TestApp/TestEvents.c index b2f174015..a81c5b8af 100644 --- a/Demos/OTG/TestApp/TestEvents.c +++ b/Demos/OTG/TestApp/TestEvents.c @@ -31,7 +31,7 @@ /** \file * * This file contains dummy handlers for all the possible USB events passed to the - * application by the library (see \ref Group_Events documentation for more details on USB events). + * application by the library (see library documentation for more details on USB events). * * Each event is caught and printed to the USART so that they may be monitored. */ @@ -50,100 +50,36 @@ static void Abort_Program(void) LEDs_SetAllLEDs(LEDS_LED1 | LEDS_LED3); - puts_P(PSTR(ESC_INVERSE_ON "\r\n**PROGRAM ABORT**")); + puts_P(PSTR(ESC_FG_RED ESC_INVERSE_ON "\r\n**PROGRAM ABORT**" ESC_FG_WHITE)); for (;;); } -/** Event handler for the USB_VBUSChange event. When fired, the event is logged to the USART. */ -void EVENT_USB_VBUSChange(void) -{ - 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. */ -void EVENT_USB_VBUSConnect(void) -{ - puts_P(PSTR(EVENT_PREFIX "VBUS +\r\n")); -} - -/** Event handler for the USB_VBUSDisconnect event. When fired, the event is logged to the USART. */ -void EVENT_USB_VBUSDisconnect(void) -{ - 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. - */ -void EVENT_USB_Connect(void) -{ - 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. - */ -void EVENT_USB_Disconnect(void) -{ - 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. */ -void EVENT_USB_Suspend(void) -{ - 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. */ -void EVENT_USB_WakeUp(void) -{ - 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. */ -void EVENT_USB_Reset(void) -{ - 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. */ void EVENT_USB_UIDChange(void) { char* ModeStrPtr; - puts_P(PSTR(EVENT_PREFIX "UID Change\r\n")); + puts_P(PSTR(ESC_FG_RED 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 if (USB_CurrentMode == USB_MODE_HOST) + ModeStrPtr = PSTR("HOST"); else ModeStrPtr = PSTR("N/A"); - - LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED3); - printf_P(PSTR(" -- New Mode %S\r\n"), ModeStrPtr); + printf_P(PSTR(" -- New Mode %S\r\n" ESC_FG_WHITE), ModeStrPtr); } /** - * Event handler for the USB_PowerOnFail event. When fired, the event is logged to the USART and the program + * Event handler for the USB_InitFailure event. When fired, the event is logged to the USART and the program * execution aborted. */ void EVENT_USB_InitFailure(const uint8_t ErrorCode) { char* ModeStrPtr; - puts_P(PSTR(EVENT_PREFIX ESC_BG_RED "Power On Fail\r\n")); + puts_P(PSTR(ESC_FG_RED EVENT_PREFIX "Power On Fail\r\n")); if (USB_CurrentMode == USB_MODE_DEVICE) ModeStrPtr = PSTR("DEVICE"); @@ -152,66 +88,94 @@ void EVENT_USB_InitFailure(const uint8_t ErrorCode) else ModeStrPtr = PSTR("N/A"); - printf_P(PSTR(" -- Mode %S\r\n"), ModeStrPtr); - printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode); + printf_P(PSTR(" -- Mode %S\r\n" + " -- Error Code %d\r\n" ESC_FG_WHITE), ModeStrPtr, ErrorCode); Abort_Program(); } -/** - * Event handler for the USB_HostError event. When fired, the event is logged to the USART and the program - * execution aborted. - */ -void EVENT_USB_HostError(const uint8_t ErrorCode) +/** Event handler for the USB_Device_Connect event. When fired, the event is logged to the USART. */ +void EVENT_USB_Device_Connect(void) { - puts_P(PSTR(EVENT_PREFIX ESC_BG_RED "Host Mode Error\r\n")); - printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode); + puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX "USB Connect\r\n" ESC_FG_WHITE)); +} - Abort_Program(); +/** Event handler for the USB_Device_Disconnect event. When fired, the event is logged to the USART. */ +void EVENT_USB_Device_Disconnect(void) +{ + puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX "USB Disconnect\r\n" ESC_FG_WHITE)); +} + +/** Event handler for the USB_Device_Suspend event. When fired, the event is logged to the USART. */ +void EVENT_USB_Device_Suspend(void) +{ + puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "USB Sleep\r\n" ESC_FG_WHITE)); +} + +/** Event handler for the USB_Device_WakeUp event. When fired, the event is logged to the USART. */ +void EVENT_USB_Device_WakeUp(void) +{ + puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "USB Wakeup\r\n" ESC_FG_WHITE)); +} + +/** Event handler for the USB_Device_Reset event. When fired, the event is logged to the USART. */ +void EVENT_USB_Device_Reset(void) +{ + puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "USB Reset\r\n" ESC_FG_WHITE)); } -/** Event handler for the USB_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */ -void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode) +/** Event handler for the USB_Device_UnhandledControlRequest event. When fired, the event is logged to the USART. */ +void EVENT_USB_Device_UnhandledControlRequest(void) { - puts_P(PSTR(ESC_BG_RED "Dev Enum Error\r\n")); - printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode); - printf_P(PSTR(" -- Sub Error Code %d\r\n"), SubErrorCode); - printf_P(PSTR(" -- In State %d\r\n"), USB_HostState); + printf_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "Ctrl Request\r\n" + " -- Req Data %d\r\n" + " -- Req Type %d\r\n" + " -- Req Length %d\r\n" ESC_FG_WHITE), USB_ControlRequest.bRequest, + USB_ControlRequest.bmRequestType, + USB_ControlRequest.wLength); } -/** Event handler for the USB_UnhandledControlPacket event. When fired, the event is logged to the USART. */ -void EVENT_USB_UnhandledControlPacket(void) +/** Event handler for the USB_Device_ConfigurationChanged event. When fired, the event is logged to the USART. */ +void EVENT_USB_Device_ConfigurationChanged(void) { - puts_P(PSTR(EVENT_PREFIX "Ctrl Request\r\n")); - 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); + puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "Configuration Number Changed\r\n" ESC_FG_WHITE)); } -/** Event handler for the USB_ConfigurationChanged event. When fired, the event is logged to the USART. */ -void EVENT_USB_ConfigurationChanged(void) +/** + * Event handler for the USB_Host_HostError event. When fired, the event is logged to the USART and the program + * execution aborted. + */ +void EVENT_USB_Host_HostError(const uint8_t ErrorCode) { - puts_P(PSTR(EVENT_PREFIX "Configuration Number Changed\r\n")); + printf_P(PSTR(ESC_FG_RED EVENT_PREFIX "Host Mode Error\r\n" + " -- Error Code %d\r\n" ESC_FG_WHITE), ErrorCode); - LEDs_SetAllLEDs(LEDS_LED2 | LEDS_LED4); + Abort_Program(); } -/** Event handler for the USB_DeviceAttached event. When fired, the event is logged to the USART. */ -void EVENT_USB_DeviceAttached(void) +/** Event handler for the USB_Host_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */ +void EVENT_USB_Host_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode) { - puts_P(PSTR(EVENT_PREFIX ESC_BG_GREEN "Device +\r\n")); + printf_P(PSTR(ESC_FG_RED EVENT_PREFIX "Dev Enum Error\r\n" + " -- Error Code %d\r\n" + " -- Sub Error Code %d\r\n" + " -- In State %d\r\n" ESC_FG_WHITE), ErrorCode, SubErrorCode, USB_HostState); +} - Scheduler_SetTaskMode(USB_USBTask, TASK_RUN); +/** Event handler for the USB_Host_DeviceEnumerationComplete event. When fired, the event is logged to the USART. */ +void EVENT_USB_Host_DeviceEnumerationComplete(void) +{ + puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "Device Enumeration Complete\r\n" ESC_FG_WHITE)); } -/** Event handler for the USB_DeviceUnattached event. When fired, the event is logged to the USART. */ -void EVENT_USB_DeviceUnattached(void) +/** Event handler for the USB_Host_DeviceAttached event. When fired, the event is logged to the USART. */ +void EVENT_USB_Host_DeviceAttached(void) { - puts_P(PSTR(EVENT_PREFIX ESC_BG_YELLOW "Device -\r\n")); + puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX "Device Attached\r\n" ESC_FG_WHITE)); } -/** Event handler for the USB_DeviceEnumerationComplete event. When fired, the event is logged to the USART. */ -void EVENT_USB_DeviceEnumerationComplete(void) +/** Event handler for the USB_Host_DeviceUnattached event. When fired, the event is logged to the USART. */ +void EVENT_USB_Host_DeviceUnattached(void) { - puts_P(PSTR(EVENT_PREFIX "Device Enumeration Complete\r\n")); + puts_P(PSTR(ESC_FG_GREEN EVENT_PREFIX "Device Unattached\r\n" ESC_FG_WHITE)); }