2 * Keyboard input helper functions (too small to be called a layer)
4 * Copyright (c) 2011 The Chromium OS Authors.
6 * SPDX-License-Identifier: GPL-2.0+
13 INPUT_MAX_MODIFIERS = 4,
14 INPUT_BUFFER_LEN = 16,
19 INPUT_LED_SCROLL = 1 << 0,
20 INPUT_LED_CAPS = 1 << 1,
21 INPUT_LED_NUM = 1 << 2,
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
30 struct input_key_xlate {
31 /* keycode of the modifiers which select this table, -1 if none */
34 const uchar *xlate; /* keycode to ASCII table */
35 int num_entries; /* number of entries in this table */
40 uchar fifo[INPUT_BUFFER_LEN];
41 int fifo_in, fifo_out;
43 /* Which modifiers are active (1 bit for each MOD_... value) */
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];
53 * Function the input helper calls to scan the keyboard
55 * @param config Input state
56 * @return 0 if no keys read, otherwise number of keys read, or 1 if
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 */
68 * Convert a list of key codes into ASCII and send them
70 * @param config Input state
71 * @param keycode List of key codes to examine
72 * @param num_keycodes Number of key codes
73 * @return number of ascii characters sent, or 0 if none, or -1 for an
76 int input_send_keycodes(struct input_config *config, int keycode[], int count);
79 * Add a new keycode to an existing list of keycodes
81 * This can be used to handle keyboards which do their own scanning. An
82 * internal list of depressed keys is maintained by the input library. Then
83 * this function is called to add a new key to the list (when a 'make code' is
84 * received), or remove a key (when a 'break code' is received).
86 * This function looks after maintenance of the list of active keys, and calls
87 * input_send_keycodes() with its updated list.
89 * @param config Input state
90 * @param new_keycode New keycode to add/remove
91 * @param release true if this key was released, false if depressed
92 * @return number of ascii characters sent, or 0 if none, or -1 for an
95 int input_add_keycode(struct input_config *config, int new_keycode,
99 * Add a new key translation table to the input
101 * @param config Input state
102 * @param left_keycode Key to hold to get into this table
103 * @param right_keycode Another key to hold to get into this table
104 * @param xlate Conversion table from key codes to ASCII
105 * @param num_entries Number of entries in xlate table
107 int input_add_table(struct input_config *config, int left_keycode,
108 int right_keycode, const uchar *xlate, int num_entries);
111 * Test if keys are available to be read
113 * @param config Input state
114 * @return 0 if no keys available, 1 if keys are available
116 int input_tstc(struct input_config *config);
121 * TODO: U-Boot wants 0 for no key, but Ctrl-@ is a valid key...
123 * @param config Input state
124 * @return key, or 0 if no key, or -1 if error
126 int input_getc(struct input_config *config);
129 * Register a new device with stdio and switch to it if wanted
131 * @param dev Pointer to device
132 * @return 0 if ok, -1 on error
134 int input_stdio_register(struct stdio_dev *dev);
137 * Set up the keyboard autorepeat delays
139 * @param repeat_delay_ms Delay before key auto-repeat starts (in ms)
140 * @param repeat_rate_ms Delay between successive key repeats (in ms)
142 void input_set_delays(struct input_config *config, int repeat_delay_ms,
146 * Set up the key map tables
148 * This must be called after input_init() or keycode decoding will not work.
150 * @param config Input state
151 * @return 0 if ok, -1 on error
153 int input_add_tables(struct input_config *config);
156 * Set up the input handler with basic key maps.
158 * @param config Input state
159 * @param leds Initial LED value (INPUT_LED_ mask), 0 suggested
160 * @return 0 if ok, -1 on error
162 int input_init(struct input_config *config, int leds);
164 #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
165 extern int overwrite_console(void);
166 #define OVERWRITE_CONSOLE overwrite_console()
168 #define OVERWRITE_CONSOLE 0
169 #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */