X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Finput%2Finput.c;h=26da3a95ff02f1775be22f438a76355f277438e9;hb=4b37928d3577e1b540b12d709e9b551fee3ccbd6;hp=fc1c45c88fe4dddaa41bfb5f635595ca59dc8ad3;hpb=0b186c0825f710a937578dc7d2ffbe125ddee7a3;p=u-boot diff --git a/drivers/input/input.c b/drivers/input/input.c index fc1c45c88f..26da3a95ff 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -8,16 +8,21 @@ */ #include +#include +#include #include #include #include +#ifdef CONFIG_DM_KEYBOARD +#include +#endif #include enum { /* These correspond to the lights on the keyboard */ - FLAG_NUM_LOCK = 1 << 0, - FLAG_CAPS_LOCK = 1 << 1, - FLAG_SCROLL_LOCK = 1 << 2, + FLAG_SCROLL_LOCK = 1 << 0, + FLAG_NUM_LOCK = 1 << 1, + FLAG_CAPS_LOCK = 1 << 2, /* Special flag ORed with key code to indicate release */ KEY_RELEASE = 1 << 15, @@ -78,6 +83,88 @@ static unsigned char kbd_ctrl_xlate[] = { '\r', 0xff, '/', '*', }; +static const uchar kbd_plain_xlate_german[] = { + 0xff, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 00-07 */ + '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */ + 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */ + 'o', 'p', 0x81, '+', '\r', 0xff, 'a', 's', /* scan 18-1F */ + 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */ + 0x84, '^', 0xff, '#', 'y', 'x', 'c', 'v', /* scan 28-2F */ + 'b', 'n', 'm', ',', '.', '-', 0xff, '*', /* scan 30-37 */ + ' ', ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '7', /* scan 40-47 */ + '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ + '2', '3', '0', ',', 0xff, 0xff, '<', 0xff, /* scan 50-57 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */ + '\r', 0xff, '/', '*', +}; + +static unsigned char kbd_shift_xlate_german[] = { + 0xff, 0x1b, '!', '"', 0x15, '$', '%', '&', /* scan 00-07 */ + '/', '(', ')', '=', '?', '`', 0x08, '\t', /* scan 08-0F */ + 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', /* scan 10-17 */ + 'O', 'P', 0x9a, '*', '\r', 0xff, 'A', 'S', /* scan 18-1F */ + 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0x99, /* scan 20-27 */ + 0x8e, 0xf8, 0xff, '\'', 'Y', 'X', 'C', 'V', /* scan 28-2F */ + 'B', 'N', 'M', ';', ':', '_', 0xff, '*', /* scan 30-37 */ + ' ', ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '7', /* scan 40-47 */ + '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ + '2', '3', '0', ',', 0xff, 0xff, '>', 0xff, /* scan 50-57 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */ + '\r', 0xff, '/', '*', +}; + +static unsigned char kbd_right_alt_xlate_german[] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */ + '{', '[', ']', '}', '\\', 0xff, 0xff, 0xff, /* scan 08-0F */ + '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */ + 0xff, 0xff, 0xff, '~', 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */ + 0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '|', 0xff, /* scan 50-57 */ +}; + +enum kbd_mask { + KBD_ENGLISH = 1 << 0, + KBD_GERMAN = 1 << 1, +}; + +static struct kbd_entry { + int kbd_mask; /* Which languages this is for */ + int left_keycode; /* Left keycode to select this map */ + int right_keycode; /* Right keycode to select this map */ + const uchar *xlate; /* Ascii code for each keycode */ + int num_entries; /* Number of entries in xlate */ +} kbd_entry[] = { + { KBD_ENGLISH, -1, -1, + kbd_plain_xlate, ARRAY_SIZE(kbd_plain_xlate) }, + { KBD_GERMAN, -1, -1, + kbd_plain_xlate_german, ARRAY_SIZE(kbd_plain_xlate_german) }, + { KBD_ENGLISH, KEY_LEFTSHIFT, KEY_RIGHTSHIFT, + kbd_shift_xlate, ARRAY_SIZE(kbd_shift_xlate) }, + { KBD_GERMAN, KEY_LEFTSHIFT, KEY_RIGHTSHIFT, + kbd_shift_xlate_german, ARRAY_SIZE(kbd_shift_xlate_german) }, + { KBD_ENGLISH | KBD_GERMAN, KEY_LEFTCTRL, KEY_RIGHTCTRL, + kbd_ctrl_xlate, ARRAY_SIZE(kbd_ctrl_xlate) }, + { KBD_GERMAN, -1, KEY_RIGHTALT, + kbd_right_alt_xlate_german, + ARRAY_SIZE(kbd_right_alt_xlate_german) }, + {}, +}; + /* * Scan key code to ANSI 3.64 escape sequence table. This table is * incomplete in that it does not include all possible extra keys. @@ -153,8 +240,11 @@ int input_getc(struct input_config *config) static struct input_key_xlate *process_modifier(struct input_config *config, int key, int release) { +#ifdef CONFIG_DM_KEYBOARD + struct udevice *dev = config->dev; + struct keyboard_ops *ops = keyboard_get_ops(dev); +#endif struct input_key_xlate *table; - int flip = -1; int i; /* Start with the main table, and see what modifiers change it */ @@ -169,6 +259,8 @@ static struct input_key_xlate *process_modifier(struct input_config *config, /* Handle the lighted keys */ if (!release) { + int flip = -1; + switch (key) { case KEY_SCROLLLOCK: flip = FLAG_SCROLL_LOCK; @@ -180,19 +272,27 @@ static struct input_key_xlate *process_modifier(struct input_config *config, flip = FLAG_CAPS_LOCK; break; } - } - if (flip != -1) { - int leds = 0; - - config->leds ^= flip; - if (config->flags & FLAG_NUM_LOCK) - leds |= INPUT_LED_NUM; - if (config->flags & FLAG_CAPS_LOCK) - leds |= INPUT_LED_CAPS; - if (config->flags & FLAG_SCROLL_LOCK) - leds |= INPUT_LED_SCROLL; - config->leds = leds; + if (flip != -1) { + int leds = 0; + + config->flags ^= flip; + if (config->flags & FLAG_NUM_LOCK) + leds |= INPUT_LED_NUM; + if (config->flags & FLAG_CAPS_LOCK) + leds |= INPUT_LED_CAPS; + if (config->flags & FLAG_SCROLL_LOCK) + leds |= INPUT_LED_SCROLL; + config->leds = leds; + config->leds_changed = flip; + +#ifdef CONFIG_DM_KEYBOARD + if (ops->update_leds) { + if (ops->update_leds(dev, config->leds)) + debug("Update keyboard's LED failed\n"); + } +#endif + } } return table; @@ -369,16 +469,25 @@ static int input_keycodes_to_ascii(struct input_config *config, /* Start conversion by looking for the first new keycode (by same). */ for (i = same; i < num_keycodes; i++) { int key = keycode[i]; - int ch = (key < table->num_entries) ? table->xlate[key] : 0xff; + int ch; /* * For a normal key (with an ASCII value), add it; otherwise * translate special key to escape sequence if possible. */ - if (ch != 0xff) { - if (ch_count < max_chars) - output_ch[ch_count] = (uchar)ch; - ch_count++; + if (key < table->num_entries) { + ch = table->xlate[key]; + if ((config->flags & FLAG_CAPS_LOCK) && + ch >= 'a' && ch <= 'z') + ch -= 'a' - 'A'; + /* ban digit numbers if 'Num Lock' is not on */ + if (!(config->flags & FLAG_NUM_LOCK)) { + if (key >= KEY_KP7 && key <= KEY_KPDOT && + key != KEY_KPMINUS && key != KEY_KPPLUS) + ch = 0xff; + } + if (ch_count < max_chars && ch != 0xff) + output_ch[ch_count++] = (uchar)ch; } else { ch_count += input_keycode_to_ansi364(config, key, output_ch, max_chars); @@ -500,21 +609,32 @@ void input_allow_repeats(struct input_config *config, bool allow_repeats) config->allow_repeats = allow_repeats; } -int input_add_tables(struct input_config *config) +int input_leds_changed(struct input_config *config) +{ + if (config->leds_changed) + return config->leds; + + return -1; +} + +int input_add_tables(struct input_config *config, bool german) { + struct kbd_entry *entry; + int mask; int ret; - ret = input_add_table(config, -1, -1, - kbd_plain_xlate, ARRAY_SIZE(kbd_plain_xlate)); - if (ret) - return ret; - ret = input_add_table(config, KEY_LEFTSHIFT, KEY_RIGHTSHIFT, - kbd_shift_xlate, ARRAY_SIZE(kbd_shift_xlate)); - if (ret) - return ret; - - return input_add_table(config, KEY_LEFTCTRL, KEY_RIGHTCTRL, - kbd_ctrl_xlate, ARRAY_SIZE(kbd_ctrl_xlate)); + mask = german ? KBD_GERMAN : KBD_ENGLISH; + for (entry = kbd_entry; entry->kbd_mask; entry++) { + if (!(mask & entry->kbd_mask)) + continue; + ret = input_add_table(config, entry->left_keycode, + entry->right_keycode, entry->xlate, + entry->num_entries); + if (ret) + return ret; + } + + return 0; } int input_init(struct input_config *config, int leds) @@ -532,7 +652,7 @@ int input_stdio_register(struct stdio_dev *dev) error = stdio_register(dev); /* check if this is the standard input device */ - if (!error && strcmp(getenv("stdin"), dev->name) == 0) { + if (!error && strcmp(env_get("stdin"), dev->name) == 0) { /* reassign the console */ if (OVERWRITE_CONSOLE || console_assign(stdin, dev->name))