]> git.sur5r.net Git - freertos/blob
5c95f4f6c3eca3a0f33f45f928a88bb412f91185
[freertos] /
1 /*\r
2  * @brief USB ROM based HID Class driver functions\r
3  *\r
4  * @note\r
5  * Copyright(C) NXP Semiconductors, 2012\r
6   * All rights reserved.\r
7  *\r
8  * @par\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
22  *\r
23  * @par\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
29  * this code.\r
30  */\r
31 \r
32 #define  __INCLUDE_FROM_USB_DRIVER\r
33 #include "../../USBMode.h"\r
34 \r
35 #if defined(USB_CAN_BE_DEVICE)\r
36 #include "../../Device.h"\r
37 #include "../../Endpoint.h"\r
38 \r
39 #if defined(USB_DEVICE_ROM_DRIVER)\r
40 \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
46 \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
49 {\r
50         uint8_t report[reportinsize];\r
51 \r
52         if(reportinbuffer == NULL)\r
53                 return (LPC_OK);\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
59                 {\r
60                         *pBuffer = reportinbuffer;\r
61                         CALLBACK_UsbdHid_SetReportChange(false);\r
62                 }\r
63                 else\r
64                 {\r
65                         *pBuffer = report;\r
66                 }\r
67                 *plength = (uint16_t)reportinsize;\r
68           break;\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
73         }\r
74         return (LPC_OK);\r
75 }\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
78 {\r
79   /* we will reuse standard EP0Buf */\r
80   if (length == 0)\r
81     return LPC_OK;\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
88       break;\r
89     case HID_REPORT_FEATURE:\r
90       return (ERR_USBD_STALL);          /* Not Supported */\r
91   }\r
92   return (LPC_OK);\r
93 }\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
96 {\r
97         USB_HID_CTRL_T* pHidCtrl = (USB_HID_CTRL_T*)data;\r
98         uint8_t report[reportinsize];\r
99 \r
100         if(reportinbuffer == NULL)\r
101                 return (LPC_OK);\r
102         memset(report, 0,reportinsize);\r
103         switch (event) {\r
104         case USB_EVT_IN:\r
105                 if(CALLBACK_UsbdHid_IsReportChanged())\r
106                 {\r
107                         USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, reportinbuffer, reportinsize);\r
108                         CALLBACK_UsbdHid_SetReportChange(false);\r
109                 }\r
110                 else\r
111                 {\r
112                         USBD_API->hw->WriteEP(hUsb, pHidCtrl->epin_adr, reportinbuffer, reportinsize);\r
113                 }\r
114                 break;\r
115         }\r
116         return LPC_OK;\r
117 }\r
118 void UsbdHid_Init(void)\r
119 {\r
120           USBD_HID_INIT_PARAM_T hid_param;\r
121           USB_HID_REPORT_T reports_data;\r
122 \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
129 \r
130           /* HID paramas */\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
140 \r
141           USBD_API->hid->init(UsbHandle, &hid_param);\r
142 }\r
143 \r
144 #endif /* USB_DEVICE_ROM_DRIVER */\r
145 \r
146 #endif /* USB_CAN_BE_DEVICE */\r