Changes in uspace/drv/usbkbd/kbddev.c [e4153ea:0533b03] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbkbd/kbddev.c
re4153ea r0533b03 56 56 #include <usb/classes/hidreq.h> 57 57 #include <usb/classes/hidreport.h> 58 #include <usb/classes/hid/utled.h>59 58 60 59 #include <usb/devdrv.h> … … 70 69 static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK; 71 70 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; 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; 84 82 85 83 /** Default idle rate for keyboards. */ … … 265 263 static void usb_kbd_set_led(usb_kbd_t *kbd_dev) 266 264 { 267 u nsigned 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;265 uint8_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; 283 281 } 284 282 … … 286 284 287 285 usb_log_debug("Creating output report.\n"); 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"); 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)); 296 291 return; 297 292 } 298 293 299 294 usb_log_debug("Output report buffer: %s\n", 300 usb_debug_str_buffer(kbd_dev->output_buffer, kbd_dev->output_size, 301 0)); 295 usb_debug_str_buffer(buffer, BOOTP_BUFFER_OUT_SIZE, 0)); 296 297 assert(kbd_dev->usb_dev != NULL); 302 298 303 299 usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe, 304 300 kbd_dev->usb_dev->interface_no, USB_HID_REPORT_TYPE_OUTPUT, 305 kbd_dev->output_buffer, kbd_dev->output_size);301 buffer, BOOTP_BUFFER_OUT_SIZE); 306 302 } 307 303 … … 454 450 * First of all, check if the kbd have reported phantom state. 455 451 * 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. 452 * this must be changed as we don't know which keys are modifiers 453 * and which are regular keys. 460 454 */ 461 455 i = 0; 462 while (i < count && key_codes[i] != ERROR_ROLLOVER) { 456 // all fields should report Error Rollover 457 while (i < count && 458 key_codes[i] == BOOTP_ERROR_ROLLOVER) { 463 459 ++i; 464 460 } 465 if (i != count) {461 if (i == count) { 466 462 usb_log_debug("Phantom state occured.\n"); 467 463 // phantom state, do nothing … … 590 586 */ 591 587 static void usb_kbd_process_data(usb_kbd_t *kbd_dev, 592 uint8_t *buffer, size_t actual_size)588 uint8_t *buffer, size_t actual_size) 593 589 { 594 590 assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED); … … 764 760 usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count); 765 761 766 kbd_dev->keys = (uint8_t *)calloc(kbd_dev->key_count, sizeof(uint8_t)); 762 kbd_dev->keys = (uint8_t *)calloc( 763 kbd_dev->key_count, sizeof(uint8_t)); 767 764 768 765 if (kbd_dev->keys == NULL) { … … 771 768 } 772 769 773 /*774 * Output report775 */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 locks810 */811 770 kbd_dev->modifiers = 0; 812 771 kbd_dev->mods = DEFAULT_ACTIVE_MODS; 813 772 kbd_dev->lock_keys = 0; 814 773 815 /*816 * Autorepeat817 */818 774 kbd_dev->repeat.key_new = 0; 819 775 kbd_dev->repeat.key_repeated = 0; … … 923 879 } 924 880 925 // free the output buffer926 usb_hid_report_output_free((*kbd_dev)->output_buffer);927 928 881 /* TODO: what about the USB device structure?? */ 929 882
Note:
See TracChangeset
for help on using the changeset viewer.