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_scan.h 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* Copyright (C) 2016 by Jacob Alexander
  2. *
  3. * This file is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This file is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this file. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. // ----- Includes -----
  18. // KLL Generated Defines
  19. #include <kll_defs.h>
  20. // ----- Defines -----
  21. // ----- Enums -----
  22. // Freescale MK20s have GPIO ports A...E
  23. typedef enum Port {
  24. Port_A = 0,
  25. Port_B = 1,
  26. Port_C = 2,
  27. Port_D = 3,
  28. Port_E = 4,
  29. } Port;
  30. // Each port has a possible 32 pins
  31. typedef enum Pin {
  32. Pin_0 = 0,
  33. Pin_1 = 1,
  34. Pin_2 = 2,
  35. Pin_3 = 3,
  36. Pin_4 = 4,
  37. Pin_5 = 5,
  38. Pin_6 = 6,
  39. Pin_7 = 7,
  40. Pin_8 = 8,
  41. Pin_9 = 9,
  42. Pin_10 = 10,
  43. Pin_11 = 11,
  44. Pin_12 = 12,
  45. Pin_13 = 13,
  46. Pin_14 = 14,
  47. Pin_15 = 15,
  48. Pin_16 = 16,
  49. Pin_17 = 17,
  50. Pin_18 = 18,
  51. Pin_19 = 19,
  52. Pin_20 = 20,
  53. Pin_21 = 21,
  54. Pin_22 = 22,
  55. Pin_23 = 23,
  56. Pin_24 = 24,
  57. Pin_25 = 25,
  58. Pin_26 = 26,
  59. Pin_27 = 27,
  60. Pin_28 = 28,
  61. Pin_29 = 29,
  62. Pin_30 = 30,
  63. Pin_31 = 31,
  64. } Pin;
  65. // Depending on the microcontroller, it can have 1 or more ADCs
  66. typedef enum ADC {
  67. #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_)
  68. ADC_0 = 0,
  69. #elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
  70. ADC_0 = 0,
  71. ADC_1 = 1,
  72. #endif
  73. } ADC;
  74. // ADC Register offset map
  75. unsigned int *ADC_reg_offset_map[] = {
  76. #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_)
  77. (unsigned int*)(&ADC0_SC1A),
  78. #elif defined(_mk20dx256_) || defined(_mk20dx256vlh7_)
  79. (unsigned int*)(&ADC0_SC1A),
  80. (unsigned int*)(&ADC1_SC1A),
  81. #endif
  82. };
  83. // Each ADC has a possible 32 channels
  84. typedef enum Channel {
  85. Channel_0 = 0,
  86. Channel_1 = 1,
  87. Channel_2 = 2,
  88. Channel_3 = 3,
  89. Channel_4 = 4,
  90. Channel_5 = 5,
  91. Channel_6 = 6,
  92. Channel_7 = 7,
  93. Channel_8 = 8,
  94. Channel_9 = 9,
  95. Channel_10 = 10,
  96. Channel_11 = 11,
  97. Channel_12 = 12,
  98. Channel_13 = 13,
  99. Channel_14 = 14,
  100. Channel_15 = 15,
  101. Channel_16 = 16,
  102. Channel_17 = 17,
  103. Channel_18 = 18,
  104. Channel_19 = 19,
  105. Channel_20 = 20,
  106. Channel_21 = 21,
  107. Channel_22 = 22,
  108. Channel_23 = 23,
  109. Channel_24 = 24,
  110. Channel_25 = 25,
  111. Channel_26 = 26,
  112. Channel_27 = 27,
  113. Channel_28 = 28,
  114. Channel_29 = 29,
  115. Channel_30 = 30,
  116. Channel_31 = 31,
  117. } Channel;
  118. // Type of pin
  119. typedef enum Type {
  120. Type_StrobeOn,
  121. Type_StrobeOff,
  122. Type_StrobeSetup,
  123. Type_Sense,
  124. Type_SenseSetup,
  125. } Type;
  126. // Keypress States
  127. typedef enum KeyPosition {
  128. KeyState_Off = 0,
  129. KeyState_Press = 1,
  130. KeyState_Hold = 2,
  131. KeyState_Release = 3,
  132. KeyState_Invalid,
  133. } KeyPosition;
  134. // ----- Structs -----
  135. // Struct container for defining Strobe pins
  136. typedef struct GPIO_Pin {
  137. Port port;
  138. Pin pin;
  139. } GPIO_Pin;
  140. // Struct container for defining Sense pins
  141. typedef struct ADC_Pin {
  142. Port port;
  143. Pin pin;
  144. ADC adc;
  145. Channel ch;
  146. } ADC_Pin;
  147. // ----- Functions -----
  148. void Matrix_setup();
  149. void Matrix_scan( uint16_t scanNum );
  150. void Matrix_currentChange( unsigned int current );