X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/253deb996f321c59c102a64e17f95d0b5b0a0e6d..09bedd6555a72c70f6d6bfb965225d44dec171cd:/Demos/OTG/TestApp/TestEvents.c diff --git a/Demos/OTG/TestApp/TestEvents.c b/Demos/OTG/TestApp/TestEvents.c index 884e5b680..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. */ -EVENT_HANDLER(USB_VBUSChange) -{ - 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. */ -EVENT_HANDLER(USB_VBUSConnect) -{ - puts_P(PSTR(EVENT_PREFIX "VBUS +\r\n")); -} - -/** Event handler for the USB_VBUSDisconnect event. When fired, the event is logged to the USART. */ -EVENT_HANDLER(USB_VBUSDisconnect) -{ - 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. - */ -EVENT_HANDLER(USB_Connect) -{ - 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. - */ -EVENT_HANDLER(USB_Disconnect) -{ - 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. */ -EVENT_HANDLER(USB_Suspend) -{ - 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. */ -EVENT_HANDLER(USB_WakeUp) -{ - 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. */ -EVENT_HANDLER(USB_Reset) -{ - 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. */ -EVENT_HANDLER(USB_UIDChange) +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. */ -EVENT_HANDLER(USB_InitFailure) +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,76 +88,94 @@ EVENT_HANDLER(USB_InitFailure) 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. - */ -EVENT_HANDLER(USB_HostError) +/** 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_DeviceEnumerationFailed event. When fired, the event is logged to the USART. */ -EVENT_HANDLER(USB_DeviceEnumerationFailed) +/** 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_BG_RED "Dev Enum Error\r\n")); - printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode); + puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "USB Sleep\r\n" ESC_FG_WHITE)); } -/** - * Event handler for the USB_DeviceError event. When fired, the event is logged to the USART and the program - * execution aborted. - */ -EVENT_HANDLER(USB_DeviceError) +/** 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(EVENT_PREFIX ESC_BG_RED "Device Mode Error\r\n")); - printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode); + puts_P(PSTR(ESC_FG_YELLOW EVENT_PREFIX "USB Wakeup\r\n" ESC_FG_WHITE)); +} - Abort_Program(); +/** 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_Device_UnhandledControlRequest event. When fired, the event is logged to the USART. */ +void EVENT_USB_Device_UnhandledControlRequest(void) +{ + 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. */ -EVENT_HANDLER(USB_UnhandledControlPacket) +/** 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. */ -EVENT_HANDLER(USB_ConfigurationChanged) +/** + * 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. */ -EVENT_HANDLER(USB_DeviceAttached) +/** 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. */ -EVENT_HANDLER(USB_DeviceUnattached) +/** 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. */ -EVENT_HANDLER(USB_DeviceEnumerationComplete) +/** 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)); }