Changes in uspace/drv/hid/usbhid/main.c [be01eb3:b7fd2a0] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/hid/usbhid/main.c
rbe01eb3 rb7fd2a0 58 58 static errno_t usb_hid_device_add(usb_device_t *dev) 59 59 { 60 usb_log_debug("%s ", __FUNCTION__);60 usb_log_debug("%s\n", __FUNCTION__); 61 61 62 62 if (dev == NULL) { 63 usb_log_error("Wrong parameter given for add_device(). ");63 usb_log_error("Wrong parameter given for add_device().\n"); 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. ");75 usb_log_error("Failed to create USB/HID device structure.\n"); 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. ");81 usb_log_error("Failed to initialize USB/HID device.\n"); 82 82 usb_hid_deinit(hid_dev); 83 83 return rc; 84 84 } 85 85 86 usb_log_debug("USB/HID device structure initialized. ");86 usb_log_debug("USB/HID device structure initialized.\n"); 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_polling_start(&hid_dev->polling); 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); 92 104 93 105 if (rc != EOK) { 94 usb_log_error("Failed to start polling fibril for `%s'. ",106 usb_log_error("Failed to start polling fibril for `%s'.\n", 95 107 usb_device_get_name(dev)); 96 108 usb_hid_deinit(hid_dev); … … 99 111 hid_dev->running = true; 100 112 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)); 113 usb_log_info("HID device `%s' ready.\n", usb_device_get_name(dev)); 118 114 119 115 return EOK; … … 126 122 * @return Error code. 127 123 */ 128 static errno_t usb_hid_device_rem ove(usb_device_t *dev)124 static errno_t usb_hid_device_rem(usb_device_t *dev) 129 125 { 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); 126 // TODO: Stop device polling 127 // TODO: Call deinit (stops autorepeat too) 128 return ENOTSUP; 136 129 } 137 130 … … 147 140 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 148 141 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 } 149 151 150 usb_log_info("Device %s gone.", usb_device_get_name(dev)); 151 return join_and_clean(dev); 152 usb_hid_deinit(hid_dev); 153 usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev)); 154 return EOK; 152 155 } 153 156 … … 155 158 static const usb_driver_ops_t usb_hid_driver_ops = { 156 159 .device_add = usb_hid_device_add, 157 .device_rem ove = usb_hid_device_remove,160 .device_rem = usb_hid_device_rem, 158 161 .device_gone = usb_hid_device_gone, 159 162 };
Note:
See TracChangeset
for help on using the changeset viewer.