From a400aedf2b6d2344a376bb262a59bfcdd713a2db Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 23 Dec 2016 02:05:59 +0800 Subject: [PATCH] HID: add special handling for Keyrah V2. --- usb/hid.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/usb/hid.c b/usb/hid.c index e9159b3..85e7ca1 100644 --- a/usb/hid.c +++ b/usb/hid.c @@ -584,6 +584,52 @@ static uint16_t collect_bits(uint8_t *p, uint16_t offset, uint8_t size, bool is_ return rval; } +static char kr_fn_table[] = +{ + 0x54, 0x48, // pause/break + 0x55, 0x46, // prnscr + 0x50, 0x4a, // home + 0x4f, 0x4d, // end + 0x52, 0x4b, // pgup + 0x51, 0x4e, // pgdown + 0x3a, 0x44, // f11 + 0x3b, 0x45 // f12 +}; + +static void keyrah_trans(unsigned char *m, unsigned char *k) +{ + char fn = 0; + char rctrl = 0; + int i = 0; + while(i<6) + { + if((k[i] == 0x64) || (k[i] == 0x32)) + { + if(k[i] == 0x64) fn = 1; + if(k[i] == 0x32) rctrl = 1; + for(int n = i; n<5; n++) k[n] = k[n+1]; + k[5] = 0; + } + else + { + i++; + } + } + + if(fn) + { + for(i=0; i<6; i++) + { + for(int n = 0; n<(sizeof(kr_fn_table)/(2*sizeof(kr_fn_table[0]))); n++) + { + if(k[i] == kr_fn_table[n*2]) k[i] = kr_fn_table[(n*2)+1]; + } + } + } + + *m = rctrl ? (*m) | 0x10 : (*m) & ~0x10; +} + /* processes a single USB interface */ static void usb_process_iface (usb_hid_iface_info_t *iface, uint16_t read, @@ -601,6 +647,8 @@ static void usb_process_iface (usb_hid_iface_info_t *iface, if(iface->device_type == HID_DEVICE_KEYBOARD) { // boot kbd needs at least eight bytes if(read >= 8) { + //Keyrah v2: USB\VID_18D8&PID_0002\A600/A1200_MULTIMEDIA_EXTENSION_VERSION + if((iface->conf.vid == 0x18D8) && (iface->conf.pid == 0x0002)) keyrah_trans(buf, buf+2); user_io_kbd(buf[0], buf+2, UIO_PRIORITY_KEYBOARD); } }