Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbkbd/kbddev.c

    r0533b03 re4153ea  
    5656#include <usb/classes/hidreq.h>
    5757#include <usb/classes/hidreport.h>
     58#include <usb/classes/hid/utled.h>
    5859
    5960#include <usb/devdrv.h>
     
    6970static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
    7071
    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;
     83static const uint8_t ERROR_ROLLOVER = 1;
    8284
    8385/** Default idle rate for keyboards. */
     
    263265static void usb_kbd_set_led(usb_kbd_t *kbd_dev)
    264266{
    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;
     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;
    281283        }
    282284
     
    284286       
    285287        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");
    291296                return;
    292297        }
    293298       
    294299        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));
    298302       
    299303        usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe,
    300304            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);
    302306}
    303307
     
    450454         * First of all, check if the kbd have reported phantom state.
    451455         *
    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.
    454460         */
    455461        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) {
    459463                ++i;
    460464        }
    461         if (i == count) {
     465        if (i != count) {
    462466                usb_log_debug("Phantom state occured.\n");
    463467                // phantom state, do nothing
     
    586590 */
    587591static void usb_kbd_process_data(usb_kbd_t *kbd_dev,
    588                                     uint8_t *buffer, size_t actual_size)
     592                                 uint8_t *buffer, size_t actual_size)
    589593{
    590594        assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
     
    760764        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    761765       
    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));
    764767       
    765768        if (kbd_dev->keys == NULL) {
     
    768771        }
    769772       
     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         */     
    770811        kbd_dev->modifiers = 0;
    771812        kbd_dev->mods = DEFAULT_ACTIVE_MODS;
    772813        kbd_dev->lock_keys = 0;
    773814       
     815        /*
     816         * Autorepeat
     817         */     
    774818        kbd_dev->repeat.key_new = 0;
    775819        kbd_dev->repeat.key_repeated = 0;
     
    879923        }
    880924       
     925        // free the output buffer
     926        usb_hid_report_output_free((*kbd_dev)->output_buffer);
     927       
    881928        /* TODO: what about the USB device structure?? */
    882929
Note: See TracChangeset for help on using the changeset viewer.