Changeset 970f6e1 in mainline
- Timestamp:
- 2018-01-09T18:25:56Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 4793023
- Parents:
- c386d6d
- Location:
- uspace/drv/hid/usbhid
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/hid/usbhid/generic/hiddev.c
rc386d6d r970f6e1 219 219 bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data) 220 220 { 221 return true; 221 /* Continue polling until the device is about to be removed. */ 222 return !hid_dev->will_deinit; 222 223 } 223 224 -
uspace/drv/hid/usbhid/main.c
rc386d6d r970f6e1 40 40 #include <errno.h> 41 41 #include <str_error.h> 42 #include <fibril_synch.h> 42 43 43 44 #include <usb/dev/driver.h> … … 98 99 /* Delay */ 99 100 -1, 101 /* Callback when the polling fails. */ 102 usb_hid_polling_error_callback, 100 103 /* Callback when the polling ends. */ 101 104 usb_hid_polling_ended_callback, … … 128 131 assert(hid_dev); 129 132 130 /* TODO: Stop device polling prior to deinit. Now it fails on endpoint error. */ 131 133 usb_log_debug2("%s will be removed, setting remove flag.\n", usb_device_get_name(dev)); 134 usb_hid_prepare_deinit(hid_dev); 135 136 return EOK; 137 } 138 139 /** 140 * Callback for when a device has just been from the driver. 141 * 142 * @param dev Structure representing the device. 143 * @return Error code. 144 */ 145 static int usb_hid_device_removed(usb_device_t *dev) 146 { 147 assert(dev); 148 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 149 assert(hid_dev); 150 151 /* Join polling fibril. */ 152 fibril_mutex_lock(&hid_dev->guard); 153 while (hid_dev->running) 154 fibril_condvar_wait(&hid_dev->poll_end, &hid_dev->guard); 155 fibril_mutex_unlock(&hid_dev->guard); 156 157 /* Clean up. */ 132 158 usb_hid_deinit(hid_dev); 133 159 usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev)); 160 134 161 return EOK; 135 162 } … … 165 192 .device_add = usb_hid_device_add, 166 193 .device_remove = usb_hid_device_remove, 194 .device_removed = usb_hid_device_removed, 167 195 .device_gone = usb_hid_device_gone, 168 196 }; -
uspace/drv/hid/usbhid/mouse/mousedev.c
rc386d6d r970f6e1 165 165 } 166 166 167 static boolusb_mouse_process_report(usb_hid_dev_t *hid_dev,167 static void usb_mouse_process_report(usb_hid_dev_t *hid_dev, 168 168 usb_mouse_t *mouse_dev) 169 169 { … … 172 172 if (mouse_dev->mouse_sess == NULL) { 173 173 usb_log_warning(NAME " No console session.\n"); 174 return true;174 return; 175 175 } 176 176 … … 191 191 if (absolute_x != absolute_y) { 192 192 usb_log_error(NAME " cannot handle mix of absolute and relative mouse move."); 193 return true;193 return; 194 194 } 195 195 … … 226 226 if (path == NULL) { 227 227 usb_log_warning("Failed to create USB HID report path.\n"); 228 return true;228 return; 229 229 } 230 230 int ret = … … 233 233 usb_hid_report_path_free(path); 234 234 usb_log_warning("Failed to add buttons to report path.\n"); 235 return true;235 return; 236 236 } 237 237 usb_hid_report_path_set_report_id(path, hid_dev->report_id); … … 266 266 267 267 usb_hid_report_path_free(path); 268 269 return true;270 268 } 271 269 … … 414 412 415 413 usb_mouse_t *mouse_dev = data; 416 417 return usb_mouse_process_report(hid_dev, mouse_dev); 414 usb_mouse_process_report(hid_dev, mouse_dev); 415 416 /* Continue polling until the device is about to be removed. */ 417 return !hid_dev->will_deinit; 418 418 } 419 419 -
uspace/drv/hid/usbhid/usbhid.c
rc386d6d r970f6e1 332 332 * During initialization, the keyboard is switched into boot protocol, the idle 333 333 * rate is set to 0 (infinity), resulting in the keyboard only reporting event 334 * when a key is pressed or released. Finally, the LED lights are turned on 334 * when a key is pressed or released. Finally, the LED lights are turned on 335 335 * according to the default setup of lock keys. 336 336 * 337 * @note By default, the keyboards is initialized with Num Lock turned on and 337 * @note By default, the keyboards is initialized with Num Lock turned on and 338 338 * other locks turned off. 339 339 * … … 354 354 hid_dev->usb_dev = dev; 355 355 hid_dev->poll_pipe_mapping = NULL; 356 357 hid_dev->will_deinit = false; 358 fibril_mutex_initialize(&hid_dev->guard); 359 fibril_condvar_initialize(&hid_dev->poll_end); 356 360 357 361 int rc = usb_hid_check_pipes(hid_dev, dev); … … 492 496 } 493 497 498 bool usb_hid_polling_error_callback(usb_device_t *dev, int err_code, void *arg) 499 { 500 assert(dev); 501 assert(arg); 502 usb_hid_dev_t *hid_dev = arg; 503 504 usb_log_error("Device %s polling error: %s", usb_device_get_name(dev), 505 str_error(err_code)); 506 507 /* Continue polling until the device is about to be removed. */ 508 return hid_dev->running && !hid_dev->will_deinit; 509 } 510 494 511 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg) 495 512 { … … 507 524 508 525 hid_dev->running = false; 526 527 /* Signal polling end to joining thread. */ 528 fibril_mutex_lock(&hid_dev->guard); 529 fibril_condvar_signal(&hid_dev->poll_end); 530 fibril_mutex_unlock(&hid_dev->guard); 509 531 } 510 532 … … 517 539 { 518 540 return hid_dev->report_nr; 541 } 542 543 void usb_hid_prepare_deinit(usb_hid_dev_t *hid_dev) 544 { 545 assert(hid_dev); 546 hid_dev->will_deinit = true; 519 547 } 520 548 … … 524 552 assert(hid_dev->subdrivers != NULL || hid_dev->subdriver_count == 0); 525 553 526 527 usb_log_debug("Subdrivers: %p, subdriver count: %d\n", 554 usb_log_debug("Subdrivers: %p, subdriver count: %d\n", 528 555 hid_dev->subdrivers, hid_dev->subdriver_count); 529 556 … … 541 568 /* Destroy the parser */ 542 569 usb_hid_report_deinit(&hid_dev->report); 543 544 570 } 545 571 -
uspace/drv/hid/usbhid/usbhid.h
rc386d6d r970f6e1 45 45 #include <usb/hid/hid.h> 46 46 #include <stdbool.h> 47 #include <fibril_synch.h> 47 48 48 49 typedef struct usb_hid_dev usb_hid_dev_t; … … 130 131 int report_nr; 131 132 volatile bool running; 133 134 volatile bool will_deinit; 135 fibril_mutex_t guard; 136 fibril_condvar_t poll_end; 132 137 }; 133 138 … … 136 141 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev); 137 142 143 void usb_hid_prepare_deinit(usb_hid_dev_t *hid_dev); 144 138 145 void usb_hid_deinit(usb_hid_dev_t *hid_dev); 139 146 140 147 bool usb_hid_polling_callback(usb_device_t *dev, 141 148 uint8_t *buffer, size_t buffer_size, void *arg); 149 150 bool usb_hid_polling_error_callback(usb_device_t *dev, int err_code, void *arg); 142 151 143 152 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg);
Note:
See TracChangeset
for help on using the changeset viewer.