Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* Copyright (C) 2014 by Jacob Alexander
  2. *
  3. * Permission is hereby granted, free of charge, to any person obtaining a copy
  4. * of this software and associated documentation files (the "Software"), to deal
  5. * in the Software without restriction, including without limitation the rights
  6. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. * copies of the Software, and to permit persons to whom the Software is
  8. * furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. * THE SOFTWARE.
  20. */
  21. #ifndef __MATRIX_SCAN_H
  22. #define __MATRIX_SCAN_H
  23. // ----- Includes -----
  24. // ----- Enums -----
  25. // Freescale MK20s have GPIO ports A...E
  26. typedef enum Port {
  27. Port_A = 0,
  28. Port_B = 1,
  29. Port_C = 2,
  30. Port_D = 3,
  31. Port_E = 4,
  32. } Port;
  33. // Each port has a possible 32 pins
  34. typedef enum Pin {
  35. Pin_0 = 0,
  36. Pin_1 = 1,
  37. Pin_2 = 2,
  38. Pin_3 = 3,
  39. Pin_4 = 4,
  40. Pin_5 = 5,
  41. Pin_6 = 6,
  42. Pin_7 = 7,
  43. Pin_8 = 8,
  44. Pin_9 = 9,
  45. Pin_10 = 10,
  46. Pin_11 = 11,
  47. Pin_12 = 12,
  48. Pin_13 = 13,
  49. Pin_14 = 14,
  50. Pin_15 = 15,
  51. Pin_16 = 16,
  52. Pin_17 = 17,
  53. Pin_18 = 18,
  54. Pin_19 = 19,
  55. Pin_20 = 20,
  56. Pin_21 = 21,
  57. Pin_22 = 22,
  58. Pin_23 = 23,
  59. Pin_24 = 24,
  60. Pin_25 = 25,
  61. Pin_26 = 26,
  62. Pin_27 = 27,
  63. Pin_28 = 28,
  64. Pin_29 = 29,
  65. Pin_30 = 30,
  66. Pin_31 = 31,
  67. } Pin;
  68. // Type of pin
  69. typedef enum Type {
  70. Type_StrobeOn,
  71. Type_StrobeOff,
  72. Type_StrobeSetup,
  73. Type_Sense,
  74. Type_SenseSetup,
  75. } Type;
  76. // Sense/Strobe configuration
  77. typedef enum Config {
  78. Config_Pullup, // Internal pull-up
  79. Config_Pulldown, // Internal pull-down
  80. Config_Opendrain, // External pull resistor
  81. } Config;
  82. // Keypress States
  83. typedef enum KeyPosition {
  84. KeyState_Off = 0,
  85. KeyState_Press = 1,
  86. KeyState_Hold = 2,
  87. KeyState_Release = 3,
  88. KeyState_Invalid,
  89. } KeyPosition;
  90. // ----- Structs -----
  91. // Struct container for defining Rows (Sense) and Columns (Strobes)
  92. typedef struct GPIO_Pin {
  93. Port port;
  94. Pin pin;
  95. } GPIO_Pin;
  96. // Debounce Element
  97. typedef struct KeyState {
  98. KeyPosition prevState;
  99. KeyPosition curState;
  100. uint8_t activeCount;
  101. uint8_t inactiveCount;
  102. } KeyState;
  103. // ----- Functions -----
  104. void Matrix_setup();
  105. void Matrix_scan( uint16_t scanNum, uint8_t firstScan );
  106. #endif // __MATRIX_SCAN_H