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

Generated on Wed Sep 30 2020 14:02:11 for gem5 by doxygen 1.8.17