summaryrefslogtreecommitdiff
path: root/common/keyboard_8042_sharedlib.c
blob: 0ea4dca79289fb7040da9019a0a38d996ca8a5a5 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* Copyright 2015 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.
 *
 * Objects which can be shared between RO and RW for 8042 keyboard protocol.
 */

#include "button.h"
#include "keyboard_8042_sharedlib.h"
#include "keyboard_config.h"
#include "keyboard_protocol.h"
#include "libsharedobjs.h"
#include "util.h"

/* The standard Chrome OS keyboard matrix table in scan code set 2. */
#ifndef CONFIG_KEYBOARD_SCANCODE_MUTABLE
SHAREDLIB(const
#endif
uint16_t scancode_set2[KEYBOARD_ROWS][KEYBOARD_COLS] = {
	{0x0000, 0xe01f, 0x0005, 0x0032, 0x0009, 0x0051, 0x0031, 0x0000, 0x0055,
	 0x0000, 0xe011, 0x0000, 0x0000},
	{0x0000, 0x0076, 0x000c, 0x0034, 0x0083, 0x0000, 0x0033, 0x0000, 0x0052,
	 0x0001, 0x0000, 0x0066, 0x0064},
	{0x0014, 0x000d, 0x0004, 0x002c, 0x000b, 0x005b, 0x0035, 0x0061, 0x0054,
	 0x000a, 0x006a, 0x0000, 0x0000},
	{0xe01f, 0x000e, 0x0006, 0x002e, 0x0003, 0x0000, 0x0036, 0x0000, 0x004e,
	 0x002f, 0x0000, 0x005d, 0x0067},
	{0xe014, 0x001c, 0x0023, 0x002b, 0x001b, 0x0042, 0x003b, 0x0000, 0x004c,
	 0x004b, 0x005d, 0x005a, 0x0000},
	{0xe007, 0x001a, 0x0021, 0x002a, 0x0022, 0x0041, 0x003a, 0x0012, 0x004a,
	 0x0049, 0x0000, 0x0029, 0x0000},
	{0x0000, 0x0016, 0x0026, 0x0025, 0x001e, 0x003e, 0x003d, 0x0000, 0x0045,
	 0x0046, 0x0011, 0xe072, 0xe074},
	{0x0000, 0x0015, 0x0024, 0x002d, 0x001d, 0x0043, 0x003c, 0x0059, 0x004d,
	 0x0044, 0x0000, 0xe075, 0xe06b},
}
#ifndef CONFIG_KEYBOARD_SCANCODE_MUTABLE
)
#endif
;

/*
 * The translation table from scan code set 2 to set 1.
 * Ref: http://kbd-project.org/docs/scancodes/scancodes-10.html#ss10.3
 * To reduce space, we only keep the translation for 0~127,
 * so a real translation need to do 0x83=>0x41 explicitly (
 * see scancode_translate_set2_to_1 below).
 */
SHAREDLIB(const uint8_t scancode_translate_table[128] = {
	0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58,
	0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59,
	0x65, 0x38, 0x2a, 0x70, 0x1d, 0x10, 0x02, 0x5a,
	0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11, 0x03, 0x5b,
	0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c,
	0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d,
	0x69, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e,
	0x6a, 0x72, 0x32, 0x24, 0x16, 0x08, 0x09, 0x5f,
	0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b, 0x0a, 0x60,
	0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61,
	0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e,
	0x3a, 0x36, 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76,
	0x55, 0x56, 0x77, 0x78, 0x79, 0x7a, 0x0e, 0x7b,
	0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e, 0x7f, 0x6f,
	0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45,
	0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54,
});

uint8_t scancode_translate_set2_to_1(uint8_t code)
{
	if (code & 0x80) {
		if (code == 0x83)
			return 0x41;
		return code;
	}
	return scancode_translate_table[code];
}

/*
 * Button scancodes in code set 2.
 * Must be in the same order as defined in keyboard_button_type.
 */
SHAREDLIB(const struct button_8042_t buttons_8042[] = {
	{0xe037, 0}, /* Power */
	{0xe021, 1}, /* Volume Down */
	{0xe032, 1}, /* Volume Up */
	{0x0016, 1}, /* 1 */
	{0x001e, 1}, /* 2 */
	{0x0026, 1}, /* 3 */
	{0x0025, 1}, /* 4 */
	{0x002e, 1}, /* 5 */
	{0x0036, 1}, /* 6 */
	{0x003d, 1}, /* 7 */
	{0x003e, 1}, /* 8 */
});
BUILD_ASSERT(ARRAY_SIZE(buttons_8042) == KEYBOARD_BUTTON_COUNT);