PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PS2Keyboard.h 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. PS2Keyboard.h - PS2Keyboard library
  3. Copyright (c) 2007 Free Software Foundation. All right reserved.
  4. Written by Christian Weichel <info@32leaves.net>
  5. ** Mostly rewritten Paul Stoffregen <paul@pjrc.com>, June 2010
  6. ** Modified for use with Arduino 13 by L. Abraham Smith, <n3bah@microcompdesign.com> *
  7. ** Modified for easy interrup pin assignement on method begin(datapin,irq_pin). Cuningan <cuninganreset@gmail.com> **
  8. This library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public
  10. License as published by the Free Software Foundation; either
  11. version 2.1 of the License, or (at your option) any later version.
  12. This library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with this library; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #ifndef PS2Keyboard_h
  21. #define PS2Keyboard_h
  22. #if defined(ARDUINO) && ARDUINO >= 100
  23. #include "Arduino.h" // for attachInterrupt, FALLING
  24. #else
  25. #include "WProgram.h"
  26. #endif
  27. #include "utility/int_pins.h"
  28. // Every call to read() returns a single byte for each
  29. // keystroke. These configure what byte will be returned
  30. // for each "special" key. To ignore a key, use zero.
  31. #define PS2_TAB 9
  32. #define PS2_ENTER 13
  33. #define PS2_BACKSPACE 127
  34. #define PS2_ESC 27
  35. #define PS2_INSERT 0
  36. #define PS2_DELETE 127
  37. #define PS2_HOME 0
  38. #define PS2_END 0
  39. #define PS2_PAGEUP 25
  40. #define PS2_PAGEDOWN 26
  41. #define PS2_UPARROW 11
  42. #define PS2_LEFTARROW 8
  43. #define PS2_DOWNARROW 10
  44. #define PS2_RIGHTARROW 21
  45. #define PS2_F1 0
  46. #define PS2_F2 0
  47. #define PS2_F3 0
  48. #define PS2_F4 0
  49. #define PS2_F5 0
  50. #define PS2_F6 0
  51. #define PS2_F7 0
  52. #define PS2_F8 0
  53. #define PS2_F9 0
  54. #define PS2_F10 0
  55. #define PS2_F11 0
  56. #define PS2_F12 0
  57. #define PS2_SCROLL 0
  58. #define PS2_EURO_SIGN 0
  59. #define PS2_INVERTED_EXCLAMATION 161 // ¡
  60. #define PS2_CENT_SIGN 162 // ¢
  61. #define PS2_POUND_SIGN 163 // £
  62. #define PS2_CURRENCY_SIGN 164 // ¤
  63. #define PS2_YEN_SIGN 165 // ¥
  64. #define PS2_BROKEN_BAR 166 // ¦
  65. #define PS2_SECTION_SIGN 167 // §
  66. #define PS2_DIAERESIS 168 // ¨
  67. #define PS2_COPYRIGHT_SIGN 169 // ©
  68. #define PS2_FEMININE_ORDINAL 170 // ª
  69. #define PS2_LEFT_DOUBLE_ANGLE_QUOTE 171 // «
  70. #define PS2_NOT_SIGN 172 // ¬
  71. #define PS2_HYPHEN 173
  72. #define PS2_REGISTERED_SIGN 174 // ®
  73. #define PS2_MACRON 175 // ¯
  74. #define PS2_DEGREE_SIGN 176 // °
  75. #define PS2_PLUS_MINUS_SIGN 177 // ±
  76. #define PS2_SUPERSCRIPT_TWO 178 // ²
  77. #define PS2_SUPERSCRIPT_THREE 179 // ³
  78. #define PS2_ACUTE_ACCENT 180 // ´
  79. #define PS2_MICRO_SIGN 181 // µ
  80. #define PS2_PILCROW_SIGN 182 // ¶
  81. #define PS2_MIDDLE_DOT 183 // ·
  82. #define PS2_CEDILLA 184 // ¸
  83. #define PS2_SUPERSCRIPT_ONE 185 // ¹
  84. #define PS2_MASCULINE_ORDINAL 186 // º
  85. #define PS2_RIGHT_DOUBLE_ANGLE_QUOTE 187 // »
  86. #define PS2_FRACTION_ONE_QUARTER 188 // ¼
  87. #define PS2_FRACTION_ONE_HALF 189 // ½
  88. #define PS2_FRACTION_THREE_QUARTERS 190 // ¾
  89. #define PS2_INVERTED_QUESTION_MARK 191 // ¿
  90. #define PS2_A_GRAVE 192 // À
  91. #define PS2_A_ACUTE 193 // Á
  92. #define PS2_A_CIRCUMFLEX 194 // Â
  93. #define PS2_A_TILDE 195 // Ã
  94. #define PS2_A_DIAERESIS 196 // Ä
  95. #define PS2_A_RING_ABOVE 197 // Å
  96. #define PS2_AE 198 // Æ
  97. #define PS2_C_CEDILLA 199 // Ç
  98. #define PS2_E_GRAVE 200 // È
  99. #define PS2_E_ACUTE 201 // É
  100. #define PS2_E_CIRCUMFLEX 202 // Ê
  101. #define PS2_E_DIAERESIS 203 // Ë
  102. #define PS2_I_GRAVE 204 // Ì
  103. #define PS2_I_ACUTE 205 // Í
  104. #define PS2_I_CIRCUMFLEX 206 // Î
  105. #define PS2_I_DIAERESIS 207 // Ï
  106. #define PS2_ETH 208 // Ð
  107. #define PS2_N_TILDE 209 // Ñ
  108. #define PS2_O_GRAVE 210 // Ò
  109. #define PS2_O_ACUTE 211 // Ó
  110. #define PS2_O_CIRCUMFLEX 212 // Ô
  111. #define PS2_O_TILDE 213 // Õ
  112. #define PS2_O_DIAERESIS 214 // Ö
  113. #define PS2_MULTIPLICATION 215 // ×
  114. #define PS2_O_STROKE 216 // Ø
  115. #define PS2_U_GRAVE 217 // Ù
  116. #define PS2_U_ACUTE 218 // Ú
  117. #define PS2_U_CIRCUMFLEX 219 // Û
  118. #define PS2_U_DIAERESIS 220 // Ü
  119. #define PS2_Y_ACUTE 221 // Ý
  120. #define PS2_THORN 222 // Þ
  121. #define PS2_SHARP_S 223 // ß
  122. #define PS2_a_GRAVE 224 // à
  123. #define PS2_a_ACUTE 225 // á
  124. #define PS2_a_CIRCUMFLEX 226 // â
  125. #define PS2_a_TILDE 227 // ã
  126. #define PS2_a_DIAERESIS 228 // ä
  127. #define PS2_a_RING_ABOVE 229 // å
  128. #define PS2_ae 230 // æ
  129. #define PS2_c_CEDILLA 231 // ç
  130. #define PS2_e_GRAVE 232 // è
  131. #define PS2_e_ACUTE 233 // é
  132. #define PS2_e_CIRCUMFLEX 234 // ê
  133. #define PS2_e_DIAERESIS 235 // ë
  134. #define PS2_i_GRAVE 236 // ì
  135. #define PS2_i_ACUTE 237 // í
  136. #define PS2_i_CIRCUMFLEX 238 // î
  137. #define PS2_i_DIAERESIS 239 // ï
  138. #define PS2_eth 240 // ð
  139. #define PS2_n_TILDE 241 // ñ
  140. #define PS2_o_GRAVE 242 // ò
  141. #define PS2_o_ACUTE 243 // ó
  142. #define PS2_o_CIRCUMFLEX 244 // ô
  143. #define PS2_o_TILDE 245 // õ
  144. #define PS2_o_DIAERESIS 246 // ö
  145. #define PS2_DIVISION 247 // ÷
  146. #define PS2_o_STROKE 248 // ø
  147. #define PS2_u_GRAVE 249 // ù
  148. #define PS2_u_ACUTE 250 // ú
  149. #define PS2_u_CIRCUMFLEX 251 // û
  150. #define PS2_u_DIAERESIS 252 // ü
  151. #define PS2_y_ACUTE 253 // ý
  152. #define PS2_thorn 254 // þ
  153. #define PS2_y_DIAERESIS 255 // ÿ
  154. #define PS2_KEYMAP_SIZE 136
  155. typedef struct {
  156. uint8_t noshift[PS2_KEYMAP_SIZE];
  157. uint8_t shift[PS2_KEYMAP_SIZE];
  158. unsigned int uses_altgr;
  159. /*
  160. * "uint8_t uses_altgr;" makes the ESP8266 - NodeMCU modules crash.
  161. * So, I replaced it with an int and... It works!
  162. * I think it's because of the 32-bit architecture of the ESP8266
  163. * and the use of the flash memory to store the keymaps.
  164. * Maybe I'm wrong, it remains a hypothesis.
  165. */
  166. uint8_t altgr[PS2_KEYMAP_SIZE];
  167. } PS2Keymap_t;
  168. extern const PROGMEM PS2Keymap_t PS2Keymap_US;
  169. extern const PROGMEM PS2Keymap_t PS2Keymap_German;
  170. extern const PROGMEM PS2Keymap_t PS2Keymap_French;
  171. extern const PROGMEM PS2Keymap_t PS2Keymap_Spanish;
  172. extern const PROGMEM PS2Keymap_t PS2Keymap_Italian;
  173. extern const PROGMEM PS2Keymap_t PS2Keymap_UK;
  174. /**
  175. * Purpose: Provides an easy access to PS2 keyboards
  176. * Author: Christian Weichel
  177. */
  178. class PS2Keyboard {
  179. public:
  180. /**
  181. * This constructor does basically nothing. Please call the begin(int,int)
  182. * method before using any other method of this class.
  183. */
  184. PS2Keyboard();
  185. /**
  186. * Starts the keyboard "service" by registering the external interrupt.
  187. * setting the pin modes correctly and driving those needed to high.
  188. * The propably best place to call this method is in the setup routine.
  189. */
  190. static void begin(uint8_t dataPin, uint8_t irq_pin, const PS2Keymap_t &map = PS2Keymap_US);
  191. /**
  192. * Returns true if there is a char to be read, false if not.
  193. */
  194. static bool available();
  195. /* Discards any received data, sets available() to false without a call to read()
  196. */
  197. static void clear();
  198. /**
  199. * Retutns ps2 scan code.
  200. */
  201. static uint8_t readScanCode(void);
  202. /**
  203. * Returns the char last read from the keyboard.
  204. * If there is no char available, -1 is returned.
  205. */
  206. static int read();
  207. static int readUnicode();
  208. };
  209. #endif