quantum.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  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[3] = {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. return false;
  284. }
  285. if (leading && timer_elapsed(leader_time) < LEADER_TIMEOUT) {
  286. leader_sequence[leader_sequence_size] = keycode;
  287. leader_sequence_size++;
  288. return false;
  289. }
  290. }
  291. #endif
  292. #define DISABLE_CHORDING
  293. #ifndef DISABLE_CHORDING
  294. if (keycode >= QK_CHORDING && keycode <= QK_CHORDING_MAX) {
  295. if (record->event.pressed) {
  296. if (!chording) {
  297. chording = true;
  298. for (uint8_t i = 0; i < CHORDING_MAX; i++)
  299. chord_keys[i] = 0;
  300. chord_key_count = 0;
  301. chord_key_down = 0;
  302. }
  303. chord_keys[chord_key_count] = (keycode & 0xFF);
  304. chord_key_count++;
  305. chord_key_down++;
  306. return false;
  307. } else {
  308. if (chording) {
  309. chord_key_down--;
  310. if (chord_key_down == 0) {
  311. chording = false;
  312. // Chord Dictionary
  313. if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
  314. register_code(KC_A);
  315. unregister_code(KC_A);
  316. return false;
  317. }
  318. for (uint8_t i = 0; i < chord_key_count; i++) {
  319. register_code(chord_keys[i]);
  320. unregister_code(chord_keys[i]);
  321. return false;
  322. }
  323. }
  324. }
  325. }
  326. }
  327. #endif
  328. #ifdef UNICODE_ENABLE
  329. if (keycode > QK_UNICODE && record->event.pressed) {
  330. uint16_t unicode = keycode & 0x7FFF;
  331. switch(input_mode) {
  332. case UC_OSX:
  333. register_code(KC_LALT);
  334. break;
  335. case UC_LNX:
  336. register_code(KC_LCTL);
  337. register_code(KC_LSFT);
  338. register_code(KC_U);
  339. unregister_code(KC_U);
  340. break;
  341. case UC_WIN:
  342. register_code(KC_LALT);
  343. register_code(KC_PPLS);
  344. unregister_code(KC_PPLS);
  345. break;
  346. }
  347. for(int i = 3; i >= 0; i--) {
  348. uint8_t digit = ((unicode >> (i*4)) & 0xF);
  349. register_code(hex_to_keycode(digit));
  350. unregister_code(hex_to_keycode(digit));
  351. }
  352. switch(input_mode) {
  353. case UC_OSX:
  354. case UC_WIN:
  355. unregister_code(KC_LALT);
  356. break;
  357. case UC_LNX:
  358. unregister_code(KC_LCTL);
  359. unregister_code(KC_LSFT);
  360. break;
  361. }
  362. }
  363. #endif
  364. // Shift / paren setup
  365. switch(keycode) {
  366. case RESET:
  367. if (record->event.pressed) {
  368. clear_keyboard();
  369. #ifdef AUDIO_ENABLE
  370. stop_all_notes();
  371. shutdown_user();
  372. #endif
  373. _delay_ms(250);
  374. #ifdef ATREUS_ASTAR
  375. *(uint16_t *)0x0800 = 0x7777; // these two are a-star-specific
  376. #endif
  377. bootloader_jump();
  378. return false;
  379. }
  380. break;
  381. case DEBUG:
  382. if (record->event.pressed) {
  383. print("\nDEBUG: enabled.\n");
  384. debug_enable = true;
  385. return false;
  386. }
  387. break;
  388. case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_UNSWAP_ALT_GUI:
  389. if (record->event.pressed) {
  390. // MAGIC actions (BOOTMAGIC without the boot)
  391. if (!eeconfig_is_enabled()) {
  392. eeconfig_init();
  393. }
  394. /* keymap config */
  395. keymap_config.raw = eeconfig_read_keymap();
  396. if (keycode == MAGIC_SWAP_CONTROL_CAPSLOCK) {
  397. keymap_config.swap_control_capslock = 1;
  398. } else if (keycode == MAGIC_CAPSLOCK_TO_CONTROL) {
  399. keymap_config.capslock_to_control = 1;
  400. } else if (keycode == MAGIC_SWAP_LALT_LGUI) {
  401. keymap_config.swap_lalt_lgui = 1;
  402. } else if (keycode == MAGIC_SWAP_RALT_RGUI) {
  403. keymap_config.swap_ralt_rgui = 1;
  404. } else if (keycode == MAGIC_NO_GUI) {
  405. keymap_config.no_gui = 1;
  406. } else if (keycode == MAGIC_SWAP_GRAVE_ESC) {
  407. keymap_config.swap_grave_esc = 1;
  408. } else if (keycode == MAGIC_SWAP_BACKSLASH_BACKSPACE) {
  409. keymap_config.swap_backslash_backspace = 1;
  410. } else if (keycode == MAGIC_HOST_NKRO) {
  411. keymap_config.nkro = 1;
  412. } else if (keycode == MAGIC_SWAP_ALT_GUI) {
  413. keymap_config.swap_lalt_lgui = 1;
  414. keymap_config.swap_ralt_rgui = 1;
  415. }
  416. /* UNs */
  417. else if (keycode == MAGIC_UNSWAP_CONTROL_CAPSLOCK) {
  418. keymap_config.swap_control_capslock = 0;
  419. } else if (keycode == MAGIC_UNCAPSLOCK_TO_CONTROL) {
  420. keymap_config.capslock_to_control = 0;
  421. } else if (keycode == MAGIC_UNSWAP_LALT_LGUI) {
  422. keymap_config.swap_lalt_lgui = 0;
  423. } else if (keycode == MAGIC_UNSWAP_RALT_RGUI) {
  424. keymap_config.swap_ralt_rgui = 0;
  425. } else if (keycode == MAGIC_UNNO_GUI) {
  426. keymap_config.no_gui = 0;
  427. } else if (keycode == MAGIC_UNSWAP_GRAVE_ESC) {
  428. keymap_config.swap_grave_esc = 0;
  429. } else if (keycode == MAGIC_UNSWAP_BACKSLASH_BACKSPACE) {
  430. keymap_config.swap_backslash_backspace = 0;
  431. } else if (keycode == MAGIC_UNHOST_NKRO) {
  432. keymap_config.nkro = 0;
  433. } else if (keycode == MAGIC_UNSWAP_ALT_GUI) {
  434. keymap_config.swap_lalt_lgui = 0;
  435. keymap_config.swap_ralt_rgui = 0;
  436. }
  437. eeconfig_update_keymap(keymap_config.raw);
  438. return false;
  439. }
  440. break;
  441. case KC_LSPO: {
  442. if (record->event.pressed) {
  443. shift_interrupted[0] = false;
  444. register_mods(MOD_BIT(KC_LSFT));
  445. }
  446. else {
  447. if (!shift_interrupted[0]) {
  448. register_code(LSPO_KEY);
  449. unregister_code(LSPO_KEY);
  450. }
  451. unregister_mods(MOD_BIT(KC_LSFT));
  452. }
  453. return false;
  454. break;
  455. }
  456. case KC_RSPC: {
  457. if (record->event.pressed) {
  458. shift_interrupted[1] = false;
  459. register_mods(MOD_BIT(KC_RSFT));
  460. }
  461. else {
  462. if (!shift_interrupted[1]) {
  463. register_code(RSPC_KEY);
  464. unregister_code(RSPC_KEY);
  465. }
  466. unregister_mods(MOD_BIT(KC_RSFT));
  467. }
  468. return false;
  469. break;
  470. }
  471. default: {
  472. shift_interrupted[0] = true;
  473. shift_interrupted[1] = true;
  474. break;
  475. }
  476. }
  477. return process_action_kb(record);
  478. }
  479. const bool ascii_to_qwerty_shift_lut[0x80] PROGMEM = {
  480. 0, 0, 0, 0, 0, 0, 0, 0,
  481. 0, 0, 0, 0, 0, 0, 0, 0,
  482. 0, 0, 0, 0, 0, 0, 0, 0,
  483. 0, 0, 0, 0, 0, 0, 0, 0,
  484. 0, 1, 1, 1, 1, 1, 1, 0,
  485. 1, 1, 1, 1, 0, 0, 0, 0,
  486. 0, 0, 0, 0, 0, 0, 0, 0,
  487. 0, 0, 1, 0, 1, 0, 1, 1,
  488. 1, 1, 1, 1, 1, 1, 1, 1,
  489. 1, 1, 1, 1, 1, 1, 1, 1,
  490. 1, 1, 1, 1, 1, 1, 1, 1,
  491. 1, 1, 1, 0, 0, 0, 1, 1,
  492. 0, 0, 0, 0, 0, 0, 0, 0,
  493. 0, 0, 0, 0, 0, 0, 0, 0,
  494. 0, 0, 0, 0, 0, 0, 0, 0,
  495. 0, 0, 0, 1, 1, 1, 1, 0
  496. };
  497. const uint8_t ascii_to_qwerty_keycode_lut[0x80] PROGMEM = {
  498. 0, 0, 0, 0, 0, 0, 0, 0,
  499. KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
  500. 0, 0, 0, 0, 0, 0, 0, 0,
  501. 0, 0, 0, KC_ESC, 0, 0, 0, 0,
  502. KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
  503. KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
  504. KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
  505. KC_8, KC_9, KC_SCLN, KC_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
  506. KC_2, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  507. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  508. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  509. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
  510. KC_GRV, KC_A, KC_B, KC_C, KC_D, KC_E, KC_F, KC_G,
  511. KC_H, KC_I, KC_J, KC_K, KC_L, KC_M, KC_N, KC_O,
  512. KC_P, KC_Q, KC_R, KC_S, KC_T, KC_U, KC_V, KC_W,
  513. KC_X, KC_Y, KC_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
  514. };
  515. /* for users whose OSes are set to Colemak */
  516. #if 0
  517. #include "keymap_colemak.h"
  518. const bool ascii_to_colemak_shift_lut[0x80] PROGMEM = {
  519. 0, 0, 0, 0, 0, 0, 0, 0,
  520. 0, 0, 0, 0, 0, 0, 0, 0,
  521. 0, 0, 0, 0, 0, 0, 0, 0,
  522. 0, 0, 0, 0, 0, 0, 0, 0,
  523. 0, 1, 1, 1, 1, 1, 1, 0,
  524. 1, 1, 1, 1, 0, 0, 0, 0,
  525. 0, 0, 0, 0, 0, 0, 0, 0,
  526. 0, 0, 1, 0, 1, 0, 1, 1,
  527. 1, 1, 1, 1, 1, 1, 1, 1,
  528. 1, 1, 1, 1, 1, 1, 1, 1,
  529. 1, 1, 1, 1, 1, 1, 1, 1,
  530. 1, 1, 1, 0, 0, 0, 1, 1,
  531. 0, 0, 0, 0, 0, 0, 0, 0,
  532. 0, 0, 0, 0, 0, 0, 0, 0,
  533. 0, 0, 0, 0, 0, 0, 0, 0,
  534. 0, 0, 0, 1, 1, 1, 1, 0
  535. };
  536. const uint8_t ascii_to_colemak_keycode_lut[0x80] PROGMEM = {
  537. 0, 0, 0, 0, 0, 0, 0, 0,
  538. KC_BSPC, KC_TAB, KC_ENT, 0, 0, 0, 0, 0,
  539. 0, 0, 0, 0, 0, 0, 0, 0,
  540. 0, 0, 0, KC_ESC, 0, 0, 0, 0,
  541. KC_SPC, KC_1, KC_QUOT, KC_3, KC_4, KC_5, KC_7, KC_QUOT,
  542. KC_9, KC_0, KC_8, KC_EQL, KC_COMM, KC_MINS, KC_DOT, KC_SLSH,
  543. KC_0, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7,
  544. KC_8, KC_9, CM_SCLN, CM_SCLN, KC_COMM, KC_EQL, KC_DOT, KC_SLSH,
  545. KC_2, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
  546. CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
  547. CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
  548. CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_6, KC_MINS,
  549. KC_GRV, CM_A, CM_B, CM_C, CM_D, CM_E, CM_F, CM_G,
  550. CM_H, CM_I, CM_J, CM_K, CM_L, CM_M, CM_N, CM_O,
  551. CM_P, CM_Q, CM_R, CM_S, CM_T, CM_U, CM_V, CM_W,
  552. CM_X, CM_Y, CM_Z, KC_LBRC, KC_BSLS, KC_RBRC, KC_GRV, KC_DEL
  553. };
  554. #endif
  555. void send_string(const char *str) {
  556. while (1) {
  557. uint8_t keycode;
  558. uint8_t ascii_code = pgm_read_byte(str);
  559. if (!ascii_code) break;
  560. keycode = pgm_read_byte(&ascii_to_qwerty_keycode_lut[ascii_code]);
  561. if (pgm_read_byte(&ascii_to_qwerty_shift_lut[ascii_code])) {
  562. register_code(KC_LSFT);
  563. register_code(keycode);
  564. unregister_code(keycode);
  565. unregister_code(KC_LSFT);
  566. }
  567. else {
  568. register_code(keycode);
  569. unregister_code(keycode);
  570. }
  571. ++str;
  572. }
  573. }
  574. void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
  575. if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
  576. layer_on(layer3);
  577. } else {
  578. layer_off(layer3);
  579. }
  580. }
  581. void matrix_init_quantum() {
  582. matrix_init_kb();
  583. }
  584. void matrix_scan_quantum() {
  585. #ifdef AUDIO_ENABLE
  586. if (music_sequence_playing) {
  587. if ((music_sequence_timer == 0) || (timer_elapsed(music_sequence_timer) > music_sequence_interval)) {
  588. music_sequence_timer = timer_read();
  589. stop_note(music_sequence[(music_sequence_position - 1 < 0)?(music_sequence_position - 1 + music_sequence_count):(music_sequence_position - 1)]);
  590. play_note(music_sequence[music_sequence_position], 0xF);
  591. music_sequence_position = (music_sequence_position + 1) % music_sequence_count;
  592. }
  593. }
  594. #endif
  595. matrix_scan_kb();
  596. }
  597. #ifdef AUDIO_ENABLE
  598. bool is_music_on(void) {
  599. return (music_activated != 0);
  600. }
  601. void music_toggle(void) {
  602. if (!music_activated) {
  603. music_on();
  604. } else {
  605. music_off();
  606. }
  607. }
  608. void music_on(void) {
  609. music_activated = 1;
  610. music_on_user();
  611. }
  612. void music_off(void) {
  613. music_activated = 0;
  614. stop_all_notes();
  615. }
  616. #endif
  617. //------------------------------------------------------------------------------
  618. // Override these functions in your keymap file to play different tunes on
  619. // different events such as startup and bootloader jump
  620. __attribute__ ((weak))
  621. void startup_user() {}
  622. __attribute__ ((weak))
  623. void shutdown_user() {}
  624. __attribute__ ((weak))
  625. void music_on_user() {}
  626. __attribute__ ((weak))
  627. void audio_on_user() {}
  628. __attribute__ ((weak))
  629. void music_scale_user() {}
  630. //------------------------------------------------------------------------------