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

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

allow compositor and console to coexist side-by-side, use the input server as a poor man's seat arbitrator

  • kernel console notifies both about the release and grab events
  • input server arbitrates the seat selection between kernel console and any number of user space UIs (currently the console server and the compositor server)
  • input port yield and reclaim methods have been removed (they are used only on Ski and Niagara, both already need a more generic mechanism for the kernel/user space cooperation)
  • console and compositor server keep track of the kernel console via the input arbitration
  • move the waiting for a character device from init and terminal widget to getterm
  • Property mode set to 100644
File size: 3.6 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(EXCHANGE_ATOMIC, service_id, 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 rc = async_connect_to_me(exch, 0, 0, 0, kbd_port_events, NULL);
85 async_exchange_end(exch);
86 if (rc != EOK) {
87 printf("%s: Failed to create callback from device\n", NAME);
88 async_hangup(dev_sess);
89 return rc;
90 }
91
92 return EOK;
93}
94
95static void adb_port_write(uint8_t data)
96{
97 /*async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);*/
98}
99
100static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
101{
102 /* Ignore parameters, the connection is already opened */
103 while (true) {
104
105 ipc_call_t call;
106 ipc_callid_t callid = async_get_call(&call);
107
108 int retval = EOK;
109
110 if (!IPC_GET_IMETHOD(call)) {
111 /* TODO: Handle hangup */
112 return;
113 }
114
115 switch (IPC_GET_IMETHOD(call)) {
116 case ADB_REG_NOTIF:
117 adb_kbd_reg0_data(IPC_GET_ARG1(call));
118 break;
119 default:
120 retval = ENOENT;
121 }
122 async_answer_0(callid, retval);
123 }
124}
125
126static void adb_kbd_reg0_data(uint16_t data)
127{
128 uint8_t b0 = (data >> 8) & 0xff;
129 uint8_t b1 = data & 0xff;
130
131 if (b0 != 0xff)
132 kbd_push_data(kbd_dev, b0);
133
134 if (b1 != 0xff)
135 kbd_push_data(kbd_dev, b1);
136}
137
138/**
139 * @}
140 */
Note: See TracBrowser for help on using the repository browser.