]>
Commit | Line | Data |
---|---|---|
9bc590e5 SG |
1 | /* |
2 | * Keyboard input helper functions (too small to be called a layer) | |
3 | * | |
4 | * Copyright (c) 2011 The Chromium OS Authors. | |
9bc590e5 | 5 | * |
1a459660 | 6 | * SPDX-License-Identifier: GPL-2.0+ |
9bc590e5 SG |
7 | */ |
8 | ||
9 | #ifndef _INPUT_H | |
10 | #define _INPUT_H | |
11 | ||
12 | enum { | |
13 | INPUT_MAX_MODIFIERS = 4, | |
14 | INPUT_BUFFER_LEN = 16, | |
15 | }; | |
16 | ||
17 | enum { | |
18 | /* Keyboard LEDs */ | |
19 | INPUT_LED_SCROLL = 1 << 0, | |
20 | INPUT_LED_CAPS = 1 << 1, | |
21 | INPUT_LED_NUM = 1 << 2, | |
22 | }; | |
23 | ||
24 | /* | |
25 | * This table translates key codes to ASCII. Most of the entries are ASCII | |
26 | * codes, but entries after KEY_FIRST_MOD indicate that this key is a | |
27 | * modifier key, like shift, ctrl. KEY_FIRST_MOD + MOD_SHIFT is the shift | |
28 | * key, for example. | |
29 | */ | |
30 | struct input_key_xlate { | |
31 | /* keycode of the modifiers which select this table, -1 if none */ | |
32 | int left_keycode; | |
33 | int right_keycode; | |
34 | const uchar *xlate; /* keycode to ASCII table */ | |
35 | int num_entries; /* number of entries in this table */ | |
36 | }; | |
37 | ||
38 | struct input_config { | |
c9cac4cd | 39 | struct udevice *dev; |
9bc590e5 SG |
40 | uchar fifo[INPUT_BUFFER_LEN]; |
41 | int fifo_in, fifo_out; | |
42 | ||
43 | /* Which modifiers are active (1 bit for each MOD_... value) */ | |
44 | uchar modifiers; | |
45 | uchar flags; /* active state keys (FLAGS_...) */ | |
46 | uchar leds; /* active LEDS (INPUT_LED_...) */ | |
47 | uchar num_tables; /* number of modifier tables */ | |
48 | int prev_keycodes[INPUT_BUFFER_LEN]; /* keys held last time */ | |
49 | int num_prev_keycodes; /* number of prev keys */ | |
50 | struct input_key_xlate table[INPUT_MAX_MODIFIERS]; | |
51 | ||
52 | /** | |
53 | * Function the input helper calls to scan the keyboard | |
54 | * | |
55 | * @param config Input state | |
56 | * @return 0 if no keys read, otherwise number of keys read, or 1 if | |
57 | * unknown | |
58 | */ | |
59 | int (*read_keys)(struct input_config *config); | |
60 | unsigned int next_repeat_ms; /* Next time we repeat a key */ | |
61 | unsigned int repeat_delay_ms; /* Time before autorepeat starts */ | |
62 | unsigned int repeat_rate_ms; /* Autorepeat rate in ms */ | |
63 | }; | |
64 | ||
65 | struct stdio_dev; | |
66 | ||
67 | /** | |
68 | * Convert a list of key codes into ASCII and send them | |
69 | * | |
70 | * @param config Input state | |
71 | * @param keycode List of key codes to examine | |
72 | * @param num_keycodes Number of key codes | |
44abe47d HTL |
73 | * @return number of ascii characters sent, or 0 if none, or -1 for an |
74 | * internal error | |
9bc590e5 SG |
75 | */ |
76 | int input_send_keycodes(struct input_config *config, int keycode[], int count); | |
77 | ||
78 | /** | |
79 | * Add a new key translation table to the input | |
80 | * | |
81 | * @param config Input state | |
82 | * @param left_keycode Key to hold to get into this table | |
83 | * @param right_keycode Another key to hold to get into this table | |
84 | * @param xlate Conversion table from key codes to ASCII | |
85 | * @param num_entries Number of entries in xlate table | |
86 | */ | |
87 | int input_add_table(struct input_config *config, int left_keycode, | |
88 | int right_keycode, const uchar *xlate, int num_entries); | |
89 | ||
90 | /** | |
91 | * Test if keys are available to be read | |
92 | * | |
93 | * @param config Input state | |
94 | * @return 0 if no keys available, 1 if keys are available | |
95 | */ | |
96 | int input_tstc(struct input_config *config); | |
97 | ||
98 | /** | |
99 | * Read a key | |
100 | * | |
101 | * TODO: U-Boot wants 0 for no key, but Ctrl-@ is a valid key... | |
102 | * | |
103 | * @param config Input state | |
104 | * @return key, or 0 if no key, or -1 if error | |
105 | */ | |
106 | int input_getc(struct input_config *config); | |
107 | ||
108 | /** | |
109 | * Register a new device with stdio and switch to it if wanted | |
110 | * | |
111 | * @param dev Pointer to device | |
112 | * @return 0 if ok, -1 on error | |
113 | */ | |
114 | int input_stdio_register(struct stdio_dev *dev); | |
115 | ||
1b1d3e64 SG |
116 | /** |
117 | * Set up the keyboard autorepeat delays | |
118 | * | |
119 | * @param repeat_delay_ms Delay before key auto-repeat starts (in ms) | |
120 | * @param repeat_rate_ms Delay between successive key repeats (in ms) | |
121 | */ | |
122 | void input_set_delays(struct input_config *config, int repeat_delay_ms, | |
123 | int repeat_rate_ms); | |
124 | ||
9bc590e5 SG |
125 | /** |
126 | * Set up the input handler with basic key maps. | |
127 | * | |
128 | * @param config Input state | |
129 | * @param leds Initial LED value (INPUT_LED_ mask), 0 suggested | |
9bc590e5 SG |
130 | * @return 0 if ok, -1 on error |
131 | */ | |
1b1d3e64 | 132 | int input_init(struct input_config *config, int leds); |
9bc590e5 SG |
133 | |
134 | #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE | |
135 | extern int overwrite_console(void); | |
136 | #define OVERWRITE_CONSOLE overwrite_console() | |
137 | #else | |
138 | #define OVERWRITE_CONSOLE 0 | |
139 | #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */ | |
140 | ||
141 | #endif |