keymap.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. Copyright 2021 0xCB - Conor Burns
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include QMK_KEYBOARD_H
  15. #include <stdio.h>
  16. enum layer_names {
  17. _HOME,
  18. _MISC,
  19. _RGB,
  20. _BLED
  21. };
  22. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  23. [_HOME] = LAYOUT(
  24. KC_MPRV, KC_MNXT, KC_MPLY,
  25. KC_PGUP, KC_PGDN, TO(3),
  26. KC_HOME, KC_END, TO(1)
  27. ),
  28. [_MISC] = LAYOUT(
  29. _______, _______, _______,
  30. _______, _______, TO(0),
  31. _______, _______, TO(2)
  32. ),
  33. [_RGB] = LAYOUT(
  34. RGB_HUI, RGB_HUD, RGB_MOD,
  35. RGB_SAI, RGB_SAD, TO(1),
  36. RGB_SPI, RGB_SPD, TO(3)
  37. ),
  38. [_BLED] = LAYOUT(
  39. BL_STEP, BL_BRTG, BL_TOGG,
  40. BL_ON, BL_OFF, TO(2),
  41. BL_INC, BL_DEC, TO(0)
  42. )
  43. };
  44. /* rotary encoder (SW3) - add more else if blocks for more granular layer control */
  45. #ifdef ENCODER_ENABLE
  46. bool encoder_update_user(uint8_t index, bool clockwise) {
  47. if (IS_LAYER_ON(_RGB)) {
  48. #ifdef RGBLIGHT_ENABLE
  49. if (clockwise) {
  50. rgblight_increase_val();
  51. } else {
  52. rgblight_decrease_val();
  53. }
  54. #endif
  55. } else if (IS_LAYER_ON(_BLED)) {
  56. if (clockwise) {
  57. backlight_increase();
  58. } else {
  59. backlight_decrease();
  60. }
  61. } else {
  62. if (clockwise) {
  63. tap_code(KC_VOLU);
  64. } else {
  65. tap_code(KC_VOLD);
  66. }
  67. }
  68. return true;
  69. }
  70. #endif
  71. /* oled stuff :) */
  72. #ifdef OLED_DRIVER_ENABLE
  73. uint16_t startup_timer;
  74. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  75. startup_timer = timer_read();
  76. return rotation;
  77. }
  78. static void render_logo(void) {
  79. static const char PROGMEM raw_logo[] = {
  80. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64,160, 19,162, 66, 66, 66, 66, 66, 66, 66,255,255,255, 0, 0, 0,252,254,254,192,192,192,192,255, 0, 0, 0, 62, 62, 60, 60, 0, 0, 1,255,255,255, 66, 66, 66, 66, 66, 66, 66,162, 19,160, 64, 0,
  85. 0, 0, 0,128, 64, 64, 64,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,128,192, 64, 64,192,128, 0, 0,192, 64, 64,192,128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,192, 64,192, 0, 0, 0, 0, 0,128,192, 64, 64,192,128, 0, 0,128,192, 64, 64,192,128, 0, 0, 64, 64, 64, 64, 64,192, 0, 0, 0, 0, 0,249, 8, 8, 8, 8, 8, 8, 8, 8,127,255,255,192,128,128, 15, 31, 31, 1, 1, 1, 1,255, 0, 0, 0, 30, 30, 14, 14,128,192,192,255,255,127, 8, 8, 8, 8, 8, 8, 8, 8,249, 0, 0, 0,
  86. 0, 0, 31, 49, 64, 78, 64, 49, 31, 0, 0, 97, 22, 8, 22, 97, 0, 0, 31, 49, 96, 64, 64, 96, 32, 0, 0,127, 68, 68,100, 59, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 64,127, 64, 64, 0, 0, 0, 32,100, 68, 68,110, 59, 0, 0, 32,100, 68, 68,110, 59, 0, 0, 0, 0, 0,126, 3, 1, 0, 0, 0, 8, 20, 35, 20, 8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 7, 7, 15,254, 30, 28, 28, 28,255, 28, 28, 28, 30,254, 15, 7, 3, 3, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 4, 10, 17, 10, 4, 0,
  87. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 40, 68, 40, 16, 16, 16, 16, 16, 16, 31, 0, 0, 16, 40, 71, 40, 16, 0, 0, 31, 16, 16, 16, 16, 16, 16, 40, 68, 40, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  88. };
  89. oled_write_raw_P(raw_logo, sizeof(raw_logo));
  90. }
  91. static void render_logo_font(void) {
  92. static const char PROGMEM qmk_logo[] = {
  93. 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xCB, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0xCB, 0xCB, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9,
  94. 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xCB, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xCB, 0xCB, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9,
  95. 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xCB, 0x88, 0x89, 0x8A, 0x8B, 0x8A, 0x8B, 0x8C, 0x8D, 0xCB, 0xCB, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5,
  96. 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xCB, 0xA8, 0xA9, 0xAA, 0xAB, 0xAA, 0xAB, 0xAC, 0xAD, 0xCB, 0xCB, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0x00
  97. };
  98. oled_write_P(qmk_logo, false);
  99. }
  100. /* Shows the name of the current layer and locks for the host (CAPS etc.) */
  101. static void render_info(void) {
  102. oled_write_P(PSTR("Layer: "), false);
  103. switch (get_highest_layer(layer_state)) {
  104. case _HOME:
  105. oled_write_ln_P(PSTR("HOME"), false);
  106. break;
  107. case _MISC:
  108. oled_write_ln_P(PSTR("MISC"), false);
  109. break;
  110. case _RGB:
  111. oled_write_ln_P(PSTR("RGB"), false);
  112. break;
  113. case _BLED:
  114. oled_write_ln_P(PSTR("Backlight"), false);
  115. break;
  116. default:
  117. oled_write_ln_P(PSTR("Undefined"), false);
  118. }
  119. led_t led_state = host_keyboard_led_state();
  120. oled_write_P(led_state.num_lock ? PSTR("NUM ") : PSTR(" "), false);
  121. oled_write_P(led_state.caps_lock ? PSTR("CAP ") : PSTR(" "), false);
  122. oled_write_ln_P(led_state.scroll_lock ? PSTR("SCR ") : PSTR(" "), false);
  123. }
  124. static void render_rgbled_status(bool full) {
  125. #ifdef RGBLIGHT_ENABLE
  126. char buf[30];
  127. if (RGBLIGHT_MODES > 1 && rgblight_is_enabled() && get_highest_layer(layer_state) == _RGB) {
  128. if (full) {
  129. snprintf(buf, sizeof(buf), "RGB mode %2d: %d,%d,%d \n",
  130. rgblight_get_mode(),
  131. rgblight_get_hue()/RGBLIGHT_HUE_STEP,
  132. rgblight_get_sat()/RGBLIGHT_SAT_STEP,
  133. rgblight_get_val()/RGBLIGHT_VAL_STEP);
  134. } else {
  135. snprintf(buf, sizeof(buf), "[%2d] ", rgblight_get_mode());
  136. }
  137. oled_write(buf, false);
  138. } else {
  139. oled_write_ln_P(PSTR("\n"), false);
  140. }
  141. #endif
  142. }
  143. void oled_task_user(void) {
  144. static bool finished_timer = false;
  145. if (!finished_timer && (timer_elapsed(startup_timer) < 1000)) {
  146. render_logo();
  147. } else {
  148. if (!finished_timer) {
  149. oled_clear();
  150. finished_timer = true;
  151. }
  152. render_info();
  153. render_rgbled_status(true);
  154. render_logo_font();
  155. }
  156. }
  157. #endif