Changes in / [7c169ce:a1d12f4] in mainline
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/virtusbkbd/keys.h
r7c169ce ra1d12f4 40 40 41 41 /** Maximum number of keys that can be pressed simultaneously. */ 42 #define KB_MAX_KEYS_AT_ONCE 642 #define KB_MAX_KEYS_AT_ONCE 4 43 43 44 44 /** Key code type. */ -
uspace/drv/usbkbd/Makefile
r7c169ce ra1d12f4 35 35 main.c \ 36 36 descparser.c \ 37 descdump.c \ 38 conv.c \ 39 us_qwerty.c 37 descdump.c 40 38 41 39 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/usbkbd/main.c
r7c169ce ra1d12f4 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 #include "layout.h"45 42 46 43 #define BUFFER_SIZE 32 … … 91 88 92 89 /* 93 * TODO: Move somewhere else94 */95 /*96 #define BYTES_PER_LINE 1297 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.c114 */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 3129 130 static layout_op_t *layout[NUM_LAYOUTS] = {131 &us_qwerty_op,132 &us_dvorak_op,133 &cz_op134 };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 else159 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 released173 * to pressed. This prevents autorepeat from messing174 * 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 // TODO181 //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-paste225 */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 now231 * 3)232 */233 234 /*235 90 * Callbacks for parser 236 91 */ … … 242 97 for (i = 0; i < count; ++i) { 243 98 printf("%d ", key_codes[i]); 244 // TODO: Key press / release245 246 // TODO: NOT WORKING247 unsigned int key = usbkbd_parse_scancode(key_codes[i]);248 kbd_push_ev(KEY_PRESS, key);249 99 } 250 100 printf("\n"); … … 414 264 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 415 265 // 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 } 266 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 267 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 424 268 } 425 269 426 270 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 427 271 { 272 return; 273 428 274 int rc; 429 275 usb_handle_t handle; … … 443 289 }; 444 290 445 printf("Polling keyboard...\n");446 447 291 while (true) { 448 async_usleep(1000 * 1000 * 2);292 async_usleep(1000 * 1000); 449 293 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 450 294 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 451 295 452 296 if (rc != EOK) { 453 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);454 297 continue; 455 298 } … … 457 300 rc = usb_drv_async_wait_for(handle); 458 301 if (rc != EOK) { 459 printf("Error in usb_drv_async_wait_for(): %d\n", rc);460 302 continue; 461 303 } … … 466 308 */ 467 309 if (actual_size == 0) { 468 printf("Keyboard returned NAK\n");469 310 continue; 470 311 } … … 473 314 * TODO: Process pressed keys. 474 315 */ 475 printf("Calling usbkbd_process_interrupt_in()\n");476 316 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 477 317 } … … 494 334 // initialize device (get and process descriptors, get address, etc.) 495 335 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 }500 336 501 337 usbkbd_poll_keyboard(kbd_dev); -
uspace/lib/usb/src/hidparser.c
r7c169ce ra1d12f4 35 35 #include <usb/classes/hidparser.h> 36 36 #include <errno.h> 37 #include <stdio.h>38 37 39 38 /** Parse HID report descriptor. … … 121 120 item.logical_max = 255; 122 121 123 if (size != 8){124 return ERANGE;122 if(size != 8){ 123 return -1; 125 124 } 126 125 127 126 uint8_t keys[6]; 128 for (i = 0; i <item.count; i++) {129 keys[i ] = data[i + item.offset];127 for(i=item.offset; i<item.count; i++) { 128 keys[i-2] = data[i]; 130 129 } 131 130
Note:
See TracChangeset
for help on using the changeset viewer.