summaryrefslogtreecommitdiff
path: root/common/keyboard_vivaldi.c
blob: 4f59f5495ba9336f5e1091aac599b3a286a028e6 (plain)
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
/* Copyright 2020 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Vivali Keyboard code for Chrome EC */

#include "keyboard_8042_sharedlib.h"
#include "keyboard_scan.h"
#include "keyboard_vivaldi.h"

/*
 * Row Column info for Top row keys T1 - T15
 * Ref: https://drive.google.com/corp/drive/folders/17UtVQ-AixnlQuicRPTp8t46HE-sT522E
 */
static const struct key {
	uint8_t row;
	uint8_t col;
} vivaldi[MAX_VIVALDI_KEYS] = {
	[T1] = {.row = 0, .col = 2},
	[T2] = {.row = 3, .col = 2},
	[T3] = {.row = 2, .col = 2},
	[T4] = {.row = 1, .col = 2},
	[T5] = {.row = 3, .col = 4},
	[T6] = {.row = 2, .col = 4},
	[T7] = {.row = 1, .col = 4},
	[T8] = {.row = 2, .col = 9},
	[T9] = {.row = 1, .col = 9},
	[T10] = {.row = 0, .col = 4},
	[T11] = {.row = 0, .col = 1},
	[T12] = {.row = 1, .col = 5},
	[T13] = {.row = 3, .col = 5},
	[T14] = {.row = 0, .col = 9},
	[T15] = {.row = 0, .col = 11},
};

void vivaldi_init(const struct vivaldi_config *keybd)
{
	uint8_t row, col, *mask;
	int key;

	cprints(CC_KEYBOARD, "VIVALDI: Num top row keys = %u\n",
		keybd->num_top_row_keys);

	if (keybd->num_top_row_keys > MAX_VIVALDI_KEYS ||
	    keybd->num_top_row_keys < 10)
		cprints(CC_KEYBOARD,
			"BAD VIVALDI CONFIG! Some keys may not work\n");

	for (key = T1; key < MAX_VIVALDI_KEYS; key++) {

		row = vivaldi[key].row;
		col = vivaldi[key].col;
		mask = keyscan_config.actual_key_mask + col;

		if (key < keybd->num_top_row_keys && keybd->scancodes[key]) {

			/* Enable the mask */
			*mask |= (1 << row);

			/* Populate the scancode */
			scancode_set2[col][row] = keybd->scancodes[key];
		} else {
			/* Disable the mask */
			*mask &= ~(1 << row);
		}
	}
}