qmk_firmare/keyboards/crkbd/keymaps/sadekbaroudi/keymap.c

195 lines
8.4 KiB
C

/*
Copyright 2019 @foostan
Copyright 2020 Drashna Jaelre <@drashna>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "sadekbaroudi.h"
#include QMK_KEYBOARD_H
/*
* The `LAYOUT_crkbd_base` macro is a template to allow the use of identical
* modifiers for the default layouts (eg ALPHA_ALT, Colemak, Dvorak, etc), so
* that there is no need to set them up for each layout, and modify all of
* them if I want to change them. This helps to keep consistency and ease
* of use. K## is a placeholder to pass through the individual keycodes
*/
// clang-format off
#define LAYOUT_crkbd_base( \
K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, \
K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, \
K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, \
K33, K34, K35, K36, K37, K38 \
) \
LAYOUT_wrapper( \
_______, K01, K02, K03, LT(_FUNCTION, K04), K05, K06, LT(_FUNCTION, K07), K08, K09, K0A, _______, \
_______, LCTL_T(K11), LGUI_T(K12), LALT_T(K13), LSFT_T(K14), K15, LT(_MOUSE, K16), RSFT_T(K17), RALT_T(K18), RGUI_T(K19), RCTL_T(K1A), _______, \
_______, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, _______, \
K33, LT(_NAVIGATION,K34), LT(_FUNCTION,K35), LT(_MEDIA,K36), LT(_SYMBOLS,K37), K38 \
)
/* Re-pass though to allow templates to be used */
#define LAYOUT_crkbd_base_wrapper(...) LAYOUT_crkbd_base(__VA_ARGS__)
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_ALPHA_ALT] = LAYOUT_crkbd_base_wrapper(
_________________ALPHA_ALT_L1_________________, _________________ALPHA_ALT_R1_________________,
_________________ALPHA_ALT_L2_________________, _________________ALPHA_ALT_R2_________________,
_________________ALPHA_ALT_L3_________________, _________________ALPHA_ALT_R3_________________,
__ALPHA_ALT_THUMBS_6__
),
[_ALPHA] = LAYOUT_crkbd_base_wrapper(
__________________ALPHA_L1____________________, __________________ALPHA_R1____________________,
__________________ALPHA_L2____________________, __________________ALPHA_R2____________________,
__________________ALPHA_L3____________________, __________________ALPHA_R3____________________,
__ALPHA_THUMBS_6__
),
[_NAVIGATION] = LAYOUT_wrapper(
_______, ________________NAVIGATION_1_______________, _________________NUMPAD_1__________________, _______,
_______, ________________NAVIGATION_2_______________, _________________NUMPAD_2__________________, _______,
_______, ________________NAVIGATION_3_______________, _________________NUMPAD_3__________________, _______,
_______, _______, KC_TAB, KC_BSPC, LT(_MEDIA,KC_SPACE), KC_DOT
),
[_SYMBOLS] = LAYOUT_wrapper(
_______, ________________SYMBOLS_L1_________________, ________________SYMBOLS_R1_________________, _______,
_______, ________________SYMBOLS_L2_________________, ________________SYMBOLS_R2_________________, _______,
_______, ________________SYMBOLS_L3_________________, ________________SYMBOLS_R3_________________, _______,
_______, LT(_MEDIA,KC_ENT), KC_TAB, KC_BSPC, _______, _______
),
[_FUNCTION] = LAYOUT_wrapper(
_______, ________________SHIFTNAV_1_________________, ________________FUNCTION_1_________________, _______,
_______, ________________SHIFTNAV_2_________________, ________________FUNCTION_2_________________, _______,
_______, ________________SHIFTNAV_3_________________, ________________FUNCTION_3_________________, _______,
_______, _______, _______, N_DEL_LINE, KC_SPACE, _______
),
[_MEDIA] = LAYOUT_wrapper(
_______, ___________________RGB_1___________________, _________________MACROS_1__________________, _______,
_______, ___________________RGB_2___________________, _________________MACROS_2__________________, _______,
_______, ___________________RGB_3___________________, _________________MACROS_3__________________, _______,
_______, _______, _______, _______, _______, _______
),
[_MOUSE] = LAYOUT_wrapper(
_______, __________________MOUSE_1__________________, ___________________BLANK___________________, _______,
_______, __________________MOUSE_2__________________, ___________________BLANK___________________, _______,
_______, __________________MOUSE_3__________________, ___________________BLANK___________________, _______,
_______, KC_MS_BTN1, KC_MS_BTN3, KC_MS_BTN3, KC_MS_BTN2, _______
)
};
#ifdef OLED_DRIVER_ENABLE
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
if (!is_master) {
return OLED_ROTATION_180; // flips the display 180 degrees if offhand
}
return rotation;
}
#define L_BASE 0
#define L_LOWER 2
#define L_RAISE 4
#define L_ADJUST 8
void oled_render_layer_state(void) {
oled_write_P(PSTR("Layer: "), false);
switch (layer_state) {
case L_BASE:
oled_write_ln_P(PSTR("Default"), false);
break;
case L_LOWER:
oled_write_ln_P(PSTR("Lower"), false);
break;
case L_RAISE:
oled_write_ln_P(PSTR("Raise"), false);
break;
case L_ADJUST:
case L_ADJUST|L_LOWER:
case L_ADJUST|L_RAISE:
case L_ADJUST|L_LOWER|L_RAISE:
oled_write_ln_P(PSTR("Adjust"), false);
break;
}
}
char keylog_str[24] = {};
const char code_to_name[60] = {
' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\',
'#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
void set_keylog(uint16_t keycode, keyrecord_t *record) {
char name = ' ';
if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) ||
(keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { keycode = keycode & 0xFF; }
if (keycode < 60) {
name = code_to_name[keycode];
}
// update keylog
snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c",
record->event.key.row, record->event.key.col,
keycode, name);
}
void oled_render_keylog(void) {
oled_write(keylog_str, false);
}
void render_bootmagic_status(bool status) {
/* Show Ctrl-Gui Swap options */
static const char PROGMEM logo[][2][3] = {
{{0x97, 0x98, 0}, {0xb7, 0xb8, 0}},
{{0x95, 0x96, 0}, {0xb5, 0xb6, 0}},
};
if (status) {
oled_write_ln_P(logo[0][0], false);
oled_write_ln_P(logo[0][1], false);
} else {
oled_write_ln_P(logo[1][0], false);
oled_write_ln_P(logo[1][1], false);
}
}
void oled_render_logo(void) {
static const char PROGMEM crkbd_logo[] = {
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4,
0};
oled_write_P(crkbd_logo, false);
}
void oled_task_user(void) {
if (is_master) {
oled_render_layer_state();
oled_render_keylog();
} else {
oled_render_logo();
}
}
#endif // OLED_DRIVER_ENABLE