]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/mitosis/keymaps/datagrok/keymap.c
mitosis:datagrok layout and readme improvements (#3400)
[qmk_firmware.git] / keyboards / mitosis / keymaps / datagrok / keymap.c
1 #include QMK_KEYBOARD_H
2 #ifdef AUDIO_ENABLE
3 #include "audio.h"
4 #endif
5
6 enum mitosis_layers
7 {
8     _xQ, // qwerty
9     _xW, // workman
10     _xS, // symbols
11     _xN, // numbers
12     _xF  // functions
13 };
14
15 // Fillers to make layering more clear
16 #define _______ KC_TRNS // Transparent
17
18 // I don't use Japanese myself, but I've placed henkan 変換 and muhenkan 無変換
19 // in my layout to act as left and right HYPER
20
21 // Momentary tri-state layers. Mitosis default keymap does this too but employs
22 // new keymappings and a bunch of conditional code. This simpler keymap
23 // accomplishes it but with a small quirk: triggering both layers then releasing
24 // one out-of-order will leave the tri-state triggered until the other is
25 // released. Which doesn't bother me.
26
27 // The weird /*,*/ comments are a hack to get slightly better automatic
28 // tabulation in my editor.
29
30 // We use Space Cadet KC_RSPC to get _ on right shift. See config.h for details.
31
32 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
33   [_xQ] = LAYOUT(
34       KC_Q, KC_W,       KC_E,    KC_R,    KC_T,    KC_Y,    KC_U,    KC_I,    KC_O,     KC_P,
35       KC_A, KC_S,       KC_D,    KC_F,    KC_G,    KC_H,    KC_J,    KC_K,    KC_L,     KC_SCLN,
36       KC_Z, KC_X,       KC_C,    KC_V,    KC_B,    KC_N,    KC_M,    KC_COMM, KC_DOT,   KC_QUOT,
37       /*,   */ KC_LGUI, KC_LCTL, MO(_xS), KC_TAB,  KC_SPC,  MO(_xS), KC_RCTL, KC_RGUI,
38       /*,   */ KC_HENK, KC_LALT, MO(_xN), KC_LSFT, KC_RSPC, MO(_xN), KC_RALT, KC_MHEN),
39   [_xW] = LAYOUT(
40       KC_Q, KC_D,       KC_R,    KC_W,    KC_B,    KC_J,    KC_F,    KC_U,    KC_P,     KC_SCLN,
41       KC_A, KC_S,       KC_H,    KC_T,    KC_G,    KC_Y,    KC_N,    KC_E,    KC_O,     KC_I,
42       KC_Z, KC_X,       KC_M,    KC_C,    KC_V,    KC_K,    KC_L,    KC_COMM, KC_DOT,   KC_QUOT,
43       /*,   */ _______, _______, _______, _______, _______, _______, _______, _______,
44       /*,   */ _______, _______, _______, _______, _______, _______, _______, _______),
45   [_xS] = LAYOUT(
46       KC_ESC,  KC_GRV ,    KC_UP,   KC_EQL , KC_TILD, KC_PLUS, KC_CIRC, KC_AMPR, KC_PERC,  KC_MINS,
47       KC_BSPC, KC_LEFT,    KC_DOWN, KC_RGHT, _______, KC_PIPE, KC_AT,   KC_DLR,  KC_HASH,  KC_ENT,
48       KC_BSLS, KC_LABK,    KC_LCBR, KC_LPRN, KC_LBRC, KC_RBRC, KC_RCBR, KC_RPRN, KC_RABK,  KC_SLSH,
49       /*,      */ _______, _______, _______, _______, _______, _______, _______, _______,
50       /*,      */ _______, _______, MO(_xF), _______, _______, MO(_xF), _______, _______),
51   [_xN] = LAYOUT(
52       _______, KC_F7,      KC_F8,   KC_F9,   KC_F10,  KC_PPLS, KC_7,    KC_8,    KC_9,     KC_PMNS,
53       _______, KC_F4,      KC_F5,   KC_F6,   KC_F11,  KC_NLCK, KC_4,    KC_5,    KC_6,     KC_PENT,
54       _______, KC_F1,      KC_F2,   KC_F3,   KC_F12,  KC_PAST, KC_1,    KC_2,    KC_3,     KC_PSLS,
55       /*,      */ _______, _______, MO(_xF), _______, _______, MO(_xF), KC_0,    KC_PDOT,
56       /*,      */ _______, _______, _______, _______, _______, _______, _______, _______),
57   [_xF] = LAYOUT(
58       RESET,   KC_INS,     KC_PGUP, KC_DEL,  KC_VOLU, KC_PPLS, KC_P7,   KC_P8,   KC_P9,    KC_PMNS,
59       CK_TOGG, KC_HOME,    KC_PGDN, KC_END,  KC_VOLD, KC_NLCK, KC_P4,   KC_P5,   KC_P6,    KC_PENT,
60       TG(_xW), KC_MPRV,    KC_MPLY, KC_MNXT, KC_MUTE, KC_PAST, KC_P1,   KC_P2,   KC_P3,    KC_PSLS,
61       /*,      */ CK_UP,   MU_TOG,  _______, _______, _______, _______, KC_P0,   KC_PDOT,
62       /*,      */ CK_DOWN, MU_MOD,  _______, _______, _______, KC_PSCR, KC_SLCK, KC_PAUS),
63 };
64
65 // This is a hack to place <question mark> on <shift-comma> and <exclaimation
66 // mark> on <shift-period>, when using an operating system configured for a
67 // US/qwerty layout.
68 bool comm_shifted = false;
69 bool ques_shifted = false;
70 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
71   uint8_t shifted;
72   uint16_t s_keycode;
73   bool *k_shifted;
74
75   switch (keycode) {
76     case KC_COMM:
77       s_keycode = KC_SLSH;
78       k_shifted = &comm_shifted;
79       break;
80     case KC_DOT:
81       s_keycode = KC_1;
82       k_shifted = &ques_shifted;
83       break;
84     default:
85       return true;
86   }
87
88   shifted = get_mods() & (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT));
89
90   // Keydown. If shift is currently pressed, register its alternate keycode.
91   if (record->event.pressed && shifted) {
92     *k_shifted = true;
93     register_code(s_keycode);
94     return false;
95     // Keyup. If shift was pressed back when the key was pressed, unregister
96     // its alternate keycode.
97   } else if (!(record->event.pressed) && *k_shifted) {
98     *k_shifted = false;
99     unregister_code(s_keycode);
100     return false;
101     // Otherwise, behave as normal.
102   } else {
103     return true;
104   }
105 }
106
107 #ifdef AUDIO_ENABLE
108 float tone_qwerty[][2]         = SONG(QWERTY_SOUND);
109 float tone_dyn_macro_rec[][2]  = SONG(DVORAK_SOUND);
110 float tone_dyn_macro_play[][2] = SONG(COLEMAK_SOUND);
111 float tone_fnpc[][2]           = SONG(PLOVER_SOUND);
112 float tone_fnmac[][2]          = SONG(PLOVER_GOODBYE_SOUND);
113
114 void startup_user()
115 {
116   float tone_startup[][2]        = SONG(STARTUP_SOUND);
117   _delay_ms(20); // gets rid of tick
118   PLAY_SONG(tone_startup);
119 }
120
121 void shutdown_user()
122 {
123   float tone_goodbye[][2]        = SONG(GOODBYE_SOUND);
124   PLAY_SONG(tone_goodbye);
125   _delay_ms(150);
126   stop_all_notes();
127 }
128
129 void music_on_user(void)
130 {
131   music_scale_user();
132 }
133
134 void music_scale_user(void)
135 {
136   float music_scale[][2]         = SONG(MUSIC_SCALE_SOUND);
137   PLAY_SONG(music_scale);
138 }
139
140 #endif
141
142 // Set the bits of A selected by MASK to the corresponding bits of B
143 #define setbits(A, B, MASK) A = (A & (B | ~MASK)) | (B & MASK)
144 void matrix_scan_user(void) {
145   //
146   // Bit #            7     6     5     4     3     2     1     0
147   // layer_state: [     |     |     | _xF | _xN | _xS | _xQ | _xW ]
148   // usb_led      [     |     |     |kana |cmps |scrl |caps | num ]
149   // PORTB:       [  NC |  10 |   9 |   8 |  14 |  16 |  15 |rxled]
150   // PORTC:       [  NC |   5 |     |     |     |     |     |     ]
151   // PORTD:       [   6 |  NC |txled|   4 | tx* | rx* | grn | p29 ]
152   // PORTE:       [     |   7 |     |     |     |     |     |     ]
153   // PORTF:       [  a0 |  a1 | red | blu |     |     |  NC |  NC ]
154   //
155   // PD0 is connected to the pairing switch and p29 on the wireless module.
156   // PF0,PF1,PB7,PC7,PD6 are not broken out by the pro micro board. I don't understand why.
157   // PB1-PB6,PD4,PD5,PD6,PF6,PF7 are not connected to the Mitosis receiver
158   // board. Each may be connected to an LED by way of a resistor (4.7k to
159   // match the others) for a total of 14 additional indicators.
160
161   // A simple (but technically inaccurate) model of the momentary layer state:
162   // Fn1 key makes _xS active; indicator = red
163   // Fn2 key makes _xN active; indicator = blue
164   // Both keys make _xF active; indicator = purple
165   // Toggling QWERTY mode makes indicator include green, so (red/blue/purple becomes yellow/cyan/white)
166
167   // negated because for ports 0=LED on.
168   uint32_t portf_bits = ~(layer_state|layer_state<<1|(layer_state&0b100)<<3);
169   setbits(PORTF, portf_bits, 0b00110000);
170   setbits(PORTD, ~layer_state, 0b00000010);
171 }
172
173 // vim: set sw=2 et: