FabGL
ESP32 Display Controller and Graphics Library
ps2controller.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 
34 #include "freertos/FreeRTOS.h"
35 #include "freertos/task.h"
36 
37 #include "fabutils.h"
38 #include "fabglconf.h"
39 
40 
41 namespace fabgl {
42 
43 
47 enum class PS2Preset {
50  MousePort0,
51 };
52 
53 
57 enum class KbdMode {
61 };
62 
63 
64 class Keyboard;
65 class Mouse;
66 
67 
75 
76 public:
77 
78  PS2Controller();
79 
80  // unwanted methods
81  PS2Controller(PS2Controller const&) = delete;
82  void operator=(PS2Controller const&) = delete;
83 
97  void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO = GPIO_UNUSED, gpio_num_t port1_datGPIO = GPIO_UNUSED);
98 
115 
123  int dataAvailable(int PS2Port);
124 
125  bool waitData(int timeOutMS, int PS2Port);
126 
134  int getData(int PS2Port);
135 
142  void sendData(uint8_t data, int PS2Port);
143 
152  void injectInRXBuffer(int value, int PS2Port);
153 
157  void suspend();
158 
162  void resume();
163 
169  Keyboard * keyboard() { return m_keyboard; }
170 
171  void setKeyboard(Keyboard * value) { m_keyboard = value; }
172 
178  Mouse * mouse() { return m_mouse; }
179 
180  void setMouse(Mouse * value) { m_mouse = value; }
181 
187  static PS2Controller * instance() { return s_instance; }
188 
189  void warmInit();
190 
191  bool parityError(int PS2Port) { return m_parityError[PS2Port]; }
192 
193 private:
194 
195  static void IRAM_ATTR rtc_isr(void * arg);
196 
197  static PS2Controller * s_instance;
198 
199  // Keyboard and Mouse instances can be created by PS2Controller in one of the begin() calls, or can be
200  // set using setKeyboard() and setMouse() calls.
201  Keyboard * m_keyboard;
202  Mouse * m_mouse;
203 
204  // address of next word to read in the circular buffer
205  volatile int m_readPos[2];
206 
207  // task that is waiting for TX ends
208  volatile TaskHandle_t m_TXWaitTask[2];
209 
210  // task that is waiting for RX event
211  volatile TaskHandle_t m_RXWaitTask[2];
212 
213  intr_handle_t m_isrHandle;
214 
215  int16_t m_suspendCount; // 0 = not suspended, >0 suspended
216 
217  // true if last call to getData() had a parity error
218  bool m_parityError[2];
219 };
220 
221 
222 
223 
224 
225 } // end of namespace
226 
227 
228 
229 
230 
231 
int dataAvailable(int PS2Port)
Gets the number of scancodes available in the controller buffer.
Keyboard * keyboard()
Returns the instance of Keyboard object automatically created by PS2Controller.
void injectInRXBuffer(int value, int PS2Port)
Injects a byte into the RX buffer.
uint8_t const * data
The PS2 Keyboard controller class.
Definition: keyboard.h:166
void sendData(uint8_t data, int PS2Port)
Sends a command to the device.
This file contains some utility classes and functions.
static PS2Controller * instance()
Returns the singleton instance of PS2Controller class.
Definition: canvas.cpp:31
KbdMode
This enum defines how handle keyboard virtual keys.
Definition: ps2controller.h:57
This file contains FabGL library configuration settings, like number of supported colors...
The PS2 device controller class.
Definition: ps2controller.h:74
int getData(int PS2Port)
Gets a scancode from the queue.
void suspend()
Suspends PS/2 ports operations.
PS2Preset
This enum defines what is connected to PS/2 ports.
Definition: ps2controller.h:47
The PS2 Mouse controller class.
Definition: mouse.h:99
Mouse * mouse()
Returns the instance of Mouse object automatically created by PS2Controller.
void resume()
Resumes PS/2 ports operations.
void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_UNUSED, gpio_num_t port1_datGPIO=GPIO_UNUSED)
Initializes PS2 device controller.