Changes in uspace/drv/usbkbd/main.c [6336b6e:fbddf94] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
r6336b6e rfbddf94 38 38 #include <usb/devreq.h> 39 39 #include <usb/descriptor.h> 40 #include <io/console.h>41 40 #include "descparser.h" 42 41 #include "descdump.h" 43 #include "conv.h"44 42 45 43 #define BUFFER_SIZE 32 … … 90 88 91 89 /* 92 * TODO: Move somewhere else93 */94 /*95 #define BYTES_PER_LINE 1296 97 static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)98 {99 printf("%s\n", msg);100 101 size_t i;102 for (i = 0; i < length; i++) {103 printf(" 0x%02X", buffer[i]);104 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0))105 || (i + 1 == length)) {106 printf("\n");107 }108 }109 }110 */111 /*112 * Copy-paste from srv/hid/kbd/generic/kbd.c113 */114 115 /** Currently active modifiers.116 *117 * TODO: put to device?118 */119 static unsigned mods = KM_NUM_LOCK;120 121 /** Currently pressed lock keys. We track these to tackle autorepeat.122 *123 * TODO: put to device?124 */125 static unsigned lock_keys;126 127 // TODO: put to device?128 //static int active_layout = 0;129 130 static void kbd_push_ev(int type, unsigned int key)131 {132 console_event_t ev;133 unsigned mod_mask;134 135 // TODO: replace by our own parsing?? or are the key codes identical??136 switch (key) {137 case KC_LCTRL: mod_mask = KM_LCTRL; break;138 case KC_RCTRL: mod_mask = KM_RCTRL; break;139 case KC_LSHIFT: mod_mask = KM_LSHIFT; break;140 case KC_RSHIFT: mod_mask = KM_RSHIFT; break;141 case KC_LALT: mod_mask = KM_LALT; break;142 case KC_RALT: mod_mask = KM_RALT; break;143 default: mod_mask = 0; break;144 }145 146 if (mod_mask != 0) {147 if (type == KEY_PRESS)148 mods = mods | mod_mask;149 else150 mods = mods & ~mod_mask;151 }152 153 switch (key) {154 case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break;155 case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break;156 case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break;157 default: mod_mask = 0; break;158 }159 160 if (mod_mask != 0) {161 if (type == KEY_PRESS) {162 /*163 * Only change lock state on transition from released164 * to pressed. This prevents autorepeat from messing165 * up the lock state.166 */167 mods = mods ^ (mod_mask & ~lock_keys);168 lock_keys = lock_keys | mod_mask;169 170 /* Update keyboard lock indicator lights. */171 // TODO172 //kbd_ctl_set_ind(mods);173 } else {174 lock_keys = lock_keys & ~mod_mask;175 }176 }177 /*178 printf("type: %d\n", type);179 printf("mods: 0x%x\n", mods);180 printf("keycode: %u\n", key);181 */182 /*183 if (type == KEY_PRESS && (mods & KM_LCTRL) &&184 key == KC_F1) {185 active_layout = 0;186 layout[active_layout]->reset();187 return;188 }189 190 if (type == KEY_PRESS && (mods & KM_LCTRL) &&191 key == KC_F2) {192 active_layout = 1;193 layout[active_layout]->reset();194 return;195 }196 197 if (type == KEY_PRESS && (mods & KM_LCTRL) &&198 key == KC_F3) {199 active_layout = 2;200 layout[active_layout]->reset();201 return;202 }203 */204 ev.type = type;205 ev.key = key;206 ev.mods = mods;207 208 //ev.c = layout[active_layout]->parse_ev(&ev);209 210 printf("Sending key %d to the console\n", ev.key);211 assert(console_callback_phone != -1);212 async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, 0);213 }214 /*215 * End of copy-paste216 */217 218 /*219 * TODO:220 * 1) key press / key release - how does the keyboard notify about release?221 * 2) layouts (use the already defined), not important now222 * 3)223 */224 225 /*226 90 * Callbacks for parser 227 91 */ … … 233 97 for (i = 0; i < count; ++i) { 234 98 printf("%d ", key_codes[i]); 235 // TODO: Key press / release236 237 // TODO: NOT WORKING238 unsigned int key = usbkbd_parse_scancode(key_codes[i]);239 kbd_push_ev(KEY_PRESS, key);240 99 } 241 100 printf("\n"); … … 405 264 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 406 265 // NULL); 407 // printf("Calling usb_hid_boot_keyboard_input_report() with size %d\n", 408 // actual_size); 409 // dump_buffer("bufffer: ", buffer, actual_size); 410 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 411 NULL); 412 if (rc != EOK) { 413 printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc); 414 } 266 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 267 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 415 268 } 416 269 417 270 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 418 271 { 272 return; 273 419 274 int rc; 420 275 usb_handle_t handle; … … 434 289 }; 435 290 436 printf("Polling keyboard...\n");437 438 291 while (true) { 439 async_usleep(1000 * 1000 * 2);292 async_usleep(1000 * 1000); 440 293 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 441 294 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 442 295 443 296 if (rc != EOK) { 444 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);445 297 continue; 446 298 } … … 448 300 rc = usb_drv_async_wait_for(handle); 449 301 if (rc != EOK) { 450 printf("Error in usb_drv_async_wait_for(): %d\n", rc);451 302 continue; 452 303 } … … 457 308 */ 458 309 if (actual_size == 0) { 459 printf("Keyboar returned NAK\n");460 310 continue; 461 311 } … … 464 314 * TODO: Process pressed keys. 465 315 */ 466 printf("Calling usbkbd_process_interrupt_in()\n"); 467 // actual_size is not set, workaround... 468 usbkbd_process_interrupt_in(kbd_dev, buffer, /*actual_size*/8); 316 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 469 317 } 470 318 … … 486 334 // initialize device (get and process descriptors, get address, etc.) 487 335 usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev); 488 if (kbd_dev == NULL) {489 printf("Error while initializing device.\n");490 return -1;491 }492 336 493 337 usbkbd_poll_keyboard(kbd_dev);
Note:
See TracChangeset
for help on using the changeset viewer.