Ignore:
Timestamp:
2011-09-25T18:46:45Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
36cb22f
Parents:
dcc44ca1 (diff), f9d8c3a (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.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/mouse/mousedev.c

    rdcc44ca1 r1db44ea  
    7575/** Default idle rate for mouses. */
    7676static const uint8_t IDLE_RATE = 0;
    77 static const size_t USB_MOUSE_BUTTON_COUNT = 3;
    7877
    7978/*----------------------------------------------------------------------------*/
     
    397396/*----------------------------------------------------------------------------*/
    398397
     398/** Get highest index of a button mentioned in given report.
     399 *
     400 * @param report HID report.
     401 * @param report_id Report id we are interested in.
     402 * @return Highest button mentioned in the report.
     403 * @retval 1 No button was mentioned.
     404 *
     405 */
     406static size_t usb_mouse_get_highest_button(usb_hid_report_t *report, uint8_t report_id)
     407{
     408        size_t highest_button = 0;
     409
     410        usb_hid_report_path_t *path = usb_hid_report_path();
     411        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_BUTTON, 0);
     412        usb_hid_report_path_set_report_id(path, report_id);
     413
     414        usb_hid_report_field_t *field = NULL;
     415
     416        /* Break from within. */
     417        while (1) {
     418                field = usb_hid_report_get_sibling(
     419                    report, field, path,
     420                    USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY,
     421                    USB_HID_REPORT_TYPE_INPUT);
     422                /* No more buttons? */
     423                if (field == NULL) {
     424                        break;
     425                }
     426
     427                size_t current_button = field->usage - field->usage_minimum;
     428                if (current_button > highest_button) {
     429                        highest_button = current_button;
     430                }
     431        }
     432
     433        usb_hid_report_path_free(path);
     434
     435        return highest_button;
     436}
     437
     438/*----------------------------------------------------------------------------*/
     439
    399440int usb_mouse_init(usb_hid_dev_t *hid_dev, void **data)
    400441{
     
    414455        }
    415456       
    416         mouse_dev->buttons = (int32_t *)calloc(USB_MOUSE_BUTTON_COUNT,
    417             sizeof(int32_t));
     457        // FIXME: This may not be optimal since stupid hardware vendor may
     458        // use buttons 1, 2, 3 and 6000 and we would allocate array of
     459        // 6001*4B and use only 4 items in it.
     460        // Since I doubt that hardware producers would do that, I think
     461        // that the current solution is good enough.
     462        /* Adding 1 because we will be accessing buttons[highest]. */
     463        mouse_dev->buttons_count = usb_mouse_get_highest_button(hid_dev->report,
     464            hid_dev->report_id) + 1;
     465        mouse_dev->buttons = calloc(mouse_dev->buttons_count, sizeof(int32_t));
    418466       
    419467        if (mouse_dev->buttons == NULL) {
    420                 usb_log_fatal("No memory!\n");
     468                usb_log_error(NAME ": out of memory, giving up on device!\n");
    421469                free(mouse_dev);
    422470                return ENOMEM;
    423471        }
    424        
     472
     473
    425474        // save the Mouse device structure into the HID device structure
    426475        *data = mouse_dev;
Note: See TracChangeset for help on using the changeset viewer.