X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/6a5a37d7d141f109dc02d0bb6d8f4757b533408d..710d48a48aa3ab5f1c446c9ec04854aceb0820b6:/Demos/Host/GenericHIDHost/GenericHIDHost.c diff --git a/Demos/Host/GenericHIDHost/GenericHIDHost.c b/Demos/Host/GenericHIDHost/GenericHIDHost.c index 4d2fefb38..b047841f6 100644 --- a/Demos/Host/GenericHIDHost/GenericHIDHost.c +++ b/Demos/Host/GenericHIDHost/GenericHIDHost.c @@ -36,12 +36,6 @@ #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 { @@ -185,30 +179,34 @@ 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 */ @@ -219,9 +217,11 @@ void ReadNextReport(void) /** Writes a report to the attached device. * * \param ReportOUTData Buffer containing the report to send to the device + * \param ReportIndex Index of the report in the device (zero if the device does not use multiple reports) + * \param ReportType Type of report to send, either HID_REPORTTYPE_OUTPUT or HID_REPORTTYPE_FEATURE * \param ReportLength Length of the report to send */ -void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength) +void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t ReportType, uint16_t ReportLength) { /* Select and unfreeze HID data OUT pipe */ Pipe_SelectPipe(HID_DATA_OUT_PIPE); @@ -233,19 +233,23 @@ void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength) 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(); return; } + + /* If the report index is used, send it before the report data */ + if (ReportIndex) + Pipe_Write_Byte(ReportIndex); - /* Read in HID report data */ + /* Write out HID report data */ 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(); @@ -257,7 +261,7 @@ void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength) { bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE), bRequest: REQ_SetReport, - wValue: 0, + wValue: ((ReportType << 8) | ReportIndex), wIndex: 0, wLength: ReportLength, };