Changes in uspace/drv/usbkbd/main.c [fbddf94:6336b6e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
rfbddf94 r6336b6e 38 38 #include <usb/devreq.h> 39 39 #include <usb/descriptor.h> 40 #include <io/console.h> 40 41 #include "descparser.h" 41 42 #include "descdump.h" 43 #include "conv.h" 42 44 43 45 #define BUFFER_SIZE 32 … … 88 90 89 91 /* 92 * TODO: Move somewhere else 93 */ 94 /* 95 #define BYTES_PER_LINE 12 96 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.c 113 */ 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 else 150 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 released 164 * to pressed. This prevents autorepeat from messing 165 * 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 // TODO 172 //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-paste 216 */ 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 now 222 * 3) 223 */ 224 225 /* 90 226 * Callbacks for parser 91 227 */ … … 97 233 for (i = 0; i < count; ++i) { 98 234 printf("%d ", key_codes[i]); 235 // TODO: Key press / release 236 237 // TODO: NOT WORKING 238 unsigned int key = usbkbd_parse_scancode(key_codes[i]); 239 kbd_push_ev(KEY_PRESS, key); 99 240 } 100 241 printf("\n"); … … 264 405 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 265 406 // NULL); 266 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 267 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 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 } 268 415 } 269 416 270 417 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 271 418 { 272 return;273 274 419 int rc; 275 420 usb_handle_t handle; … … 289 434 }; 290 435 436 printf("Polling keyboard...\n"); 437 291 438 while (true) { 292 async_usleep(1000 * 1000 );439 async_usleep(1000 * 1000 * 2); 293 440 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 294 441 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 295 442 296 443 if (rc != EOK) { 444 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc); 297 445 continue; 298 446 } … … 300 448 rc = usb_drv_async_wait_for(handle); 301 449 if (rc != EOK) { 450 printf("Error in usb_drv_async_wait_for(): %d\n", rc); 302 451 continue; 303 452 } … … 308 457 */ 309 458 if (actual_size == 0) { 459 printf("Keyboar returned NAK\n"); 310 460 continue; 311 461 } … … 314 464 * TODO: Process pressed keys. 315 465 */ 316 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 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); 317 469 } 318 470 … … 334 486 // initialize device (get and process descriptors, get address, etc.) 335 487 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 } 336 492 337 493 usbkbd_poll_keyboard(kbd_dev);
Note:
See TracChangeset
for help on using the changeset viewer.