Changeset a33f0a6 in mainline for uspace/srv/hid/input/port/adb.c


Ignore:
Timestamp:
2011-08-03T17:34:57Z (14 years ago)
Author:
Oleg Romanenko <romanenko.oleg@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1940326
Parents:
52a79081 (diff), 3fab770 (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 from mainline

File:
1 moved

Legend:

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

    r52a79081 ra33f0a6  
    11/*
    2  * Copyright (c) 2010 Jiri Svoboda
     2 * Copyright (c) 2011 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3030 * @ingroup kbd
    3131 * @{
    32  */ 
     32 */
    3333/** @file
    3434 * @brief ADB keyboard port driver.
     
    3737#include <ipc/adb.h>
    3838#include <async.h>
     39#include <input.h>
    3940#include <kbd_port.h>
    4041#include <kbd.h>
     
    4243#include <fcntl.h>
    4344#include <errno.h>
     45#include <devmap.h>
    4446
    45 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall);
     47static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
    4648static void adb_kbd_reg0_data(uint16_t data);
    4749
    48 static int dev_phone;
     50static int adb_port_init(kbd_dev_t *);
     51static void adb_port_yield(void);
     52static void adb_port_reclaim(void);
     53static void adb_port_write(uint8_t data);
    4954
    50 #define NAME "kbd"
     55kbd_port_ops_t adb_port = {
     56        .init = adb_port_init,
     57        .yield = adb_port_yield,
     58        .reclaim = adb_port_reclaim,
     59        .write = adb_port_write
     60};
    5161
    52 int kbd_port_init(void)
     62static kbd_dev_t *kbd_dev;
     63static async_sess_t *dev_sess;
     64
     65static int adb_port_init(kbd_dev_t *kdev)
    5366{
    54         const char *input = "/dev/adb/kbd";
    55         int input_fd;
    56 
    57         printf(NAME ": open %s\n", input);
    58 
    59         input_fd = open(input, O_RDONLY);
    60         if (input_fd < 0) {
    61                 printf(NAME ": Failed opening %s (%d)\n", input, input_fd);
    62                 return false;
     67        const char *dev = "adb/kbd";
     68        devmap_handle_t handle;
     69        async_exch_t *exch;
     70        int rc;
     71       
     72        kbd_dev = kdev;
     73       
     74        rc = devmap_device_get_handle(dev, &handle, 0);
     75        if (rc != EOK)
     76                return rc;
     77       
     78        dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 0);
     79        if (dev_sess == NULL) {
     80                printf("%s: Failed to connect to device\n", NAME);
     81                return ENOENT;
    6382        }
    64 
    65         dev_phone = fd_phone(input_fd);
    66         if (dev_phone < 0) {
    67                 printf(NAME ": Failed to connect to device\n");
    68                 return false;
     83       
     84        exch = async_exchange_begin(dev_sess);
     85        if (exch == NULL) {
     86                printf("%s: Failed starting exchange with device\n", NAME);
     87                async_hangup(dev_sess);
     88                return ENOMEM;
    6989        }
    70 
     90       
    7191        /* NB: The callback connection is slotted for removal */
    72         if (async_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events) != 0) {
    73                 printf(NAME ": Failed to create callback from device\n");
    74                 return false;
     92        rc = async_connect_to_me(exch, 0, 0, 0, kbd_port_events, NULL);
     93        async_exchange_end(exch);
     94        if (rc != EOK) {
     95                printf("%s: Failed to create callback from device\n", NAME);
     96                async_hangup(dev_sess);
     97                return rc;
    7598        }
    76 
    77         return 0;
     99       
     100        return EOK;
    78101}
    79102
    80 void kbd_port_yield(void)
     103static void adb_port_yield(void)
    81104{
    82105}
    83106
    84 void kbd_port_reclaim(void)
     107static void adb_port_reclaim(void)
    85108{
    86109}
    87110
    88 void kbd_port_write(uint8_t data)
     111static void adb_port_write(uint8_t data)
    89112{
    90113        /*async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);*/
    91114}
    92115
    93 static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall)
     116static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    94117{
    95118        /* Ignore parameters, the connection is already opened */
     
    100123
    101124                int retval;
    102 
    103                 switch (IPC_GET_IMETHOD(call)) {
    104                 case IPC_M_PHONE_HUNGUP:
     125               
     126                if (!IPC_GET_IMETHOD(call)) {
    105127                        /* TODO: Handle hangup */
    106128                        return;
     129                }
     130               
     131                switch (IPC_GET_IMETHOD(call)) {
    107132                case ADB_REG_NOTIF:
    108133                        adb_kbd_reg0_data(IPC_GET_ARG1(call));
     
    117142static void adb_kbd_reg0_data(uint16_t data)
    118143{
    119         uint8_t b0, b1;
    120 
    121         b0 = (data >> 8) & 0xff;
    122         b1 = data & 0xff;
    123 
     144        uint8_t b0 = (data >> 8) & 0xff;
     145        uint8_t b1 = data & 0xff;
     146       
    124147        if (b0 != 0xff)
    125                 kbd_push_scancode(b0);
     148                kbd_push_data(kbd_dev, b0);
     149       
    126150        if (b1 != 0xff)
    127                 kbd_push_scancode(b1);
     151                kbd_push_data(kbd_dev, b1);
    128152}
    129153
Note: See TracChangeset for help on using the changeset viewer.