xref: /openbmc/u-boot/include/input.h (revision 63495ad7)
1 /*
2  * Keyboard input helper functions (too small to be called a layer)
3  *
4  * Copyright (c) 2011 The Chromium OS Authors.
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
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.
12  *
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.
17  *
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,
21  * MA 02111-1307 USA
22  */
23 
24 #ifndef _INPUT_H
25 #define _INPUT_H
26 
27 enum {
28 	INPUT_MAX_MODIFIERS	= 4,
29 	INPUT_BUFFER_LEN	= 16,
30 };
31 
32 enum {
33 	/* Keyboard LEDs */
34 	INPUT_LED_SCROLL	= 1 << 0,
35 	INPUT_LED_CAPS		= 1 << 1,
36 	INPUT_LED_NUM		= 1 << 2,
37 };
38 
39 /*
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
43  * key, for example.
44  */
45 struct input_key_xlate {
46 	/* keycode of the modifiers which select this table, -1 if none */
47 	int left_keycode;
48 	int right_keycode;
49 	const uchar *xlate;	/* keycode to ASCII table */
50 	int num_entries;	/* number of entries in this table */
51 };
52 
53 struct input_config {
54 	uchar fifo[INPUT_BUFFER_LEN];
55 	int fifo_in, fifo_out;
56 
57 	/* Which modifiers are active (1 bit for each MOD_... value) */
58 	uchar modifiers;
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];
65 
66 	/**
67 	 * Function the input helper calls to scan the keyboard
68 	 *
69 	 * @param config	Input state
70 	 * @return 0 if no keys read, otherwise number of keys read, or 1 if
71 	 *		unknown
72 	 */
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 */
77 };
78 
79 struct stdio_dev;
80 
81 /**
82  * Convert a list of key codes into ASCII and send them
83  *
84  * @param config	Input state
85  * @param keycode	List of key codes to examine
86  * @param num_keycodes	Number of key codes
87  * @return number of ascii characters sent, or 0 if none, or -1 for an
88  *	internal error
89  */
90 int input_send_keycodes(struct input_config *config, int keycode[], int count);
91 
92 /**
93  * Add a new key translation table to the input
94  *
95  * @param config	Input state
96  * @param left_keycode	Key to hold to get into this table
97  * @param right_keycode	Another key to hold to get into this table
98  * @param xlate		Conversion table from key codes to ASCII
99  * @param num_entries	Number of entries in xlate table
100  */
101 int input_add_table(struct input_config *config, int left_keycode,
102 		    int right_keycode, const uchar *xlate, int num_entries);
103 
104 /**
105  * Test if keys are available to be read
106  *
107  * @param config	Input state
108  * @return 0 if no keys available, 1 if keys are available
109  */
110 int input_tstc(struct input_config *config);
111 
112 /**
113  * Read a key
114  *
115  * TODO: U-Boot wants 0 for no key, but Ctrl-@ is a valid key...
116  *
117  * @param config	Input state
118  * @return key, or 0 if no key, or -1 if error
119  */
120 int input_getc(struct input_config *config);
121 
122 /**
123  * Register a new device with stdio and switch to it if wanted
124  *
125  * @param dev	Pointer to device
126  * @return 0 if ok, -1 on error
127  */
128 int input_stdio_register(struct stdio_dev *dev);
129 
130 /**
131  * Set up the keyboard autorepeat delays
132  *
133  * @param repeat_delay_ms	Delay before key auto-repeat starts (in ms)
134  * @param repeat_rate_ms	Delay between successive key repeats (in ms)
135  */
136 void input_set_delays(struct input_config *config, int repeat_delay_ms,
137 	       int repeat_rate_ms);
138 
139 /**
140  * Set up the input handler with basic key maps.
141  *
142  * @param config	Input state
143  * @param leds		Initial LED value (INPUT_LED_ mask), 0 suggested
144  * @return 0 if ok, -1 on error
145  */
146 int input_init(struct input_config *config, int leds);
147 
148 #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
149 extern int overwrite_console(void);
150 #define OVERWRITE_CONSOLE overwrite_console()
151 #else
152 #define OVERWRITE_CONSOLE 0
153 #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
154 
155 #endif
156