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.

matrix.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Copyright (C) 2011 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_H
  22. #define __MATRIX_H
  23. // ----- Includes -----
  24. // Compiler Includes
  25. #include <stdint.h>
  26. // ----- Quick Map (don't change) -----
  27. #define pinA0 0
  28. #define pinA1 1
  29. #define pinA2 2
  30. #define pinA3 3
  31. #define pinA4 4
  32. #define pinA5 5
  33. #define pinA6 6
  34. #define pinA7 7
  35. #define pinB0 10
  36. #define pinB1 11
  37. #define pinB2 12
  38. #define pinB3 13
  39. #define pinB4 14
  40. #define pinB5 15
  41. #define pinB6 16
  42. #define pinB7 17
  43. #define pinC0 20
  44. #define pinC1 21
  45. #define pinC2 22
  46. #define pinC3 23
  47. #define pinC4 24
  48. #define pinC5 25
  49. #define pinC6 26
  50. #define pinC7 27
  51. #define pinD0 30
  52. #define pinD1 31
  53. #define pinD2 32
  54. #define pinD3 33
  55. #define pinD4 34
  56. #define pinD5 35
  57. #define pinD6 36
  58. #define pinD7 37
  59. #define pinE0 40
  60. #define pinE1 41
  61. #define pinE2 42
  62. #define pinE3 43
  63. #define pinE4 44
  64. #define pinE5 45
  65. #define pinE6 46
  66. #define pinE7 47
  67. #define pinF0 50
  68. #define pinF1 51
  69. #define pinF2 52
  70. #define pinF3 53
  71. #define pinF4 54
  72. #define pinF5 55
  73. #define pinF6 56
  74. #define pinF7 57
  75. #define pinNULL 128
  76. // ----- Scan Mode (usually dual-scan) -----
  77. // Ordered by increasing memory/CPU usage
  78. #define scanRow 0 // Needed for powered switches (Hall-Effect)
  79. #define scanCol 1 // Opposite of scanRow
  80. #define scanRow_powrCol 2 // NKRO supported (simple detection)
  81. #define scanCol_powrRow 3 // Opposite of scanRow_powrCol
  82. #define scanDual 4 // Typical ~2KRO matrix
  83. // ----- Scan Mode Setting -----
  84. #define scanMode scanCol
  85. // ----- Key Settings -----
  86. #define KEYBOARD_SIZE 16 // # of keys
  87. #define MAX_ROW_SIZE 16 // # of keys in the largest row
  88. // ----- Matrix Configuration -----
  89. static const uint8_t matrix_pinout[][MAX_ROW_SIZE + 1] = {
  90. // Just layout the matrix by rows and columns
  91. // Usually you'll want to set the scanMode above to scanDual or scanCol_powrRow/scanRow_powrCol
  92. // The mode allows for optimization in the kind of scanning algorithms that are done
  93. //
  94. // The key numbers are used to translate into the keymap table (array) (and always start from 1, not 0).
  95. // Thus if a row doesn't use all the key positions, you can denote it as 0, which will be ignored/skipped on each scan
  96. // See the keymap.h file for the various preconfigured arrays.
  97. // Scan Mode | Col 1 | Col 2 | Col 3 | Col 4 | Col 4 | ...
  98. // -------------------------------------------------------
  99. // Row 1 | Key 1 Key 7 Key32 ...
  100. // Row 2 | Key 3 Key92 ...
  101. // Row 3 | Key23 ...
  102. // Row 4 | ...
  103. // Row 5 |
  104. // ... |
  105. { scanMode, pinF4, pinA6, pinA1, pinA3, pinF5, pinA5, pinA2, pinF0, pinF6, pinA7, pinA0, pinF1, pinF3, pinF7, pinA4, pinF2 },
  106. { pinNULL, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 },
  107. // Example Rows
  108. //{ pinE0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 },
  109. //{ pinE1, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, },
  110. };
  111. // ----- Variables -----
  112. // NOTE: Highest Bit: Valid keypress (0x80 is valid keypress)
  113. // Other Bits: Pressed state sample counter
  114. extern uint8_t KeyIndex_Array [KEYBOARD_SIZE + 1];
  115. static const uint8_t KeyIndex_Size = KEYBOARD_SIZE;
  116. // ----- Functions -----
  117. #endif // __MATRIX_H