Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset dafab9e0 in mainline


Ignore:
Timestamp:
2010-12-12T13:39:09Z (11 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master
Children:
a3b1107
Parents:
e7726a4
Message:

Getting of full configuration descriptor.

File:
1 edited

Legend:

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

    re7726a4 rdafab9e0  
    3434#include <usb/classes/hidparser.h>
    3535#include <usb/devreq.h>
     36#include <usb/descriptor.h>
    3637
    3738#define BUFFER_SIZE 32
     
    5253 * Kbd functions
    5354 */
    54 static int usbkbd_get_descriptors()
    55 {
    56         // copy-pasted:
    57        
    58         /* Prepare the setup packet. */
    59         usb_device_request_setup_packet_t setup_packet = {
    60                 .request_type = 128,
    61                 .request = USB_DEVREQ_GET_DESCRIPTOR,
    62                 .index = 0,
    63                 .length = sizeof(usb_standard_device_descriptor_t)
    64         };
    65        
    66         setup_packet.value_high = USB_DESCTYPE_DEVICE;
    67         setup_packet.value_low = 0;
    68 
    69         /* Prepare local descriptor. */
    70         size_t actually_transferred = 0;
    71         usb_standard_device_descriptor_t descriptor_tmp;
    72 
    73         /* Perform the control read transaction. */
    74         int rc = usb_drv_psync_control_read(phone, target,
    75             &setup_packet, sizeof(setup_packet),
    76             &descriptor_tmp, sizeof(descriptor_tmp), &actually_transferred);
    77 
     55static int usbkbd_parse_descriptors(usb_hid_dev_kbd_t *kbd_dev,
     56                                    const uint8_t *data, size_t size)
     57{
     58//      const uint8_t *pos = data;
     59       
     60//      // get the configuration descriptor (should be first)
     61//      if (*pos != sizeof(usb_standard_configuration_descriptor_t)
     62//          || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) {
     63//              fprintf(stderr, "Wrong format of configuration descriptor");
     64//              return EINVAL;
     65//      }
     66       
     67//      usb_standard_configuration_descriptor_t config_descriptor;
     68//      memcpy(&config_descriptor, pos,
     69//          sizeof(usb_standard_configuration_descriptor_t));
     70//      pos += sizeof(usb_standard_configuration_descriptor_t);
     71       
     72//      // parse other descriptors
     73//      while (pos - data < size) {
     74//              //uint8_t desc_size = *pos;
     75//              uint8_t desc_type = *(pos + 1);
     76//              switch (desc_type) {
     77//              case USB_DESCTYPE_INTERFACE:
     78//                      break;
     79//              case USB_DESCTYPE_ENDPOINT:
     80//                      break;
     81//              case USB_DESCTYPE_HID:
     82//                      break;
     83//              case USB_DESCTYPE_HID_REPORT:
     84//                      break;
     85//              case USB_DESCTYPE_HID_PHYSICAL:
     86//                      break;
     87//              }
     88//      }
     89       
     90        return EOK;
     91}
     92
     93static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev)
     94{
     95        // get the first configuration descriptor (TODO: or some other??)
     96        usb_standard_configuration_descriptor_t config_desc;
     97       
     98        int rc = usb_drv_req_get_bare_configuration_descriptor(
     99            kbd_dev->device->parent_phone, kbd_dev->address, 0, &config_desc);
     100       
    78101        if (rc != EOK) {
    79102                return rc;
    80103        }
    81104       
    82         // end of copy-paste
     105        // prepare space for all underlying descriptors
     106        uint8_t *descriptors = (uint8_t *)malloc(config_desc.total_length);
     107        if (descriptors == NULL) {
     108                return ENOMEM;
     109        }
     110       
     111        size_t transferred = 0;
     112        // get full configuration descriptor
     113        rc = usb_drv_req_get_full_configuration_descriptor(
     114            kbd_dev->device->parent_phone, kbd_dev->address, 0, descriptors,
     115            config_desc.total_length, &transferred);
     116       
     117        if (rc != EOK) {
     118                return rc;
     119        }
     120        if (transferred != config_desc.total_length) {
     121                return ELIMIT;
     122        }
     123       
     124        rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred);
     125        free(descriptors);
     126       
     127        return rc;
    83128}
    84129
     
    111156        // default endpoint
    112157        kbd_dev->default_ep = CONTROL_EP;
     158       
     159        /*
     160         * will need all descriptors:
     161         * 1) choose one configuration from configuration descriptors
     162         *    (set it to the device)
     163         * 2) set endpoints from endpoint descriptors
     164         */
    113165
    114166        // TODO: get descriptors
    115         usbkbd_get_descriptors();
     167        usbkbd_get_descriptors(kbd_dev);
    116168        // TODO: parse descriptors and save endpoints
    117169
     
    132184        callbacks->keyboard = usbkbd_process_keycodes;
    133185
    134         usb_hid_parse_report(kbd_dev->parser, buffer, callbacks, NULL);
     186        usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
     187            NULL);
    135188}
    136189
Note: See TracChangeset for help on using the changeset viewer.