quantum.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. #include "quantum.h"
  2. __attribute__ ((weak))
  3. void matrix_init_kb(void) {}
  4. __attribute__ ((weak))
  5. void matrix_scan_kb(void) {}
  6. __attribute__ ((weak))
  7. bool process_action_kb(keyrecord_t *record) {
  8. return true;
  9. }
  10. __attribute__ ((weak))
  11. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  12. return process_record_user(keycode, record);
  13. }
  14. __attribute__ ((weak))
  15. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  16. return true;
  17. }
  18. __attribute__ ((weak))
  19. void leader_start(void) {}
  20. __attribute__ ((weak))
  21. void leader_end(void) {}
  22. uint8_t starting_note = 0x0C;
  23. int offset = 7;
  24. #ifdef AUDIO_ENABLE
  25. bool music_activated = false;
  26. // music sequencer
  27. static bool music_sequence_recording = false;
  28. static bool music_sequence_playing = false;
  29. static float music_sequence[16] = {0};
  30. static uint8_t music_sequence_count = 0;
  31. static uint8_t music_sequence_position = 0;
  32. static uint16_t music_sequence_timer = 0;
  33. static uint16_t music_sequence_interval = 100;
  34. #endif
  35. #ifdef MIDI_ENABLE
  36. bool midi_activated = false;
  37. #endif
  38. // Leader key stuff
  39. bool leading = false;
  40. uint16_t leader_time = 0;
  41. uint16_t leader_sequence[5] = {0, 0, 0, 0, 0};
  42. uint8_t leader_sequence_size = 0;
  43. // Chording stuff
  44. #define CHORDING_MAX 4
  45. bool chording = false;
  46. uint8_t chord_keys[CHORDING_MAX] = {0};
  47. uint8_t chord_key_count = 0;
  48. uint8_t chord_key_down = 0;
  49. #ifdef UNICODE_ENABLE
  50. static uint8_t input_mode;
  51. #endif
  52. // Shift / paren setup
  53. #ifndef LSPO_KEY
  54. #define LSPO_KEY KC_9
  55. #endif
  56. #ifndef RSPC_KEY
  57. #define RSPC_KEY KC_0
  58. #endif
  59. static bool shift_interrupted[2] = {0, 0};
  60. bool keys_chord(uint8_t keys[]) {
  61. uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
  62. bool pass = true;
  63. uint8_t in = 0;
  64. for (uint8_t i = 0; i < chord_key_count; i++) {
  65. bool found = false;
  66. for (uint8_t j = 0; j < keys_size; j++) {
  67. if (chord_keys[i] == (keys[j] & 0xFF)) {
  68. in++; // detects key in chord
  69. found = true;
  70. break;
  71. }
  72. }
  73. if (found)
  74. continue;
  75. if (chord_keys[i] != 0) {
  76. pass = false; // makes sure rest are blank
  77. }
  78. }
  79. return (pass && (in == keys_size));
  80. }
  81. #ifdef UNICODE_ENABLE
  82. uint16_t hex_to_keycode(uint8_t hex)
  83. {
  84. if (hex == 0x0) {
  85. return KC_0;
  86. } else if (hex < 0xA) {
  87. return KC_1 + (hex - 0x1);
  88. } else {
  89. return KC_A + (hex - 0xA);
  90. }
  91. }
  92. void set_unicode_mode(uint8_t os_target)
  93. {
  94. input_mode = os_target;
  95. }
  96. #endif
  97. bool process_record_quantum(keyrecord_t *record) {
  98. /* This gets the keycode from the key pressed */
  99. keypos_t key = record->event.key;
  100. uint16_t keycode;
  101. #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
  102. uint8_t layer;
  103. if (record->event.pressed) {
  104. layer = layer_switch_get_layer(key);
  105. update_source_layers_cache(key, layer);
  106. } else {
  107. layer = read_source_layers_cache(key);
  108. }
  109. keycode = keymap_key_to_keycode(layer, key);
  110. #else
  111. keycode = keymap_key_to_keycode(layer_switch_get_layer(key), key);
  112. #endif
  113. if (!process_record_kb(keycode, record))
  114. return false;
  115. // This is how you use actions here
  116. // if (keycode == KC_LEAD) {
  117. // action_t action;
  118. // action.code = ACTION_DEFAULT_LAYER_SET(0);
  119. // process_action(record, action);
  120. // return false;
  121. // }
  122. #ifdef MIDI_ENABLE
  123. if (keycode == MI_ON && record->event.pressed) {
  124. midi_activated = true;
  125. music_scale_user();
  126. return false;
  127. }
  128. if (keycode == MI_OFF && record->event.pressed) {
  129. midi_activated = false;
  130. midi_send_cc(&midi_device, 0, 0x7B, 0);
  131. return false;
  132. }
  133. if (midi_activated) {
  134. if (record->event.key.col == (MATRIX_COLS - 1) && record->event.key.row == (MATRIX_ROWS - 1)) {
  135. if (record->event.pressed) {
  136. starting_note++; // Change key
  137. midi_send_cc(&midi_device, 0, 0x7B, 0);
  138. }
  139. return false;
  140. }
  141. if (record->event.key.col == (MATRIX_COLS - 2) && record->event.key.row == (MATRIX_ROWS - 1)) {
  142. if (record->event.pressed) {
  143. starting_note--; // Change key
  144. midi_send_cc(&midi_device, 0, 0x7B, 0);
  145. }
  146. return false;
  147. }
  148. if (record->event.key.col == (MATRIX_COLS - 3) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
  149. offset++; // Change scale
  150. midi_send_cc(&midi_device, 0, 0x7B, 0);
  151. return false;
  152. }
  153. if (record->event.key.col == (MATRIX_COLS - 4) && record->event.key.row == (MATRIX_ROWS - 1) && record->event.pressed) {
  154. offset--; // Change scale
  155. midi_send_cc(&midi_device, 0, 0x7B, 0);
  156. return false;
  157. }
  158. // basic
  159. // uint8_t note = (starting_note + SCALE[record->event.key.col + offset])+12*(MATRIX_ROWS - record->event.key.row);
  160. // advanced
  161. // uint8_t note = (starting_note + record->event.key.col + offset)+12*(MATRIX_ROWS - record->event.key.row);
  162. // guitar
  163. uint8_t note = (starting_note + record->event.key.col + offset)+5*(MATRIX_ROWS - record->event.key.row);
  164. // violin
  165. // uint8_t note = (starting_note + record->event.key.col + offset)+7*(MATRIX_ROWS - record->event.key.row);
  166. if (record->event.pressed) {
  167. // midi_send_noteon(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
  168. midi_send_noteon(&midi_device, 0, note, 127);
  169. } else {
  170. // midi_send_noteoff(&midi_device, record->event.key.row, starting_note + SCALE[record->event.key.col], 127);
  171. midi_send_noteoff(&midi_device, 0, note, 127);
  172. }
  173. if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
  174. return false;
  175. }
  176. #endif
  177. #ifdef AUDIO_ENABLE
  178. if (keycode == AU_ON && record->event.pressed) {
  179. audio_on();
  180. return false;
  181. }
  182. if (keycode == AU_OFF && record->event.pressed) {
  183. audio_off();
  184. return false;
  185. }
  186. if (keycode == AU_TOG && record->event.pressed) {
  187. if (is_audio_on())
  188. {
  189. audio_off();
  190. }
  191. else
  192. {
  193. audio_on();
  194. }
  195. return false;
  196. }
  197. if (keycode == MU_ON && record->event.pressed) {
  198. music_on();
  199. return false;
  200. }
  201. if (keycode == MU_OFF && record->event.pressed) {
  202. music_off();
  203. return false;
  204. }
  205. if (keycode == MU_TOG && record->event.pressed) {
  206. if (music_activated)
  207. {
  208. music_off();
  209. }
  210. else
  211. {
  212. music_on();
  213. }
  214. return false;
  215. }
  216. if (keycode == MUV_IN && record->event.pressed) {
  217. voice_iterate();
  218. music_scale_user();
  219. return false;
  220. }
  221. if (keycode == MUV_DE && record->event.pressed) {
  222. voice_deiterate();
  223. music_scale_user();
  224. return false;
  225. }
  226. if (music_activated) {
  227. if (keycode == KC_LCTL && record->event.pressed) { // Start recording
  228. stop_all_notes();
  229. music_sequence_recording = true;
  230. music_sequence_playing = false;
  231. music_sequence_count = 0;
  232. return false;
  233. }
  234. if (keycode == KC_LALT && record->event.pressed) { // Stop recording/playing
  235. stop_all_notes();
  236. music_sequence_recording = false;
  237. music_sequence_playing = false;
  238. return false;
  239. }
  240. if (keycode == KC_LGUI && record->event.pressed) { // Start playing
  241. stop_all_notes();
  242. music_sequence_recording = false;
  243. music_sequence_playing = true;
  244. music_sequence_position = 0;
  245. music_sequence_timer = 0;
  246. return false;
  247. }
  248. if (keycode == KC_UP) {
  249. if (record->event.pressed)
  250. music_sequence_interval-=10;
  251. return false;
  252. }
  253. if (keycode == KC_DOWN) {
  254. if (record->event.pressed)
  255. music_sequence_interval+=10;
  256. return false;
  257. }
  258. float freq = ((float)220.0)*pow(2.0, -5.0)*pow(2.0,(starting_note + SCALE[record->event.key.col + offset])/12.0+(MATRIX_ROWS - record->event.key.row));
  259. if (record->event.pressed) {
  260. play_note(freq, 0xF);
  261. if (music_sequence_recording) {
  262. music_sequence[music_sequence_count] = freq;
  263. music_sequence_count++;
  264. }
  265. } else {
  266. stop_note(freq);
  267. }
  268. if (keycode < 0xFF) // ignores all normal keycodes, but lets RAISE, LOWER, etc through
  269. return false;
  270. }
  271. #endif
  272. #ifndef DISABLE_LEADER
  273. // Leader key set-up
  274. if (record->event.pressed) {
  275. if (!leading && keycode == KC_LEAD) {
  276. leader_start();
  277. leading = true;
  278. leader_time = timer_read();
  279. leader_sequence_size = 0;
  280. leader_sequence[0] = 0;
  281. leader_sequence[1] = 0;
  282. leader_sequence[2] = 0;
  283. leader_sequence[3] = 0;
  284. leader_sequence[4] = 0;
  285. return false;
  286. }
  287. if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
  288. leader_sequence[leader_sequence_size] = keycode;
  289. leader_sequence_size++;
  290. return false;
  291. }
  292. }
  293. #endif
  294. #define DISABLE_CHORDING
  295. #ifndef DISABLE_CHORDING
  296. if (keycode >= QK_CHORDING && keycode <= QK_CHORDING_MAX) {
  297. if (record->event.pressed) {
  298. if (!chording) {
  299. chording = true;
  300. for (uint8_t i = 0; i < CHORDING_MAX; i++)
  301. chord_keys[i] = 0;
  302. chord_key_count = 0;
  303. chord_key_down = 0;
  304. }
  305. chord_keys[chord_key_count] = (keycode & 0xFF);
  306. chord_key_count++;
  307. chord_key_down++;
  308. return false;
  309. } else {
  310. if (chording) {
  311. chord_key_down--;
  312. if (chord_key_down == 0) {
  313. chording = false;
  314. // Chord Dictionary
  315. if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
  316. register_code(KC_A);
  317. unregister_code(KC_A);
  318. return false;
  319. }
  320. for (uint8_t i = 0; i < chord_key_count; i++) {
  321. register_code(chord_keys[i]);
  322. unregister_code(chord_keys[i]);
  323. return false;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. #endif
  330. #ifdef UNICODE_ENABLE
  331. if (keycode > QK_UNICODE && record->event.pressed) {
  332. uint16_t unicode = keycode & 0x7FFF;
  333. switch(input_mode) {
  334. case UC_OSX:
  335. register_code(KC_LALT);
  336. break;
  337. case UC_LNX:
  338. register_code(KC_LCTL);
  339. register_code(KC_LSFT);
  340. register_code(KC_U);
  341. unregister_code(KC_U);
  342. break;
  343. case UC_WIN:
  344. register_code(KC_LALT);
  345. register_code(KC_PPLS);
  346. unregister_code(KC_PPLS);
  347. break;
  348. }
  349. for(int i = 3; i >= 0; i--) {
  350. uint8_t digit = ((unicode >> (i*4)) & 0xF);
  351. register_code(hex_to_keycode(digit));
  352. unregister_code(hex_to_keycode(digit));
  353. }
  354. switch(input_mode) {
  355. case UC_OSX:
  356. case UC_WIN:
  357. unregister_code(KC_LALT);
  358. break;
  359. case UC_LNX:
  360. unregister_code(KC_LCTL);
  361. unregister_code(KC_LSFT);
  362. break;
  363. }
  364. }
  365. #endif
  366. // Shift / paren setup
  367. switch(keycode) {
  368. case RESET:
  369. if (record->event.pressed) {
  370. clear_keyboard();
  371. #ifdef AUDIO_ENABLE
  372. stop_all_notes();
  373. shutdown_user();
  374. #endif
  375. _delay_ms(250);
  376. #ifdef ATREUS_ASTAR
  377. *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
  378. #endif
  379. bootloader_jump();
  380. return false;
  381. }
  382. break;
  383. case DEBUG:
  384. if (record->event.pressed) {
  385. print("\nDEBUG: enabled.\n");
  386. debug_enable = true;
  387. return false;
  388. }
  389. break;
  390. case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
  391. if (record->event.pressed) {
  392. // MAGIC actions (BOOTMAGIC without the boot)
  393. if (!eeconfig_is_enabled()) {
  394. eeconfig_init();
  395. }
  396. /* keymap config */
  397. keymap_config.raw = eeconfig_read_keymap();
  398. if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
  399. keymap_config.swap_control_capslock = 1;
  400. } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
  401. keymap_config.capslock_to_control = 1;
  402. } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
  403. keymap_config.swap_lalt_lgui = 1;
  404. } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
  405. keymap_config.swap_ralt_rgui = 1;
  406. } else if (keycode == MAGIC_NO_GUI) {
  407. keymap_config.no_gui = 1;
  408. } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
  409. keymap_config.swap_grave_esc = 1;
  410. } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
  411. keymap_config.swap_backslash_backspace = 1;
  412. } else if (keycode == MAGIC_HOST_NKRO) {
  413. keymap_config.nkro = 1;
  414. } else if (keycode == MAGIC_SWAP_ALT_GUI) {
  415. keymap_config.swap_lalt_lgui = 1;
  416. keymap_config.swap_ralt_rgui = 1;
  417. }
  418. /* UNs */
  419. else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
  420. keymap_config.swap_control_capslock = 0;
  421. } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
  422. keymap_config.capslock_to_control = 0;
  423. } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
  424. keymap_config.swap_lalt_lgui = 0;
  425. } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
  426. keymap_config.swap_ralt_rgui = 0;
  427. } else if (keycode == MAGIC_UNNO_GUI) {
  428. keymap_config.no_gui = 0;
  429. } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
  430. keymap_config.swap_grave_esc = 0;
  431. } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
  432. keymap_config.swap_backslash_backspace = 0;
  433. } else if (keycode == MAGIC_UNHOST_NKRO) {
  434. keymap_config.nkro = 0;
  435. } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
  436. keymap_config.swap_lalt_lgui = 0;
  437. keymap_config.swap_ralt_rgui = 0;
  438. }
  439. eeconfig_update_keymap(keymap_config.raw);
  440. return false;
  441. }
  442. break;
  443. case KC_LSPO: {
  444. if (record->event.pressed) {
  445. shift_interrupted[0] = false;
  446. register_mods(MOD_BIT(KC_LSFT));
  447. }
  448. else {
  449. if (!shift_interrupted[0]) {
  450. register_code(LSPO_KEY);
  451. unregister_code(LSPO_KEY);
  452. }
  453. unregister_mods(MOD_BIT(KC_LSFT));
  454. }
  455. return false;
  456. break;
  457. }
  458. case KC_RSPC: {
  459. if (record->event.pressed) {
  460. shift_interrupted[1] = false;
  461. register_mods(MOD_BIT(KC_RSFT));
  462. }
  463. else {
  464. if (!shift_interrupted[1]) {
  465. register_code(RSPC_KEY);
  466. unregister_code(RSPC_KEY);
  467. }
  468. unregister_mods(MOD_BIT(KC_RSFT));
  469. }
  470. return false;
  471. break;
  472. }
  473. default: {
  474. shift_interrupted[0] = true;
  475. shift_interrupted[1] = true;
  476. break;
  477. }
  478. }
  479. return process_action_kb(record);
  480. }
  481. const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
  482. 0, 0, 0, 0, 0, 0, 0, 0,
  483. 0, 0, 0, 0, 0, 0, 0, 0,
  484. 0, 0, 0, 0, 0, 0, 0, 0,
  485. 0, 0, 0, 0, 0, 0, 0, 0,
  486. 0, 1, 1, 1, 1, 1, 1, 0,
  487. 1, 1, 1, 1, 0, 0, 0, 0,
  488. 0, 0, 0, 0, 0, 0, 0, 0,
  489. 0, 0, 1, 0, 1, 0, 1, 1,
  490. 1, 1, 1, 1, 1, 1, 1, 1,
  491. 1, 1, 1, 1, 1, 1, 1, 1,
  492. 1, 1, 1, 1, 1, 1, 1, 1,
  493. 1, 1, 1, 0, 0, 0, 1, 1,
  494. 0, 0, 0, 0, 0, 0, 0, 0,
  495. 0, 0, 0, 0, 0, 0, 0, 0,
  496. 0, 0, 0, 0, 0, 0, 0, 0,
  497. 0, 0, 0, 1, 1, 1, 1, 0
  498. };
  499. const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
  500. 0, 0, 0, 0, 0, 0, 0, 0,
  501. KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
  502. 0, 0, 0, 0, 0, 0, 0, 0,
  503. 0, 0, 0, KC_ESC, 0, 0, 0, 0,
  504. KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
  505. KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
  506. KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
  507. KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
  508. KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  509. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  510. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  511. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
  512. KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  513. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  514. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  515. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
  516. };
  517. /* for users whose OSes are set to Colemak */
  518. #if 0
  519. #include "keymap_colemak.h"
  520. const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
  521. 0, 0, 0, 0, 0, 0, 0, 0,
  522. 0, 0, 0, 0, 0, 0, 0, 0,
  523. 0, 0, 0, 0, 0, 0, 0, 0,
  524. 0, 0, 0, 0, 0, 0, 0, 0,
  525. 0, 1, 1, 1, 1, 1, 1, 0,
  526. 1, 1, 1, 1, 0, 0, 0, 0,
  527. 0, 0, 0, 0, 0, 0, 0, 0,
  528. 0, 0, 1, 0, 1, 0, 1, 1,
  529. 1, 1, 1, 1, 1, 1, 1, 1,
  530. 1, 1, 1, 1, 1, 1, 1, 1,
  531. 1, 1, 1, 1, 1, 1, 1, 1,
  532. 1, 1, 1, 0, 0, 0, 1, 1,
  533. 0, 0, 0, 0, 0, 0, 0, 0,
  534. 0, 0, 0, 0, 0, 0, 0, 0,
  535. 0, 0, 0, 0, 0, 0, 0, 0,
  536. 0, 0, 0, 1, 1, 1, 1, 0
  537. };
  538. const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
  539. 0, 0, 0, 0, 0, 0, 0, 0,
  540. KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
  541. 0, 0, 0, 0, 0, 0, 0, 0,
  542. 0, 0, 0, KC_ESC, 0, 0, 0, 0,
  543. KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
  544. KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
  545. KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
  546. KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
  547. KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
  548. CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
  549. CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
  550. CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
  551. KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
  552. CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
  553. CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
  554. CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
  555. };
  556. #endif
  557. void send_string(const char *str) {
  558. while (1) {
  559. uint8_t keycode;
  560. uint8_t ascii_code = pgm_read_byte(str);
  561. if (!ascii_code) break;
  562. keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
  563. if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
  564. register_code(KC_LSFT);
  565. register_code(keycode);
  566. unregister_code(keycode);
  567. unregister_code(KC_LSFT);
  568. }
  569. else {
  570. register_code(keycode);
  571. unregister_code(keycode);
  572. }
  573. ++str;
  574. }
  575. }
  576. void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  577. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  578. layer_on(layer3);
  579. } else {
  580. layer_off(layer3);
  581. }
  582. }
  583. void matrix_init_quantum() {
  584. matrix_init_kb();
  585. }
  586. void matrix_scan_quantum() {
  587. #ifdef AUDIO_ENABLE
  588. if (music_sequence_playing) {
  589. if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
  590. music_sequence_timer = timer_read();
  591. stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
  592. play_note(music_sequence[music_sequence_position], 0xF);
  593. music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
  594. }
  595. }
  596. #endif
  597. matrix_scan_kb();
  598. }
  599. #ifdef AUDIO_ENABLE
  600. bool is_music_on(void) {
  601. return (music_activated != 0);
  602. }
  603. void music_toggle(void) {
  604. if (!music_activated) {
  605. music_on();
  606. } else {
  607. music_off();
  608. }
  609. }
  610. void music_on(void) {
  611. music_activated = 1;
  612. music_on_user();
  613. }
  614. void music_off(void) {
  615. music_activated = 0;
  616. stop_all_notes();
  617. }
  618. #endif
  619. //------------------------------------------------------------------------------
  620. // Override these functions in your keymap file to play different tunes on
  621. // different events such as startup and bootloader jump
  622. __attribute__ ((weak))
  623. void startup_user() {}
  624. __attribute__ ((weak))
  625. void shutdown_user() {}
  626. __attribute__ ((weak))
  627. void music_on_user() {}
  628. __attribute__ ((weak))
  629. void audio_on_user() {}
  630. __attribute__ ((weak))
  631. void music_scale_user() {}
  632. //------------------------------------------------------------------------------