Changes in uspace/drv/usbkbd/main.c [11797d5:ba54451] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/main.c
r11797d5 rba54451 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 /** @addtogroup drvusbhid 29 * @{ 30 */ 28 31 #include <usb/usbdrv.h> 29 32 #include <driver.h> … … 38 41 #include <usb/devreq.h> 39 42 #include <usb/descriptor.h> 40 #include <io/console.h>41 43 #include "descparser.h" 42 44 #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 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 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 else158 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 released172 * to pressed. This prevents autorepeat from messing173 * 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 // TODO180 //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-paste224 */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 now230 * 3)231 */232 233 /*234 93 * Callbacks for parser 235 94 */ 236 95 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count, 237 uint8_t modifiers, void *arg)96 uint8_t modifiers, void *arg) 238 97 { 239 98 printf("Got keys: "); … … 241 100 for (i = 0; i < count; ++i) { 242 101 printf("%d ", key_codes[i]); 243 // TODO: Key press / release244 245 // TODO: NOT WORKING246 unsigned int key = usbkbd_parse_scancode(key_codes[i]);247 kbd_push_ev(KEY_PRESS, key);248 102 } 249 103 printf("\n"); … … 413 267 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 414 268 // 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 } 269 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 270 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 423 271 } 424 272 425 273 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 426 274 { 275 return; 276 427 277 int rc; 428 278 usb_handle_t handle; … … 442 292 }; 443 293 444 printf("Polling keyboard...\n");445 446 294 while (true) { 447 async_usleep(1000 * 1000 * 2);295 async_usleep(1000 * 1000); 448 296 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 449 297 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 450 298 451 299 if (rc != EOK) { 452 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc);453 300 continue; 454 301 } … … 456 303 rc = usb_drv_async_wait_for(handle); 457 304 if (rc != EOK) { 458 printf("Error in usb_drv_async_wait_for(): %d\n", rc);459 305 continue; 460 306 } … … 465 311 */ 466 312 if (actual_size == 0) { 467 printf("Keyboard returned NAK\n");468 313 continue; 469 314 } … … 472 317 * TODO: Process pressed keys. 473 318 */ 474 printf("Calling usbkbd_process_interrupt_in()\n");475 319 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 476 320 } … … 493 337 // initialize device (get and process descriptors, get address, etc.) 494 338 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 }499 339 500 340 usbkbd_poll_keyboard(kbd_dev); … … 557 397 return driver_main(&kbd_driver); 558 398 } 399 400 /** 401 * @} 402 */
Note:
See TracChangeset
for help on using the changeset viewer.