Changes in / [a1d12f4:7c169ce] in mainline
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/keys.h
ra1d12f4 r7c169ce 40 40 41 41 /** Maximum number of keys that can be pressed simultaneously. */ 42 #define KB_MAX_KEYS_AT_ONCE 442 #define KB_MAX_KEYS_AT_ONCE 6 43 43 44 44 /** Key code type. */ -
uspace/drv/usbkbd/Makefile
ra1d12f4 r7c169ce 35 35 main.c \ 36 36 descparser.c \ 37 descdump.c 37 descdump.c \ 38 conv.c \ 39 us_qwerty.c 38 40 39 41 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/usbkbd/main.c
ra1d12f4 r7c169ce 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" 44 #include "layout.h" 42 45 43 46 #define BUFFER_SIZE 32 … … 88 91 89 92 /* 93 * TODO: Move somewhere else 94 */ 95 /* 96 #define BYTES_PER_LINE 12 97 98 static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 99 { 100 printf("%s\n", msg); 101 102 size_t i; 103 for (i = 0; i < length; i++) { 104 printf(" 0x%02X", buffer[i]); 105 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0)) 106 || (i + 1 == length)) { 107 printf("\n"); 108 } 109 } 110 } 111 */ 112 /* 113 * Copy-paste from srv/hid/kbd/generic/kbd.c 114 */ 115 116 /** Currently active modifiers. 117 * 118 * TODO: put to device? 119 */ 120 static unsigned mods = KM_NUM_LOCK; 121 122 /** Currently pressed lock keys. We track these to tackle autorepeat. 123 * 124 * TODO: put to device? 125 */ 126 static unsigned lock_keys; 127 128 #define NUM_LAYOUTS 3 129 130 static layout_op_t *layout[NUM_LAYOUTS] = { 131 &us_qwerty_op, 132 &us_dvorak_op, 133 &cz_op 134 }; 135 136 // TODO: put to device? 137 static int active_layout = 0; 138 139 static void kbd_push_ev(int type, unsigned int key) 140 { 141 console_event_t ev; 142 unsigned mod_mask; 143 144 // TODO: replace by our own parsing?? or are the key codes identical?? 145 switch (key) { 146 case KC_LCTRL: mod_mask = KM_LCTRL; break; 147 case KC_RCTRL: mod_mask = KM_RCTRL; break; 148 case KC_LSHIFT: mod_mask = KM_LSHIFT; break; 149 case KC_RSHIFT: mod_mask = KM_RSHIFT; break; 150 case KC_LALT: mod_mask = KM_LALT; break; 151 case KC_RALT: mod_mask = KM_RALT; break; 152 default: mod_mask = 0; break; 153 } 154 155 if (mod_mask != 0) { 156 if (type == KEY_PRESS) 157 mods = mods | mod_mask; 158 else 159 mods = mods & ~mod_mask; 160 } 161 162 switch (key) { 163 case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break; 164 case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break; 165 case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break; 166 default: mod_mask = 0; break; 167 } 168 169 if (mod_mask != 0) { 170 if (type == KEY_PRESS) { 171 /* 172 * Only change lock state on transition from released 173 * to pressed. This prevents autorepeat from messing 174 * up the lock state. 175 */ 176 mods = mods ^ (mod_mask & ~lock_keys); 177 lock_keys = lock_keys | mod_mask; 178 179 /* Update keyboard lock indicator lights. */ 180 // TODO 181 //kbd_ctl_set_ind(mods); 182 } else { 183 lock_keys = lock_keys & ~mod_mask; 184 } 185 } 186 /* 187 printf("type: %d\n", type); 188 printf("mods: 0x%x\n", mods); 189 printf("keycode: %u\n", key); 190 */ 191 /* 192 if (type == KEY_PRESS && (mods & KM_LCTRL) && 193 key == KC_F1) { 194 active_layout = 0; 195 layout[active_layout]->reset(); 196 return; 197 } 198 199 if (type == KEY_PRESS && (mods & KM_LCTRL) && 200 key == KC_F2) { 201 active_layout = 1; 202 layout[active_layout]->reset(); 203 return; 204 } 205 206 if (type == KEY_PRESS && (mods & KM_LCTRL) && 207 key == KC_F3) { 208 active_layout = 2; 209 layout[active_layout]->reset(); 210 return; 211 } 212 */ 213 ev.type = type; 214 ev.key = key; 215 ev.mods = mods; 216 217 ev.c = layout[active_layout]->parse_ev(&ev); 218 219 printf("Sending key %d to the console\n", ev.key); 220 assert(console_callback_phone != -1); 221 async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c); 222 } 223 /* 224 * End of copy-paste 225 */ 226 227 /* 228 * TODO: 229 * 1) key press / key release - how does the keyboard notify about release? 230 * 2) layouts (use the already defined), not important now 231 * 3) 232 */ 233 234 /* 90 235 * Callbacks for parser 91 236 */ … … 97 242 for (i = 0; i < count; ++i) { 98 243 printf("%d ", key_codes[i]); 244 // TODO: Key press / release 245 246 // TODO: NOT WORKING 247 unsigned int key = usbkbd_parse_scancode(key_codes[i]); 248 kbd_push_ev(KEY_PRESS, key); 99 249 } 100 250 printf("\n"); … … 264 414 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 265 415 // NULL); 266 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 267 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 416 printf("Calling usb_hid_boot_keyboard_input_report() with size %d\n", 417 actual_size); 418 //dump_buffer("bufffer: ", buffer, actual_size); 419 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 420 NULL); 421 if (rc != EOK) { 422 printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc); 423 } 268 424 } 269 425 270 426 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 271 427 { 272 return;273 274 428 int rc; 275 429 usb_handle_t handle; … … 289 443 }; 290 444 445 printf("Polling keyboard...\n"); 446 291 447 while (true) { 292 async_usleep(1000 * 1000 );448 async_usleep(1000 * 1000 * 2); 293 449 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 294 450 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 295 451 296 452 if (rc != EOK) { 453 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc); 297 454 continue; 298 455 } … … 300 457 rc = usb_drv_async_wait_for(handle); 301 458 if (rc != EOK) { 459 printf("Error in usb_drv_async_wait_for(): %d\n", rc); 302 460 continue; 303 461 } … … 308 466 */ 309 467 if (actual_size == 0) { 468 printf("Keyboard returned NAK\n"); 310 469 continue; 311 470 } … … 314 473 * TODO: Process pressed keys. 315 474 */ 475 printf("Calling usbkbd_process_interrupt_in()\n"); 316 476 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 317 477 } … … 334 494 // initialize device (get and process descriptors, get address, etc.) 335 495 usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev); 496 if (kbd_dev == NULL) { 497 printf("Error while initializing device.\n"); 498 return -1; 499 } 336 500 337 501 usbkbd_poll_keyboard(kbd_dev); -
uspace/lib/usb/src/hidparser.c
ra1d12f4 r7c169ce 35 35 #include <usb/classes/hidparser.h> 36 36 #include <errno.h> 37 #include <stdio.h> 37 38 38 39 /** Parse HID report descriptor. … … 120 121 item.logical_max = 255; 121 122 122 if (size != 8){123 return -1;123 if (size != 8) { 124 return ERANGE; 124 125 } 125 126 126 127 uint8_t keys[6]; 127 for (i=item.offset; i<item.count; i++) {128 keys[i -2] = data[i];128 for (i = 0; i < item.count; i++) { 129 keys[i] = data[i + item.offset]; 129 130 } 130 131
Note:
See TracChangeset
for help on using the changeset viewer.