Lines Matching +full:key +full:- +full:code

1 // SPDX-License-Identifier: GPL-2.0+
3 * Translate key codes into ASCII
26 /* Special flag ORed with key code to indicate release */
32 * These takes map key codes to ASCII. 0xff means no key, or special key.
33 * Three tables are provided - one for plain keys, one for when the shift
34 * 'modifier' key is pressed and one for when the ctrl modifier key is
39 '7', '8', '9', '0', '-', '=', '\b', '\t', /* 0x00 - 0x0f */
41 'o', 'p', '[', ']', '\r', 0xff, 'a', 's', /* 0x10 - 0x1f */
43 '\'', '`', 0xff, '\\', 'z', 'x', 'c', 'v', /* 0x20 - 0x2f */
45 ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30 - 0x3f */
47 '8', '9', '-', '4', '5', '6', '+', '1', /* 0x40 - 0x4f */
49 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50 - 0x5F */
55 '&', '*', '(', ')', '_', '+', '\b', '\t', /* 0x00 - 0x0f */
57 'O', 'P', '{', '}', '\r', 0xff, 'A', 'S', /* 0x10 - 0x1f */
59 '"', '~', 0xff, '|', 'Z', 'X', 'C', 'V', /* 0x20 - 0x2f */
61 ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30 - 0x3f */
63 '8', '9', '-', '4', '5', '6', '+', '1', /* 0x40 - 0x4f */
65 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50 - 0x5F */
71 '7', '8', '9', '0', 0x1F, '=', '\b', '\t', /* 0x00 - 0x0f */
73 0x0f, 0x10, 0x1b, 0x1d, '\n', 0xff, 0x01, 0x13, /* 0x10 - 0x1f */
75 '\'', '~', 0x00, 0x1c, 0x1a, 0x18, 0x03, 0x16, /* 0x20 - 0x2f */
77 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x30 - 0x3f */
79 '8', '9', '-', '4', '5', '6', '+', '1', /* 0x40 - 0x4f */
81 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 0x50 - 0x5F */
86 * German keymap. Special letters are mapped according to code page 437.
89 0xff, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */
90 '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */
91 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */
92 'o', 'p', 0x81, '+', '\r', 0xff, 'a', 's', /* scan 18-1F */
93 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */
94 0x84, '^', 0xff, '#', 'y', 'x', 'c', 'v', /* scan 28-2F */
95 'b', 'n', 'm', ',', '.', '-', 0xff, '*', /* scan 30-37 */
96 ' ', ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
97 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '7', /* scan 40-47 */
98 '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
99 '2', '3', '0', ',', 0xff, 0xff, '<', 0xff, /* scan 50-57 */
100 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
101 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
102 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
103 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
104 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
109 0xff, 0x1b, '!', '"', 0x15, '$', '%', '&', /* scan 00-07 */
110 '/', '(', ')', '=', '?', '`', 0x08, '\t', /* scan 08-0F */
111 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', /* scan 10-17 */
112 'O', 'P', 0x9a, '*', '\r', 0xff, 'A', 'S', /* scan 18-1F */
113 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0x99, /* scan 20-27 */
114 0x8e, 0xf8, 0xff, '\'', 'Y', 'X', 'C', 'V', /* scan 28-2F */
115 'B', 'N', 'M', ';', ':', '_', 0xff, '*', /* scan 30-37 */
116 ' ', ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
117 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '7', /* scan 40-47 */
118 '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */
119 '2', '3', '0', ',', 0xff, 0xff, '>', 0xff, /* scan 50-57 */
120 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
121 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
122 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
123 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
124 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
129 0xff, 0xff, 0xff, 0xfd, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
130 '{', '[', ']', '}', '\\', 0xff, 0xff, 0xff, /* scan 08-0F */
131 '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */
132 0xff, 0xff, 0xff, '~', 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */
133 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */
134 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */
135 0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */
136 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
137 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */
138 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
139 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '|', 0xff, /* scan 50-57 */
151 const uchar *xlate; /* Ascii code for each keycode */
154 { KBD_ENGLISH, -1, -1,
156 { KBD_GERMAN, -1, -1,
164 { KBD_GERMAN, -1, KEY_RIGHTALT,
171 * Scan key code to ANSI 3.64 escape sequence table. This table is
189 if (config->fifo_in + 1 == INPUT_BUFFER_LEN) { in input_queue_ascii()
190 if (!config->fifo_out) in input_queue_ascii()
191 return -1; /* buffer full */ in input_queue_ascii()
193 config->fifo_in = 0; in input_queue_ascii()
195 if (config->fifo_in + 1 == config->fifo_out) in input_queue_ascii()
196 return -1; /* buffer full */ in input_queue_ascii()
197 config->fifo_in++; in input_queue_ascii()
200 config->fifo[config->fifo_in] = (uchar)ch; in input_queue_ascii()
207 if (config->fifo_in == config->fifo_out && config->read_keys) { in input_tstc()
208 if (!(*config->read_keys)(config)) in input_tstc()
211 return config->fifo_in != config->fifo_out; in input_tstc()
218 while (config->fifo_in == config->fifo_out) { in input_getc()
219 if (config->read_keys) in input_getc()
220 err = (*config->read_keys)(config); in input_getc()
222 return -1; in input_getc()
225 if (++config->fifo_out == INPUT_BUFFER_LEN) in input_getc()
226 config->fifo_out = 0; in input_getc()
228 return config->fifo[config->fifo_out]; in input_getc()
232 * Process a modifier/special key press or release and decide which key
238 * @param key Key code to process
240 * @return pointer to keycode->ascii translation table that should be used
243 int key, int release) in process_modifier() argument
246 struct udevice *dev = config->dev; in process_modifier()
253 assert(config->num_tables > 0); in process_modifier()
254 table = &config->table[0]; in process_modifier()
255 for (i = 1; i < config->num_tables; i++) { in process_modifier()
256 struct input_key_xlate *tab = &config->table[i]; in process_modifier()
258 if (key == tab->left_keycode || key == tab->right_keycode) in process_modifier()
264 int flip = -1; in process_modifier()
266 switch (key) { in process_modifier()
278 if (flip != -1) { in process_modifier()
281 config->flags ^= flip; in process_modifier()
282 if (config->flags & FLAG_NUM_LOCK) in process_modifier()
284 if (config->flags & FLAG_CAPS_LOCK) in process_modifier()
286 if (config->flags & FLAG_SCROLL_LOCK) in process_modifier()
288 config->leds = leds; in process_modifier()
289 config->leds_changed = flip; in process_modifier()
292 if (ops->update_leds) { in process_modifier()
293 if (ops->update_leds(dev, config->leds)) in process_modifier()
304 * Search an int array for a key value
308 * @param key Key value to find
309 * @return element where value was first found, -1 if none
311 static int array_search(int *array, int count, int key) in array_search() argument
316 if (array[i] == key) in array_search()
320 return -1; in array_search()
351 if (array_search(temp, count, order[i]) != -1) in sort_array_by_ordering()
358 if (array_search(order, ocount, temp[i]) == -1) in sort_array_by_ordering()
366 * Check a list of key codes against the previous key scan
368 * Given a list of new key codes, we check how many of these are the same
372 * @param keycode List of key codes to examine
373 * @param num_keycodes Number of key codes
374 * @param same Returns number of key codes which are the same
380 if (!config->num_tables) { in input_check_keycodes()
382 return -1; in input_check_keycodes()
387 config->prev_keycodes, config->num_prev_keycodes); in input_check_keycodes()
389 memcpy(config->prev_keycodes, keycode, num_keycodes * sizeof(int)); in input_check_keycodes()
390 config->num_prev_keycodes = num_keycodes; in input_check_keycodes()
396 * Checks and converts a special key code into ANSI 3.64 escape sequence.
399 * @param keycode Key code to examine
404 * @return number of characters output, if the key was converted, otherwise 0.
430 * Converts and queues a list of key codes in escaped ASCII string form
431 * Convert a list of key codes into ASCII
441 * @param keycode List of key codes to examine
442 * @param num_keycodes Number of key codes
447 * @param same Number of key codes which are the same
448 * @return number of characters written into output_ch, or -1 if we would
459 table = &config->table[0]; in input_keycodes_to_ascii()
463 int key = keycode[i] & KEY_MASK; in input_keycodes_to_ascii() local
465 if (key >= table->num_entries || table->xlate[key] == 0xff) { in input_keycodes_to_ascii()
466 table = process_modifier(config, key, in input_keycodes_to_ascii()
473 int key = keycode[i]; in input_keycodes_to_ascii() local
477 * For a normal key (with an ASCII value), add it; otherwise in input_keycodes_to_ascii()
478 * translate special key to escape sequence if possible. in input_keycodes_to_ascii()
480 if (key < table->num_entries) { in input_keycodes_to_ascii()
481 ch = table->xlate[key]; in input_keycodes_to_ascii()
482 if ((config->flags & FLAG_CAPS_LOCK) && in input_keycodes_to_ascii()
484 ch -= 'a' - 'A'; in input_keycodes_to_ascii()
486 if (!(config->flags & FLAG_NUM_LOCK)) { in input_keycodes_to_ascii()
487 if (key >= KEY_KP7 && key <= KEY_KPDOT && in input_keycodes_to_ascii()
488 key != KEY_KPMINUS && key != KEY_KPPLUS) in input_keycodes_to_ascii()
494 ch_count += input_keycode_to_ansi364(config, key, in input_keycodes_to_ascii()
502 return -1; in input_keycodes_to_ascii()
517 config->modifiers = 0; in _input_send_keycodes()
520 * Same as last time - is it time for another repeat? in _input_send_keycodes()
523 * auto-repeat speed is not quite correct. We should in _input_send_keycodes()
527 is_repeat = config->allow_repeats || (config->repeat_rate_ms && in _input_send_keycodes()
528 (int)get_timer(config->next_repeat_ms) >= 0); in _input_send_keycodes()
540 config->repeat_rate_ms : in _input_send_keycodes()
541 config->repeat_delay_ms; in _input_send_keycodes()
543 config->next_repeat_ms = get_timer(0) + delay_ms; in _input_send_keycodes()
561 for (i = 0, count = 0; i < config->num_prev_keycodes; i++) { in input_add_keycode()
562 int code = config->prev_keycodes[i]; in input_add_keycode() local
564 if (new_keycode == code) { in input_add_keycode()
567 new_keycode = -1; in input_add_keycode()
569 keycode[count++] = code; in input_add_keycode()
572 if (!release && new_keycode != -1) in input_add_keycode()
579 /* Don't output any ASCII characters if this is a key release */ in input_add_keycode()
588 if (config->num_tables == INPUT_MAX_MODIFIERS) { in input_add_table()
590 return -1; in input_add_table()
593 table = &config->table[config->num_tables++]; in input_add_table()
594 table->left_keycode = left_keycode; in input_add_table()
595 table->right_keycode = right_keycode; in input_add_table()
596 table->xlate = xlate; in input_add_table()
597 table->num_entries = num_entries; in input_add_table()
605 config->repeat_delay_ms = repeat_delay_ms; in input_set_delays()
606 config->repeat_rate_ms = repeat_rate_ms; in input_set_delays()
611 config->allow_repeats = allow_repeats; in input_allow_repeats()
616 if (config->leds_changed) in input_leds_changed()
617 return config->leds; in input_leds_changed()
619 return -1; in input_leds_changed()
629 for (entry = kbd_entry; entry->kbd_mask; entry++) { in input_add_tables()
630 if (!(mask & entry->kbd_mask)) in input_add_tables()
632 ret = input_add_table(config, entry->left_keycode, in input_add_tables()
633 entry->right_keycode, entry->xlate, in input_add_tables()
634 entry->num_entries); in input_add_tables()
645 config->leds = leds; in input_init()
657 if (!error && strcmp(env_get("stdin"), dev->name) == 0) { in input_stdio_register()
660 console_assign(stdin, dev->name)) in input_stdio_register()
661 return -1; in input_stdio_register()