Ignore:
File:
1 edited

Legend:

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

    rf9a0cef 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>
     
    4144#define GUESSED_POLL_ENDPOINT 1
    4245
     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}
     90
    4391/*
    4492 * Callbacks for parser
     
    142190        // get phone to my HC and save it as my parent's phone
    143191        // TODO: maybe not a good idea if DDF will use parent_phone
    144         kbd_dev->device->parent_phone = usb_drv_hc_connect(dev, 0);
     192        kbd_dev->device->parent_phone = usb_drv_hc_connect_auto(dev, 0);
    145193
    146194        kbd_dev->address = usb_drv_get_my_address(dev->parent_phone,
     
    183231                sizeof(usb_hid_report_in_callbacks_t));
    184232        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        }
    185242
    186243        usb_hid_parse_report(kbd_dev->parser, buffer, actual_size, callbacks,
     
    268325         * Not supported yet, skip..
    269326         */
    270 //      int phone = usb_drv_hc_connect(dev, 0);
     327//      int phone = usb_drv_hc_connect_auto(dev, 0);
    271328//      if (phone < 0) {
    272329//              /*
     
    289346        fibril_add_ready(fid);
    290347
     348        dev->ops = &keyboard_ops;
     349
     350        add_device_to_class(dev, "keyboard");
     351
    291352        /*
    292353         * Hurrah, device is initialized.
Note: See TracChangeset for help on using the changeset viewer.