Kiibohd Controller
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /* Copyright (C) 2014-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. // Project Includes
  21. #include <print.h>
  22. #include <scan_loop.h>
  23. #include <macro.h>
  24. #include <output_com.h>
  25. // USB HID Keymap list
  26. #include <usb_hid.h>
  27. // ----- Types -----
  28. // - NOTE -
  29. // It is possible to change the maximum state and indexing positions of the state machine.
  30. // This usually affects the SRAM usage quite a bit, so it can be used to fit the code on smaller uCs
  31. // Or to allow for nearly infinite states.
  32. #if StateWordSize_define == 32
  33. typedef uint32_t var_uint_t;
  34. #elif StateWordSize_define == 16
  35. typedef uint16_t var_uint_t;
  36. #elif StateWordSize_define == 8
  37. typedef uint8_t var_uint_t;
  38. #else
  39. #error "Invalid StateWordSize, possible values: 32, 16 and 8."
  40. #endif
  41. // - NOTE -
  42. // It is possible to change the maximum number of trigger/result index sizes
  43. // This will affect SRAM and flash usage, so it can be used to fit code on smaller uCs.
  44. // Also allows for over 4 billion triggers and results (triggers and results have separate indices)
  45. #if IndexWordSize_define == 32
  46. typedef uint32_t index_uint_t;
  47. #elif IndexWordSize_define == 16
  48. typedef uint16_t index_uint_t;
  49. #elif IndexWordSize_define == 8
  50. typedef uint8_t index_uint_t;
  51. #else
  52. #error "Invalid IndexWordSize, possible values: 32, 16 and 8."
  53. #endif
  54. // - NOTE -
  55. // Native pointer length
  56. // This needs to be defined per microcontroller
  57. // e.g. mk20s -> 32 bit
  58. // atmega -> 16 bit
  59. #if defined(_mk20dx128_) || defined(_mk20dx128vlf5_) || defined(_mk20dx256_) || defined(_mk20dx256vlh7_) // ARM
  60. typedef uint32_t nat_ptr_t;
  61. #elif defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_) // AVR
  62. typedef uint16_t nat_ptr_t;
  63. #endif
  64. // ----- Structs -----
  65. // -- Result Macro
  66. // Defines the sequence of combinations to as the Result of Trigger Macro
  67. // For RAM optimization reasons, ResultMacro has been split into ResultMacro and ResultMacroRecord structures
  68. //
  69. // Capability + args per USB send
  70. // Default Args (always sent): key state/analog of last key
  71. // Combo Length of 0 signifies end of sequence
  72. //
  73. // ResultMacro.guide -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
  74. //
  75. // ResultMacroRecord.pos -> <current combo position>
  76. // ResultMacroRecord.state -> <last key state>
  77. // ResultMacroRecord.stateType -> <last key state type>
  78. // ResultMacro struct, one is created per ResultMacro, no duplicates
  79. typedef struct ResultMacro {
  80. const uint8_t *guide;
  81. } ResultMacro;
  82. typedef struct ResultMacroRecord {
  83. var_uint_t pos;
  84. uint8_t state;
  85. uint8_t stateType;
  86. } ResultMacroRecord;
  87. // Guide, key element
  88. #define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
  89. typedef struct ResultGuide {
  90. uint8_t index;
  91. uint8_t args; // This is used as an array pointer (but for packing purposes, must be 8 bit)
  92. } ResultGuide;
  93. // -- Trigger Macro
  94. // Defines the sequence of combinations to Trigger a Result Macro
  95. // For RAM optimization reasons TriggerMacro has been split into TriggerMacro and TriggerMacroRecord
  96. // Key Types:
  97. // * 0x00 Normal (Press/Hold/Release)
  98. // * 0x01 LED State (On/Off)
  99. // * 0x02 Analog (Threshold)
  100. // * 0x03-0xFE Reserved
  101. // * 0xFF Debug State
  102. //
  103. // Key State:
  104. // * Off - 0x00 (all flag states)
  105. // * On - 0x01
  106. // * Press/Hold/Release - 0x01/0x02/0x03
  107. // * Threshold (Range) - 0x01 (Released), 0x10 (Light press), 0xFF (Max press)
  108. // * Debug - 0xFF (Print capability name)
  109. //
  110. // Combo Length of 0 signifies end of sequence
  111. //
  112. // TriggerMacro.guide -> [<combo length>|<key1 type>|<key1 state>|<key1>...<keyn type>|<keyn state>|<keyn>|<combo length>...|0]
  113. // TriggerMacro.result -> <index to result macro>
  114. //
  115. // TriggerMacroRecord.pos -> <current combo position>
  116. // TriggerMacroRecord.state -> <status of the macro pos>
  117. // TriggerMacro states
  118. typedef enum TriggerMacroState {
  119. TriggerMacro_Press, // Combo in sequence is passing
  120. TriggerMacro_Release, // Move to next combo in sequence (or finish if at end of sequence)
  121. TriggerMacro_Waiting, // Awaiting user input
  122. } TriggerMacroState;
  123. // TriggerMacro struct, one is created per TriggerMacro, no duplicates
  124. typedef struct TriggerMacro {
  125. const uint8_t *guide;
  126. const var_uint_t result;
  127. } TriggerMacro;
  128. typedef struct TriggerMacroRecord {
  129. var_uint_t pos;
  130. TriggerMacroState state;
  131. } TriggerMacroRecord;
  132. // Guide, key element
  133. #define TriggerGuideSize sizeof( TriggerGuide )
  134. typedef struct TriggerGuide {
  135. uint8_t type;
  136. uint8_t state;
  137. uint8_t scanCode;
  138. } TriggerGuide;
  139. // ----- Capabilities -----
  140. // Capability
  141. typedef struct Capability {
  142. const void *func;
  143. const uint8_t argCount;
  144. } Capability;
  145. // Total Number of Capabilities
  146. // (generated by KLL)
  147. #define CapabilitiesNum CapabilitiesNum_KLL
  148. // -- Result Macros
  149. // Guide_RM / Define_RM Pair
  150. // Guide_RM( index ) = result;
  151. // * index - Result Macro index number
  152. // * result - Result Macro guide (see ResultMacro)
  153. // Define_RM( index );
  154. // * index - Result Macro index number
  155. // Must be used after Guide_RM
  156. #define Guide_RM( index ) const uint8_t rm##index##_guide[]
  157. #define Define_RM( index ) { rm##index##_guide }
  158. // -- Result Macro List
  159. // Total number of result macros (rm's)
  160. // Used to create pending rm's table
  161. // (generated by KLL)
  162. #define ResultMacroNum ResultMacroNum_KLL
  163. // -- Trigger Macros
  164. // Guide_TM / Define_TM Trigger Setup
  165. // Guide_TM( index ) = trigger;
  166. // * index - Trigger Macro index number
  167. // * trigger - Trigger Macro guide (see TriggerMacro)
  168. // Define_TM( index, result );
  169. // * index - Trigger Macro index number
  170. // * result - Result Macro index number which is triggered by this Trigger Macro
  171. #define Guide_TM( index ) const uint8_t tm##index##_guide[]
  172. #define Define_TM( index, result ) { tm##index##_guide, result }
  173. // -- Trigger Macro List
  174. // Total number of trigger macros (tm's)
  175. // Used to create pending tm's table
  176. // (generated by KLL)
  177. #define TriggerMacroNum TriggerMacroNum_KLL
  178. // ----- Trigger Maps -----
  179. // Define_TL( layer, scanCode ) = triggerList;
  180. // * layer - basename of the layer
  181. // * scanCode - Hex value of the scanCode
  182. // * triggerList - Trigger List (see Trigger Lists)
  183. #define Define_TL( layer, scanCode ) const nat_ptr_t layer##_tl_##scanCode[]
  184. // ----- Layer Index -----
  185. // Defines each map of trigger macro lists
  186. // Layer 0 is always the default map
  187. // Layer States:
  188. // * Off - 0x00
  189. // * Shift - 0x01
  190. // * Latch - 0x02
  191. // * Lock - 0x04
  192. // Layer states are stored in the LayerState array
  193. //
  194. // Except for Off, all states an exist simultaneously for each layer
  195. // For example:
  196. // state -> 0x04 + 0x01 = 0x05 (Shift + Lock), which is effectively Off (0x00)
  197. //
  198. // First defines the first used scan code (most keyboards start at 0, some start higher e.g. 0x40)
  199. // - Compiler calculates this
  200. //
  201. // Last defines the last scan code used (helps reduce RAM usage)
  202. //
  203. // The name is defined for cli debugging purposes (Null terminated string)
  204. typedef struct Layer {
  205. const nat_ptr_t **triggerMap;
  206. const char *name;
  207. const uint8_t first;
  208. const uint8_t last;
  209. } Layer;
  210. // Layer_IN( map, name, first );
  211. // * map - Trigger map
  212. // * name - Name of the trigger map
  213. // * first - First scan code used (most keyboards start at 0, some start higher e.g. 0x40)
  214. #define Layer_IN( map, name, first ) { map, name, first, sizeof( map ) / sizeof( nat_ptr_t ) - 1 + first }
  215. // Total number of layers (generated by KLL)
  216. #define LayerNum LayerNum_KLL