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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since a8bf1ea was 15f3c3f, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Rename devmap to loc, devfs to locfs.

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[3a2f8aa]1/*
[9be360ee]2 * Copyright (c) 2011 Jiri Svoboda
[3a2f8aa]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 * @{
[79ae36dd]32 */
[3a2f8aa]33/** @file
34 * @brief ADB keyboard port driver.
35 */
36
37#include <ipc/adb.h>
38#include <async.h>
[854eddd6]39#include <input.h>
[3a2f8aa]40#include <kbd_port.h>
41#include <kbd.h>
42#include <vfs/vfs.h>
43#include <fcntl.h>
44#include <errno.h>
[15f3c3f]45#include <loc.h>
[3a2f8aa]46
[9934f7d]47static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg);
[3a2f8aa]48static void adb_kbd_reg0_data(uint16_t data);
49
[9be360ee]50static int adb_port_init(kbd_dev_t *);
[b1bdc7a4]51static void adb_port_yield(void);
52static void adb_port_reclaim(void);
53static void adb_port_write(uint8_t data);
54
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};
61
[9be360ee]62static kbd_dev_t *kbd_dev;
[a40dea3]63static async_sess_t *dev_sess;
[3a2f8aa]64
[9be360ee]65static int adb_port_init(kbd_dev_t *kdev)
[3a2f8aa]66{
[79ae36dd]67 const char *dev = "adb/kbd";
[15f3c3f]68 service_id_t service_id;
[a40dea3]69 async_exch_t *exch;
70 int rc;
71
[9be360ee]72 kbd_dev = kdev;
[79ae36dd]73
[15f3c3f]74 rc = loc_service_get_id(dev, &service_id, 0);
[a40dea3]75 if (rc != EOK)
[79ae36dd]76 return rc;
77
[15f3c3f]78 dev_sess = loc_service_connect(EXCHANGE_ATOMIC, service_id, 0);
[a40dea3]79 if (dev_sess == NULL) {
80 printf("%s: Failed to connect to device\n", NAME);
81 return ENOENT;
82 }
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;
89 }
90
[3a2f8aa]91 /* NB: The callback connection is slotted for removal */
[a40dea3]92 rc = async_connect_to_me(exch, 0, 0, 0, kbd_port_events, NULL);
93 async_exchange_end(exch);
[79ae36dd]94 if (rc != EOK) {
[1875a0c]95 printf("%s: Failed to create callback from device\n", NAME);
[a40dea3]96 async_hangup(dev_sess);
[79ae36dd]97 return rc;
[3a2f8aa]98 }
[79ae36dd]99
100 return EOK;
[3a2f8aa]101}
102
[b1bdc7a4]103static void adb_port_yield(void)
[3a2f8aa]104{
105}
106
[b1bdc7a4]107static void adb_port_reclaim(void)
[3a2f8aa]108{
109}
110
[b1bdc7a4]111static void adb_port_write(uint8_t data)
[3a2f8aa]112{
113 /*async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);*/
114}
115
[9934f7d]116static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
[3a2f8aa]117{
118 /* Ignore parameters, the connection is already opened */
119 while (true) {
120
121 ipc_call_t call;
122 ipc_callid_t callid = async_get_call(&call);
123
124 int retval;
[79ae36dd]125
126 if (!IPC_GET_IMETHOD(call)) {
[3a2f8aa]127 /* TODO: Handle hangup */
128 return;
[79ae36dd]129 }
130
131 switch (IPC_GET_IMETHOD(call)) {
[3a2f8aa]132 case ADB_REG_NOTIF:
133 adb_kbd_reg0_data(IPC_GET_ARG1(call));
134 break;
135 default:
136 retval = ENOENT;
137 }
[4f14e1f8]138 async_answer_0(callid, retval);
[3a2f8aa]139 }
140}
141
142static void adb_kbd_reg0_data(uint16_t data)
143{
[1875a0c]144 uint8_t b0 = (data >> 8) & 0xff;
145 uint8_t b1 = data & 0xff;
146
[3a2f8aa]147 if (b0 != 0xff)
[1875a0c]148 kbd_push_data(kbd_dev, b0);
149
[3a2f8aa]150 if (b1 != 0xff)
[1875a0c]151 kbd_push_data(kbd_dev, b1);
[3a2f8aa]152}
153
154/**
155 * @}
156 */
Note: See TracBrowser for help on using the repository browser.