LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Mouse.c
Go to the documentation of this file.
1 /*
2  * @brief Make your board becomes a USB mouse
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 "Mouse.h"
34 
37 
43  .Config = {
44  .InterfaceNumber = 0,
45 
46  .ReportINEndpointNumber = MOUSE_EPNUM,
47  .ReportINEndpointSize = MOUSE_EPSIZE,
48  .ReportINEndpointDoubleBank = false,
49 
50  .PrevReportINBuffer = PrevMouseHIDReportBuffer,
51  .PrevReportINBufferSize = sizeof(PrevMouseHIDReportBuffer),
52  },
53 };
54 #if defined(USB_DEVICE_ROM_DRIVER)
55 extern void CALLBACK_UsbdHid_SetReportChange(bool newstate);
56 
57 #endif
58 
61 int main(void)
62 {
63  SetupHardware();
64 
65  for (;; ) {
66  #if defined(USB_DEVICE_ROM_DRIVER)
68  uint16_t reportsize;
69  uint8_t reportID = 0;
70 
71  memset(&report, 0, sizeof(USB_MouseReport_Data_t));
72  CALLBACK_HID_Device_CreateHIDReport(&Mouse_HID_Interface, &reportID, HID_REPORT_ITEM_In, &report, &reportsize);
73  if (memcmp(&report, Mouse_HID_Interface.Config.PrevReportINBuffer,
74  Mouse_HID_Interface.Config.PrevReportINBufferSize)) {
75  memcpy(Mouse_HID_Interface.Config.PrevReportINBuffer,
76  &report,
77  Mouse_HID_Interface.Config.PrevReportINBufferSize);
79  }
80  #else
81  HID_Device_USBTask(&Mouse_HID_Interface);
82  USB_USBTask();
83  #endif
84  }
85 }
86 
88 void SetupHardware(void)
89 {
90  Board_Init();
93  USB_Init();
94 #if defined(USB_DEVICE_ROM_DRIVER)
95  UsbdHid_Init();
96 #endif
97 }
98 
101 {}
102 
105 {}
106 
109 {
110  bool ConfigSuccess = true;
111 
112  ConfigSuccess &= HID_Device_ConfigureEndpoints(&Mouse_HID_Interface);
113 
115 }
116 
119 {
120  HID_Device_ProcessControlRequest(&Mouse_HID_Interface);
121 }
122 
125 {
126  HID_Device_MillisecondElapsed(&Mouse_HID_Interface);
127 }
128 
132  uint8_t *const ReportID,
133  const uint8_t ReportType,
134  void *ReportData,
135  uint16_t *const ReportSize)
136 {
138 
139  uint8_t JoyStatus_LCL = Joystick_GetStatus();
140  uint8_t ButtonStatus_LCL = Buttons_GetStatus();
141 
142  if (JoyStatus_LCL & JOY_UP) {
143  MouseReport->Y = -1;
144  }
145  else if (JoyStatus_LCL & JOY_DOWN) {
146  MouseReport->Y = 1;
147  }
148 
149  if (JoyStatus_LCL & JOY_LEFT) {
150  MouseReport->X = -1;
151  }
152  else if (JoyStatus_LCL & JOY_RIGHT) {
153  MouseReport->X = 1;
154  }
155 
156  if (JoyStatus_LCL & JOY_PRESS) {
157  MouseReport->Button |= (1 << 0);
158  }
159 
160  if (ButtonStatus_LCL & BUTTONS_BUTTON1) {
161  MouseReport->Button |= (1 << 1);
162  }
163 
164  *ReportSize = sizeof(USB_MouseReport_Data_t);
165  return true;
166 }
167 
171  const uint8_t ReportID,
172  const uint8_t ReportType,
173  const void *ReportData,
174  const uint16_t ReportSize)
175 {
176  // Unused (but mandatory for the HID class driver) in this demo, since there are no Host->Device reports
177 }