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-2020 Fabrizio Di Vittorio.
4  All rights reserved.
5 
6  This file is part of FabGL Library.
7 
8  FabGL is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  FabGL is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with FabGL. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #pragma once
24 
25 
26 
27 #include "freertos/FreeRTOS.h"
28 #include "freertos/semphr.h"
29 
30 #include "fabglconf.h"
31 #include "ps2controller.h"
32 
33 
41 namespace fabgl {
42 
43 
44 
48 enum class PS2DeviceType {
55  M2Keyboard,
56 };
57 
58 
59 
66 class PS2Device {
67 
68 public:
69 
75  PS2DeviceType identify() { PS2DeviceType result; send_cmdIdentify(&result); return result; };
76 
84  bool lock(int timeOutMS);
85 
89  void unlock();
90 
91  bool parityError();
92 
93 protected:
94 
95  PS2Device();
96  ~PS2Device();
97 
98  void quickCheckHardware();
99 
100  void begin(int PS2Port);
101 
102  int dataAvailable();
103  int getData(int timeOutMS);
104 
105  void requestToResendLastByte();
106 
107  bool sendCommand(uint8_t cmd, uint8_t expectedReply);
108 
109  bool send_cmdLEDs(bool numLock, bool capsLock, bool scrollLock);
110  bool send_cmdEcho();
111  bool send_cmdGetScancodeSet(uint8_t * result);
112  bool send_cmdSetScancodeSet(uint8_t scancodeSet);
113  bool send_cmdIdentify(PS2DeviceType * result);
114  bool send_cmdDisableScanning();
115  bool send_cmdEnableScanning();
116  bool send_cmdTypematicRateAndDelay(int repeatRateMS, int repeatDelayMS);
117  bool send_cmdSetSampleRate(int sampleRate);
118  bool send_cmdSetDefaultParams();
119  bool send_cmdReset();
120  bool send_cmdSetResolution(int resolution);
121  bool send_cmdSetScaling(int scaling);
122 
123 private:
124 
125  SemaphoreHandle_t m_deviceLock;
126  int16_t m_PS2Port;
127  int16_t m_retryCount;
128  int16_t m_cmdTimeOut;
129  int16_t m_cmdSubTimeOut;
130 };
131 
132 
133 
134 struct PS2DeviceLock {
135  PS2DeviceLock(PS2Device * PS2Device) : m_PS2Device(PS2Device) { m_PS2Device->lock(-1); }
136  ~PS2DeviceLock() { m_PS2Device->unlock(); }
137 
138  PS2Device * m_PS2Device;
139 };
140 
141 
142 
143 
144 
145 
146 
147 } // end of namespace
148 
149 
150 
This file contains fabgl::PS2Controller definition.
bool lock(int timeOutMS)
Gets exclusive access to the device.
Definition: ps2device.cpp:91
PS2DeviceType
Represents the type of device attached to PS/2 port.
Definition: ps2device.h:48
PS2DeviceType identify()
Identifies the device attached to the PS2 port.
Definition: ps2device.h:75
Definition: canvas.cpp:31
Base class for PS2 devices (like mouse or keyboard).
Definition: ps2device.h:66
This file contains FabGL library configuration settings, like number of supported colors...
void unlock()
Releases device from exclusive access.
Definition: ps2device.cpp:97