2 * @brief USB ROM based HID Class driver functions
\r
5 * Copyright(C) NXP Semiconductors, 2012
\r
6 * All rights reserved.
\r
9 * Software that is described herein is for illustrative purposes only
\r
10 * which provides customers with programming information regarding the
\r
11 * LPC products. This software is supplied "AS IS" without any warranties of
\r
12 * any kind, and NXP Semiconductors and its licensor disclaim any and
\r
13 * all warranties, express or implied, including all implied warranties of
\r
14 * merchantability, fitness for a particular purpose and non-infringement of
\r
15 * intellectual property rights. NXP Semiconductors assumes no responsibility
\r
16 * or liability for the use of the software, conveys no license or rights under any
\r
17 * patent, copyright, mask work right, or any other intellectual property rights in
\r
18 * or to any products. NXP Semiconductors reserves the right to make changes
\r
19 * in the software without notification. NXP Semiconductors also makes no
\r
20 * representation or warranty that such application will be suitable for the
\r
21 * specified use without further testing or modification.
\r
24 * Permission to use, copy, modify, and distribute this software and its
\r
25 * documentation is hereby granted, under NXP Semiconductors' and its
\r
26 * licensor's relevant copyrights in the software, without fee, provided that it
\r
27 * is used in conjunction with NXP Semiconductors microcontrollers. This
\r
28 * copyright, permission, and disclaimer notice must appear in all copies of
\r
32 #define __INCLUDE_FROM_USB_DRIVER
\r
33 #include "../../USBMode.h"
\r
35 #if defined(USB_CAN_BE_DEVICE)
\r
36 #include "../../Device.h"
\r
37 #include "../../Endpoint.h"
\r
39 #if defined(USB_DEVICE_ROM_DRIVER)
\r
41 /* FIXME Abstract & make this size configurable */
\r
42 //#define ROMDRIVER_HID_MEM_SIZE 0x800
\r
43 //uint8_t usb_RomDriver_HID_buffer[ROMDRIVER_HID_MEM_SIZE] ATTR_ALIGNED(4) __BSS(USBRAM_SECTION);
\r
44 uint8_t *reportinbuffer;
\r
45 uint32_t reportinsize;
\r
47 ErrorCode_t GetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* plength);
\r
48 ErrorCode_t GetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* plength)
\r
50 uint8_t report[reportinsize];
\r
52 if(reportinbuffer == NULL)
\r
54 memset(report, 0,reportinsize);
\r
55 /* ReportID = SetupPacket.wValue.WB.L; */
\r
56 switch (pSetup->wValue.WB.H) {
\r
57 case HID_REPORT_INPUT:
\r
58 if(CALLBACK_UsbdHid_IsReportChanged())
\r
60 *pBuffer = reportinbuffer;
\r
61 CALLBACK_UsbdHid_SetReportChange(false);
\r
67 *plength = (uint16_t)reportinsize;
\r
69 case HID_REPORT_OUTPUT:
\r
70 return (ERR_USBD_STALL); /* Not Supported */
\r
71 case HID_REPORT_FEATURE:
\r
72 return (ERR_USBD_STALL); /* Not Supported */
\r
76 ErrorCode_t SetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length);
\r
77 ErrorCode_t SetReport( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length)
\r
79 /* we will reuse standard EP0Buf */
\r
82 /* ReportID = SetupPacket.wValue.WB.L; */
\r
83 switch (pSetup->wValue.WB.H) {
\r
84 case HID_REPORT_INPUT:
\r
85 return (ERR_USBD_STALL); /* Not Supported */
\r
86 case HID_REPORT_OUTPUT:
\r
87 CALLBACK_UsbdHid_SetReport(pBuffer,(uint32_t)length);
\r
89 case HID_REPORT_FEATURE:
\r
90 return (ERR_USBD_STALL); /* Not Supported */
\r
94 ErrorCode_t EpInHdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event);
\r
95 ErrorCode_t EpInHdlr (USBD_HANDLE_T hUsb, void* data, uint32_t event)
\r
97 USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*)data;
\r
98 uint8_t report[reportinsize];
\r
100 if(reportinbuffer == NULL)
\r
102 memset(report, 0,reportinsize);
\r
105 if(CALLBACK_UsbdHid_IsReportChanged())
\r
107 USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, reportinbuffer, reportinsize);
\r
108 CALLBACK_UsbdHid_SetReportChange(false);
\r
112 USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, reportinbuffer, reportinsize);
\r
118 void UsbdHid_Init(void)
\r
120 USBD_HID_INIT_PARAM_T hid_param;
\r
121 USB_HID_REPORT_T reports_data;
\r
123 memset((void*)&hid_param, 0, sizeof(USBD_HID_INIT_PARAM_T));
\r
124 /* Init reports_data */
\r
125 reports_data.len = (uint16_t)CALLBACK_UsbdHid_Register_ReportDescriptor(&reports_data.desc);
\r
126 reports_data.idle_time = 0;
\r
127 /* Init reports buffer */
\r
128 reportinsize = CALLBACK_UsbdHid_Register_ReportInBuffer(&reportinbuffer);
\r
131 hid_param.mem_base = (uint32_t)usb_RomDriver_HID_buffer;
\r
132 hid_param.mem_size = (uint32_t)ROMDRIVER_HID_MEM_SIZE;
\r
133 hid_param.max_reports = 1; //TODO let user configures this number
\r
134 hid_param.intf_desc = (uint8_t*)CALLBACK_UsbdHid_Register_InterfaceDescriptor();
\r
135 hid_param.report_data = &reports_data;
\r
136 /* user defined functions */
\r
137 hid_param.HID_GetReport = GetReport;
\r
138 hid_param.HID_SetReport = SetReport;
\r
139 hid_param.HID_EpIn_Hdlr = EpInHdlr;
\r
141 USBD_API->hid->init(UsbHandle, &hid_param);
\r
144 #endif /* USB_DEVICE_ROM_DRIVER */
\r
146 #endif /* USB_CAN_BE_DEVICE */
\r