FabGL
ESP32 Display Controller and Graphics Library
ps2device.h
Go to the documentation of this file.
1 /*
2  Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3  Copyright (c) 2019-2021 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6 
7 * Please contact fdivitto2013@gmail.com if you need a commercial license.
8 
9 
10 * This library and related software is available under GPL v3. Feel free to use FabGL in free software and hardware:
11 
12  FabGL is free software: you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation, either version 3 of the License, or
15  (at your option) any later version.
16 
17  FabGL is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 
27 #pragma once
28 
29 
30 
31 #include "freertos/FreeRTOS.h"
32 #include "freertos/semphr.h"
33 
34 #include "fabglconf.h"
35 #include "ps2controller.h"
36 
37 
45 namespace fabgl {
46 
47 
48 
52 enum class PS2DeviceType {
59  M2Keyboard,
60 };
61 
62 
63 
70 class PS2Device {
71 
72 public:
73 
79  PS2DeviceType identify() { PS2DeviceType result; send_cmdIdentify(&result); return result; };
80 
88  bool lock(int timeOutMS);
89 
93  void unlock();
94 
95  bool parityError();
96 
97  bool syncError();
98 
99  bool CLKTimeOutError();
100 
109  bool sendCommand(uint8_t cmd, uint8_t expectedReply);
110 
116  void sendCommand(uint8_t cmd);
117 
123  void suspendPort();
124 
130  void resumePort();
131 
132  uint16_t deviceID() { return m_deviceID; }
133 
134 
135 protected:
136 
137  PS2Device();
138  ~PS2Device();
139 
140  void quickCheckHardware();
141 
142  void begin(int PS2Port);
143 
144  int dataAvailable();
145  int getData(int timeOutMS);
146 
147  void requestToResendLastByte();
148 
149  bool send_cmdLEDs(bool numLock, bool capsLock, bool scrollLock);
150  bool send_cmdEcho();
151  bool send_cmdGetScancodeSet(uint8_t * result);
152  bool send_cmdSetScancodeSet(uint8_t scancodeSet);
153  bool send_cmdIdentify(PS2DeviceType * result);
154  bool send_cmdDisableScanning();
155  bool send_cmdEnableScanning();
156  bool send_cmdTypematicRateAndDelay(int repeatRateMS, int repeatDelayMS);
157  bool send_cmdSetSampleRate(int sampleRate);
158  bool send_cmdSetDefaultParams();
159  bool send_cmdReset();
160  bool send_cmdSetResolution(int resolution);
161  bool send_cmdSetScaling(int scaling);
162 
163 private:
164 
165  int16_t m_PS2Port;
166  int16_t m_cmdTimeOut;
167  int16_t m_cmdSubTimeOut;
168  uint16_t m_deviceID; // read by send_cmdIdentify()
169 };
170 
171 
172 
173 struct PS2DeviceLock {
174  PS2DeviceLock(PS2Device * PS2Device) : m_PS2Device(PS2Device) { m_PS2Device->lock(-1); }
175  ~PS2DeviceLock() { m_PS2Device->unlock(); }
176 
177  PS2Device * m_PS2Device;
178 };
179 
180 
181 
182 
183 
184 
185 
186 } // end of namespace
187 
188 
189 
void suspendPort()
Suspends PS/2 port driving the CLK line Low.
Definition: ps2device.cpp:133
This file contains fabgl::PS2Controller definition.
bool lock(int timeOutMS)
Gets exclusive access to the device.
Definition: ps2device.cpp:91
bool sendCommand(uint8_t cmd, uint8_t expectedReply)
Sends a raw command to the PS/2 device and wait for reply.
Definition: ps2device.cpp:167
PS2DeviceType
Represents the type of device attached to PS/2 port.
Definition: ps2device.h:52
PS2DeviceType identify()
Identifies the device attached to the PS2 port.
Definition: ps2device.h:79
Definition: canvas.cpp:36
Base class for PS2 devices (like mouse or keyboard).
Definition: ps2device.h:70
This file contains FabGL library configuration settings, like number of supported colors...
void resumePort()
Resumes PS/2 port releasing CLK line.
Definition: ps2device.cpp:139
void unlock()
Releases device from exclusive access.
Definition: ps2device.cpp:97