2 * Copyright (c) 2010, 2017-2018 ARM Limited
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.
14 * Copyright (c) 2005 The Regents of The University of Michigan
15 * All rights reserved.
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.
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.
45 #include "dev/ps2/touchkit.hh"
47 #include "base/logging.hh"
48 #include "debug/PS2.hh"
50 #include "params/PS2TouchKit.hh"
52 const uint8_t PS2TouchKit::ID
[] = {0x00};
54 PS2TouchKit::PS2TouchKit(const PS2TouchKitParams
*p
)
57 enabled(false), touchKitEnabled(false)
64 PS2TouchKit::serialize(CheckpointOut
&cp
) const
66 PS2Device::serialize(cp
);
68 SERIALIZE_SCALAR(enabled
);
69 SERIALIZE_SCALAR(touchKitEnabled
);
73 PS2TouchKit::unserialize(CheckpointIn
&cp
)
75 PS2Device::unserialize(cp
);
77 UNSERIALIZE_SCALAR(enabled
);
78 UNSERIALIZE_SCALAR(touchKitEnabled
);
82 PS2TouchKit::recv(const std::vector
<uint8_t> &data
)
86 DPRINTF(PS2
, "Resetting device.\n");
88 touchKitEnabled
= false;
90 send(Ps2::SelfTestPass
);
93 case Ps2::SetResolution
:
95 case Ps2::SetStatusLed
:
97 return data
.size() == 2;
101 send((const uint8_t *)&ID
, sizeof(ID
));
105 // We're not a trackpoint device, this should make the probe
113 case Ps2::SetScaling1_1
:
114 case Ps2::SetScaling1_2
:
119 DPRINTF(PS2
, "Disabling device.\n");
125 DPRINTF(PS2
, "Enabling device.\n");
130 case Ps2::SetDefaults
:
131 DPRINTF(PS2
, "Setting defaults and disabling device.\n");
136 case Ps2::StatusRequest
:
139 send(2); // default resolution
140 send(100); // default sample rate
143 case Ps2::TouchKitId
:
144 return recvTouchKit(data
);
147 panic("Unknown byte received: %#x\n", data
[0]);
152 PS2TouchKit::recvTouchKit(const std::vector
<uint8_t> &data
)
154 // Ack all incoming bytes
157 // Packet format is: 0x0A SIZE CMD DATA
158 assert(data
[0] == Ps2::TouchKitId
);
159 if (data
.size() < 3 || data
.size() - 2 < data
[1])
162 const uint8_t len
= data
[1];
163 const uint8_t cmd
= data
[2];
165 // We have received at least one TouchKit diagnostic
166 // command. Enabled TouchKit reports.
167 touchKitEnabled
= true;
172 warn_if(len
!= 1, "Unexpected activate packet length: %u\n", len
);
177 panic("Unimplemented touchscreen command: %#x\n", cmd
);
182 PS2TouchKit::sendTouchKit(const uint8_t *data
, size_t size
)
184 send(Ps2::TouchKitId
);
186 for (int i
= 0; i
< size
; ++i
)
192 PS2TouchKit::mouseAt(uint16_t x
, uint16_t y
, uint8_t buttons
)
194 // If the driver hasn't initialized the device yet, no need to try and send
195 // it anything. Similarly we can get vnc mouse events orders of magnitude
196 // faster than m5 can process them. Only queue up two sets mouse movements
197 // and don't add more until those are processed.
198 if (!enabled
|| !touchKitEnabled
|| sendPending() > 10)
201 // Convert screen coordinates to touchpad coordinates
202 const uint16_t _x
= (2047.0 / vnc
->videoWidth()) * x
;
203 const uint16_t _y
= (2047.0 / vnc
->videoHeight()) * y
;
205 const uint8_t resp
[] = {
207 (uint8_t)(_x
>> 7), (uint8_t)(_x
& 0x7f),
208 (uint8_t)(_y
>> 7), (uint8_t)(_y
& 0x7f),
211 send(resp
, sizeof(resp
));
215 PS2TouchKitParams::create()
217 return new PS2TouchKit(this);