blob: 0f4acb27f83782a70d1e5aa75c3782fffe7d6b20 [file] [log] [blame]
Simon Glass9bc590e2012-04-17 09:01:30 +00001/*
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
27enum {
28 INPUT_MAX_MODIFIERS = 4,
29 INPUT_BUFFER_LEN = 16,
30};
31
32enum {
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 */
45struct 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
53struct 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
79struct 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 */
88int input_send_keycodes(struct input_config *config, int keycode[], int count);
89
90/**
91 * Add a new key translation table to the input
92 *
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
98 */
99int input_add_table(struct input_config *config, int left_keycode,
100 int right_keycode, const uchar *xlate, int num_entries);
101
102/**
103 * Test if keys are available to be read
104 *
105 * @param config Input state
106 * @return 0 if no keys available, 1 if keys are available
107 */
108int input_tstc(struct input_config *config);
109
110/**
111 * Read a key
112 *
113 * TODO: U-Boot wants 0 for no key, but Ctrl-@ is a valid key...
114 *
115 * @param config Input state
116 * @return key, or 0 if no key, or -1 if error
117 */
118int input_getc(struct input_config *config);
119
120/**
121 * Register a new device with stdio and switch to it if wanted
122 *
123 * @param dev Pointer to device
124 * @return 0 if ok, -1 on error
125 */
126int input_stdio_register(struct stdio_dev *dev);
127
128/**
Simon Glass1b1d3e62012-09-27 15:18:41 +0000129 * Set up the keyboard autorepeat delays
130 *
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)
133 */
134void input_set_delays(struct input_config *config, int repeat_delay_ms,
135 int repeat_rate_ms);
136
137/**
Simon Glass9bc590e2012-04-17 09:01:30 +0000138 * Set up the input handler with basic key maps.
139 *
140 * @param config Input state
141 * @param leds Initial LED value (INPUT_LED_ mask), 0 suggested
Simon Glass9bc590e2012-04-17 09:01:30 +0000142 * @return 0 if ok, -1 on error
143 */
Simon Glass1b1d3e62012-09-27 15:18:41 +0000144int input_init(struct input_config *config, int leds);
Simon Glass9bc590e2012-04-17 09:01:30 +0000145
146#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
147extern int overwrite_console(void);
148#define OVERWRITE_CONSOLE overwrite_console()
149#else
150#define OVERWRITE_CONSOLE 0
151#endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
152
153#endif