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


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/port
Files:
10 edited
2 moved

Legend:

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

    ra9d85df r1875a0c  
    9393        async_exchange_end(exch);
    9494        if (rc != EOK) {
    95                 printf(NAME ": Failed to create callback from device\n");
     95                printf("%s: Failed to create callback from device\n", NAME);
    9696                async_hangup(dev_sess);
    9797                return rc;
     
    142142static void adb_kbd_reg0_data(uint16_t data)
    143143{
    144         uint8_t b0, b1;
    145 
    146         b0 = (data >> 8) & 0xff;
    147         b1 = data & 0xff;
    148 
     144        uint8_t b0 = (data >> 8) & 0xff;
     145        uint8_t b1 = data & 0xff;
     146       
    149147        if (b0 != 0xff)
    150                 kbd_push_scancode(kbd_dev, b0);
     148                kbd_push_data(kbd_dev, b0);
     149       
    151150        if (b1 != 0xff)
    152                 kbd_push_scancode(kbd_dev, b1);
     151                kbd_push_data(kbd_dev, b1);
    153152}
    154153
  • uspace/srv/hid/input/port/adb_mouse.c

    ra9d85df r1875a0c  
    11/*
    2  * Copyright (c) 2009 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 ADB mouse port driver.
    3435 */
    3536
    36 #include <ipc/char.h>
     37#include <ipc/adb.h>
    3738#include <async.h>
    38 #include <vfs/vfs.h>
    39 #include <fcntl.h>
     39#include <input.h>
     40#include <mouse_port.h>
     41#include <mouse.h>
    4042#include <errno.h>
    4143#include <devmap.h>
    42 #include <char_mouse.h>
    43 #include <mouse_port.h>
    4444
    45 static void chardev_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
    46 
     45static mouse_dev_t *mouse_dev;
    4746static async_sess_t *dev_sess;
    4847
    49 #define NAME "char_mouse"
    50 
    51 int mouse_port_init(void)
    52 {
    53         devmap_handle_t handle;
    54         async_exch_t *exch;
    55         int rc;
    56        
    57         rc = devmap_device_get_handle("char/ps2b", &handle,
    58             IPC_FLAG_BLOCKING);
    59        
    60         if (rc != EOK) {
    61                 printf("%s: Failed resolving PS/2\n", NAME);
    62                 return rc;
    63         }
    64        
    65         dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle,
    66             IPC_FLAG_BLOCKING);
    67         if (dev_sess == NULL) {
    68                 printf("%s: Failed connecting to PS/2\n", NAME);
    69                 return ENOENT;
    70         }
    71        
    72         exch = async_exchange_begin(dev_sess);
    73         if (exch == NULL) {
    74                 printf("%s: Failed starting exchange with PS/2\n", NAME);
    75                 async_hangup(dev_sess);
    76                 return ENOMEM;
    77         }
    78        
    79         /* NB: The callback connection is slotted for removal */
    80         rc = async_connect_to_me(exch, 0, 0, 0, chardev_events, NULL);
    81         async_exchange_end(exch);
    82        
    83         if (rc != 0) {
    84                 printf(NAME ": Failed to create callback from device\n");
    85                 async_hangup(dev_sess);
    86                 return false;
    87         }
    88        
    89         return 0;
    90 }
    91 
    92 void mouse_port_yield(void)
    93 {
    94 }
    95 
    96 void mouse_port_reclaim(void)
    97 {
    98 }
    99 
    100 void mouse_port_write(uint8_t data)
    101 {
    102         async_exch_t *exch = async_exchange_begin(dev_sess);
    103         if (exch == NULL) {
    104                 printf("%s: Failed starting exchange with PS/2\n", NAME);
    105                 return;
    106         }
    107        
    108         async_msg_1(exch, CHAR_WRITE_BYTE, data);
    109        
    110         async_exchange_end(exch);
    111 }
    112 
    113 static void chardev_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     48static void mouse_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    11449{
    11550        /* Ignore parameters, the connection is already opened */
    11651        while (true) {
    117 
    11852                ipc_call_t call;
    11953                ipc_callid_t callid = async_get_call(&call);
    120 
     54               
    12155                int retval;
    12256               
     
    12559                        return;
    12660                }
    127 
     61               
    12862                switch (IPC_GET_IMETHOD(call)) {
    129                 case IPC_FIRST_USER_METHOD:
    130                         mouse_handle_byte(IPC_GET_ARG1(call));
     63                case ADB_REG_NOTIF:
     64                        mouse_push_data(mouse_dev, IPC_GET_ARG1(call));
    13165                        break;
    13266                default:
    13367                        retval = ENOENT;
    13468                }
     69               
    13570                async_answer_0(callid, retval);
    13671        }
    13772}
    13873
     74static int adb_port_init(mouse_dev_t *mdev)
     75{
     76        const char *dev = "adb/mouse";
     77       
     78        mouse_dev = mdev;
     79       
     80        devmap_handle_t handle;
     81        int rc = devmap_device_get_handle(dev, &handle, 0);
     82        if (rc != EOK)
     83                return rc;
     84       
     85        dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 0);
     86        if (dev_sess == NULL) {
     87                printf("%s: Failed to connect to device\n", NAME);
     88                return ENOENT;
     89        }
     90       
     91        async_exch_t *exch = async_exchange_begin(dev_sess);
     92        if (exch == NULL) {
     93                printf("%s: Failed starting exchange with device\n", NAME);
     94                async_hangup(dev_sess);
     95                return ENOMEM;
     96        }
     97       
     98        /* NB: The callback connection is slotted for removal */
     99        rc = async_connect_to_me(exch, 0, 0, 0, mouse_port_events, NULL);
     100        async_exchange_end(exch);
     101        if (rc != EOK) {
     102                printf("%s: Failed to create callback from device\n", NAME);
     103                async_hangup(dev_sess);
     104                return rc;
     105        }
     106       
     107        return EOK;
     108}
     109
     110static void adb_port_yield(void)
     111{
     112}
     113
     114static void adb_port_reclaim(void)
     115{
     116}
     117
     118static void adb_port_write(uint8_t data)
     119{
     120}
     121
     122mouse_port_ops_t adb_mouse_port = {
     123        .init = adb_port_init,
     124        .yield = adb_port_yield,
     125        .reclaim = adb_port_reclaim,
     126        .write = adb_port_write
     127};
     128
    139129/**
    140130 * @}
  • uspace/srv/hid/input/port/chardev.c

    ra9d85df r1875a0c  
    108108       
    109109        if (rc != 0) {
    110                 printf(NAME ": Failed to create callback from device\n");
     110                printf("%s: Failed to create callback from device\n", NAME);
    111111                async_hangup(dev_sess);
    112112                return -1;
     
    153153                switch (IPC_GET_IMETHOD(call)) {
    154154                case CHAR_NOTIF_BYTE:
    155                         kbd_push_scancode(kbd_dev, IPC_GET_ARG1(call));
     155                        kbd_push_data(kbd_dev, IPC_GET_ARG1(call));
    156156                        break;
    157157                default:
  • 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/**
  • uspace/srv/hid/input/port/gxemul.c

    ra9d85df r1875a0c  
    108108
    109109/** Process data sent when a key is pressed.
    110  * 
    111  *  @param keybuffer Buffer of pressed keys.
    112  *  @param call      IPC call.
    113110 *
    114  *  @return Always 1.
     111 * @param keybuffer Buffer of pressed keys.
     112 * @param call      IPC call.
     113 *
    115114 */
    116115static void gxemul_irq_handler(ipc_callid_t iid, ipc_call_t *call)
    117116{
    118         int scan_code = IPC_GET_ARG2(*call);
    119 
    120         kbd_push_scancode(kbd_dev, scan_code);
     117        kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
    121118}
    122119
  • uspace/srv/hid/input/port/msim.c

    ra9d85df r1875a0c  
    109109static void msim_irq_handler(ipc_callid_t iid, ipc_call_t *call)
    110110{
    111         int scan_code = IPC_GET_ARG2(*call);
    112         kbd_push_scancode(kbd_dev, scan_code);
     111        kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
    113112}
    114113
    115114/** @}
    116 */
     115 */
  • uspace/srv/hid/input/port/niagara.c

    ra9d85df r1875a0c  
    148148                c = input_buffer->data[input_buffer->read_ptr];
    149149                input_buffer->read_ptr =
    150                         ((input_buffer->read_ptr) + 1) % INPUT_BUFFER_SIZE;
    151                 kbd_push_scancode(kbd_dev, c);
     150                    ((input_buffer->read_ptr) + 1) % INPUT_BUFFER_SIZE;
     151                kbd_push_data(kbd_dev, c);
    152152        }
    153153}
  • uspace/srv/hid/input/port/ns16550.c

    ra9d85df r1875a0c  
    156156static void ns16550_irq_handler(ipc_callid_t iid, ipc_call_t *call)
    157157{
    158         int scan_code = IPC_GET_ARG2(*call);
    159         kbd_push_scancode(kbd_dev, scan_code);
     158        kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
    160159       
    161160        if (irc_service)
  • uspace/srv/hid/input/port/pl050.c

    ra9d85df r1875a0c  
    137137static void pl050_irq_handler(ipc_callid_t iid, ipc_call_t *call)
    138138{
    139         int scan_code = IPC_GET_ARG2(*call);
    140 
    141         kbd_push_scancode(kbd_dev, scan_code);
    142         return;
     139        kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
    143140}
    144141
    145142/**
    146143 * @}
    147  */ 
     144 */
  • uspace/srv/hid/input/port/sgcn.c

    ra9d85df r1875a0c  
    183183                *in_rdptr_ptr = (((*in_rdptr_ptr) - begin + 1) % size) + begin;
    184184                buf_ptr = (volatile char *)
    185                         SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
    186                 kbd_push_scancode(kbd_dev, c);
     185                    SGCN_BUFFER(char, SGCN_BUFFER_HEADER->in_rdptr);
     186                kbd_push_data(kbd_dev, c);
    187187        }
    188188}
  • uspace/srv/hid/input/port/ski.c

    ra9d85df r1875a0c  
    110110                        if (c == 0)
    111111                                break;
    112                         kbd_push_scancode(kbd_dev, c);
     112                        kbd_push_data(kbd_dev, c);
    113113                }
    114114
  • uspace/srv/hid/input/port/z8530.c

    ra9d85df r1875a0c  
    142142static void z8530_irq_handler(ipc_callid_t iid, ipc_call_t *call)
    143143{
    144         int scan_code = IPC_GET_ARG2(*call);
    145         kbd_push_scancode(kbd_dev, scan_code);
     144        kbd_push_data(kbd_dev, IPC_GET_ARG2(*call));
    146145       
    147146        if (irc_service)
Note: See TracChangeset for help on using the changeset viewer.