Debian Codegraph @

ports/stm32/usbhost/Class/HID/Src/usbh_hid_mouse.c

raw
1 /**
2 ******************************************************************************
3 * @file usbh_hid_mouse.c
4 * @author MCD Application Team
5 * @version V3.0.0
6 * @date 18-February-2014
7 * @brief This file is the application layer for USB Host HID Mouse Handling.
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
12 *
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
16 *
17 * http://www.st.com/software_license_agreement_liberty_v2
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 ******************************************************************************
26 */
27
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbh_hid_mouse.h"
30 #include "usbh_hid_parser.h"
31
32
33 /** @addtogroup USBH_LIB
34 * @{
35 */
36
37 /** @addtogroup USBH_CLASS
38 * @{
39 */
40
41 /** @addtogroup USBH_HID_CLASS
42 * @{
43 */
44
45 /** @defgroup USBH_HID_MOUSE
46 * @brief This file includes HID Layer Handlers for USB Host HID class.
47 * @{
48 */
49
50 /** @defgroup USBH_HID_MOUSE_Private_TypesDefinitions
51 * @{
52 */
53 /**
54 * @}
55 */
56
57
58 /** @defgroup USBH_HID_MOUSE_Private_Defines
59 * @{
60 */
61 /**
62 * @}
63 */
64
65
66 /** @defgroup USBH_HID_MOUSE_Private_Macros
67 * @{
68 */
69 /**
70 * @}
71 */
72
73 /** @defgroup USBH_HID_MOUSE_Private_FunctionPrototypes
74 * @{
75 */
76 static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost);
77
78 /**
79 * @}
80 */
81
82
83 /** @defgroup USBH_HID_MOUSE_Private_Variables
84 * @{
85 */
86 HID_MOUSE_Info_TypeDef mouse_info;
87 uint32_t mouse_report_data[1];
88
89 /* Structures defining how to access items in a HID mouse report */
90 /* Access button 1 state. */
91 static const HID_Report_ItemTypedef prop_b1={
92 (uint8_t *)mouse_report_data+0, /*data*/
93 1, /*size*/
94 0, /*shift*/
95 0, /*count (only for array items)*/
96 0, /*signed?*/
97 0, /*min value read can return*/
98 1, /*max value read can return*/
99 0, /*min value device can report*/
100 1, /*max value device can report*/
101 1 /*resolution*/
102 };
103
104 /* Access button 2 state. */
105 static const HID_Report_ItemTypedef prop_b2={
106 (uint8_t *)mouse_report_data+0, /*data*/
107 1, /*size*/
108 1, /*shift*/
109 0, /*count (only for array items)*/
110 0, /*signed?*/
111 0, /*min value read can return*/
112 1, /*max value read can return*/
113 0, /*min value device can report*/
114 1, /*max value device can report*/
115 1 /*resolution*/
116 };
117
118 /* Access button 3 state. */
119 static const HID_Report_ItemTypedef prop_b3={
120 (uint8_t *)mouse_report_data+0, /*data*/
121 1, /*size*/
122 2, /*shift*/
123 0, /*count (only for array items)*/
124 0, /*signed?*/
125 0, /*min value read can return*/
126 1, /*max value read can return*/
127 0, /*min vale device can report*/
128 1, /*max value device can report*/
129 1 /*resolution*/
130 };
131
132 /* Access x coordinate change. */
133 static const HID_Report_ItemTypedef prop_x={
134 (uint8_t *)mouse_report_data+1, /*data*/
135 8, /*size*/
136 0, /*shift*/
137 0, /*count (only for array items)*/
138 1, /*signed?*/
139 0, /*min value read can return*/
140 0xFFFF,/*max value read can return*/
141 0, /*min vale device can report*/
142 0xFFFF,/*max value device can report*/
143 1 /*resolution*/
144 };
145
146 /* Access y coordinate change. */
147 static const HID_Report_ItemTypedef prop_y={
148 (uint8_t *)mouse_report_data+2, /*data*/
149 8, /*size*/
150 0, /*shift*/
151 0, /*count (only for array items)*/
152 1, /*signed?*/
153 0, /*min value read can return*/
154 0xFFFF,/*max value read can return*/
155 0, /*min vale device can report*/
156 0xFFFF,/*max value device can report*/
157 1 /*resolution*/
158 };
159
160
161 /**
162 * @}
163 */
164
165
166 /** @defgroup USBH_HID_MOUSE_Private_Functions
167 * @{
168 */
169
170 /**
171 * @brief USBH_HID_MouseInit
172 * The function init the HID mouse.
173 * @param phost: Host handle
174 * @retval USBH Status
175 */
176 USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost)
177 {
178 HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
179
180 mouse_info.x=0;
181 mouse_info.y=0;
182 mouse_info.buttons[0]=0;
183 mouse_info.buttons[1]=0;
184 mouse_info.buttons[2]=0;
185
186 mouse_report_data[0]=0;
187
188 if(HID_Handle->length > sizeof(mouse_report_data))
189 {
190 HID_Handle->length = sizeof(mouse_report_data);
191 }
192 HID_Handle->pData = (uint8_t *)mouse_report_data;
193 fifo_init(&HID_Handle->fifo, phost->device.Data, HID_QUEUE_SIZE * sizeof(mouse_report_data));
194
195 return USBH_OK;
196 }
197
198 /**
199 * @brief USBH_HID_GetMouseInfo
200 * The function return mouse information.
201 * @param phost: Host handle
202 * @retval mouse information
203 */
204 HID_MOUSE_Info_TypeDef *USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost)
205 {
206 if(USBH_HID_MouseDecode(phost)== USBH_OK)
207 {
208 return &mouse_info;
209 }
210 else
211 {
212 return NULL;
213 }
214 }
215
216 /**
217 * @brief USBH_HID_MouseDecode
218 * The function decode mouse data.
219 * @param phost: Host handle
220 * @retval USBH Status
221 */
222 static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost)
223 {
224 HID_HandleTypeDef *HID_Handle = phost->pActiveClass->pData;
225
226 if(HID_Handle->length == 0)
227 {
228 return USBH_FAIL;
229 }
230 /*Fill report */
231 if(fifo_read(&HID_Handle->fifo, &mouse_report_data, HID_Handle->length) == HID_Handle->length)
232 {
233
234 /*Decode report */
235 mouse_info.x = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_x, 0);
236 mouse_info.y = (int16_t )HID_ReadItem((HID_Report_ItemTypedef *) &prop_y, 0);
237
238 mouse_info.buttons[0]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b1, 0);
239 mouse_info.buttons[1]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b2, 0);
240 mouse_info.buttons[2]=(uint8_t)HID_ReadItem((HID_Report_ItemTypedef *) &prop_b3, 0);
241
242 return USBH_OK;
243 }
244 return USBH_FAIL;
245 }
246
247 /**
248 * @}
249 */
250
251 /**
252 * @}
253 */
254
255 /**
256 * @}
257 */
258
259 /**
260 * @}
261 */
262
263
264 /**
265 * @}
266 */
267 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/