Ignore:
Timestamp:
2011-07-13T22:39:18Z (13 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e6910c8
Parents:
5974661 (diff), 8ecef91 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge libposix.

File:
1 moved

Legend:

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

    r5974661 re4f8c77  
    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 <devmap_obsolete.h>
    43 #include <async.h>
    44 #include <async_obsolete.h>
    45 #include <kernel/ipc/ipc_methods.h>
     42#include <input.h>
     43#include <mouse_port.h>
     44#include <mouse.h>
    4645
    47 #include "adb_mouse.h"
    48 #include "adb_dev.h"
     46static mouse_dev_t *mouse_dev;
     47static async_sess_t *dev_sess;
    4948
    50 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall);
     49/** List of devices to try connecting to. */
     50static const char *in_devs[] = {
     51        "char/ps2b",
     52};
    5153
    52 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)
    5383{
    5484        devmap_handle_t handle;
    55         int rc = devmap_device_get_handle("adb/mouse", &handle,
    56             IPC_FLAG_BLOCKING);
     85        unsigned int i;
     86        int rc;
    5787       
    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         int dev_phone = devmap_obsolete_device_connect(handle, IPC_FLAG_BLOCKING);
    64         if (dev_phone < 0) {
    65                 printf("%s: Failed connecting to ADB\n", NAME);
     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,
     102            IPC_FLAG_BLOCKING);
     103        if (dev_sess == NULL) {
     104                printf("%s: Failed connecting to device\n", NAME);
    66105                return ENOENT;
    67106        }
    68107       
     108        async_exch_t *exch = async_exchange_begin(dev_sess);
     109        if (exch == NULL) {
     110                printf("%s: Failed starting exchange with device\n", NAME);
     111                async_hangup(dev_sess);
     112                return ENOMEM;
     113        }
     114       
    69115        /* NB: The callback connection is slotted for removal */
    70         if (async_obsolete_connect_to_me(dev_phone, 0, 0, 0, adb_dev_events) != 0) {
    71                 printf(NAME ": Failed to create callback from device\n");
    72                 return false;
     116        rc = async_connect_to_me(exch, 0, 0, 0, mouse_port_events, NULL);
     117        async_exchange_end(exch);
     118       
     119        if (rc != 0) {
     120                printf("%s: Failed to create callback from device\n", NAME);
     121                async_hangup(dev_sess);
     122                return -1;
    73123        }
    74124       
     
    76126}
    77127
    78 static void adb_dev_events(ipc_callid_t iid, ipc_call_t *icall)
     128static void chardev_port_yield(void)
    79129{
    80         /* Ignore parameters, the connection is already opened */
    81         while (true) {
     130}
    82131
    83                 ipc_call_t call;
    84                 ipc_callid_t callid = async_get_call(&call);
     132static void chardev_port_reclaim(void)
     133{
     134}
    85135
    86                 int retval;
    87                
    88                 if (!IPC_GET_IMETHOD(call)) {
    89                         /* TODO: Handle hangup */
    90                         return;
    91                 }
     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        }
    92143
    93                 switch (IPC_GET_IMETHOD(call)) {
    94                 case IPC_FIRST_USER_METHOD:
    95                         mouse_handle_data(IPC_GET_ARG1(call));
    96                         break;
    97                 default:
    98                         retval = ENOENT;
    99                 }
    100                 async_answer_0(callid, retval);
    101         }
     144        async_msg_1(exch, CHAR_WRITE_BYTE, data);
     145        async_exchange_end(exch);
    102146}
     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};
    103154
    104155/**
Note: See TracChangeset for help on using the changeset viewer.