Changes in uspace/drv/usbhid/kbddev.c [ac8285d:2f593872] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/kbddev.c
rac8285d r2f593872 38 38 #include <str_error.h> 39 39 #include <fibril.h> 40 #include <stdio.h> 40 41 41 42 #include <io/keycode.h> … … 62 63 static const size_t BOOTP_BUFFER_SIZE = 8; 63 64 static const size_t BOOTP_BUFFER_OUT_SIZE = 1; 65 static const uint8_t BOOTP_ERROR_ROLLOVER = 1; 66 static const uint8_t IDLE_RATE = 0; 64 67 65 68 /** Keyboard polling endpoint description for boot protocol class. */ … … 149 152 uint8_t buffer[BOOTP_BUFFER_OUT_SIZE]; 150 153 int rc= 0; 151 unsigned i;152 154 153 155 memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE); … … 177 179 } 178 180 179 // TODO: REFACTOR!!! 180 181 usb_log_debug("Output report buffer: "); 182 for (i = 0; i < BOOTP_BUFFER_OUT_SIZE; ++i) { 183 usb_log_debug("0x%x ", buffer[i]); 184 } 185 usb_log_debug("\n"); 186 187 uint16_t value = 0; 188 value |= (USB_HID_REPORT_TYPE_OUTPUT << 8); 189 181 usb_log_debug("Output report buffer: %s\n", 182 usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0)); 183 190 184 assert(kbd_dev->hid_dev != NULL); 191 185 assert(kbd_dev->hid_dev->initialized); 192 usbhid_req_set_report(kbd_dev->hid_dev, value, buffer,193 BOOTP_BUFFER_OUT_SIZE);186 usbhid_req_set_report(kbd_dev->hid_dev, USB_HID_REPORT_TYPE_OUTPUT, 187 buffer, BOOTP_BUFFER_OUT_SIZE); 194 188 } 195 189 … … 228 222 229 223 if (mod_mask != 0) { 230 usb_log_debug2("\n\nChanging mods and lock keys\n");231 usb_log_debug2("\nmods before: 0x%x\n", kbd_dev->mods);232 usb_log_debug2("\nLock keys before:0x%x\n\n",233 kbd_dev->lock_keys);234 235 224 if (type == KEY_PRESS) { 236 usb_log_debug2("\nKey pressed.\n");237 225 /* 238 226 * Only change lock state on transition from released … … 247 235 usbhid_kbd_set_led(kbd_dev); 248 236 } else { 249 usb_log_debug2("\nKey released.\n");250 237 kbd_dev->lock_keys = kbd_dev->lock_keys & ~mod_mask; 251 238 } 252 239 } 253 240 254 usb_log_debug2("\n\nmods after: 0x%x\n", kbd_dev->mods);255 usb_log_debug2("\nLock keys after: 0x%x\n\n", kbd_dev->lock_keys);256 257 241 if (key == KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) { 258 242 // do not send anything to the console, this is our business … … 281 265 ev.key = key; 282 266 ev.mods = kbd_dev->mods; 283 284 if (ev.mods & KM_NUM_LOCK) {285 usb_log_debug("\n\nNum Lock turned on.\n\n");286 }287 267 288 268 ev.c = layout[active_layout]->parse_ev(&ev); 289 269 290 270 usb_log_debug2("Sending key %d to the console\n", ev.key); 291 assert(kbd_dev->console_phone != -1); 271 if (kbd_dev->console_phone < 0) { 272 usb_log_warning( 273 "Connection to console not ready, key discarded.\n"); 274 return; 275 } 292 276 293 277 async_msg_4(kbd_dev->console_phone, KBD_EVENT, ev.type, ev.key, … … 336 320 const uint8_t *key_codes) 337 321 { 338 // TODO: phantom state!!339 340 322 unsigned int key; 341 323 unsigned int i, j; 324 325 /* 326 * First of all, check if the kbd have reported phantom state. 327 */ 328 i = 0; 329 // all fields should report Error Rollover 330 while (i < kbd_dev->keycode_count && 331 key_codes[i] == BOOTP_ERROR_ROLLOVER) { 332 ++i; 333 } 334 if (i == kbd_dev->keycode_count) { 335 usb_log_debug("Phantom state occured.\n"); 336 // phantom state, do nothing 337 return; 338 } 342 339 343 340 // TODO: quite dummy right now, think of better implementation … … 358 355 key = usbhid_parse_scancode(kbd_dev->keycodes[j]); 359 356 usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key); 360 usb_log_debug2(" \nKey released: %d\n", key);357 usb_log_debug2("Key released: %d\n", key); 361 358 } else { 362 359 // found, nothing happens … … 378 375 // not found, i.e. new key pressed 379 376 key = usbhid_parse_scancode(key_codes[i]); 380 usb_log_debug2(" \nKey pressed: %d (keycode: %d)\n", key,377 usb_log_debug2("Key pressed: %d (keycode: %d)\n", key, 381 378 key_codes[i]); 382 379 usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key); … … 385 382 } 386 383 } 384 // // report all currently pressed keys 385 // for (i = 0; i < kbd_dev->keycode_count; ++i) { 386 // if (key_codes[i] != 0) { 387 // key = usbhid_parse_scancode(key_codes[i]); 388 // usb_log_debug2("Key pressed: %d (keycode: %d)\n", key, 389 // key_codes[i]); 390 // usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key); 391 // } 392 // } 387 393 388 394 memcpy(kbd_dev->keycodes, key_codes, kbd_dev->keycode_count); 389 390 usb_log_debug2("\nNew stored keycodes: "); 391 for (i = 0; i < kbd_dev->keycode_count; ++i) { 392 usb_log_debug2("%d ", kbd_dev->keycodes[i]); 393 } 395 396 usb_log_debug("New stored keycodes: %s\n", 397 usb_debug_str_buffer(kbd_dev->keycodes, kbd_dev->keycode_count, 0)); 394 398 } 395 399 … … 406 410 return; 407 411 } 408 409 usb_log_debug2("Got keys from parser: ");410 unsigned i;411 for (i = 0; i < count; ++i) {412 usb_log_debug2("%d ", key_codes[i]);413 }414 usb_log_debug2("\n");415 412 416 413 usbhid_kbd_t *kbd_dev = (usbhid_kbd_t *)arg; 417 414 assert(kbd_dev != NULL); 415 416 usb_log_debug("Got keys from parser: %s\n", 417 usb_debug_str_buffer(key_codes, kbd_dev->keycode_count, 0)); 418 418 419 419 if (count != kbd_dev->keycode_count) { … … 440 440 callbacks->keyboard = usbhid_kbd_process_keycodes; 441 441 442 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 443 // NULL); 444 /*usb_log_debug2("Calling usb_hid_boot_keyboard_input_report() with size" 445 " %zu\n", actual_size);*/ 446 //dump_buffer("bufffer: ", buffer, actual_size); 447 448 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, 449 callbacks, kbd_dev); 442 usb_log_debug("Calling usb_hid_parse_report() with " 443 "buffer %s\n", usb_debug_str_buffer(buffer, actual_size, 0)); 444 445 // int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, 446 // callbacks, kbd_dev); 447 int rc = usb_hid_parse_report(kbd_dev->hid_dev->parser, buffer, 448 actual_size, callbacks, kbd_dev); 450 449 451 450 if (rc != EOK) { … … 499 498 } 500 499 500 usb_hid_free_report_parser((*kbd_dev)->parser); 501 501 502 free(*kbd_dev); 502 503 *kbd_dev = NULL; … … 555 556 * Set boot protocol. 556 557 * Set LEDs according to initial setup. 558 * Set Idle rate 557 559 */ 558 560 assert(kbd_dev->hid_dev != NULL); 559 561 assert(kbd_dev->hid_dev->initialized); 560 usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT);562 //usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT); 561 563 562 564 usbhid_kbd_set_led(kbd_dev); 565 566 usbhid_req_set_idle(kbd_dev->hid_dev, IDLE_RATE); 563 567 564 568 kbd_dev->initialized = 1; … … 589 593 590 594 while (true) { 591 async_usleep(1000 * 10);592 593 595 sess_rc = usb_endpoint_pipe_start_session( 594 596 &kbd_dev->hid_dev->poll_pipe); … … 631 633 usb_log_debug("Calling usbhid_kbd_process_data()\n"); 632 634 usbhid_kbd_process_data(kbd_dev, buffer, actual_size); 635 636 // disabled for now, no reason to sleep 637 //async_usleep(kbd_dev->hid_dev->poll_interval); 633 638 } 634 639
Note:
See TracChangeset
for help on using the changeset viewer.