LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
GenericHID.c
Go to the documentation of this file.
1 /*
2  * @brief Generic HID Device Example
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2012
6  * Copyright(C) Dean Camera, 2011, 2012
7  * All rights reserved.
8  *
9  * @par
10  * Software that is described herein is for illustrative purposes only
11  * which provides customers with programming information regarding the
12  * LPC products. This software is supplied "AS IS" without any warranties of
13  * any kind, and NXP Semiconductors and its licensor disclaim any and
14  * all warranties, express or implied, including all implied warranties of
15  * merchantability, fitness for a particular purpose and non-infringement of
16  * intellectual property rights. NXP Semiconductors assumes no responsibility
17  * or liability for the use of the software, conveys no license or rights under any
18  * patent, copyright, mask work right, or any other intellectual property rights in
19  * or to any products. NXP Semiconductors reserves the right to make changes
20  * in the software without notification. NXP Semiconductors also makes no
21  * representation or warranty that such application will be suitable for the
22  * specified use without further testing or modification.
23  *
24  * @par
25  * Permission to use, copy, modify, and distribute this software and its
26  * documentation is hereby granted, under NXP Semiconductors' and its
27  * licensor's relevant copyrights in the software, without fee, provided that it
28  * is used in conjunction with NXP Semiconductors microcontrollers. This
29  * copyright, permission, and disclaimer notice must appear in all copies of
30  * this code.
31  */
32 
33 #include "GenericHID.h"
34 
37 
43  .Config = {
44  .InterfaceNumber = 0,
45 
46  .ReportINEndpointNumber = GENERIC_IN_EPNUM,
47  .ReportINEndpointSize = GENERIC_EPSIZE,
48  .ReportINEndpointDoubleBank = false,
49 
50  .PrevReportINBuffer = PrevHIDReportBuffer,
51  .PrevReportINBufferSize = sizeof(PrevHIDReportBuffer),
52  },
53 };
54 
58 int main(void)
59 {
60  SetupHardware();
61 
62  for (;; ) {
63  #if defined(USB_DEVICE_ROM_DRIVER)
65  uint16_t reportsize;
66  uint8_t reportID = 0;
67 
68  memset(&report, 0, sizeof(USB_Descriptor_HIDReport_Datatype_t));
69  CALLBACK_HID_Device_CreateHIDReport(&Generic_HID_Interface, &reportID, HID_REPORT_ITEM_In, &report, &reportsize);
70  if (memcmp(&report, Generic_HID_Interface.Config.PrevReportINBuffer,
71  Generic_HID_Interface.Config.PrevReportINBufferSize)) {
72  memcpy(Generic_HID_Interface.Config.PrevReportINBuffer,
73  &report,
74  Generic_HID_Interface.Config.PrevReportINBufferSize);
76  }
77  #else
78  HID_Device_USBTask(&Generic_HID_Interface);
79  USB_USBTask();
80  #endif
81  }
82 }
83 
85 void SetupHardware(void)
86 {
87  Board_Init();
90  USB_Init();
91 #if defined(USB_DEVICE_ROM_DRIVER)
92  UsbdHid_Init();
93 #endif
94 }
95 
98 {}
99 
102 {}
103 
106 {
107  bool ConfigSuccess = true;
108 
109  ConfigSuccess &= HID_Device_ConfigureEndpoints(&Generic_HID_Interface);
110 
112 
113  // LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
114 }
115 
118 {
119  HID_Device_ProcessControlRequest(&Generic_HID_Interface);
120 }
121 
124 {
125  HID_Device_MillisecondElapsed(&Generic_HID_Interface);
126 }
127 
131  uint8_t *const ReportID,
132  const uint8_t ReportType,
133  void *ReportData,
134  uint16_t *const ReportSize)
135 {
136  uint8_t *Data = (uint8_t *) ReportData;
137  uint8_t JoyStatus_LCL = Joystick_GetStatus();
138  uint8_t ButtonStatus_LCL = Buttons_GetStatus();
139  uint8_t ret = 0;
140 
141  if (JoyStatus_LCL & JOY_UP) {
142  ret |= 0x01;
143  }
144  if (JoyStatus_LCL & JOY_LEFT) {
145  ret |= 0x02;
146  }
147  if (JoyStatus_LCL & JOY_RIGHT) {
148  ret |= 0x04;
149  }
150  if (JoyStatus_LCL & JOY_PRESS) {
151  ret |= 0x08;
152  }
153  if (JoyStatus_LCL & JOY_DOWN) {
154  ret |= 0x10;
155  }
156  if (ButtonStatus_LCL & BUTTONS_BUTTON1) {
157  ret |= 0x20;
158  }
159 
160  Data[0] = ret;
161 
162  *ReportSize = GENERIC_REPORT_SIZE;
163  return false;
164 }
165 
169  const uint8_t ReportID,
170  const uint8_t ReportType,
171  const void *ReportData,
172  const uint16_t ReportSize)
173 {
174  uint8_t *Data = (uint8_t *) ReportData;
175  uint8_t NewLEDMask = LEDS_NO_LEDS;
176 
177  if (Data[0] & 0x01) {
178  NewLEDMask |= LEDS_LED1;
179  }
180  if (Data[0] & 0x02) {
181  NewLEDMask |= LEDS_LED2;
182  }
183  if (Data[0] & 0x04) {
184  NewLEDMask |= LEDS_LED3;
185  }
186  if (Data[0] & 0x08) {
187  NewLEDMask |= LEDS_LED4;
188  }
189 
190 }