Changes in uspace/drv/usbhid/kbddev.c [2f593872:ac8285d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/kbddev.c
r2f593872 rac8285d 38 38 #include <str_error.h> 39 39 #include <fibril.h> 40 #include <stdio.h>41 40 42 41 #include <io/keycode.h> … … 63 62 static const size_t BOOTP_BUFFER_SIZE = 8; 64 63 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;67 64 68 65 /** Keyboard polling endpoint description for boot protocol class. */ … … 152 149 uint8_t buffer[BOOTP_BUFFER_OUT_SIZE]; 153 150 int rc= 0; 151 unsigned i; 154 152 155 153 memset(buffer, 0, BOOTP_BUFFER_OUT_SIZE); … … 179 177 } 180 178 181 usb_log_debug("Output report buffer: %s\n", 182 usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0)); 183 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 184 190 assert(kbd_dev->hid_dev != NULL); 185 191 assert(kbd_dev->hid_dev->initialized); 186 usbhid_req_set_report(kbd_dev->hid_dev, USB_HID_REPORT_TYPE_OUTPUT,187 buffer,BOOTP_BUFFER_OUT_SIZE);192 usbhid_req_set_report(kbd_dev->hid_dev, value, buffer, 193 BOOTP_BUFFER_OUT_SIZE); 188 194 } 189 195 … … 222 228 223 229 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 224 235 if (type == KEY_PRESS) { 236 usb_log_debug2("\nKey pressed.\n"); 225 237 /* 226 238 * Only change lock state on transition from released … … 235 247 usbhid_kbd_set_led(kbd_dev); 236 248 } else { 249 usb_log_debug2("\nKey released.\n"); 237 250 kbd_dev->lock_keys = kbd_dev->lock_keys & ~mod_mask; 238 251 } 239 252 } 240 253 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 241 257 if (key == KC_CAPS_LOCK || key == KC_NUM_LOCK || key == KC_SCROLL_LOCK) { 242 258 // do not send anything to the console, this is our business … … 265 281 ev.key = key; 266 282 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 } 267 287 268 288 ev.c = layout[active_layout]->parse_ev(&ev); 269 289 270 290 usb_log_debug2("Sending key %d to the console\n", ev.key); 271 if (kbd_dev->console_phone < 0) { 272 usb_log_warning( 273 "Connection to console not ready, key discarded.\n"); 274 return; 275 } 291 assert(kbd_dev->console_phone != -1); 276 292 277 293 async_msg_4(kbd_dev->console_phone, KBD_EVENT, ev.type, ev.key, … … 320 336 const uint8_t *key_codes) 321 337 { 338 // TODO: phantom state!! 339 322 340 unsigned int key; 323 341 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 Rollover330 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 nothing337 return;338 }339 342 340 343 // TODO: quite dummy right now, think of better implementation … … 355 358 key = usbhid_parse_scancode(kbd_dev->keycodes[j]); 356 359 usbhid_kbd_push_ev(kbd_dev, KEY_RELEASE, key); 357 usb_log_debug2(" Key released: %d\n", key);360 usb_log_debug2("\nKey released: %d\n", key); 358 361 } else { 359 362 // found, nothing happens … … 375 378 // not found, i.e. new key pressed 376 379 key = usbhid_parse_scancode(key_codes[i]); 377 usb_log_debug2(" Key pressed: %d (keycode: %d)\n", key,380 usb_log_debug2("\nKey pressed: %d (keycode: %d)\n", key, 378 381 key_codes[i]); 379 382 usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key); … … 382 385 } 383 386 } 384 // // report all currently pressed keys385 // 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 // }393 387 394 388 memcpy(kbd_dev->keycodes, key_codes, kbd_dev->keycode_count); 395 396 usb_log_debug("New stored keycodes: %s\n", 397 usb_debug_str_buffer(kbd_dev->keycodes, kbd_dev->keycode_count, 0)); 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 } 398 394 } 399 395 … … 410 406 return; 411 407 } 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"); 412 415 413 416 usbhid_kbd_t *kbd_dev = (usbhid_kbd_t *)arg; 414 417 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_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); 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); 449 450 450 451 if (rc != EOK) { … … 498 499 } 499 500 500 usb_hid_free_report_parser((*kbd_dev)->parser);501 502 501 free(*kbd_dev); 503 502 *kbd_dev = NULL; … … 556 555 * Set boot protocol. 557 556 * Set LEDs according to initial setup. 558 * Set Idle rate559 557 */ 560 558 assert(kbd_dev->hid_dev != NULL); 561 559 assert(kbd_dev->hid_dev->initialized); 562 //usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT);560 usbhid_req_set_protocol(kbd_dev->hid_dev, USB_HID_PROTOCOL_BOOT); 563 561 564 562 usbhid_kbd_set_led(kbd_dev); 565 566 usbhid_req_set_idle(kbd_dev->hid_dev, IDLE_RATE);567 563 568 564 kbd_dev->initialized = 1; … … 593 589 594 590 while (true) { 591 async_usleep(1000 * 10); 592 595 593 sess_rc = usb_endpoint_pipe_start_session( 596 594 &kbd_dev->hid_dev->poll_pipe); … … 633 631 usb_log_debug("Calling usbhid_kbd_process_data()\n"); 634 632 usbhid_kbd_process_data(kbd_dev, buffer, actual_size); 635 636 // disabled for now, no reason to sleep637 //async_usleep(kbd_dev->hid_dev->poll_interval);638 633 } 639 634
Note:
See TracChangeset
for help on using the changeset viewer.