Skip to content

Instantly share code, notes, and snippets.

@ksh3
Last active August 25, 2024 01:37
Show Gist options
  • Save ksh3/16f1b141190ce382726b11e8dd0530a6 to your computer and use it in GitHub Desktop.
Save ksh3/16f1b141190ce382726b11e8dd0530a6 to your computer and use it in GitHub Desktop.
keyball44_keymap.c
/*
Copyright 2022 @Yowkees
Copyright 2022 MURAOKA Taro (aka KoRoN, @kaoriya)
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 QMK_KEYBOARD_H
#include "quantum.h"
enum layer_number {
_QWERTY = 0,
_RAISE = 1,
KC_OPSYM = 2
};
#define KC_ KC_TRNS
#define RAISE_TAB LT(_RAISE, KC_TAB)
#define RAISE_ESC LT(_RAISE, KC_ESC)
#define LSFT_SPC LSFT_T(KC_SPC)
#define RSFT_ENT RSFT_T(KC_ENT)
#define CMD_JA RGUI_T(KC_LANG1)
#define CMD_EN RGUI_T(KC_LANG2)
#define CMD_DEL LGUI_T(KC_DEL)
#define CMD_BS LGUI_T(KC_BSPC)
#define ALT_BS ALT_T(KC_BSPC)
#define ALT_DEL ALT_T(KC_DEL)
#define ALT_EN ALT_T(KC_LANG2)
#define CTRL_ESC LCTL_T(KC_ESC)
#define CTRL_TAB LCTL_T(KC_TAB)
#define LA_SEL MEH(KC_LEFT)
#define LA_SEL_AL SGUI(KC_LEFT)
#define RA_SEL MEH(KC_RIGHT)
#define RA_SEL_AL SGUI(KC_RIGHT)
// clang-format off
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
enum layer_number {
_QWERTY = 0,
_RAISE = 1,
};
// clang-format off
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// keymap for defaultEN
[_QWERTY] = LAYOUT_universal(
KC_OPSYM , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_EQL ,
KC_LBRC , KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCLN , KC_QUOT ,
KC_RBRC , KC_Z , KC_X , KC_C , KC_V , KC_B , KC_N , KC_M , KC_COMM , KC_DOT , KC_SLSH , KC_MINS ,
ALT_DEL, CMD_BS, CMD_BS, LSFT_SPC, CTRL_ESC, RAISE_TAB , RSFT_ENT, _______, _______ , ALT_JA
),
[_RAISE] = LAYOUT_universal(
KC_GRV, KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_BSLS,
KC_BRMD, LA_SEL_AL, LA_SEL, RA_SEL, RA_SEL_AL , KC_BRMU, KC_LEFT, KC_DOWN, KC_UP , KC_RGHT, KC_VOLD, KC_VOLU ,
KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_F12 ,
_______, _______, _______, _______, _______, _______, _______, _______, _______, ALT_EN
),
[4] = LAYOUT_universal(
KBC_RST, KBC_SAVE, KC_7, KC_8, KC_9 , KC_KP_SLASH, KC_NO , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO ,
CPI_D100 ,CPI_I100 ,KC_4, KC_5 ,KC_6, KC_KP_ASTERISK , KC_LEFT, KC_DOWN, KC_UP , KC_RGHT,KC_NO , KC_LNG1 ,
SCRL_DVI , SCRL_DVD , KC_1 , KC_2 , KC_3 , KC_KP_MINUS , KC_NO , KC_MY_BTN1 ,SCRL_MO, KC_MY_BTN2 , KC_NO ,KC_LNG,
KC_DEL , KC_0 , KC_TAB , KC_SPC , KC_ESC , KC_NO , KC_NO , KC_NO , KC_NO , KC_NO
)
};
// clang-format on
layer_state_t layer_state_set_user(layer_state_t state) {
// Auto enable scroll mode when the highest layer is 3
keyball_set_scroll_mode(get_highest_layer(state) == 3);
return state;
}
#ifdef OLED_ENABLE
# include "lib/oledkit/oledkit.h"
void oledkit_render_info_user(void) {
keyball_oled_render_keyinfo();
keyball_oled_render_ballinfo();
}
#endif
// When add source files to SRC in rules.mk, you can use functions.
const char *read_layer_state(void);
const char *read_logo(void);
void set_keylog(uint16_t keycode, keyrecord_t *record);
const char *read_keylog(void);
const char *read_keylogs(void);
void matrix_scan_user(void) {
iota_gfx_task();
}
uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case CTRL_TAB:
case RAISE_ESC:
return 120;
}
}
void matrix_render_user(struct CharacterMatrix *matrix) {
if (is_master) {
// If you want to change the display of OLED, you need to change here
matrix_write_ln(matrix, read_layer_state());
matrix_write_ln(matrix, read_keylog());
matrix_write_ln(matrix, read_keylogs());
//matrix_write_ln(matrix, read_mode_icon(keymap_config.swap_lalt_lgui));
//matrix_write_ln(matrix, read_host_led_state());
//matrix_write_ln(matrix, read_timelog());
} else {
matrix_write(matrix, read_logo());
}
}
void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) {
if (memcmp(dest->display, source->display, sizeof(dest->display))) {
memcpy(dest->display, source->display, sizeof(dest->display));
dest->dirty = true;
}
}
void iota_gfx_task_user(void) {
struct CharacterMatrix matrix;
matrix_clear(&matrix);
matrix_render_user(&matrix);
matrix_update(&display, &matrix);
}
#endif//SSD1306OLED
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
static bool ctrl_pressed = false;
static bool lshift_pressed= false;
static bool rshift_pressed = false;
if (record->event.pressed) {
#ifdef SSD1306OLED
set_keylog(keycode, record);
#endif
// set_timelog();
}
switch (keycode) {
case _QWERTY:
if (record->event.pressed) {
set_single_persistent_default_layer(_QWERTY);
}
return false;
break;
case _RAISE:
if (record->event.pressed) {
layer_on(_RAISE);
} else {
layer_off(_RAISE);
}
return false;
break;
case RAISE_ESC:
if (!record->event.pressed && IS_LAYER_OFF(_RAISE)) {
tap_code(KC_LANG2);
}
// break;
// case CTRL_ESC:
// ctrl_pressed = keyboard_report->mods & MOD_BIT(KC_LCTL);
// if (!record->event.pressed && !ctrl_pressed) {
// tap_code(KC_LANG2);
// }
// break;
case KC_OPSYM:
lshift_pressed = keyboard_report->mods & MOD_BIT(KC_LSFT);
rshift_pressed = keyboard_report->mods & MOD_BIT(KC_RSFT);
if (record->event.pressed) {
if (rshift_pressed || lshift_pressed) {
tap_code(KC_BSLS);
} else {
register_code(KC_LSFT);
tap_code(KC_7);
unregister_code(KC_LSFT);
}
}
break;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment