X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/8f6b4ddf764c3a54e42d00a7502c82c5c3e71b1c..6a7c298c0f7119e44e18de15d714cd8b938e3bef:/Demos/Host/KeyboardHost/KeyboardHost.c?ds=inline diff --git a/Demos/Host/KeyboardHost/KeyboardHost.c b/Demos/Host/KeyboardHost/KeyboardHost.c index 35055ca79..2b9bb2b0b 100644 --- a/Demos/Host/KeyboardHost/KeyboardHost.c +++ b/Demos/Host/KeyboardHost/KeyboardHost.c @@ -39,8 +39,8 @@ /* Scheduler Task List */ TASK_LIST { - { Task: USB_USBTask , TaskStatus: TASK_STOP }, - { Task: USB_Keyboard_Host , TaskStatus: TASK_STOP }, + { .Task = USB_USBTask , .TaskStatus = TASK_STOP }, + { .Task = USB_Keyboard_Host , .TaskStatus = TASK_STOP }, }; @@ -80,7 +80,7 @@ int main(void) /** Event handler for the USB_DeviceAttached event. This indicates that a device has been attached to the host, and * starts the library USB task to begin the enumeration and USB management process. */ -EVENT_HANDLER(USB_DeviceAttached) +void EVENT_USB_DeviceAttached(void) { puts_P(PSTR("Device Attached.\r\n")); UpdateStatus(Status_USBEnumerating); @@ -92,7 +92,7 @@ EVENT_HANDLER(USB_DeviceAttached) /** Event handler for the USB_DeviceUnattached event. This indicates that a device has been removed from the host, and * stops the library USB task management process. */ -EVENT_HANDLER(USB_DeviceUnattached) +void EVENT_USB_DeviceUnattached(void) { /* Stop Keyboard and USB management task */ Scheduler_SetTaskMode(USB_USBTask, TASK_STOP); @@ -105,7 +105,7 @@ EVENT_HANDLER(USB_DeviceUnattached) /** Event handler for the USB_DeviceEnumerationComplete event. This indicates that a device has been successfully * enumerated by the host and is now ready to be used by the application. */ -EVENT_HANDLER(USB_DeviceEnumerationComplete) +void EVENT_USB_DeviceEnumerationComplete(void) { /* Start Keyboard Host task */ Scheduler_SetTaskMode(USB_Keyboard_Host, TASK_RUN); @@ -115,7 +115,7 @@ EVENT_HANDLER(USB_DeviceEnumerationComplete) } /** Event handler for the USB_HostError event. This indicates that a hardware error occurred while in host mode. */ -EVENT_HANDLER(USB_HostError) +void EVENT_USB_HostError(const uint8_t ErrorCode) { USB_ShutDown(); @@ -129,7 +129,7 @@ EVENT_HANDLER(USB_HostError) /** Event handler for the USB_DeviceEnumerationFailed event. This indicates that a problem occurred while * enumerating an attached USB device. */ -EVENT_HANDLER(USB_DeviceEnumerationFailed) +void EVENT_USB_DeviceEnumerationFailed(const uint8_t ErrorCode, const uint8_t SubErrorCode) { puts_P(PSTR(ESC_BG_RED "Dev Enum Error\r\n")); printf_P(PSTR(" -- Error Code %d\r\n"), ErrorCode); @@ -180,18 +180,14 @@ void ReadNextReport(void) /* Select keyboard data pipe */ Pipe_SelectPipe(KEYBOARD_DATAPIPE); - #if !defined(INTERRUPT_DATA_PIPE) /* Unfreeze keyboard data pipe */ Pipe_Unfreeze(); - #endif /* Check to see if a packet has been received */ if (!(Pipe_IsINReceived())) { - #if !defined(INTERRUPT_DATA_PIPE) /* Refreeze HID data IN pipe */ Pipe_Freeze(); - #endif return; } @@ -231,15 +227,12 @@ void ReadNextReport(void) putchar(PressedKey); } } - - + /* Clear the IN endpoint, ready for next data packet */ Pipe_ClearIN(); - #if !defined(INTERRUPT_DATA_PIPE) /* Refreeze keyboard data pipe */ Pipe_Freeze(); - #endif } /** Task to set the configuration of the attached device after it has been enumerated, and to read and process @@ -253,13 +246,13 @@ TASK(USB_Keyboard_Host) { case HOST_STATE_Addressed: /* Standard request to set the device configuration to configuration 1 */ - USB_HostRequest = (USB_Host_Request_Header_t) + USB_ControlRequest = (USB_Request_Header_t) { - bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE), - bRequest: REQ_SetConfiguration, - wValue: 1, - wIndex: 0, - wLength: 0, + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE), + .bRequest = REQ_SetConfiguration, + .wValue = 1, + .wIndex = 0, + .wLength = 0, }; /* Select the control pipe for the request transfer */ @@ -303,13 +296,13 @@ TASK(USB_Keyboard_Host) } /* HID class request to set the keyboard protocol to the Boot Protocol */ - USB_HostRequest = (USB_Host_Request_Header_t) + USB_ControlRequest = (USB_Request_Header_t) { - bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - bRequest: REQ_SetProtocol, - wValue: 0, - wIndex: 0, - wLength: 0, + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), + .bRequest = REQ_SetProtocol, + .wValue = 0, + .wIndex = 0, + .wLength = 0, }; /* Select the control pipe for the request transfer */ @@ -329,53 +322,14 @@ TASK(USB_Keyboard_Host) break; } - #if defined(INTERRUPT_DATA_PIPE) - /* Select and unfreeze keyboard data pipe */ - Pipe_SelectPipe(KEYBOARD_DATAPIPE); - Pipe_Unfreeze(); - #endif - puts_P(PSTR("Keyboard Enumerated.\r\n")); USB_HostState = HOST_STATE_Ready; break; - #if !defined(INTERRUPT_DATA_PIPE) case HOST_STATE_Ready: /* If a report has been received, read and process it */ ReadNextReport(); break; - #endif } } - -#if defined(INTERRUPT_DATA_PIPE) -/** Interrupt handler for the Endpoint/Pipe interrupt vector. This interrupt fires each time an enabled - * pipe interrupt occurs on a pipe which has had that interrupt enabled. - */ -ISR(ENDPOINT_PIPE_vect, ISR_BLOCK) -{ - /* Save previously selected pipe before selecting a new pipe */ - uint8_t PrevSelectedPipe = Pipe_GetCurrentPipe(); - - /* Check to see if the keyboard data pipe has caused the interrupt */ - if (Pipe_HasPipeInterrupted(KEYBOARD_DATAPIPE)) - { - /* Clear the pipe interrupt, and select the keyboard pipe */ - Pipe_ClearPipeInterrupt(KEYBOARD_DATAPIPE); - Pipe_SelectPipe(KEYBOARD_DATAPIPE); - - /* Check to see if the pipe IN interrupt has fired */ - if (USB_INT_HasOccurred(PIPE_INT_IN) && USB_INT_IsEnabled(PIPE_INT_IN)) - { - /* Clear interrupt flag */ - USB_INT_Clear(PIPE_INT_IN); - - /* Read and process the next report from the device */ - ReadNextReport(); - } - - /* Restore previously selected pipe */ - Pipe_SelectPipe(PrevSelectedPipe); -} -#endif