From 00fea219ee4c8b1d85475b712392286f60599c25 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 23 Dec 2016 02:04:35 +0800 Subject: [PATCH 1/6] Store VID/PID for all HID devices. --- usb/hid.c | 10 +++++----- usb/hidparser.h | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/usb/hid.c b/usb/hid.c index de11832..e9159b3 100644 --- a/usb/hid.c +++ b/usb/hid.c @@ -327,6 +327,9 @@ static uint8_t usb_hid_init(usb_device_t *dev) { // process all supported interfaces for(i=0; ibNumIfaces; i++) { + info->iface[i].conf.pid = pid; + info->iface[i].conf.vid = vid; + // no boot mode, try to parse HID report descriptor // when running archie core force the usage of the HID descriptor as // boot mode only supports two buttons and the archie wants three @@ -349,9 +352,6 @@ static uint8_t usb_hid_init(usb_device_t *dev) { info->iface[i].conf.report_id, info->iface[i].conf.report_size); - info->iface[i].conf.joystick_mouse.pid = pid; - info->iface[i].conf.joystick_mouse.vid = vid; - for(k=0;k<2;k++) iprintf("Axis%d: %d@%d %d->%d\n", k, info->iface[i].conf.joystick_mouse.axis[k].size, @@ -738,13 +738,13 @@ static void usb_process_iface (usb_hid_iface_info_t *iface, jmap |= btn << JOY_BTN_SHIFT; // add buttons // report joystick 1 to OSD - StateUsbIdSet( conf->joystick_mouse.vid, conf->joystick_mouse.pid, conf->joystick_mouse.button_count, iface->jindex); + StateUsbIdSet( conf->vid, conf->pid, conf->joystick_mouse.button_count, iface->jindex); StateUsbJoySet( jmap, btn_extra, iface->jindex); // map virtual joypad uint16_t vjoy = jmap; vjoy |= btn_extra << 8; - vjoy = virtual_joystick_mapping( conf->joystick_mouse.vid, conf->joystick_mouse.pid, vjoy ); + vjoy = virtual_joystick_mapping( conf->vid, conf->pid, vjoy ); //iprintf("VIRTUAL JOY:%d\n", vjoy); //if (jmap != 0) iprintf("JMAP pre map:%d\n", jmap); diff --git a/usb/hidparser.h b/usb/hidparser.h index afdff01..bddb3a5 100644 --- a/usb/hidparser.h +++ b/usb/hidparser.h @@ -12,6 +12,10 @@ typedef struct { uint8_t report_id; uint8_t report_size; + // for downstream mapping + uint16_t vid; + uint16_t pid; + union { struct { struct { @@ -33,9 +37,6 @@ typedef struct { uint8_t size; } hat; // 1 hat (joystick only) - // for downstream mapping - uint16_t vid; - uint16_t pid; uint8_t button_count; } joystick_mouse; From a400aedf2b6d2344a376bb262a59bfcdd713a2db Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 23 Dec 2016 02:05:59 +0800 Subject: [PATCH 2/6] 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); } } From 3fe3af8d29b3dbf46883ec1347c5446d30446801 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 23 Dec 2016 02:42:25 +0800 Subject: [PATCH 3/6] Revert "esa10: user_io.c fix -> re-intialize SPI, make sure all other" This reverts commit 4c4abb62fd8bc38e41c029581f93c743f9a00c1a. --- user_io.c | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/user_io.c b/user_io.c index 20c9a7b..c50f16b 100644 --- a/user_io.c +++ b/user_io.c @@ -195,40 +195,19 @@ static void user_io_read_core_name() { void user_io_detect_core_type() { core_name[0] = 0; - int retry = 0; - // make sure to have SPI initialized - // and cycle enable/disable all other - // SPI devices which could be possibly left enabled - // and cause the contention of the shared SPI bus - spi_init(); - EnableCard(); - DisableCard(); - EnableFpga(); - DisableFpga(); - EnableOsd(); - DisableOsd(); - EnableDMode(); - DisableDMode(); + EnableIO(); + core_type = SPI(0xff); + DisableIO(); - core_type = CORE_TYPE_UNKNOWN; - while(retry++ < 15 && core_type == CORE_TYPE_UNKNOWN) - { - TIMER_wait(100); - EnableIO(); - core_type = SPI(0xff); - DisableIO(); - iprintf("Detecting core type (0x%02x), retry %d\n", core_type, retry); - - if((core_type != CORE_TYPE_DUMB) && - (core_type != CORE_TYPE_MINIMIG) && - (core_type != CORE_TYPE_MINIMIG2) && - (core_type != CORE_TYPE_PACE) && - (core_type != CORE_TYPE_MIST) && - (core_type != CORE_TYPE_ARCHIE) && - (core_type != CORE_TYPE_8BIT)) - core_type = CORE_TYPE_UNKNOWN; - } + if((core_type != CORE_TYPE_DUMB) && + (core_type != CORE_TYPE_MINIMIG) && + (core_type != CORE_TYPE_MINIMIG2) && + (core_type != CORE_TYPE_PACE) && + (core_type != CORE_TYPE_MIST) && + (core_type != CORE_TYPE_ARCHIE) && + (core_type != CORE_TYPE_8BIT)) + core_type = CORE_TYPE_UNKNOWN; switch(core_type) { case CORE_TYPE_UNKNOWN: From 62b6aead5e59f81eb7dc06f777eca8575d61d74a Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 23 Dec 2016 04:03:38 +0800 Subject: [PATCH 4/6] Keyrah: Fn+LCtrl+LAmiga+LAmiga - hard reset. --- usb/hid.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/usb/hid.c b/usb/hid.c index 85e7ca1..df6eb2a 100644 --- a/usb/hid.c +++ b/usb/hid.c @@ -618,6 +618,12 @@ static void keyrah_trans(unsigned char *m, unsigned char *k) if(fn) { + if(*m == 0x89) + { + *AT91C_RSTC_RCR = 0xA5 << 24 | AT91C_RSTC_PERRST | AT91C_RSTC_PROCRST | AT91C_RSTC_EXTRST; // reset + for(;;); + } + for(i=0; i<6; i++) { for(int n = 0; n<(sizeof(kr_fn_table)/(2*sizeof(kr_fn_table[0]))); n++) From 3d4bf9eaa67de40f79adece9fd64a585236f2ea7 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Fri, 23 Dec 2016 06:28:21 +0800 Subject: [PATCH 5/6] Keyrah: Use LCtrl+LAmiga+LAmiga for Minimig reset. --- usb/hid.c | 10 +++++++++- user_io.c | 7 ++----- user_io.h | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/usb/hid.c b/usb/hid.c index df6eb2a..1383054 100644 --- a/usb/hid.c +++ b/usb/hid.c @@ -654,7 +654,15 @@ static void usb_process_iface (usb_hid_iface_info_t *iface, // 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); + if((iface->conf.vid == 0x18D8) && (iface->conf.pid == 0x0002)) + { + keyrah_trans(buf, buf+2); + check_reset(buf[0], 0); + } + else + { + check_reset(buf[0], 1); + } user_io_kbd(buf[0], buf+2, UIO_PRIORITY_KEYBOARD); } } diff --git a/user_io.c b/user_io.c index c50f16b..d36ec2a 100644 --- a/user_io.c +++ b/user_io.c @@ -1379,10 +1379,10 @@ unsigned short keycode(unsigned char in) { return MISS; } -void check_reset(unsigned char modifiers) { +void check_reset(unsigned char modifiers, char useAlt) { if((core_type == CORE_TYPE_MINIMIG) || (core_type == CORE_TYPE_MINIMIG2)) { - if(modifiers == 0x45) // ctrl - alt - alt + if(modifiers == (useAlt ? 0x45 : 0x89)) // ctrl - alt - alt / ctrl - amiga - amiga OsdReset(RESET_NORMAL); } } @@ -1533,9 +1533,6 @@ void user_io_kbd(unsigned char m, unsigned char *k, uint8_t priority) { for(i=0;i<8;i++) { // Do we have a downstroke on a modifier key? if((m & (1< Date: Fri, 23 Dec 2016 08:18:24 +0800 Subject: [PATCH 6/6] Fix Minimig key extended flags (Caps Lock, Num Lock, Scroll Lock). --- user_io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_io.c b/user_io.c index d36ec2a..4448bb4 100644 --- a/user_io.c +++ b/user_io.c @@ -288,7 +288,7 @@ void user_io_detect_core_type() { } } -unsigned char usb2amiga( unsigned char k ) { +unsigned short usb2amiga( unsigned char k ) { // replace MENU key by RGUI to allow using Right Amiga on reduced keyboards // (it also disables the use of Menu for OSD) if (mist_cfg.key_menu_as_rgui && k==0x65) {