quantum.c 32 KB

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