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-2021 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. Feel free to use FabGL in free software and hardware:
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 
33 namespace fabgl {
34 
35 
36 // 8042 PS/2 Keyboard Controller. Actually it is emulated how it is seen in the IBM AT
37 
38 class i8042 {
39 
40 public:
41 
42  typedef bool (*InterruptCallback)(void * context);
43 
44  i8042();
45  ~i8042();
46 
47  void init();
48 
49  void setCallbacks(void * context, InterruptCallback keyboardInterrupt, InterruptCallback mouseInterrupt) {
50  m_context = context;
51  m_keyboardInterrupt = keyboardInterrupt;
52  m_mouseInterrupt = mouseInterrupt;
53  }
54 
55  void tick();
56 
57  uint8_t read(int address);
58  void write(int address, uint8_t value);
59 
60  Keyboard * keyboard() { return m_keyboard; }
61  Mouse * mouse() { return m_mouse; }
62 
63  void enableMouse(bool value);
64 
65 private:
66 
67  void execCommand();
68  void updateCommandByte(uint8_t newValue);
69  bool trigKeyboardInterrupt();
70  bool trigMouseInterrupt();
71 
72  PS2Controller m_PS2Controller;
73  Keyboard * m_keyboard;
74  Mouse * m_mouse;
75 
76  void * m_context;
77  InterruptCallback m_keyboardInterrupt;
78  InterruptCallback m_mouseInterrupt;
79 
80  uint8_t m_STATUS;
81  uint8_t m_DBBOUT;
82  uint8_t m_DBBIN;
83  uint8_t m_commandByte;
84  bool m_writeToMouse; // if True next byte on port 0 (0x60) is transferred to mouse port
85  MousePacket m_mousePacket;
86  int m_mousePacketIdx;
87 
88  // used when a command requires a parameter
89  uint8_t m_executingCommand; // 0 = none
90 
91  SemaphoreHandle_t m_mutex;
92 
93  int m_mouseIntTrigs;
94  int m_keybIntTrigs;
95 
96 };
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 } // namespace fabgl
Definition: canvas.cpp:36
This file is the all in one include file. Application can just include this file to use FabGL library...