Changes in / [a80849c:92574f4] in mainline
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/hid.h
ra80849c r92574f4 37 37 #define USBHID_HID_H_ 38 38 39 #include <stdint.h> 40 39 41 #include <usb/classes/hid.h> 40 42 #include <ddf/driver.h> … … 74 76 usb_endpoint_pipe_t ctrl_pipe; 75 77 usb_endpoint_pipe_t poll_pipe; 78 79 uint8_t *keycodes; 80 size_t keycode_count; 81 uint8_t modifiers; 76 82 } usb_hid_dev_kbd_t; 77 83 -
uspace/drv/usbhid/main.c
ra80849c r92574f4 51 51 #include <usb/descriptor.h> 52 52 #include <io/console.h> 53 #include <stdint.h> 53 54 #include "hid.h" 54 55 #include "descparser.h" … … 61 62 62 63 #define GUESSED_POLL_ENDPOINT 1 64 #define BOOTP_REPORT_SIZE 6 63 65 64 66 /** Keyboard polling endpoint description for boot protocol class. */ … … 207 209 } 208 210 /* 209 printf("type: %d\n", type);210 printf("mods: 0x%x\n", mods);211 printf("keycode: %u\n", key);211 usb_log_debug2("type: %d\n", type); 212 usb_log_debug2("mods: 0x%x\n", mods); 213 usb_log_debug2("keycode: %u\n", key); 212 214 */ 213 215 … … 239 241 ev.c = layout[active_layout]->parse_ev(&ev); 240 242 241 printf("Sending key %d to the console\n", ev.key);243 usb_log_debug("Sending key %d to the console\n", ev.key); 242 244 assert(console_callback_phone != -1); 243 async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c); 245 async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, 246 ev.mods, ev.c); 244 247 } 245 248 /* … … 249 252 /* 250 253 * TODO: 251 * 1) key press / key release - how does the keyboard notify about release? 254 * 1) key press / key release - how does the keyboard notify about 255 * release? 252 256 * 2) layouts (use the already defined), not important now 253 257 * 3) 254 258 */ 255 259 260 static const keycode_t usb_hid_modifiers_boot_keycodes[5] = { 261 KC_NUM_LOCK, /* USB_HID_MOD_BOOT_NUM_LOCK */ 262 KC_CAPS_LOCK, /* USB_HID_MOD_BOOT_CAPS_LOCK */ 263 KC_SCROLL_LOCK, /* USB_HID_MOD_BOOT_SCROLL_LOCK */ 264 0, /* USB_HID_MOD_BOOT_COMPOSE */ 265 0 /* USB_HID_MOD_BOOT_KANA */ 266 }; 267 268 static void usbkbd_check_modifier_changes(usb_hid_dev_kbd_t *kbd_dev, 269 uint8_t modifiers) 270 { 271 /* 272 * TODO: why the USB keyboard has NUM_, SCROLL_ and CAPS_LOCK 273 * both as modifiers and as keys with their own scancodes??? 274 * 275 * modifiers should be sent as normal keys to usbkbd_parse_scancode()!! 276 * so maybe it would be better if I received it from report parser in 277 * that way 278 */ 279 280 int i; 281 for (i = 0; i < USB_HID_MOD_BOOT_COUNT; ++i) { 282 if ((modifiers & usb_hid_modifiers_boot_consts[i]) && 283 !(kbd_dev->modifiers & usb_hid_modifiers_boot_consts[i])) { 284 // modifier pressed 285 if (usb_hid_modifiers_boot_keycodes[i] != 0) { 286 kbd_push_ev(KEY_PRESS, 287 usb_hid_modifiers_boot_keycodes[i]); 288 } 289 } else if (!(modifiers & usb_hid_modifiers_boot_consts[i]) && 290 (kbd_dev->modifiers & usb_hid_modifiers_boot_consts[i])) { 291 // modifier released 292 if (usb_hid_modifiers_boot_keycodes[i] != 0) { 293 kbd_push_ev(KEY_RELEASE, 294 usb_hid_modifiers_boot_keycodes[i]); 295 } 296 } // no change 297 } 298 } 299 300 static void usbkbd_check_key_changes(usb_hid_dev_kbd_t *kbd_dev, 301 const uint8_t *key_codes) 302 { 303 // TODO: phantom state!! 304 305 unsigned int key; 306 unsigned int i, j; 307 308 // TODO: quite dummy right now, think of better implementation 309 310 // key releases 311 for (j = 0; j < kbd_dev->keycode_count; ++j) { 312 // try to find the old key in the new key list 313 i = 0; 314 while (i < kbd_dev->keycode_count 315 && key_codes[i] != kbd_dev->keycodes[j]) { 316 ++j; 317 } 318 319 if (j == kbd_dev->keycode_count) { 320 // not found, i.e. the key was released 321 key = usbkbd_parse_scancode(kbd_dev->keycodes[j]); 322 kbd_push_ev(KEY_RELEASE, key); 323 } else { 324 // found, nothing happens 325 } 326 } 327 328 // key presses 329 for (i = 0; i < kbd_dev->keycode_count; ++i) { 330 // try to find the new key in the old key list 331 j = 0; 332 while (j < kbd_dev->keycode_count 333 && kbd_dev->keycodes[j] != key_codes[i]) { 334 ++j; 335 } 336 337 assert(kbd_dev->keycode_count <= kbd_dev->keycode_count); 338 339 if (j == kbd_dev->keycode_count) { 340 // not found, i.e. new key pressed 341 key = usbkbd_parse_scancode(key_codes[i]); 342 kbd_push_ev(KEY_PRESS, key); 343 } else { 344 // found, nothing happens 345 } 346 } 347 } 348 256 349 /* 257 350 * Callbacks for parser … … 260 353 uint8_t modifiers, void *arg) 261 354 { 262 printf("Got keys: "); 355 if (arg == NULL) { 356 usb_log_warning("Missing argument in callback " 357 "usbkbd_process_keycodes().\n"); 358 return; 359 } 360 361 usb_log_debug2("Got keys from parser: "); 263 362 unsigned i; 264 363 for (i = 0; i < count; ++i) { 265 printf("%d ", key_codes[i]); 266 } 267 printf("\n"); 268 269 for (i = 0; i < count; ++i) { 270 // TODO: Key press / release 271 272 // TODO: NOT WORKING 273 unsigned int key = usbkbd_parse_scancode(key_codes[i]); 274 275 if (key == 0) { 276 continue; 277 } 278 kbd_push_ev(KEY_PRESS, key); 279 } 280 printf("\n"); 364 usb_log_debug2("%d ", key_codes[i]); 365 } 366 usb_log_debug2("\n"); 367 368 usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)arg; 369 370 if (count != kbd_dev->keycode_count) { 371 usb_log_warning("Number of received keycodes (%d) differs from" 372 " expected number (%d).\n", count, kbd_dev->keycode_count); 373 return; 374 } 375 376 usbkbd_check_modifier_changes(kbd_dev, modifiers); 377 usbkbd_check_key_changes(kbd_dev, key_codes); 281 378 } 282 379 … … 291 388 for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) { 292 389 // TODO: endianness 293 uint16_t length = 294 kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;390 uint16_t length = kbd_dev->conf->interfaces[i].hid_desc. 391 report_desc_info.length; 295 392 size_t actual_size = 0; 296 393 297 394 // allocate space for the report descriptor 298 kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length); 395 kbd_dev->conf->interfaces[i].report_desc = 396 (uint8_t *)malloc(length); 299 397 300 398 // get the descriptor from the device … … 317 415 return EOK; 318 416 } 417 319 418 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev) 320 419 { … … 388 487 free(descriptors); 389 488 if (rc != EOK) { 390 printf("Problem with parsing standard descriptors.\n");489 usb_log_warning("Problem with parsing standard descriptors.\n"); 391 490 return rc; 392 491 } … … 395 494 rc = usbkbd_get_report_descriptor(kbd_dev); 396 495 if (rc != EOK) { 397 printf("Problem with parsing HIDREPORT descriptor.\n");496 usb_log_warning("Problem with parsing REPORT descriptor.\n"); 398 497 return rc; 399 498 } … … 405 504 * 1) select one configuration (lets say the first) 406 505 * 2) how many interfaces?? how to select one?? 407 * ("The default setting for an interface is always alternate setting zero.") 506 * ("The default setting for an interface is always alternate 507 * setting zero.") 408 508 * 3) find endpoint which is IN and INTERRUPT (parse), save its number 409 509 * as the endpoint for polling 410 510 */ 411 511 … … 421 521 422 522 if (kbd_dev == NULL) { 423 fprintf(stderr, NAME ":No memory!\n");523 usb_log_fatal("No memory!\n"); 424 524 return NULL; 425 525 } … … 476 576 usb_hid_report_in_callbacks_t *callbacks = 477 577 (usb_hid_report_in_callbacks_t *)malloc( 478 578 sizeof(usb_hid_report_in_callbacks_t)); 479 579 callbacks->keyboard = usbkbd_process_keycodes; 480 580 481 581 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 482 582 // NULL); 483 printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n",484 actual_size);583 /*usb_log_debug2("Calling usb_hid_boot_keyboard_input_report() with size" 584 " %zu\n", actual_size);*/ 485 585 //dump_buffer("bufffer: ", buffer, actual_size); 486 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 487 NULL); 488 if (rc != EOK) { 489 printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc); 586 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, 587 callbacks, kbd_dev); 588 589 if (rc != EOK) { 590 usb_log_warning("Error in usb_hid_boot_keyboard_input_report():" 591 "%s\n", str_error(rc)); 490 592 } 491 593 } … … 497 599 size_t actual_size; 498 600 499 printf("Polling keyboard...\n");601 usb_log_info("Polling keyboard...\n"); 500 602 501 603 while (true) { … … 504 606 sess_rc = usb_endpoint_pipe_start_session(&kbd_dev->poll_pipe); 505 607 if (sess_rc != EOK) { 506 printf("Failed to start a session: %s.\n",608 usb_log_warning("Failed to start a session: %s.\n", 507 609 str_error(sess_rc)); 508 610 continue; … … 514 616 515 617 if (rc != EOK) { 516 printf("Error polling the keyboard: %s.\n",618 usb_log_warning("Error polling the keyboard: %s.\n", 517 619 str_error(rc)); 518 620 continue; … … 520 622 521 623 if (sess_rc != EOK) { 522 printf("Error closing session: %s.\n",624 usb_log_warning("Error closing session: %s.\n", 523 625 str_error(sess_rc)); 524 626 continue; … … 530 632 */ 531 633 if (actual_size == 0) { 532 printf("Keyboard returned NAK\n");634 usb_log_debug("Keyboard returned NAK\n"); 533 635 continue; 534 636 } … … 537 639 * TODO: Process pressed keys. 538 640 */ 539 printf("Calling usbkbd_process_interrupt_in()\n");641 usb_log_debug("Calling usbkbd_process_interrupt_in()\n"); 540 642 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 541 643 } … … 547 649 static int usbkbd_fibril_device(void *arg) 548 650 { 549 printf("!!! USB device fibril\n");550 551 651 if (arg == NULL) { 552 printf("No device!\n");652 usb_log_error("No device!\n"); 553 653 return -1; 554 654 } … … 559 659 usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev); 560 660 if (kbd_dev == NULL) { 561 printf("Error while initializing device.\n");661 usb_log_error("Error while initializing device.\n"); 562 662 return -1; 563 663 } … … 607 707 fid_t fid = fibril_create(usbkbd_fibril_device, dev); 608 708 if (fid == 0) { 609 printf("%s: failed to start fibril for HID device\n", NAME);709 usb_log_error("Failed to start fibril for HID device\n"); 610 710 return ENOMEM; 611 711 } … … 634 734 int main(int argc, char *argv[]) 635 735 { 636 usb_log_enable(USB_LOG_LEVEL_ INFO, "usbhid");736 usb_log_enable(USB_LOG_LEVEL_MAX, NAME); 637 737 return ddf_driver_main(&kbd_driver); 638 738 } -
uspace/lib/usb/include/usb/classes/hidparser.h
ra80849c r92574f4 70 70 } usb_hid_report_in_callbacks_t; 71 71 72 #define USB_HID_BOOT_KEYBOARD_NUM_LOCK 0x01 73 #define USB_HID_BOOT_KEYBOARD_CAPS_LOCK 0x02 74 #define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK 0x04 75 #define USB_HID_BOOT_KEYBOARD_COMPOSE 0x08 76 #define USB_HID_BOOT_KEYBOARD_KANA 0x10 72 73 typedef enum { 74 USB_HID_MOD_BOOT_NUM_LOCK = 0x01, 75 USB_HID_MOD_BOOT_CAPS_LOCK = 0x02, 76 USB_HID_MOD_BOOT_SCROLL_LOCK = 0x04, 77 USB_HID_MOD_BOOT_COMPOSE = 0x08, 78 USB_HID_MOD_BOOT_KANA = 0x10, 79 USB_HID_MOD_BOOT_COUNT = 5 80 } usb_hid_modifiers_boot_t; 81 82 static const usb_hid_modifiers_boot_t usb_hid_modifiers_boot_consts[5] = { 83 USB_HID_MOD_BOOT_NUM_LOCK, 84 USB_HID_MOD_BOOT_CAPS_LOCK, 85 USB_HID_MOD_BOOT_SCROLL_LOCK, 86 USB_HID_MOD_BOOT_COMPOSE, 87 USB_HID_MOD_BOOT_KANA 88 }; 89 90 //#define USB_HID_BOOT_KEYBOARD_NUM_LOCK 0x01 91 //#define USB_HID_BOOT_KEYBOARD_CAPS_LOCK 0x02 92 //#define USB_HID_BOOT_KEYBOARD_SCROLL_LOCK 0x04 93 //#define USB_HID_BOOT_KEYBOARD_COMPOSE 0x08 94 //#define USB_HID_BOOT_KEYBOARD_KANA 0x10 77 95 78 96 /*
Note:
See TracChangeset
for help on using the changeset viewer.