Fork us on GitHub Follow us on Facebook Follow us on Twitter

Ignore:
Timestamp:
2011-06-21T19:10:20Z (11 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
022d9f67
Parents:
a9d85df
Message:

input server improvements

  • integrate legacy port mouse drivers (PS/2, ADB) into the input server (to be on par with the legacy keyboard drivers)
  • create generic port/protocol layers for the mouse in the input server
  • rename the "hid_in" namespace to "hid" namespace (hid_in/input was rather redundant)
  • rename the mouse event IPC messages to be more consistent with the keyboard event messages
  • rename input server ops structure members to be more generic (parse_scancode → parse)
  • cstyle changes (newlines, comments, printouts)
File:
1 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/port/chardev_mouse.c

    ra9d85df r1875a0c  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup mouse
     29/** @addtogroup mouse_port
     30 * @ingroup mouse
    3031 * @{
    31  */ 
     32 */
    3233/** @file
    33  * @brief
     34 * @brief Chardev mouse port driver.
    3435 */
    3536
    36 #include <ipc/adb.h>
     37#include <ipc/char.h>
     38#include <stdio.h>
    3739#include <async.h>
    38 #include <vfs/vfs.h>
    39 #include <fcntl.h>
    4040#include <errno.h>
    4141#include <devmap.h>
    42 #include <async.h>
    43 #include <kernel/ipc/ipc_methods.h>
     42#include <input.h>
     43#include <mouse_port.h>
     44#include <mouse.h>
    4445
    45 #include "adb_mouse.h"
    46 #include "adb_dev.h"
     46static mouse_dev_t *mouse_dev;
     47static async_sess_t *dev_sess;
    4748
    48 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
     49/** List of devices to try connecting to. */
     50static const char *in_devs[] = {
     51        "char/ps2b",
     52};
    4953
    50 int adb_dev_init(void)
     54static const unsigned int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
     55
     56static void mouse_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     57{
     58        /* Ignore parameters, the connection is already opened */
     59        while (true) {
     60                ipc_call_t call;
     61                ipc_callid_t callid = async_get_call(&call);
     62               
     63                if (!IPC_GET_IMETHOD(call)) {
     64                        /* TODO: Handle hangup */
     65                        return;
     66                }
     67               
     68                int retval;
     69               
     70                switch (IPC_GET_IMETHOD(call)) {
     71                case CHAR_NOTIF_BYTE:
     72                        mouse_push_data(mouse_dev, IPC_GET_ARG1(call));
     73                        break;
     74                default:
     75                        retval = ENOENT;
     76                }
     77               
     78                async_answer_0(callid, retval);
     79        }
     80}
     81
     82static int chardev_port_init(mouse_dev_t *mdev)
    5183{
    5284        devmap_handle_t handle;
    53         async_exch_t *exch;
     85        unsigned int i;
    5486        int rc;
    5587       
    56         rc = devmap_device_get_handle("adb/mouse", &handle,
    57             IPC_FLAG_BLOCKING);
    58         if (rc != EOK) {
    59                 printf("%s: Failed resolving ADB\n", NAME);
    60                 return rc;
     88        mouse_dev = mdev;
     89       
     90        for (i = 0; i < num_devs; i++) {
     91                rc = devmap_device_get_handle(in_devs[i], &handle, 0);
     92                if (rc == EOK)
     93                        break;
    6194        }
    6295       
    63         async_sess_t *dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle,
     96        if (i >= num_devs) {
     97                printf("%s: Could not find any suitable input device\n", NAME);
     98                return -1;
     99        }
     100       
     101        dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle,
    64102            IPC_FLAG_BLOCKING);
    65103        if (dev_sess == NULL) {
    66                 printf("%s: Failed connecting to ADB\n", NAME);
     104                printf("%s: Failed connecting to device\n", NAME);
    67105                return ENOENT;
    68106        }
    69107       
    70         exch = async_exchange_begin(dev_sess);
     108        async_exch_t *exch = async_exchange_begin(dev_sess);
    71109        if (exch == NULL) {
    72                 printf("%s: Failed starting exchange with ADB\n", NAME);
     110                printf("%s: Failed starting exchange with device\n", NAME);
    73111                async_hangup(dev_sess);
    74112                return ENOMEM;
     
    76114       
    77115        /* NB: The callback connection is slotted for removal */
    78         rc = async_connect_to_me(exch, 0, 0, 0, adb_dev_events, NULL);
     116        rc = async_connect_to_me(exch, 0, 0, 0, mouse_port_events, NULL);
    79117        async_exchange_end(exch);
    80118       
    81119        if (rc != 0) {
    82                 printf(NAME ": Failed to create callback from device\n");
     120                printf("%s: Failed to create callback from device\n", NAME);
    83121                async_hangup(dev_sess);
    84                 return ENOENT;
     122                return -1;
    85123        }
    86124       
     
    88126}
    89127
    90 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     128static void chardev_port_yield(void)
    91129{
    92         /* Ignore parameters, the connection is already opened */
    93         while (true) {
     130}
    94131
    95                 ipc_call_t call;
    96                 ipc_callid_t callid = async_get_call(&call);
     132static void chardev_port_reclaim(void)
     133{
     134}
    97135
    98                 int retval;
    99                
    100                 if (!IPC_GET_IMETHOD(call)) {
    101                         /* TODO: Handle hangup */
    102                         return;
    103                 }
     136static void chardev_port_write(uint8_t data)
     137{
     138        async_exch_t *exch = async_exchange_begin(dev_sess);
     139        if (exch == NULL) {
     140                printf("%s: Failed starting exchange with device\n", NAME);
     141                return;
     142        }
    104143
    105                 switch (IPC_GET_IMETHOD(call)) {
    106                 case IPC_FIRST_USER_METHOD:
    107                         mouse_handle_data(IPC_GET_ARG1(call));
    108                         break;
    109                 default:
    110                         retval = ENOENT;
    111                 }
    112                 async_answer_0(callid, retval);
    113         }
     144        async_msg_1(exch, CHAR_WRITE_BYTE, data);
     145        async_exchange_end(exch);
    114146}
     147
     148mouse_port_ops_t chardev_mouse_port = {
     149        .init = chardev_port_init,
     150        .yield = chardev_port_yield,
     151        .reclaim = chardev_port_reclaim,
     152        .write = chardev_port_write
     153};
    115154
    116155/**
Note: See TracChangeset for help on using the changeset viewer.