Changeset 60c0573 in mainline
- Timestamp:
- 2011-04-10T15:17:22Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ba358ed
- Parents:
- dc4c19e
- Location:
- uspace/drv/usbhid
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/generic/hiddev.c
rdc4c19e r60c0573 39 39 40 40 #include "hiddev.h" 41 #include "usbhid.h" 41 42 42 43 /*----------------------------------------------------------------------------*/ … … 54 55 /*----------------------------------------------------------------------------*/ 55 56 56 bool usb_ hid_polling_callback(usb_device_t *dev, uint8_t *buffer,57 size_t buffer_size, void *arg)57 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, 58 uint8_t *buffer, size_t buffer_size) 58 59 { 59 usb_log_debug("usb_hid_polling_callback(%p, %p, %zu , %p)\n",60 dev, buffer, buffer_size, arg);60 usb_log_debug("usb_hid_polling_callback(%p, %p, %zu)\n", 61 hid_dev, buffer, buffer_size); 61 62 usb_debug_str_buffer(buffer, buffer_size, 0); 62 63 return true; -
uspace/drv/usbhid/generic/hiddev.h
rdc4c19e r60c0573 39 39 #include <usb/devdrv.h> 40 40 41 struct usb_hid_dev; 42 41 43 usb_endpoint_description_t usb_hid_generic_poll_endpoint_description; 42 44 … … 44 46 const char *HID_GENERIC_CLASS_NAME; 45 47 46 bool usb_ hid_polling_callback(usb_device_t *dev, uint8_t *buffer,47 size_t buffer_size, void *arg);48 bool usb_generic_hid_polling_callback(struct usb_hid_dev *hid_dev, 49 uint8_t *buffer, size_t buffer_size); 48 50 49 51 #endif // USB_HIDDDEV_H_ -
uspace/drv/usbhid/kbd/kbddev.c
rdc4c19e r60c0573 856 856 /*----------------------------------------------------------------------------*/ 857 857 858 bool usb_kbd_polling_callback(usb_ device_t *dev, uint8_t *buffer,859 size_t buffer_size , void *arg)860 { 861 if ( dev == NULL || buffer == NULL || arg== NULL) {858 bool usb_kbd_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer, 859 size_t buffer_size) 860 { 861 if (hid_dev == NULL || buffer == NULL) { 862 862 // do not continue polling (???) 863 863 return false; 864 864 } 865 866 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;867 865 868 866 // TODO: add return value from this function … … 916 914 /*----------------------------------------------------------------------------*/ 917 915 918 void usb_kbd_deinit( structusb_hid_dev_t *hid_dev)916 void usb_kbd_deinit(usb_hid_dev_t *hid_dev) 919 917 { 920 918 if (hid_dev == NULL) { -
uspace/drv/usbhid/kbd/kbddev.h
rdc4c19e r60c0573 49 49 #include "kbdrepeat.h" 50 50 51 struct usb_hid_dev _t;51 struct usb_hid_dev; 52 52 53 53 /*----------------------------------------------------------------------------*/ … … 115 115 /*----------------------------------------------------------------------------*/ 116 116 117 int usb_kbd_init(struct usb_hid_dev _t*hid_dev);117 int usb_kbd_init(struct usb_hid_dev *hid_dev); 118 118 119 bool usb_kbd_polling_callback( usb_device_t *dev, uint8_t *buffer,120 size_t buffer_size, void *arg);119 bool usb_kbd_polling_callback(struct usb_hid_dev *hid_dev, uint8_t *buffer, 120 size_t buffer_size); 121 121 122 122 int usb_kbd_is_initialized(const usb_kbd_t *kbd_dev); … … 126 126 void usb_kbd_free(usb_kbd_t **kbd_dev); 127 127 128 void usb_kbd_push_ev(struct usb_hid_dev _t*hid_dev, usb_kbd_t *kbd_dev,128 void usb_kbd_push_ev(struct usb_hid_dev *hid_dev, usb_kbd_t *kbd_dev, 129 129 int type, unsigned int key); 130 130 131 void usb_kbd_deinit(struct usb_hid_dev _t*hid_dev);131 void usb_kbd_deinit(struct usb_hid_dev *hid_dev); 132 132 133 int usb_kbd_set_boot_protocol(struct usb_hid_dev _t*hid_dev);133 int usb_kbd_set_boot_protocol(struct usb_hid_dev *hid_dev); 134 134 135 135 #endif /* USB_KBDDEV_H_ */ -
uspace/drv/usbhid/main.c
rdc4c19e r60c0573 98 98 /* Create the function exposed under /dev/devices. */ 99 99 ddf_fun_t *hid_fun = ddf_fun_create(dev->ddf_dev, fun_exposed, 100 usb_hid_get_function_name(hid_dev ->device_type));100 usb_hid_get_function_name(hid_dev)); 101 101 if (hid_fun == NULL) { 102 102 usb_log_error("Could not create DDF function node.\n"); … … 122 122 } 123 123 124 rc = ddf_fun_add_to_class(hid_fun, 125 usb_hid_get_class_name(hid_dev->device_type)); 124 rc = ddf_fun_add_to_class(hid_fun, usb_hid_get_class_name(hid_dev)); 126 125 if (rc != EOK) { 127 126 usb_log_error( … … 142 141 hid_dev->poll_pipe_index, 143 142 /* Callback when data arrives. */ 144 hid_dev->poll_callback,143 usb_hid_polling_callback, 145 144 /* How much data to request. */ 146 145 dev->pipes[hid_dev->poll_pipe_index].pipe->max_packet_size, -
uspace/drv/usbhid/mouse/mousedev.c
rdc4c19e r60c0573 231 231 /*----------------------------------------------------------------------------*/ 232 232 233 int usb_mouse_init( structusb_hid_dev_t *hid_dev)233 int usb_mouse_init(usb_hid_dev_t *hid_dev) 234 234 { 235 235 usb_log_debug("Initializing HID/Mouse structure...\n"); … … 252 252 253 253 // set handler for incoming calls 254 // TODO: now does this behave when we have more such handlers in255 // one actual driver??256 254 hid_dev->ops.default_handler = default_connection_handler; 257 255 258 256 // TODO: how to know if the device supports the request??? 259 //usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe,260 //hid_dev->usb_dev->interface_no, IDLE_RATE);257 usbhid_req_set_idle(&hid_dev->usb_dev->ctrl_pipe, 258 hid_dev->usb_dev->interface_no, IDLE_RATE); 261 259 262 260 return EOK; … … 265 263 /*----------------------------------------------------------------------------*/ 266 264 267 bool usb_mouse_polling_callback(usb_ device_t *dev, uint8_t *buffer,268 size_t buffer_size , void *arg)265 bool usb_mouse_polling_callback(usb_hid_dev_t *hid_dev, uint8_t *buffer, 266 size_t buffer_size) 269 267 { 270 268 usb_log_debug("usb_mouse_polling_callback()\n"); 271 269 usb_debug_str_buffer(buffer, buffer_size, 0); 272 270 273 if ( arg== NULL) {271 if (hid_dev == NULL) { 274 272 usb_log_error("Missing argument to the mouse polling callback." 275 273 "\n"); … … 277 275 } 278 276 279 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;280 277 if (hid_dev->data == NULL) { 281 278 usb_log_error("Wrong argument to the mouse polling callback." … … 290 287 /*----------------------------------------------------------------------------*/ 291 288 292 void usb_mouse_deinit( structusb_hid_dev_t *hid_dev)289 void usb_mouse_deinit(usb_hid_dev_t *hid_dev) 293 290 { 294 291 usb_mouse_free((usb_mouse_t **)&hid_dev->data); … … 297 294 /*----------------------------------------------------------------------------*/ 298 295 299 int usb_mouse_set_boot_protocol( structusb_hid_dev_t *hid_dev)296 int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev) 300 297 { 301 298 int rc = usb_hid_parse_report_descriptor(hid_dev->parser, -
uspace/drv/usbhid/mouse/mousedev.h
rdc4c19e r60c0573 39 39 #include <usb/devdrv.h> 40 40 41 struct usb_hid_dev _t;41 struct usb_hid_dev; 42 42 43 43 /*----------------------------------------------------------------------------*/ … … 60 60 /*----------------------------------------------------------------------------*/ 61 61 62 int usb_mouse_init(struct usb_hid_dev _t*hid_dev);62 int usb_mouse_init(struct usb_hid_dev *hid_dev); 63 63 64 bool usb_mouse_polling_callback( usb_device_t *dev, uint8_t *buffer,65 size_t buffer_size, void *arg);64 bool usb_mouse_polling_callback(struct usb_hid_dev *hid_dev, uint8_t *buffer, 65 size_t buffer_size); 66 66 67 void usb_mouse_deinit(struct usb_hid_dev _t*hid_dev);67 void usb_mouse_deinit(struct usb_hid_dev *hid_dev); 68 68 69 int usb_mouse_set_boot_protocol(struct usb_hid_dev _t*hid_dev);69 int usb_mouse_set_boot_protocol(struct usb_hid_dev *hid_dev); 70 70 71 71 /*----------------------------------------------------------------------------*/ -
uspace/drv/usbhid/usbhid.c
rdc4c19e r60c0573 51 51 /*----------------------------------------------------------------------------*/ 52 52 53 typedef struct usb_hid_callback_mapping { 54 usb_hid_report_path_t *path; 55 char *vendor_id; 56 char *product_id; 57 } usb_hid_callback_mapping; 58 59 /*----------------------------------------------------------------------------*/ 60 53 61 /* Array of endpoints expected on the device, NULL terminated. */ 54 62 usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1] = { … … 61 69 /*----------------------------------------------------------------------------*/ 62 70 71 static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev) 72 { 73 assert(hid_dev->subdriver_count == 0); 74 75 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 76 sizeof(usb_hid_subdriver_t)); 77 if (hid_dev->subdrivers == NULL) { 78 return ENOMEM; 79 } 80 81 // set the init callback 82 hid_dev->subdrivers[0].init = usb_kbd_init; 83 84 // set the polling callback 85 hid_dev->subdrivers[0].poll = usb_kbd_polling_callback; 86 87 // set the polling ended callback 88 hid_dev->subdrivers[0].poll_end = NULL; 89 90 // set the deinit callback 91 hid_dev->subdrivers[0].deinit = usb_kbd_deinit; 92 93 // set subdriver count 94 hid_dev->subdriver_count = 1; 95 96 return EOK; 97 } 98 99 /*----------------------------------------------------------------------------*/ 100 101 static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev) 102 { 103 assert(hid_dev->subdriver_count == 0); 104 105 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 106 sizeof(usb_hid_subdriver_t)); 107 if (hid_dev->subdrivers == NULL) { 108 return ENOMEM; 109 } 110 111 // set the init callback 112 hid_dev->subdrivers[0].init = usb_mouse_init; 113 114 // set the polling callback 115 hid_dev->subdrivers[0].poll = usb_mouse_polling_callback; 116 117 // set the polling ended callback 118 hid_dev->subdrivers[0].poll_end = NULL; 119 120 // set the deinit callback 121 hid_dev->subdrivers[0].deinit = usb_mouse_deinit; 122 123 // set subdriver count 124 hid_dev->subdriver_count = 1; 125 126 return EOK; 127 } 128 129 /*----------------------------------------------------------------------------*/ 130 131 static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev) 132 { 133 assert(hid_dev->subdriver_count == 0); 134 135 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 136 sizeof(usb_hid_subdriver_t)); 137 if (hid_dev->subdrivers == NULL) { 138 return ENOMEM; 139 } 140 141 // set the init callback 142 hid_dev->subdrivers[0].init = NULL; 143 144 // set the polling callback 145 hid_dev->subdrivers[0].poll = usb_generic_hid_polling_callback; 146 147 // set the polling ended callback 148 hid_dev->subdrivers[0].poll_end = NULL; 149 150 // set the deinit callback 151 hid_dev->subdrivers[0].deinit = NULL; 152 153 return EOK; 154 } 155 156 /*----------------------------------------------------------------------------*/ 157 158 static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev) 159 { 160 return EOK; 161 } 162 163 /*----------------------------------------------------------------------------*/ 164 165 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev) 166 { 167 // first try to find subdrivers that may want to handle this device 168 int rc = usb_hid_find_subdrivers(hid_dev); 169 170 if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) { 171 usb_log_debug("Found keyboard endpoint.\n"); 172 173 // save the pipe index 174 hid_dev->poll_pipe_index = USB_HID_KBD_POLL_EP_NO; 175 176 // if no subdrivers registered, use the boot kbd subdriver 177 if (hid_dev->subdriver_count == 0) { 178 rc = usb_hid_set_boot_kbd_subdriver(hid_dev); 179 } 180 } else if (dev->pipes[USB_HID_MOUSE_POLL_EP_NO].present) { 181 usb_log_debug("Found mouse endpoint.\n"); 182 183 // save the pipe index 184 hid_dev->poll_pipe_index = USB_HID_MOUSE_POLL_EP_NO; 185 //hid_dev->device_type = USB_HID_PROTOCOL_MOUSE; 186 187 // if no subdrivers registered, use the boot kbd subdriver 188 if (hid_dev->subdriver_count == 0) { 189 rc = usb_hid_set_boot_mouse_subdriver(hid_dev); 190 } 191 } else if (dev->pipes[USB_HID_GENERIC_POLL_EP_NO].present) { 192 usb_log_debug("Found generic HID endpoint.\n"); 193 194 // save the pipe index 195 hid_dev->poll_pipe_index = USB_HID_GENERIC_POLL_EP_NO; 196 197 if (hid_dev->subdriver_count == 0) { 198 usb_log_warning("Found no subdriver for handling this" 199 " HID device. Setting generic HID subdriver.\n"); 200 usb_hid_set_generic_hid_subdriver(hid_dev); 201 return EOK; 202 } 203 } else { 204 usb_log_error("None of supported endpoints found - probably" 205 " not a supported device.\n"); 206 rc = ENOTSUP; 207 } 208 209 return rc; 210 } 211 212 /*----------------------------------------------------------------------------*/ 213 214 static int usb_hid_init_parser(usb_hid_dev_t *hid_dev) 215 { 216 /* Initialize the report parser. */ 217 int rc = usb_hid_parser_init(hid_dev->parser); 218 if (rc != EOK) { 219 usb_log_error("Failed to initialize report parser.\n"); 220 return rc; 221 } 222 223 /* Get the report descriptor and parse it. */ 224 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 225 hid_dev->parser); 226 227 // TODO: remove the hack 228 if (rc != EOK || hid_dev->poll_pipe_index == USB_HID_MOUSE_POLL_EP_NO) { 229 usb_log_warning("Could not process report descriptor.\n"); 230 231 if (hid_dev->poll_pipe_index == USB_HID_KBD_POLL_EP_NO) { 232 usb_log_warning("Falling back to boot protocol.\n"); 233 rc = usb_kbd_set_boot_protocol(hid_dev); 234 } else if (hid_dev->poll_pipe_index 235 == USB_HID_MOUSE_POLL_EP_NO) { 236 usb_log_warning("Falling back to boot protocol.\n"); 237 rc = usb_mouse_set_boot_protocol(hid_dev); 238 } 239 } 240 241 return rc; 242 } 243 244 /*----------------------------------------------------------------------------*/ 245 63 246 usb_hid_dev_t *usb_hid_new(void) 64 247 { … … 84 267 /*----------------------------------------------------------------------------*/ 85 268 86 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)87 {88 if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) {89 usb_log_debug("Found keyboard endpoint.\n");90 91 // save the pipe index and device type92 hid_dev->poll_pipe_index = USB_HID_KBD_POLL_EP_NO;93 hid_dev->device_type = USB_HID_PROTOCOL_KEYBOARD;94 95 // set the polling callback96 hid_dev->poll_callback = usb_kbd_polling_callback;97 98 } else if (dev->pipes[USB_HID_MOUSE_POLL_EP_NO].present) {99 usb_log_debug("Found mouse endpoint.\n");100 101 // save the pipe index and device type102 hid_dev->poll_pipe_index = USB_HID_MOUSE_POLL_EP_NO;103 hid_dev->device_type = USB_HID_PROTOCOL_MOUSE;104 105 // set the polling callback106 hid_dev->poll_callback = usb_mouse_polling_callback;107 108 } else if (dev->pipes[USB_HID_GENERIC_POLL_EP_NO].present) {109 usb_log_debug("Found generic HID endpoint.\n");110 111 // save the pipe index and device type112 hid_dev->poll_pipe_index = USB_HID_GENERIC_POLL_EP_NO;113 hid_dev->device_type = USB_HID_PROTOCOL_NONE;114 115 // set the polling callback116 hid_dev->poll_callback = usb_hid_polling_callback;117 118 } else {119 usb_log_warning("None of supported endpoints found - probably"120 " not a supported device.\n");121 return ENOTSUP;122 }123 124 return EOK;125 }126 127 /*----------------------------------------------------------------------------*/128 129 static int usb_hid_init_parser(usb_hid_dev_t *hid_dev)130 {131 /* Initialize the report parser. */132 int rc = usb_hid_parser_init(hid_dev->parser);133 if (rc != EOK) {134 usb_log_error("Failed to initialize report parser.\n");135 return rc;136 }137 138 /* Get the report descriptor and parse it. */139 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev,140 hid_dev->parser);141 142 if (rc != EOK || hid_dev->device_type == USB_HID_PROTOCOL_MOUSE) {143 usb_log_warning("Could not process report descriptor.\n");144 145 if (hid_dev->device_type == USB_HID_PROTOCOL_KEYBOARD) {146 usb_log_warning("Falling back to boot protocol.\n");147 rc = usb_kbd_set_boot_protocol(hid_dev);148 } else if (hid_dev->device_type == USB_HID_PROTOCOL_MOUSE) {149 usb_log_warning("Falling back to boot protocol.\n");150 rc = usb_mouse_set_boot_protocol(hid_dev);151 }152 }153 154 return rc;155 }156 157 /*----------------------------------------------------------------------------*/158 159 269 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev) 160 270 { 161 int rc ;271 int rc, i; 162 272 163 273 usb_log_debug("Initializing HID structure...\n"); … … 189 299 } 190 300 191 switch (hid_dev->device_type) { 192 case USB_HID_PROTOCOL_KEYBOARD: 193 // initialize the keyboard structure 194 rc = usb_kbd_init(hid_dev); 195 if (rc != EOK) { 196 usb_log_warning("Failed to initialize KBD structure." 197 "\n"); 198 } 199 break; 200 case USB_HID_PROTOCOL_MOUSE: 201 rc = usb_mouse_init(hid_dev); 202 if (rc != EOK) { 203 usb_log_warning("Failed to initialize Mouse structure." 204 "\n"); 205 } 206 break; 207 default: 208 break; 301 for (i = 0; i < hid_dev->subdriver_count; ++i) { 302 if (hid_dev->subdrivers[i].init != NULL) { 303 rc = hid_dev->subdrivers[i].init(hid_dev); 304 if (rc != EOK) { 305 usb_log_warning("Failed to initialize HID" 306 " subdriver structure.\n"); 307 } 308 } 209 309 } 210 310 211 311 return rc; 312 } 313 314 /*----------------------------------------------------------------------------*/ 315 316 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 317 size_t buffer_size, void *arg) 318 { 319 int i; 320 321 if (dev == NULL || arg == NULL || buffer == NULL) { 322 usb_log_error("Missing arguments to polling callback.\n"); 323 return false; 324 } 325 326 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 327 328 bool cont = false; 329 330 // continue if at least one of the subdrivers want to continue 331 for (i = 0; i < hid_dev->subdriver_count; ++i) { 332 if (hid_dev->subdrivers[i].poll != NULL 333 && hid_dev->subdrivers[i].poll(hid_dev, buffer, 334 buffer_size)) { 335 cont = true; 336 } 337 } 338 339 return cont; 212 340 } 213 341 … … 217 345 void *arg) 218 346 { 347 int i; 348 219 349 if (dev == NULL || arg == NULL) { 220 350 return; … … 223 353 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 224 354 355 for (i = 0; i < hid_dev->subdriver_count; ++i) { 356 if (hid_dev->subdrivers[i].poll_end != NULL) { 357 hid_dev->subdrivers[i].poll_end(hid_dev, reason); 358 } 359 } 360 225 361 usb_hid_free(&hid_dev); 226 362 } … … 228 364 /*----------------------------------------------------------------------------*/ 229 365 230 const char *usb_hid_get_function_name( usb_hid_iface_protocol_t device_type)231 { 232 switch ( device_type) {233 case USB_HID_ PROTOCOL_KEYBOARD:366 const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev) 367 { 368 switch (hid_dev->poll_pipe_index) { 369 case USB_HID_KBD_POLL_EP_NO: 234 370 return HID_KBD_FUN_NAME; 235 371 break; 236 case USB_HID_ PROTOCOL_MOUSE:372 case USB_HID_MOUSE_POLL_EP_NO: 237 373 return HID_MOUSE_FUN_NAME; 238 374 break; … … 244 380 /*----------------------------------------------------------------------------*/ 245 381 246 const char *usb_hid_get_class_name(usb_hid_iface_protocol_t device_type) 247 { 248 switch (device_type) { 249 case USB_HID_PROTOCOL_KEYBOARD: 382 const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev) 383 { 384 // this means that only boot protocol keyboards will be connected 385 // to the console; there is probably no better way to do this 386 387 switch (hid_dev->poll_pipe_index) { 388 case USB_HID_KBD_POLL_EP_NO: 250 389 return HID_KBD_CLASS_NAME; 251 390 break; 252 case USB_HID_ PROTOCOL_MOUSE:391 case USB_HID_MOUSE_POLL_EP_NO: 253 392 return HID_MOUSE_CLASS_NAME; 254 393 break; … … 262 401 void usb_hid_free(usb_hid_dev_t **hid_dev) 263 402 { 403 int i; 404 264 405 if (hid_dev == NULL || *hid_dev == NULL) { 265 406 return; 266 407 } 267 408 268 switch ((*hid_dev)->device_type) { 269 case USB_HID_PROTOCOL_KEYBOARD: 270 usb_kbd_deinit(*hid_dev); 271 break; 272 case USB_HID_PROTOCOL_MOUSE: 273 usb_mouse_deinit(*hid_dev); 274 break; 275 default: 276 break; 409 for (i = 0; i < (*hid_dev)->subdriver_count; ++i) { 410 if ((*hid_dev)->subdrivers[i].deinit != NULL) { 411 (*hid_dev)->subdrivers[i].deinit(*hid_dev); 412 } 277 413 } 278 414 -
uspace/drv/usbhid/usbhid.h
rdc4c19e r60c0573 45 45 #include <usb/classes/hid.h> 46 46 47 struct usb_hid_dev; 48 49 typedef int (*usb_hid_driver_init_t)(struct usb_hid_dev *); 50 typedef void (*usb_hid_driver_deinit_t)(struct usb_hid_dev *); 51 typedef bool (*usb_hid_driver_poll)(struct usb_hid_dev *, uint8_t *, size_t); 52 typedef int (*usb_hid_driver_poll_ended)(struct usb_hid_dev *, bool reason); 53 54 // TODO: add function and class name?? 55 typedef struct usb_hid_subdriver { 56 /** Function to be called when initializing HID device. */ 57 usb_hid_driver_init_t init; 58 /** Function to be called when destroying the HID device structure. */ 59 usb_hid_driver_deinit_t deinit; 60 /** Function to be called when data arrives from the device. */ 61 usb_hid_driver_poll poll; 62 /** Function to be called when polling ends. */ 63 usb_hid_driver_poll_ended poll_end; 64 } usb_hid_subdriver_t; 65 47 66 /*----------------------------------------------------------------------------*/ 48 67 /** 49 68 * Structure for holding general HID device data. 50 69 */ 51 typedef struct usb_hid_dev _t{70 typedef struct usb_hid_dev { 52 71 /** Structure holding generic USB device information. */ 53 72 usb_device_t *usb_dev; … … 59 78 int poll_pipe_index; 60 79 61 /** Function to be called when data arrives from the device. */ 62 usb_polling_callback_t poll_callback; 80 /** Subdrivers. */ 81 usb_hid_subdriver_t *subdrivers; 82 83 /** Number of subdrivers. */ 84 int subdriver_count; 63 85 64 86 /** Report descriptor. */ … … 73 95 /** Arbitrary data (e.g. a special structure for handling keyboard). */ 74 96 void *data; 75 76 /** Type of the device (keyboard, mouse, generic HID device). */77 usb_hid_iface_protocol_t device_type;78 97 } usb_hid_dev_t; 79 98 … … 95 114 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev); 96 115 116 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 117 size_t buffer_size, void *arg); 118 97 119 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, 98 120 void *arg); 99 121 100 const char *usb_hid_get_function_name( usb_hid_iface_protocol_t device_type);122 const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev); 101 123 102 const char *usb_hid_get_class_name( usb_hid_iface_protocol_t device_type);124 const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev); 103 125 104 126 void usb_hid_free(usb_hid_dev_t **hid_dev);
Note:
See TracChangeset
for help on using the changeset viewer.