1*9bc590e5SSimon Glass /* 2*9bc590e5SSimon Glass * Keyboard input helper functions (too small to be called a layer) 3*9bc590e5SSimon Glass * 4*9bc590e5SSimon Glass * Copyright (c) 2011 The Chromium OS Authors. 5*9bc590e5SSimon Glass * See file CREDITS for list of people who contributed to this 6*9bc590e5SSimon Glass * project. 7*9bc590e5SSimon Glass * 8*9bc590e5SSimon Glass * This program is free software; you can redistribute it and/or 9*9bc590e5SSimon Glass * modify it under the terms of the GNU General Public License as 10*9bc590e5SSimon Glass * published by the Free Software Foundation; either version 2 of 11*9bc590e5SSimon Glass * the License, or (at your option) any later version. 12*9bc590e5SSimon Glass * 13*9bc590e5SSimon Glass * This program is distributed in the hope that it will be useful, 14*9bc590e5SSimon Glass * but WITHOUT ANY WARRANTY; without even the implied warranty of 15*9bc590e5SSimon Glass * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*9bc590e5SSimon Glass * GNU General Public License for more details. 17*9bc590e5SSimon Glass * 18*9bc590e5SSimon Glass * You should have received a copy of the GNU General Public License 19*9bc590e5SSimon Glass * along with this program; if not, write to the Free Software 20*9bc590e5SSimon Glass * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 21*9bc590e5SSimon Glass * MA 02111-1307 USA 22*9bc590e5SSimon Glass */ 23*9bc590e5SSimon Glass 24*9bc590e5SSimon Glass #ifndef _INPUT_H 25*9bc590e5SSimon Glass #define _INPUT_H 26*9bc590e5SSimon Glass 27*9bc590e5SSimon Glass enum { 28*9bc590e5SSimon Glass INPUT_MAX_MODIFIERS = 4, 29*9bc590e5SSimon Glass INPUT_BUFFER_LEN = 16, 30*9bc590e5SSimon Glass }; 31*9bc590e5SSimon Glass 32*9bc590e5SSimon Glass enum { 33*9bc590e5SSimon Glass /* Keyboard LEDs */ 34*9bc590e5SSimon Glass INPUT_LED_SCROLL = 1 << 0, 35*9bc590e5SSimon Glass INPUT_LED_CAPS = 1 << 1, 36*9bc590e5SSimon Glass INPUT_LED_NUM = 1 << 2, 37*9bc590e5SSimon Glass }; 38*9bc590e5SSimon Glass 39*9bc590e5SSimon Glass /* 40*9bc590e5SSimon Glass * This table translates key codes to ASCII. Most of the entries are ASCII 41*9bc590e5SSimon Glass * codes, but entries after KEY_FIRST_MOD indicate that this key is a 42*9bc590e5SSimon Glass * modifier key, like shift, ctrl. KEY_FIRST_MOD + MOD_SHIFT is the shift 43*9bc590e5SSimon Glass * key, for example. 44*9bc590e5SSimon Glass */ 45*9bc590e5SSimon Glass struct input_key_xlate { 46*9bc590e5SSimon Glass /* keycode of the modifiers which select this table, -1 if none */ 47*9bc590e5SSimon Glass int left_keycode; 48*9bc590e5SSimon Glass int right_keycode; 49*9bc590e5SSimon Glass const uchar *xlate; /* keycode to ASCII table */ 50*9bc590e5SSimon Glass int num_entries; /* number of entries in this table */ 51*9bc590e5SSimon Glass }; 52*9bc590e5SSimon Glass 53*9bc590e5SSimon Glass struct input_config { 54*9bc590e5SSimon Glass uchar fifo[INPUT_BUFFER_LEN]; 55*9bc590e5SSimon Glass int fifo_in, fifo_out; 56*9bc590e5SSimon Glass 57*9bc590e5SSimon Glass /* Which modifiers are active (1 bit for each MOD_... value) */ 58*9bc590e5SSimon Glass uchar modifiers; 59*9bc590e5SSimon Glass uchar flags; /* active state keys (FLAGS_...) */ 60*9bc590e5SSimon Glass uchar leds; /* active LEDS (INPUT_LED_...) */ 61*9bc590e5SSimon Glass uchar num_tables; /* number of modifier tables */ 62*9bc590e5SSimon Glass int prev_keycodes[INPUT_BUFFER_LEN]; /* keys held last time */ 63*9bc590e5SSimon Glass int num_prev_keycodes; /* number of prev keys */ 64*9bc590e5SSimon Glass struct input_key_xlate table[INPUT_MAX_MODIFIERS]; 65*9bc590e5SSimon Glass 66*9bc590e5SSimon Glass /** 67*9bc590e5SSimon Glass * Function the input helper calls to scan the keyboard 68*9bc590e5SSimon Glass * 69*9bc590e5SSimon Glass * @param config Input state 70*9bc590e5SSimon Glass * @return 0 if no keys read, otherwise number of keys read, or 1 if 71*9bc590e5SSimon Glass * unknown 72*9bc590e5SSimon Glass */ 73*9bc590e5SSimon Glass int (*read_keys)(struct input_config *config); 74*9bc590e5SSimon Glass unsigned int next_repeat_ms; /* Next time we repeat a key */ 75*9bc590e5SSimon Glass unsigned int repeat_delay_ms; /* Time before autorepeat starts */ 76*9bc590e5SSimon Glass unsigned int repeat_rate_ms; /* Autorepeat rate in ms */ 77*9bc590e5SSimon Glass }; 78*9bc590e5SSimon Glass 79*9bc590e5SSimon Glass struct stdio_dev; 80*9bc590e5SSimon Glass 81*9bc590e5SSimon Glass /** 82*9bc590e5SSimon Glass * Convert a list of key codes into ASCII and send them 83*9bc590e5SSimon Glass * 84*9bc590e5SSimon Glass * @param config Input state 85*9bc590e5SSimon Glass * @param keycode List of key codes to examine 86*9bc590e5SSimon Glass * @param num_keycodes Number of key codes 87*9bc590e5SSimon Glass */ 88*9bc590e5SSimon Glass int input_send_keycodes(struct input_config *config, int keycode[], int count); 89*9bc590e5SSimon Glass 90*9bc590e5SSimon Glass /** 91*9bc590e5SSimon Glass * Add a new key translation table to the input 92*9bc590e5SSimon Glass * 93*9bc590e5SSimon Glass * @param config Input state 94*9bc590e5SSimon Glass * @param left_keycode Key to hold to get into this table 95*9bc590e5SSimon Glass * @param right_keycode Another key to hold to get into this table 96*9bc590e5SSimon Glass * @param xlate Conversion table from key codes to ASCII 97*9bc590e5SSimon Glass * @param num_entries Number of entries in xlate table 98*9bc590e5SSimon Glass */ 99*9bc590e5SSimon Glass int input_add_table(struct input_config *config, int left_keycode, 100*9bc590e5SSimon Glass int right_keycode, const uchar *xlate, int num_entries); 101*9bc590e5SSimon Glass 102*9bc590e5SSimon Glass /** 103*9bc590e5SSimon Glass * Test if keys are available to be read 104*9bc590e5SSimon Glass * 105*9bc590e5SSimon Glass * @param config Input state 106*9bc590e5SSimon Glass * @return 0 if no keys available, 1 if keys are available 107*9bc590e5SSimon Glass */ 108*9bc590e5SSimon Glass int input_tstc(struct input_config *config); 109*9bc590e5SSimon Glass 110*9bc590e5SSimon Glass /** 111*9bc590e5SSimon Glass * Read a key 112*9bc590e5SSimon Glass * 113*9bc590e5SSimon Glass * TODO: U-Boot wants 0 for no key, but Ctrl-@ is a valid key... 114*9bc590e5SSimon Glass * 115*9bc590e5SSimon Glass * @param config Input state 116*9bc590e5SSimon Glass * @return key, or 0 if no key, or -1 if error 117*9bc590e5SSimon Glass */ 118*9bc590e5SSimon Glass int input_getc(struct input_config *config); 119*9bc590e5SSimon Glass 120*9bc590e5SSimon Glass /** 121*9bc590e5SSimon Glass * Register a new device with stdio and switch to it if wanted 122*9bc590e5SSimon Glass * 123*9bc590e5SSimon Glass * @param dev Pointer to device 124*9bc590e5SSimon Glass * @return 0 if ok, -1 on error 125*9bc590e5SSimon Glass */ 126*9bc590e5SSimon Glass int input_stdio_register(struct stdio_dev *dev); 127*9bc590e5SSimon Glass 128*9bc590e5SSimon Glass /** 129*9bc590e5SSimon Glass * Set up the input handler with basic key maps. 130*9bc590e5SSimon Glass * 131*9bc590e5SSimon Glass * @param config Input state 132*9bc590e5SSimon Glass * @param leds Initial LED value (INPUT_LED_ mask), 0 suggested 133*9bc590e5SSimon Glass * @param repeat_delay_ms Delay before key auto-repeat starts (in ms) 134*9bc590e5SSimon Glass * @param repeat_rate_ms Delay between successive key repeats (in ms) 135*9bc590e5SSimon Glass * @return 0 if ok, -1 on error 136*9bc590e5SSimon Glass */ 137*9bc590e5SSimon Glass int input_init(struct input_config *config, int leds, int repeat_delay_ms, 138*9bc590e5SSimon Glass int repeat_rate_ms); 139*9bc590e5SSimon Glass 140*9bc590e5SSimon Glass #ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE 141*9bc590e5SSimon Glass extern int overwrite_console(void); 142*9bc590e5SSimon Glass #define OVERWRITE_CONSOLE overwrite_console() 143*9bc590e5SSimon Glass #else 144*9bc590e5SSimon Glass #define OVERWRITE_CONSOLE 0 145*9bc590e5SSimon Glass #endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */ 146*9bc590e5SSimon Glass 147*9bc590e5SSimon Glass #endif 148