summaryrefslogtreecommitdiffhomepage
path: root/src/srp/fw-ec/hybrid.diff.html
blob: a37d3b5fb48b2d267e4777436eba807d9a29cfc5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<code><span class="diff-meta">diff --git a/board/hx20/keyboard_customization.c b/board/hx20/keyboard_customization.c</span></code>
<code><span class="diff-meta">index 9a5050a0f..2756f17ce 100644</span></code>
<code><span class="diff-meta">--- a/board/hx20/keyboard_customization.c</span></code>
<code><span class="diff-meta">+++ b/board/hx20/keyboard_customization.c</span></code>
<code><span class="diff-loc">@@ -22,12 +22,15 @@</span></code>
<code> #define CPRINTS(format, args...) cprints(CC_KEYBOARD, format, ## args)</code>
<code> #define CPRINTF(format, args...) cprintf(CC_KEYBOARD, format, ## args)</code>
<code></code>
<code><span class="diff-ins">+/* The scancode for the caps-lock key, which is now a hybrid key */</span></code>
<code><span class="diff-ins">+#define SCANCODE_CTRL_ESC 0x0101</span></code>
<code><span class="diff-ins">+</span></code>
<code> uint16_t scancode_set2[KEYBOARD_COLS_MAX][KEYBOARD_ROWS] = {</code>
<code> 		{0x0021, 0x007B, 0x0079, 0x0072, 0x007A, 0x0071, 0x0069, 0xe04A},</code>
<code> 		{0xe071, 0xe070, 0x007D, 0xe01f, 0x006c, 0xe06c, 0xe07d, 0x0077},</code>
<code> 		{0x0015, 0x0070, 0x00ff, 0x000D, 0x000E, 0x0016, 0x0067, 0x001c},</code>
<code> 		{0xe011, 0x0011, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000},</code>
<code><span class="diff-del">-		{0xe05a, 0x0029, 0x0024, 0x000c, 0x0058, 0x0026, 0x0004, 0xe07a},</span></code>
<code><span class="diff-ins">+		{0xe05a, 0x0029, 0x0024, 0x000c, 0x0101, 0x0026, 0x0004, 0xe07a},</span></code>
<code> 		{0x0022, 0x001a, 0x0006, 0x0005, 0x001b, 0x001e, 0x001d, 0x0076},</code>
<code> 		{0x002A, 0x0032, 0x0034, 0x002c, 0x002e, 0x0025, 0x002d, 0x002b},</code>
<code> 		{0x003a, 0x0031, 0x0033, 0x0035, 0x0036, 0x003d, 0x003c, 0x003b},</code>
<code><span class="diff-loc">@@ -497,6 +500,55 @@ int functional_hotkey(uint16_t *key_code, int8_t pressed)</span></code>
<code> 	return EC_SUCCESS;</code>
<code> }</code>
<code></code>
<code><span class="diff-ins">+int try_ctrl_esc(uint16_t *key_code, int8_t pressed) {</span></code>
<code><span class="diff-ins">+	static enum {</span></code>
<code><span class="diff-ins">+		NONE,</span></code>
<code><span class="diff-ins">+		HELD,</span></code>
<code><span class="diff-ins">+		CTRL</span></code>
<code><span class="diff-ins">+	} ctrl_esc_state;</span></code>
<code><span class="diff-ins">+</span></code>
<code><span class="diff-ins">+	if (*key_code == SCANCODE_CTRL_ESC) {</span></code>
<code><span class="diff-ins">+		/* If we pressed the caps key, enter the HELD state.  Otherwise,</span></code>
<code><span class="diff-ins">+		 * we are either releasing from the HELD state or the CTRL</span></code>
<code><span class="diff-ins">+		 * state.  In both cases we should reset the state to NONE, but</span></code>
<code><span class="diff-ins">+		 * when releasing from the HELD state we want to send an ESC and</span></code>
<code><span class="diff-ins">+		 * when releasing from the CTRL state we want to end the CTRL.</span></code>
<code><span class="diff-ins">+		 *</span></code>
<code><span class="diff-ins">+		 * Also important to note is that even before we know if we’re</span></code>
<code><span class="diff-ins">+		 * going to be acting as ESC or CTRL, we need to send a press-</span></code>
<code><span class="diff-ins">+		 * event of the CTRL key because you can chord CTRL with mouse-</span></code>
<code><span class="diff-ins">+		 * clicks too, not just other keys.</span></code>
<code><span class="diff-ins">+		 */</span></code>
<code><span class="diff-ins">+		if (pressed) {</span></code>
<code><span class="diff-ins">+			ctrl_esc_state = HELD;</span></code>
<code><span class="diff-ins">+			simulate_keyboard(SCANCODE_LEFT_CTRL, 1);</span></code>
<code><span class="diff-ins">+		} else if (ctrl_esc_state == HELD) {</span></code>
<code><span class="diff-ins">+			ctrl_esc_state = NONE;</span></code>
<code><span class="diff-ins">+			simulate_keyboard(SCANCODE_LEFT_CTRL, 0);</span></code>
<code><span class="diff-ins">+			simulate_keyboard(SCANCODE_ESC, 1);</span></code>
<code><span class="diff-ins">+			simulate_keyboard(SCANCODE_ESC, 0);</span></code>
<code><span class="diff-ins">+		} else if (ctrl_esc_state == CTRL) {</span></code>
<code><span class="diff-ins">+			ctrl_esc_state = NONE;</span></code>
<code><span class="diff-ins">+			simulate_keyboard(SCANCODE_LEFT_CTRL, 0);</span></code>
<code><span class="diff-ins">+		}</span></code>
<code><span class="diff-ins">+</span></code>
<code><span class="diff-ins">+		return EC_ERROR_UNIMPLEMENTED;</span></code>
<code><span class="diff-ins">+	}</span></code>
<code><span class="diff-ins">+</span></code>
<code><span class="diff-ins">+	/* If we get here then we are dealing with a key that isn’t the caps</span></code>
<code><span class="diff-ins">+	 * key.  In that case we need to handle all 3 states.  If the state is</span></code>
<code><span class="diff-ins">+	 * NONE then we can just exit from this function.  If it’s HELD and we</span></code>
<code><span class="diff-ins">+	 * are pressing a key, then that’s a key-chord and we need to start a</span></code>
<code><span class="diff-ins">+	 * CTRL.  Finally, if we are in the CTRL state, there is nothing to do.</span></code>
<code><span class="diff-ins">+	 */</span></code>
<code><span class="diff-ins">+	if (ctrl_esc_state == HELD && pressed) {</span></code>
<code><span class="diff-ins">+		ctrl_esc_state = CTRL;</span></code>
<code><span class="diff-ins">+		simulate_keyboard(SCANCODE_LEFT_CTRL, 1);</span></code>
<code><span class="diff-ins">+	}</span></code>
<code><span class="diff-ins">+</span></code>
<code><span class="diff-ins">+	return EC_SUCCESS;</span></code>
<code><span class="diff-ins">+}</span></code>
<code><span class="diff-ins">+</span></code>
<code> enum ec_error_list keyboard_scancode_callback(uint16_t *make_code,</code>
<code> 					      int8_t pressed)</code>
<code> {</code>
<code><span class="diff-loc">@@ -521,6 +573,10 @@ enum ec_error_list keyboard_scancode_callback(uint16_t *make_code,</span></code>
<code> 	if (!pos_get_state())</code>
<code> 		return EC_SUCCESS;</code>
<code></code>
<code><span class="diff-ins">+	r = try_ctrl_esc(make_code, pressed);</span></code>
<code><span class="diff-ins">+	if (r != EC_SUCCESS)</span></code>
<code><span class="diff-ins">+		return r;</span></code>
<code><span class="diff-ins">+</span></code>
<code> 	r = hotkey_F1_F12(make_code, Fn_key, pressed);</code>
<code> 	if (r != EC_SUCCESS)</code>
<code> 		return r;</code>