FabGL
ESP32 VGA 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 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 PS2Device {
56 };
57 
58 
59 
69 
70 public:
71 
77  PS2Device identify() { PS2Device result; send_cmdIdentify(&result); return result; };
78 
86  bool lock(int timeOutMS);
87 
91  void unlock();
92 
93 protected:
94 
96  ~PS2DeviceClass();
97 
98  void begin(int PS2Port);
99 
100  int dataAvailable();
101  int getData(int timeOutMS);
102 
103  void requestToResendLastByte();
104 
105  bool sendCommand(uint8_t cmd, uint8_t expectedReply);
106 
107  bool send_cmdLEDs(bool numLock, bool capsLock, bool scrollLock);
108  bool send_cmdEcho();
109  bool send_cmdGetScancodeSet(uint8_t * result);
110  bool send_cmdSetScancodeSet(uint8_t scancodeSet);
111  bool send_cmdIdentify(PS2Device * result);
112  bool send_cmdDisableScanning();
113  bool send_cmdEnableScanning();
114  bool send_cmdTypematicRateAndDelay(int repeatRateMS, int repeatDelayMS);
115  bool send_cmdSetSampleRate(int sampleRate);
116  bool send_cmdSetDefaultParams();
117  bool send_cmdReset();
118  bool send_cmdSetResolution(int resolution);
119  bool send_cmdSetScaling(int scaling);
120 
121 private:
122 
123  int m_PS2Port;
124  SemaphoreHandle_t m_deviceLock;
125 };
126 
127 
128 
129 struct PS2DeviceLock {
130  PS2DeviceLock(PS2DeviceClass * PS2Device) : m_PS2Device(PS2Device) { m_PS2Device->lock(-1); }
131  ~PS2DeviceLock() { m_PS2Device->unlock(); }
132 
133  PS2DeviceClass * m_PS2Device;
134 };
135 
136 
137 
138 
139 
140 
141 
142 } // end of namespace
143 
144 
145 
bool lock(int timeOutMS)
Gets exclusive access to the device.
Definition: ps2device.cpp:78
Definition: ps2device.h:54
This file contains fabgl::PS2ControllerClass definition and the PS2Controller instance.
Definition: ps2device.h:55
Definition: ps2device.h:50
Definition: ps2device.h:53
Definition: ps2device.h:49
Definition: canvas.cpp:47
PS2Device identify()
Identifies the device attached to the PS2 port.
Definition: ps2device.h:77
void unlock()
Releases device from exclusive access.
Definition: ps2device.cpp:84
This file contains FabGL library configuration settings, like number of supported colors...
Definition: ps2device.h:51
Base class for PS2 devices (like mouse or keyboard).
Definition: ps2device.h:68
Definition: ps2device.h:52
PS2Device
Represents the type of device attached to PS/2 port.
Definition: ps2device.h:48