Changes in uspace/drv/usbkbd/main.c [ba54451:11797d5] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
rba54451 r11797d5 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup drvusbhid29 * @{30 */31 28 #include <usb/usbdrv.h> 32 29 #include <driver.h> … … 41 38 #include <usb/devreq.h> 42 39 #include <usb/descriptor.h> 40 #include <io/console.h> 43 41 #include "descparser.h" 44 42 #include "descdump.h" 43 #include "conv.h" 44 #include "layout.h" 45 45 46 46 #define BUFFER_SIZE 32 … … 91 91 92 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 static int active_layout = 0; 137 138 static void kbd_push_ev(int type, unsigned int key) 139 { 140 console_event_t ev; 141 unsigned mod_mask; 142 143 // TODO: replace by our own parsing?? or are the key codes identical?? 144 switch (key) { 145 case KC_LCTRL: mod_mask = KM_LCTRL; break; 146 case KC_RCTRL: mod_mask = KM_RCTRL; break; 147 case KC_LSHIFT: mod_mask = KM_LSHIFT; break; 148 case KC_RSHIFT: mod_mask = KM_RSHIFT; break; 149 case KC_LALT: mod_mask = KM_LALT; break; 150 case KC_RALT: mod_mask = KM_RALT; break; 151 default: mod_mask = 0; break; 152 } 153 154 if (mod_mask != 0) { 155 if (type == KEY_PRESS) 156 mods = mods | mod_mask; 157 else 158 mods = mods & ~mod_mask; 159 } 160 161 switch (key) { 162 case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break; 163 case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break; 164 case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break; 165 default: mod_mask = 0; break; 166 } 167 168 if (mod_mask != 0) { 169 if (type == KEY_PRESS) { 170 /* 171 * Only change lock state on transition from released 172 * to pressed. This prevents autorepeat from messing 173 * up the lock state. 174 */ 175 mods = mods ^ (mod_mask & ~lock_keys); 176 lock_keys = lock_keys | mod_mask; 177 178 /* Update keyboard lock indicator lights. */ 179 // TODO 180 //kbd_ctl_set_ind(mods); 181 } else { 182 lock_keys = lock_keys & ~mod_mask; 183 } 184 } 185 /* 186 printf("type: %d\n", type); 187 printf("mods: 0x%x\n", mods); 188 printf("keycode: %u\n", key); 189 */ 190 191 if (type == KEY_PRESS && (mods & KM_LCTRL) && 192 key == KC_F1) { 193 active_layout = 0; 194 layout[active_layout]->reset(); 195 return; 196 } 197 198 if (type == KEY_PRESS && (mods & KM_LCTRL) && 199 key == KC_F2) { 200 active_layout = 1; 201 layout[active_layout]->reset(); 202 return; 203 } 204 205 if (type == KEY_PRESS && (mods & KM_LCTRL) && 206 key == KC_F3) { 207 active_layout = 2; 208 layout[active_layout]->reset(); 209 return; 210 } 211 212 ev.type = type; 213 ev.key = key; 214 ev.mods = mods; 215 216 ev.c = layout[active_layout]->parse_ev(&ev); 217 218 printf("Sending key %d to the console\n", ev.key); 219 assert(console_callback_phone != -1); 220 async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c); 221 } 222 /* 223 * End of copy-paste 224 */ 225 226 /* 227 * TODO: 228 * 1) key press / key release - how does the keyboard notify about release? 229 * 2) layouts (use the already defined), not important now 230 * 3) 231 */ 232 233 /* 93 234 * Callbacks for parser 94 235 */ 95 236 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count, 96 237 uint8_t modifiers, void *arg) 97 238 { 98 239 printf("Got keys: "); … … 100 241 for (i = 0; i < count; ++i) { 101 242 printf("%d ", key_codes[i]); 243 // TODO: Key press / release 244 245 // TODO: NOT WORKING 246 unsigned int key = usbkbd_parse_scancode(key_codes[i]); 247 kbd_push_ev(KEY_PRESS, key); 102 248 } 103 249 printf("\n"); … … 267 413 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 268 414 // NULL); 269 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 270 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 415 printf("Calling usb_hid_boot_keyboard_input_report() with size %d\n", 416 actual_size); 417 //dump_buffer("bufffer: ", buffer, actual_size); 418 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 419 NULL); 420 if (rc != EOK) { 421 printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc); 422 } 271 423 } 272 424 273 425 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 274 426 { 275 return;276 277 427 int rc; 278 428 usb_handle_t handle; … … 292 442 }; 293 443 444 printf("Polling keyboard...\n"); 445 294 446 while (true) { 295 async_usleep(1000 * 1000 );447 async_usleep(1000 * 1000 * 2); 296 448 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 297 449 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 298 450 299 451 if (rc != EOK) { 452 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc); 300 453 continue; 301 454 } … … 303 456 rc = usb_drv_async_wait_for(handle); 304 457 if (rc != EOK) { 458 printf("Error in usb_drv_async_wait_for(): %d\n", rc); 305 459 continue; 306 460 } … … 311 465 */ 312 466 if (actual_size == 0) { 467 printf("Keyboard returned NAK\n"); 313 468 continue; 314 469 } … … 317 472 * TODO: Process pressed keys. 318 473 */ 474 printf("Calling usbkbd_process_interrupt_in()\n"); 319 475 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 320 476 } … … 337 493 // initialize device (get and process descriptors, get address, etc.) 338 494 usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev); 495 if (kbd_dev == NULL) { 496 printf("Error while initializing device.\n"); 497 return -1; 498 } 339 499 340 500 usbkbd_poll_keyboard(kbd_dev); … … 397 557 return driver_main(&kbd_driver); 398 558 } 399 400 /**401 * @}402 */
Note:
See TracChangeset
for help on using the changeset viewer.