quantum.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. /* Copyright 2016-2017 Jack Humbert
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "quantum.h"
  17. #ifdef PROTOCOL_LUFA
  18. #include "outputselect.h"
  19. #endif
  20. #ifndef TAPPING_TERM
  21. #define TAPPING_TERM 200
  22. #endif
  23. #ifndef BREATHING_PERIOD
  24. #define BREATHING_PERIOD 6
  25. #endif
  26. #include "backlight.h"
  27. extern backlight_config_t backlight_config;
  28. #ifdef FAUXCLICKY_ENABLE
  29. #include "fauxclicky.h"
  30. #endif
  31. #ifdef API_ENABLE
  32. #include "api.h"
  33. #endif
  34. #ifdef MIDI_ENABLE
  35. #include "process_midi.h"
  36. #endif
  37. #ifdef AUDIO_ENABLE
  38. #ifndef GOODBYE_SONG
  39. #define GOODBYE_SONG SONG(GOODBYE_SOUND)
  40. #endif
  41. #ifndef AG_NORM_SONG
  42. #define AG_NORM_SONG SONG(AG_NORM_SOUND)
  43. #endif
  44. #ifndef AG_SWAP_SONG
  45. #define AG_SWAP_SONG SONG(AG_SWAP_SOUND)
  46. #endif
  47. float goodbye_song[][2] = GOODBYE_SONG;
  48. float ag_norm_song[][2] = AG_NORM_SONG;
  49. float ag_swap_song[][2] = AG_SWAP_SONG;
  50. #ifdef DEFAULT_LAYER_SONGS
  51. float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
  52. #endif
  53. #endif
  54. static void do_code16 (uint16_t code, void (*f) (uint8_t)) {
  55. switch (code) {
  56. case QK_MODS ... QK_MODS_MAX:
  57. break;
  58. default:
  59. return;
  60. }
  61. if (code & QK_LCTL)
  62. f(KC_LCTL);
  63. if (code & QK_LSFT)
  64. f(KC_LSFT);
  65. if (code & QK_LALT)
  66. f(KC_LALT);
  67. if (code & QK_LGUI)
  68. f(KC_LGUI);
  69. if (code < QK_RMODS_MIN) return;
  70. if (code & QK_RCTL)
  71. f(KC_RCTL);
  72. if (code & QK_RSFT)
  73. f(KC_RSFT);
  74. if (code & QK_RALT)
  75. f(KC_RALT);
  76. if (code & QK_RGUI)
  77. f(KC_RGUI);
  78. }
  79. static inline void qk_register_weak_mods(uint8_t kc) {
  80. add_weak_mods(MOD_BIT(kc));
  81. send_keyboard_report();
  82. }
  83. static inline void qk_unregister_weak_mods(uint8_t kc) {
  84. del_weak_mods(MOD_BIT(kc));
  85. send_keyboard_report();
  86. }
  87. static inline void qk_register_mods(uint8_t kc) {
  88. add_weak_mods(MOD_BIT(kc));
  89. send_keyboard_report();
  90. }
  91. static inline void qk_unregister_mods(uint8_t kc) {
  92. del_weak_mods(MOD_BIT(kc));
  93. send_keyboard_report();
  94. }
  95. void register_code16 (uint16_t code) {
  96. if (IS_MOD(code) || code == KC_NO) {
  97. do_code16 (code, qk_register_mods);
  98. } else {
  99. do_code16 (code, qk_register_weak_mods);
  100. }
  101. register_code (code);
  102. }
  103. void unregister_code16 (uint16_t code) {
  104. unregister_code (code);
  105. if (IS_MOD(code) || code == KC_NO) {
  106. do_code16 (code, qk_unregister_mods);
  107. } else {
  108. do_code16 (code, qk_unregister_weak_mods);
  109. }
  110. }
  111. __attribute__ ((weak))
  112. bool process_action_kb(keyrecord_t *record) {
  113. return true;
  114. }
  115. __attribute__ ((weak))
  116. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  117. return process_record_user(keycode, record);
  118. }
  119. __attribute__ ((weak))
  120. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  121. return true;
  122. }
  123. void reset_keyboard(void) {
  124. clear_keyboard();
  125. #if defined(MIDI_ENABLE) && defined(MIDI_BASIC)
  126. process_midi_all_notes_off();
  127. #endif
  128. #if defined(AUDIO_ENABLE) && !defined(NO_MUSIC_MODE)
  129. music_all_notes_off();
  130. uint16_t timer_start = timer_read();
  131. PLAY_SONG(goodbye_song);
  132. shutdown_user();
  133. while(timer_elapsed(timer_start) < 250)
  134. wait_ms(1);
  135. stop_all_notes();
  136. #else
  137. wait_ms(250);
  138. #endif
  139. // this is also done later in bootloader.c - not sure if it's neccesary here
  140. #ifdef BOOTLOADER_CATERINA
  141. *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
  142. #endif
  143. bootloader_jump();
  144. }
  145. // Shift / paren setup
  146. #ifndef LSPO_KEY
  147. #define LSPO_KEY KC_9
  148. #endif
  149. #ifndef RSPC_KEY
  150. #define RSPC_KEY KC_0
  151. #endif
  152. // Shift / Enter setup
  153. #ifndef SFTENT_KEY
  154. #define SFTENT_KEY KC_ENT
  155. #endif
  156. static bool shift_interrupted[2] = {0, 0};
  157. static uint16_t scs_timer[2] = {0, 0};
  158. /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
  159. * Used to ensure that the correct keycode is released if the key is released.
  160. */
  161. static bool grave_esc_was_shifted = false;
  162. bool process_record_quantum(keyrecord_t *record) {
  163. /* This gets the keycode from the key pressed */
  164. keypos_t key = record->event.key;
  165. uint16_t keycode;
  166. #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
  167. /* TODO: Use store_or_get_action() or a similar function. */
  168. if (!disable_action_cache) {
  169. uint8_t layer;
  170. if (record->event.pressed) {
  171. layer = layer_switch_get_layer(key);
  172. update_source_layers_cache(key, layer);
  173. } else {
  174. layer = read_source_layers_cache(key);
  175. }
  176. keycode = keymap_key_to_keycode(layer, key);
  177. } else
  178. #endif
  179. keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
  180. // This is how you use actions here
  181. // if (keycode == KC_LEAD) {
  182. // action_t action;
  183. // action.code = ACTION_DEFAULT_LAYER_SET(0);
  184. // process_action(record, action);
  185. // return false;
  186. // }
  187. #ifdef TAP_DANCE_ENABLE
  188. preprocess_tap_dance(keycode, record);
  189. #endif
  190. if (!(
  191. #if defined(KEY_LOCK_ENABLE)
  192. // Must run first to be able to mask key_up events.
  193. process_key_lock(&keycode, record) &&
  194. #endif
  195. process_record_kb(keycode, record) &&
  196. #if defined(MIDI_ENABLE) && defined(MIDI_ADVANCED)
  197. process_midi(keycode, record) &&
  198. #endif
  199. #ifdef AUDIO_ENABLE
  200. process_audio(keycode, record) &&
  201. #endif
  202. #ifdef STENO_ENABLE
  203. process_steno(keycode, record) &&
  204. #endif
  205. #if ( defined(AUDIO_ENABLE) || (defined(MIDI_ENABLE) && defined(MIDI_BASIC))) && !defined(NO_MUSIC_MODE)
  206. process_music(keycode, record) &&
  207. #endif
  208. #ifdef TAP_DANCE_ENABLE
  209. process_tap_dance(keycode, record) &&
  210. #endif
  211. #ifndef DISABLE_LEADER
  212. process_leader(keycode, record) &&
  213. #endif
  214. #ifndef DISABLE_CHORDING
  215. process_chording(keycode, record) &&
  216. #endif
  217. #ifdef COMBO_ENABLE
  218. process_combo(keycode, record) &&
  219. #endif
  220. #ifdef UNICODE_ENABLE
  221. process_unicode(keycode, record) &&
  222. #endif
  223. #ifdef UCIS_ENABLE
  224. process_ucis(keycode, record) &&
  225. #endif
  226. #ifdef PRINTING_ENABLE
  227. process_printer(keycode, record) &&
  228. #endif
  229. #ifdef AUTO_SHIFT_ENABLE
  230. process_auto_shift(keycode, record) &&
  231. #endif
  232. #ifdef UNICODEMAP_ENABLE
  233. process_unicode_map(keycode, record) &&
  234. #endif
  235. #ifdef TERMINAL_ENABLE
  236. process_terminal(keycode, record) &&
  237. #endif
  238. true)) {
  239. return false;
  240. }
  241. // Shift / paren setup
  242. switch(keycode) {
  243. case RESET:
  244. if (record->event.pressed) {
  245. reset_keyboard();
  246. }
  247. return false;
  248. case DEBUG:
  249. if (record->event.pressed) {
  250. debug_enable = true;
  251. print("DEBUG: enabled.\n");
  252. }
  253. return false;
  254. #ifdef FAUXCLICKY_ENABLE
  255. case FC_TOG:
  256. if (record->event.pressed) {
  257. FAUXCLICKY_TOGGLE;
  258. }
  259. return false;
  260. case FC_ON:
  261. if (record->event.pressed) {
  262. FAUXCLICKY_ON;
  263. }
  264. return false;
  265. case FC_OFF:
  266. if (record->event.pressed) {
  267. FAUXCLICKY_OFF;
  268. }
  269. return false;
  270. #endif
  271. #ifdef RGBLIGHT_ENABLE
  272. case RGB_TOG:
  273. if (record->event.pressed) {
  274. rgblight_toggle();
  275. }
  276. return false;
  277. case RGB_MODE_FORWARD:
  278. if (record->event.pressed) {
  279. uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT));
  280. if(shifted) {
  281. rgblight_step_reverse();
  282. }
  283. else {
  284. rgblight_step();
  285. }
  286. }
  287. return false;
  288. case RGB_MODE_REVERSE:
  289. if (record->event.pressed) {
  290. uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT));
  291. if(shifted) {
  292. rgblight_step();
  293. }
  294. else {
  295. rgblight_step_reverse();
  296. }
  297. }
  298. return false;
  299. case RGB_HUI:
  300. if (record->event.pressed) {
  301. rgblight_increase_hue();
  302. }
  303. return false;
  304. case RGB_HUD:
  305. if (record->event.pressed) {
  306. rgblight_decrease_hue();
  307. }
  308. return false;
  309. case RGB_SAI:
  310. if (record->event.pressed) {
  311. rgblight_increase_sat();
  312. }
  313. return false;
  314. case RGB_SAD:
  315. if (record->event.pressed) {
  316. rgblight_decrease_sat();
  317. }
  318. return false;
  319. case RGB_VAI:
  320. if (record->event.pressed) {
  321. rgblight_increase_val();
  322. }
  323. return false;
  324. case RGB_VAD:
  325. if (record->event.pressed) {
  326. rgblight_decrease_val();
  327. }
  328. return false;
  329. case RGB_MODE_PLAIN:
  330. if (record->event.pressed) {
  331. rgblight_mode(1);
  332. }
  333. return false;
  334. case RGB_MODE_BREATHE:
  335. if (record->event.pressed) {
  336. if ((2 <= rgblight_get_mode()) && (rgblight_get_mode() < 5)) {
  337. rgblight_step();
  338. } else {
  339. rgblight_mode(2);
  340. }
  341. }
  342. return false;
  343. case RGB_MODE_RAINBOW:
  344. if (record->event.pressed) {
  345. if ((6 <= rgblight_get_mode()) && (rgblight_get_mode() < 8)) {
  346. rgblight_step();
  347. } else {
  348. rgblight_mode(6);
  349. }
  350. }
  351. return false;
  352. case RGB_MODE_SWIRL:
  353. if (record->event.pressed) {
  354. if ((9 <= rgblight_get_mode()) && (rgblight_get_mode() < 14)) {
  355. rgblight_step();
  356. } else {
  357. rgblight_mode(9);
  358. }
  359. }
  360. return false;
  361. case RGB_MODE_SNAKE:
  362. if (record->event.pressed) {
  363. if ((15 <= rgblight_get_mode()) && (rgblight_get_mode() < 20)) {
  364. rgblight_step();
  365. } else {
  366. rgblight_mode(15);
  367. }
  368. }
  369. return false;
  370. case RGB_MODE_KNIGHT:
  371. if (record->event.pressed) {
  372. if ((21 <= rgblight_get_mode()) && (rgblight_get_mode() < 23)) {
  373. rgblight_step();
  374. } else {
  375. rgblight_mode(21);
  376. }
  377. }
  378. return false;
  379. case RGB_MODE_XMAS:
  380. if (record->event.pressed) {
  381. rgblight_mode(24);
  382. }
  383. return false;
  384. case RGB_MODE_GRADIENT:
  385. if (record->event.pressed) {
  386. if ((25 <= rgblight_get_mode()) && (rgblight_get_mode() < 34)) {
  387. rgblight_step();
  388. } else {
  389. rgblight_mode(25);
  390. }
  391. }
  392. return false;
  393. #endif
  394. #ifdef PROTOCOL_LUFA
  395. case OUT_AUTO:
  396. if (record->event.pressed) {
  397. set_output(OUTPUT_AUTO);
  398. }
  399. return false;
  400. case OUT_USB:
  401. if (record->event.pressed) {
  402. set_output(OUTPUT_USB);
  403. }
  404. return false;
  405. #ifdef BLUETOOTH_ENABLE
  406. case OUT_BT:
  407. if (record->event.pressed) {
  408. set_output(OUTPUT_BLUETOOTH);
  409. }
  410. return false;
  411. #endif
  412. #endif
  413. case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_NKRO:
  414. if (record->event.pressed) {
  415. // MAGIC actions (BOOTMAGIC without the boot)
  416. if (!eeconfig_is_enabled()) {
  417. eeconfig_init();
  418. }
  419. /* keymap config */
  420. keymap_config.raw = eeconfig_read_keymap();
  421. switch (keycode)
  422. {
  423. case MAGIC_SWAP_CONTROL_CAPSLOCK:
  424. keymap_config.swap_control_capslock = true;
  425. break;
  426. case MAGIC_CAPSLOCK_TO_CONTROL:
  427. keymap_config.capslock_to_control = true;
  428. break;
  429. case MAGIC_SWAP_LALT_LGUI:
  430. keymap_config.swap_lalt_lgui = true;
  431. break;
  432. case MAGIC_SWAP_RALT_RGUI:
  433. keymap_config.swap_ralt_rgui = true;
  434. break;
  435. case MAGIC_NO_GUI:
  436. keymap_config.no_gui = true;
  437. break;
  438. case MAGIC_SWAP_GRAVE_ESC:
  439. keymap_config.swap_grave_esc = true;
  440. break;
  441. case MAGIC_SWAP_BACKSLASH_BACKSPACE:
  442. keymap_config.swap_backslash_backspace = true;
  443. break;
  444. case MAGIC_HOST_NKRO:
  445. keymap_config.nkro = true;
  446. break;
  447. case MAGIC_SWAP_ALT_GUI:
  448. keymap_config.swap_lalt_lgui = true;
  449. keymap_config.swap_ralt_rgui = true;
  450. #ifdef AUDIO_ENABLE
  451. PLAY_SONG(ag_swap_song);
  452. #endif
  453. break;
  454. case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
  455. keymap_config.swap_control_capslock = false;
  456. break;
  457. case MAGIC_UNCAPSLOCK_TO_CONTROL:
  458. keymap_config.capslock_to_control = false;
  459. break;
  460. case MAGIC_UNSWAP_LALT_LGUI:
  461. keymap_config.swap_lalt_lgui = false;
  462. break;
  463. case MAGIC_UNSWAP_RALT_RGUI:
  464. keymap_config.swap_ralt_rgui = false;
  465. break;
  466. case MAGIC_UNNO_GUI:
  467. keymap_config.no_gui = false;
  468. break;
  469. case MAGIC_UNSWAP_GRAVE_ESC:
  470. keymap_config.swap_grave_esc = false;
  471. break;
  472. case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
  473. keymap_config.swap_backslash_backspace = false;
  474. break;
  475. case MAGIC_UNHOST_NKRO:
  476. keymap_config.nkro = false;
  477. break;
  478. case MAGIC_UNSWAP_ALT_GUI:
  479. keymap_config.swap_lalt_lgui = false;
  480. keymap_config.swap_ralt_rgui = false;
  481. #ifdef AUDIO_ENABLE
  482. PLAY_SONG(ag_norm_song);
  483. #endif
  484. break;
  485. case MAGIC_TOGGLE_NKRO:
  486. keymap_config.nkro = !keymap_config.nkro;
  487. break;
  488. default:
  489. break;
  490. }
  491. eeconfig_update_keymap(keymap_config.raw);
  492. clear_keyboard(); // clear to prevent stuck keys
  493. return false;
  494. }
  495. break;
  496. case KC_LSPO: {
  497. if (record->event.pressed) {
  498. shift_interrupted[0] = false;
  499. scs_timer[0] = timer_read ();
  500. register_mods(MOD_BIT(KC_LSFT));
  501. }
  502. else {
  503. #ifdef DISABLE_SPACE_CADET_ROLLOVER
  504. if (get_mods() & MOD_BIT(KC_RSFT)) {
  505. shift_interrupted[0] = true;
  506. shift_interrupted[1] = true;
  507. }
  508. #endif
  509. if (!shift_interrupted[0] && timer_elapsed(scs_timer[0]) < TAPPING_TERM) {
  510. register_code(LSPO_KEY);
  511. unregister_code(LSPO_KEY);
  512. }
  513. unregister_mods(MOD_BIT(KC_LSFT));
  514. }
  515. return false;
  516. }
  517. case KC_RSPC: {
  518. if (record->event.pressed) {
  519. shift_interrupted[1] = false;
  520. scs_timer[1] = timer_read ();
  521. register_mods(MOD_BIT(KC_RSFT));
  522. }
  523. else {
  524. #ifdef DISABLE_SPACE_CADET_ROLLOVER
  525. if (get_mods() & MOD_BIT(KC_LSFT)) {
  526. shift_interrupted[0] = true;
  527. shift_interrupted[1] = true;
  528. }
  529. #endif
  530. if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) {
  531. register_code(RSPC_KEY);
  532. unregister_code(RSPC_KEY);
  533. }
  534. unregister_mods(MOD_BIT(KC_RSFT));
  535. }
  536. return false;
  537. }
  538. case KC_SFTENT: {
  539. if (record->event.pressed) {
  540. shift_interrupted[1] = false;
  541. scs_timer[1] = timer_read ();
  542. register_mods(MOD_BIT(KC_RSFT));
  543. }
  544. else if (!shift_interrupted[1] && timer_elapsed(scs_timer[1]) < TAPPING_TERM) {
  545. unregister_mods(MOD_BIT(KC_RSFT));
  546. register_code(SFTENT_KEY);
  547. unregister_code(SFTENT_KEY);
  548. }
  549. else {
  550. unregister_mods(MOD_BIT(KC_RSFT));
  551. }
  552. return false;
  553. }
  554. case GRAVE_ESC: {
  555. uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT)
  556. |MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)));
  557. #ifdef GRAVE_ESC_ALT_OVERRIDE
  558. // if ALT is pressed, ESC is always sent
  559. // this is handy for the cmd+opt+esc shortcut on macOS, among other things.
  560. if (get_mods() & (MOD_BIT(KC_LALT) | MOD_BIT(KC_RALT))) {
  561. shifted = 0;
  562. }
  563. #endif
  564. #ifdef GRAVE_ESC_CTRL_OVERRIDE
  565. // if CTRL is pressed, ESC is always sent
  566. // this is handy for the ctrl+shift+esc shortcut on windows, among other things.
  567. if (get_mods() & (MOD_BIT(KC_LCTL) | MOD_BIT(KC_RCTL))) {
  568. shifted = 0;
  569. }
  570. #endif
  571. #ifdef GRAVE_ESC_GUI_OVERRIDE
  572. // if GUI is pressed, ESC is always sent
  573. if (get_mods() & (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))) {
  574. shifted = 0;
  575. }
  576. #endif
  577. #ifdef GRAVE_ESC_SHIFT_OVERRIDE
  578. // if SHIFT is pressed, ESC is always sent
  579. if (get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) {
  580. shifted = 0;
  581. }
  582. #endif
  583. if (record->event.pressed) {
  584. grave_esc_was_shifted = shifted;
  585. add_key(shifted ? KC_GRAVE : KC_ESCAPE);
  586. }
  587. else {
  588. del_key(grave_esc_was_shifted ? KC_GRAVE : KC_ESCAPE);
  589. }
  590. send_keyboard_report();
  591. return false;
  592. }
  593. #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING)
  594. case BL_BRTG: {
  595. if (record->event.pressed)
  596. breathing_toggle();
  597. return false;
  598. }
  599. #endif
  600. default: {
  601. shift_interrupted[0] = true;
  602. shift_interrupted[1] = true;
  603. break;
  604. }
  605. }
  606. return process_action_kb(record);
  607. }
  608. __attribute__ ((weak))
  609. const bool ascii_to_shift_lut[0x80] PROGMEM = {
  610. 0, 0, 0, 0, 0, 0, 0, 0,
  611. 0, 0, 0, 0, 0, 0, 0, 0,
  612. 0, 0, 0, 0, 0, 0, 0, 0,
  613. 0, 0, 0, 0, 0, 0, 0, 0,
  614. 0, 1, 1, 1, 1, 1, 1, 0,
  615. 1, 1, 1, 1, 0, 0, 0, 0,
  616. 0, 0, 0, 0, 0, 0, 0, 0,
  617. 0, 0, 1, 0, 1, 0, 1, 1,
  618. 1, 1, 1, 1, 1, 1, 1, 1,
  619. 1, 1, 1, 1, 1, 1, 1, 1,
  620. 1, 1, 1, 1, 1, 1, 1, 1,
  621. 1, 1, 1, 0, 0, 0, 1, 1,
  622. 0, 0, 0, 0, 0, 0, 0, 0,
  623. 0, 0, 0, 0, 0, 0, 0, 0,
  624. 0, 0, 0, 0, 0, 0, 0, 0,
  625. 0, 0, 0, 1, 1, 1, 1, 0
  626. };
  627. __attribute__ ((weak))
  628. const uint8_t ascii_to_keycode_lut[0x80] PROGMEM = {
  629. 0, 0, 0, 0, 0, 0, 0, 0,
  630. KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
  631. 0, 0, 0, 0, 0, 0, 0, 0,
  632. 0, 0, 0, KC_ESC, 0, 0, 0, 0,
  633. KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
  634. KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
  635. KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
  636. KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
  637. KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  638. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  639. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  640. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
  641. KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  642. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  643. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  644. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
  645. };
  646. void send_string(const char *str) {
  647. send_string_with_delay(str, 0);
  648. }
  649. void send_string_P(const char *str) {
  650. send_string_with_delay_P(str, 0);
  651. }
  652. void send_string_with_delay(const char *str, uint8_t interval) {
  653. while (1) {
  654. char ascii_code = *str;
  655. if (!ascii_code) break;
  656. if (ascii_code == 1) {
  657. // tap
  658. uint8_t keycode = *(++str);
  659. register_code(keycode);
  660. unregister_code(keycode);
  661. } else if (ascii_code == 2) {
  662. // down
  663. uint8_t keycode = *(++str);
  664. register_code(keycode);
  665. } else if (ascii_code == 3) {
  666. // up
  667. uint8_t keycode = *(++str);
  668. unregister_code(keycode);
  669. } else {
  670. send_char(ascii_code);
  671. }
  672. ++str;
  673. // interval
  674. { uint8_t ms = interval; while (ms--) wait_ms(1); }
  675. }
  676. }
  677. void send_string_with_delay_P(const char *str, uint8_t interval) {
  678. while (1) {
  679. char ascii_code = pgm_read_byte(str);
  680. if (!ascii_code) break;
  681. if (ascii_code == 1) {
  682. // tap
  683. uint8_t keycode = pgm_read_byte(++str);
  684. register_code(keycode);
  685. unregister_code(keycode);
  686. } else if (ascii_code == 2) {
  687. // down
  688. uint8_t keycode = pgm_read_byte(++str);
  689. register_code(keycode);
  690. } else if (ascii_code == 3) {
  691. // up
  692. uint8_t keycode = pgm_read_byte(++str);
  693. unregister_code(keycode);
  694. } else {
  695. send_char(ascii_code);
  696. }
  697. ++str;
  698. // interval
  699. { uint8_t ms = interval; while (ms--) wait_ms(1); }
  700. }
  701. }
  702. void send_char(char ascii_code) {
  703. uint8_t keycode;
  704. keycode = pgm_read_byte(&ascii_to_keycode_lut[(uint8_t)ascii_code]);
  705. if (pgm_read_byte(&ascii_to_shift_lut[(uint8_t)ascii_code])) {
  706. register_code(KC_LSFT);
  707. register_code(keycode);
  708. unregister_code(keycode);
  709. unregister_code(KC_LSFT);
  710. } else {
  711. register_code(keycode);
  712. unregister_code(keycode);
  713. }
  714. }
  715. void set_single_persistent_default_layer(uint8_t default_layer) {
  716. #if defined(AUDIO_ENABLE) && defined(DEFAULT_LAYER_SONGS)
  717. PLAY_SONG(default_layer_songs[default_layer]);
  718. #endif
  719. eeconfig_update_default_layer(1U<<default_layer);
  720. default_layer_set(1U<<default_layer);
  721. }
  722. void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  723. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  724. layer_on(layer3);
  725. } else {
  726. layer_off(layer3);
  727. }
  728. }
  729. void tap_random_base64(void) {
  730. #if defined(__AVR_ATmega32U4__)
  731. uint8_t key = (TCNT0 + TCNT1 + TCNT3 + TCNT4) % 64;
  732. #else
  733. uint8_t key = rand() % 64;
  734. #endif
  735. switch (key) {
  736. case 0 ... 25:
  737. register_code(KC_LSFT);
  738. register_code(key + KC_A);
  739. unregister_code(key + KC_A);
  740. unregister_code(KC_LSFT);
  741. break;
  742. case 26 ... 51:
  743. register_code(key - 26 + KC_A);
  744. unregister_code(key - 26 + KC_A);
  745. break;
  746. case 52:
  747. register_code(KC_0);
  748. unregister_code(KC_0);
  749. break;
  750. case 53 ... 61:
  751. register_code(key - 53 + KC_1);
  752. unregister_code(key - 53 + KC_1);
  753. break;
  754. case 62:
  755. register_code(KC_LSFT);
  756. register_code(KC_EQL);
  757. unregister_code(KC_EQL);
  758. unregister_code(KC_LSFT);
  759. break;
  760. case 63:
  761. register_code(KC_SLSH);
  762. unregister_code(KC_SLSH);
  763. break;
  764. }
  765. }
  766. void matrix_init_quantum() {
  767. #ifdef BACKLIGHT_ENABLE
  768. backlight_init_ports();
  769. #endif
  770. #ifdef AUDIO_ENABLE
  771. audio_init();
  772. #endif
  773. matrix_init_kb();
  774. }
  775. void matrix_scan_quantum() {
  776. #if defined(AUDIO_ENABLE)
  777. matrix_scan_music();
  778. #endif
  779. #ifdef TAP_DANCE_ENABLE
  780. matrix_scan_tap_dance();
  781. #endif
  782. #ifdef COMBO_ENABLE
  783. matrix_scan_combo();
  784. #endif
  785. #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
  786. backlight_task();
  787. #endif
  788. matrix_scan_kb();
  789. }
  790. #if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_PIN)
  791. static const uint8_t backlight_pin = BACKLIGHT_PIN;
  792. // depending on the pin, we use a different output compare unit
  793. #if BACKLIGHT_PIN == B7
  794. # define COM1x1 COM1C1
  795. # define OCR1x OCR1C
  796. #elif BACKLIGHT_PIN == B6
  797. # define COM1x1 COM1B1
  798. # define OCR1x OCR1B
  799. #elif BACKLIGHT_PIN == B5
  800. # define COM1x1 COM1A1
  801. # define OCR1x OCR1A
  802. #else
  803. # define NO_HARDWARE_PWM
  804. #endif
  805. #ifndef BACKLIGHT_ON_STATE
  806. #define BACKLIGHT_ON_STATE 0
  807. #endif
  808. #ifdef NO_HARDWARE_PWM // pwm through software
  809. __attribute__ ((weak))
  810. void backlight_init_ports(void)
  811. {
  812. // Setup backlight pin as output and output to on state.
  813. // DDRx |= n
  814. _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
  815. #if BACKLIGHT_ON_STATE == 0
  816. // PORTx &= ~n
  817. _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
  818. #else
  819. // PORTx |= n
  820. _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
  821. #endif
  822. }
  823. __attribute__ ((weak))
  824. void backlight_set(uint8_t level) {}
  825. uint8_t backlight_tick = 0;
  826. #ifndef BACKLIGHT_CUSTOM_DRIVER
  827. void backlight_task(void) {
  828. if ((0xFFFF >> ((BACKLIGHT_LEVELS - get_backlight_level()) * ((BACKLIGHT_LEVELS + 1) / 2))) & (1 << backlight_tick)) {
  829. #if BACKLIGHT_ON_STATE == 0
  830. // PORTx &= ~n
  831. _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
  832. #else
  833. // PORTx |= n
  834. _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
  835. #endif
  836. } else {
  837. #if BACKLIGHT_ON_STATE == 0
  838. // PORTx |= n
  839. _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
  840. #else
  841. // PORTx &= ~n
  842. _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
  843. #endif
  844. }
  845. backlight_tick = (backlight_tick + 1) % 16;
  846. }
  847. #endif
  848. #ifdef BACKLIGHT_BREATHING
  849. #ifndef BACKLIGHT_CUSTOM_DRIVER
  850. #error "Backlight breathing only available with hardware PWM. Please disable."
  851. #endif
  852. #endif
  853. #else // pwm through timer
  854. #define TIMER_TOP 0xFFFFU
  855. // See http://jared.geek.nz/2013/feb/linear-led-pwm
  856. static uint16_t cie_lightness(uint16_t v) {
  857. if (v <= 5243) // if below 8% of max
  858. return v / 9; // same as dividing by 900%
  859. else {
  860. uint32_t y = (((uint32_t) v + 10486) << 8) / (10486 + 0xFFFFUL); // add 16% of max and compare
  861. // to get a useful result with integer division, we shift left in the expression above
  862. // and revert what we've done again after squaring.
  863. y = y * y * y >> 8;
  864. if (y > 0xFFFFUL) // prevent overflow
  865. return 0xFFFFU;
  866. else
  867. return (uint16_t) y;
  868. }
  869. }
  870. // range for val is [0..TIMER_TOP]. PWM pin is high while the timer count is below val.
  871. static inline void set_pwm(uint16_t val) {
  872. OCR1x = val;
  873. }
  874. #ifndef BACKLIGHT_CUSTOM_DRIVER
  875. __attribute__ ((weak))
  876. void backlight_set(uint8_t level) {
  877. if (level > BACKLIGHT_LEVELS)
  878. level = BACKLIGHT_LEVELS;
  879. if (level == 0) {
  880. // Turn off PWM control on backlight pin
  881. TCCR1A &= ~(_BV(COM1x1));
  882. } else {
  883. // Turn on PWM control of backlight pin
  884. TCCR1A |= _BV(COM1x1);
  885. }
  886. // Set the brightness
  887. set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS));
  888. }
  889. void backlight_task(void) {}
  890. #endif // BACKLIGHT_CUSTOM_DRIVER
  891. #ifdef BACKLIGHT_BREATHING
  892. #define BREATHING_NO_HALT 0
  893. #define BREATHING_HALT_OFF 1
  894. #define BREATHING_HALT_ON 2
  895. #define BREATHING_STEPS 128
  896. static uint8_t breathing_period = BREATHING_PERIOD;
  897. static uint8_t breathing_halt = BREATHING_NO_HALT;
  898. static uint16_t breathing_counter = 0;
  899. bool is_breathing(void) {
  900. return !!(TIMSK1 & _BV(TOIE1));
  901. }
  902. #define breathing_interrupt_enable() do {TIMSK1 |= _BV(TOIE1);} while (0)
  903. #define breathing_interrupt_disable() do {TIMSK1 &= ~_BV(TOIE1);} while (0)
  904. #define breathing_min() do {breathing_counter = 0;} while (0)
  905. #define breathing_max() do {breathing_counter = breathing_period * 244 / 2;} while (0)
  906. void breathing_enable(void)
  907. {
  908. breathing_counter = 0;
  909. breathing_halt = BREATHING_NO_HALT;
  910. breathing_interrupt_enable();
  911. }
  912. void breathing_pulse(void)
  913. {
  914. if (get_backlight_level() == 0)
  915. breathing_min();
  916. else
  917. breathing_max();
  918. breathing_halt = BREATHING_HALT_ON;
  919. breathing_interrupt_enable();
  920. }
  921. void breathing_disable(void)
  922. {
  923. breathing_interrupt_disable();
  924. // Restore backlight level
  925. backlight_set(get_backlight_level());
  926. }
  927. void breathing_self_disable(void)
  928. {
  929. if (get_backlight_level() == 0)
  930. breathing_halt = BREATHING_HALT_OFF;
  931. else
  932. breathing_halt = BREATHING_HALT_ON;
  933. }
  934. void breathing_toggle(void) {
  935. if (is_breathing())
  936. breathing_disable();
  937. else
  938. breathing_enable();
  939. }
  940. void breathing_period_set(uint8_t value)
  941. {
  942. if (!value)
  943. value = 1;
  944. breathing_period = value;
  945. }
  946. void breathing_period_default(void) {
  947. breathing_period_set(BREATHING_PERIOD);
  948. }
  949. void breathing_period_inc(void)
  950. {
  951. breathing_period_set(breathing_period+1);
  952. }
  953. void breathing_period_dec(void)
  954. {
  955. breathing_period_set(breathing_period-1);
  956. }
  957. /* To generate breathing curve in python:
  958. * from math import sin, pi; [int(sin(x/128.0*pi)**4*255) for x in range(128)]
  959. */
  960. static const uint8_t breathing_table[BREATHING_STEPS] PROGMEM = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 17, 20, 24, 28, 32, 36, 41, 46, 51, 57, 63, 70, 76, 83, 91, 98, 106, 113, 121, 129, 138, 146, 154, 162, 170, 178, 185, 193, 200, 207, 213, 220, 225, 231, 235, 240, 244, 247, 250, 252, 253, 254, 255, 254, 253, 252, 250, 247, 244, 240, 235, 231, 225, 220, 213, 207, 200, 193, 185, 178, 170, 162, 154, 146, 138, 129, 121, 113, 106, 98, 91, 83, 76, 70, 63, 57, 51, 46, 41, 36, 32, 28, 24, 20, 17, 15, 12, 10, 8, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  961. // Use this before the cie_lightness function.
  962. static inline uint16_t scale_backlight(uint16_t v) {
  963. return v / BACKLIGHT_LEVELS * get_backlight_level();
  964. }
  965. /* Assuming a 16MHz CPU clock and a timer that resets at 64k (ICR1), the following interrupt handler will run
  966. * about 244 times per second.
  967. */
  968. ISR(TIMER1_OVF_vect)
  969. {
  970. uint16_t interval = (uint16_t) breathing_period * 244 / BREATHING_STEPS;
  971. // resetting after one period to prevent ugly reset at overflow.
  972. breathing_counter = (breathing_counter + 1) % (breathing_period * 244);
  973. uint8_t index = breathing_counter / interval % BREATHING_STEPS;
  974. if (((breathing_halt == BREATHING_HALT_ON) && (index == BREATHING_STEPS / 2)) ||
  975. ((breathing_halt == BREATHING_HALT_OFF) && (index == BREATHING_STEPS - 1)))
  976. {
  977. breathing_interrupt_disable();
  978. }
  979. set_pwm(cie_lightness(scale_backlight((uint16_t) pgm_read_byte(&breathing_table[index]) * 0x0101U)));
  980. }
  981. #endif // BACKLIGHT_BREATHING
  982. __attribute__ ((weak))
  983. void backlight_init_ports(void)
  984. {
  985. // Setup backlight pin as output and output to on state.
  986. // DDRx |= n
  987. _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
  988. #if BACKLIGHT_ON_STATE == 0
  989. // PORTx &= ~n
  990. _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
  991. #else
  992. // PORTx |= n
  993. _SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
  994. #endif
  995. // I could write a wall of text here to explain... but TL;DW
  996. // Go read the ATmega32u4 datasheet.
  997. // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
  998. // Pin PB7 = OCR1C (Timer 1, Channel C)
  999. // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
  1000. // (i.e. start high, go low when counter matches.)
  1001. // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
  1002. // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
  1003. /*
  1004. 14.8.3:
  1005. "In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM [..]."
  1006. "In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGMn3:0 = 5, 6, or 7), the value in ICRn (WGMn3:0 = 14), or the value in OCRnA (WGMn3:0 = 15)."
  1007. */
  1008. TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
  1009. TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
  1010. // Use full 16-bit resolution. Counter counts to ICR1 before reset to 0.
  1011. ICR1 = TIMER_TOP;
  1012. backlight_init();
  1013. #ifdef BACKLIGHT_BREATHING
  1014. breathing_enable();
  1015. #endif
  1016. }
  1017. #endif // NO_HARDWARE_PWM
  1018. #else // backlight
  1019. __attribute__ ((weak))
  1020. void backlight_init_ports(void) {}
  1021. __attribute__ ((weak))
  1022. void backlight_set(uint8_t level) {}
  1023. #endif // backlight
  1024. // Functions for spitting out values
  1025. //
  1026. void send_dword(uint32_t number) { // this might not actually work
  1027. uint16_t word = (number >> 16);
  1028. send_word(word);
  1029. send_word(number & 0xFFFFUL);
  1030. }
  1031. void send_word(uint16_t number) {
  1032. uint8_t byte = number >> 8;
  1033. send_byte(byte);
  1034. send_byte(number & 0xFF);
  1035. }
  1036. void send_byte(uint8_t number) {
  1037. uint8_t nibble = number >> 4;
  1038. send_nibble(nibble);
  1039. send_nibble(number & 0xF);
  1040. }
  1041. void send_nibble(uint8_t number) {
  1042. switch (number) {
  1043. case 0:
  1044. register_code(KC_0);
  1045. unregister_code(KC_0);
  1046. break;
  1047. case 1 ... 9:
  1048. register_code(KC_1 + (number - 1));
  1049. unregister_code(KC_1 + (number - 1));
  1050. break;
  1051. case 0xA ... 0xF:
  1052. register_code(KC_A + (number - 0xA));
  1053. unregister_code(KC_A + (number - 0xA));
  1054. break;
  1055. }
  1056. }
  1057. __attribute__((weak))
  1058. uint16_t hex_to_keycode(uint8_t hex)
  1059. {
  1060. hex = hex & 0xF;
  1061. if (hex == 0x0) {
  1062. return KC_0;
  1063. } else if (hex < 0xA) {
  1064. return KC_1 + (hex - 0x1);
  1065. } else {
  1066. return KC_A + (hex - 0xA);
  1067. }
  1068. }
  1069. void api_send_unicode(uint32_t unicode) {
  1070. #ifdef API_ENABLE
  1071. uint8_t chunk[4];
  1072. dword_to_bytes(unicode, chunk);
  1073. MT_SEND_DATA(DT_UNICODE, chunk, 5);
  1074. #endif
  1075. }
  1076. __attribute__ ((weak))
  1077. void led_set_user(uint8_t usb_led) {
  1078. }
  1079. __attribute__ ((weak))
  1080. void led_set_kb(uint8_t usb_led) {
  1081. led_set_user(usb_led);
  1082. }
  1083. __attribute__ ((weak))
  1084. void led_init_ports(void)
  1085. {
  1086. }
  1087. __attribute__ ((weak))
  1088. void led_set(uint8_t usb_led)
  1089. {
  1090. // Example LED Code
  1091. //
  1092. // // Using PE6 Caps Lock LED
  1093. // if (usb_led & (1<<USB_LED_CAPS_LOCK))
  1094. // {
  1095. // // Output high.
  1096. // DDRE |= (1<<6);
  1097. // PORTE |= (1<<6);
  1098. // }
  1099. // else
  1100. // {
  1101. // // Output low.
  1102. // DDRE &= ~(1<<6);
  1103. // PORTE &= ~(1<<6);
  1104. // }
  1105. led_set_kb(usb_led);
  1106. }
  1107. //------------------------------------------------------------------------------
  1108. // Override these functions in your keymap file to play different tunes on
  1109. // different events such as startup and bootloader jump
  1110. __attribute__ ((weak))
  1111. void startup_user() {}
  1112. __attribute__ ((weak))
  1113. void shutdown_user() {}
  1114. //------------------------------------------------------------------------------