STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
usbh_hid_mouse.c
Go to the documentation of this file.
1 
28 /* Includes ------------------------------------------------------------------*/
29 #include "usbh_hid_mouse.h"
30 #include "usbh_hid_parser.h"
31 
32 
76 static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost);
77 
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 
177 {
178  HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) 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 
205 {
206  if(USBH_HID_MouseDecode(phost)== USBH_OK)
207  {
208  return &mouse_info;
209  }
210  else
211  {
212  return NULL;
213  }
214 }
215 
222 static USBH_StatusTypeDef USBH_HID_MouseDecode(USBH_HandleTypeDef *phost)
223 {
224  HID_HandleTypeDef *HID_Handle = (HID_HandleTypeDef *) 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 
267 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define HID_QUEUE_SIZE
Definition: usbh_hid.h:67
USBH_DeviceTypeDef device
Definition: usbh_def.h:456
uint16_t length
Definition: usbh_hid.h:226
FIFO_TypeDef fifo
Definition: usbh_hid.h:224
uint32_t mouse_report_data[1]
USBH_StatusTypeDef USBH_HID_MouseInit(USBH_HandleTypeDef *phost)
USBH_HID_MouseInit The function init the HID mouse.
#define NULL
Definition: usbd_def.h:53
uint8_t * pData
Definition: usbh_hid.h:225
This file contains all the prototypes for the usbh_hid_mouse.c.
HID_MOUSE_Info_TypeDef * USBH_HID_GetMouseInfo(USBH_HandleTypeDef *phost)
USBH_HID_GetMouseInfo The function return mouse information.
USBH_StatusTypeDef
Definition: usbh_def.h:302
uint16_t fifo_read(FIFO_TypeDef *f, void *buf, uint16_t nbytes)
fifo_read Read from FIFO.
Definition: usbh_hid.c:723
uint8_t Data[USBH_MAX_DATA_BUFFER]
Definition: usbh_def.h:424
USBH_ClassTypeDef * pActiveClass
Definition: usbh_def.h:458
void fifo_init(FIFO_TypeDef *f, uint8_t *buf, uint16_t size)
fifo_init Initialize FIFO.
Definition: usbh_hid.c:706
HID_MOUSE_Info_TypeDef mouse_info
uint8_t buttons[3]
uint32_t HID_ReadItem(HID_Report_ItemTypedef *ri, uint8_t ndx)
HID_ReadItem The function read a report item.