source: mainline/uspace/srv/hid/kbd/port/chardev.c@ 4f14e1f8

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

do not intermix low-level IPC methods with async framework methods

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2009 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 Chardev keyboard port driver.
35 */
36
37#include <ipc/char.h>
38#include <async.h>
39#include <kbd_port.h>
40#include <kbd.h>
41#include <vfs/vfs.h>
42#include <sys/stat.h>
43#include <fcntl.h>
44#include <errno.h>
45
46static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall);
47
48static int dev_phone;
49
50#define NAME "kbd"
51
52/** List of devices to try connecting to. */
53static const char *in_devs[] = {
54 "/dev/char/ps2a",
55 "/dev/char/s3c24ser"
56};
57
58static const int num_devs = sizeof(in_devs) / sizeof(in_devs[0]);
59
60int kbd_port_init(void)
61{
62 int input_fd;
63 int i;
64
65 input_fd = -1;
66 for (i = 0; i < num_devs; i++) {
67 struct stat s;
68
69 if (stat(in_devs[i], &s) == EOK)
70 break;
71 }
72
73 if (i >= num_devs) {
74 printf(NAME ": Could not find any suitable input device.\n");
75 return -1;
76 }
77
78 input_fd = open(in_devs[i], O_RDONLY);
79 if (input_fd < 0) {
80 printf(NAME ": failed opening device %s (%d).\n", in_devs[i],
81 input_fd);
82 return -1;
83 }
84
85 dev_phone = fd_phone(input_fd);
86 if (dev_phone < 0) {
87 printf(NAME ": Failed connecting to device\n");
88 return -1;
89 }
90
91 /* NB: The callback connection is slotted for removal */
92 if (async_connect_to_me(dev_phone, 0, 0, 0, kbd_port_events) != 0) {
93 printf(NAME ": Failed to create callback from device\n");
94 return -1;
95 }
96
97 return 0;
98}
99
100void kbd_port_yield(void)
101{
102}
103
104void kbd_port_reclaim(void)
105{
106}
107
108void kbd_port_write(uint8_t data)
109{
110 async_msg_1(dev_phone, CHAR_WRITE_BYTE, data);
111}
112
113static void kbd_port_events(ipc_callid_t iid, ipc_call_t *icall)
114{
115 /* Ignore parameters, the connection is already opened */
116 while (true) {
117
118 ipc_call_t call;
119 ipc_callid_t callid = async_get_call(&call);
120
121 int retval;
122
123 switch (IPC_GET_IMETHOD(call)) {
124 case IPC_M_PHONE_HUNGUP:
125 /* TODO: Handle hangup */
126 return;
127 case CHAR_NOTIF_BYTE:
128 kbd_push_scancode(IPC_GET_ARG1(call));
129 break;
130 default:
131 retval = ENOENT;
132 }
133 async_answer_0(callid, retval);
134 }
135}
136
137
138/**
139 * @}
140 */
Note: See TracBrowser for help on using the repository browser.