source: mainline/uspace/srv/hid/input/port/adb.c@ d776329b

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since d776329b was f9b2cb4c, checked in by Martin Decky <martin@…>, 10 years ago

unify interface API

  • introduce new interfaces
  • unify location service clients to always expect service ID as the second argument
  • remove obsolete methods that take explicit exchange management arguments (first phase)
  • use interfaces in device drivers, devman, location service, logger, inet
  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup kbd_port
30 * @ingroup kbd
31 * @{
32 */
33/** @file
34 * @brief ADB keyboard port driver.
35 */
36
37#include <ipc/adb.h>
38#include <async.h>
39#include <vfs/vfs.h>
40#include <fcntl.h>
41#include <errno.h>
42#include <loc.h>
43#include "../input.h"
44#include "../kbd_port.h"
45#include "../kbd.h"
46
47static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
48static void adb_kbd_reg0_data(uint16_t data);
49
50static int adb_port_init(kbd_dev_t *);
51static void adb_port_write(uint8_t);
52
53kbd_port_ops_t adb_port = {
54 .init = adb_port_init,
55 .write = adb_port_write
56};
57
58static kbd_dev_t *kbd_dev;
59static async_sess_t *dev_sess;
60
61static int adb_port_init(kbd_dev_t *kdev)
62{
63 kbd_dev = kdev;
64
65 const char *dev = "adb/kbd";
66 service_id_t service_id;
67 int rc = loc_service_get_id(dev, &service_id, 0);
68 if (rc != EOK)
69 return rc;
70
71 dev_sess = loc_service_connect(service_id, INTERFACE_DDF, 0);
72 if (dev_sess == NULL) {
73 printf("%s: Failed to connect to device\n", NAME);
74 return ENOENT;
75 }
76
77 async_exch_t *exch = async_exchange_begin(dev_sess);
78 if (exch == NULL) {
79 printf("%s: Failed starting exchange with device\n", NAME);
80 async_hangup(dev_sess);
81 return ENOMEM;
82 }
83
84 port_id_t port;
85 rc = async_create_callback_port(exch, INTERFACE_ADB_CB, 0, 0,
86 kbd_port_events, NULL, &port);
87
88 async_exchange_end(exch);
89 if (rc != EOK) {
90 printf("%s: Failed to create callback from device\n", NAME);
91 async_hangup(dev_sess);
92 return rc;
93 }
94
95 return EOK;
96}
97
98static void adb_port_write(uint8_t data)
99{
100 /*async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);*/
101}
102
103static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
104{
105 /* Ignore parameters, the connection is already opened */
106 while (true) {
107
108 ipc_call_t call;
109 ipc_callid_t callid = async_get_call(&call);
110
111 int retval = EOK;
112
113 if (!IPC_GET_IMETHOD(call)) {
114 /* TODO: Handle hangup */
115 return;
116 }
117
118 switch (IPC_GET_IMETHOD(call)) {
119 case ADB_REG_NOTIF:
120 adb_kbd_reg0_data(IPC_GET_ARG1(call));
121 break;
122 default:
123 retval = ENOENT;
124 }
125 async_answer_0(callid, retval);
126 }
127}
128
129static void adb_kbd_reg0_data(uint16_t data)
130{
131 uint8_t b0 = (data >> 8) & 0xff;
132 uint8_t b1 = data & 0xff;
133
134 if (b0 != 0xff)
135 kbd_push_data(kbd_dev, b0);
136
137 if (b1 != 0xff)
138 kbd_push_data(kbd_dev, b1);
139}
140
141/**
142 * @}
143 */
Note: See TracBrowser for help on using the repository browser.