FabGL
ESP32 VGA 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 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 "fabglconf.h"
38 
39 
40 namespace fabgl {
41 
42 
46 enum class PS2Preset {
49  MousePort0,
50 };
51 
52 
56 enum class KbdMode {
60 };
61 
62 
63 
71 
72 public:
73 
84  void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO = GPIO_NUM_39, gpio_num_t port1_datGPIO = GPIO_NUM_39);
85 
102 
110  int dataAvailable(int PS2Port);
111 
112  bool waitData(int timeOutMS, int PS2Port);
113 
121  int getData(int PS2Port);
122 
129  void sendData(uint8_t data, int PS2Port);
130 
139  void injectInRXBuffer(int value, int PS2Port);
140 
144  void suspend();
145 
149  void resume();
150 
151 private:
152 
153  void warmInit();
154 
155  static void IRAM_ATTR rtc_isr(void * arg);
156 
157  // address of next word to read in the circular buffer
158  int m_readPos[2];
159 
160  // task that is waiting for TX ends
161  volatile TaskHandle_t m_TXWaitTask[2];
162 
163  // task that is waiting for RX event
164  volatile TaskHandle_t m_RXWaitTask[2];
165 
166  intr_handle_t m_isrHandle;
167 
168  int16_t m_suspendCount; // 0 = not suspended, >0 suspended
169  uint16_t m_suspendPortsState; // bit 0 = port 0 was enabled, bit 1 = port 1 was enabled
170 };
171 
172 
173 
174 
175 
176 } // end of namespace
177 
178 
179 
180 extern fabgl::PS2ControllerClass PS2Controller;
181 
182 
void suspend()
Suspends PS/2 ports operations.
Definition: ps2controller.cpp:901
void resume()
Resumes PS/2 ports operations.
Definition: ps2controller.cpp:911
void sendData(uint8_t data, int PS2Port)
Sends a command to the device.
Definition: ps2controller.cpp:1009
PS2Preset
This enum defines what is connected to PS/2 ports.
Definition: ps2controller.h:46
Definition: canvas.cpp:47
The PS2 device controller class.
Definition: ps2controller.h:70
KbdMode
This enum defines how handle keyboard virtual keys.
Definition: ps2controller.h:56
void injectInRXBuffer(int value, int PS2Port)
Injects a byte into the RX buffer.
Definition: ps2controller.cpp:987
This file contains FabGL library configuration settings, like number of supported colors...
void begin(gpio_num_t port0_clkGPIO, gpio_num_t port0_datGPIO, gpio_num_t port1_clkGPIO=GPIO_NUM_39, gpio_num_t port1_datGPIO=GPIO_NUM_39)
Initializes PS2 device controller.
Definition: ps2controller.cpp:838
int getData(int PS2Port)
Gets a scancode from the queue.
Definition: ps2controller.cpp:936
int dataAvailable(int PS2Port)
Gets the number of scancodes available in the controller buffer.
Definition: ps2controller.cpp:921