touchkit.cc (12655:a1646f7c13ab) touchkit.cc (12656:335489e574f3)
1/*
2 * Copyright (c) 2010, 2017-2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ali Saidi
41 * William Wang
42 * Andreas Sandberg
43 */
44
45#include "dev/ps2/touchkit.hh"
46
47#include "base/logging.hh"
48#include "debug/PS2.hh"
49#include "dev/ps2.hh"
50#include "params/PS2TouchKit.hh"
51
52const uint8_t PS2TouchKit::ID[] = {0x00};
53
54PS2TouchKit::PS2TouchKit(const PS2TouchKitParams *p)
55 : PS2Device(p),
56 vnc(p->vnc),
1/*
2 * Copyright (c) 2010, 2017-2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2005 The Regents of The University of Michigan
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ali Saidi
41 * William Wang
42 * Andreas Sandberg
43 */
44
45#include "dev/ps2/touchkit.hh"
46
47#include "base/logging.hh"
48#include "debug/PS2.hh"
49#include "dev/ps2.hh"
50#include "params/PS2TouchKit.hh"
51
52const uint8_t PS2TouchKit::ID[] = {0x00};
53
54PS2TouchKit::PS2TouchKit(const PS2TouchKitParams *p)
55 : PS2Device(p),
56 vnc(p->vnc),
57 ackNext(false),
58 driverInitialized(false)
59{
60 if (vnc)
61 vnc->setMouse(this);
62}
63
64void
65PS2TouchKit::serialize(CheckpointOut &cp) const
66{
67 PS2Device::serialize(cp);
68
57 driverInitialized(false)
58{
59 if (vnc)
60 vnc->setMouse(this);
61}
62
63void
64PS2TouchKit::serialize(CheckpointOut &cp) const
65{
66 PS2Device::serialize(cp);
67
69 SERIALIZE_SCALAR(ackNext);
70 SERIALIZE_SCALAR(driverInitialized);
71}
72
73void
74PS2TouchKit::unserialize(CheckpointIn &cp)
75{
76 PS2Device::unserialize(cp);
77
68 SERIALIZE_SCALAR(driverInitialized);
69}
70
71void
72PS2TouchKit::unserialize(CheckpointIn &cp)
73{
74 PS2Device::unserialize(cp);
75
78 UNSERIALIZE_SCALAR(ackNext);
79 UNSERIALIZE_SCALAR(driverInitialized);
80}
81
76 UNSERIALIZE_SCALAR(driverInitialized);
77}
78
82void
83PS2TouchKit::recv(uint8_t data)
79bool
80PS2TouchKit::recv(const std::vector<uint8_t> &data)
84{
81{
85 if (ackNext) {
86 ackNext--;
87 sendAck();
88 return;
89 }
90
91 switch (data) {
82 switch (data[0]) {
92 case Ps2::Ps2Reset:
93 sendAck();
94 send(Ps2::SelfTestPass);
83 case Ps2::Ps2Reset:
84 sendAck();
85 send(Ps2::SelfTestPass);
95 break;
86 return true;
96
97 case Ps2::SetResolution:
98 case Ps2::SetRate:
99 case Ps2::SetStatusLed:
100 sendAck();
87
88 case Ps2::SetResolution:
89 case Ps2::SetRate:
90 case Ps2::SetStatusLed:
91 sendAck();
101 ackNext = 1;
102 break;
92 return data.size() == 2;
103
104 case Ps2::ReadId:
105 sendAck();
106 send((const uint8_t *)&ID, sizeof(ID));
93
94 case Ps2::ReadId:
95 sendAck();
96 send((const uint8_t *)&ID, sizeof(ID));
107 break;
97 return true;
108
109 case Ps2::TpReadId:
110 // We're not a trackpoint device, this should make the probe
111 // go away
112 sendAck();
113 send(0);
114 send(0);
115 sendAck();
98
99 case Ps2::TpReadId:
100 // We're not a trackpoint device, this should make the probe
101 // go away
102 sendAck();
103 send(0);
104 send(0);
105 sendAck();
116 break;
106 return true;
117
118 case Ps2::SetScaling1_1:
119 case Ps2::SetScaling1_2:
120 case Ps2::Disable:
121 case Ps2::Enable:
122 case Ps2::SetDefaults:
123 sendAck();
107
108 case Ps2::SetScaling1_1:
109 case Ps2::SetScaling1_2:
110 case Ps2::Disable:
111 case Ps2::Enable:
112 case Ps2::SetDefaults:
113 sendAck();
124 break;
114 return true;
125
126 case Ps2::StatusRequest:
127 sendAck();
128 send(0);
129 send(2); // default resolution
130 send(100); // default sample rate
115
116 case Ps2::StatusRequest:
117 sendAck();
118 send(0);
119 send(2); // default resolution
120 send(100); // default sample rate
131 break;
121 return true;
132
133 case Ps2::TouchKitId:
122
123 case Ps2::TouchKitId:
134 ackNext = 2;
135 sendAck();
124 sendAck();
136 send(Ps2::TouchKitId);
137 send(1);
138 send('A');
125 if (data.size() == 1) {
126 send(Ps2::TouchKitId);
127 send(1);
128 send('A');
139
129
140 driverInitialized = true;
141 break;
130 return false;
131 } else if (data.size() == 3) {
132 driverInitialized = true;
133 return true;
134 } else {
135 return false;
136 }
142
143 default:
137
138 default:
144 panic("Unknown byte received: %d\n", data);
139 panic("Unknown byte received: %d\n", data[0]);
145 }
146}
147
148void
149PS2TouchKit::mouseAt(uint16_t x, uint16_t y, uint8_t buttons)
150{
151 // If the driver hasn't initialized the device yet, no need to try and send
152 // it anything. Similarly we can get vnc mouse events orders of magnitude
153 // faster than m5 can process them. Only queue up two sets mouse movements
154 // and don't add more until those are processed.
155 if (!driverInitialized || sendPending() > 10)
156 return;
157
158 // Convert screen coordinates to touchpad coordinates
159 const uint16_t _x = (2047.0 / vnc->videoWidth()) * x;
160 const uint16_t _y = (2047.0 / vnc->videoHeight()) * y;
161
162 const uint8_t resp[] = {
163 buttons,
164 (uint8_t)(_x >> 7), (uint8_t)(_x & 0x7f),
165 (uint8_t)(_y >> 7), (uint8_t)(_y & 0x7f),
166 };
167
168 send(resp, sizeof(resp));
169}
170
171PS2TouchKit *
172PS2TouchKitParams::create()
173{
174 return new PS2TouchKit(this);
175}
140 }
141}
142
143void
144PS2TouchKit::mouseAt(uint16_t x, uint16_t y, uint8_t buttons)
145{
146 // If the driver hasn't initialized the device yet, no need to try and send
147 // it anything. Similarly we can get vnc mouse events orders of magnitude
148 // faster than m5 can process them. Only queue up two sets mouse movements
149 // and don't add more until those are processed.
150 if (!driverInitialized || sendPending() > 10)
151 return;
152
153 // Convert screen coordinates to touchpad coordinates
154 const uint16_t _x = (2047.0 / vnc->videoWidth()) * x;
155 const uint16_t _y = (2047.0 / vnc->videoHeight()) * y;
156
157 const uint8_t resp[] = {
158 buttons,
159 (uint8_t)(_x >> 7), (uint8_t)(_x & 0x7f),
160 (uint8_t)(_y >> 7), (uint8_t)(_y & 0x7f),
161 };
162
163 send(resp, sizeof(resp));
164}
165
166PS2TouchKit *
167PS2TouchKitParams::create()
168{
169 return new PS2TouchKit(this);
170}