source: mainline/uspace/srv/hid/input/ctl/kbdev.c

Last change on this file was fafb8e5, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Mechanically lowercase IPC_SET_*/IPC_GET_*

  • Property mode set to 100644
File size: 4.5 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_ctl
30 * @ingroup input
31 * @{
32 */
33/**
34 * @file
35 * @brief Keyboard device connector controller driver.
36 */
37
38#include <async.h>
39#include <stdbool.h>
40#include <errno.h>
41#include <io/console.h>
42#include <io/keycode.h>
43#include <ipc/kbdev.h>
44#include <loc.h>
45#include <stdlib.h>
46#include <vfs/vfs_sess.h>
47#include "../gsp.h"
48#include "../input.h"
49#include "../kbd.h"
50#include "../kbd_ctl.h"
51#include "../kbd_port.h"
52
53static errno_t kbdev_ctl_init(kbd_dev_t *);
54static void kbdev_ctl_set_ind(kbd_dev_t *, unsigned int);
55
56static void kbdev_callback_conn(ipc_call_t *, void *arg);
57
58kbd_ctl_ops_t kbdev_ctl = {
59 .parse = NULL,
60 .init = kbdev_ctl_init,
61 .set_ind = kbdev_ctl_set_ind
62};
63
64/** Kbdev softstate */
65typedef struct {
66 /** Link to generic keyboard device */
67 kbd_dev_t *kbd_dev;
68
69 /** Session with kbdev device */
70 async_sess_t *sess;
71} kbdev_t;
72
73static kbdev_t *kbdev_new(kbd_dev_t *kdev)
74{
75 kbdev_t *kbdev = calloc(1, sizeof(kbdev_t));
76 if (kbdev == NULL)
77 return NULL;
78
79 kbdev->kbd_dev = kdev;
80
81 return kbdev;
82}
83
84static void kbdev_destroy(kbdev_t *kbdev)
85{
86 if (kbdev->sess != NULL)
87 async_hangup(kbdev->sess);
88
89 free(kbdev);
90}
91
92static errno_t kbdev_ctl_init(kbd_dev_t *kdev)
93{
94 async_sess_t *sess = loc_service_connect(kdev->svc_id,
95 INTERFACE_DDF, 0);
96 if (sess == NULL) {
97 printf("%s: Failed starting session with '%s.'\n", NAME,
98 kdev->svc_name);
99 return ENOENT;
100 }
101
102 kbdev_t *kbdev = kbdev_new(kdev);
103 if (kbdev == NULL) {
104 printf("%s: Failed allocating device structure for '%s'.\n",
105 NAME, kdev->svc_name);
106 async_hangup(sess);
107 return ENOMEM;
108 }
109
110 kbdev->sess = sess;
111
112 async_exch_t *exch = async_exchange_begin(sess);
113 if (exch == NULL) {
114 printf("%s: Failed starting exchange with '%s'.\n", NAME,
115 kdev->svc_name);
116 kbdev_destroy(kbdev);
117 return ENOENT;
118 }
119
120 port_id_t port;
121 errno_t rc = async_create_callback_port(exch, INTERFACE_KBD_CB, 0, 0,
122 kbdev_callback_conn, kbdev, &port);
123
124 if (rc != EOK) {
125 printf("%s: Failed creating callback connection from '%s'.\n",
126 NAME, kdev->svc_name);
127 async_exchange_end(exch);
128 kbdev_destroy(kbdev);
129 return rc;
130 }
131
132 async_exchange_end(exch);
133
134 kdev->ctl_private = (void *) kbdev;
135 return 0;
136}
137
138static void kbdev_ctl_set_ind(kbd_dev_t *kdev, unsigned mods)
139{
140 async_sess_t *sess = ((kbdev_t *) kdev->ctl_private)->sess;
141 async_exch_t *exch = async_exchange_begin(sess);
142 if (!exch)
143 return;
144
145 async_msg_1(exch, KBDEV_SET_IND, mods);
146 async_exchange_end(exch);
147}
148
149static void kbdev_callback_conn(ipc_call_t *icall, void *arg)
150{
151 kbdev_t *kbdev;
152 errno_t retval;
153 int type, key;
154
155 /* Kbdev device structure */
156 kbdev = arg;
157
158 while (true) {
159 ipc_call_t call;
160 async_get_call(&call);
161
162 if (!ipc_get_imethod(&call)) {
163 async_answer_0(&call, EOK);
164 kbdev_destroy(kbdev);
165 return;
166 }
167
168 switch (ipc_get_imethod(&call)) {
169 case KBDEV_EVENT:
170 /* Got event from keyboard device */
171 retval = 0;
172 type = ipc_get_arg1(&call);
173 key = ipc_get_arg2(&call);
174 kbd_push_event(kbdev->kbd_dev, type, key);
175 break;
176 default:
177 retval = ENOTSUP;
178 break;
179 }
180
181 async_answer_0(&call, retval);
182 }
183}
184
185/**
186 * @}
187 */
Note: See TracBrowser for help on using the repository browser.