X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/ef06bfd1c0ef5272c32808e23d0fd60d2d1bca9c..eeba38e343a299e12964aec15fd43108d3dc9130:/Demos/Host/GenericHIDHost/GenericHIDHost.c?ds=sidebyside diff --git a/Demos/Host/GenericHIDHost/GenericHIDHost.c b/Demos/Host/GenericHIDHost/GenericHIDHost.c index 716f1c333..580612c97 100644 --- a/Demos/Host/GenericHIDHost/GenericHIDHost.c +++ b/Demos/Host/GenericHIDHost/GenericHIDHost.c @@ -36,17 +36,11 @@ #include "GenericHIDHost.h" -/* Project Tags, for reading out using the ButtLoad project */ -BUTTLOADTAG(ProjName, "LUFA GenHid Host App"); -BUTTLOADTAG(BuildTime, __TIME__); -BUTTLOADTAG(BuildDate, __DATE__); -BUTTLOADTAG(LUFAVersion, "LUFA V" LUFA_VERSION_STRING); - /* Scheduler Task List */ TASK_LIST { - { Task: USB_USBTask , TaskStatus: TASK_STOP }, - { Task: USB_HID_Host , TaskStatus: TASK_STOP }, + { .Task = USB_USBTask , .TaskStatus = TASK_STOP }, + { .Task = USB_HID_Host , .TaskStatus = TASK_STOP }, }; @@ -185,35 +179,35 @@ void ReadNextReport(void) Pipe_SelectPipe(HID_DATA_IN_PIPE); Pipe_Unfreeze(); - /* Ensure pipe contains data and is ready to be read before continuing */ - if (!(Pipe_ReadWriteAllowed())) + /* 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; } - uint8_t ReportINData[Pipe_BytesInPipe()]; + /* Ensure pipe contains data before trying to read from it */ + if (Pipe_IsReadWriteAllowed()) + { + uint8_t ReportINData[Pipe_BytesInPipe()]; - /* Read in HID report data */ - Pipe_Read_Stream_LE(&ReportINData, sizeof(ReportINData)); + /* Read in HID report data */ + Pipe_Read_Stream_LE(&ReportINData, sizeof(ReportINData)); + + /* Print report data through the serial port */ + for (uint16_t CurrByte = 0; CurrByte < sizeof(ReportINData); CurrByte++) + printf_P(PSTR("0x%02X "), ReportINData[CurrByte]); + + puts_P(PSTR("\r\n")); + } /* Clear the IN endpoint, ready for next data packet */ - Pipe_ClearCurrentBank(); - - /* Print report data through the serial port */ - for (uint16_t CurrByte = 0; CurrByte < sizeof(ReportINData); CurrByte++) - printf_P(PSTR("0x%02X "), ReportINData[CurrByte]); - - puts_P(PSTR("\r\n")); + Pipe_ClearIN(); - #if !defined(INTERRUPT_DATA_PIPE) /* Refreeze HID data IN pipe */ Pipe_Freeze(); - #endif } /** Writes a report to the attached device. @@ -235,7 +229,7 @@ void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t Report Pipe_Unfreeze(); /* Ensure pipe is ready to be written to before continuing */ - if (!(Pipe_ReadWriteAllowed())) + if (!(Pipe_IsOUTReady())) { /* Refreeze the data OUT pipe */ Pipe_Freeze(); @@ -251,7 +245,7 @@ void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t Report Pipe_Write_Stream_LE(ReportOUTData, ReportLength); /* Clear the OUT endpoint, send last data packet */ - Pipe_ClearCurrentBank(); + Pipe_ClearOUT(); /* Refreeze the data OUT pipe */ Pipe_Freeze(); @@ -259,13 +253,13 @@ void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t Report else { /* Class specific request to send a HID report to the device */ - USB_HostRequest = (USB_Host_Request_Header_t) + USB_ControlRequest = (USB_Request_Header_t) { - bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), - bRequest: REQ_SetReport, - wValue: ((ReportType << 8) | ReportIndex), - wIndex: 0, - wLength: ReportLength, + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), + .bRequest = REQ_SetReport, + .wValue = ((ReportType << 8) | ReportIndex), + .wIndex = 0, + .wLength = ReportLength, }; /* Select the control pipe for the request transfer */ @@ -288,13 +282,13 @@ TASK(USB_HID_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 */ @@ -337,53 +331,13 @@ TASK(USB_HID_Host) break; } - #if defined(INTERRUPT_DATA_PIPE) - /* Select and unfreeze HID data IN pipe */ - Pipe_SelectPipe(HID_DATA_IN_PIPE); - Pipe_Unfreeze(); - #endif - puts_P(PSTR("HID Device Enumerated.\r\n")); USB_HostState = HOST_STATE_Ready; break; - #if !defined(INTERRUPT_DATA_PIPE) case HOST_STATE_Ready: 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 HID data IN pipe has caused the interrupt */ - if (Pipe_HasPipeInterrupted(HID_DATA_IN_PIPE)) - { - /* Clear the pipe interrupt, and select the data IN pipe */ - Pipe_ClearPipeInterrupt(HID_DATA_IN_PIPE); - Pipe_SelectPipe(HID_DATA_IN_PIPE); - - /* 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