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_proto
|
---|
30 | * @ingroup input
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /**
|
---|
34 | * @file
|
---|
35 | * @brief ADB protocol driver.
|
---|
36 | */
|
---|
37 |
|
---|
38 | #include <bool.h>
|
---|
39 | #include <mouse.h>
|
---|
40 | #include <mouse_port.h>
|
---|
41 | #include <mouse_proto.h>
|
---|
42 |
|
---|
43 | static mouse_dev_t *mouse_dev;
|
---|
44 | static bool b1_pressed;
|
---|
45 | static bool b2_pressed;
|
---|
46 |
|
---|
47 | static int adb_proto_init(mouse_dev_t *mdev)
|
---|
48 | {
|
---|
49 | mouse_dev = mdev;
|
---|
50 | b1_pressed = false;
|
---|
51 | b2_pressed = false;
|
---|
52 |
|
---|
53 | return 0;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /** Process mouse data */
|
---|
57 | static void adb_proto_parse(sysarg_t data)
|
---|
58 | {
|
---|
59 | bool b1, b2;
|
---|
60 | uint16_t udx, udy;
|
---|
61 | int dx, dy;
|
---|
62 |
|
---|
63 | /* Extract fields. */
|
---|
64 | b1 = ((data >> 15) & 1) == 0;
|
---|
65 | udy = (data >> 8) & 0x7f;
|
---|
66 | b2 = ((data >> 7) & 1) == 0;
|
---|
67 | udx = data & 0x7f;
|
---|
68 |
|
---|
69 | /* Decode 7-bit two's complement signed values. */
|
---|
70 | dx = (udx & 0x40) ? (udx - 0x80) : udx;
|
---|
71 | dy = (udy & 0x40) ? (udy - 0x80) : udy;
|
---|
72 |
|
---|
73 | if (b1 != b1_pressed) {
|
---|
74 | mouse_push_event_button(mouse_dev, 1, b1);
|
---|
75 | b1_pressed = b1;
|
---|
76 | }
|
---|
77 |
|
---|
78 | if (b2 != b2_pressed) {
|
---|
79 | mouse_push_event_button(mouse_dev, 2, b2);
|
---|
80 | b1_pressed = b1;
|
---|
81 | }
|
---|
82 |
|
---|
83 | if (dx != 0 || dy != 0)
|
---|
84 | mouse_push_event_move(mouse_dev, dx, dy, 0);
|
---|
85 | }
|
---|
86 |
|
---|
87 | mouse_proto_ops_t adb_proto = {
|
---|
88 | .parse = adb_proto_parse,
|
---|
89 | .init = adb_proto_init
|
---|
90 | };
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * @}
|
---|
94 | */
|
---|