Changeset 2002595 in mainline


Ignore:
Timestamp:
2011-05-29T19:41:35Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b9e3aa3
Parents:
2f09dee
Message:

Some fixes to the HID driver.

  • Not initializing report buffer if no subdrivers initialized.
  • Ignore reports larger than the allocated size.
  • Save the fallback subdriver as the last one not the first (and only) one.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/usbhid.c

    r2f09dee r2002595  
    7878        }
    7979       
     80        assert(hid_dev->subdriver_count >= 0);
     81       
    8082        // set the init callback
    81         hid_dev->subdrivers[0].init = usb_kbd_init;
     83        hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_kbd_init;
    8284       
    8385        // set the polling callback
    84         hid_dev->subdrivers[0].poll = usb_kbd_polling_callback;
     86        hid_dev->subdrivers[hid_dev->subdriver_count].poll =
     87            usb_kbd_polling_callback;
    8588       
    8689        // set the polling ended callback
    87         hid_dev->subdrivers[0].poll_end = NULL;
     90        hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
    8891       
    8992        // set the deinit callback
    90         hid_dev->subdrivers[0].deinit = usb_kbd_deinit;
     93        hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_kbd_deinit;
    9194       
    9295        // set subdriver count
    93         hid_dev->subdriver_count = 1;
     96        ++hid_dev->subdriver_count;
    9497       
    9598        return EOK;
     
    108111        }
    109112       
     113        assert(hid_dev->subdriver_count >= 0);
     114       
    110115        // set the init callback
    111         hid_dev->subdrivers[0].init = usb_mouse_init;
     116        hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_mouse_init;
    112117       
    113118        // set the polling callback
    114         hid_dev->subdrivers[0].poll = usb_mouse_polling_callback;
     119        hid_dev->subdrivers[hid_dev->subdriver_count].poll =
     120            usb_mouse_polling_callback;
    115121       
    116122        // set the polling ended callback
    117         hid_dev->subdrivers[0].poll_end = NULL;
     123        hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
    118124       
    119125        // set the deinit callback
    120         hid_dev->subdrivers[0].deinit = usb_mouse_deinit;
     126        hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_mouse_deinit;
    121127       
    122128        // set subdriver count
    123         hid_dev->subdriver_count = 1;
     129        ++hid_dev->subdriver_count;
    124130       
    125131        return EOK;
     
    138144        }
    139145       
     146        assert(hid_dev->subdriver_count >= 0);
     147       
    140148        // set the init callback
    141         hid_dev->subdrivers[0].init = usb_generic_hid_init;
     149        hid_dev->subdrivers[hid_dev->subdriver_count].init =
     150            usb_generic_hid_init;
    142151       
    143152        // set the polling callback
    144         hid_dev->subdrivers[0].poll = usb_generic_hid_polling_callback;
     153        hid_dev->subdrivers[hid_dev->subdriver_count].poll =
     154            usb_generic_hid_polling_callback;
    145155       
    146156        // set the polling ended callback
    147         hid_dev->subdrivers[0].poll_end = NULL;
     157        hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
    148158       
    149159        // set the deinit callback
    150         hid_dev->subdrivers[0].deinit = NULL;
     160        hid_dev->subdrivers[hid_dev->subdriver_count].deinit = NULL;
    151161       
    152162        // set subdriver count
    153         hid_dev->subdriver_count = 1;
     163        ++hid_dev->subdriver_count;
    154164       
    155165        return EOK;
     
    216226        }
    217227       
    218         usb_log_debug("Size of the input report: %zuB\n", size);
     228        usb_log_debug("Size of the input report: %zu\n", size);
    219229        usb_hid_report_path_free(usage_path);
    220230       
     
    368378       
    369379        do {
     380                usb_log_debug("Getting size of the report.\n");
    370381                size = usb_hid_report_byte_size(hid_dev->report, report_id,
    371382                    USB_HID_REPORT_TYPE_INPUT);
    372383                usb_log_debug("Report ID: %u, size: %zu\n", report_id, size);
    373384                max_size = (size > max_size) ? size : max_size;
     385                usb_log_debug("Getting next report ID\n");
    374386                report_id = usb_hid_get_next_report_id(hid_dev->report,
    375387                    report_id, USB_HID_REPORT_TYPE_INPUT);
     
    501513                    hid_dev->subdriver_count);
    502514                //usb_hid_free(&hid_dev);
     515               
    503516        } else {
    504517                bool ok = false;
     
    527540        }
    528541       
    529         // save max input report size and allocate space for the report
    530         rc = usb_hid_init_report(hid_dev);
    531         if (rc != EOK) {
    532                 usb_log_error("Failed to initialize input report buffer.\n");
    533         }
     542       
     543        if (rc == EOK) {
     544                // save max input report size and allocate space for the report
     545                rc = usb_hid_init_report(hid_dev);
     546                if (rc != EOK) {
     547                        usb_log_error("Failed to initialize input report buffer"
     548                            ".\n");
     549                }
     550        }
     551       
    534552       
    535553        return rc;
     
    554572        usb_log_debug("Max input report size: %zu, buffer size: %zu\n",
    555573            hid_dev->max_input_report_size, buffer_size);
    556         assert(hid_dev->max_input_report_size >= buffer_size);
    557        
    558 //      if (/*!allocated*/
    559 //          /*|| *//*hid_dev->input_report_size < buffer_size*/) {
    560 //              uint8_t *input_old = hid_dev->input_report;
    561 //              uint8_t *input_new = (uint8_t *)malloc(buffer_size);
    562                
    563 //              if (input_new == NULL) {
    564 //                      usb_log_error("Failed to allocate space for input "
    565 //                          "buffer. This event may not be reported\n");
    566 //                      memset(hid_dev->input_report, 0,
    567 //                          hid_dev->input_report_size);
    568 //              } else {
    569 //                      memcpy(input_new, input_old,
    570 //                          hid_dev->input_report_size);
    571 //                      hid_dev->input_report = input_new;
    572 //                      if (allocated) {
    573 //                              free(input_old);
    574 //                      }
    575 //                      usb_hid_new_report();
    576 //              }
    577 //      }
    578        
    579         /*! @todo This should probably be atomic. */
    580         memcpy(hid_dev->input_report, buffer, buffer_size);
    581         hid_dev->input_report_size = buffer_size;
    582         usb_hid_new_report(hid_dev);
     574        //assert(hid_dev->max_input_report_size >= buffer_size);
     575        if (hid_dev->max_input_report_size >= buffer_size) {
     576                /*! @todo This should probably be atomic. */
     577                memcpy(hid_dev->input_report, buffer, buffer_size);
     578                hid_dev->input_report_size = buffer_size;
     579                usb_hid_new_report(hid_dev);
     580        }
    583581       
    584582        bool cont = false;
Note: See TracChangeset for help on using the changeset viewer.