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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /* Copyright (C) 2014 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. #ifndef __kll_h
  17. #define __kll_h
  18. // ----- Includes -----
  19. // Project Includes
  20. #include <print.h>
  21. #include <scan_loop.h>
  22. #include <macro.h>
  23. #include <output_com.h>
  24. // USB HID Keymap list
  25. #include <usb_hid.h>
  26. // ----- Structs -----
  27. // -- Result Macro
  28. // Defines the sequence of combinations to as the Result of Trigger Macro
  29. //
  30. // Capability + args per USB send
  31. // Default Args (always sent): key state/analog of last key
  32. // Combo Length of 0 signifies end of sequence
  33. //
  34. // ResultMacro.guide -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
  35. // ResultMacro.pos -> <current combo position>
  36. // ResultMacro.state -> <last key state>
  37. // ResultMacro.stateType -> <last key state type>
  38. // ResultMacro struct, one is created per ResultMacro, no duplicates
  39. typedef struct ResultMacro {
  40. const uint8_t *guide;
  41. unsigned int pos;
  42. uint8_t state;
  43. uint8_t stateType;
  44. } ResultMacro;
  45. // Guide, key element
  46. #define ResultGuideSize( guidePtr ) sizeof( ResultGuide ) - 1 + CapabilitiesList[ (guidePtr)->index ].argCount
  47. typedef struct ResultGuide {
  48. uint8_t index;
  49. uint8_t args; // This is used as an array pointer (but for packing purposes, must be 8 bit)
  50. } ResultGuide;
  51. // -- Trigger Macro
  52. // Defines the sequence of combinations to Trigger a Result Macro
  53. // Key Types:
  54. // * 0x00 Normal (Press/Hold/Release)
  55. // * 0x01 LED State (On/Off)
  56. // * 0x02 Analog (Threshold)
  57. // * 0x03-0xFE Reserved
  58. // * 0xFF Debug State
  59. //
  60. // Key State:
  61. // * Off - 0x00 (all flag states)
  62. // * On - 0x01
  63. // * Press/Hold/Release - 0x01/0x02/0x03
  64. // * Threshold (Range) - 0x01 (Released), 0x10 (Light press), 0xFF (Max press)
  65. // * Debug - 0xFF (Print capability name)
  66. //
  67. // Combo Length of 0 signifies end of sequence
  68. //
  69. // TriggerMacro.guide -> [<combo length>|<key1 type>|<key1 state>|<key1>...<keyn type>|<keyn state>|<keyn>|<combo length>...|0]
  70. // TriggerMacro.result -> <index to result macro>
  71. // TriggerMacro.pos -> <current combo position>
  72. // TriggerMacro.state -> <status of the macro pos>
  73. // TriggerMacro states
  74. typedef enum TriggerMacroState {
  75. TriggerMacro_Press, // Combo in sequence is passing
  76. TriggerMacro_Release, // Move to next combo in sequence (or finish if at end of sequence)
  77. TriggerMacro_Waiting, // Awaiting user input
  78. } TriggerMacroState;
  79. // TriggerMacro struct, one is created per TriggerMacro, no duplicates
  80. typedef struct TriggerMacro {
  81. const uint8_t *guide;
  82. unsigned int result;
  83. unsigned int pos;
  84. TriggerMacroState state;
  85. } TriggerMacro;
  86. // Guide, key element
  87. #define TriggerGuideSize sizeof( TriggerGuide )
  88. typedef struct TriggerGuide {
  89. uint8_t type;
  90. uint8_t state;
  91. uint8_t scanCode;
  92. } TriggerGuide;
  93. // ----- Capabilities -----
  94. // Capability
  95. typedef struct Capability {
  96. void *func;
  97. uint8_t argCount;
  98. } Capability;
  99. // Total Number of Capabilities
  100. #define CapabilitiesNum sizeof( CapabilitiesList ) / sizeof( Capability )
  101. // -- Result Macros
  102. // Guide_RM / Define_RM Pair
  103. // Guide_RM( index ) = result;
  104. // * index - Result Macro index number
  105. // * result - Result Macro guide (see ResultMacro)
  106. // Define_RM( index );
  107. // * index - Result Macro index number
  108. // Must be used after Guide_RM
  109. #define Guide_RM( index ) const uint8_t rm##index##_guide[]
  110. #define Define_RM( index ) { rm##index##_guide, 0, 0, 0 }
  111. // -- Result Macro List
  112. // Total number of result macros (rm's)
  113. // Used to create pending rm's table
  114. #define ResultMacroNum sizeof( ResultMacroList ) / sizeof( ResultMacro )
  115. // -- Trigger Macros
  116. // Guide_TM / Define_TM Trigger Setup
  117. // Guide_TM( index ) = trigger;
  118. // * index - Trigger Macro index number
  119. // * trigger - Trigger Macro guide (see TriggerMacro)
  120. // Define_TM( index, result );
  121. // * index - Trigger Macro index number
  122. // * result - Result Macro index number which is triggered by this Trigger Macro
  123. #define Guide_TM( index ) const uint8_t tm##index##_guide[]
  124. #define Define_TM( index, result ) { tm##index##_guide, result, 0, TriggerMacro_Waiting }
  125. // -- Trigger Macro List
  126. // Total number of trigger macros (tm's)
  127. // Used to create pending tm's table
  128. #define TriggerMacroNum sizeof( TriggerMacroList ) / sizeof( TriggerMacro )
  129. // ----- Trigger Maps -----
  130. // Define_TL( layer, scanCode ) = triggerList;
  131. // * layer - basename of the layer
  132. // * scanCode - Hex value of the scanCode
  133. // * triggerList - Trigger List (see Trigger Lists)
  134. #define Define_TL( layer, scanCode ) const unsigned int layer##_tl_##scanCode[]
  135. // ----- Layer Index -----
  136. // Defines each map of trigger macro lists
  137. // Layer 0 is always the default map
  138. // Layer States:
  139. // * Off - 0x00
  140. // * Shift - 0x01
  141. // * Latch - 0x02
  142. // * Lock - 0x04
  143. //
  144. // Except for Off, all states an exist simultaneously for each layer
  145. // For example:
  146. // state -> 0x04 + 0x01 = 0x05 (Shift + Lock), which is effectively Off (0x00)
  147. //
  148. // Max defines the maximum number of keys in the map, maximum of 0xFF
  149. // - Compiler calculates this
  150. //
  151. // The name is defined for cli debugging purposes (Null terminated string)
  152. typedef struct Layer {
  153. const unsigned int **triggerMap;
  154. const char *name;
  155. const uint8_t max;
  156. uint8_t state;
  157. } Layer;
  158. // Layer_IN( map, name );
  159. // * map - Trigger map
  160. // * name - Name of the trigger map
  161. #define Layer_IN( map, name ) { map, name, sizeof( map ) / 4 - 1, 0 }
  162. // Total number of layers
  163. #define LayerNum sizeof( LayerIndex ) / sizeof( Layer )
  164. #endif // __kll_h