Commit b9ec4e10 authored by Samuel Thibault's avatar Samuel Thibault Committed by Dmitry Torokhov

Input: add support for Braille devices

- Add KEY_BRL_* input keys and K_BRL_* keycodes;
- Add emulation of how braille keyboards usually combine braille dots
  to the console keyboard driver;
- Add handling of unicode U+28xy diacritics.
Signed-off-by: default avatarSamuel Thibault <samuel.thibault@ens-lyon.org>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent 53a2670c
......@@ -74,7 +74,7 @@ void compute_shiftstate(void);
k_self, k_fn, k_spec, k_pad,\
k_dead, k_cons, k_cur, k_shift,\
k_meta, k_ascii, k_lock, k_lowercase,\
k_slock, k_dead2, k_ignore, k_ignore
k_slock, k_dead2, k_brl, k_ignore
typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value,
char up_flag, struct pt_regs *regs);
......@@ -100,7 +100,7 @@ static fn_handler_fn *fn_handler[] = { FN_HANDLERS };
const int max_vals[] = {
255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1,
NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1,
255, NR_LOCK - 1, 255
255, NR_LOCK - 1, 255, NR_BRL - 1
};
const int NR_TYPES = ARRAY_SIZE(max_vals);
......@@ -126,7 +126,7 @@ static unsigned long key_down[NBITS(KEY_MAX)]; /* keyboard key bitmap */
static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */
static int dead_key_next;
static int npadch = -1; /* -1 or number assembled on pad */
static unsigned char diacr;
static unsigned int diacr;
static char rep; /* flag telling character repeat */
static unsigned char ledstate = 0xff; /* undefined */
......@@ -394,22 +394,30 @@ void compute_shiftstate(void)
* Otherwise, conclude that DIACR was not combining after all,
* queue it and return CH.
*/
static unsigned char handle_diacr(struct vc_data *vc, unsigned char ch)
static unsigned int handle_diacr(struct vc_data *vc, unsigned int ch)
{
int d = diacr;
unsigned int d = diacr;
unsigned int i;
diacr = 0;
for (i = 0; i < accent_table_size; i++) {
if ((d & ~0xff) == BRL_UC_ROW) {
if ((ch & ~0xff) == BRL_UC_ROW)
return d | ch;
} else {
for (i = 0; i < accent_table_size; i++)
if (accent_table[i].diacr == d && accent_table[i].base == ch)
return accent_table[i].result;
}
if (ch == ' ' || ch == d)
if (ch == ' ' || ch == (BRL_UC_ROW|0) || ch == d)
return d;
if (kbd->kbdmode == VC_UNICODE)
to_utf8(vc, d);
else if (d < 0x100)
put_queue(vc, d);
return ch;
}
......@@ -419,6 +427,9 @@ static unsigned char handle_diacr(struct vc_data *vc, unsigned char ch)
static void fn_enter(struct vc_data *vc, struct pt_regs *regs)
{
if (diacr) {
if (kbd->kbdmode == VC_UNICODE)
to_utf8(vc, diacr);
else if (diacr < 0x100)
put_queue(vc, diacr);
diacr = 0;
}
......@@ -615,7 +626,7 @@ static void k_lowercase(struct vc_data *vc, unsigned char value, char up_flag, s
printk(KERN_ERR "keyboard.c: k_lowercase was called - impossible\n");
}
static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag, struct pt_regs *regs)
{
if (up_flag)
return; /* no action, if this is a key release */
......@@ -628,6 +639,9 @@ static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct
diacr = value;
return;
}
if (kbd->kbdmode == VC_UNICODE)
to_utf8(vc, value);
else if (value < 0x100)
put_queue(vc, value);
}
......@@ -636,13 +650,23 @@ static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct
* dead keys modifying the same character. Very useful
* for Vietnamese.
*/
static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
static void k_deadunicode(struct vc_data *vc, unsigned int value, char up_flag, struct pt_regs *regs)
{
if (up_flag)
return;
diacr = (diacr ? handle_diacr(vc, value) : value);
}
static void k_self(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
{
k_unicode(vc, value, up_flag, regs);
}
static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
{
k_deadunicode(vc, value, up_flag, regs);
}
/*
* Obsolete - for backwards compatibility only
*/
......@@ -650,7 +674,7 @@ static void k_dead(struct vc_data *vc, unsigned char value, char up_flag, struct
{
static unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' };
value = ret_diacr[value];
k_dead2(vc, value, up_flag, regs);
k_deadunicode(vc, value, up_flag, regs);
}
static void k_cons(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
......@@ -835,6 +859,62 @@ static void k_slock(struct vc_data *vc, unsigned char value, char up_flag, struc
}
}
/* by default, 300ms interval for combination release */
static long brl_timeout = 300;
MODULE_PARM_DESC(brl_timeout, "Braille keys release delay in ms (0 for combination on first release, < 0 for dead characters)");
module_param(brl_timeout, long, 0644);
static void k_brl(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs)
{
static unsigned pressed,committing;
static unsigned long releasestart;
if (kbd->kbdmode != VC_UNICODE) {
if (!up_flag)
printk("keyboard mode must be unicode for braille patterns\n");
return;
}
if (!value) {
k_unicode(vc, BRL_UC_ROW, up_flag, regs);
return;
}
if (value > 8)
return;
if (brl_timeout < 0) {
k_deadunicode(vc, BRL_UC_ROW | (1 << (value - 1)), up_flag, regs);
return;
}
if (up_flag) {
if (brl_timeout) {
if (!committing ||
jiffies - releasestart > (brl_timeout * HZ) / 1000) {
committing = pressed;
releasestart = jiffies;
}
pressed &= ~(1 << (value - 1));
if (!pressed) {
if (committing) {
k_unicode(vc, BRL_UC_ROW | committing, 0, regs);
committing = 0;
}
}
} else {
if (committing) {
k_unicode(vc, BRL_UC_ROW | committing, 0, regs);
committing = 0;
}
pressed &= ~(1 << (value - 1));
}
} else {
pressed |= 1 << (value - 1);
if (!brl_timeout)
committing = pressed;
}
}
/*
* The leds display either (i) the status of NumLock, CapsLock, ScrollLock,
* or (ii) whatever pattern of lights people want to show using KDSETLED,
......@@ -1125,9 +1205,13 @@ static void kbd_keycode(unsigned int keycode, int down,
}
if (keycode > NR_KEYS)
if (keycode >= KEY_BRL_DOT1 && keycode <= KEY_BRL_DOT8)
keysym = K(KT_BRL, keycode - KEY_BRL_DOT1 + 1);
else
return;
else
keysym = key_map[keycode];
type = KTYP(keysym);
if (type < 0xf0) {
......
......@@ -512,6 +512,15 @@ struct input_absinfo {
#define KEY_FN_S 0x1e3
#define KEY_FN_B 0x1e4
#define KEY_BRL_DOT1 0x1f1
#define KEY_BRL_DOT2 0x1f2
#define KEY_BRL_DOT3 0x1f3
#define KEY_BRL_DOT4 0x1f4
#define KEY_BRL_DOT5 0x1f5
#define KEY_BRL_DOT6 0x1f6
#define KEY_BRL_DOT7 0x1f7
#define KEY_BRL_DOT8 0x1f8
/* We avoid low common keys in module aliases so they don't get huge. */
#define KEY_MIN_INTERESTING KEY_MUTE
#define KEY_MAX 0x1ff
......
......@@ -135,6 +135,8 @@ static inline void chg_vc_kbd_led(struct kbd_struct * kbd, int flag)
#define U(x) ((x) ^ 0xf000)
#define BRL_UC_ROW 0x2800
/* keyboard.c */
struct console;
......
......@@ -44,6 +44,7 @@ extern unsigned short plain_map[NR_KEYS];
#define KT_ASCII 9
#define KT_LOCK 10
#define KT_SLOCK 12
#define KT_BRL 14
#define K(t,v) (((t)<<8)|(v))
#define KTYP(x) ((x) >> 8)
......@@ -427,5 +428,17 @@ extern unsigned short plain_map[NR_KEYS];
#define NR_LOCK 8
#define K_BRL_BLANK K(KT_BRL, 0)
#define K_BRL_DOT1 K(KT_BRL, 1)
#define K_BRL_DOT2 K(KT_BRL, 2)
#define K_BRL_DOT3 K(KT_BRL, 3)
#define K_BRL_DOT4 K(KT_BRL, 4)
#define K_BRL_DOT5 K(KT_BRL, 5)
#define K_BRL_DOT6 K(KT_BRL, 6)
#define K_BRL_DOT7 K(KT_BRL, 7)
#define K_BRL_DOT8 K(KT_BRL, 8)
#define NR_BRL 9
#define MAX_DIACR 256
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment