Changeset 4687fcd4 in mainline for uspace/drv/usbhid/main.c
- Timestamp:
- 2011-01-29T10:19:04Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 72e19f50
- Parents:
- 67a1b78 (diff), a09128c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbhid/main.c
r67a1b78 r4687fcd4 1 1 /* 2 2 * Copyright (c) 2010 Vojtech Horky 3 * Copyright (c) 2011 Lubos Slovak 3 4 * All rights reserved. 4 5 * … … 26 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 28 */ 29 28 30 /** @addtogroup drvusbhid 29 31 * @{ 30 32 */ 33 /** 34 * @file 35 * Main routines of USB HID driver. 36 */ 37 31 38 #include <usb/usbdrv.h> 32 39 #include <driver.h> … … 41 48 #include <usb/devreq.h> 42 49 #include <usb/descriptor.h> 50 #include <io/console.h> 43 51 #include "descparser.h" 44 52 #include "descdump.h" 53 #include "conv.h" 54 #include "layout.h" 45 55 46 56 #define BUFFER_SIZE 32 47 #define NAME "usb kbd"57 #define NAME "usbhid" 48 58 49 59 #define GUESSED_POLL_ENDPOINT 1 … … 91 101 92 102 /* 103 * TODO: Move somewhere else 104 */ 105 /* 106 #define BYTES_PER_LINE 12 107 108 static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length) 109 { 110 printf("%s\n", msg); 111 112 size_t i; 113 for (i = 0; i < length; i++) { 114 printf(" 0x%02X", buffer[i]); 115 if (((i > 0) && (((i+1) % BYTES_PER_LINE) == 0)) 116 || (i + 1 == length)) { 117 printf("\n"); 118 } 119 } 120 } 121 */ 122 /* 123 * Copy-paste from srv/hid/kbd/generic/kbd.c 124 */ 125 126 /** Currently active modifiers. 127 * 128 * TODO: put to device? 129 */ 130 static unsigned mods = KM_NUM_LOCK; 131 132 /** Currently pressed lock keys. We track these to tackle autorepeat. 133 * 134 * TODO: put to device? 135 */ 136 static unsigned lock_keys; 137 138 #define NUM_LAYOUTS 3 139 140 static layout_op_t *layout[NUM_LAYOUTS] = { 141 &us_qwerty_op, 142 &us_dvorak_op, 143 &cz_op 144 }; 145 146 static int active_layout = 0; 147 148 static void kbd_push_ev(int type, unsigned int key) 149 { 150 console_event_t ev; 151 unsigned mod_mask; 152 153 // TODO: replace by our own parsing?? or are the key codes identical?? 154 switch (key) { 155 case KC_LCTRL: mod_mask = KM_LCTRL; break; 156 case KC_RCTRL: mod_mask = KM_RCTRL; break; 157 case KC_LSHIFT: mod_mask = KM_LSHIFT; break; 158 case KC_RSHIFT: mod_mask = KM_RSHIFT; break; 159 case KC_LALT: mod_mask = KM_LALT; break; 160 case KC_RALT: mod_mask = KM_RALT; break; 161 default: mod_mask = 0; break; 162 } 163 164 if (mod_mask != 0) { 165 if (type == KEY_PRESS) 166 mods = mods | mod_mask; 167 else 168 mods = mods & ~mod_mask; 169 } 170 171 switch (key) { 172 case KC_CAPS_LOCK: mod_mask = KM_CAPS_LOCK; break; 173 case KC_NUM_LOCK: mod_mask = KM_NUM_LOCK; break; 174 case KC_SCROLL_LOCK: mod_mask = KM_SCROLL_LOCK; break; 175 default: mod_mask = 0; break; 176 } 177 178 if (mod_mask != 0) { 179 if (type == KEY_PRESS) { 180 /* 181 * Only change lock state on transition from released 182 * to pressed. This prevents autorepeat from messing 183 * up the lock state. 184 */ 185 mods = mods ^ (mod_mask & ~lock_keys); 186 lock_keys = lock_keys | mod_mask; 187 188 /* Update keyboard lock indicator lights. */ 189 // TODO 190 //kbd_ctl_set_ind(mods); 191 } else { 192 lock_keys = lock_keys & ~mod_mask; 193 } 194 } 195 /* 196 printf("type: %d\n", type); 197 printf("mods: 0x%x\n", mods); 198 printf("keycode: %u\n", key); 199 */ 200 201 if (type == KEY_PRESS && (mods & KM_LCTRL) && 202 key == KC_F1) { 203 active_layout = 0; 204 layout[active_layout]->reset(); 205 return; 206 } 207 208 if (type == KEY_PRESS && (mods & KM_LCTRL) && 209 key == KC_F2) { 210 active_layout = 1; 211 layout[active_layout]->reset(); 212 return; 213 } 214 215 if (type == KEY_PRESS && (mods & KM_LCTRL) && 216 key == KC_F3) { 217 active_layout = 2; 218 layout[active_layout]->reset(); 219 return; 220 } 221 222 ev.type = type; 223 ev.key = key; 224 ev.mods = mods; 225 226 ev.c = layout[active_layout]->parse_ev(&ev); 227 228 printf("Sending key %d to the console\n", ev.key); 229 assert(console_callback_phone != -1); 230 async_msg_4(console_callback_phone, KBD_EVENT, ev.type, ev.key, ev.mods, ev.c); 231 } 232 /* 233 * End of copy-paste 234 */ 235 236 /* 237 * TODO: 238 * 1) key press / key release - how does the keyboard notify about release? 239 * 2) layouts (use the already defined), not important now 240 * 3) 241 */ 242 243 /* 93 244 * Callbacks for parser 94 245 */ 95 246 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count, 96 247 uint8_t modifiers, void *arg) 97 248 { 98 249 printf("Got keys: "); … … 100 251 for (i = 0; i < count; ++i) { 101 252 printf("%d ", key_codes[i]); 253 // TODO: Key press / release 254 255 // TODO: NOT WORKING 256 unsigned int key = usbkbd_parse_scancode(key_codes[i]); 257 kbd_push_ev(KEY_PRESS, key); 102 258 } 103 259 printf("\n"); … … 267 423 //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks, 268 424 // NULL); 269 printf("Calling usb_hid_boot_keyboard_input_report()...\n)"); 270 usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL); 425 printf("Calling usb_hid_boot_keyboard_input_report() with size %zu\n", 426 actual_size); 427 //dump_buffer("bufffer: ", buffer, actual_size); 428 int rc = usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, 429 NULL); 430 if (rc != EOK) { 431 printf("Error in usb_hid_boot_keyboard_input_report(): %d\n", rc); 432 } 271 433 } 272 434 273 435 static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev) 274 436 { 275 return;276 277 437 int rc; 278 438 usb_handle_t handle; … … 292 452 }; 293 453 454 printf("Polling keyboard...\n"); 455 294 456 while (true) { 295 async_usleep(1000 * 1000 );457 async_usleep(1000 * 1000 * 2); 296 458 rc = usb_drv_async_interrupt_in(kbd_dev->device->parent_phone, 297 459 poll_target, buffer, BUFFER_SIZE, &actual_size, &handle); 298 460 299 461 if (rc != EOK) { 462 printf("Error in usb_drv_async_interrupt_in(): %d\n", rc); 300 463 continue; 301 464 } … … 303 466 rc = usb_drv_async_wait_for(handle); 304 467 if (rc != EOK) { 468 printf("Error in usb_drv_async_wait_for(): %d\n", rc); 305 469 continue; 306 470 } … … 311 475 */ 312 476 if (actual_size == 0) { 477 printf("Keyboard returned NAK\n"); 313 478 continue; 314 479 } … … 317 482 * TODO: Process pressed keys. 318 483 */ 484 printf("Calling usbkbd_process_interrupt_in()\n"); 319 485 usbkbd_process_interrupt_in(kbd_dev, buffer, actual_size); 320 486 } … … 337 503 // initialize device (get and process descriptors, get address, etc.) 338 504 usb_hid_dev_kbd_t *kbd_dev = usbkbd_init_device(dev); 505 if (kbd_dev == NULL) { 506 printf("Error while initializing device.\n"); 507 return -1; 508 } 339 509 340 510 usbkbd_poll_keyboard(kbd_dev);
Note:
See TracChangeset
for help on using the changeset viewer.