2 * Keyboard input helper functions (too small to be called a layer)
4 * Copyright (c) 2011 The Chromium OS Authors.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 INPUT_MAX_MODIFIERS = 4,
29 INPUT_BUFFER_LEN = 16,
34 INPUT_LED_SCROLL = 1 << 0,
35 INPUT_LED_CAPS = 1 << 1,
36 INPUT_LED_NUM = 1 << 2,
40 * This table translates key codes to ASCII. Most of the entries are ASCII
41 * codes, but entries after KEY_FIRST_MOD indicate that this key is a
42 * modifier key, like shift, ctrl. KEY_FIRST_MOD + MOD_SHIFT is the shift
45 struct input_key_xlate {
46 /* keycode of the modifiers which select this table, -1 if none */
49 const uchar *xlate; /* keycode to ASCII table */
50 int num_entries; /* number of entries in this table */
54 uchar fifo[INPUT_BUFFER_LEN];
55 int fifo_in, fifo_out;
57 /* Which modifiers are active (1 bit for each MOD_... value) */
59 uchar flags; /* active state keys (FLAGS_...) */
60 uchar leds; /* active LEDS (INPUT_LED_...) */
61 uchar num_tables; /* number of modifier tables */
62 int prev_keycodes[INPUT_BUFFER_LEN]; /* keys held last time */
63 int num_prev_keycodes; /* number of prev keys */
64 struct input_key_xlate table[INPUT_MAX_MODIFIERS];
67 * Function the input helper calls to scan the keyboard
69 * @param config Input state
70 * @return 0 if no keys read, otherwise number of keys read, or 1 if
73 int (*read_keys)(struct input_config *config);
74 unsigned int next_repeat_ms; /* Next time we repeat a key */
75 unsigned int repeat_delay_ms; /* Time before autorepeat starts */
76 unsigned int repeat_rate_ms; /* Autorepeat rate in ms */
82 * Convert a list of key codes into ASCII and send them
84 * @param config Input state
85 * @param keycode List of key codes to examine
86 * @param num_keycodes Number of key codes
88 int input_send_keycodes(struct input_config *config, int keycode[], int count);
91 * Add a new key translation table to the input
93 * @param config Input state
94 * @param left_keycode Key to hold to get into this table
95 * @param right_keycode Another key to hold to get into this table
96 * @param xlate Conversion table from key codes to ASCII
97 * @param num_entries Number of entries in xlate table
99 int input_add_table(struct input_config *config, int left_keycode,
100 int right_keycode, const uchar *xlate, int num_entries);
103 * Test if keys are available to be read
105 * @param config Input state
106 * @return 0 if no keys available, 1 if keys are available
108 int input_tstc(struct input_config *config);
113 * TODO: U-Boot wants 0 for no key, but Ctrl-@ is a valid key...
115 * @param config Input state
116 * @return key, or 0 if no key, or -1 if error
118 int input_getc(struct input_config *config);
121 * Register a new device with stdio and switch to it if wanted
123 * @param dev Pointer to device
124 * @return 0 if ok, -1 on error
126 int input_stdio_register(struct stdio_dev *dev);
129 * Set up the keyboard autorepeat delays
131 * @param repeat_delay_ms Delay before key auto-repeat starts (in ms)
132 * @param repeat_rate_ms Delay between successive key repeats (in ms)
134 void input_set_delays(struct input_config *config, int repeat_delay_ms,
138 * Set up the input handler with basic key maps.
140 * @param config Input state
141 * @param leds Initial LED value (INPUT_LED_ mask), 0 suggested
142 * @return 0 if ok, -1 on error
144 int input_init(struct input_config *config, int leds);
146 #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
147 extern int overwrite_console(void);
148 #define OVERWRITE_CONSOLE overwrite_console()
150 #define OVERWRITE_CONSOLE 0
151 #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */