19bc590e5SSimon Glass /* 29bc590e5SSimon Glass * Keyboard input helper functions (too small to be called a layer) 39bc590e5SSimon Glass * 49bc590e5SSimon Glass * Copyright (c) 2011 The Chromium OS Authors. 59bc590e5SSimon Glass * See file CREDITS for list of people who contributed to this 69bc590e5SSimon Glass * project. 79bc590e5SSimon Glass * 89bc590e5SSimon Glass * This program is free software; you can redistribute it and/or 99bc590e5SSimon Glass * modify it under the terms of the GNU General Public License as 109bc590e5SSimon Glass * published by the Free Software Foundation; either version 2 of 119bc590e5SSimon Glass * the License, or (at your option) any later version. 129bc590e5SSimon Glass * 139bc590e5SSimon Glass * This program is distributed in the hope that it will be useful, 149bc590e5SSimon Glass * but WITHOUT ANY WARRANTY; without even the implied warranty of 159bc590e5SSimon Glass * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 169bc590e5SSimon Glass * GNU General Public License for more details. 179bc590e5SSimon Glass * 189bc590e5SSimon Glass * You should have received a copy of the GNU General Public License 199bc590e5SSimon Glass * along with this program; if not, write to the Free Software 209bc590e5SSimon Glass * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 219bc590e5SSimon Glass * MA 02111-1307 USA 229bc590e5SSimon Glass */ 239bc590e5SSimon Glass 249bc590e5SSimon Glass #ifndef _INPUT_H 259bc590e5SSimon Glass #define _INPUT_H 269bc590e5SSimon Glass 279bc590e5SSimon Glass enum { 289bc590e5SSimon Glass INPUT_MAX_MODIFIERS = 4, 299bc590e5SSimon Glass INPUT_BUFFER_LEN = 16, 309bc590e5SSimon Glass }; 319bc590e5SSimon Glass 329bc590e5SSimon Glass enum { 339bc590e5SSimon Glass /* Keyboard LEDs */ 349bc590e5SSimon Glass INPUT_LED_SCROLL = 1 << 0, 359bc590e5SSimon Glass INPUT_LED_CAPS = 1 << 1, 369bc590e5SSimon Glass INPUT_LED_NUM = 1 << 2, 379bc590e5SSimon Glass }; 389bc590e5SSimon Glass 399bc590e5SSimon Glass /* 409bc590e5SSimon Glass * This table translates key codes to ASCII. Most of the entries are ASCII 419bc590e5SSimon Glass * codes, but entries after KEY_FIRST_MOD indicate that this key is a 429bc590e5SSimon Glass * modifier key, like shift, ctrl. KEY_FIRST_MOD + MOD_SHIFT is the shift 439bc590e5SSimon Glass * key, for example. 449bc590e5SSimon Glass */ 459bc590e5SSimon Glass struct input_key_xlate { 469bc590e5SSimon Glass /* keycode of the modifiers which select this table, -1 if none */ 479bc590e5SSimon Glass int left_keycode; 489bc590e5SSimon Glass int right_keycode; 499bc590e5SSimon Glass const uchar *xlate; /* keycode to ASCII table */ 509bc590e5SSimon Glass int num_entries; /* number of entries in this table */ 519bc590e5SSimon Glass }; 529bc590e5SSimon Glass 539bc590e5SSimon Glass struct input_config { 549bc590e5SSimon Glass uchar fifo[INPUT_BUFFER_LEN]; 559bc590e5SSimon Glass int fifo_in, fifo_out; 569bc590e5SSimon Glass 579bc590e5SSimon Glass /* Which modifiers are active (1 bit for each MOD_... value) */ 589bc590e5SSimon Glass uchar modifiers; 599bc590e5SSimon Glass uchar flags; /* active state keys (FLAGS_...) */ 609bc590e5SSimon Glass uchar leds; /* active LEDS (INPUT_LED_...) */ 619bc590e5SSimon Glass uchar num_tables; /* number of modifier tables */ 629bc590e5SSimon Glass int prev_keycodes[INPUT_BUFFER_LEN]; /* keys held last time */ 639bc590e5SSimon Glass int num_prev_keycodes; /* number of prev keys */ 649bc590e5SSimon Glass struct input_key_xlate table[INPUT_MAX_MODIFIERS]; 659bc590e5SSimon Glass 669bc590e5SSimon Glass /** 679bc590e5SSimon Glass * Function the input helper calls to scan the keyboard 689bc590e5SSimon Glass * 699bc590e5SSimon Glass * @param config Input state 709bc590e5SSimon Glass * @return 0 if no keys read, otherwise number of keys read, or 1 if 719bc590e5SSimon Glass * unknown 729bc590e5SSimon Glass */ 739bc590e5SSimon Glass int (*read_keys)(struct input_config *config); 749bc590e5SSimon Glass unsigned int next_repeat_ms; /* Next time we repeat a key */ 759bc590e5SSimon Glass unsigned int repeat_delay_ms; /* Time before autorepeat starts */ 769bc590e5SSimon Glass unsigned int repeat_rate_ms; /* Autorepeat rate in ms */ 779bc590e5SSimon Glass }; 789bc590e5SSimon Glass 799bc590e5SSimon Glass struct stdio_dev; 809bc590e5SSimon Glass 819bc590e5SSimon Glass /** 829bc590e5SSimon Glass * Convert a list of key codes into ASCII and send them 839bc590e5SSimon Glass * 849bc590e5SSimon Glass * @param config Input state 859bc590e5SSimon Glass * @param keycode List of key codes to examine 869bc590e5SSimon Glass * @param num_keycodes Number of key codes 879bc590e5SSimon Glass */ 889bc590e5SSimon Glass int input_send_keycodes(struct input_config *config, int keycode[], int count); 899bc590e5SSimon Glass 909bc590e5SSimon Glass /** 919bc590e5SSimon Glass * Add a new key translation table to the input 929bc590e5SSimon Glass * 939bc590e5SSimon Glass * @param config Input state 949bc590e5SSimon Glass * @param left_keycode Key to hold to get into this table 959bc590e5SSimon Glass * @param right_keycode Another key to hold to get into this table 969bc590e5SSimon Glass * @param xlate Conversion table from key codes to ASCII 979bc590e5SSimon Glass * @param num_entries Number of entries in xlate table 989bc590e5SSimon Glass */ 999bc590e5SSimon Glass int input_add_table(struct input_config *config, int left_keycode, 1009bc590e5SSimon Glass int right_keycode, const uchar *xlate, int num_entries); 1019bc590e5SSimon Glass 1029bc590e5SSimon Glass /** 1039bc590e5SSimon Glass * Test if keys are available to be read 1049bc590e5SSimon Glass * 1059bc590e5SSimon Glass * @param config Input state 1069bc590e5SSimon Glass * @return 0 if no keys available, 1 if keys are available 1079bc590e5SSimon Glass */ 1089bc590e5SSimon Glass int input_tstc(struct input_config *config); 1099bc590e5SSimon Glass 1109bc590e5SSimon Glass /** 1119bc590e5SSimon Glass * Read a key 1129bc590e5SSimon Glass * 1139bc590e5SSimon Glass * TODO: U-Boot wants 0 for no key, but Ctrl-@ is a valid key... 1149bc590e5SSimon Glass * 1159bc590e5SSimon Glass * @param config Input state 1169bc590e5SSimon Glass * @return key, or 0 if no key, or -1 if error 1179bc590e5SSimon Glass */ 1189bc590e5SSimon Glass int input_getc(struct input_config *config); 1199bc590e5SSimon Glass 1209bc590e5SSimon Glass /** 1219bc590e5SSimon Glass * Register a new device with stdio and switch to it if wanted 1229bc590e5SSimon Glass * 1239bc590e5SSimon Glass * @param dev Pointer to device 1249bc590e5SSimon Glass * @return 0 if ok, -1 on error 1259bc590e5SSimon Glass */ 1269bc590e5SSimon Glass int input_stdio_register(struct stdio_dev *dev); 1279bc590e5SSimon Glass 1289bc590e5SSimon Glass /** 129*1b1d3e64SSimon Glass * Set up the keyboard autorepeat delays 130*1b1d3e64SSimon Glass * 131*1b1d3e64SSimon Glass * @param repeat_delay_ms Delay before key auto-repeat starts (in ms) 132*1b1d3e64SSimon Glass * @param repeat_rate_ms Delay between successive key repeats (in ms) 133*1b1d3e64SSimon Glass */ 134*1b1d3e64SSimon Glass void input_set_delays(struct input_config *config, int repeat_delay_ms, 135*1b1d3e64SSimon Glass int repeat_rate_ms); 136*1b1d3e64SSimon Glass 137*1b1d3e64SSimon Glass /** 1389bc590e5SSimon Glass * Set up the input handler with basic key maps. 1399bc590e5SSimon Glass * 1409bc590e5SSimon Glass * @param config Input state 1419bc590e5SSimon Glass * @param leds Initial LED value (INPUT_LED_ mask), 0 suggested 1429bc590e5SSimon Glass * @return 0 if ok, -1 on error 1439bc590e5SSimon Glass */ 144*1b1d3e64SSimon Glass int input_init(struct input_config *config, int leds); 1459bc590e5SSimon Glass 1469bc590e5SSimon Glass #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE 1479bc590e5SSimon Glass extern int overwrite_console(void); 1489bc590e5SSimon Glass #define OVERWRITE_CONSOLE overwrite_console() 1499bc590e5SSimon Glass #else 1509bc590e5SSimon Glass #define OVERWRITE_CONSOLE 0 1519bc590e5SSimon Glass #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */ 1529bc590e5SSimon Glass 1539bc590e5SSimon Glass #endif 154