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

Generated on Fri Feb 28 2020 16:27:01 for gem5 by doxygen 1.8.13