Changeset 1875a0c in mainline for uspace/srv/hid/input/proto


Ignore:
Timestamp:
2011-06-21T19:10:20Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
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)
Location:
uspace/srv/hid/input/proto
Files:
3 moved

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/input/proto/adb.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
    30  * @brief
     29/** @addtogroup mouse_proto
     30 * @ingroup input
    3131 * @{
    3232 */
    33 /** @file
     33/**
     34 * @file
     35 * @brief ADB protocol driver.
    3436 */
    3537
    36 #ifndef ADB_MOUSE_H_
    37 #define ADB_MOUSE_H_
     38#include <bool.h>
     39#include <mouse.h>
     40#include <mouse_port.h>
     41#include <mouse_proto.h>
    3842
    39 #include <sys/types.h>
     43static mouse_dev_t *mouse_dev;
     44static bool b1_pressed;
     45static bool b2_pressed;
    4046
    41 #define NAME       "adb_ms"
    42 #define NAMESPACE  "hid_in"
     47static int adb_proto_init(mouse_dev_t *mdev)
     48{
     49        mouse_dev = mdev;
     50        b1_pressed = false;
     51        b2_pressed = false;
     52       
     53        return 0;
     54}
    4355
    44 extern void mouse_handle_data(uint16_t);
     56/** Process mouse data */
     57static void adb_proto_parse(sysarg_t data)
     58{
     59        bool b1, b2;
     60        uint16_t udx, udy;
     61        int dx, dy;
     62       
     63        /* Extract fields. */
     64        b1 = ((data >> 15) & 1) == 0;
     65        udy = (data >> 8) & 0x7f;
     66        b2 = ((data >> 7) & 1) == 0;
     67        udx = data & 0x7f;
     68       
     69        /* Decode 7-bit two's complement signed values. */
     70        dx = (udx & 0x40) ? (udx - 0x80) : udx;
     71        dy = (udy & 0x40) ? (udy - 0x80) : udy;
     72       
     73        if (b1 != b1_pressed) {
     74                mouse_push_event_button(mouse_dev, 1, b1);
     75                b1_pressed = b1;
     76        }
     77       
     78        if (b2 != b2_pressed) {
     79                mouse_push_event_button(mouse_dev, 2, b2);
     80                b1_pressed = b1;
     81        }
     82       
     83        if (dx != 0 || dy != 0)
     84                mouse_push_event_move(mouse_dev, dx, dy);
     85}
    4586
    46 #endif
     87mouse_proto_ops_t adb_proto = {
     88        .parse = adb_proto_parse,
     89        .init = adb_proto_init
     90};
    4791
    4892/**
  • uspace/srv/hid/input/proto/mousedev.c

    ra9d85df r1875a0c  
    11/*
    2  * Copyright (c) 2011 Jiri Svoboda
     2 * Copyright (c) 2011 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /**
    30  * @addtogroup inputgen generic
    31  * @brief Mouse device handling.
     29/** @addtogroup mouse_proto
    3230 * @ingroup input
    3331 * @{
    3432 */
    35 /** @file
     33/**
     34 * @file
     35 * @brief Mouse device connector controller driver.
    3636 */
    3737
    38 #include <adt/list.h>
     38#include <stdio.h>
     39#include <fcntl.h>
     40#include <vfs/vfs_sess.h>
     41#include <malloc.h>
    3942#include <async.h>
    4043#include <errno.h>
    41 #include <fcntl.h>
     44#include <ipc/mouseev.h>
    4245#include <input.h>
    43 #include <ipc/mouse.h>
    4446#include <mouse.h>
    45 #include <stdio.h>
    46 #include <stdlib.h>
    47 #include <vfs/vfs_sess.h>
     47#include <mouse_port.h>
     48#include <mouse_proto.h>
    4849
    49 static void mouse_callback_conn(ipc_callid_t, ipc_call_t *, void *);
     50/** Mousedev softstate */
     51typedef struct {
     52        /** Link to generic mouse device */
     53        mouse_dev_t *mouse_dev;
     54       
     55        /** Session to mouse device */
     56        async_sess_t *sess;
     57       
     58        /** File descriptor of open mousedev device */
     59        int fd;
     60} mousedev_t;
    5061
    51 static mouse_dev_t *mouse_dev_new(void)
     62static mousedev_t *mousedev_new(mouse_dev_t *mdev)
    5263{
    53         mouse_dev_t *mdev;
    54 
    55         mdev = calloc(1, sizeof(mouse_dev_t));
    56         if (mdev == NULL) {
    57                 printf(NAME ": Error allocating mouse device. "
    58                     "Out of memory.\n");
     64        mousedev_t *mousedev = calloc(1, sizeof(mousedev_t));
     65        if (mousedev == NULL)
    5966                return NULL;
    60         }
    61 
    62         link_initialize(&mdev->mouse_devs);
    63         return mdev;
     67       
     68        mousedev->mouse_dev = mdev;
     69        mousedev->fd = -1;
     70       
     71        return mousedev;
    6472}
    6573
    66 static int mouse_dev_connect(mouse_dev_t *mdev, const char *dev_path)
     74static void mousedev_destroy(mousedev_t *mousedev)
    6775{
    68         async_sess_t *sess;
    69         async_exch_t *exch;
    70         int fd;
    71         int rc;
    72 
    73         fd = open(dev_path, O_RDWR);
    74         if (fd < 0) {
    75                 return -1;
    76         }
    77 
    78         sess = fd_session(EXCHANGE_SERIALIZE, fd);
    79         if (sess == NULL) {
    80                 printf(NAME ": Failed starting session with '%s'\n", dev_path);
    81                 close(fd);
    82                 return -1;
    83         }
    84 
    85         exch = async_exchange_begin(sess);
    86         if (exch == NULL) {
    87                 printf(NAME ": Failed starting exchange with '%s'.\n", dev_path);
    88                 return -1;
    89         }
    90 
    91         rc = async_connect_to_me(exch, 0, 0, 0, mouse_callback_conn, mdev);
    92         if (rc != EOK) {
    93                 printf(NAME ": Failed creating callback connection from '%s'.\n",
    94                     dev_path);
    95                 async_exchange_end(exch);
    96                 return -1;
    97         }
    98 
    99         async_exchange_end(exch);
    100 
    101         mdev->dev_path = dev_path;
    102         return 0;
     76        if (mousedev->sess != NULL)
     77                async_hangup(mousedev->sess);
     78       
     79        if (mousedev->fd >= 0)
     80                close(mousedev->fd);
     81       
     82        free(mousedev);
    10383}
    10484
    105 /** Add new mouse device.
    106  *
    107  * @param dev_path      Filesystem path to the device (/dev/class/...)
    108  */
    109 int mouse_add_dev(const char *dev_path)
     85static void mousedev_callback_conn(ipc_callid_t iid, ipc_call_t *icall,
     86    void *arg)
    11087{
    111         mouse_dev_t *mdev;
    112         int rc;
    113 
    114         mdev = mouse_dev_new();
    115         if (mdev == NULL)
    116                 return -1;
    117 
    118         rc = mouse_dev_connect(mdev, dev_path);
    119         if (rc != EOK) {
    120                 free(mdev);
    121                 return -1;
    122         }
    123 
    124         list_append(&mdev->mouse_devs, &mouse_devs);
    125         return EOK;
    126 }
    127 
    128 /** Mouse device callback connection handler. */
    129 static void mouse_callback_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    130 {
    131         int retval;
    132 
     88        /* Mousedev device structure */
     89        mousedev_t *mousedev = (mousedev_t *) arg;
     90       
    13391        while (true) {
    13492                ipc_call_t call;
    135                 ipc_callid_t callid;
    136 
    137                 callid = async_get_call(&call);
     93                ipc_callid_t callid = async_get_call(&call);
     94               
    13895                if (!IPC_GET_IMETHOD(call)) {
    13996                        /* XXX Handle hangup */
    14097                        return;
    14198                }
    142 
     99               
     100                int retval;
     101               
    143102                switch (IPC_GET_IMETHOD(call)) {
    144                 case MEVENT_BUTTON:
    145                         input_event_button(IPC_GET_ARG1(call),
     103                case MOUSEEV_MOVE_EVENT:
     104                        mouse_push_event_move(mousedev->mouse_dev, IPC_GET_ARG1(call),
    146105                            IPC_GET_ARG2(call));
    147                         retval = 0;
     106                        retval = EOK;
    148107                        break;
    149                 case MEVENT_MOVE:
    150                         input_event_move(IPC_GET_ARG1(call),
     108                case MOUSEEV_BUTTON_EVENT:
     109                        mouse_push_event_button(mousedev->mouse_dev, IPC_GET_ARG1(call),
    151110                            IPC_GET_ARG2(call));
    152                         retval = 0;
     111                        retval = EOK;
    153112                        break;
    154113                default:
     
    156115                        break;
    157116                }
    158 
     117               
    159118                async_answer_0(callid, retval);
    160119        }
    161120}
    162121
     122static int mousedev_proto_init(mouse_dev_t *mdev)
     123{
     124        const char *pathname = mdev->dev_path;
     125       
     126        int fd = open(pathname, O_RDWR);
     127        if (fd < 0)
     128                return -1;
     129       
     130        async_sess_t *sess = fd_session(EXCHANGE_SERIALIZE, fd);
     131        if (sess == NULL) {
     132                printf("%s: Failed starting session with '%s'\n", NAME, pathname);
     133                close(fd);
     134                return -1;
     135        }
     136       
     137        mousedev_t *mousedev = mousedev_new(mdev);
     138        if (mousedev == NULL) {
     139                printf("%s: Failed allocating device structure for '%s'.\n",
     140                    NAME, pathname);
     141                return -1;
     142        }
     143       
     144        mousedev->fd = fd;
     145        mousedev->sess = sess;
     146       
     147        async_exch_t *exch = async_exchange_begin(sess);
     148        if (exch == NULL) {
     149                printf("%s: Failed starting exchange with '%s'.\n", NAME, pathname);
     150                mousedev_destroy(mousedev);
     151                return -1;
     152        }
     153       
     154        int rc = async_connect_to_me(exch, 0, 0, 0, mousedev_callback_conn, mousedev);
     155        async_exchange_end(exch);
     156       
     157        if (rc != EOK) {
     158                printf("%s: Failed creating callback connection from '%s'.\n",
     159                    NAME, pathname);
     160                mousedev_destroy(mousedev);
     161                return -1;
     162        }
     163       
     164        return 0;
     165}
     166
     167mouse_proto_ops_t mousedev_proto = {
     168        .init = mousedev_proto_init
     169};
     170
    163171/**
    164172 * @}
  • uspace/srv/hid/input/proto/ps2.c

    ra9d85df r1875a0c  
    11/*
    2  * Copyright (c) 2006 Ondrej Palkovsky
     2 * Copyright (c) 2011 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup mouse
     29/** @addtogroup mouse_proto
     30 * @ingroup input
    3031 * @{
    3132 */
    3233/**
    3334 * @file
    34  * @brief PS/2 mouse protocol driver.
     35 * @brief PS/2 protocol driver.
    3536 */
    3637
    37 #include <stdio.h>
     38#include <mouse.h>
    3839#include <mouse_port.h>
    39 #include <char_mouse.h>
    4040#include <mouse_proto.h>
    41 
    42 #define BUFSIZE 3
    4341
    4442#define PS2_MOUSE_OUT_INIT  0xf4
    4543#define PS2_MOUSE_ACK       0xfa
     44
     45#define BUFSIZE 3
    4646
    4747typedef struct {
     
    4949                unsigned char data[BUFSIZE];
    5050                struct {
    51                         unsigned leftbtn : 1;
    52                         unsigned rightbtn : 1;
    53                         unsigned middlebtn : 1;
    54                         unsigned isone : 1; /* Always one */
    55                         unsigned xsign : 1;
    56                         unsigned ysign : 1;
    57                         unsigned xovfl : 1;
    58                         unsigned yovfl : 1;
     51                        unsigned int leftbtn : 1;
     52                        unsigned int rightbtn : 1;
     53                        unsigned int middlebtn : 1;
     54                        unsigned int isone : 1; /* Always one */
     55                        unsigned int xsign : 1;
     56                        unsigned int ysign : 1;
     57                        unsigned int xovfl : 1;
     58                        unsigned int yovfl : 1;
    5959                        unsigned char x;
    6060                        unsigned char y;
     
    6464
    6565static ps2packet_t buf;
    66 static int bufpos = 0;
    67 static int leftbtn = 0;
    68 static int rightbtn = 0;
    69 static int middlebtn = 0;
     66static unsigned int bufpos;
     67static unsigned int leftbtn;
     68static unsigned int rightbtn;
     69static unsigned int middlebtn;
    7070
    71 int mouse_proto_init(void)
     71static mouse_dev_t *mouse_dev;
     72
     73static int ps2_proto_init(mouse_dev_t *mdev)
    7274{
    73         mouse_port_write(PS2_MOUSE_OUT_INIT);
     75        mouse_dev = mdev;
     76        bufpos = 0;
     77        leftbtn = 0;
     78        rightbtn = 0;
     79       
     80        mouse_dev->port_ops->write(PS2_MOUSE_OUT_INIT);
    7481        return 0;
    7582}
     
    7986{
    8087        int tmp;
    81 
     88       
    8289        if (!sign)
    8390                return data;
    84 
    85         tmp = ((unsigned char)~data) + 1;
     91       
     92        tmp = ((unsigned char) ~data) + 1;
    8693        return -tmp;
    8794}
    8895
    8996/** Process mouse data */
    90 void mouse_proto_parse_byte(int data)
     97static void ps2_proto_parse(sysarg_t data)
    9198{
    9299        int x, y;
    93 
     100       
    94101        /* Check that we have not lost synchronization */
    95102        if (bufpos == 0 && !(data & 0x8))
    96103                return; /* Synchro lost, ignore byte */
    97 
     104       
    98105        buf.u.data[bufpos++] = data;
    99106        if (bufpos == BUFSIZE) {
    100107                bufpos = 0;
    101 
     108               
    102109                if (buf.u.val.leftbtn ^ leftbtn) {
    103110                        leftbtn = buf.u.val.leftbtn;
    104                         mouse_ev_btn(1, leftbtn);
     111                        mouse_push_event_button(mouse_dev, 1, leftbtn);
    105112                }
    106 
     113               
    107114                if (buf.u.val.rightbtn ^ rightbtn) {
    108115                        rightbtn = buf.u.val.rightbtn;
    109                         mouse_ev_btn(2, rightbtn);
     116                        mouse_push_event_button(mouse_dev, 2, rightbtn);
    110117                }
    111 
     118               
    112119                if (buf.u.val.middlebtn ^ middlebtn) {
    113120                        middlebtn = buf.u.val.middlebtn;
    114                         mouse_ev_btn(3, middlebtn);
     121                        mouse_push_event_button(mouse_dev, 3, middlebtn);
    115122                }
     123               
     124                x = bit9toint(buf.u.val.xsign, buf.u.val.x);
     125                y = -bit9toint(buf.u.val.ysign, buf.u.val.y);
     126               
     127                if (x != 0 || y != 0)
     128                        mouse_push_event_move(mouse_dev, x, y);
     129        }
     130}
    116131
    117                 x =   bit9toint(buf.u.val.xsign, buf.u.val.x);
    118                 y = - bit9toint(buf.u.val.ysign, buf.u.val.y);
    119 
    120                 if (x != 0 || y != 0) {
    121                         mouse_ev_move(x, y);
    122                 }
    123         }
    124 
    125         return;
    126 }
     132mouse_proto_ops_t ps2_proto = {
     133        .parse = ps2_proto_parse,
     134        .init = ps2_proto_init
     135};
    127136
    128137/**
Note: See TracChangeset for help on using the changeset viewer.