PDL for FM4  Version1.2
Peripheral Driverl Library for FM4
UsbDeviceHidMouse.c
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2013 Spansion LLC. All Rights Reserved.
3 *
4 * This software is owned and published by:
5 * Spansion LLC, 915 DeGuigne Dr. Sunnyvale, CA 94088-3453 ("Spansion").
6 *
7 * BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
8 * BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
9 *
10 * This software contains source code for use with Spansion
11 * components. This software is licensed by Spansion to be adapted only
12 * for use in systems utilizing Spansion components. Spansion shall not be
13 * responsible for misuse or illegal use of this software for devices not
14 * supported herein. Spansion is providing this software "AS IS" and will
15 * not be responsible for issues arising from incorrect user implementation
16 * of the software.
17 *
18 * SPANSION MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
19 * REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
20 * ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
21 * WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
22 * WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
23 * WARRANTY OF NONINFRINGEMENT.
24 * SPANSION SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
25 * NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
26 * LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
27 * LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
28 * INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
30 * SAVINGS OR PROFITS,
31 * EVEN IF SPANSION HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32 * YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
33 * INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
34 * FROM, THE SOFTWARE.
35 *
36 * This software may be replicated in part or whole for the licensed use,
37 * with the restriction that this Disclaimer and Copyright notice must be
38 * included with each copy of this software, whether used in part or whole,
39 * at all times.
40 */
41 /******************************************************************************/
53 /*****************************************************************************/
54 /* Include files */
55 /*****************************************************************************/
56 
57 #include "UsbDeviceHidMouse.h"
58 
59 #if ((FM_PERIPHERAL_USB_DEVICE_ENABLED == ON) && (USBDEVICEHIDMOUSE_ENABLED == ON))
60 
61 /*****************************************************************************/
62 /* Local pre-processor symbols/macros ('#define') */
63 /*****************************************************************************/
64 
65 
66 
67 /*****************************************************************************/
68 /* Global variable definitions (declared in header file with 'extern') */
69 /*****************************************************************************/
70 
71 /*****************************************************************************/
72 /* Local type definitions ('typedef') */
73 /*****************************************************************************/
74 
75 
76 
77 /*****************************************************************************/
78 /* Local variable definitions ('static') */
79 /*****************************************************************************/
80 
81 static uint8_t DataSentFlags = 0; //Status for sent data
82 static uint8_t pu8MouseData[4];
85 static stc_usbn_t* pstcUsbHandle = NULL;
87 
88 
89 
90 
91 
92 
93 /*****************************************************************************/
94 /* Local function prototypes ('static') */
95 /*****************************************************************************/
96 
97 static void ConfCallback(stc_usbn_t* pstcUsb);
98 
99 /*****************************************************************************/
100 /* Function implementation - global ('extern') and local ('static') */
101 /*****************************************************************************/
102 
103 
114 static void ConfCallback(stc_usbn_t* pstcUsb)
115 {
116  if (UsbDevice_GetStatus(pstcUsb) == UsbConfigured)
117  {
118  bReady = TRUE;
119  } else
120  {
121  bReady = FALSE;
122  }
123 }
124 
125 /*****************************************************************************/
126 /* Function implementation - global ('extern') and local ('static') */
127 /*****************************************************************************/
128 
129 void UsbDeviceHidMouse_Init(stc_usbn_t* pstcUsb)
130 {
131  stc_usbdevice_class_config_t stcUsbClassConfig;
132  stc_usbdevice_endpoint_config_t stcEndpointConfig;
133  uint8_t* pu8Interface = NULL;
134  uint8_t u8InterfaceLength = 0;
135  uint8_t u8i = 0;
136  uint8_t u8NumEndpoints = 0;
137  pstcUsbHandle = pstcUsb;
138 
139  stcUsbClassConfig.u8InterfaceNumber = 0xFF; // do not use fix interface number, choose by class, subclass, protocol
140  stcUsbClassConfig.u8InterfaceClass = 0x03; // HID Class
141  stcUsbClassConfig.u8InterfaceSubClass = 0x01; // Custom Sub Class
142  stcUsbClassConfig.u8InterfaceProtocoll = 0x02; // Custom Protocol
143  stcUsbClassConfig.pfnSetupRequestCallback = NULL; // setup requests handled
144  stcUsbClassConfig.pfnConnectionCallback = NULL; // No connection callback handled
145  stcUsbClassConfig.pfnDisconnectionCallback = NULL; // No disconnection callback handled
146  stcUsbClassConfig.pfnConfCallback = ConfCallback; // Callback for configuration set
147  UsbDevice_RegisterVendorClass(pstcUsb,&stcUsbClassConfig,&pu8Interface,&u8InterfaceLength);
148 
149  for(u8i = 0;u8i < u8InterfaceLength;)
150  {
151  u8i += pu8Interface[u8i];
152  if (USBDESCR_ENDPOINT == pu8Interface[u8i + 1])
153  {
154  stcEndpointConfig.u8EndpointAddress = pu8Interface[u8i + 2];
155  if (((stcEndpointConfig.u8EndpointAddress) & 0x80) == 0)
156  {
157  /* NOT USED */
158  }
159  else
160  {
161  stcEndpointConfig.pstcEndpointBuffer = &stcEndpointBufferIN;
162  pstcEndpointIN = UsbDevice_SetupEndpoint(pstcUsb, &stcEndpointConfig);
163  }
164  u8NumEndpoints++;
165  }
166  }
167 
168 }
169 
180 static boolean_t SendData(uint8_t* pu8Buffer, uint32_t u32DataSize, en_usbsend_mode_t enMode)
181 {
183  {
184  DataSentFlags &= ~(1<<1);
185 
186  UsbDevice_SendData(pstcUsbHandle, pstcEndpointIN, pu8Buffer, u32DataSize, enMode);
187  if (enMode == UsbPOLL)
188  {
189  DataSentFlags |= (1<<1);
190  }
191  return TRUE;
192  }
193  return FALSE;
194 }
195 
196 
205 void UsbDeviceHidMouse_Move(int8_t i8X, int8_t i8Y)
206 {
207  pu8MouseData[1] = (int8_t)i8X;
208  pu8MouseData[2] = (int8_t)i8Y;
209  SendData((uint8_t*)pu8MouseData,4,UsbPOLL);
210 }
211 
212 
219 {
223 }
224 
225 
232 {
238 }
239 
246 {
247  pu8MouseData[0] |= 0x01;
248  pu8MouseData[1] = 0;
249  pu8MouseData[2] = 0;
250  pu8MouseData[3] = 0;
251  SendData((uint8_t*)pu8MouseData,4,UsbPOLL);
252 }
253 
260 {
261  pu8MouseData[0] &= ~0x01;
262  pu8MouseData[1] = 0;
263  pu8MouseData[2] = 0;
264  pu8MouseData[3] = 0;
265  SendData((uint8_t*)pu8MouseData,4,UsbPOLL);
266 }
267 
274 {
278 }
279 
286 {
292 }
293 
300 {
301  pu8MouseData[0] |= 0x02;
302  pu8MouseData[1] = 0;
303  pu8MouseData[2] = 0;
304  pu8MouseData[3] = 0;
305  SendData((uint8_t*)pu8MouseData,4,UsbPOLL);
306 }
307 
314 {
315  pu8MouseData[0] &= ~0x02;
316  pu8MouseData[1] = 0;
317  pu8MouseData[2] = 0;
318  pu8MouseData[3] = 0;
319  SendData((uint8_t*)pu8MouseData,4,UsbPOLL);
320 }
321 
329 void UsbDeviceHidMouse_Scroll(int8_t i8Scroll)
330 {
331  pu8MouseData[1] = 0;
332  pu8MouseData[2] = 0;
333  pu8MouseData[3] = (int8_t)i8Scroll;
334  SendData((uint8_t*)pu8MouseData,4,UsbPOLL);
335 }
336 
345 {
346  return bReady;
347 }
348 #endif