Changeset 1b9c0e2 in mainline for uspace/drv/usbkbd/kbddev.c
- Timestamp:
- 2011-04-01T14:41:35Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 03eea27, 8e7d724
- Parents:
- 98169ab (diff), e4153ea (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 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/kbddev.c
r98169ab r1b9c0e2 56 56 #include <usb/classes/hidreq.h> 57 57 #include <usb/classes/hidreport.h> 58 #include <usb/classes/hid/utled.h> 58 59 59 60 #include <usb/devdrv.h> … … 69 70 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; 70 71 71 /** Boot protocol report size (key part). */ 72 static const size_t BOOTP_REPORT_SIZE = 6; 73 74 /** Boot protocol total report size. */ 75 static const size_t BOOTP_BUFFER_SIZE = 8; 76 77 /** Boot protocol output report size. */ 78 static const size_t BOOTP_BUFFER_OUT_SIZE = 1; 79 80 /** Boot protocol error key code. */ 81 static const uint8_t BOOTP_ERROR_ROLLOVER = 1; 72 ///** Boot protocol report size (key part). */ 73 //static const size_t BOOTP_REPORT_SIZE = 6; 74 75 ///** Boot protocol total report size. */ 76 //static const size_t BOOTP_BUFFER_SIZE = 8; 77 78 ///** Boot protocol output report size. */ 79 //static const size_t BOOTP_BUFFER_OUT_SIZE = 1; 80 81 ///** Boot protocol error key code. */ 82 //static const uint8_t BOOTP_ERROR_ROLLOVER = 1; 83 static const uint8_t ERROR_ROLLOVER = 1; 82 84 83 85 /** Default idle rate for keyboards. */ … … 263 265 static void usb_kbd_set_led(usb_kbd_t *kbd_dev) 264 266 { 265 u int8_t buffer[BOOTP_BUFFER_OUT_SIZE];266 int rc= 0;267 268 memset( buffer, 0, BOOTP_BUFFER_OUT_SIZE);269 uint8_t leds = 0;270 271 if (kbd_dev->mods & KM_NUM_LOCK) {272 leds |= USB_HID_LED_NUM_LOCK;273 }274 275 if (kbd_dev->mods & KM_CAPS_LOCK) {276 leds |= USB_HID_LED_CAPS_LOCK;277 }278 279 if (kbd_dev->mods & KM_SCROLL_LOCK) {280 leds |= USB_HID_LED_SCROLL_LOCK;267 unsigned i = 0; 268 269 /* Reset the LED data. */ 270 memset(kbd_dev->led_data, 0, kbd_dev->led_output_size * sizeof(int32_t)); 271 272 if ((kbd_dev->mods & KM_NUM_LOCK) && (i < kbd_dev->led_output_size)) { 273 kbd_dev->led_data[i++] = USB_HID_LED_NUM_LOCK; 274 } 275 276 if ((kbd_dev->mods & KM_CAPS_LOCK) && (i < kbd_dev->led_output_size)) { 277 kbd_dev->led_data[i++] = USB_HID_LED_CAPS_LOCK; 278 } 279 280 if ((kbd_dev->mods & KM_SCROLL_LOCK) 281 && (i < kbd_dev->led_output_size)) { 282 kbd_dev->led_data[i++] = USB_HID_LED_SCROLL_LOCK; 281 283 } 282 284 … … 284 286 285 287 usb_log_debug("Creating output report.\n"); 286 usb_log_debug("Leds: 0x%x\n", leds); 287 if ((rc = usb_hid_boot_keyboard_output_report( 288 leds, buffer, BOOTP_BUFFER_OUT_SIZE)) != EOK) { 289 usb_log_warning("Error composing output report to the keyboard:" 290 "%s.\n", str_error(rc)); 288 289 int rc = usb_hid_report_output_translate(kbd_dev->parser, 290 kbd_dev->led_path, USB_HID_PATH_COMPARE_END, kbd_dev->output_buffer, 291 kbd_dev->output_size, kbd_dev->led_data, kbd_dev->led_output_size); 292 293 if (rc != EOK) { 294 usb_log_warning("Error translating LED output to output report" 295 ".\n"); 291 296 return; 292 297 } 293 298 294 299 usb_log_debug("Output report buffer: %s\n", 295 usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0)); 296 297 assert(kbd_dev->usb_dev != NULL); 300 usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size, 301 0)); 298 302 299 303 usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe, 300 304 kbd_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT, 301 buffer, BOOTP_BUFFER_OUT_SIZE);305 kbd_dev->output_buffer, kbd_dev->output_size); 302 306 } 303 307 … … 450 454 * First of all, check if the kbd have reported phantom state. 451 455 * 452 * this must be changed as we don't know which keys are modifiers 453 * and which are regular keys. 456 * As there is no way to distinguish keys from modifiers, we do not have 457 * a way to check that 'all keys report Error Rollover'. We thus check 458 * if there is at least one such error and in such case we ignore the 459 * whole input report. 454 460 */ 455 461 i = 0; 456 // all fields should report Error Rollover 457 while (i < count && 458 key_codes[i] == BOOTP_ERROR_ROLLOVER) { 462 while (i < count && key_codes[i] != ERROR_ROLLOVER) { 459 463 ++i; 460 464 } 461 if (i == count) {465 if (i != count) { 462 466 usb_log_debug("Phantom state occured.\n"); 463 467 // phantom state, do nothing … … 586 590 */ 587 591 static void usb_kbd_process_data(usb_kbd_t *kbd_dev, 588 592 uint8_t *buffer, size_t actual_size) 589 593 { 590 594 assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED); … … 760 764 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 761 765 762 kbd_dev->keys = (uint8_t *)calloc( 763 kbd_dev->key_count, sizeof(uint8_t)); 766 kbd_dev->keys = (uint8_t *)calloc(kbd_dev->key_count, sizeof(uint8_t)); 764 767 765 768 if (kbd_dev->keys == NULL) { … … 768 771 } 769 772 773 /* 774 * Output report 775 */ 776 kbd_dev->output_size = 0; 777 kbd_dev->output_buffer = usb_hid_report_output(kbd_dev->parser, 778 &kbd_dev->output_size); 779 if (kbd_dev->output_buffer == NULL) { 780 usb_log_warning("Error creating output report buffer.\n"); 781 free(kbd_dev->keys); 782 return ENOMEM; /* TODO: other error code */ 783 } 784 785 usb_log_debug("Output buffer size: %zu\n", kbd_dev->output_size); 786 787 kbd_dev->led_path = usb_hid_report_path(); 788 usb_hid_report_path_append_item( 789 kbd_dev->led_path, USB_HIDUT_PAGE_LED, 0); 790 791 kbd_dev->led_output_size = usb_hid_report_output_size(kbd_dev->parser, 792 kbd_dev->led_path, USB_HID_PATH_COMPARE_END); 793 794 usb_log_debug("Output report size (in items): %zu\n", 795 kbd_dev->led_output_size); 796 797 kbd_dev->led_data = (int32_t *)calloc( 798 kbd_dev->led_output_size, sizeof(int32_t)); 799 800 if (kbd_dev->led_data == NULL) { 801 usb_log_warning("Error creating buffer for LED output report." 802 "\n"); 803 free(kbd_dev->keys); 804 usb_hid_report_output_free(kbd_dev->output_buffer); 805 return ENOMEM; 806 } 807 808 /* 809 * Modifiers and locks 810 */ 770 811 kbd_dev->modifiers = 0; 771 812 kbd_dev->mods = DEFAULT_ACTIVE_MODS; 772 813 kbd_dev->lock_keys = 0; 773 814 815 /* 816 * Autorepeat 817 */ 774 818 kbd_dev->repeat.key_new = 0; 775 819 kbd_dev->repeat.key_repeated = 0; … … 879 923 } 880 924 925 // free the output buffer 926 usb_hid_report_output_free((*kbd_dev)->output_buffer); 927 881 928 /* TODO: what about the USB device structure?? */ 882 929
Note:
See TracChangeset
for help on using the changeset viewer.