]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/sol/keymaps/brianweyer/keymap.c
Reducing size of data send in one frame & update Zen rev2 oled usage
[qmk_firmware.git] / keyboards / sol / keymaps / brianweyer / keymap.c
1 #include QMK_KEYBOARD_H
2 #ifdef PROTOCOL_LUFA
3 #include "lufa.h"
4 #include "split_util.h"
5 #endif
6
7 extern keymap_config_t keymap_config;
8
9 #ifdef RGBLIGHT_ENABLE
10 //Following line allows macro to read current RGB settings
11 extern rgblight_config_t rgblight_config;
12 #endif
13
14 extern uint8_t is_master;
15
16 // Each layer gets a name for readability, which is then used in the keymap matrix below.
17 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
18 // Layer names don't all need to be of the same length, obviously, and you can also skip them
19 // entirely and just use numbers.
20 enum layer_number {
21     _QWERTY = 0,
22     _FN,
23     _ADJ
24 };
25
26 enum custom_keycodes {
27   QWERTY = SAFE_RANGE,
28   FN,
29   ADJ,
30   RGBRST
31 };
32
33
34 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
35   /* QWERTY
36    * ,------------------------------------------------.  ,------------------------------------------------.
37    * |   `  |   1  |   2  |   3  |   4  |   5  |   -  |  |   =  |   6  |   7  |   8  |   9  |   0  | Bspc |
38    * |------+------+------+------+------+------|------|  |------|------+------+------+------+------+------|
39    * |  Tab |   Q  |   W  |   E  |   R  |   T  |   [  |  |   ]  |   Y  |   U  |   I  |   O  |   P  |   \  |
40    * |------+------+------+------+------+------|------|  |------|------+------+------+------+------+------|
41    * |  Esc |   A  |   S  |   D  |   F  |   G  |      |  |      |   H  |   J  |   K  |   L  |   ;  |   '  |
42    * |------+------+------+------+------+------+------|  |------+------+------+------+------+------+------|
43    * | Shift|   Z  |   X  |   C  |   V  |   B  |      |  |      |   N  |   M  |   ,  |   .  |   /  | Shift|
44    * |------+------+------+------+------+------+------|  |------+------+------+------+------+------+------|
45    * | Ctrl |  Alt |  FN  | LGui |  RGB |  Spc |  Del |  | Bspc |  Spc |  Adj | LGui |  FN  |  Alt | Ctrl |
46    * |------+------+------+------+------+------+------|  |------+------+------+------+------+------+------|
47    *                                    |  Spc |  Ent |  |  Ent |  Spc |
48    *                                    `-------------'  `-------------'
49    */
50   [_QWERTY] = LAYOUT_kc( \
51   //,--------+--------+--------+--------+--------+--------+--+--------+.   ,--------+--+--------+--------+--------+--------+--------+--------+
52           GRV,       1,       2,       3,       4,       5,       MINS,          EQL,          6,       7,       8,       9,       0,    BSPC,
53   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
54           TAB,       Q,       W,       E,       R,       T,       LBRC,         RBRC,          Y,       U,       I,       O,       P,    BSLS,
55   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
56           ESC,       A,       S,       D,       F,       G,    _______,      _______,          H,       J,       K,       L,    SCLN,    QUOT,
57   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
58          LSPO,       Z,       X,       C,       V,       B,    _______,      _______,          N,       M,    COMM,     DOT,    SLSH,    RSPC,
59   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
60          LCTL,    LALT,      FN,    LGUI, RGB_MOD,        SPC,     DEL,         BSPC,        SPC,     ADJ,    LGUI,      FN,    LALT,    LCTL,
61   //|--------+--------+--------+--------+--------+--+--------+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
62                            VOLD,    VOLU,                 SPC,     ENT,          ENT,        SPC,             DOWN,    UP
63   //                      Rotary Left               |--------+--------|    |--------+-----------+              Rotary Right
64       ),
65
66   /* FN
67    * ,------------------------------------------------.  ,------------------------------------------------.
68    * |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |      |  |      |  F7  |  F8  |  F9  |  F10 |  F11 |  F12 |
69    * |------+------+------+------+------+------|------|  |------|------+------+------+------+------+------|
70    * |      |      |      |  Up  |      |      |      |  |      |      |      |      |      |      |      |
71    * |------+------+------+------+------+------|------|  |------|------+------+------+------+------+------|
72    * |      |      | Left | Down | Right|      |      |  |      | Play | Next | Mute | V-Up |V-Down|      |
73    * |------+------+------+------+------+------+------|  |------+------+------+------+------+------+------|
74    * |      |      |      |      |      |      |      |  |      |      |      |      |      |      |      |
75    * |------+------+------+------+------+------+------|  |------+------+------+------+------+------+------|
76    * |      |      |      |      |      |      |      |  |      |      |      |      |      |      |      |
77    * |------+------+------+------+------+------+------|  |------+------+------+------+------+------+------|
78    *                                    |      |      |  |      |      |
79    *                                    `-------------'  `-------------'
80    */
81   [_FN] = LAYOUT_kc( \
82   //,--------+--------+--------+--------+--------+--------+--+--------+.   ,--------+--+--------+--------+--------+--------+--------+--------+
83            F1,      F2,      F3,      F4,      F5,      F6,    _______,      _______,         F7,      F8,      F9,     F10,     F11,     F12,
84   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
85       _______, _______, _______,      UP, _______, _______,    _______,      _______,    _______, _______, _______, _______, _______, _______,
86   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
87       _______, _______,    LEFT,    DOWN,    RGHT, _______,    _______,      _______,       MPLY,    MNXT,    MUTE,    VOLD,    VOLU, _______,
88   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
89       _______, _______, _______, _______, _______, _______,    _______,      _______,    _______, _______, _______, _______, _______, _______,
90   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
91       _______, _______, _______, _______, _______,    _______, _______,      _______,    _______, _______, _______, _______, _______, _______,
92   //|--------+--------+--------+--------+--------+--+--------+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
93                            VOLD,    VOLU,             _______, _______,      _______,    _______,               UP,    DOWN
94   //                      Rotary Left               |--------+--------|    |--------+-----------+              Rotary Right
95       ),
96
97   /* ADJ
98    * ,------------------------------------------------.  ,------------------------------------------------.
99    * |      |      |      |      |      |      |      |  |      |      |      |      |      |      |      |
100    * |------+------+------+------+------+------|------|  |------|------+------+------+------+------+------|
101    * |      | Sat+ | Val+ | Hue+ |Speed+|Toggle|      |  |      |      |      |      |      |      |      |
102    * |------+------+------+------+------+------|------|  |------|------+------+------+------+------+------|
103    * |      | Sat- | Val- | Hue- |Speed-|Reset |      |  |      |      |QWERTY| COLE |      |      |      |
104    * |------+------+------+------+------+------+------|  |------+------+------+------+------+------+------|
105    * |      |      |      |      |      |      |      |  |      |      |      |      |      |      |      |
106    * |------+------+------+------+------+------+------|  |------+------+------+------+------+------+------|
107    * |      |      |      |      |      |      |      |  |      |      |      |      |      |      |      |
108    * |------+------+------+------+------+------+------|  |------+------+------+------+------+------+------|
109    *                                    |      |      |  |      |      |
110    *                                    `-------------'  `-------------'
111    */
112
113   [_ADJ] =  LAYOUT( \
114   //,--------+--------+--------+--------+--------+--------+--+--------+.   ,--------+--+--------+--------+--------+--------+--------+--------+
115         RESET, _______, _______, _______, _______, _______,    _______,      _______,    _______, _______, _______, _______, _______,   RESET, \
116   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
117       _______, RGB_SAI, RGB_VAI, RGB_HUI, RGB_SPI, RGB_TOG,    _______,      _______,    _______, _______, _______, _______, _______, _______, \
118   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
119       _______, RGB_SAD, RGB_VAD, RGB_HUD, RGB_SPD,  RGBRST,    _______,      _______,    _______, _______, _______, _______, _______, _______, \
120   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
121       _______, _______, _______, _______, _______, _______,    _______,      _______,    _______, _______, _______, _______, _______, _______, \
122   //|--------+--------+--------+--------+--------+--------+--+--------|    |--------+--+--------+--------+--------+--------+--------+--------|
123       _______, _______, _______, _______, _______,    _______, _______,      _______, _______,    _______, _______, _______, _______, _______, \
124   //|--------+--------+--------+--------+--------+--+--------+--------|    |--------+--------+--+--------+--------+--------+--------+--------|
125                         _______, _______,             _______, _______,      _______, _______,             _______, _______ \
126   //                      Rotary Left               |--------+--------|    |--------+--------+              Rotary Right
127       )
128 };
129
130
131 // define variables for reactive RGB
132 bool TOG_STATUS = false;
133 int RGB_current_mode;
134
135 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
136
137   switch (keycode) {
138     case QWERTY:
139       if (record->event.pressed) {
140         set_single_persistent_default_layer(_QWERTY);
141       }
142       return false;
143       break;
144     case FN:
145       if (record->event.pressed) {
146         layer_on(_FN);
147       } else {
148         layer_off(_FN);
149       }
150       return false;
151       break;
152     case ADJ:
153         if (record->event.pressed) {
154           layer_on(_ADJ);
155         } else {
156           layer_off(_ADJ);
157         }
158         return false;
159         break;
160       //led operations - RGB mode change now updates the RGB_current_mode to allow the right RGB mode to be set after reactive keys are released
161     case RGBRST:
162       #ifdef RGBLIGHT_ENABLE
163         if (record->event.pressed) {
164           eeconfig_update_rgblight_default();
165           rgblight_enable();
166           RGB_current_mode = rgblight_config.mode;
167         }
168       #endif
169       break;
170   }
171   return true;
172 }
173
174 void matrix_init_user(void) {
175 #ifdef RGBLIGHT_ENABLE
176   RGB_current_mode = rgblight_config.mode;
177 #endif
178 }
179
180
181 // OLED Driver Logic
182 #ifdef OLED_DRIVER_ENABLE
183
184 oled_rotation_t oled_init_user(oled_rotation_t rotation) {
185   if (!has_usb())
186     return OLED_ROTATION_180;  // flip 180 for offhand
187   return rotation;
188 }
189
190 static void render_logo(void) {
191   static const char PROGMEM sol_logo[] = {
192     0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
193     0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
194     0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0};
195
196   oled_write_P(sol_logo, false);
197 }
198
199 //assign the right code to your layers for OLED display
200 #define L_BASE 0
201 #define L_FN (1<<_FN)
202 #define L_ADJ (1<<_ADJ)
203 #define L_ADJ_TRI (L_ADJ|L_FN)
204
205 static void render_status(void) {
206   // Render to mode icon
207   static const char PROGMEM mode_logo[4][4] = {
208     {0x95,0x96,0x0a,0},
209     {0xb5,0xb6,0x0a,0},
210     {0x97,0x98,0x0a,0},
211     {0xb7,0xb8,0x0a,0} };
212
213   if (keymap_config.swap_lalt_lgui != false) {
214     oled_write_P(mode_logo[0], false);
215     oled_write_P(mode_logo[1], false);
216   } else {
217     oled_write_P(mode_logo[2], false);
218     oled_write_P(mode_logo[3], false);
219   }
220
221   // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below
222
223   oled_write_P(PSTR("Layer: "), false);
224   switch (layer_state) {
225     case L_BASE:
226       oled_write_P(PSTR("Laser     \n"), false);
227       break;
228     case L_FN:
229       oled_write_P(PSTR("Function  \n"), false);
230       break;
231     case L_ADJ:
232     case L_ADJ_TRI:
233       oled_write_P(PSTR("Adjustment\n"), false);
234       break;
235     default:
236       oled_write_P(PSTR("Undefined \n"), false);
237   }
238
239   // Host Keyboard LED Status
240   uint8_t led_usb_state = host_keyboard_leds();
241   oled_write_P(led_usb_state & (1<<USB_LED_NUM_LOCK) ? PSTR("NUMLOCK ") : PSTR("        "), false);
242   oled_write_P(led_usb_state & (1<<USB_LED_CAPS_LOCK) ? PSTR("CAPS ") : PSTR("     "), false);
243   oled_write_P(led_usb_state & (1<<USB_LED_SCROLL_LOCK) ? PSTR("SCLK ") : PSTR("     "), false);
244 }
245
246 void oled_task_user(void) {
247   if (is_master)
248     render_status();
249   else
250     render_logo();
251 }
252
253 #endif