Ignore:
File:
1 edited

Legend:

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

    r71ed4849 r1f383dde  
    2929#include <driver.h>
    3030#include <ipc/driver.h>
    31 #include <ipc/kbd.h>
    32 #include <io/keycode.h>
    33 #include <io/console.h>
    3431#include <errno.h>
    3532#include <fibril.h>
     
    3835#include <usb/devreq.h>
    3936#include <usb/descriptor.h>
     37#include "descparser.h"
    4038
    4139#define BUFFER_SIZE 32
     
    4341
    4442#define GUESSED_POLL_ENDPOINT 1
    45 
    46 static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
    47 static device_ops_t keyboard_ops = {
    48         .default_handler = default_connection_handler
    49 };
    50 
    51 static int console_callback_phone = -1;
    52 
    53 /** Default handler for IPC methods not handled by DDF.
    54  *
    55  * @param dev Device handling the call.
    56  * @param icallid Call id.
    57  * @param icall Call data.
    58  */
    59 void default_connection_handler(device_t *dev,
    60     ipc_callid_t icallid, ipc_call_t *icall)
    61 {
    62         sysarg_t method = IPC_GET_IMETHOD(*icall);
    63 
    64         if (method == IPC_M_CONNECT_TO_ME) {
    65                 int callback = IPC_GET_ARG5(*icall);
    66 
    67                 if (console_callback_phone != -1) {
    68                         ipc_answer_0(icallid, ELIMIT);
    69                         return;
    70                 }
    71 
    72                 console_callback_phone = callback;
    73                 ipc_answer_0(icallid, EOK);
    74                 return;
    75         }
    76 
    77         ipc_answer_0(icallid, EINVAL);
    78 }
    79 
    80 static void send_key(int key, int type, wchar_t c) {
    81         async_msg_4(console_callback_phone, KBD_EVENT, type, key,
    82             KM_NUM_LOCK, c);
    83 }
    84 
    85 static void send_alnum(int key, wchar_t c) {
    86         printf(NAME ": sending key '%lc' to console\n", (wint_t) c);
    87         send_key(key, KEY_PRESS, c);
    88         send_key(key, KEY_RELEASE, c);
    89 }
    9043
    9144/*
     
    9548                                    void *arg)
    9649{
    97 
     50        printf("Got keys: ");
     51        unsigned i;
     52        for (i = 0; i < count; ++i) {
     53                printf("%d ", key_codes[i]);
     54        }
     55        printf("\n");
    9856}
    9957
     
    10159 * Kbd functions
    10260 */
    103 static int usbkbd_parse_descriptors(usb_hid_dev_kbd_t *kbd_dev,
    104                                     const uint8_t *data, size_t size)
    105 {
    106 //      const uint8_t *pos = data;
    107        
    108 //      // get the configuration descriptor (should be first)
    109 //      if (*pos != sizeof(usb_standard_configuration_descriptor_t)
    110 //          || *(pos + 1) != USB_DESCTYPE_CONFIGURATION) {
    111 //              fprintf(stderr, "Wrong format of configuration descriptor");
    112 //              return EINVAL;
    113 //      }
    114        
    115 //      usb_standard_configuration_descriptor_t config_descriptor;
    116 //      memcpy(&config_descriptor, pos,
    117 //          sizeof(usb_standard_configuration_descriptor_t));
    118 //      pos += sizeof(usb_standard_configuration_descriptor_t);
    119        
    120 //      // parse other descriptors
    121 //      while (pos - data < size) {
    122 //              //uint8_t desc_size = *pos;
    123 //              uint8_t desc_type = *(pos + 1);
    124 //              switch (desc_type) {
    125 //              case USB_DESCTYPE_INTERFACE:
    126 //                      break;
    127 //              case USB_DESCTYPE_ENDPOINT:
    128 //                      break;
    129 //              case USB_DESCTYPE_HID:
    130 //                      break;
    131 //              case USB_DESCTYPE_HID_REPORT:
    132 //                      break;
    133 //              case USB_DESCTYPE_HID_PHYSICAL:
    134 //                      break;
    135 //              }
    136 //      }
    137        
    138         return EOK;
    139 }
    140 
    141 static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    142 {
    143         // get the first configuration descriptor (TODO: or some other??)
     61static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
     62{
     63        // get the first configuration descriptor (TODO: parse also other!)
    14464        usb_standard_configuration_descriptor_t config_desc;
    14565       
     
    17090        }
    17191       
    172         rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred);
     92        kbd_dev->conf = (usb_hid_configuration_t *)calloc(1,
     93            sizeof(usb_hid_configuration_t));
     94        if (kbd_dev->conf == NULL) {
     95                free(descriptors);
     96                return ENOMEM;
     97        }
     98       
     99        rc = usbkbd_parse_descriptors(descriptors, transferred, kbd_dev->conf);
    173100        free(descriptors);
    174101       
     102        //usbkbd_print_config(kbd_dev->conf);
     103       
    175104        return rc;
    176105}
     
    178107static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    179108{
    180         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc(
    181                         sizeof(usb_hid_dev_kbd_t));
     109        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
     110            sizeof(usb_hid_dev_kbd_t));
    182111
    183112        if (kbd_dev == NULL) {
     
    190119        // get phone to my HC and save it as my parent's phone
    191120        // TODO: maybe not a good idea if DDF will use parent_phone
    192         kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
     121        kbd_dev->device->parent_phone = usb_drv_hc_connect(dev, 0);
    193122
    194123        kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,
     
    212141         */
    213142
    214         // TODO: get descriptors
    215         usbkbd_get_descriptors(kbd_dev);
    216         // TODO: parse descriptors and save endpoints
     143        // TODO: get descriptors, parse descriptors and save endpoints
     144        usbkbd_process_descriptors(kbd_dev);
    217145
    218146        return kbd_dev;
     
    231159                sizeof(usb_hid_report_in_callbacks_t));
    232160        callbacks->keyboard = usbkbd_process_keycodes;
    233 
    234         if (console_callback_phone != -1) {
    235                 static size_t counter = 0;
    236                 counter++;
    237                 if (counter > 3) {
    238                         counter = 0;
    239                         send_alnum(KC_A, L'a');
    240                 }
    241         }
    242161
    243162        usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
     
    325244         * Not supported yet, skip..
    326245         */
    327 //      int phone = usb_drv_hc_connect_auto(dev, 0);
     246//      int phone = usb_drv_hc_connect(dev, 0);
    328247//      if (phone < 0) {
    329248//              /*
     
    346265        fibril_add_ready(fid);
    347266
    348         dev->ops = &keyboard_ops;
    349 
    350         add_device_to_class(dev, "keyboard");
    351 
    352267        /*
    353268         * Hurrah, device is initialized.
Note: See TracChangeset for help on using the changeset viewer.