3      Copyright (C) Dean Camera, 2014. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2014  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, distribute, and sell this 
  13   software and its documentation for any purpose is hereby granted 
  14   without fee, provided that the above copyright notice appear in 
  15   all copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting 
  17   documentation, and that the name of the author not be used in 
  18   advertising or publicity pertaining to distribution of the 
  19   software without specific, written prior permission. 
  21   The author disclaims all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  31 #include "HIDReport.h" 
  33 /** Size in bytes of the attached device's HID report descriptor */ 
  34 uint16_t         HIDReportSize
; 
  36 /** Processed HID report descriptor items structure, containing information on each HID report element */ 
  37 HID_ReportInfo_t HIDReportInfo
; 
  40 /** Function to read in the HID report descriptor from the attached device, and process it into easy-to-read 
  41  *  structures via the HID parser routines in the LUFA library. 
  43  *  \return A value from the \ref KeyboardHostWithParser_GetHIDReportDataCodes_t enum 
  45 uint8_t GetHIDReportData(void) 
  47         /* Create a buffer big enough to hold the entire returned HID report */ 
  48         uint8_t HIDReportData
[HIDReportSize
]; 
  50         USB_ControlRequest 
= (USB_Request_Header_t
) 
  52                         .bmRequestType 
= (REQDIR_DEVICETOHOST 
| REQTYPE_STANDARD 
| REQREC_INTERFACE
), 
  53                         .bRequest      
= REQ_GetDescriptor
, 
  54                         .wValue        
= (HID_DTYPE_Report 
<< 8), 
  56                         .wLength       
= HIDReportSize
, 
  59         /* Select the control pipe for the request transfer */ 
  60         Pipe_SelectPipe(PIPE_CONTROLPIPE
); 
  62         /* Send control request to retrieve the HID report from the attached device */ 
  63         if (USB_Host_SendControlRequest(HIDReportData
) != HOST_SENDCONTROL_Successful
) 
  64           return ParseControlError
; 
  66         /* Send the HID report to the parser for processing */ 
  67         if (USB_ProcessHIDReport(HIDReportData
, HIDReportSize
, &HIDReportInfo
) != HID_PARSE_Successful
) 
  70         return ParseSuccessful
; 
  73 /** Callback for the HID Report Parser. This function is called each time the HID report parser is about to store 
  74  *  an IN, OUT or FEATURE item into the HIDReportInfo structure. To save on RAM, we are able to filter out items 
  75  *  we aren't interested in (preventing us from being able to extract them later on, but saving on the RAM they would 
  78  *  \param[in] CurrentItem  Pointer to the item the HID report parser is currently working with 
  80  *  \return Boolean \c true if the item should be stored into the HID report structure, \c false if it should be discarded 
  82 bool CALLBACK_HIDParser_FilterHIDReportItem(HID_ReportItem_t
* const CurrentItem
) 
  84         /* Check the attributes of the current item - see if we are interested in it or not; 
  85          * only store KEYBOARD usage page items into the Processed HID Report structure to 
  86          * save RAM and ignore the rest 
  88         return (CurrentItem
->Attributes
.Usage
.Page 
== USAGE_PAGE_KEYBOARD
);