Changeset 20a3465 in mainline for uspace/drv/bus/usb/usbhid/main.c
- Timestamp:
- 2011-10-30T19:50:54Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3ce78580, 48902fa
- Parents:
- 4c3ad56 (diff), 45bf63c (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/bus/usb/usbhid/main.c
r4c3ad56 r20a3465 46 46 #include "usbhid.h" 47 47 48 /*----------------------------------------------------------------------------*/49 50 48 #define NAME "usbhid" 51 49 … … 67 65 * 68 66 * @param dev Device to add. 69 * 70 * @retval EOK if successful. 71 * @retval ENOMEM if there 72 * @return Other error code inherited from one of functions usb_kbd_init(), 73 * ddf_fun_bind() and ddf_fun_add_to_class(). 67 * @return Error code. 74 68 */ 75 69 static int usb_hid_try_add_device(usb_device_t *dev) 76 70 { 77 71 assert(dev != NULL); 78 79 /* 80 * Initialize device (get and process descriptors, get address, etc.) 81 */ 72 73 /* Initialize device (get and process descriptors, get address, etc.) */ 82 74 usb_log_debug("Initializing USB/HID device...\n"); 83 84 usb_hid_dev_t *hid_dev = usb_hid_new(); 75 76 usb_hid_dev_t *hid_dev = 77 usb_device_data_alloc(dev, sizeof(usb_hid_dev_t)); 85 78 if (hid_dev == NULL) { 86 79 usb_log_error("Error while creating USB/HID device " … … 88 81 return ENOMEM; 89 82 } 90 83 91 84 int rc = usb_hid_init(hid_dev, dev); 92 85 93 86 if (rc != EOK) { 94 87 usb_log_error("Failed to initialize USB/HID device.\n"); 95 usb_hid_de stroy(hid_dev);88 usb_hid_deinit(hid_dev); 96 89 return rc; 97 } 98 90 } 91 99 92 usb_log_debug("USB/HID device structure initialized.\n"); 100 93 101 94 /* 102 95 * 1) subdriver vytvori vlastnu ddf_fun, vlastne ddf_dev_ops, ktore da … … 109 102 * pouzit usb/classes/hid/iface.h - prvy int je telefon 110 103 */ 111 104 112 105 /* Start automated polling function. 113 106 * This will create a separate fibril that will query the device … … 125 118 /* Custom argument. */ 126 119 hid_dev); 127 128 120 129 121 if (rc != EOK) { 130 122 usb_log_error("Failed to start polling fibril for `%s'.\n", 131 123 dev->ddf_dev->name); 124 usb_hid_deinit(hid_dev); 132 125 return rc; 133 126 } 127 hid_dev->running = true; 134 128 135 129 /* … … 138 132 return EOK; 139 133 } 140 141 134 /*----------------------------------------------------------------------------*/ 142 135 /** … … 146 139 * 147 140 * @param dev Structure representing the new device. 148 * 149 * @retval EOK if successful. 150 * @retval EREFUSED if the device is not supported. 141 * @return Error code. 151 142 */ 152 143 static int usb_hid_device_add(usb_device_t *dev) 153 144 { 154 145 usb_log_debug("usb_hid_device_add()\n"); 155 146 156 147 if (dev == NULL) { 157 148 usb_log_warning("Wrong parameter given for add_device().\n"); 158 149 return EINVAL; 159 150 } 160 151 161 152 if (dev->interface_no < 0) { 162 153 usb_log_warning("Device is not a supported HID device.\n"); … … 165 156 return ENOTSUP; 166 157 } 167 158 168 159 int rc = usb_hid_try_add_device(dev); 169 160 170 161 if (rc != EOK) { 171 162 usb_log_warning("Device is not a supported HID device.\n"); … … 174 165 return rc; 175 166 } 176 167 177 168 usb_log_info("HID device `%s' ready to use.\n", dev->ddf_dev->name); 178 169 179 170 return EOK; 180 171 } 181 182 /*----------------------------------------------------------------------------*/ 183 184 /* Currently, the framework supports only device adding. Once the framework 185 * supports unplug, more callbacks will be added. */ 186 static usb_driver_ops_t usb_hid_driver_ops = { 187 .device_add = usb_hid_device_add, 172 /*----------------------------------------------------------------------------*/ 173 /** 174 * Callback for a device about to be removed from the driver. 175 * 176 * @param dev Structure representing the device. 177 * @return Error code. 178 */ 179 static int usb_hid_device_rem(usb_device_t *dev) 180 { 181 return EOK; 182 } 183 /*----------------------------------------------------------------------------*/ 184 /** 185 * Callback for removing a device from the driver. 186 * 187 * @param dev Structure representing the device. 188 * @return Error code. 189 */ 190 static int usb_hid_device_gone(usb_device_t *dev) 191 { 192 usb_hid_dev_t *hid_dev = dev->driver_data; 193 unsigned tries = 10; 194 while (hid_dev->running) { 195 async_usleep(100000); 196 if (!tries--) { 197 usb_log_error("Can't remove hub, still running.\n"); 198 return EBUSY; 199 } 200 } 201 202 assert(!hid_dev->running); 203 usb_hid_deinit(hid_dev); 204 usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name); 205 return EOK; 206 } 207 /*----------------------------------------------------------------------------*/ 208 /** USB generic driver callbacks */ 209 static const usb_driver_ops_t usb_hid_driver_ops = { 210 .device_add = usb_hid_device_add, 211 .device_rem = usb_hid_device_rem, 212 .device_gone = usb_hid_device_gone, 188 213 }; 189 190 191 /* The driver itself. */ 192 static usb_driver_t usb_hid_driver = { 214 /*----------------------------------------------------------------------------*/ 215 /** The driver itself. */ 216 static const usb_driver_t usb_hid_driver = { 193 217 .name = NAME, 194 218 .ops = &usb_hid_driver_ops, 195 219 .endpoints = usb_hid_endpoints 196 220 }; 197 198 /*----------------------------------------------------------------------------*/ 199 221 /*----------------------------------------------------------------------------*/ 200 222 int main(int argc, char *argv[]) 201 223 { … … 206 228 return usb_driver_main(&usb_hid_driver); 207 229 } 208 209 230 /** 210 231 * @}
Note:
See TracChangeset
for help on using the changeset viewer.