diff --git a/usb/hid.c b/usb/hid.c index de11832..1383054 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, @@ -584,6 +584,58 @@ 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) + { + 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++) + { + 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 +653,16 @@ 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); + check_reset(buf[0], 0); + } + else + { + check_reset(buf[0], 1); + } user_io_kbd(buf[0], buf+2, UIO_PRIORITY_KEYBOARD); } } @@ -738,13 +800,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; diff --git a/user_io.c b/user_io.c index c50f16b..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) { @@ -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<