Ignore:
File:
1 edited

Legend:

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

    rfbddf94 r38c5dfa  
    3838#include <usb/devreq.h>
    3939#include <usb/descriptor.h>
    40 #include "descparser.h"
    41 #include "descdump.h"
    4240
    4341#define BUFFER_SIZE 32
     
    9088 * Callbacks for parser
    9189 */
    92 static void usbkbd_process_keycodes(const uint8_t *key_codes, size_t count,
    93                                     uint8_t modifiers, void *arg)
    94 {
    95         printf("Got keys: ");
    96         unsigned i;
    97         for (i = 0; i < count; ++i) {
    98                 printf("%d ", key_codes[i]);
    99         }
    100         printf("\n");
     90static void usbkbd_process_keycodes(const uint16_t *key_codes, size_t count,
     91                                    void *arg)
     92{
     93
    10194}
    10295
     
    10497 * Kbd functions
    10598 */
    106 static int usbkbd_get_report_descriptor(usb_hid_dev_kbd_t *kbd_dev)
    107 {
    108         // iterate over all configurations and interfaces
    109         // TODO: more configurations!!
    110         unsigned i;
    111         for (i = 0; i < kbd_dev->conf->config_descriptor.interface_count; ++i) {
    112                 // TODO: endianness
    113                 uint16_t length =
    114                     kbd_dev->conf->interfaces[i].hid_desc.report_desc_info.length;
    115                 size_t actual_size = 0;
    116 
    117                 // allocate space for the report descriptor
    118                 kbd_dev->conf->interfaces[i].report_desc = (uint8_t *)malloc(length);
    119                
    120                 // get the descriptor from the device
    121                 int rc = usb_drv_req_get_descriptor(kbd_dev->device->parent_phone,
    122                     kbd_dev->address, USB_REQUEST_TYPE_CLASS, USB_DESCTYPE_HID_REPORT,
    123                     0, i, kbd_dev->conf->interfaces[i].report_desc, length,
    124                     &actual_size);
    125 
    126                 if (rc != EOK) {
    127                         return rc;
    128                 }
    129 
    130                 assert(actual_size == length);
    131 
    132                 //dump_hid_class_descriptor(0, USB_DESCTYPE_HID_REPORT,
    133                 //    kbd_dev->conf->interfaces[i].report_desc, length);
    134         }
    135 
     99static int usbkbd_parse_descriptors(usb_hid_dev_kbd_t *kbd_dev,
     100                                    const uint8_t *data, size_t size)
     101{
     102//      const uint8_t *pos = data;
     103       
     104//      // get the configuration descriptor (should be first)
     105//      if (*pos != sizeof(usb_standard_configuration_descriptor_t)
     106//          || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) {
     107//              fprintf(stderr, "Wrong format of configuration descriptor");
     108//              return EINVAL;
     109//      }
     110       
     111//      usb_standard_configuration_descriptor_t config_descriptor;
     112//      memcpy(&config_descriptor, pos,
     113//          sizeof(usb_standard_configuration_descriptor_t));
     114//      pos += sizeof(usb_standard_configuration_descriptor_t);
     115       
     116//      // parse other descriptors
     117//      while (pos - data < size) {
     118//              //uint8_t desc_size = *pos;
     119//              uint8_t desc_type = *(pos + 1);
     120//              switch (desc_type) {
     121//              case USB_DESCTYPE_INTERFACE:
     122//                      break;
     123//              case USB_DESCTYPE_ENDPOINT:
     124//                      break;
     125//              case USB_DESCTYPE_HID:
     126//                      break;
     127//              case USB_DESCTYPE_HID_REPORT:
     128//                      break;
     129//              case USB_DESCTYPE_HID_PHYSICAL:
     130//                      break;
     131//              }
     132//      }
     133       
    136134        return EOK;
    137135}
    138136
    139 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    140 {
    141         // get the first configuration descriptor (TODO: parse also other!)
     137static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev)
     138{
     139        // get the first configuration descriptor (TODO: or some other??)
    142140        usb_standard_configuration_descriptor_t config_desc;
    143141       
     
    168166        }
    169167       
    170         kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
    171             sizeof(usb_hid_configuration_t));
    172         if (kbd_dev->conf == NULL) {
    173                 free(descriptors);
    174                 return ENOMEM;
    175         }
    176        
    177         rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
     168        rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred);
    178169        free(descriptors);
    179         if (rc != EOK) {
    180                 printf("Problem with parsing standard descriptors.\n");
    181                 return rc;
    182         }
    183 
    184         // get and report descriptors
    185         rc = usbkbd_get_report_descriptor(kbd_dev);
    186         if (rc != EOK) {
    187                 printf("Problem with parsing HID REPORT descriptor.\n");
    188                 return rc;
    189         }
    190        
    191         //usbkbd_print_config(kbd_dev->conf);
    192 
    193         /*
    194          * TODO:
    195          * 1) select one configuration (lets say the first)
    196          * 2) how many interfaces?? how to select one??
    197      *    ("The default setting for an interface is always alternate setting zero.")
    198          * 3) find endpoint which is IN and INTERRUPT (parse), save its number
    199      *    as the endpoint for polling
    200          */
    201        
    202         return EOK;
     170       
     171        return rc;
    203172}
    204173
    205174static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    206175{
    207         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    208             sizeof(usb_hid_dev_kbd_t));
     176        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc(
     177                        sizeof(usb_hid_dev_kbd_t));
    209178
    210179        if (kbd_dev == NULL) {
     
    217186        // get phone to my HC and save it as my parent's phone
    218187        // TODO: maybe not a good idea if DDF will use parent_phone
    219         int rc = kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    220         if (rc < 0) {
    221                 printf("Problem setting phone to HC.\n");
    222                 free(kbd_dev);
    223                 return NULL;
    224         }
    225 
    226         rc = kbd_dev->address = usb_drv_get_my_address(dev->parent_phone, dev);
    227         if (rc < 0) {
    228                 printf("Problem getting address of the device.\n");
    229                 free(kbd_dev);
    230                 return NULL;
    231         }
     188        kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
     189
     190        kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,
     191            dev);
    232192
    233193        // doesn't matter now that we have no address
     
    248208         */
    249209
    250         // TODO: get descriptors, parse descriptors and save endpoints
    251         usbkbd_process_descriptors(kbd_dev);
     210        // TODO: get descriptors
     211        usbkbd_get_descriptors(kbd_dev);
     212        // TODO: parse descriptors and save endpoints
    252213
    253214        return kbd_dev;
     
    257218                                        uint8_t *buffer, size_t actual_size)
    258219{
     220        /*
     221         * here, the parser will be called, probably with some callbacks
     222         * now only take last 6 bytes and process, i.e. send to kbd
     223         */
     224
    259225        usb_hid_report_in_callbacks_t *callbacks =
    260226            (usb_hid_report_in_callbacks_t *)malloc(
     
    262228        callbacks->keyboard = usbkbd_process_keycodes;
    263229
    264         //usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
    265         //    NULL);
    266         printf("Calling usb_hid_boot_keyboard_input_report()...\n)");
    267         usb_hid_boot_keyboard_input_report(buffer, actual_size, callbacks, NULL);
     230        usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
     231            NULL);
    268232}
    269233
    270234static void usbkbd_poll_keyboard(usb_hid_dev_kbd_t *kbd_dev)
    271235{
    272         return;
    273        
    274236        int rc;
    275237        usb_handle_t handle;
Note: See TracChangeset for help on using the changeset viewer.