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