Changes in / [1f131fb9:98fb010] in mainline
- Location:
- uspace
- Files:
-
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/mkbd/main.c
r1f131fb9 r98fb010 69 69 int rc = usb_hid_report_init(*report); 70 70 if (rc != EOK) { 71 usb_hid_ report_deinit(*report);71 usb_hid_free_report(*report); 72 72 *report = NULL; 73 73 return rc; … … 79 79 &report_desc_size); 80 80 if (rc != EOK) { 81 usb_hid_ report_deinit(*report);81 usb_hid_free_report(*report); 82 82 *report = NULL; 83 83 return rc; … … 85 85 86 86 if (report_desc_size == 0) { 87 usb_hid_ report_deinit(*report);87 usb_hid_free_report(*report); 88 88 *report = NULL; 89 89 // TODO: other error code? … … 93 93 uint8_t *desc = (uint8_t *) malloc(report_desc_size); 94 94 if (desc == NULL) { 95 usb_hid_ report_deinit(*report);95 usb_hid_free_report(*report); 96 96 *report = NULL; 97 97 return ENOMEM; … … 103 103 &actual_size); 104 104 if (rc != EOK) { 105 usb_hid_ report_deinit(*report);105 usb_hid_free_report(*report); 106 106 *report = NULL; 107 107 free(desc); … … 110 110 111 111 if (actual_size != report_desc_size) { 112 usb_hid_ report_deinit(*report);112 usb_hid_free_report(*report); 113 113 *report = NULL; 114 114 free(desc); -
uspace/app/usbinfo/hid.c
r1f131fb9 r98fb010 167 167 168 168 free(raw_report); 169 usb_hid_ report_deinit(&report);169 usb_hid_free_report(&report); 170 170 } 171 171 -
uspace/drv/bus/usb/usbhid/generic/hiddev.c
r1f131fb9 r98fb010 48 48 /*----------------------------------------------------------------------------*/ 49 49 50 constusb_endpoint_description_t usb_hid_generic_poll_endpoint_description = {50 usb_endpoint_description_t usb_hid_generic_poll_endpoint_description = { 51 51 .transfer_type = USB_TRANSFER_INTERRUPT, 52 52 .direction = USB_DIRECTION_IN, -
uspace/drv/bus/usb/usbhid/generic/hiddev.h
r1f131fb9 r98fb010 41 41 struct usb_hid_dev; 42 42 43 extern const usb_endpoint_description_t 44 usb_hid_generic_poll_endpoint_description; 43 usb_endpoint_description_t usb_hid_generic_poll_endpoint_description; 45 44 46 45 const char *HID_GENERIC_FUN_NAME; -
uspace/drv/bus/usb/usbhid/kbd/kbddev.c
r1f131fb9 r98fb010 88 88 89 89 /** Keyboard polling endpoint description for boot protocol class. */ 90 constusb_endpoint_description_t usb_hid_kbd_poll_endpoint_description = {90 usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description = { 91 91 .transfer_type = USB_TRANSFER_INTERRUPT, 92 92 .direction = USB_DIRECTION_IN, … … 237 237 238 238 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 239 &hid_dev->report, NULL, kbd_dev->led_path,239 hid_dev->report, NULL, kbd_dev->led_path, 240 240 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 241 241 USB_HID_REPORT_TYPE_OUTPUT); 242 242 243 243 while (field != NULL) { 244 245 if ((field->usage == USB_HID_LED_NUM_LOCK) 244 245 if ((field->usage == USB_HID_LED_NUM_LOCK) 246 246 && (kbd_dev->mods & KM_NUM_LOCK)){ 247 247 field->value = 1; 248 248 } 249 249 250 if ((field->usage == USB_HID_LED_CAPS_LOCK) 250 if ((field->usage == USB_HID_LED_CAPS_LOCK) 251 251 && (kbd_dev->mods & KM_CAPS_LOCK)){ 252 252 field->value = 1; 253 253 } 254 254 255 if ((field->usage == USB_HID_LED_SCROLL_LOCK) 255 if ((field->usage == USB_HID_LED_SCROLL_LOCK) 256 256 && (kbd_dev->mods & KM_SCROLL_LOCK)){ 257 257 field->value = 1; 258 258 } 259 260 field = usb_hid_report_get_sibling( 261 &hid_dev->report, field, kbd_dev->led_path,262 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,263 259 260 field = usb_hid_report_get_sibling(hid_dev->report, field, 261 kbd_dev->led_path, 262 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 263 USB_HID_REPORT_TYPE_OUTPUT); 264 264 } 265 265 266 266 // TODO: what about the Report ID? 267 int rc = usb_hid_report_output_translate( &hid_dev->report, 0,267 int rc = usb_hid_report_output_translate(hid_dev->report, 0, 268 268 kbd_dev->output_buffer, kbd_dev->output_size); 269 269 … … 432 432 static void usb_kbd_process_data(usb_hid_dev_t *hid_dev, usb_kbd_t *kbd_dev) 433 433 { 434 assert(hid_dev->report != NULL); 434 435 assert(hid_dev != NULL); 435 436 assert(kbd_dev != NULL); … … 443 444 444 445 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 445 &hid_dev->report, NULL, path,446 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 446 hid_dev->report, NULL, path, 447 USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 447 448 USB_HID_REPORT_TYPE_INPUT); 448 449 unsigned i = 0; … … 453 454 454 455 assert(i < kbd_dev->key_count); 455 456 456 457 // save the key usage 457 458 if (field->value != 0) { … … 462 463 } 463 464 usb_log_debug2("Saved %u. key usage %d\n", i, kbd_dev->keys[i]); 464 465 465 466 ++i; 466 field = usb_hid_report_get_sibling( 467 &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END468 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,467 field = usb_hid_report_get_sibling(hid_dev->report, field, path, 468 USB_HID_PATH_COMPARE_END 469 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 469 470 USB_HID_REPORT_TYPE_INPUT); 470 471 } … … 615 616 616 617 kbd_dev->key_count = usb_hid_report_size( 617 &hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT);618 hid_dev->report, 0, USB_HID_REPORT_TYPE_INPUT); 618 619 usb_hid_report_path_free(path); 619 620 620 621 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 621 622 622 kbd_dev->keys = calloc(kbd_dev->key_count, sizeof(int32_t));623 kbd_dev->keys = (int32_t *)calloc(kbd_dev->key_count, sizeof(int32_t)); 623 624 624 625 if (kbd_dev->keys == NULL) { … … 642 643 */ 643 644 kbd_dev->output_size = 0; 644 kbd_dev->output_buffer = usb_hid_report_output( &hid_dev->report,645 kbd_dev->output_buffer = usb_hid_report_output(hid_dev->report, 645 646 &kbd_dev->output_size, 0); 646 647 if (kbd_dev->output_buffer == NULL) { … … 656 657 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 657 658 658 kbd_dev->led_output_size = usb_hid_report_size( 659 &hid_dev->report,0, USB_HID_REPORT_TYPE_OUTPUT);659 kbd_dev->led_output_size = usb_hid_report_size(hid_dev->report, 660 0, USB_HID_REPORT_TYPE_OUTPUT); 660 661 661 662 usb_log_debug("Output report size (in items): %zu\n", … … 825 826 int usb_kbd_set_boot_protocol(usb_hid_dev_t *hid_dev) 826 827 { 827 int rc = usb_hid_parse_report_descriptor( 828 &hid_dev->report, USB_KBD_BOOT_REPORT_DESCRIPTOR,828 int rc = usb_hid_parse_report_descriptor(hid_dev->report, 829 USB_KBD_BOOT_REPORT_DESCRIPTOR, 829 830 USB_KBD_BOOT_REPORT_DESCRIPTOR_SIZE); 830 831 … … 835 836 } 836 837 837 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 838 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 838 839 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 839 840 -
uspace/drv/bus/usb/usbhid/kbd/kbddev.h
r1f131fb9 r98fb010 118 118 /*----------------------------------------------------------------------------*/ 119 119 120 extern constusb_endpoint_description_t usb_hid_kbd_poll_endpoint_description;120 usb_endpoint_description_t usb_hid_kbd_poll_endpoint_description; 121 121 122 122 const char *HID_KBD_FUN_NAME; -
uspace/drv/bus/usb/usbhid/main.c
r1f131fb9 r98fb010 92 92 if (rc != EOK) { 93 93 usb_log_error("Failed to initialize USB/HID device.\n"); 94 usb_hid_de init(hid_dev);94 usb_hid_destroy(hid_dev); 95 95 return rc; 96 96 } … … 128 128 usb_log_error("Failed to start polling fibril for `%s'.\n", 129 129 dev->ddf_dev->name); 130 usb_hid_de init(hid_dev);130 usb_hid_destroy(hid_dev); 131 131 return rc; 132 132 } 133 133 hid_dev->running = true; 134 dev->driver_data = hid_dev; 134 135 135 136 /* … … 203 204 204 205 assert(!hid_dev->running); 205 usb_hid_de init(hid_dev);206 usb_hid_destroy(hid_dev); 206 207 usb_log_debug2("%s destruction complete.\n", dev->ddf_dev->name); 207 208 return EOK; -
uspace/drv/bus/usb/usbhid/mouse/mousedev.c
r1f131fb9 r98fb010 59 59 /*----------------------------------------------------------------------------*/ 60 60 61 constusb_endpoint_description_t usb_hid_mouse_poll_endpoint_description = {61 usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description = { 62 62 .transfer_type = USB_TRANSFER_INTERRUPT, 63 63 .direction = USB_DIRECTION_IN, … … 268 268 269 269 int shift_x = get_mouse_axis_move_value(hid_dev->report_id, 270 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X);270 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_X); 271 271 int shift_y = get_mouse_axis_move_value(hid_dev->report_id, 272 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y);272 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_Y); 273 273 int wheel = get_mouse_axis_move_value(hid_dev->report_id, 274 &hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL);274 hid_dev->report, USB_HIDUT_USAGE_GENERIC_DESKTOP_WHEEL); 275 275 276 276 if ((shift_x != 0) || (shift_y != 0)) { 277 async_exch_t *exch = 278 async_exchange_begin(mouse_dev->mouse_sess); 277 async_exch_t *exch = async_exchange_begin(mouse_dev->mouse_sess); 279 278 async_req_2_0(exch, MOUSEEV_MOVE_EVENT, shift_x, shift_y); 280 279 async_exchange_end(exch); … … 292 291 293 292 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 294 &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 295 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, USB_HID_REPORT_TYPE_INPUT); 293 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 294 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 295 USB_HID_REPORT_TYPE_INPUT); 296 296 297 297 while (field != NULL) { … … 314 314 async_req_2_0(exch, MOUSEEV_BUTTON_EVENT, field->usage, 0); 315 315 async_exchange_end(exch); 316 316 317 317 mouse_dev->buttons[field->usage - field->usage_minimum] = 318 318 field->value; 319 319 } 320 320 321 321 field = usb_hid_report_get_sibling( 322 &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END323 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 322 hid_dev->report, field, path, USB_HID_PATH_COMPARE_END 323 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 324 324 USB_HID_REPORT_TYPE_INPUT); 325 325 } … … 474 474 // that the current solution is good enough. 475 475 /* Adding 1 because we will be accessing buttons[highest]. */ 476 mouse_dev->buttons_count = 1 + usb_mouse_get_highest_button(477 &hid_dev->report, hid_dev->report_id);476 mouse_dev->buttons_count = usb_mouse_get_highest_button(hid_dev->report, 477 hid_dev->report_id) + 1; 478 478 mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t)); 479 479 … … 532 532 int usb_mouse_set_boot_protocol(usb_hid_dev_t *hid_dev) 533 533 { 534 int rc = usb_hid_parse_report_descriptor( 535 &hid_dev->report, USB_MOUSE_BOOT_REPORT_DESCRIPTOR,534 int rc = usb_hid_parse_report_descriptor(hid_dev->report, 535 USB_MOUSE_BOOT_REPORT_DESCRIPTOR, 536 536 USB_MOUSE_BOOT_REPORT_DESCRIPTOR_SIZE); 537 537 … … 542 542 } 543 543 544 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 544 rc = usbhid_req_set_protocol(&hid_dev->usb_dev->ctrl_pipe, 545 545 hid_dev->usb_dev->interface_no, USB_HID_PROTOCOL_BOOT); 546 546 -
uspace/drv/bus/usb/usbhid/mouse/mousedev.h
r1f131fb9 r98fb010 63 63 /*----------------------------------------------------------------------------*/ 64 64 65 extern constusb_endpoint_description_t usb_hid_mouse_poll_endpoint_description;65 usb_endpoint_description_t usb_hid_mouse_poll_endpoint_description; 66 66 67 67 const char *HID_MOUSE_FUN_NAME; -
uspace/drv/bus/usb/usbhid/multimedia/multimedia.c
r1f131fb9 r98fb010 161 161 /*----------------------------------------------------------------------------*/ 162 162 163 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data) 164 { 165 if (hid_dev == NULL || hid_dev->usb_dev == NULL) { 166 return EINVAL; /*! @todo Other return code? */ 167 } 168 169 usb_log_debug(NAME " Initializing HID/multimedia structure...\n"); 170 163 static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev, 164 usb_multimedia_t *multim_dev) 165 { 171 166 /* Create the exposed function. */ 172 ddf_fun_t *fun = ddf_fun_create( 173 hid_dev->usb_dev->ddf_dev, fun_exposed,NAME);167 ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed, 168 NAME); 174 169 if (fun == NULL) { 175 170 usb_log_error("Could not create DDF function node.\n"); … … 178 173 179 174 fun->ops = &multimedia_ops; 180 181 usb_multimedia_t *multim_dev = 182 ddf_fun_data_alloc(fun, sizeof(usb_multimedia_t)); 183 if (multim_dev == NULL) { 184 ddf_fun_destroy(fun); 185 return ENOMEM; 186 } 187 188 multim_dev->console_sess = NULL; 189 multim_dev->fun = fun; 190 191 //todo Autorepeat? 175 fun->driver_data = multim_dev; // TODO: maybe change to hid_dev->data 192 176 193 177 int rc = ddf_fun_bind(fun); … … 210 194 return rc; 211 195 } 212 213 /* Save the KBD device structure into the HID device structure. */ 196 multim_dev->fun = fun; 197 198 return EOK; 199 } 200 201 /*----------------------------------------------------------------------------*/ 202 203 int usb_multimedia_init(struct usb_hid_dev *hid_dev, void **data) 204 { 205 if (hid_dev == NULL || hid_dev->usb_dev == NULL) { 206 return EINVAL; /*! @todo Other return code? */ 207 } 208 209 usb_log_debug(NAME " Initializing HID/multimedia structure...\n"); 210 211 usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc( 212 sizeof(usb_multimedia_t)); 213 if (multim_dev == NULL) { 214 return ENOMEM; 215 } 216 217 multim_dev->console_sess = NULL; 218 219 /*! @todo Autorepeat */ 220 221 // save the KBD device structure into the HID device structure 214 222 *data = multim_dev; 215 223 224 usb_log_debug(NAME " HID/multimedia device structure initialized.\n"); 225 226 int rc = usb_multimedia_create_function(hid_dev, multim_dev); 227 if (rc != EOK) 228 return rc; 229 216 230 usb_log_debug(NAME " HID/multimedia structure initialized.\n"); 231 217 232 return EOK; 218 233 } … … 257 272 258 273 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 259 &hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END260 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 274 hid_dev->report, NULL, path, USB_HID_PATH_COMPARE_END 275 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 261 276 USB_HID_REPORT_TYPE_INPUT); 262 277 … … 278 293 279 294 field = usb_hid_report_get_sibling( 280 &hid_dev->report, field, path, USB_HID_PATH_COMPARE_END295 hid_dev->report, field, path, USB_HID_PATH_COMPARE_END 281 296 | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY, 282 297 USB_HID_REPORT_TYPE_INPUT); -
uspace/drv/bus/usb/usbhid/subdrivers.c
r1f131fb9 r98fb010 42 42 #include "generic/hiddev.h" 43 43 44 static constusb_hid_subdriver_usage_t path_kbd[] = {45 {USB_HIDUT_PAGE_GENERIC_DESKTOP, 46 USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD}, 44 static usb_hid_subdriver_usage_t path_kbd[] = { 45 {USB_HIDUT_PAGE_GENERIC_DESKTOP, 46 USB_HIDUT_USAGE_GENERIC_DESKTOP_KEYBOARD}, 47 47 {0, 0} 48 48 }; 49 49 50 static constusb_hid_subdriver_usage_t path_mouse[] = {50 static usb_hid_subdriver_usage_t path_mouse[] = { 51 51 {USB_HIDUT_PAGE_GENERIC_DESKTOP, USB_HIDUT_USAGE_GENERIC_DESKTOP_MOUSE}, 52 52 {0, 0} 53 53 }; 54 54 55 static constusb_hid_subdriver_usage_t multim_key_path[] = {55 static usb_hid_subdriver_usage_t multim_key_path[] = { 56 56 {USB_HIDUT_PAGE_CONSUMER, USB_HIDUT_USAGE_CONSUMER_CONSUMER_CONTROL}, 57 57 {0, 0} … … 71 71 .poll_end = NULL 72 72 }, 73 73 74 }, 74 75 { … … 101 102 }; 102 103 103 const int USB_HID_MAX_SUBDRIVERS =104 sizeof(usb_hid_subdrivers) / sizeof(usb_hid_subdrivers[0]);105 106 104 /** 107 105 * @} -
uspace/drv/bus/usb/usbhid/subdrivers.h
r1f131fb9 r98fb010 78 78 79 79 /** Subdriver for controlling this device. */ 80 constusb_hid_subdriver_t subdriver;80 usb_hid_subdriver_t subdriver; 81 81 } usb_hid_subdriver_mapping_t; 82 82 … … 84 84 85 85 extern const usb_hid_subdriver_mapping_t usb_hid_subdrivers[]; 86 extern const int USB_HID_MAX_SUBDRIVERS;87 86 88 87 /*----------------------------------------------------------------------------*/ -
uspace/drv/bus/usb/usbhid/usbhid.c
r1f131fb9 r98fb010 54 54 55 55 /* Array of endpoints expected on the device, NULL terminated. */ 56 constusb_endpoint_description_t *usb_hid_endpoints[] = {56 usb_endpoint_description_t *usb_hid_endpoints[] = { 57 57 &usb_hid_kbd_poll_endpoint_description, 58 58 &usb_hid_mouse_poll_endpoint_description, … … 61 61 }; 62 62 63 static const int USB_HID_MAX_SUBDRIVERS = 10; 64 63 65 /*----------------------------------------------------------------------------*/ 64 66 65 67 static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev) 66 68 { 67 assert(hid_dev != NULL );68 assert(hid_dev->subdriver_count == 0); 69 70 hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t));69 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 70 71 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 72 sizeof(usb_hid_subdriver_t)); 71 73 if (hid_dev->subdrivers == NULL) { 72 74 return ENOMEM; 73 75 } 74 hid_dev->subdriver_count = 1; 75 // TODO 0 should be keyboard, but find a better way 76 hid_dev->subdrivers[0] = usb_hid_subdrivers[0].subdriver; 76 77 assert(hid_dev->subdriver_count >= 0); 78 79 // set the init callback 80 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_kbd_init; 81 82 // set the polling callback 83 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 84 usb_kbd_polling_callback; 85 86 // set the polling ended callback 87 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 88 89 // set the deinit callback 90 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_kbd_deinit; 91 92 // set subdriver count 93 ++hid_dev->subdriver_count; 77 94 78 95 return EOK; … … 83 100 static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev) 84 101 { 85 assert(hid_dev != NULL );86 assert(hid_dev->subdriver_count == 0); 87 88 hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t));102 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 103 104 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 105 sizeof(usb_hid_subdriver_t)); 89 106 if (hid_dev->subdrivers == NULL) { 90 107 return ENOMEM; 91 108 } 92 hid_dev->subdriver_count = 1; 93 // TODO 2 should be mouse, but find a better way 94 hid_dev->subdrivers[2] = usb_hid_subdrivers[0].subdriver; 109 110 assert(hid_dev->subdriver_count >= 0); 111 112 // set the init callback 113 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_mouse_init; 114 115 // set the polling callback 116 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 117 usb_mouse_polling_callback; 118 119 // set the polling ended callback 120 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 121 122 // set the deinit callback 123 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_mouse_deinit; 124 125 // set subdriver count 126 ++hid_dev->subdriver_count; 95 127 96 128 return EOK; … … 103 135 assert(hid_dev != NULL && hid_dev->subdriver_count == 0); 104 136 105 hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t)); 137 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc( 138 sizeof(usb_hid_subdriver_t)); 106 139 if (hid_dev->subdrivers == NULL) { 107 140 return ENOMEM; 108 141 } 109 hid_dev->subdriver_count = 1; 110 111 /* Set generic hid subdriver routines */ 112 hid_dev->subdrivers[0].init = usb_generic_hid_init; 113 hid_dev->subdrivers[0].poll = usb_generic_hid_polling_callback; 114 hid_dev->subdrivers[0].poll_end = NULL; 115 hid_dev->subdrivers[0].deinit = usb_generic_hid_deinit; 142 143 assert(hid_dev->subdriver_count >= 0); 144 145 // set the init callback 146 hid_dev->subdrivers[hid_dev->subdriver_count].init = 147 usb_generic_hid_init; 148 149 // set the polling callback 150 hid_dev->subdrivers[hid_dev->subdriver_count].poll = 151 usb_generic_hid_polling_callback; 152 153 // set the polling ended callback 154 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL; 155 156 // set the deinit callback 157 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = 158 usb_generic_hid_deinit; 159 160 // set subdriver count 161 ++hid_dev->subdriver_count; 116 162 117 163 return EOK; … … 120 166 /*----------------------------------------------------------------------------*/ 121 167 122 static bool usb_hid_ids_match( const usb_hid_dev_t *hid_dev,168 static bool usb_hid_ids_match(usb_hid_dev_t *hid_dev, 123 169 const usb_hid_subdriver_mapping_t *mapping) 124 170 { … … 126 172 assert(hid_dev->usb_dev != NULL); 127 173 128 return (hid_dev->usb_dev->descriptors.device.vendor_id 174 return (hid_dev->usb_dev->descriptors.device.vendor_id 129 175 == mapping->vendor_id 130 176 && hid_dev->usb_dev->descriptors.device.product_id … … 134 180 /*----------------------------------------------------------------------------*/ 135 181 136 static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev, 182 static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev, 137 183 const usb_hid_subdriver_mapping_t *mapping) 138 184 { … … 146 192 } 147 193 int i = 0; 148 while (mapping->usage_path[i].usage != 0 194 while (mapping->usage_path[i].usage != 0 149 195 || mapping->usage_path[i].usage_page != 0) { 150 if (usb_hid_report_path_append_item(usage_path, 151 mapping->usage_path[i].usage_page, 196 if (usb_hid_report_path_append_item(usage_path, 197 mapping->usage_path[i].usage_page, 152 198 mapping->usage_path[i].usage) != EOK) { 153 199 usb_log_debug("Failed to append to usage path.\n"); … … 158 204 } 159 205 206 assert(hid_dev->report != NULL); 207 160 208 usb_log_debug("Compare flags: %d\n", mapping->compare); 161 209 … … 165 213 do { 166 214 usb_log_debug("Trying report id %u\n", report_id); 167 215 168 216 if (report_id != 0) { 169 217 usb_hid_report_path_set_report_id(usage_path, … … 172 220 173 221 usb_hid_report_field_t *field = usb_hid_report_get_sibling( 174 &hid_dev->report, NULL, usage_path, mapping->compare, 222 hid_dev->report, 223 NULL, usage_path, mapping->compare, 175 224 USB_HID_REPORT_TYPE_INPUT); 176 225 177 226 usb_log_debug("Field: %p\n", field); 178 227 … … 181 230 break; 182 231 } 183 232 184 233 report_id = usb_hid_get_next_report_id( 185 &hid_dev->report, report_id, USB_HID_REPORT_TYPE_INPUT); 234 hid_dev->report, report_id, 235 USB_HID_REPORT_TYPE_INPUT); 186 236 } while (!matches && report_id != 0); 187 237 … … 193 243 /*----------------------------------------------------------------------------*/ 194 244 195 static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev, 245 static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev, 196 246 const usb_hid_subdriver_t **subdrivers, int count) 197 247 { … … 204 254 } 205 255 206 /* +1 for generic hid subdriver */ 207 hid_dev->subdrivers = calloc((count + 1), sizeof(usb_hid_subdriver_t)); 256 // add one generic HID subdriver per device 257 258 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) * 259 sizeof(usb_hid_subdriver_t)); 208 260 if (hid_dev->subdrivers == NULL) { 209 261 return ENOMEM; … … 217 269 } 218 270 219 /* Add one generic HID subdriver per device */220 271 hid_dev->subdrivers[count].init = usb_generic_hid_init; 221 272 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback; … … 256 307 return EINVAL; 257 308 } 258 309 259 310 ids_matched = false; 260 311 matched = false; 261 312 262 313 if (mapping->vendor_id >= 0) { 263 314 assert(mapping->product_id >= 0); … … 270 321 } 271 322 } 272 323 273 324 if (mapping->usage_path != NULL) { 274 325 usb_log_debug("Comparing device against usage path.\n"); … … 281 332 matched = ids_matched; 282 333 } 283 334 284 335 if (matched) { 285 336 usb_log_debug("Subdriver matched.\n"); 286 337 subdrivers[count++] = &mapping->subdriver; 287 338 } 288 339 289 340 mapping = &usb_hid_subdrivers[++i]; 290 341 } 291 342 292 /* We have all subdrivers determined, save them into the hid device */ 293 // TODO Dowe really need this complicated stuff if there is 294 // max_subdrivers limitation? 343 // we have all subdrivers determined, save them into the hid device 295 344 return usb_hid_save_subdrivers(hid_dev, subdrivers, count); 296 345 } … … 298 347 /*----------------------------------------------------------------------------*/ 299 348 300 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, const usb_device_t *dev) 301 { 302 assert(hid_dev); 303 assert(dev); 349 static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev) 350 { 351 assert(hid_dev != NULL && dev != NULL); 352 353 int rc = EOK; 304 354 305 355 if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) { … … 318 368 usb_log_error("None of supported endpoints found - probably" 319 369 " not a supported device.\n"); 320 r eturnENOTSUP;321 } 322 323 return EOK;370 rc = ENOTSUP; 371 } 372 373 return rc; 324 374 } 325 375 … … 328 378 static int usb_hid_init_report(usb_hid_dev_t *hid_dev) 329 379 { 330 assert(hid_dev != NULL );380 assert(hid_dev != NULL && hid_dev->report != NULL); 331 381 332 382 uint8_t report_id = 0; 383 size_t size; 384 333 385 size_t max_size = 0; 334 386 335 387 do { 336 388 usb_log_debug("Getting size of the report.\n"); 337 const size_t size = 338 usb_hid_report_byte_size(&hid_dev->report, report_id, 339 USB_HID_REPORT_TYPE_INPUT); 389 size = usb_hid_report_byte_size(hid_dev->report, report_id, 390 USB_HID_REPORT_TYPE_INPUT); 340 391 usb_log_debug("Report ID: %u, size: %zu\n", report_id, size); 341 392 max_size = (size > max_size) ? size : max_size; 342 393 usb_log_debug("Getting next report ID\n"); 343 report_id = usb_hid_get_next_report_id( &hid_dev->report,394 report_id = usb_hid_get_next_report_id(hid_dev->report, 344 395 report_id, USB_HID_REPORT_TYPE_INPUT); 345 396 } while (report_id != 0); … … 347 398 usb_log_debug("Max size of input report: %zu\n", max_size); 348 399 400 hid_dev->max_input_report_size = max_size; 349 401 assert(hid_dev->input_report == NULL); 350 402 351 hid_dev->input_report = calloc(1,max_size);403 hid_dev->input_report = malloc(max_size); 352 404 if (hid_dev->input_report == NULL) { 353 405 return ENOMEM; 354 406 } 355 hid_dev->max_input_report_size = max_size;407 memset(hid_dev->input_report, 0, max_size); 356 408 357 409 return EOK; … … 378 430 } 379 431 380 usb_hid_report_init(&hid_dev->report); 432 hid_dev->report = (usb_hid_report_t *)(malloc(sizeof( 433 usb_hid_report_t))); 434 if (hid_dev->report == NULL) { 435 usb_log_error("No memory!\n"); 436 return ENOMEM; 437 } 438 usb_hid_report_init(hid_dev->report); 381 439 382 440 /* The USB device should already be initialized, save it in structure */ … … 388 446 return rc; 389 447 } 390 448 391 449 /* Get the report descriptor and parse it. */ 392 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 393 &hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);450 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev, 451 hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size); 394 452 395 453 bool fallback = false; … … 430 488 break; 431 489 default: 432 assert(hid_dev->poll_pipe_index 490 assert(hid_dev->poll_pipe_index 433 491 == USB_HID_GENERIC_POLL_EP_NO); 434 492 435 493 usb_log_info("Falling back to generic HID driver.\n"); 436 494 rc = usb_hid_set_generic_hid_subdriver(hid_dev); … … 441 499 usb_log_error("No subdriver for handling this device could be" 442 500 " initialized: %s.\n", str_error(rc)); 443 usb_log_debug("Subdriver count: %d\n", 501 usb_log_debug("Subdriver count: %d\n", 444 502 hid_dev->subdriver_count); 503 445 504 } else { 446 505 bool ok = false; 447 448 usb_log_debug("Subdriver count: %d\n", 506 507 usb_log_debug("Subdriver count: %d\n", 449 508 hid_dev->subdriver_count); 450 509 451 510 for (i = 0; i < hid_dev->subdriver_count; ++i) { 452 511 if (hid_dev->subdrivers[i].init != NULL) { … … 465 524 } 466 525 } 467 526 468 527 rc = (ok) ? EOK : -1; // what error to report 469 528 } … … 479 538 } 480 539 540 481 541 return rc; 482 542 } … … 484 544 /*----------------------------------------------------------------------------*/ 485 545 486 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 546 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 487 547 size_t buffer_size, void *arg) 488 548 { 549 int i; 550 489 551 if (dev == NULL || arg == NULL || buffer == NULL) { 490 552 usb_log_error("Missing arguments to polling callback.\n"); 491 553 return false; 492 554 } 493 usb_hid_dev_t *hid_dev = arg; 555 556 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 494 557 495 558 assert(hid_dev->input_report != NULL); 496 497 559 usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size, 498 560 hid_dev->max_input_report_size, … … 506 568 } 507 569 508 /* Parse the input report */ 509 const int rc = usb_hid_parse_report( 510 &hid_dev->report, buffer, buffer_size, &hid_dev->report_id); 570 // parse the input report 571 572 int rc = usb_hid_parse_report(hid_dev->report, buffer, buffer_size, 573 &hid_dev->report_id); 574 511 575 if (rc != EOK) { 512 576 usb_log_warning("Error in usb_hid_parse_report():" 513 577 "%s\n", str_error(rc)); 514 } 578 } 515 579 516 580 bool cont = false; 517 /* Continue if at least one of the subdrivers want to continue */ 518 for (int i = 0; i < hid_dev->subdriver_count; ++i) { 519 if (hid_dev->subdrivers[i].poll != NULL) { 520 cont = cont || hid_dev->subdrivers[i].poll( 521 hid_dev, hid_dev->subdrivers[i].data); 581 582 // continue if at least one of the subdrivers want to continue 583 for (i = 0; i < hid_dev->subdriver_count; ++i) { 584 if (hid_dev->subdrivers[i].poll != NULL 585 && hid_dev->subdrivers[i].poll(hid_dev, 586 hid_dev->subdrivers[i].data)) { 587 cont = true; 522 588 } 523 589 } … … 528 594 /*----------------------------------------------------------------------------*/ 529 595 530 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg) 531 { 532 assert(dev); 533 assert(arg); 534 535 usb_hid_dev_t *hid_dev = arg; 536 537 for (int i = 0; i < hid_dev->subdriver_count; ++i) { 596 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, 597 void *arg) 598 { 599 int i; 600 601 if (dev == NULL || arg == NULL) { 602 return; 603 } 604 605 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg; 606 607 for (i = 0; i < hid_dev->subdriver_count; ++i) { 538 608 if (hid_dev->subdrivers[i].poll_end != NULL) { 539 hid_dev->subdrivers[i].poll_end( 540 hid_dev , hid_dev->subdrivers[i].data, reason);609 hid_dev->subdrivers[i].poll_end(hid_dev, 610 hid_dev->subdrivers[i].data, reason); 541 611 } 542 612 } … … 554 624 /*----------------------------------------------------------------------------*/ 555 625 556 int usb_hid_report_number( constusb_hid_dev_t *hid_dev)626 int usb_hid_report_number(usb_hid_dev_t *hid_dev) 557 627 { 558 628 return hid_dev->report_nr; … … 561 631 /*----------------------------------------------------------------------------*/ 562 632 563 void usb_hid_deinit(usb_hid_dev_t *hid_dev) 564 { 565 assert(hid_dev); 566 assert(hid_dev->subdrivers != NULL || hid_dev->subdriver_count == 0); 567 633 void usb_hid_destroy(usb_hid_dev_t *hid_dev) 634 { 635 int i; 636 637 if (hid_dev == NULL) { 638 return; 639 } 568 640 569 641 usb_log_debug("Subdrivers: %p, subdriver count: %d\n", 570 642 hid_dev->subdrivers, hid_dev->subdriver_count); 571 643 572 for (int i = 0; i < hid_dev->subdriver_count; ++i) { 644 assert(hid_dev->subdrivers != NULL 645 || hid_dev->subdriver_count == 0); 646 647 for (i = 0; i < hid_dev->subdriver_count; ++i) { 573 648 if (hid_dev->subdrivers[i].deinit != NULL) { 574 649 hid_dev->subdrivers[i].deinit(hid_dev, … … 582 657 583 658 /* Destroy the parser */ 584 usb_hid_report_deinit(&hid_dev->report); 659 if (hid_dev->report != NULL) { 660 usb_hid_free_report(hid_dev->report); 661 } 585 662 586 663 } -
uspace/drv/bus/usb/usbhid/usbhid.h
r1f131fb9 r98fb010 119 119 120 120 /** HID Report parser. */ 121 usb_hid_report_t report;121 usb_hid_report_t *report; 122 122 123 123 uint8_t report_id; … … 141 141 }; 142 142 143 extern constusb_endpoint_description_t *usb_hid_endpoints[];143 extern usb_endpoint_description_t *usb_hid_endpoints[]; 144 144 145 145 /*----------------------------------------------------------------------------*/ … … 147 147 int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev); 148 148 149 void usb_hid_deinit(usb_hid_dev_t *hid_dev); 149 bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer, 150 size_t buffer_size, void *arg); 150 151 151 bool usb_hid_polling_callback(usb_device_t *dev, 152 uint8_t *buffer, size_t buffer_size, void *arg); 153 154 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg); 152 void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, 153 void *arg); 155 154 156 155 void usb_hid_new_report(usb_hid_dev_t *hid_dev); 157 156 158 int usb_hid_report_number(const usb_hid_dev_t *hid_dev); 157 int usb_hid_report_number(usb_hid_dev_t *hid_dev); 158 159 void usb_hid_destroy(usb_hid_dev_t *hid_dev); 159 160 160 161 #endif /* USB_HID_USBHID_H_ */ -
uspace/drv/bus/usb/usbhub/main.c
r1f131fb9 r98fb010 67 67 68 68 /** Hub endpoints, excluding control endpoint. */ 69 static constusb_endpoint_description_t *usb_hub_endpoints[] = {69 static usb_endpoint_description_t *usb_hub_endpoints[] = { 70 70 &hub_status_change_endpoint_description, 71 71 NULL, -
uspace/drv/bus/usb/usbmast/main.c
r1f131fb9 r98fb010 72 72 }; 73 73 74 static constusb_endpoint_description_t *mast_endpoints[] = {74 usb_endpoint_description_t *mast_endpoints[] = { 75 75 &bulk_in_ep, 76 76 &bulk_out_ep, -
uspace/drv/bus/usb/usbmouse/init.c
r1f131fb9 r98fb010 44 44 45 45 /** Mouse polling endpoint description for boot protocol subclass. */ 46 constusb_endpoint_description_t poll_endpoint_description = {46 usb_endpoint_description_t poll_endpoint_description = { 47 47 .transfer_type = USB_TRANSFER_INTERRUPT, 48 48 .direction = USB_DIRECTION_IN, -
uspace/drv/bus/usb/usbmouse/main.c
r1f131fb9 r98fb010 83 83 }; 84 84 85 static constusb_endpoint_description_t *endpoints[] = {85 static usb_endpoint_description_t *endpoints[] = { 86 86 &poll_endpoint_description, 87 87 NULL -
uspace/drv/bus/usb/usbmouse/mouse.c
r1f131fb9 r98fb010 124 124 mouse->console_sess = NULL; 125 125 126 usb_device_de init(dev);126 usb_device_destroy(dev); 127 127 } 128 128 -
uspace/drv/bus/usb/usbmouse/mouse.h
r1f131fb9 r98fb010 61 61 } usb_mouse_t; 62 62 63 extern constusb_endpoint_description_t poll_endpoint_description;63 extern usb_endpoint_description_t poll_endpoint_description; 64 64 65 65 extern int usb_mouse_create(usb_device_t *); -
uspace/lib/usbdev/include/usb/dev/driver.h
r1f131fb9 r98fb010 156 156 \endcode 157 157 */ 158 constusb_endpoint_description_t **endpoints;158 usb_endpoint_description_t **endpoints; 159 159 /** Driver ops. */ 160 160 const usb_driver_ops_t *ops; … … 164 164 165 165 int usb_device_select_interface(usb_device_t *, uint8_t, 166 constusb_endpoint_description_t **);166 usb_endpoint_description_t **); 167 167 168 168 int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *); 169 169 int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *, 170 constusb_endpoint_description_t **, const uint8_t *, size_t, int, int,170 usb_endpoint_description_t **, const uint8_t *, size_t, int, int, 171 171 usb_endpoint_mapping_t **, size_t *); 172 172 int usb_device_destroy_pipes(const ddf_dev_t *, usb_endpoint_mapping_t *, size_t); 173 int usb_device_create(ddf_dev_t *, const usb_endpoint_description_t **, 174 usb_device_t **, const char **); 175 void usb_device_deinit(usb_device_t *); 173 int usb_device_create(ddf_dev_t *, usb_endpoint_description_t **, usb_device_t **, const char **); 174 void usb_device_destroy(usb_device_t *); 176 175 void * usb_device_data_alloc(usb_device_t *, size_t); 177 176 -
uspace/lib/usbdev/src/devdrv.c
r1f131fb9 r98fb010 81 81 * @return Number of pipes (excluding default control pipe). 82 82 */ 83 static size_t count_other_pipes( constusb_endpoint_description_t **endpoints)83 static size_t count_other_pipes(usb_endpoint_description_t **endpoints) 84 84 { 85 85 size_t count = 0; … … 101 101 * @return Error code. 102 102 */ 103 static int initialize_other_pipes( constusb_endpoint_description_t **endpoints,103 static int initialize_other_pipes(usb_endpoint_description_t **endpoints, 104 104 usb_device_t *dev, int alternate_setting) 105 105 { … … 154 154 rc = driver->ops->device_add(dev); 155 155 if (rc != EOK) 156 usb_device_de init(dev);156 usb_device_destroy(dev); 157 157 return rc; 158 158 } … … 191 191 const int ret = driver->ops->device_gone(usb_dev); 192 192 if (ret == EOK) 193 usb_device_de init(usb_dev);193 usb_device_destroy(usb_dev); 194 194 195 195 return ret; … … 238 238 */ 239 239 int usb_device_select_interface(usb_device_t *dev, uint8_t alternate_setting, 240 constusb_endpoint_description_t **endpoints)240 usb_endpoint_description_t **endpoints) 241 241 { 242 242 if (dev->interface_no < 0) { … … 321 321 */ 322 322 int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire, 323 constusb_endpoint_description_t **endpoints,323 usb_endpoint_description_t **endpoints, 324 324 const uint8_t *config_descr, size_t config_descr_size, 325 325 int interface_no, int interface_setting, … … 526 526 */ 527 527 int usb_device_create(ddf_dev_t *ddf_dev, 528 constusb_endpoint_description_t **endpoints,528 usb_endpoint_description_t **endpoints, 529 529 usb_device_t **dev_ptr, const char **errstr_ptr) 530 530 { … … 590 590 /** Destroy instance of a USB device. 591 591 * 592 * @param dev Device to be de-initialized. 593 * 594 * Does not free/destroy supplied pointer. 595 */ 596 void usb_device_deinit(usb_device_t *dev) 592 * @param dev Device to be destroyed. 593 */ 594 void usb_device_destroy(usb_device_t *dev) 597 595 { 598 596 if (dev == NULL) { -
uspace/lib/usbhid/include/usb/hid/hiddescriptor.h
r1f131fb9 r98fb010 42 42 #include <usb/hid/hidtypes.h> 43 43 44 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 44 int usb_hid_parse_report_descriptor(usb_hid_report_t *report, 45 45 const uint8_t *data, size_t size); 46 47 void usb_hid_free_report(usb_hid_report_t *report); 46 48 47 49 void usb_hid_descriptor_print(usb_hid_report_t *report); 48 50 49 51 int usb_hid_report_init(usb_hid_report_t *report); 50 51 void usb_hid_report_deinit(usb_hid_report_t *report);52 52 53 53 int usb_hid_report_append_fields(usb_hid_report_t *report, -
uspace/lib/usbhid/src/hiddescriptor.c
r1f131fb9 r98fb010 1016 1016 * @return void 1017 1017 */ 1018 void usb_hid_ report_deinit(usb_hid_report_t *report)1018 void usb_hid_free_report(usb_hid_report_t *report) 1019 1019 { 1020 1020 if(report == NULL){
Note:
See TracChangeset
for help on using the changeset viewer.