Ignore:
File:
1 edited

Legend:

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

    re4153ea r0533b03  
    5656#include <usb/classes/hidreq.h>
    5757#include <usb/classes/hidreport.h>
    58 #include <usb/classes/hid/utled.h>
    5958
    6059#include <usb/devdrv.h>
     
    7069static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
    7170
    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). */
     72static const size_t BOOTP_REPORT_SIZE = 6;
     73
     74/** Boot protocol total report size. */
     75static const size_t BOOTP_BUFFER_SIZE = 8;
     76
     77/** Boot protocol output report size. */
     78static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
     79
     80/** Boot protocol error key code. */
     81static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
    8482
    8583/** Default idle rate for keyboards. */
     
    265263static void usb_kbd_set_led(usb_kbd_t *kbd_dev)
    266264{
    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;
     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;
    283281        }
    284282
     
    286284       
    287285        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));
    296291                return;
    297292        }
    298293       
    299294        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);
    302298       
    303299        usbhid_req_set_report(&kbd_dev->usb_dev->ctrl_pipe,
    304300            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);
    306302}
    307303
     
    454450         * First of all, check if the kbd have reported phantom state.
    455451         *
    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.
    460454         */
    461455        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) {
    463459                ++i;
    464460        }
    465         if (i != count) {
     461        if (i == count) {
    466462                usb_log_debug("Phantom state occured.\n");
    467463                // phantom state, do nothing
     
    590586 */
    591587static 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)
    593589{
    594590        assert(kbd_dev->initialized == USB_KBD_STATUS_INITIALIZED);
     
    764760        usb_log_debug("Size of the input report: %zu\n", kbd_dev->key_count);
    765761       
    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));
    767764       
    768765        if (kbd_dev->keys == NULL) {
     
    771768        }
    772769       
    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          */     
    811770        kbd_dev->modifiers = 0;
    812771        kbd_dev->mods = DEFAULT_ACTIVE_MODS;
    813772        kbd_dev->lock_keys = 0;
    814773       
    815         /*
    816          * Autorepeat
    817          */     
    818774        kbd_dev->repeat.key_new = 0;
    819775        kbd_dev->repeat.key_repeated = 0;
     
    923879        }
    924880       
    925         // free the output buffer
    926         usb_hid_report_output_free((*kbd_dev)->output_buffer);
    927        
    928881        /* TODO: what about the USB device structure?? */
    929882
Note: See TracChangeset for help on using the changeset viewer.