Changeset df6ded8 in mainline for uspace/drv/hid/usbhid/main.c
- Timestamp:
- 2018-02-28T16:37:50Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1b20da0
- Parents:
- f5e5f73 (diff), b2dca8de (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Jakub Jermar <jakub@…> (2018-02-28 16:06:42)
- git-committer:
- Jakub Jermar <jakub@…> (2018-02-28 16:37:50)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/hid/usbhid/main.c
rf5e5f73 rdf6ded8 2 2 * Copyright (c) 2010 Vojtech Horky 3 3 * Copyright (c) 2011 Lubos Slovak 4 * Copyright (c) 2018 Petr Manek, Ondrej Hlavaty 4 5 * All rights reserved. 5 6 * … … 58 59 static errno_t usb_hid_device_add(usb_device_t *dev) 59 60 { 60 usb_log_debug("%s \n", __FUNCTION__);61 usb_log_debug("%s", __FUNCTION__); 61 62 62 63 if (dev == NULL) { 63 usb_log_error("Wrong parameter given for add_device(). \n");64 usb_log_error("Wrong parameter given for add_device()."); 64 65 return EINVAL; 65 66 } … … 73 74 usb_device_data_alloc(dev, sizeof(usb_hid_dev_t)); 74 75 if (hid_dev == NULL) { 75 usb_log_error("Failed to create USB/HID device structure. \n");76 usb_log_error("Failed to create USB/HID device structure."); 76 77 return ENOMEM; 77 78 } … … 79 80 errno_t rc = usb_hid_init(hid_dev, dev); 80 81 if (rc != EOK) { 81 usb_log_error("Failed to initialize USB/HID device. \n");82 usb_log_error("Failed to initialize USB/HID device."); 82 83 usb_hid_deinit(hid_dev); 83 84 return rc; 84 85 } 85 86 86 usb_log_debug("USB/HID device structure initialized. \n");87 usb_log_debug("USB/HID device structure initialized."); 87 88 88 89 /* Start automated polling function. 89 90 * This will create a separate fibril that will query the device 90 91 * 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); 92 rc = usb_polling_start(&hid_dev->polling); 104 93 105 94 if (rc != EOK) { 106 usb_log_error("Failed to start polling fibril for `%s'. \n",95 usb_log_error("Failed to start polling fibril for `%s'.", 107 96 usb_device_get_name(dev)); 108 97 usb_hid_deinit(hid_dev); … … 111 100 hid_dev->running = true; 112 101 113 usb_log_info("HID device `%s' ready.\n", usb_device_get_name(dev)); 102 usb_log_info("HID device `%s' ready.", usb_device_get_name(dev)); 103 104 return EOK; 105 } 106 107 static errno_t join_and_clean(usb_device_t *dev) 108 { 109 assert(dev); 110 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 111 assert(hid_dev); 112 113 /* Join polling fibril (ignoring error code). */ 114 usb_polling_join(&hid_dev->polling); 115 116 /* Clean up. */ 117 usb_hid_deinit(hid_dev); 118 usb_log_info("%s destruction complete.", usb_device_get_name(dev)); 114 119 115 120 return EOK; … … 122 127 * @return Error code. 123 128 */ 124 static errno_t usb_hid_device_rem (usb_device_t *dev)129 static errno_t usb_hid_device_remove(usb_device_t *dev) 125 130 { 126 // TODO: Stop device polling 127 // TODO: Call deinit (stops autorepeat too) 128 return ENOTSUP; 131 assert(dev); 132 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 133 assert(hid_dev); 134 135 usb_log_info("Device %s removed.", usb_device_get_name(dev)); 136 return join_and_clean(dev); 129 137 } 130 138 … … 140 148 usb_hid_dev_t *hid_dev = usb_device_data_get(dev); 141 149 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 150 152 usb_hid_deinit(hid_dev); 153 usb_log_debug2("%s destruction complete.\n", usb_device_get_name(dev)); 154 return EOK; 151 usb_log_info("Device %s gone.", usb_device_get_name(dev)); 152 return join_and_clean(dev); 155 153 } 156 154 … … 158 156 static const usb_driver_ops_t usb_hid_driver_ops = { 159 157 .device_add = usb_hid_device_add, 160 .device_rem = usb_hid_device_rem,158 .device_remove = usb_hid_device_remove, 161 159 .device_gone = usb_hid_device_gone, 162 160 };
Note:
See TracChangeset
for help on using the changeset viewer.