gem5 v24.0.0.0
Loading...
Searching...
No Matches
touchkit.cc
Go to the documentation of this file.
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
41#include "dev/ps2/touchkit.hh"
42
43#include <cstdint>
44
45#include "base/logging.hh"
46#include "base/trace.hh"
47#include "debug/PS2.hh"
48#include "dev/ps2/mouse.hh"
49#include "dev/ps2/types.hh"
50#include "params/PS2TouchKit.hh"
51
52namespace gem5
53{
54
55namespace ps2
56{
57
58TouchKit::TouchKit(const PS2TouchKitParams &p)
59 : Device(p),
60 vnc(p.vnc),
61 enabled(false), touchKitEnabled(false)
62{
63 if (vnc)
64 vnc->setMouse(this);
65}
66
67void
75
76void
84
85bool
87{
88 switch (data[0]) {
89 case Reset:
90 DPRINTF(PS2, "Resetting device.\n");
91 enabled = false;
92 touchKitEnabled = false;
93 sendAck();
95 return true;
96
97 case ReadID:
98 sendAck();
100 return true;
101
102 case Disable:
103 DPRINTF(PS2, "Disabling device.\n");
104 enabled = false;
105 sendAck();
106 return true;
107
108 case Enable:
109 DPRINTF(PS2, "Enabling device.\n");
110 enabled = true;
111 sendAck();
112 return true;
113
115 DPRINTF(PS2, "Setting defaults and disabling device.\n");
116 enabled = false;
117 sendAck();
118 return true;
119
120 case mouse::Scale1to1:
121 case mouse::Scale2to1:
122 sendAck();
123 return true;
124
127 sendAck();
128 return data.size() == 2;
129
130 case mouse::GetStatus:
131 sendAck();
132 send(0);
133 send(2); // default resolution
134 send(100); // default sample rate
135 return true;
136
137 case TpReadId:
138 // We're not a trackpoint device, this should make the probe
139 // go away
140 sendAck();
141 send(0);
142 send(0);
143 sendAck();
144 return true;
145
146 case TouchKitDiag:
147 return recvTouchKit(data);
148
149 default:
150 panic("Unknown byte received: %#x\n", data[0]);
151 }
152}
153
154bool
156{
157 // Ack all incoming bytes
158 sendAck();
159
160 // Packet format is: 0x0A SIZE CMD DATA
161 assert(data[0] == TouchKitDiag);
162 if (data.size() < 3 || data.size() - 2 < data[1])
163 return false;
164
165 const uint8_t len = data[1];
166 const uint8_t cmd = data[2];
167
168 // We have received at least one TouchKit diagnostic
169 // command. Enabled TouchKit reports.
170 touchKitEnabled = true;
171
172
173 switch (cmd) {
174 case TouchKitActive:
175 warn_if(len != 1, "Unexpected activate packet length: %u\n", len);
176 sendTouchKit('A');
177 return true;
178
179 default:
180 panic("Unimplemented touchscreen command: %#x\n", cmd);
181 }
182}
183
184void
185TouchKit::sendTouchKit(const uint8_t *data, size_t size)
186{
188 send(size);
189 for (int i = 0; i < size; ++i)
190 send(data[i]);
191}
192
193
194void
195TouchKit::mouseAt(uint16_t x, uint16_t y, uint8_t buttons)
196{
197 // If the driver hasn't initialized the device yet, no need to try and send
198 // it anything. Similarly we can get vnc mouse events orders of magnitude
199 // faster than m5 can process them. Only queue up two sets mouse movements
200 // and don't add more until those are processed.
201 if (!enabled || !touchKitEnabled || sendPending() > 10)
202 return;
203
204 // Convert screen coordinates to touchpad coordinates
205 const uint16_t _x = (2047.0 / vnc->videoWidth()) * x;
206 const uint16_t _y = (2047.0 / vnc->videoHeight()) * y;
207
208 const uint8_t resp[] = {
209 buttons,
210 (uint8_t)(_x >> 7), (uint8_t)(_x & 0x7f),
211 (uint8_t)(_y >> 7), (uint8_t)(_y & 0x7f),
212 };
213
214 send(resp, sizeof(resp));
215}
216
217} // namespace ps2
218} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
const char data[]
void setMouse(VncMouse *_mouse)
Setup the device that would like to receive notifications when mouse movements or button presses are ...
Definition vncinput.hh:186
uint16_t videoHeight() const
What is the height of the screen we're displaying.
Definition vncinput.hh:200
uint16_t videoWidth() const
What is the width of the screen we're displaying.
Definition vncinput.hh:193
size_t sendPending() const
Output buffer size.
Definition device.hh:142
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition device.cc:65
void send(const uint8_t *data, size_t size)
Send data from a PS/2 device to a host.
Definition device.cc:113
void sendAck()
Send an ACK byte to the host.
Definition device.cc:128
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition device.cc:75
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition touchkit.cc:77
VncInput *const vnc
The vnc server we're connected to (if any)
Definition touchkit.hh:87
bool recvTouchKit(const std::vector< uint8_t > &data)
Definition touchkit.cc:155
TouchKit(const PS2TouchKitParams &p)
Definition touchkit.cc:58
void mouseAt(uint16_t x, uint16_t y, uint8_t buttons) override
called whenever the mouse moves or it's button state changes buttons is a simple mask with each butto...
Definition touchkit.cc:195
void sendTouchKit(const uint8_t *data, size_t size)
Definition touchkit.cc:185
bool touchKitEnabled
Has the driver enabled TouchKit mode? The model suppresses touch event generation until this is true.
Definition touchkit.hh:96
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition touchkit.cc:68
bool enabled
Is the device enabled?
Definition touchkit.hh:90
bool recv(const std::vector< uint8_t > &data) override
Data received from host.
Definition touchkit.cc:86
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
Definition logging.hh:283
Bitfield< 18, 16 > len
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
Bitfield< 3 > x
Definition pagetable.hh:73
const std::vector< uint8_t > ID
Definition types.cc:52
@ DefaultsAndDisable
Definition types.hh:65
@ ReadID
Definition types.hh:62
@ Disable
Definition types.hh:64
@ Reset
Definition types.hh:69
@ Enable
Definition types.hh:63
@ SelfTestPass
Definition types.hh:61
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
std::ostream CheckpointOut
Definition serialize.hh:66
#define UNSERIALIZE_SCALAR(scalar)
Definition serialize.hh:575
#define SERIALIZE_SCALAR(scalar)
Definition serialize.hh:568

Generated on Tue Jun 18 2024 16:24:03 for gem5 by doxygen 1.11.0