]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/infinity60/keymaps/jpetermans/keymap.c
add ability to toggle individual led by address
[qmk_firmware.git] / keyboards / infinity60 / keymaps / jpetermans / keymap.c
1 #include "infinity60.h"
2 #include "led_controller.h"
3 #include "keymap_jpetermans.h"
4
5 //Helpful Defines
6 #define _______ KC_TRNS
7
8 //Define Layer Names
9 #define _BASE 0
10 #define _NUMPAD 1
11 #define _FNAV 2
12 #define _MEDIA 3
13 #define _TILDE 4
14
15 /* ==================================
16  *             KEYMAPS 
17  * ==================================*/
18
19 const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
20     /* Layer 0: Default Layer
21      * ,-----------------------------------------------------------.
22      * |Esc|  1|  2|  3|  4|  5|  6|  7|  8|  9|  0|  -|  =|  Backs|
23      * |-----------------------------------------------------------|
24      * |Tab  |  Q|  W|  E|  R|  T|  Y|  U|  I|  O|  P|  [|  ]|    \|
25      * |-----------------------------------------------------------|
26      * |CapsLo|  A|  S|  D|  F|  G|  H|  J|  K|  L|  ;|  '|Enter   |
27      * |-----------------------------------------------------------|
28      * |Shif|   |  Z|  X|  C|  V|  B|  N|  M|  ,|  .|  /|Shift     |
29      * |-----------------------------------------------------------|
30      * |Ctrl|Gui |Alt |         Space    |Alt |Gui |  FN  | Ctrl   |
31      * `-----------------------------------------------------------'
32      */
33     /* default */
34     [_BASE] = KEYMAP( \
35         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,\
36         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,   \
37         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,         \
38         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,          \
39         KC_LCTL,   KC_LGUI,KC_LALT,               KC_SPC,          KC_RALT,TG(_NUMPAD),MO(_MEDIA), KC_RCTL         \
40     ),
41
42     /* F-, arrow, and media keys */
43     [_FNAV] = KEYMAP( \
44         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,\
45         KC_CAPS,_______,_______,_______,_______,_______,_______,KC_PGUP,KC_UP,KC_PGDN,KC_PSCR,_______,_______,KC_DEL,  \
46         _______,M(0),KC_BTN2,_______,_______,_______,KC_HOME,KC_LEFT,KC_DOWN,KC_RGHT,KC_INS,_______,_______,     \
47         _______,KC_APP,KC_BTN1,KC_CALC,_______,_______,KC_END,_______,_______,_______,_______,_______,KC_NO,         \
48         _______,_______,_______,               _______,             F(0),KC_NLCK,_______,_______   \
49     ),
50
51     /* numpad */
52     [_NUMPAD] = KEYMAP( \
53         _______,_______,_______,_______,_______,_______,_______, KC_P7, KC_P8, KC_P9, KC_PSLS, _______,_______,_______,KC_NO,\
54         _______,_______,_______,_______,_______,_______,_______, KC_P4, KC_P5, KC_P6, KC_PAST, _______,_______,_______, \
55         MO(_FNAV),_______,_______,_______,_______,_______,_______, KC_P1, KC_P2, KC_P3, KC_PMNS, _______,_______,      \
56         _______,_______,_______,_______,_______,_______,_______, KC_P0,KC_COMM,KC_PDOT,KC_PPLS, _______,KC_NO,      \
57         _______,_______,_______,               MO(_BASE),           _______,_______,_______,_______   \
58     ),
59
60     /* media */
61     [_MEDIA] = KEYMAP( \
62         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,KC_MUTE, KC_VOLD, KC_VOLU,_______,KC_NO,\
63         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,\
64         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,     \
65         _______,_______,F(2),F(3),F(4),_______,_______, _______, KC_MPRV, KC_MNXT,KC_MSTP, _______,KC_NO,       \
66         _______,_______,_______,               KC_MPLY,             _______,_______, _______,_______      \
67     ),
68     /* ~ */
69     [_TILDE] = KEYMAP( \
70         KC_GRV,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,KC_NO,\
71         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,\
72         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,     \
73         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,KC_NO,       \
74         _______,_______,_______,               _______,             _______,_______, _______,_______      \
75     ),
76     /* template */
77     [5] = KEYMAP( \
78         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,KC_NO,\
79         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,_______,\
80         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,_______,     \
81         _______,_______,_______,_______,_______,_______,_______, _______, _______, _______,_______, _______,KC_NO,       \
82         _______,_______,_______,               _______,             _______,_______, _______,_______      \
83     ),
84 };
85
86 //id for user defined functions and macros
87 enum function_id {
88     NONE,
89 };
90
91 enum macro_id {
92     ACTION_LEDS_ALL,
93     ACTION_LEDS_GAME,
94     ACTION_LED_1
95 };
96         
97 /* ==================================
98  *          LED MAPPING 
99  * ==================================*/
100
101 //TODO: ACTION_LED_LAYER which reads current layer and turns on appropriate LED
102
103 /*
104    Configuring led control can be done as
105    1. full keyboard at a time - define led array, or
106    2. individual led - send specific led address (defined in keymap.h)
107
108     Infinity60 LED MAP
109     11 12 13 14 15 16 17 18 21 22 23 24 25  26 27*
110      28 31 32 33 34 35 36 37 38 41 42 43 44 45
111      46 47 48 51 52 53 54 55 56 57 58 61    62
112       63 64 65 66 67 68 71 72 73 74 75      76 77*
113     78  81  82       83         84  85  86  87
114     *Unused in Alphabet Layout
115
116     The full keyboard arrays map to the mcu's LED pages 
117     (8 available) desribed in led_controller.c
118    
119     0x24 (pcb row 1) is first byte of PWM portion of LED page
120     0x34 (pcb row 2) is 17th byte of PWM portion of LED page
121     array translates to row and column positions
122 */
123
124 //"WASD"
125 const uint8_t led_game[72] = {
126   0x24,
127   0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
128   0x34,
129   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
130   0x44,
131   0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
132   0x54,
133   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
134   0x64,
135   0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
136   0x74,
137   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
138   0x84,
139   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
140   0x94,
141   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
142 };
143
144 const uint8_t led_all[72] = {
145   0x24,
146   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
147   0x34,
148   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
149   0x44,
150   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
151   0x54,
152   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
153   0x64,
154   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
155   0x74,
156   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
157   0x84,
158   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
159   0x94,
160   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
161 };
162
163 const uint16_t fn_actions[] = {
164     [0] = ACTION_KEY(LALT(LCTL(KC_DEL))),
165     [1] = ACTION_LAYER_MODS(_TILDE, MOD_LSFT),
166     [2] = ACTION_FUNCTION(ACTION_LEDS_ALL),
167     [3] = ACTION_FUNCTION(ACTION_LEDS_GAME),
168     [4] = ACTION_FUNCTION(ACTION_LED_1)
169
170 };
171
172 /* custom action function */
173 void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
174   (void)opt;
175   switch(id) {
176     case ACTION_LEDS_ALL:
177       if(record->event.pressed) {
178         // signal the LED controller thread
179         chMBPost(&led_mailbox, 1, TIME_IMMEDIATE);
180       }
181       break;
182     case ACTION_LEDS_GAME:
183       if(record->event.pressed) {
184         // signal the LED controller thread
185         chMBPost(&led_mailbox, 2, TIME_IMMEDIATE);
186       }
187       break;
188     case ACTION_LED_1:
189       if(record->event.pressed) {
190         // signal the LED controller thread
191         chMBPost(&led_mailbox, ADDR_LED_1, TIME_IMMEDIATE);
192       }
193       break;
194   }
195 }
196
197 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
198 {
199     switch(id) {
200       case 0: 
201         if (record->event.pressed) {
202         }
203         break;
204       case 1:
205         if (record->event.pressed) {
206         }
207         break;
208     }
209     return MACRO_NONE;
210 };
211
212
213 // Runs just one time when the keyboard initializes.
214 void matrix_init_user(void) {
215     uint8_t j;
216
217     led_controller_init();
218
219 //TODO: do pages need to be written at init or ok on demand?
220   /* Write pages */
221   for(j=0; j<8; j++) {
222     is31_write_data(1,(uint8_t *)(led_game+(9*j)),9);
223     chThdSleepMilliseconds(5);
224     is31_write_data(2,(uint8_t *)(led_all+(9*j)),9);
225     chThdSleepMilliseconds(5);
226   }
227
228 };
229
230 // Runs constantly in the background, in a loop.
231 void matrix_scan_user(void) {
232
233 };
234