Changes in uspace/drv/hid/usbhid/main.c [b7fd2a0:be01eb3] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/hid/usbhid/main.c
rb7fd2a0 rbe01eb3 58 58 static errno_t usb_hid_device_add(usb_device_t *dev) 59 59 { 60 usb_log_debug("%s \n", __FUNCTION__);60 usb_log_debug("%s", __FUNCTION__); 61 61 62 62 if (dev == NULL) { 63 usb_log_error("Wrong parameter given for add_device(). \n");63 usb_log_error("Wrong parameter given for add_device()."); 64 64 return EINVAL; 65 65 } … … 73 73 usb_device_data_alloc(dev, sizeof(usb_hid_dev_t)); 74 74 if (hid_dev == NULL) { 75 usb_log_error("Failed to create USB/HID device structure. \n");75 usb_log_error("Failed to create USB/HID device structure."); 76 76 return ENOMEM; 77 77 } … … 79 79 errno_t rc = usb_hid_init(hid_dev, dev); 80 80 if (rc != EOK) { 81 usb_log_error("Failed to initialize USB/HID device. \n");81 usb_log_error("Failed to initialize USB/HID device."); 82 82 usb_hid_deinit(hid_dev); 83 83 return rc; 84 84 } 85 85 86 usb_log_debug("USB/HID device structure initialized. \n");86 usb_log_debug("USB/HID device structure initialized."); 87 87 88 88 /* Start automated polling function. 89 89 * This will create a separate fibril that will query the device 90 90 * for the data continuously. */ 91 rc = usb_device_auto_poll_desc(dev, 92 /* Index of the polling pipe. */ 93 hid_dev->poll_pipe_mapping->description, 94 /* Callback when data arrives. */ 95 usb_hid_polling_callback, 96 /* How much data to request. */ 97 hid_dev->poll_pipe_mapping->pipe.max_packet_size, 98 /* Delay */ 99 -1, 100 /* Callback when the polling ends. */ 101 usb_hid_polling_ended_callback, 102 /* Custom argument. */ 103 hid_dev); 91 rc = usb_polling_start(&hid_dev->polling); 104 92 105 93 if (rc != EOK) { 106 usb_log_error("Failed to start polling fibril for `%s'. \n",94 usb_log_error("Failed to start polling fibril for `%s'.", 107 95 usb_device_get_name(dev)); 108 96 usb_hid_deinit(hid_dev); … … 111 99 hid_dev->running = true; 112 100 113 usb_log_info("HID device `%s' ready.\n", usb_device_get_name(dev)); 101 usb_log_info("HID device `%s' ready.", usb_device_get_name(dev)); 102 103 return EOK; 104 } 105 106 static errno_t join_and_clean(usb_device_t *dev) 107 { 108 assert(dev); 109 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 110 assert(hid_dev); 111 112 /* Join polling fibril (ignoring error code). */ 113 usb_polling_join(&hid_dev->polling); 114 115 /* Clean up. */ 116 usb_hid_deinit(hid_dev); 117 usb_log_info("%s destruction complete.", usb_device_get_name(dev)); 114 118 115 119 return EOK; … … 122 126 * @return Error code. 123 127 */ 124 static errno_t usb_hid_device_rem (usb_device_t *dev)128 static errno_t usb_hid_device_remove(usb_device_t *dev) 125 129 { 126 // TODO: Stop device polling 127 // TODO: Call deinit (stops autorepeat too) 128 return ENOTSUP; 130 assert(dev); 131 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 132 assert(hid_dev); 133 134 usb_log_info("Device %s removed.", usb_device_get_name(dev)); 135 return join_and_clean(dev); 129 136 } 130 137 … … 140 147 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 141 148 assert(hid_dev); 142 unsigned tries = 100;143 /* Wait for fail. */144 while (hid_dev->running && tries--) {145 async_usleep(100000);146 }147 if (hid_dev->running) {148 usb_log_error("Can't remove hid, still running.\n");149 return EBUSY;150 }151 149 152 usb_hid_deinit(hid_dev); 153 usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev)); 154 return EOK; 150 usb_log_info("Device %s gone.", usb_device_get_name(dev)); 151 return join_and_clean(dev); 155 152 } 156 153 … … 158 155 static const usb_driver_ops_t usb_hid_driver_ops = { 159 156 .device_add = usb_hid_device_add, 160 .device_rem = usb_hid_device_rem,157 .device_remove = usb_hid_device_remove, 161 158 .device_gone = usb_hid_device_gone, 162 159 };
Note:
See TracChangeset
for help on using the changeset viewer.