Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unimap_hasu.c 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. Copyright 2016 Jun Wako <[email protected]>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "unimap_trans.h"
  15. /* id for user defined functions */
  16. enum function_id {
  17. LSHIFT_LPAREN,
  18. };
  19. enum macro_id {
  20. HELLO,
  21. VOLUP,
  22. ALT_TAB,
  23. };
  24. #define AC_L1 ACTION_LAYER_MOMENTARY(1)
  25. #define AC_SLS2 ACTION_LAYER_TAP_KEY(2, KC_SLSH)
  26. #define AC_SCL3 ACTION_LAYER_TAP_KEY(3, KC_SCLN)
  27. #define AC_SPC4 ACTION_LAYER_TAP_KEY(4, KC_SPC)
  28. #define AC_APSW ACTION_MACRO(ALT_TAB)
  29. #define AC_BACK ACTION_MODS_KEY(MOD_LALT, KC_LEFT)
  30. #define AC_FRWD ACTION_MODS_KEY(MOD_LALT, KC_RIGHT)
  31. #define AC_ENT_ ACTION_MODS_TAP_KEY(MOD_RCTL, KC_ENT)
  32. // Function: LShift with tap '('
  33. #define AC_LPRN ACTION_FUNCTION_TAP(LSHIFT_LPAREN)
  34. // Macro: say hello
  35. #define AC_HELO ACTION_MACRO(HELLO)
  36. #ifdef KEYMAP_SECTION_ENABLE
  37. const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] __attribute__ ((section (".keymap.keymaps"))) = {
  38. #else
  39. const action_t actionmaps[][UNIMAP_ROWS][UNIMAP_COLS] PROGMEM = {
  40. #endif
  41. [0] = UNIMAP_HHKB(
  42. ESC, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSLS,GRV,
  43. TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC, BSPC,
  44. LCTL,A, S, D, F, G, H, J, K, L, SCLN,QUOT, ENT_,
  45. LPRN, Z, X, C, V, B, N, M, COMM,DOT, SLS2, RSFT,L1,
  46. LGUI,LALT, SPC4, RALT,RGUI),
  47. [1] = UNIMAP_HHKB(
  48. PWR, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL,
  49. CAPS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,TRNS,PSCR,SLCK,PAUS,UP, TRNS, TRNS,
  50. TRNS,VOLD,VOLU,MUTE,TRNS,TRNS,PAST,PSLS,HOME,PGUP,LEFT,RGHT, PENT,
  51. TRNS, TRNS,TRNS,TRNS,TRNS,TRNS,PPLS,PMNS,END, PGDN,DOWN, TRNS,TRNS,
  52. TRNS,TRNS, TRNS, TRNS,TRNS),
  53. [2] = UNIMAP_HHKB(
  54. GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL,
  55. TAB, HOME,PGDN,UP, PGUP,END, HOME,PGDN,PGUP,END, NO, NO, NO, BSPC,
  56. LCTL,NO, LEFT,DOWN,RGHT,NO, LEFT,DOWN,UP, RGHT,NO, NO, ENT,
  57. LSFT, NO, NO, NO, NO, NO, HOME,PGDN,PGUP,END, TRNS, RSFT,TRNS,
  58. LGUI,LALT, SPC, RALT,RGUI),
  59. [3] = UNIMAP_HHKB(
  60. GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL,
  61. APSW,NO, NO, NO, NO, NO, WH_L,WH_D,MS_U,WH_U,WH_R,BACK,FRWD, APSW,
  62. LCTL,ACL0,ACL1,ACL2,ACL2,NO, NO, MS_L,MS_D,MS_R,TRNS,NO, ENT,
  63. LSFT, NO, NO, NO, NO, BTN3,BTN2,BTN1,BACK,FRWD,NO, RSFT,TRNS,
  64. LGUI,LALT, BTN1, TRNS,TRNS),
  65. [4] = UNIMAP_HHKB(
  66. GRV, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, INS, DEL,
  67. APSW,NO, NO, NO, NO, NO, WH_L,WH_D,MS_U,WH_U,WH_R,BTN4,BTN5, APSW,
  68. LCTL,VOLD,VOLU,MUTE,NO, NO, NO, MS_L,MS_D,MS_R,BTN1,NO, ENT,
  69. LSFT, NO, NO, NO, NO, BTN3,BTN2,BTN1,BACK,FRWD,NO, RSFT,TRNS,
  70. TRNS,TRNS, TRNS, TRNS,TRNS),
  71. };
  72. /*
  73. * Macro definition
  74. */
  75. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  76. {
  77. switch (id) {
  78. case HELLO:
  79. return (record->event.pressed ?
  80. MACRO( I(0), T(H), T(E), T(L), T(L), W(255), T(O), END ) :
  81. MACRO_NONE );
  82. case VOLUP:
  83. return (record->event.pressed ?
  84. MACRO( D(VOLU), U(VOLU), END ) :
  85. MACRO_NONE );
  86. case ALT_TAB:
  87. return (record->event.pressed ?
  88. MACRO( D(LALT), D(TAB), END ) :
  89. MACRO( U(TAB), END ));
  90. }
  91. return MACRO_NONE;
  92. }
  93. /*
  94. * user defined action function
  95. */
  96. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
  97. {
  98. if (record->event.pressed) dprint("P"); else dprint("R");
  99. dprintf("%d", record->tap.count);
  100. if (record->tap.interrupted) dprint("i");
  101. dprint("\n");
  102. switch (id) {
  103. case LSHIFT_LPAREN:
  104. // Shift parentheses example: LShft + tap '('
  105. // http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#shift-parentheses
  106. // http://geekhack.org/index.php?topic=41989.msg1304899#msg1304899
  107. if (record->event.pressed) {
  108. if (record->tap.count > 0 && !record->tap.interrupted) {
  109. if (record->tap.interrupted) {
  110. dprint("tap interrupted\n");
  111. register_mods(MOD_BIT(KC_LSHIFT));
  112. }
  113. } else {
  114. register_mods(MOD_BIT(KC_LSHIFT));
  115. }
  116. } else {
  117. if (record->tap.count > 0 && !(record->tap.interrupted)) {
  118. add_weak_mods(MOD_BIT(KC_LSHIFT));
  119. send_keyboard_report();
  120. register_code(KC_9);
  121. unregister_code(KC_9);
  122. del_weak_mods(MOD_BIT(KC_LSHIFT));
  123. send_keyboard_report();
  124. record->tap.count = 0; // ad hoc: cancel tap
  125. } else {
  126. unregister_mods(MOD_BIT(KC_LSHIFT));
  127. }
  128. }
  129. break;
  130. }
  131. }