]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - include/input.h
Unified codebase for TX28, TX48, TX51, TX53
[karo-tx-uboot.git] / include / input.h
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  */
88 int 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  */
99 int 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  */
108 int 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  */
118 int 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  */
126 int input_stdio_register(struct stdio_dev *dev);
127
128 /**
129  * Set up the input handler with basic key maps.
130  *
131  * @param config        Input state
132  * @param leds          Initial LED value (INPUT_LED_ mask), 0 suggested
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  * @return 0 if ok, -1 on error
136  */
137 int input_init(struct input_config *config, int leds, int repeat_delay_ms,
138                int repeat_rate_ms);
139
140 #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
141 extern int overwrite_console(void);
142 #define OVERWRITE_CONSOLE overwrite_console()
143 #else
144 #define OVERWRITE_CONSOLE 0
145 #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
146
147 #endif