keymap.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /* Copyright 2021 Kyle McCreery
  2. * Copyright 2021 Jonavin Eng
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include QMK_KEYBOARD_H
  18. #include "jonavin.h"
  19. #include "layout_landscape.h"
  20. // Defines names for use in layer keycodes and the keymap
  21. enum layer_names {
  22. _FN2 = 2,
  23. _FN3,
  24. _FN4,
  25. _RGB
  26. };
  27. #ifdef LANDSCAPE_MODE
  28. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  29. [_BASE] = LAYOUT_landscape(
  30. TT(_FN1), TT(_FN2), KC_MUTE,
  31. KC_NUM, KC_PSLS, KC_PAST, KC_PMNS, KC_PPLS, KC_BSPC,
  32. KC_TAB, KC_P7, KC_P8, KC_P9, KC_PDOT, KC_RGUI,
  33. KC_RSFT, KC_P4, KC_P5, KC_P6, KC_COMMA, KC_RCTL,
  34. KC_P0, KC_P1, KC_P2, KC_P3, KC_PENT, KC_RALT,
  35. TT(_FN3), TT(_FN4), TT(_RGB)
  36. ),
  37. [_FN1] = LAYOUT_landscape(
  38. _______, _______, ENCFUNC,
  39. _______, KC_F10, KC_F11, KC_F12, KC_PSCR, _______,
  40. _______, KC_F7, KC_F8, KC_F9, KC_SCRL, _______,
  41. _______, KC_F4, KC_F5, KC_F6, KC_PAUS, _______,
  42. _______, KC_F1, KC_F2, KC_F3, _______, _______,
  43. _______, _______, _______
  44. ),
  45. [_FN2] = LAYOUT_landscape(
  46. _______, _______, QK_BOOT,
  47. _______, _______, KC_MPLY, KC_MPRV, KC_MNXT, _______,
  48. _______, _______, _______, _______, _______, _______,
  49. _______, _______, _______, _______, _______, _______,
  50. _______, _______, _______, _______, _______, _______,
  51. _______, _______, _______
  52. ),
  53. [_FN3] = LAYOUT_landscape(
  54. _______, _______, _______,
  55. _______, _______, _______, _______, _______, _______,
  56. _______, _______, _______, _______, _______, _______,
  57. _______, _______, _______, _______, _______, _______,
  58. _______, _______, _______, _______, _______, _______,
  59. _______, _______, _______
  60. ),
  61. [_FN4] = LAYOUT_landscape(
  62. _______, _______, _______,
  63. _______, _______, _______, _______, _______, _______,
  64. _______, _______, _______, _______, _______, _______,
  65. _______, _______, _______, _______, _______, _______,
  66. _______, _______, _______, _______, _______, _______,
  67. _______, _______, _______
  68. ),
  69. [_RGB] = LAYOUT_landscape(
  70. _______, _______, _______,
  71. _______, _______, _______, _______, _______, _______,
  72. _______, RGB_HUD, RGB_SPI, RGB_HUI, RGB_SAI, _______,
  73. _______, RGB_RMOD, RGB_TOG, RGB_MOD, RGB_SAD, _______,
  74. _______, RGB_VAD, RGB_SPD, RGB_VAI, KC_NO, _______,
  75. _______, _______, _______
  76. ),
  77. };
  78. #endif // LANDSCAPE_MODE
  79. #ifndef LANDSCAPE_MODE
  80. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  81. /* Base */
  82. [_BASE] = LAYOUT(
  83. TT(_FN2),TT(_FN3),TT(_FN4),LT(_RGB,KC_PSCR),
  84. KC_NUM, KC_PSLS, KC_PAST, KC_PMNS,
  85. KC_P7, KC_P8, KC_P9, KC_PPLS,
  86. KC_MUTE, KC_P4, KC_P5, KC_P6, _______,
  87. TT(_FN1), KC_P1, KC_P2, KC_P3, KC_PENT,
  88. KC_RALT, KC_P0, _______, KC_PDOT, _______,
  89. TT(_FN3), TT(_FN4), TT(_RGB)
  90. ),
  91. [_FN1] = LAYOUT(
  92. _______, _______, _______, QK_BOOT,
  93. KC_CALC, _______, _______, _______,
  94. _______, _______, _______, _______,
  95. ENCFUNC, KC_TAB, _______, _______, _______,
  96. _______, _______, _______, _______, _______,
  97. _______, KC_BSPC, _______, KC_DEL, _______,
  98. _______, _______, _______
  99. ),
  100. [_FN2] = LAYOUT(
  101. _______, _______, _______, _______,
  102. _______, _______, KC_MPLY, KC_MPRV,
  103. _______, _______, _______, KC_MNXT,
  104. QK_BOOT, _______, _______, _______, _______,
  105. _______, _______, _______, _______, _______,
  106. _______, _______, _______, _______, _______,
  107. _______, _______, _______
  108. ),
  109. [_FN3] = LAYOUT(
  110. _______, _______, _______, _______,
  111. _______, _______, _______, _______,
  112. _______, _______, _______, _______,
  113. _______, _______, _______, _______, _______,
  114. _______, _______, _______, _______, _______,
  115. _______, _______, _______, _______, _______,
  116. _______, _______, _______
  117. ),
  118. [_FN4] = LAYOUT(
  119. _______, _______, _______, _______,
  120. _______, _______, _______, _______,
  121. _______, _______, _______, _______,
  122. _______, _______, _______, _______, _______,
  123. _______, _______, _______, _______, _______,
  124. _______, _______, _______, _______, _______,
  125. _______, _______, _______
  126. ),
  127. [_RGB] = LAYOUT(
  128. _______, _______, _______, _______,
  129. _______, _______, _______, _______,
  130. RGB_HUD, RGB_SPI, RGB_HUI, _______,
  131. _______, RGB_RMOD, RGB_TOG, RGB_MOD, _______,
  132. _______, RGB_VAD, RGB_SPD, RGB_VAI, _______,
  133. _______, RGB_SAD, _______, RGB_SAI, _______,
  134. _______, _______, _______
  135. ),
  136. };
  137. #endif // !LANDSCAPE_MODE
  138. typedef struct {
  139. char keydesc[6]; // this will be displayed on OLED
  140. uint16_t keycode; // this is the keycode that will be sent when activted
  141. } keycodedescType;
  142. static const keycodedescType PROGMEM keyselection[] = {
  143. // list of key codes that will be scrolled through by encoder and description
  144. {"TASK ", KC_TASK},
  145. {"PREV ", KC_MEDIA_PREV_TRACK},
  146. {"NEXT ", KC_MEDIA_NEXT_TRACK},
  147. {"PLAY ", KC_MEDIA_PLAY_PAUSE},
  148. {"PrtScm", KC_PSCR},
  149. {"ScrLk", KC_SCLN},
  150. {"Break", KC_PAUS},
  151. {"C-A-D", KC_CAD}, // Ctrl-Alt-Del
  152. {"AltF4", KC_AF4},
  153. {"RESET", QK_BOOT}, // firmware flash mode
  154. };
  155. #define MAX_KEYSELECTION ARRAY_SIZE(keyselection)
  156. static uint8_t selectedkey_idx = 0;
  157. static keycodedescType selectedkey_rec;
  158. static void set_selectedkey(uint8_t idx) {
  159. // make a copy from PROGMEM
  160. memcpy_P (&selectedkey_rec, &keyselection[idx], sizeof selectedkey_rec);
  161. //selectedkey_rec = keyselection[idx];
  162. }
  163. void keyboard_post_init_keymap(void) {
  164. // Call the keyboard post init code.
  165. set_selectedkey(selectedkey_idx);
  166. }
  167. bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
  168. switch (keycode) {
  169. case ENCFUNC:
  170. if (record->event.pressed) {
  171. selectedkey_rec.keycode == QK_BOOT ? reset_keyboard() : tap_code16(selectedkey_rec.keycode); // handle QK_BOOT code
  172. } else {
  173. // when keycode is released
  174. }
  175. break;
  176. }
  177. return true;
  178. };
  179. #ifdef ENCODER_ENABLE // Encoder Functionality
  180. void encoder_action_selectkey(bool clockwise) {
  181. if ( clockwise ) {
  182. if ( selectedkey_idx < MAX_KEYSELECTION-1) {
  183. selectedkey_idx ++;
  184. } else {
  185. // do nothing
  186. }
  187. } else if ( !clockwise ) {
  188. if ( selectedkey_idx > 0){
  189. selectedkey_idx --;
  190. } else {
  191. // do nothing
  192. }
  193. }
  194. set_selectedkey(selectedkey_idx);
  195. }
  196. bool encoder_update_user(uint8_t index, bool clockwise) {
  197. #ifdef OLED_ENABLE
  198. oled_clear();
  199. oled_render();
  200. #endif
  201. uint8_t mods_state = get_mods();
  202. switch (index) {
  203. case 0: // main primary encoder
  204. switch(get_highest_layer(layer_state)){ // special handling per layer
  205. case _FN1: // on Fn layer select what the encoder does when pressed
  206. if (!mods_state) {
  207. encoder_action_selectkey(clockwise);
  208. break;
  209. } else {
  210. // continue to default
  211. }
  212. case _RGB:
  213. if (!mods_state) {
  214. encoder_action_rgb_hue(clockwise);
  215. break;
  216. }
  217. default: // all other layers
  218. if (mods_state & MOD_BIT(KC_RSFT) ) { // If you are holding R shift, encoder changes layers
  219. encoder_action_layerchange(clockwise);
  220. } else if (mods_state & MOD_BIT(KC_RCTL)) { // if holding Right Ctrl, navigate next/prev word
  221. encoder_action_navword(clockwise);
  222. } else if (mods_state & MOD_BIT(KC_RALT)) { // if holding Right Alt, change media next/prev track
  223. encoder_action_mediatrack(clockwise);
  224. } else {
  225. encoder_action_volume(clockwise); // Otherwise it just changes volume
  226. }
  227. break;
  228. }
  229. break;
  230. case 1: // optional secondary encoder
  231. switch(get_highest_layer(layer_state)){ // special handling per layer
  232. case _RGB:
  233. if (!mods_state) {
  234. encoder_action_rgb_mode(clockwise);
  235. break;
  236. }
  237. default: // all other layers
  238. encoder_action_mediatrack(clockwise); // Otherwise prev/next track
  239. break;
  240. }
  241. }
  242. return false;
  243. }
  244. #endif
  245. #ifdef OLED_ENABLE
  246. static void render_logo(void) { // Render MechWild "MW" Logo
  247. static const char PROGMEM logo_1[] = {0x8A, 0x8B, 0x8C, 0x8D, 0x00};
  248. static const char PROGMEM logo_2[] = {0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0x00};
  249. static const char PROGMEM logo_3[] = {0xCA, 0xCB, 0xCC, 0xCD, 0x00};
  250. static const char PROGMEM logo_4[] = {0x20, 0x8E, 0x8F, 0x90, 0x00};
  251. oled_set_cursor(0,0);
  252. oled_write_P(logo_1, false);
  253. oled_set_cursor(0,1);
  254. oled_write_P(logo_2, false);
  255. oled_set_cursor(0,2);
  256. oled_write_P(logo_3, false);
  257. oled_set_cursor(0,3);
  258. oled_write_P(logo_4, false);
  259. }
  260. #ifdef LANDSCAPE_MODE
  261. oled_rotation_t oled_init_user(oled_rotation_t rotation) {
  262. return OLED_ROTATION_0; // do not flip the display
  263. }
  264. bool oled_task_user(void) {
  265. render_logo();
  266. oled_set_cursor(8,2);
  267. switch(get_selected_layer()){
  268. case _BASE:
  269. oled_write_P(PSTR("BASE"), false);
  270. break;
  271. case _FN1:
  272. oled_write_P(PSTR("FN "), false);
  273. oled_write(selectedkey_rec.keydesc, false);
  274. break;
  275. case _FN2:
  276. oled_write_P(PSTR("FN2 "), false);
  277. break;
  278. case _FN3:
  279. oled_write_P(PSTR("FN3 "), false);
  280. break;
  281. case _FN4:
  282. oled_write_P(PSTR("FN4 "), false);
  283. break;
  284. case _RGB:
  285. oled_write_P(PSTR("RGB "), false);
  286. break;
  287. default:
  288. oled_write_P(PSTR(" ?? "), false); // Should never display, here as a catchall
  289. }
  290. oled_write_P(keymap_config.no_gui ? PSTR(" WL") : PSTR(" "), false);
  291. oled_set_cursor(8,3);
  292. if (get_highest_layer(layer_state) == get_selected_layer()) {
  293. oled_write_P(PSTR(" "), false);
  294. } else {
  295. switch (get_highest_layer(layer_state)) {
  296. case _BASE:
  297. oled_write_P(PSTR("Temp BASE"), false);
  298. break;
  299. case _FN1:
  300. oled_write_P(PSTR("Temp FN "), false);
  301. oled_write(selectedkey_rec.keydesc, false);
  302. break;
  303. case _FN2:
  304. oled_write_P(PSTR("Temp FN2 "), false);
  305. break;
  306. case _FN3:
  307. oled_write_P(PSTR("Temp FN3 "), false);
  308. break;
  309. case _FN4:
  310. oled_write_P(PSTR("Temp FN4 "), false);
  311. break;
  312. case _RGB:
  313. oled_write_P(PSTR("Temp RGB "), false);
  314. break;
  315. default:
  316. oled_write_P(PSTR("Temp ????"), false); // Should never display, here as a catchall
  317. }
  318. }
  319. led_t led_state = host_keyboard_led_state();
  320. oled_set_cursor(8,0);
  321. oled_write_P(PSTR(" JONAVIN "), false);
  322. oled_set_cursor(8,1);
  323. oled_write_P(led_state.num_lock ? PSTR("NUM ") : PSTR(" "), false);
  324. oled_write_P(led_state.caps_lock ? PSTR("CAPS ") : PSTR(" "), false);
  325. oled_write_P(led_state.scroll_lock ? PSTR("SCR") : PSTR(" "), false);
  326. return false;
  327. }
  328. #endif // LANDSCAPE_MODE
  329. // regular mode
  330. #ifndef LANDSCAPE_MODE
  331. bool oled_task_user(void) {
  332. render_logo();
  333. oled_set_cursor(0,5);
  334. oled_write_ln_P(PSTR("-JV-"), false);
  335. oled_write_ln_P(PSTR(" "), false);
  336. bool showSelectedKey = false;
  337. switch (get_highest_layer(layer_state)) {
  338. case _BASE:
  339. oled_write_ln_P(PSTR("BASE"), false);
  340. break;
  341. case _FN1:
  342. oled_write_ln_P(PSTR("FN 1"), false);
  343. showSelectedKey = true;
  344. break;
  345. case _FN2:
  346. oled_write_ln_P(PSTR("FN 2"), false);
  347. break;
  348. case _FN3:
  349. oled_write_ln_P(PSTR("FN 3"), false);
  350. break;
  351. case _FN4:
  352. oled_write_ln_P(PSTR("FN 4"), false);
  353. break;
  354. case _RGB:
  355. oled_write_ln_P(PSTR("RGB "), false);
  356. break;
  357. default:
  358. oled_write_ln_P(PSTR(" ?? "), false);
  359. }
  360. if (showSelectedKey) oled_write_ln(selectedkey_rec.keydesc, false);
  361. else oled_write_ln_P(PSTR(" "), false);
  362. // Host Keyboard LED Status
  363. led_t led_state = host_keyboard_led_state();
  364. oled_set_cursor(0,11);
  365. oled_write_ln_P(led_state.num_lock ? PSTR(" NUM") : PSTR(" "), false);
  366. oled_write_ln_P(led_state.caps_lock ? PSTR(" CAP") : PSTR(" "), false);
  367. oled_write_ln_P(led_state.scroll_lock ? PSTR(" SCR") : PSTR(" "), false);
  368. return false;
  369. }
  370. #endif // !LANDSCAPE_MODE
  371. void suspend_power_down_user(void) { // shutdown oled when powered down to prevent OLED from showing Mercutio all the time
  372. oled_off();
  373. rgblight_disable_noeeprom();
  374. }
  375. void suspend_wakeup_init_user(void) {
  376. rgblight_enable_noeeprom();
  377. }
  378. #endif