Changes in / [3ee48f2:2b96463] in mainline
- Location:
- uspace
- Files:
-
- 4 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/Makefile
r3ee48f2 r2b96463 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 -I.31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBUSB_PREFIX)/include 32 32 BINARY = usbkbd 33 SRV_KBD = $(USPACE_PREFIX)/srv/hid/kbd34 33 35 34 SOURCES = \ 36 35 main.c \ 37 36 descparser.c \ 38 descdump.c \ 39 conv.c \ 40 us_qwerty.c \ 41 us_dvorak.c \ 42 cz.c 37 descdump.c 43 38 44 39 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
r3ee48f2 r2b96463 41 41 #include <usb/devreq.h> 42 42 #include <usb/descriptor.h> 43 #include <io/console.h>44 43 #include "descparser.h" 45 44 #include "descdump.h" 46 #include "conv.h"47 #include "layout.h"48 45 49 46 #define BUFFER_SIZE 32 … … 94 91 95 92 /* 96 * TODO: Move somewhere else97 */98 /*99 #define BYTES_PER_LINE 12100 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.c117 */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 3132 133 static layout_op_t *layout[NUM_LAYOUTS] = {134 &us_qwerty_op,135 &us_dvorak_op,136 &cz_op137 };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 else161 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 released175 * to pressed. This prevents autorepeat from messing176 * 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 // TODO183 //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-paste227 */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 now233 * 3)234 */235 236 /*237 93 * Callbacks for parser 238 94 */ 239 95 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count, 240 uint8_t modifiers, void *arg)96 uint8_t modifiers, void *arg) 241 97 { 242 98 printf("Got keys: "); … … 244 100 for (i = 0; i < count; ++i) { 245 101 printf("%d ", key_codes[i]); 246 // TODO: Key press / release247 248 // TODO: NOT WORKING249 unsigned int key = usbkbd_parse_scancode(key_codes[i]);250 kbd_push_ev(KEY_PRESS, key);251 102 } 252 103 printf("\n"); … … 416 267 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 417 268 // NULL); 418 printf("Calling usb_hid_boot_keyboard_input_report() with size %d\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 } 269 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 270 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 426 271 } 427 272 428 273 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 429 274 { 275 return; 276 430 277 int rc; 431 278 usb_handle_t handle; … … 445 292 }; 446 293 447 printf("Polling keyboard...\n");448 449 294 while (true) { 450 async_usleep(1000 * 1000 * 2);295 async_usleep(1000 * 1000); 451 296 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 452 297 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 453 298 454 299 if (rc != EOK) { 455 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);456 300 continue; 457 301 } … … 459 303 rc = usb_drv_async_wait_for(handle); 460 304 if (rc != EOK) { 461 printf("Error in usb_drv_async_wait_for(): %d\n", rc);462 305 continue; 463 306 } … … 468 311 */ 469 312 if (actual_size == 0) { 470 printf("Keyboard returned NAK\n");471 313 continue; 472 314 } … … 475 317 * TODO: Process pressed keys. 476 318 */ 477 printf("Calling usbkbd_process_interrupt_in()\n");478 319 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 479 320 } … … 496 337 // initialize device (get and process descriptors, get address, etc.) 497 338 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 }502 339 503 340 usbkbd_poll_keyboard(kbd_dev); -
uspace/lib/usb/src/hidparser.c
r3ee48f2 r2b96463 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.