Ignore:
File:
1 edited

Legend:

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

    r1f383dde r71ed4849  
    2929#include <driver.h>
    3030#include <ipc/driver.h>
     31#include <ipc/kbd.h>
     32#include <io/keycode.h>
     33#include <io/console.h>
    3134#include <errno.h>
    3235#include <fibril.h>
     
    3538#include <usb/devreq.h>
    3639#include <usb/descriptor.h>
    37 #include "descparser.h"
    3840
    3941#define BUFFER_SIZE 32
     
    4143
    4244#define GUESSED_POLL_ENDPOINT 1
     45
     46static void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
     47static device_ops_t keyboard_ops = {
     48        .default_handler = default_connection_handler
     49};
     50
     51static 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 */
     59void 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
     80static 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
     85static 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}
    4390
    4491/*
     
    4895                                    void *arg)
    4996{
    50         printf("Got keys: ");
    51         unsigned i;
    52         for (i = 0; i < count; ++i) {
    53                 printf("%d ", key_codes[i]);
    54         }
    55         printf("\n");
     97
    5698}
    5799
     
    59101 * Kbd functions
    60102 */
    61 static int usbkbd_process_descriptors(usb_hid_dev_kbd_t *kbd_dev)
    62 {
    63         // get the first configuration descriptor (TODO: parse also other!)
     103static 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
     141static int usbkbd_get_descriptors(usb_hid_dev_kbd_t *kbd_dev)
     142{
     143        // get the first configuration descriptor (TODO: or some other??)
    64144        usb_standard_configuration_descriptor_t config_desc;
    65145       
     
    90170        }
    91171       
    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);
     172        rc = usbkbd_parse_descriptors(kbd_dev, descriptors, transferred);
    100173        free(descriptors);
    101174       
    102         //usbkbd_print_config(kbd_dev->conf);
    103        
    104175        return rc;
    105176}
     
    107178static usb_hid_dev_kbd_t *usbkbd_init_device(device_t *dev)
    108179{
    109         usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)calloc(1,
    110             sizeof(usb_hid_dev_kbd_t));
     180        usb_hid_dev_kbd_t *kbd_dev = (usb_hid_dev_kbd_t *)malloc(
     181                        sizeof(usb_hid_dev_kbd_t));
    111182
    112183        if (kbd_dev == NULL) {
     
    119190        // get phone to my HC and save it as my parent's phone
    120191        // TODO: maybe not a good idea if DDF will use parent_phone
    121         kbd_dev->device->parent_phone = usb_drv_hc_connect(dev, 0);
     192        kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    122193
    123194        kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,
     
    141212         */
    142213
    143         // TODO: get descriptors, parse descriptors and save endpoints
    144         usbkbd_process_descriptors(kbd_dev);
     214        // TODO: get descriptors
     215        usbkbd_get_descriptors(kbd_dev);
     216        // TODO: parse descriptors and save endpoints
    145217
    146218        return kbd_dev;
     
    159231                sizeof(usb_hid_report_in_callbacks_t));
    160232        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        }
    161242
    162243        usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
     
    244325         * Not supported yet, skip..
    245326         */
    246 //      int phone = usb_drv_hc_connect(dev, 0);
     327//      int phone = usb_drv_hc_connect_auto(dev, 0);
    247328//      if (phone < 0) {
    248329//              /*
     
    265346        fibril_add_ready(fid);
    266347
     348        dev->ops = &keyboard_ops;
     349
     350        add_device_to_class(dev, "keyboard");
     351
    267352        /*
    268353         * Hurrah, device is initialized.
Note: See TracChangeset for help on using the changeset viewer.