Changes in / [ea991e84:1879a7d] in mainline
- Location:
- uspace
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/Makefile
rea991e84 r1879a7d 29 29 USPACE_PREFIX = ../.. 30 30 LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBUSB_PREFIX)/libusb.a 31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include 31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include -I. 32 32 BINARY = usbkbd 33 SRV_KBD = $(USPACE_PREFIX)/srv/hid/kbd 33 34 34 35 SOURCES = \ 35 36 main.c \ 36 37 descparser.c \ 37 descdump.c 38 descdump.c \ 39 conv.c \ 40 us_qwerty.c \ 41 us_dvorak.c \ 42 cz.c 38 43 39 44 include $(USPACE_PREFIX)/Makefile.common 45 46 us_qwerty.c: 47 ln -snf $(SRV_KBD)/layout/$@ $@ 48 49 us_dvorak.c: 50 ln -snf $(SRV_KBD)/layout/$@ $@ 51 52 cz.c: 53 ln -snf $(SRV_KBD)/layout/$@ $@ 54 55 -
uspace/drv/usbkbd/main.c
rea991e84 r1879a7d 41 41 #include <usb/devreq.h> 42 42 #include <usb/descriptor.h> 43 #include <io/console.h> 43 44 #include "descparser.h" 44 45 #include "descdump.h" 46 #include "conv.h" 47 #include "layout.h" 45 48 46 49 #define BUFFER_SIZE 32 … … 91 94 92 95 /* 96 * TODO: Move somewhere else 97 */ 98 /* 99 #define BYTES_PER_LINE 12 100 101 static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 102 { 103 printf("%s\n", msg); 104 105 size_t i; 106 for (i = 0; i < length; i++) { 107 printf(" 0x%02X", buffer[i]); 108 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0)) 109 || (i + 1 == length)) { 110 printf("\n"); 111 } 112 } 113 } 114 */ 115 /* 116 * Copy-paste from srv/hid/kbd/generic/kbd.c 117 */ 118 119 /** Currently active modifiers. 120 * 121 * TODO: put to device? 122 */ 123 static unsigned mods = KM_NUM_LOCK; 124 125 /** Currently pressed lock keys. We track these to tackle autorepeat. 126 * 127 * TODO: put to device? 128 */ 129 static unsigned lock_keys; 130 131 #define NUM_LAYOUTS 3 132 133 static layout_op_t *layout[NUM_LAYOUTS] = { 134 &us_qwerty_op, 135 &us_dvorak_op, 136 &cz_op 137 }; 138 139 static int active_layout = 0; 140 141 static void kbd_push_ev(int type, unsigned int key) 142 { 143 console_event_t ev; 144 unsigned mod_mask; 145 146 // TODO: replace by our own parsing?? or are the key codes identical?? 147 switch (key) { 148 case KC_LCTRL: mod_mask = KM_LCTRL; break; 149 case KC_RCTRL: mod_mask = KM_RCTRL; break; 150 case KC_LSHIFT: mod_mask = KM_LSHIFT; break; 151 case KC_RSHIFT: mod_mask = KM_RSHIFT; break; 152 case KC_LALT: mod_mask = KM_LALT; break; 153 case KC_RALT: mod_mask = KM_RALT; break; 154 default: mod_mask = 0; break; 155 } 156 157 if (mod_mask != 0) { 158 if (type == KEY_PRESS) 159 mods = mods | mod_mask; 160 else 161 mods = mods & ~mod_mask; 162 } 163 164 switch (key) { 165 case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break; 166 case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break; 167 case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break; 168 default: mod_mask = 0; break; 169 } 170 171 if (mod_mask != 0) { 172 if (type == KEY_PRESS) { 173 /* 174 * Only change lock state on transition from released 175 * to pressed. This prevents autorepeat from messing 176 * up the lock state. 177 */ 178 mods = mods ^ (mod_mask & ~lock_keys); 179 lock_keys = lock_keys | mod_mask; 180 181 /* Update keyboard lock indicator lights. */ 182 // TODO 183 //kbd_ctl_set_ind(mods); 184 } else { 185 lock_keys = lock_keys & ~mod_mask; 186 } 187 } 188 /* 189 printf("type: %d\n", type); 190 printf("mods: 0x%x\n", mods); 191 printf("keycode: %u\n", key); 192 */ 193 194 if (type == KEY_PRESS && (mods & KM_LCTRL) && 195 key == KC_F1) { 196 active_layout = 0; 197 layout[active_layout]->reset(); 198 return; 199 } 200 201 if (type == KEY_PRESS && (mods & KM_LCTRL) && 202 key == KC_F2) { 203 active_layout = 1; 204 layout[active_layout]->reset(); 205 return; 206 } 207 208 if (type == KEY_PRESS && (mods & KM_LCTRL) && 209 key == KC_F3) { 210 active_layout = 2; 211 layout[active_layout]->reset(); 212 return; 213 } 214 215 ev.type = type; 216 ev.key = key; 217 ev.mods = mods; 218 219 ev.c = layout[active_layout]->parse_ev(&ev); 220 221 printf("Sending key %d to the console\n", ev.key); 222 assert(console_callback_phone != -1); 223 async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c); 224 } 225 /* 226 * End of copy-paste 227 */ 228 229 /* 230 * TODO: 231 * 1) key press / key release - how does the keyboard notify about release? 232 * 2) layouts (use the already defined), not important now 233 * 3) 234 */ 235 236 /* 93 237 * Callbacks for parser 94 238 */ 95 239 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count, 96 240 uint8_t modifiers, void *arg) 97 241 { 98 242 printf("Got keys: "); … … 100 244 for (i = 0; i < count; ++i) { 101 245 printf("%d ", key_codes[i]); 246 // TODO: Key press / release 247 248 // TODO: NOT WORKING 249 unsigned int key = usbkbd_parse_scancode(key_codes[i]); 250 kbd_push_ev(KEY_PRESS, key); 102 251 } 103 252 printf("\n"); … … 267 416 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 268 417 // NULL); 269 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 270 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 418 printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n", 419 actual_size); 420 //dump_buffer("bufffer: ", buffer, actual_size); 421 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 422 NULL); 423 if (rc != EOK) { 424 printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc); 425 } 271 426 } 272 427 273 428 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 274 429 { 275 return;276 277 430 int rc; 278 431 usb_handle_t handle; … … 292 445 }; 293 446 447 printf("Polling keyboard...\n"); 448 294 449 while (true) { 295 async_usleep(1000 * 1000 );450 async_usleep(1000 * 1000 * 2); 296 451 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 297 452 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 298 453 299 454 if (rc != EOK) { 455 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc); 300 456 continue; 301 457 } … … 303 459 rc = usb_drv_async_wait_for(handle); 304 460 if (rc != EOK) { 461 printf("Error in usb_drv_async_wait_for(): %d\n", rc); 305 462 continue; 306 463 } … … 311 468 */ 312 469 if (actual_size == 0) { 470 printf("Keyboard returned NAK\n"); 313 471 continue; 314 472 } … … 317 475 * TODO: Process pressed keys. 318 476 */ 477 printf("Calling usbkbd_process_interrupt_in()\n"); 319 478 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 320 479 } … … 337 496 // initialize device (get and process descriptors, get address, etc.) 338 497 usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev); 498 if (kbd_dev == NULL) { 499 printf("Error while initializing device.\n"); 500 return -1; 501 } 339 502 340 503 usbkbd_poll_keyboard(kbd_dev); -
uspace/lib/usb/src/hidparser.c
rea991e84 r1879a7d 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.