Changeset fa8d346 in mainline


Ignore:
Timestamp:
2011-05-24T22:19:26Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8d3f198
Parents:
9dddb3d
Message:

Fixes in mkbd and libusbhid.

  • Fixed initialization of report parser in mkbd.
  • Fixed usb_hid_process_report_descriptor() - added some parameters.
Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/mkbd/main.c

    r9dddb3d rfa8d346  
    6060static int dev_phone = -1;
    6161
    62 static int initialize_report_parser(int dev_phone, usb_hid_report_t *report)
    63 {
    64         report = (usb_hid_report_t *)malloc(sizeof(usb_hid_report_t));
    65         if (report == NULL) {
    66                 return ENOMEM;
    67         }
    68        
    69         int rc = usb_hid_report_init(report);
    70         if (rc != EOK) {
    71                 usb_hid_free_report(report);
     62static int initialize_report_parser(int dev_phone, usb_hid_report_t **report)
     63{
     64        *report = (usb_hid_report_t *)malloc(sizeof(usb_hid_report_t));
     65        if (*report == NULL) {
     66                return ENOMEM;
     67        }
     68       
     69        int rc = usb_hid_report_init(*report);
     70        if (rc != EOK) {
     71                usb_hid_free_report(*report);
     72                *report = NULL;
     73                printf("usb_hid_report_init() failed.\n");
    7274                return rc;
    7375        }
     
    7880            dev_phone, &report_desc_size);
    7981        if (rc != EOK) {
    80                 usb_hid_free_report(report);
     82                usb_hid_free_report(*report);
     83                *report = NULL;
     84                printf("usbhid_dev_get_report_descriptor_length() failed.\n");
    8185                return rc;
    8286        }
    8387       
    8488        if (report_desc_size == 0) {
    85                 usb_hid_free_report(report);
     89                usb_hid_free_report(*report);
     90                *report = NULL;
     91                printf("usbhid_dev_get_report_descriptor_length() returned 0.\n");
    8692                return EINVAL;  // TODO: other error code?
    8793        }
     
    8995        uint8_t *desc = (uint8_t *)malloc(report_desc_size);
    9096        if (desc == NULL) {
    91                 usb_hid_free_report(report);
     97                usb_hid_free_report(*report);
     98                *report = NULL;
    9299                return ENOMEM;
    93100        }
     
    98105            &actual_size);
    99106        if (rc != EOK) {
    100                 usb_hid_free_report(report);
     107                usb_hid_free_report(*report);
     108                *report = NULL;
    101109                free(desc);
     110                printf("usbhid_dev_get_report_descriptor() failed.\n");
    102111                return rc;
    103112        }
    104113       
    105114        if (actual_size != report_desc_size) {
    106                 usb_hid_free_report(report);
     115                usb_hid_free_report(*report);
     116                *report = NULL;
    107117                free(desc);
     118                printf("usbhid_dev_get_report_descriptor() returned wrong size:"
     119                    " %zu, expected: %zu.\n", actual_size, report_desc_size);
    108120                return EINVAL;  // TODO: other error code?
    109121        }
     
    111123        // initialize the report parser
    112124       
    113         rc = usb_hid_parse_report_descriptor(report, desc, report_desc_size);
     125        rc = usb_hid_parse_report_descriptor(*report, desc, report_desc_size);
    114126        free(desc);
    115127       
    116128        if (rc != EOK) {
    117129                free(desc);
     130                printf("usb_hid_parse_report_descriptor() failed.\n");
    118131                return rc;
    119132        }
     
    215228       
    216229        usb_hid_report_t *report = NULL;
    217         rc = initialize_report_parser(dev_phone, report);
     230        rc = initialize_report_parser(dev_phone, &report);
    218231        if (rc != EOK) {
    219232                printf("Failed to initialize report parser: %s\n",
  • uspace/drv/usbhid/generic/hiddev.c

    r9dddb3d rfa8d346  
    153153        usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    154154       
     155        printf("hid_dev->report_desc_size = %zu\n", hid_dev->report_desc_size);
     156       
    155157        return hid_dev->report_desc_size;
    156158}
  • uspace/drv/usbhid/usbhid.c

    r9dddb3d rfa8d346  
    443443        /* Get the report descriptor and parse it. */
    444444        rc = usb_hid_process_report_descriptor(hid_dev->usb_dev,
    445             hid_dev->report);
     445            hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);
    446446       
    447447        bool fallback = false;
  • uspace/lib/usbhid/include/usb/hid/hidreport.h

    r9dddb3d rfa8d346  
    4444 * report parser.
    4545 *
    46  * \param dev USB device representing a HID device.
    47  * \param parser HID Report parser.
     46 * \param[in] dev USB device representing a HID device.
     47 * \param[in/out] parser HID Report parser.
     48 * \param[out] report_desc Place to save report descriptor into.
     49 * \param[out] report_size
    4850 *
    4951 * \retval EOK if successful.
     
    5759 */
    5860int usb_hid_process_report_descriptor(usb_device_t *dev,
    59     usb_hid_report_t *report);
     61    usb_hid_report_t *report, uint8_t **report_desc, size_t *report_size);
    6062
    6163#endif /* LIBUSB_HIDREPORT_H_ */
  • uspace/lib/usbhid/src/hidreport.c

    r9dddb3d rfa8d346  
    164164
    165165int usb_hid_process_report_descriptor(usb_device_t *dev,
    166     usb_hid_report_t *report)
     166    usb_hid_report_t *report, uint8_t **report_desc, size_t *report_size)
    167167{
    168168        if (dev == NULL || report == NULL) {
     
    172172        }
    173173       
    174         uint8_t *report_desc = NULL;
    175         size_t report_size;
    176        
    177         int rc = usb_hid_get_report_descriptor(dev, &report_desc,
    178             &report_size);
     174//      uint8_t *report_desc = NULL;
     175//      size_t report_size;
     176       
     177        int rc = usb_hid_get_report_descriptor(dev, report_desc, report_size);
    179178       
    180179        if (rc != EOK) {
    181180                usb_log_error("Problem with getting Report descriptor: %s.\n",
    182181                    str_error(rc));
    183                 if (report_desc != NULL) {
    184                         free(report_desc);
     182                if (*report_desc != NULL) {
     183                        free(*report_desc);
     184                        *report_desc = NULL;
    185185                }
    186186                return rc;
    187187        }
    188188       
    189         assert(report_desc != NULL);
    190        
    191         rc = usb_hid_parse_report_descriptor(report, report_desc, report_size);
     189        assert(*report_desc != NULL);
     190       
     191        rc = usb_hid_parse_report_descriptor(report, *report_desc, *report_size);
    192192        if (rc != EOK) {
    193193                usb_log_error("Problem parsing Report descriptor: %s.\n",
    194194                    str_error(rc));
    195                 free(report_desc);
     195                free(*report_desc);
     196                *report_desc = NULL;
    196197                return rc;
    197198        }
    198199       
    199200        usb_hid_descriptor_print(report);
    200         free(report_desc);
    201201       
    202202        return EOK;
Note: See TracChangeset for help on using the changeset viewer.