keymap.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #include "infinity60.h"
  2. #include "led_controller.h"
  3. #include "keymap_jpetermans.h"
  4. //Helpful Defines
  5. #define _______ KC_TRNS
  6. //Define Layer Names
  7. #define _BASE 0
  8. #define _NUMPAD 1
  9. #define _FNAV 2
  10. #define _MEDIA 3
  11. #define _TILDE 4
  12. const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  13. /* Layer 0: Default Layer
  14. * ,-----------------------------------------------------------.
  15. * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| Backs|
  16. * |-----------------------------------------------------------|
  17. * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \|
  18. * |-----------------------------------------------------------|
  19. * |CapsLo| A| S| D| F| G| H| J| K| L| ;| '|Enter |
  20. * |-----------------------------------------------------------|
  21. * |Shif| | Z| X| C| V| B| N| M| ,| .| /|Shift |
  22. * |-----------------------------------------------------------|
  23. * |Ctrl|Gui |Alt | Space |Alt |Gui | FN | Ctrl |
  24. * `-----------------------------------------------------------'
  25. */
  26. /* default */
  27. [_BASE] = KEYMAP( \
  28. KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_BSLS,KC_NO,\
  29. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSPC, \
  30. TT(_FNAV), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT,KC_ENT, \
  31. F(1), KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH,KC_RSFT,KC_NO, \
  32. KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RALT,TG(_NUMPAD),MO(_MEDIA), KC_RCTL \
  33. ),
  34. /* F-, arrow, and media keys */
  35. [_FNAV] = KEYMAP( \
  36. KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,KC_NO,\
  37. KC_CAPS,_______,_______,_______,_______,_______,_______,KC_PGUP,KC_UP,KC_PGDN,KC_PSCR,_______,_______,KC_DEL, \
  38. _______,M(0),KC_BTN2,_______,_______,_______,KC_HOME,KC_LEFT,KC_DOWN,KC_RGHT,KC_INS,_______,_______, \
  39. _______,KC_APP,KC_BTN1,KC_CALC,_______,_______,KC_END,_______,_______,_______,_______,_______,KC_NO, \
  40. _______,_______,_______, _______, F(0),KC_NLCK,_______,_______ \
  41. ),
  42. /* numpad */
  43. [_NUMPAD] = KEYMAP( \
  44. _______,_______,_______,_______,_______,_______,_______, KC_P7, KC_P8, KC_P9, KC_PSLS, _______,_______,_______,KC_NO,\
  45. _______,_______,_______,_______,_______,_______,_______, KC_P4, KC_P5, KC_P6, KC_PAST, _______,_______,_______, \
  46. MO(_FNAV),_______,_______,_______,_______,_______,_______, KC_P1, KC_P2, KC_P3, KC_PMNS, _______,_______, \
  47. _______,_______,_______,_______,_______,_______,_______, KC_P0,KC_COMM,KC_PDOT,KC_PPLS, _______,KC_NO, \
  48. _______,_______,_______, MO(_BASE), _______,_______,_______,_______ \
  49. ),
  50. /* media */
  51. [_MEDIA] = KEYMAP( \
  52. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,KC_MUTE, KC_VOLD, KC_VOLU,_______,KC_NO,\
  53. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,\
  54. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______, \
  55. _______,_______,F(2),F(3),_______,_______,_______, _______, KC_MPRV, KC_MNXT,KC_MSTP, _______,KC_NO, \
  56. _______,_______,_______, KC_MPLY, _______,_______, _______,_______ \
  57. ),
  58. /* ~ */
  59. [_TILDE] = KEYMAP( \
  60. KC_GRV,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,KC_NO,\
  61. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,\
  62. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______, \
  63. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,KC_NO, \
  64. _______,_______,_______, _______, _______,_______, _______,_______ \
  65. ),
  66. /* template */
  67. [5] = KEYMAP( \
  68. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,KC_NO,\
  69. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,\
  70. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______, \
  71. _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,KC_NO, \
  72. _______,_______,_______, _______, _______,_______, _______,_______ \
  73. ),
  74. };
  75. //id for user defined functions and macros
  76. enum function_id {
  77. NONE,
  78. };
  79. enum macro_id {
  80. ACTION_LEDS_ALL,
  81. ACTION_LEDS_GAME
  82. //TODO: ACTION_LED_LAYER which reads current layer and turns on appropriate LED
  83. };
  84. /*
  85. Configuring led control can be done
  86. 1. full keyboard at a time - define led array, or
  87. 2. individual - send specific led address (defined in keymap.h)
  88. The arrays relate to the mcu's LED pages (8 available) desribed in led_controller.c
  89. 0x24 (pcb row 1) is first byte of PWM portion of LED page
  90. 0x34 (pcb row 2) is 17th byte of PWM portion of LED page
  91. array translates to row and column positions
  92. Infinity60 LED MAP
  93. 11 12 13 14 15 16 17 18 21 22 23 24 25 26 27*
  94. 28 31 32 33 34 35 36 37 38 41 42 43 44 45
  95. 46 47 48 51 52 53 54 55 56 57 58 61 62
  96. 63 64 65 66 67 68 71 72 73 74 75 76 77*
  97. 78 81 82 83 84 85 86 87
  98. *Unused in Alphabet Layout
  99. */
  100. //"WASD"
  101. const uint8_t led_game[72] = {
  102. 0x24,
  103. 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  104. 0x34,
  105. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  106. 0x44,
  107. 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  108. 0x54,
  109. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
  110. 0x64,
  111. 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  112. 0x74,
  113. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  114. 0x84,
  115. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  116. 0x94,
  117. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  118. };
  119. const uint8_t led_all[72] = {
  120. 0x24,
  121. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  122. 0x34,
  123. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  124. 0x44,
  125. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  126. 0x54,
  127. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  128. 0x64,
  129. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  130. 0x74,
  131. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  132. 0x84,
  133. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  134. 0x94,
  135. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  136. };
  137. const uint16_t fn_actions[] = {
  138. [0] = ACTION_KEY(LALT(LCTL(KC_DEL))),
  139. [1] = ACTION_LAYER_MODS(_TILDE, MOD_LSFT),
  140. [2] = ACTION_FUNCTION(ACTION_LEDS_ALL),
  141. [3] = ACTION_FUNCTION(ACTION_LEDS_GAME)
  142. };
  143. /* custom action function */
  144. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
  145. (void)opt;
  146. switch(id) {
  147. case ACTION_LEDS_ALL:
  148. if(record->event.pressed) {
  149. // signal the LED controller thread
  150. chMBPost(&led_mailbox, LED_MSG_GAME_TOGGLE, TIME_IMMEDIATE);
  151. }
  152. break;
  153. case ACTION_LEDS_GAME:
  154. if(record->event.pressed) {
  155. // signal the LED controller thread
  156. chMBPost(&led_mailbox, LED_MSG_ALL_TOGGLE, TIME_IMMEDIATE);
  157. }
  158. break;
  159. }
  160. }
  161. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  162. {
  163. switch(id) {
  164. case 0:
  165. if (record->event.pressed) {
  166. }
  167. break;
  168. case 1:
  169. if (record->event.pressed) {
  170. }
  171. break;
  172. }
  173. return MACRO_NONE;
  174. };
  175. // Runs just one time when the keyboard initializes.
  176. void matrix_init_user(void) {
  177. uint8_t j;
  178. led_controller_init();
  179. //TODO: do pages need to be written at init or ok on demand?
  180. /* Write pages */
  181. for(j=0; j<8; j++) {
  182. is31_write_data(1,(uint8_t *)(led_game+(9*j)),9);
  183. chThdSleepMilliseconds(5);
  184. is31_write_data(2,(uint8_t *)(led_all+(9*j)),9);
  185. chThdSleepMilliseconds(5);
  186. }
  187. };
  188. // Runs constantly in the background, in a loop.
  189. void matrix_scan_user(void) {
  190. };