FabGL
ESP32 Display Controller and Graphics Library
i8042.h
1/*
2 Created by Fabrizio Di Vittorio (fdivitto2013@gmail.com) - <http://www.fabgl.com>
3 Copyright (c) 2019-2022 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.
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#include "fabgl.h"
30
31
32
33namespace fabgl {
34
35
36// 8042 PS/2 Keyboard Controller. Actually it is emulated how it is seen in the IBM AT
37
38class i8042 {
39
40public:
41
42 typedef bool (*InterruptCallback)(void * context);
43
44 i8042();
45 ~i8042();
46
47 void init();
48
49 void reset();
50
51 void setCallbacks(void * context, InterruptCallback keyboardInterrupt, InterruptCallback mouseInterrupt, InterruptCallback reset, InterruptCallback sysReq) {
52 m_context = context;
53 m_keyboardInterrupt = keyboardInterrupt;
54 m_mouseInterrupt = mouseInterrupt;
55 m_reset = reset;
56 m_sysReq = sysReq;
57 }
58
59 void tick();
60
61 uint8_t read(int address);
62 void write(int address, uint8_t value);
63
64 Keyboard * keyboard() { return m_keyboard; }
65 Mouse * mouse() { return m_mouse; }
66
67 void enableMouse(bool value);
68
69private:
70
71 void execCommand();
72 void updateCommandByte(uint8_t newValue);
73 bool trigKeyboardInterrupt();
74 bool trigMouseInterrupt();
75 void checkSysReq(int scode2);
76
77 PS2Controller m_PS2Controller;
78 Keyboard * m_keyboard;
79 Mouse * m_mouse;
80
81 void * m_context;
82 InterruptCallback m_keyboardInterrupt;
83 InterruptCallback m_mouseInterrupt;
84 InterruptCallback m_reset;
85 InterruptCallback m_sysReq;
86
87 uint8_t m_STATUS;
88 uint8_t m_DBBOUT;
89 uint8_t m_DBBIN;
90 uint8_t m_commandByte;
91 bool m_writeToMouse; // if True next byte on port 0 (0x60) is transferred to mouse port
92 MousePacket m_mousePacket;
93 int m_mousePacketIdx;
94
95 // used when a command requires a parameter
96 uint8_t m_executingCommand; // 0 = none
97
98 SemaphoreHandle_t m_mutex;
99
100 int m_mouseIntTrigs;
101 int m_keybIntTrigs;
102
103 bool m_sysReqTriggered;
104
105};
106
107
108
109
110
111
112
113
114
115
116
117} // namespace fabgl
This file is the all in one include file. Application can just include this file to use FabGL library...