touchkit.cc (12656:335489e574f3) touchkit.cc (12658:eaa132294582)
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

--- 40 unchanged lines hidden (view full) ---

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

--- 40 unchanged lines hidden (view full) ---

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 driverInitialized(false)
57 enabled(false), touchKitEnabled(false)
58{
59 if (vnc)
60 vnc->setMouse(this);
61}
62
63void
64PS2TouchKit::serialize(CheckpointOut &cp) const
65{
66 PS2Device::serialize(cp);
67
58{
59 if (vnc)
60 vnc->setMouse(this);
61}
62
63void
64PS2TouchKit::serialize(CheckpointOut &cp) const
65{
66 PS2Device::serialize(cp);
67
68 SERIALIZE_SCALAR(driverInitialized);
68 SERIALIZE_SCALAR(enabled);
69 SERIALIZE_SCALAR(touchKitEnabled);
69}
70
71void
72PS2TouchKit::unserialize(CheckpointIn &cp)
73{
74 PS2Device::unserialize(cp);
75
70}
71
72void
73PS2TouchKit::unserialize(CheckpointIn &cp)
74{
75 PS2Device::unserialize(cp);
76
76 UNSERIALIZE_SCALAR(driverInitialized);
77 UNSERIALIZE_SCALAR(enabled);
78 UNSERIALIZE_SCALAR(touchKitEnabled);
77}
78
79bool
80PS2TouchKit::recv(const std::vector<uint8_t> &data)
81{
82 switch (data[0]) {
83 case Ps2::Ps2Reset:
79}
80
81bool
82PS2TouchKit::recv(const std::vector<uint8_t> &data)
83{
84 switch (data[0]) {
85 case Ps2::Ps2Reset:
86 DPRINTF(PS2, "Resetting device.\n");
87 enabled = false;
88 touchKitEnabled = false;
84 sendAck();
85 send(Ps2::SelfTestPass);
86 return true;
87
88 case Ps2::SetResolution:
89 case Ps2::SetRate:
90 case Ps2::SetStatusLed:
91 sendAck();

--- 10 unchanged lines hidden (view full) ---

102 sendAck();
103 send(0);
104 send(0);
105 sendAck();
106 return true;
107
108 case Ps2::SetScaling1_1:
109 case Ps2::SetScaling1_2:
89 sendAck();
90 send(Ps2::SelfTestPass);
91 return true;
92
93 case Ps2::SetResolution:
94 case Ps2::SetRate:
95 case Ps2::SetStatusLed:
96 sendAck();

--- 10 unchanged lines hidden (view full) ---

107 sendAck();
108 send(0);
109 send(0);
110 sendAck();
111 return true;
112
113 case Ps2::SetScaling1_1:
114 case Ps2::SetScaling1_2:
115 sendAck();
116 return true;
117
110 case Ps2::Disable:
118 case Ps2::Disable:
119 DPRINTF(PS2, "Disabling device.\n");
120 enabled = false;
121 sendAck();
122 return true;
123
111 case Ps2::Enable:
124 case Ps2::Enable:
125 DPRINTF(PS2, "Enabling device.\n");
126 enabled = true;
127 sendAck();
128 return true;
129
112 case Ps2::SetDefaults:
130 case Ps2::SetDefaults:
131 DPRINTF(PS2, "Setting defaults and disabling device.\n");
132 enabled = false;
113 sendAck();
114 return true;
115
116 case Ps2::StatusRequest:
117 sendAck();
118 send(0);
119 send(2); // default resolution
120 send(100); // default sample rate
121 return true;
122
123 case Ps2::TouchKitId:
133 sendAck();
134 return true;
135
136 case Ps2::StatusRequest:
137 sendAck();
138 send(0);
139 send(2); // default resolution
140 send(100); // default sample rate
141 return true;
142
143 case Ps2::TouchKitId:
124 sendAck();
125 if (data.size() == 1) {
126 send(Ps2::TouchKitId);
127 send(1);
128 send('A');
144 return recvTouchKit(data);
129
145
130 return false;
131 } else if (data.size() == 3) {
132 driverInitialized = true;
133 return true;
134 } else {
135 return false;
136 }
146 default:
147 panic("Unknown byte received: %#x\n", data[0]);
148 }
149}
137
150
151bool
152PS2TouchKit::recvTouchKit(const std::vector<uint8_t> &data)
153{
154 // Ack all incoming bytes
155 sendAck();
156
157 // Packet format is: 0x0A SIZE CMD DATA
158 assert(data[0] == Ps2::TouchKitId);
159 if (data.size() < 3 || data.size() - 2 < data[1])
160 return false;
161
162 const uint8_t len = data[1];
163 const uint8_t cmd = data[2];
164
165 // We have received at least one TouchKit diagnostic
166 // command. Enabled TouchKit reports.
167 touchKitEnabled = true;
168
169
170 switch (cmd) {
171 case TouchKitActive:
172 warn_if(len != 1, "Unexpected activate packet length: %u\n", len);
173 sendTouchKit('A');
174 return true;
175
138 default:
176 default:
139 panic("Unknown byte received: %d\n", data[0]);
177 panic("Unimplemented touchscreen command: %#x\n", cmd);
140 }
141}
142
143void
178 }
179}
180
181void
182PS2TouchKit::sendTouchKit(const uint8_t *data, size_t size)
183{
184 send(Ps2::TouchKitId);
185 send(size);
186 for (int i = 0; i < size; ++i)
187 send(data[i]);
188}
189
190
191void
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.
192PS2TouchKit::mouseAt(uint16_t x, uint16_t y, uint8_t buttons)
193{
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.
150 if (!driverInitialized || sendPending() > 10)
198 if (!enabled || !touchKitEnabled || 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,

--- 12 unchanged lines hidden ---
199 return;
200
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;
204
205 const uint8_t resp[] = {
206 buttons,

--- 12 unchanged lines hidden ---