source: mainline/uspace/srv/hid/input/port/adb_mouse.c@ df02460

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since df02460 was df02460, checked in by Jakub Jermar <jakub@…>, 14 years ago

Fix includes.

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
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 mouse_port
30 * @ingroup mouse
31 * @{
32 */
33/** @file
34 * @brief ADB mouse port driver.
35 */
36
37#include <ipc/adb.h>
38#include <async.h>
39#include <input.h>
40#include <mouse_port.h>
41#include <mouse.h>
42#include <errno.h>
43#include <devmap.h>
44#include <stdio.h>
45
46static mouse_dev_t *mouse_dev;
47static async_sess_t *dev_sess;
48
49static void mouse_port_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
50{
51 /* Ignore parameters, the connection is already opened */
52 while (true) {
53 ipc_call_t call;
54 ipc_callid_t callid = async_get_call(&call);
55
56 int retval;
57
58 if (!IPC_GET_IMETHOD(call)) {
59 /* TODO: Handle hangup */
60 return;
61 }
62
63 switch (IPC_GET_IMETHOD(call)) {
64 case ADB_REG_NOTIF:
65 mouse_push_data(mouse_dev, IPC_GET_ARG1(call));
66 break;
67 default:
68 retval = ENOENT;
69 }
70
71 async_answer_0(callid, retval);
72 }
73}
74
75static int adb_port_init(mouse_dev_t *mdev)
76{
77 const char *dev = "adb/mouse";
78
79 mouse_dev = mdev;
80
81 devmap_handle_t handle;
82 int rc = devmap_device_get_handle(dev, &handle, 0);
83 if (rc != EOK)
84 return rc;
85
86 dev_sess = devmap_device_connect(EXCHANGE_ATOMIC, handle, 0);
87 if (dev_sess == NULL) {
88 printf("%s: Failed to connect to device\n", NAME);
89 return ENOENT;
90 }
91
92 async_exch_t *exch = async_exchange_begin(dev_sess);
93 if (exch == NULL) {
94 printf("%s: Failed starting exchange with device\n", NAME);
95 async_hangup(dev_sess);
96 return ENOMEM;
97 }
98
99 /* NB: The callback connection is slotted for removal */
100 rc = async_connect_to_me(exch, 0, 0, 0, mouse_port_events, NULL);
101 async_exchange_end(exch);
102 if (rc != EOK) {
103 printf("%s: Failed to create callback from device\n", NAME);
104 async_hangup(dev_sess);
105 return rc;
106 }
107
108 return EOK;
109}
110
111static void adb_port_yield(void)
112{
113}
114
115static void adb_port_reclaim(void)
116{
117}
118
119static void adb_port_write(uint8_t data)
120{
121}
122
123mouse_port_ops_t adb_mouse_port = {
124 .init = adb_port_init,
125 .yield = adb_port_yield,
126 .reclaim = adb_port_reclaim,
127 .write = adb_port_write
128};
129
130/**
131 * @}
132 */
Note: See TracBrowser for help on using the repository browser.