diff options
author | lokher <lokher@gmail.com> | 2022-12-06 17:04:10 +0800 |
---|---|---|
committer | lokher <lokher@gmail.com> | 2022-12-06 17:04:10 +0800 |
commit | 27fc28fd2ff52e079a5bc58d6aaea4c752420615 (patch) | |
tree | 7ac943fb1ba4f430a7220efd18f66f6a77205c30 /keyboards/crkbd/keymaps/mcrown | |
parent | e736133392fe6427cfb995da0787337189828272 (diff) | |
parent | 2709b6ed616f8012ff4cfd3ee69a822a8d188351 (diff) |
Merge upstream master
Diffstat (limited to 'keyboards/crkbd/keymaps/mcrown')
-rw-r--r-- | keyboards/crkbd/keymaps/mcrown/mcrown.h | 109 | ||||
-rw-r--r-- | keyboards/crkbd/keymaps/mcrown/oled.c | 355 |
2 files changed, 464 insertions, 0 deletions
diff --git a/keyboards/crkbd/keymaps/mcrown/mcrown.h b/keyboards/crkbd/keymaps/mcrown/mcrown.h new file mode 100644 index 0000000000..b60f759469 --- /dev/null +++ b/keyboards/crkbd/keymaps/mcrown/mcrown.h @@ -0,0 +1,109 @@ +/** @file mcrown.h + * @brief mcrown header thant incluedes key layout and some definintions. + * + * 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/>. + * + * @author Mario Corona (mariocc@comunidad.unam.mx) 2021 + * + */ + +#pragma once + +#include QMK_KEYBOARD_H +#include "oled.h" + +#define KC_XXXXX KC_NO +#define KC_LOWER LOWER +#define KC_RAISE RAISE +#define KC_CTLTB CTL_T(KC_TAB) +#define KC_GUIEI GUI_T(KC_LNG2) +#define KC_ALTKN ALT_T(KC_LNG1) + +#define LAYOUT_wrapper(...) LAYOUT(__VA_ARGS__) + +/* For values greater than 0x200, substract that value and add 0x20 so the characters can be mapped */ +#define RM_LSFT(kc) ((uint8_t)(0x20)+(kc-0x200)) + +/* ######################################################################### LAYOUT BLOCKS ##################################################### */ +/* -----------------------------------------BUTTON1---BUTTON2- BUTTON3------- */ +#define _____________MOD_LEFT_____________ KC_GUIEI, KC_LOWER, KC_SPC +#define _____________MOD_RIGHT____________ KC_ENT, KC_RAISE, KC_ALTKN + + +/* ------------------------------------------------------------COL1------COL2-----COL3-----COL4-----COL5-----COL6--------- */ +#define _____________________RAISE_L1_______________________ KC_ESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC +#define _____________________RAISE_L2_______________________ KC_LSFT, KC_MPLY, KC_VOLU, KC_MNXT, XXXXXXX, XXXXXXX +#define _____________________RAISE_L3_______________________ KC_CTLTB, KC_CALC, KC_VOLD, KC_MPRV, KC_BRIU, KC_BRID + +#define _____________________RAISE_R1_______________________ KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_DEL +#define _____________________RAISE_R2_______________________ KC_MINS, KC_EQL, KC_LCBR, KC_RCBR, KC_PIPE, KC_GRV +#define _____________________RAISE_R3_______________________ KC_UNDS, KC_PLUS, KC_LBRC, KC_RBRC, KC_BSLS, KC_TILD + +/* ------------------------------------------------------------COL1------COL2-----COL3-----COL4-----COL5-----COL6--------- */ +#define _____________________QWERTY_L1______________________ KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T +#define _____________________QWERTY_L2______________________ KC_LSFT, KC_A, KC_S, KC_D, KC_F, KC_G +#define _____________________QWERTY_L3______________________ KC_CTLTB, KC_Z, KC_X, KC_C, KC_V, KC_B + +#define _____________________QWERTY_R1______________________ KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC +#define _____________________QWERTY_R2______________________ KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT +#define _____________________QWERTY_R3______________________ KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT + +/* ------------------------------------------------------------COL1------COL2-----COL3-----COL4-----COL5-----COL6--------- */ +#define _____________________LOWER_L1_______________________ KC_CAPS, KC_1, KC_2, KC_3, KC_4, KC_5 +#define _____________________LOWER_L2_______________________ KC_LSFT, XXXXXXX, XXXXXXX, XXXXXXX, KC_PGUP, KC_PGDN +#define _____________________LOWER_L3_______________________ KC_CTLTB, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5 + +#define _____________________LOWER_R1_______________________ KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC +#define _____________________LOWER_R2_______________________ KC_LEFT, KC_UP, KC_DOWN, KC_RIGHT, KC_HOME, KC_END +#define _____________________LOWER_R3_______________________ KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11 + +/* ------------------------------------------------------------COL1------COL2-----COL3-----COL4-----COL5-----COL6--------- */ +#define _____________________ADJUST_L1______________________ XXXXXXX, EE_CLR, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX +#if defined(RGB_MATRIX_ENABLE) || defined(RGBLIGHT_ENABLE) + #define _____________________ADJUST_L2______________________ XXXXXXX, XXXXXXX, RGB_SPI, RGB_SAI, RGB_HUI, RGB_VAI + #define _____________________ADJUST_L3______________________ XXXXXXX, XXXXXXX, RGB_SPD, RGB_SAD, RGB_HUD, RGB_VAD +#else/* ---------------------------------------------------------------|---------|--------|--------|--------|------------- */ + #define _____________________ADJUST_L2______________________ M_VRSN, M_MALL, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX + #define _____________________ADJUST_L3______________________ M_FLSH, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX +#endif/* --------------------------------------------------------------|---------|--------|--------|--------|------------- */ +#if defined(RGB_MATRIX_ENABLE) || defined(RGBLIGHT_ENABLE) + #define _____________________ADJUST_R1______________________ RGB_TOG, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX + #define _____________________ADJUST_R3______________________ RGB_MOD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX +#else/* ---------------------------------------------------------------|---------|--------|--------|--------|------------- */ + #define _____________________ADJUST_R1______________________ XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX + #define _____________________ADJUST_R3______________________ XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX +#endif/* --------------------------------------------------------------|---------|--------|--------|--------|------------- */ +#define _____________________ADJUST_R2______________________ RGB_RMOD, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX + +/* Each layer gets a name for readability */ +typedef enum custom_layers { + _QWERTY, + _DVORAK, + _COLEMAK, + _LOWER, + _RAISE, + _ADJUST, + _NUMPAD, + _MAX_LAYERS +}CUSTOM_LAYERS_T; + +/* To be used to identify the current working layer */ +typedef enum custom_keycodes{ + QWERTY = SAFE_RANGE, + LOWER, + RAISE, + ADJUST, + BACKLIT, + RGBRST +}CUSTOM_KEYCODES_T; diff --git a/keyboards/crkbd/keymaps/mcrown/oled.c b/keyboards/crkbd/keymaps/mcrown/oled.c new file mode 100644 index 0000000000..f88fc0c8d8 --- /dev/null +++ b/keyboards/crkbd/keymaps/mcrown/oled.c @@ -0,0 +1,355 @@ +/** @file oled.h + * @brief mcrown oled service implementation. + * + * 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/>. + * + * @author Mario Corona (mariocc@comunidad.unam.mx) 2021 + * + */ + +#include QMK_KEYBOARD_H +#include <stdio.h> +#include <string.h> +#include "mcrown.h" +#include "oled.h" + +#define ASCII_TABLE_LENGTH (0x80) +#define KEYLOG_STRING_STARTUP (KEYLOG_EOL_LEN+1) +#define ALT_CODE (0x7E) +#define SPECIAL_KEYS_SHIFT(kc) (0x18+(kc)) + +static void render_keylogger_status(void); + +static char keylog_str[KEYLOG_EOL_LEN] = {' '}; +static uint16_t log_timer = 0; +static uint8_t current_cursor_pos=0; +static uint32_t cursor_oled_timer = 0; +static uint32_t standby_oled_timer = 0; +static char last_c=' '; + +/* Provides the ASCII value or the address of the character selected of the OLED font specified in glcfont.c */ +static const char ascii_t[ASCII_TABLE_LENGTH] = { + /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + /* | | | | | | | | | | | | | | | | */ + 0x0F, 0x1A, 0x1B, 0x19, 0x18, 0x0E, ' ', ' ', 0x11, 0x1C, 0x97, ' ', ' ', ' ', ' ', ' ', /* 0 */ + /* | | | | | | | | | | | | | | | | */ + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0x1D, ' ', ' ', ' ', ' ', /* 1 */ + /* | | | | | | | | | | | | | | | | */ + 0x16, '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', /* 2 */ + /* | | | | | | | | | | | | | | | | */ + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', /* 3 */ + /* | | | | | | | | | | | | | | | | */ + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', /* 4 */ + /* | | | | | | | | | | | | | | | | */ + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', /* 5 */ + /* | | | | | | | | | | | | | | | | */ + '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', /* 6 */ + /* | | | | | | | | | | | | | | | | */ + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', 0x7F, /* 7 */ +}; + +/* This table is to remap and get the corresponding ASCII value based on the KEYCODE (taken as the index of the array) of quatum_keycodes.h module */ +static const unsigned char code_to_ascii[ASCII_TABLE_LENGTH] = { + /* 0 1 2 3 4 5 6 7 8 9 A B C D E F */ + /* | | | | | | | | | | | | | | | | */ + 0x00, 0x00, 0x00, 0x00, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', /* 0 */ + /* | | | | | | | | | | | | | | | | */ + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', /* 1 */ + /* | | | | | | | | | | | | | | | | */ + '3', '4', '5', '6', '7', '8', '9', '0', 0x0A, 0x1B, 0x08, 0x09, ' ', '-', '=', '[', /* 2 */ + /* | | | | | | | | | | | | | | | | */ + ']', '\\', 0x00, ';', '\'', '`', ',', '.', '/', 0x00, 0x00, 0x00, 0x00, 0x00, '!', '@', /* 3 */ + /* | | | | | | | | | | | | | | | | */ + '#', '$', '%', '^', '&', '*', '(', ')', 0x00, 0x00, 0x00, 0x00, 0x00, '_', '+', '{', /* 4 */ + /* | | | | | | | | | | | | | | | | */ + '}', '|', 0x00, 0x00, 0x00, '~', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 5 */ + /* | | | | | | | | | | | | | | | | */ + 0x00, 0x00, 0x00, 0x00, 0x7F, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, /* 6 */ + /* | | | | | | | | | | | | | | | | */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, /* 7 */ +}; + +/** @brief maps the keycode to get the ascii value. + * + * If any argument is invalid, the function has no effect. + * + * @param keycode value of the pressed key. + * @return ascii value of the pressed key or a special value for non-ascii keys. + */ +inline static char get_ascii(int16_t keycode){ + uint8_t ascii_idx=0x00; + + if(keycode<KC_F1){ + ascii_idx=code_to_ascii[(uint8_t)keycode]; + }else if(keycode<KC_KP_ENTER){ + ascii_idx=code_to_ascii[SPECIAL_KEYS_SHIFT(keycode)]; + }else if(KC_LNG1==keycode){ + ascii_idx=code_to_ascii[ALT_CODE]; + }else if( QK_LSFT==(QK_LSFT&keycode) ){ + ascii_idx=code_to_ascii[RM_LSFT(keycode)]; + } + + return ascii_t[ascii_idx]; +} + +/** @brief detect retuns the rotation of the display based on the keyboard side. + * + * If any argument is invalid, the function has no effect. + * + * @param oled_rotation_t rotation + * @return rotation of the display. + */ +oled_rotation_t oled_init_user(oled_rotation_t rotation){ + oled_rotation_t oled_rot=OLED_ROTATION_180; + + if(true==is_keyboard_master()){ +#ifdef OLED_VERTICAL + oled_rot=OLED_ROTATION_270; +#else + oled_rot=OLED_ROTATION_0; +#endif + } + return oled_rot; +} + +/** @brief renders the keylog string and display it. This function also toggles the cursor. + * + * If any argument is invalid, the function has no effect. + * + * @param void. + * @return void. + */ +static void render_keylogger_status(void){ + static bool cursor_f=true; + + if(timer_elapsed32(cursor_oled_timer) > 300){ + cursor_oled_timer = timer_read32(); + cursor_f=!cursor_f; + } + oled_write_P(PSTR("\n>:"), false); + if(current_cursor_pos>(KEYLOG_LEN-1)){ + current_cursor_pos=0; + memset(keylog_str, ' ', sizeof(char)*KEYLOG_EOL_LEN); + /* Here the EOL is to clear with white spaces all the keylog area */ + keylog_str[KEYLOG_EOL_LEN-1] = '\0'; + oled_write(keylog_str, false); + /* Reset EOL to the begining of the keylog string */ + keylog_str[0] = '\0'; + } + oled_write(keylog_str, false); + oled_write_char(last_c, cursor_f); + +} + +/** @brief displays the current active layout. + * + * If any argument is invalid, the function has no effect. + * + * @param void. + * @return void. + */ +void render_layout_state(void){ + CUSTOM_LAYERS_T current_layer; + current_layer=(CUSTOM_LAYERS_T)get_highest_layer(layer_state); + +#ifdef OLED_VERTICAL + oled_write_P(PSTR("Lyt:\n"), false); +#else + oled_write_P(PSTR("Layout: "), false); +#endif + + switch (current_layer){ +#ifdef OLED_VERTICAL + case _COLEMAK: + oled_write_P(PSTR("Clmak\n"), false); + break; + + case _DVORAK: + oled_write_P(PSTR("Dvak\n"), false); + break; + + case _QWERTY: + oled_write_P(PSTR("Qwty\n"), false); + break; + + default: + oled_write_P(PSTR("Undf\n"), false); + break; + +#else + case _COLEMAK: + oled_write_P(PSTR("Colemak\n"), false); + break; + + case _DVORAK: + oled_write_P(PSTR("Dvorak\n"), false); + break; + + case _QWERTY: + oled_write_P(PSTR("Qwerty\n"), false); + break; + + default: + oled_write_P(PSTR("Undefined\n"), false); + break; +#endif + } +} + +/** @brief displays the current active layer. + * + * If any argument is invalid, the function has no effect. + * + * @param void. + * @return void. + */ +void render_layer_state(void){ + CUSTOM_LAYERS_T current_layer; + current_layer=(CUSTOM_LAYERS_T)get_highest_layer(layer_state); + +#ifdef OLED_VERTICAL + oled_write_P(PSTR("Lyr:\n"), false); +#else + oled_write_P(PSTR("Layer:"), false); +#endif + + switch(current_layer){ +#ifdef OLED_VERTICAL + case _LOWER: + oled_write_P(PSTR("Lwr\n"), true); + break; + + case _RAISE: + oled_write_P(PSTR("Ris\n"), true); + break; + + case _ADJUST: + oled_write_P(PSTR("Adj\n"), true); + break; + + case _NUMPAD: + oled_write_P(PSTR("Num\n"), true); + break; + + default: + oled_write_P(PSTR("Def\n"), false); + break; + +#else + case _LOWER: + oled_write_P(PSTR(" Lower "), true); + break; + + case _RAISE: + oled_write_P(PSTR(" Raise "), true); + break; + + case _ADJUST: + oled_write_P(PSTR(" Adjust "), true); + break; + + case _NUMPAD: + oled_write_P(PSTR(" Numpad "), true); + break; + + default: + oled_write_P(PSTR(" Default "), false); + break; +#endif + } +} + +/** @brief displays the current status of the main display/ + * + * If any argument is invalid, the function has no effect. + * + * @param void. + * @return void. + */ +void render_status(void){ + render_layout_state(); + oled_write_P(PSTR("\n"), false); + render_layer_state(); + render_keylogger_status(); +} + +/** @brief renders the logo to be displayed. + * + * If any argument is invalid, the function has no effect. + * + * @param void. + * @return void. + */ +static void render_logo(void){ + static const char PROGMEM qmk_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, + 0x00}; + + oled_write_P(qmk_logo, false); +} + +/** @brief executes the actions for both displays. + * + * If any argument is invalid, the function has no effect. + * + * @param void. + * @return void. + */ +bool oled_task_user(void){ + if (timer_elapsed32(standby_oled_timer) > 15000){ + oled_off(); + }else{ + oled_on(); + if(true==is_keyboard_master()){ + render_status(); + }else{ + render_logo(); + oled_write_P(PSTR("\n"), false); + oled_scroll_left(); + } + } + return false; +} + +/** @brief process the current key and add it to the keylog string. + * + * If any argument is invalid, the function has no effect. + * + * @param keycode pressed key. + * @return void. + */ +extern void add_keylog(uint16_t keycode){ + if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)){ + keycode&=0x00FF; + } + + if(current_cursor_pos>(KEYLOG_LEN-1)||(current_cursor_pos>KEYLOG_STRING_STARTUP)){ + current_cursor_pos=0; + last_c=get_ascii(keycode); + current_cursor_pos++; + }else{ + if(keycode <= KC_TILD){ + keylog_str[current_cursor_pos]=last_c; + last_c=get_ascii(keycode); + current_cursor_pos++; + } + keylog_str[current_cursor_pos] = '\0'; + } + + log_timer = timer_read(); + + standby_oled_timer = timer_read32(); +} |