Changeset ca038b4 in mainline for uspace/drv/usbkbd/main.c


Ignore:
Timestamp:
2010-12-12T16:50:48Z (14 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
692f13e4
Parents:
c694b7e
Message:

Configuration parsing

Added functions for parsing configuration descriptor and all underlying

descriptors (interface, endpoint, HID, class-specific).

Kbd driver uses new function usbkbd_parse_descriptors() to get the

configuration. As for now, only one configuration is considered.

File:
1 edited

Legend:

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

    rc694b7e rca038b4  
    3535#include <usb/devreq.h>
    3636#include <usb/descriptor.h>
     37#include "descparser.h"
    3738
    3839#define BUFFER_SIZE 32
     
    5354 * Kbd functions
    5455 */
    55 static 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 
    93 static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    94 {
    95         // get the first configuration descriptor (TODO: or some other??)
     56static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
     57{
     58        // get the first configuration descriptor (TODO: parse also other!)
    9659        usb_standard_configuration_descriptor_t config_desc;
    9760       
     
    12285        }
    12386       
    124         rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred);
     87        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
     88            sizeof(usb_hid_configuration_t));
     89        if (kbd_dev->conf == NULL) {
     90                free(descriptors);
     91                return ENOMEM;
     92        }
     93       
     94        rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    12595        free(descriptors);
    12696       
     
    130100static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    131101{
    132         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc(
    133                         sizeof(usb_hid_dev_kbd_t));
     102        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
     103            sizeof(usb_hid_dev_kbd_t));
    134104
    135105        if (kbd_dev == NULL) {
     
    164134         */
    165135
    166         // TODO: get descriptors
    167         usbkbd_get_descriptors(kbd_dev);
    168         // TODO: parse descriptors and save endpoints
     136        // TODO: get descriptors, parse descriptors and save endpoints
     137        usbkbd_process_descriptors(kbd_dev);
    169138
    170139        return kbd_dev;
Note: See TracChangeset for help on using the changeset viewer.