diff --git a/VoodooPS2Controller.xcodeproj/project.pbxproj b/VoodooPS2Controller.xcodeproj/project.pbxproj index 324e275c..f0fdc456 100644 --- a/VoodooPS2Controller.xcodeproj/project.pbxproj +++ b/VoodooPS2Controller.xcodeproj/project.pbxproj @@ -19,7 +19,7 @@ 84833FA3161B627D00845294 /* ApplePS2Device.h in Headers */ = {isa = PBXBuildFile; fileRef = 84833F9D161B627D00845294 /* ApplePS2Device.h */; settings = {ATTRIBUTES = (); }; }; 84833FA5161B627D00845294 /* ApplePS2KeyboardDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84833F9F161B627D00845294 /* ApplePS2KeyboardDevice.h */; settings = {ATTRIBUTES = (); }; }; 84833FA7161B627D00845294 /* ApplePS2MouseDevice.h in Headers */ = {isa = PBXBuildFile; fileRef = 84833FA1161B627D00845294 /* ApplePS2MouseDevice.h */; settings = {ATTRIBUTES = (); }; }; - 84833FAA161B629500845294 /* ApplePS2ToHIDMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 84833FA9161B629500845294 /* ApplePS2ToHIDMap.h */; settings = {ATTRIBUTES = (); }; }; + 84833FAA161B629500845294 /* ApplePS2ToADBMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 84833FA9161B629500845294 /* ApplePS2ToADBMap.h */; settings = {ATTRIBUTES = (); }; }; 84833FB1161B62A900845294 /* VoodooPS2ALPSGlidePoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84833FAB161B62A900845294 /* VoodooPS2ALPSGlidePoint.cpp */; }; 84833FB2161B62A900845294 /* VoodooPS2ALPSGlidePoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 84833FAC161B62A900845294 /* VoodooPS2ALPSGlidePoint.h */; settings = {ATTRIBUTES = (); }; }; 84833FB3161B62A900845294 /* VoodooPS2SentelicFSP.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84833FAD161B62A900845294 /* VoodooPS2SentelicFSP.cpp */; }; @@ -39,9 +39,6 @@ CE8DA1C6251839B7008C44E8 /* libkmod.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE8DA1C4251839B2008C44E8 /* libkmod.a */; }; CE8DA1C7251839B9008C44E8 /* libkmod.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE8DA1C4251839B2008C44E8 /* libkmod.a */; }; CE8DA1CC251839BC008C44E8 /* libkmod.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE8DA1C4251839B2008C44E8 /* libkmod.a */; }; - EE4CEE1C2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = EE4CEE1A2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.cpp */; }; - EE4CEE1D2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.hpp in Headers */ = {isa = PBXBuildFile; fileRef = EE4CEE1B2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.hpp */; }; - EE4CEE252A9D8AF800314737 /* VoodooPS2EventDriver.hpp in Headers */ = {isa = PBXBuildFile; fileRef = EE4CEE232A9D8AF800314737 /* VoodooPS2EventDriver.hpp */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -103,7 +100,7 @@ 84833F9F161B627D00845294 /* ApplePS2KeyboardDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ApplePS2KeyboardDevice.h; path = VoodooPS2Controller/ApplePS2KeyboardDevice.h; sourceTree = ""; }; 84833FA0161B627D00845294 /* ApplePS2MouseDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ApplePS2MouseDevice.cpp; sourceTree = ""; }; 84833FA1161B627D00845294 /* ApplePS2MouseDevice.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ApplePS2MouseDevice.h; path = VoodooPS2Controller/ApplePS2MouseDevice.h; sourceTree = ""; }; - 84833FA9161B629500845294 /* ApplePS2ToHIDMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplePS2ToHIDMap.h; sourceTree = ""; }; + 84833FA9161B629500845294 /* ApplePS2ToADBMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApplePS2ToADBMap.h; sourceTree = ""; }; 84833FAB161B62A900845294 /* VoodooPS2ALPSGlidePoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = VoodooPS2ALPSGlidePoint.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; 84833FAC161B62A900845294 /* VoodooPS2ALPSGlidePoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VoodooPS2ALPSGlidePoint.h; sourceTree = ""; }; 84833FAD161B62A900845294 /* VoodooPS2SentelicFSP.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = VoodooPS2SentelicFSP.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; @@ -134,9 +131,6 @@ EDD95559208E2B640031D99E /* SSDT-Thinkpad_Clickpad.dsl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "SSDT-Thinkpad_Clickpad.dsl"; sourceTree = ""; }; EDD9555A208E2E7A0031D99E /* SSDT-Thinkpad_Trackpad.dsl */ = {isa = PBXFileReference; lastKnownFileType = text; path = "SSDT-Thinkpad_Trackpad.dsl"; sourceTree = ""; }; EDD970FD1FD0B826004CCFFD /* SSDT-HP-FixLidSleep.dsl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "SSDT-HP-FixLidSleep.dsl"; sourceTree = ""; }; - EE4CEE1A2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VoodooPS2KeyboardHIDWrapper.cpp; sourceTree = ""; }; - EE4CEE1B2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = VoodooPS2KeyboardHIDWrapper.hpp; sourceTree = ""; }; - EE4CEE232A9D8AF800314737 /* VoodooPS2EventDriver.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = VoodooPS2EventDriver.hpp; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -242,13 +236,10 @@ 8416782E161B5613002C60E6 /* VoodooPS2Keyboard */ = { isa = PBXGroup; children = ( - 84833FA9161B629500845294 /* ApplePS2ToHIDMap.h */, + 84833FA9161B629500845294 /* ApplePS2ToADBMap.h */, 84167834161B5613002C60E6 /* VoodooPS2Keyboard.h */, 84167835161B5613002C60E6 /* VoodooPS2Keyboard.cpp */, 8416782F161B5613002C60E6 /* Supporting Files */, - EE4CEE1A2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.cpp */, - EE4CEE1B2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.hpp */, - EE4CEE232A9D8AF800314737 /* VoodooPS2EventDriver.hpp */, ); path = VoodooPS2Keyboard; sourceTree = ""; @@ -382,10 +373,8 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 84833FAA161B629500845294 /* ApplePS2ToHIDMap.h in Headers */, + 84833FAA161B629500845294 /* ApplePS2ToADBMap.h in Headers */, 84833FC2161B69C700845294 /* VoodooPS2Keyboard.h in Headers */, - EE4CEE1D2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.hpp in Headers */, - EE4CEE252A9D8AF800314737 /* VoodooPS2EventDriver.hpp in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -645,7 +634,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - EE4CEE1C2A9D85DA00314737 /* VoodooPS2KeyboardHIDWrapper.cpp in Sources */, 84167836161B5613002C60E6 /* VoodooPS2Keyboard.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -777,7 +765,7 @@ KERNEL_FRAMEWORK_HEADERS = "$(PROJECT_DIR)/MacKernelSDK/Headers"; "LLVM_LTO[arch=x86_64]" = YES; MACOSX_DEPLOYMENT_TARGET = 10.11; - MODULE_VERSION = 3.0.0; + MODULE_VERSION = 2.3.6; ONLY_ACTIVE_ARCH = YES; "OTHER_LDFLAGS[arch=x86_64]" = "-dead_strip"; PRODUCT_NAME = VoodooPS2Controller; @@ -832,7 +820,7 @@ KERNEL_FRAMEWORK_HEADERS = "$(PROJECT_DIR)/MacKernelSDK/Headers"; "LLVM_LTO[arch=x86_64]" = YES; MACOSX_DEPLOYMENT_TARGET = 10.11; - MODULE_VERSION = 3.0.0; + MODULE_VERSION = 2.3.6; "OTHER_LDFLAGS[arch=x86_64]" = "-dead_strip"; PRODUCT_NAME = VoodooPS2Controller; SDKROOT = macosx; @@ -857,7 +845,7 @@ ); MODULE_NAME = as.acidanthera.driver.VoodooPS2Controller; OTHER_CFLAGS = "-fno-stack-protector"; - PRODUCT_BUNDLE_IDENTIFIER = com.1revenger1.PS2Controller; + PRODUCT_BUNDLE_IDENTIFIER = as.acidanthera.voodoo.driver.PS2Controller; PRODUCT_NAME = "$(TARGET_NAME)"; RUN_CLANG_STATIC_ANALYZER = YES; STRIP_INSTALLED_PRODUCT = YES; @@ -878,7 +866,7 @@ ); MODULE_NAME = as.acidanthera.driver.VoodooPS2Controller; OTHER_CFLAGS = "-fno-stack-protector"; - PRODUCT_BUNDLE_IDENTIFIER = com.1revenger1.PS2Controller; + PRODUCT_BUNDLE_IDENTIFIER = as.acidanthera.voodoo.driver.PS2Controller; PRODUCT_NAME = "$(TARGET_NAME)"; STRIP_INSTALLED_PRODUCT = YES; STRIP_STYLE = "non-global"; @@ -902,7 +890,7 @@ ); MODULE_NAME = as.acidanthera.driver.VoodooPS2Keyboard; OTHER_CFLAGS = "-fno-stack-protector"; - PRODUCT_BUNDLE_IDENTIFIER = com.1revenger1.PS2Keyboard; + PRODUCT_BUNDLE_IDENTIFIER = as.acidanthera.voodoo.driver.PS2Keyboard; PRODUCT_NAME = "$(TARGET_NAME)"; RUN_CLANG_STATIC_ANALYZER = YES; STRIP_INSTALLED_PRODUCT = YES; @@ -924,7 +912,7 @@ ); MODULE_NAME = as.acidanthera.driver.VoodooPS2Keyboard; OTHER_CFLAGS = "-fno-stack-protector"; - PRODUCT_BUNDLE_IDENTIFIER = com.1revenger1.PS2Keyboard; + PRODUCT_BUNDLE_IDENTIFIER = as.acidanthera.voodoo.driver.PS2Keyboard; PRODUCT_NAME = "$(TARGET_NAME)"; STRIP_INSTALLED_PRODUCT = YES; STRIP_STYLE = "non-global"; @@ -948,7 +936,7 @@ ); MODULE_NAME = as.acidanthera.driver.VoodooPS2Mouse; OTHER_CFLAGS = "-fno-stack-protector"; - PRODUCT_BUNDLE_IDENTIFIER = com.1revenger1.PS2Mouse; + PRODUCT_BUNDLE_IDENTIFIER = as.acidanthera.voodoo.driver.PS2Mouse; PRODUCT_NAME = "$(TARGET_NAME)"; RUN_CLANG_STATIC_ANALYZER = YES; STRIP_INSTALLED_PRODUCT = YES; @@ -970,7 +958,7 @@ ); MODULE_NAME = as.acidanthera.driver.VoodooPS2Mouse; OTHER_CFLAGS = "-fno-stack-protector"; - PRODUCT_BUNDLE_IDENTIFIER = com.1revenger1.PS2Mouse; + PRODUCT_BUNDLE_IDENTIFIER = as.acidanthera.voodoo.driver.PS2Mouse; PRODUCT_NAME = "$(TARGET_NAME)"; STRIP_INSTALLED_PRODUCT = YES; STRIP_STYLE = "non-global"; @@ -995,7 +983,7 @@ ); MODULE_NAME = as.acidanthera.driver.VoodooPS2Trackpad; OTHER_CFLAGS = "-fno-stack-protector"; - PRODUCT_BUNDLE_IDENTIFIER = com.1revenger1.PS2Trackpad; + PRODUCT_BUNDLE_IDENTIFIER = as.acidanthera.voodoo.driver.PS2Trackpad; PRODUCT_NAME = "$(TARGET_NAME)"; RUN_CLANG_STATIC_ANALYZER = YES; STRIP_INSTALLED_PRODUCT = YES; @@ -1018,7 +1006,7 @@ ); MODULE_NAME = as.acidanthera.driver.VoodooPS2Trackpad; OTHER_CFLAGS = "-fno-stack-protector"; - PRODUCT_BUNDLE_IDENTIFIER = com.1revenger1.PS2Trackpad; + PRODUCT_BUNDLE_IDENTIFIER = as.acidanthera.voodoo.driver.PS2Trackpad; PRODUCT_NAME = "$(TARGET_NAME)"; STRIP_INSTALLED_PRODUCT = YES; STRIP_STYLE = "non-global"; diff --git a/VoodooPS2Controller/VoodooPS2Controller.cpp b/VoodooPS2Controller/VoodooPS2Controller.cpp index 6194e90e..497b47bc 100644 --- a/VoodooPS2Controller/VoodooPS2Controller.cpp +++ b/VoodooPS2Controller/VoodooPS2Controller.cpp @@ -2126,7 +2126,7 @@ static OSString* getPlatformOverride(IORegistryEntry* reg, const char* sz) return NULL; } -static LIBKERN_RETURNS_RETAINED OSString* getPlatformManufacturer(IORegistryEntry* reg) +static OSString* getPlatformManufacturer(IORegistryEntry* reg) { // allow override in PS2K ACPI device OSString* id = getPlatformOverride(reg, "RM,oem-id"); @@ -2148,7 +2148,7 @@ static LIBKERN_RETURNS_RETAINED OSString* getPlatformManufacturer(IORegistryEntr return OSString::withCStringNoCopy(oemID); } -static LIBKERN_RETURNS_RETAINED OSString* getPlatformProduct(IORegistryEntry* reg) +static OSString* getPlatformProduct(IORegistryEntry* reg) { // allow override in PS2K ACPI device OSString* id = getPlatformOverride(reg, "RM,oem-table-id"); diff --git a/VoodooPS2Keyboard/ApplePS2ToHIDMap.h b/VoodooPS2Keyboard/ApplePS2ToADBMap.h similarity index 53% rename from VoodooPS2Keyboard/ApplePS2ToHIDMap.h rename to VoodooPS2Keyboard/ApplePS2ToADBMap.h index b2158217..022536ee 100644 --- a/VoodooPS2Keyboard/ApplePS2ToHIDMap.h +++ b/VoodooPS2Keyboard/ApplePS2ToADBMap.h @@ -23,119 +23,122 @@ #ifndef _APPLEPS2TOADBMAP_H #define _APPLEPS2TOADBMAP_H -#include -#include - #define PROBOOK -#define DEADKEY 0x00 -#define DEADKEY_EXTENDED { 0, 0 } +#define DEADKEY 0x80 -#define BRIGHTNESS_DOWN { kHIDPage_AppleVendorTopCase, kHIDUsage_AV_TopCase_BrightnessDown } -#define BRIGHTNESS_UP { kHIDPage_AppleVendorTopCase, kHIDUsage_AV_TopCase_BrightnessUp } +#if 0 +// These ADB codes are for normal NX key brightness (broken in 10.12) +#define BRIGHTNESS_DOWN 0x91 +#define BRIGHTNESS_UP 0x90 +#else +// These ADB codes are for F14/F15 (works in 10.12) +#define BRIGHTNESS_DOWN 0x6b +#define BRIGHTNESS_UP 0x71 +#endif -#define ADB_CONVERTER_LEN 256 // 0x00~0xff : normal key , 0x100~0x1ff : extended key +#define ADB_CONVERTER_LEN 256 * 2 // 0x00~0xff : normal key , 0x100~0x1ff : extended key #define ADB_CONVERTER_EX_START 256 // PS/2 scancode reference : USB HID to PS/2 Scan Code Translation Table PS/2 Set 1 columns // http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/translate.pdf -static const UInt8 PS2ToHIDMapStock[ADB_CONVERTER_LEN] = +static const UInt8 PS2ToADBMapStock[ADB_CONVERTER_LEN] = { -/* HID AT ANSI Key-Legend +/* ADB AT ANSI Key-Legend ======================== */ - DEADKEY, // 00 - kHIDUsage_KeyboardEscape, // 01 Escape - kHIDUsage_Keyboard1, // 02 1! - kHIDUsage_Keyboard2, // 03 2@ - kHIDUsage_Keyboard3, // 04 3# - kHIDUsage_Keyboard4, // 05 4$ - kHIDUsage_Keyboard5, // 06 5% - kHIDUsage_Keyboard6, // 07 6^ - kHIDUsage_Keyboard7, // 08 7& - kHIDUsage_Keyboard8, // 09 8* - kHIDUsage_Keyboard9, // 0a 9( - kHIDUsage_Keyboard0, // 0b 0) - kHIDUsage_KeyboardHyphen, // 0c -_ - kHIDUsage_KeyboardEqualSign,// 0d =+ - kHIDUsage_KeyboardDeleteOrBackspace, // 0e Backspace - kHIDUsage_KeyboardTab, // 0f Tab - kHIDUsage_KeyboardQ, // 10 qQ - kHIDUsage_KeyboardW, // 11 wW - kHIDUsage_KeyboardE, // 12 eE - kHIDUsage_KeyboardR, // 13 rR - kHIDUsage_KeyboardT, // 14 tT - kHIDUsage_KeyboardY, // 15 yY - kHIDUsage_KeyboardU, // 16 uU - kHIDUsage_KeyboardI, // 17 iI - kHIDUsage_KeyboardO, // 18 oO - kHIDUsage_KeyboardP, // 19 pP - kHIDUsage_KeyboardOpenBracket, // 1a [{ - kHIDUsage_KeyboardCloseBracket, // 1b ]} - kHIDUsage_KeyboardReturnOrEnter, // 1c Return - kHIDUsage_KeyboardLeftControl, // 1d Left Control - kHIDUsage_KeyboardA, // 1e aA - kHIDUsage_KeyboardS, // 1f sS - kHIDUsage_KeyboardD, // 20 dD - kHIDUsage_KeyboardF, // 21 fF - kHIDUsage_KeyboardG, // 22 gG - kHIDUsage_KeyboardH, // 23 hH - kHIDUsage_KeyboardJ, // 24 jJ - kHIDUsage_KeyboardK, // 25 kK - kHIDUsage_KeyboardL, // 26 lL - kHIDUsage_KeyboardSemicolon,// 27 ;: - kHIDUsage_KeyboardQuote, // 28 '" - kHIDUsage_KeyboardGraveAccentAndTilde, // 29 `~ - kHIDUsage_KeyboardLeftShift, // 2a Left Shift - kHIDUsage_KeyboardBackslash, // 2b \| , Europe 1(ISO) - kHIDUsage_KeyboardZ, // 2c zZ - kHIDUsage_KeyboardX, // 2d xX - kHIDUsage_KeyboardC, // 2e cC - kHIDUsage_KeyboardV, // 2f vV - kHIDUsage_KeyboardB, // 30 bB - kHIDUsage_KeyboardN, // 31 nN - kHIDUsage_KeyboardM, // 32 mM - kHIDUsage_KeyboardComma, // 33 ,< - kHIDUsage_KeyboardPeriod, // 34 .> - kHIDUsage_KeyboardSlash, // 35 /? - kHIDUsage_KeyboardRightShift, // 36 Right Shift - kHIDUsage_KeypadAsterisk, // 37 Keypad * - kHIDUsage_KeyboardLeftAlt, // 38 Left Alt - kHIDUsage_KeyboardSpacebar, // 39 Space - kHIDUsage_KeyboardCapsLock, // 3a Caps Lock - kHIDUsage_KeyboardF1, // 3b F1 - kHIDUsage_KeyboardF2, // 3c F2 - kHIDUsage_KeyboardF3, // 3d F3 - kHIDUsage_KeyboardF4, // 3e F4 - kHIDUsage_KeyboardF5, // 3f F5 - kHIDUsage_KeyboardF6, // 40 F6 - kHIDUsage_KeyboardF7, // 41 F7 - kHIDUsage_KeyboardF8, // 42 F8 - kHIDUsage_KeyboardF9, // 43 F9 - kHIDUsage_KeyboardF10, // 44 F10 - kHIDUsage_KeypadNumLock, // 45 Num Lock - kHIDUsage_KeyboardScrollLock, // 46 Scroll Lock - kHIDUsage_Keypad7, // 47 Keypad 7 Home - kHIDUsage_Keypad8, // 48 Keypad 8 Up - kHIDUsage_Keypad9, // 49 Keypad 9 PageUp - kHIDUsage_KeypadHyphen, // 4a Keypad - - kHIDUsage_Keypad4, // 4b Keypad 4 Left - kHIDUsage_Keypad5, // 4c Keypad 5 - kHIDUsage_Keypad6, // 4d Keypad 6 Right - kHIDUsage_KeypadPlus, // 4e Keypad + - kHIDUsage_Keypad1, // 4f Keypad 1 End - kHIDUsage_Keypad2, // 50 Keypad 2 Down - kHIDUsage_Keypad3, // 51 Keypad 3 PageDn - kHIDUsage_Keypad0, // 52 Keypad 0 Insert - kHIDUsage_KeypadPeriod, // 53 Keypad . Delete - kHIDUsage_KeyboardSysReqOrAttention, // 54 SysReq + DEADKEY,// 00 + 0x35, // 01 Escape + 0x12, // 02 1! + 0x13, // 03 2@ + 0x14, // 04 3# + 0x15, // 05 4$ + 0x17, // 06 5% + 0x16, // 07 6^ + 0x1a, // 08 7& + 0x1c, // 09 8* + 0x19, // 0a 9( + 0x1d, // 0b 0) + 0x1b, // 0c -_ + 0x18, // 0d =+ + 0x33, // 0e Backspace + 0x30, // 0f Tab + 0x0c, // 10 qQ + 0x0d, // 11 wW + 0x0e, // 12 eE + 0x0f, // 13 rR + 0x11, // 14 tT + 0x10, // 15 yY + 0x20, // 16 uU + 0x22, // 17 iI + 0x1f, // 18 oO + 0x23, // 19 pP + 0x21, // 1a [{ + 0x1e, // 1b ]} + 0x24, // 1c Return + 0x3b, // 1d Left Control + 0x00, // 1e aA + 0x01, // 1f sS + 0x02, // 20 dD + 0x03, // 21 fF + 0x05, // 22 gG + 0x04, // 23 hH + 0x26, // 24 jJ + 0x28, // 25 kK + 0x25, // 26 lL + 0x29, // 27 ;: + 0x27, // 28 '" + 0x32, // 29 `~ + 0x38, // 2a Left Shift + 0x2a, // 2b \| , Europe 1(ISO) + 0x06, // 2c zZ + 0x07, // 2d xX + 0x08, // 2e cC + 0x09, // 2f vV + 0x0b, // 30 bB + 0x2d, // 31 nN + 0x2e, // 32 mM + 0x2b, // 33 ,< + 0x2f, // 34 .> + 0x2c, // 35 /? + 0x3c, // 36 Right Shift + 0x43, // 37 Keypad * + 0x3a, // 38 Left Alt + 0x31, // 39 Space + 0x39, // 3a Caps Lock + 0x7a, // 3b F1 + 0x78, // 3c F2 + 0x63, // 3d F3 + 0x76, // 3e F4 + 0x60, // 3f F5 + 0x61, // 40 F6 + 0x62, // 41 F7 + 0x64, // 42 F8 + 0x65, // 43 F9 + 0x6d, // 44 F10 + 0x47, // 45 Num Lock + 0x6b, // 46 Scroll Lock + 0x59, // 47 Keypad 7 Home + 0x5b, // 48 Keypad 8 Up + 0x5c, // 49 Keypad 9 PageUp + 0x4e, // 4a Keypad - + 0x56, // 4b Keypad 4 Left + 0x57, // 4c Keypad 5 + 0x58, // 4d Keypad 6 Right + 0x45, // 4e Keypad + + 0x53, // 4f Keypad 1 End + 0x54, // 50 Keypad 2 Down + 0x55, // 51 Keypad 3 PageDn + 0x52, // 52 Keypad 0 Insert + 0x41, // 53 Keypad . Delete + 0x44, // 54 SysReq 0x46, // 55 - kHIDUsage_KeyboardNonUSBackslash, // 56 Europe 2(ISO) - kHIDUsage_KeyboardF11, // 57 F11 - kHIDUsage_KeyboardF12, // 58 F12 - kHIDUsage_KeypadEqualSign, // 59 Keypad = + 0x0a, // 56 Europe 2(ISO) + 0x67, // 57 F11 + 0x6f, // 58 F12 + 0x51, // 59 Keypad = DEADKEY,// 5a DEADKEY,// 5b - kHIDUsage_KeyboardInternational6, // 5c Keyboard Int'l 6 (PC9800 Keypad , ) + 0x5f, // 5c Keyboard Int'l 6 (PC9800 Keypad , ) DEADKEY,// 5d DEADKEY,// 5e DEADKEY,// 5f @@ -143,33 +146,33 @@ static const UInt8 PS2ToHIDMapStock[ADB_CONVERTER_LEN] = DEADKEY,// 61 DEADKEY,// 62 DEADKEY,// 63 - kHIDUsage_KeyboardF13, // 64 F13 - kHIDUsage_KeyboardF14, // 65 F14 - kHIDUsage_KeyboardF15, // 66 F15 - kHIDUsage_KeyboardF16, // 67 F16 - kHIDUsage_KeyboardF17, // 68 F17 - kHIDUsage_KeyboardF18, // 69 F18 - kHIDUsage_KeyboardF19, // 6a F19 - kHIDUsage_KeyboardF20, // 6b F20 - kHIDUsage_KeyboardF21, // 6c F21 - kHIDUsage_KeyboardF22, // 6d F22 - kHIDUsage_KeyboardF23, // 6e F23 + 0x69, // 64 F13 + 0x6b, // 65 F14 + 0x71, // 66 F15 + 0x6a, // 67 F16 + 0x40, // 68 F17 + 0x4f, // 69 F18 + 0x50, // 6a F19 + 0x5a, // 6b F20 + DEADKEY,// 6c F21 + DEADKEY,// 6d F22 + DEADKEY,// 6e F23 DEADKEY,// 6f - kHIDUsage_KeyboardInternational2, // 70 Keyboard Intl'2 (Japanese Katakana/Hiragana) + 0x68, // 70 Keyboard Intl'2 (Japanese Katakana/Hiragana) DEADKEY,// 71 DEADKEY,// 72 - kHIDUsage_KeyboardInternational1, // 73 Keyboard Int'l 1 (Japanese Ro) + 0x5e, // 73 Keyboard Int'l 1 (Japanese Ro) DEADKEY,// 74 DEADKEY,// 75 - kHIDUsage_KeyboardF24, // 76 F24 , Keyboard Lang 5 (Japanese Zenkaku/Hankaku) - kHIDUsage_KeyboardLANG4, // 77 Keyboard Lang 4 (Japanese Hiragana) - kHIDUsage_KeyboardLANG3, // 78 Keyboard Lang 3 (Japanese Katakana) - kHIDUsage_KeyboardInternational4, // 79 Keyboard Int'l 4 (Japanese Henkan) + DEADKEY,// 76 F24 , Keyboard Lang 5 (Japanese Zenkaku/Hankaku) + 0x68, // 77 Keyboard Lang 4 (Japanese Hiragana) + 0x68, // 78 Keyboard Lang 3 (Japanese Katakana) + 0x68, // 79 Keyboard Int'l 4 (Japanese Henkan) DEADKEY,// 7a - kHIDUsage_KeyboardInternational5, // 7b Keyboard Int'l 5 (Japanese Muhenkan) + 0x66, // 7b Keyboard Int'l 5 (Japanese Muhenkan) DEADKEY,// 7c - kHIDUsage_KeyboardInternational3, // 7d Keyboard Int'l 3 (Japanese Yen) - kHIDUsage_KeypadComma, // 7e Keypad , (Brazilian Keypad .) + 0x5d, // 7d Keyboard Int'l 3 (Japanese Yen) + 0x5f, // 7e Keypad , (Brazilian Keypad .) DEADKEY,// 7f DEADKEY,// 80 DEADKEY,// 81 @@ -284,8 +287,8 @@ static const UInt8 PS2ToHIDMapStock[ADB_CONVERTER_LEN] = DEADKEY,// ee DEADKEY,// ef DEADKEY,// f0 - kHIDUsage_KeyboardLANG2, // f1* Keyboard Lang 2 (Korean Hanja) - kHIDUsage_KeyboardLANG1, // f2* Keyboard Lang 1 (Korean Hangul) + 0x66, // f1* Keyboard Lang 2 (Korean Hanja) + 0x68, // f2* Keyboard Lang 1 (Korean Hangul) DEADKEY,// f3 DEADKEY,// f4 DEADKEY,// f5 @@ -298,289 +301,278 @@ static const UInt8 PS2ToHIDMapStock[ADB_CONVERTER_LEN] = DEADKEY,// fc DEADKEY,// fd DEADKEY,// fe - DEADKEY,// ff -}; - -struct VoodooPS2HidElement { - uint16_t usagePage; - uint16_t usage; -}; - -#define KEY(a) { kHIDPage_KeyboardOrKeypad, (a)} -#define MEDIA(a) { kHIDPage_Consumer, (a)} - -static const VoodooPS2HidElement ExtendedPS2ToHIDStockMap[ADB_CONVERTER_LEN] { - DEADKEY_EXTENDED,// e0 00 - DEADKEY_EXTENDED,// e0 01 - DEADKEY_EXTENDED,// e0 02 - DEADKEY_EXTENDED,// e0 03 - DEADKEY_EXTENDED,// e0 04 - BRIGHTNESS_DOWN, // e0 05 dell down - BRIGHTNESS_UP, // e0 06 dell up - DEADKEY_EXTENDED,// e0 07 + DEADKEY,// ff + DEADKEY,// e0 00 + DEADKEY,// e0 01 + DEADKEY,// e0 02 + DEADKEY,// e0 03 + DEADKEY,// e0 04 + BRIGHTNESS_DOWN, // e0 05 dell down + BRIGHTNESS_UP, // e0 06 dell up + DEADKEY,// e0 07 #ifndef PROBOOK BRIGHTNESS_UP, // e0 08 samsung up BRIGHTNESS_DOWN, // e0 09 samsung down #else - DEADKEY_EXTENDED,// e0 08 - { kHIDPage_AppleVendorKeyboard, kHIDUsage_AppleVendorKeyboard_Launchpad }, // e0 09 Launchpad (hp Fn+F6) + DEADKEY,// e0 08 + 0x83, // e0 09 Launchpad (hp Fn+F6) #endif - { kHIDPage_AppleVendorKeyboard, kHIDUsage_AppleVendorKeyboard_Expose_All }, // e0 0a Mission Control (hp Fn+F5) - DEADKEY_EXTENDED,// e0 0b - DEADKEY_EXTENDED,// e0 0c - DEADKEY_EXTENDED,// e0 0d - DEADKEY_EXTENDED,// e0 0e - DEADKEY_EXTENDED,// e0 0f - MEDIA ( kHIDUsage_Csmr_ScanPreviousTrack ), // e0 10 Scan Previous Track (hp Fn+F10) - DEADKEY_EXTENDED,// e0 11 + 0xa0, // e0 0a Mission Control (hp Fn+F5) + DEADKEY,// e0 0b + DEADKEY,// e0 0c + DEADKEY,// e0 0d + DEADKEY,// e0 0e + DEADKEY,// e0 0f + 0x4d, // e0 10 Scan Previous Track (hp Fn+F10) + DEADKEY,// e0 11 BRIGHTNESS_DOWN, // e0 12 hp down (Fn+F2) - DEADKEY_EXTENDED,// e0 13 - DEADKEY_EXTENDED,// e0 14 - DEADKEY_EXTENDED,// e0 15 - DEADKEY_EXTENDED,// e0 16 + DEADKEY,// e0 13 + DEADKEY,// e0 14 + DEADKEY,// e0 15 + DEADKEY,// e0 16 BRIGHTNESS_UP, // e0 17 hp up (Fn+F3) - DEADKEY_EXTENDED,// e0 18 - MEDIA ( kHIDUsage_Csmr_ScanNextTrack ), // e0 19 Scan Next Track (hp Fn+F12) - DEADKEY_EXTENDED,// e0 1a - DEADKEY_EXTENDED,// e0 1b - KEY( kHIDUsage_KeypadEnter ), // e0 1c Keypad Enter - KEY( kHIDUsage_KeyboardRightControl ), // e0 1d Right Control - DEADKEY_EXTENDED,// e0 1e - DEADKEY_EXTENDED,// e0 1f - MEDIA ( kHIDUsage_Csmr_Mute ), // e0 20 Mute (hp Fn+F7) - MEDIA ( kHIDUsage_Csmr_ALCalculator ),// e0 21 Calculator - MEDIA ( kHIDUsage_Csmr_PlayOrPause ), // e0 22 Play/Pause (hp Fn+F11) - DEADKEY_EXTENDED,// e0 23 - MEDIA ( kHIDUsage_Csmr_Stop ),// e0 24 Stop - DEADKEY_EXTENDED,// e0 25 - DEADKEY_EXTENDED,// e0 26 - DEADKEY_EXTENDED,// e0 27 - DEADKEY_EXTENDED,// e0 28 - DEADKEY_EXTENDED,// e0 29 - DEADKEY_EXTENDED,// e0 2a - DEADKEY_EXTENDED,// e0 2b - DEADKEY_EXTENDED,// e0 2c - DEADKEY_EXTENDED,// e0 2d - MEDIA ( kHIDUsage_Csmr_VolumeDecrement ), // e0 2e Volume Down (hp Fn+F8) - DEADKEY_EXTENDED,// e0 2f - MEDIA ( kHIDUsage_Csmr_VolumeIncrement ), // e0 30 Volume Up (hp Fn+F9) - DEADKEY_EXTENDED,// e0 31 - MEDIA ( kHIDUsage_Csmr_ACHome ),// e0 32 WWW Home - DEADKEY_EXTENDED,// e0 33 - DEADKEY_EXTENDED,// e0 34 - KEY ( kHIDUsage_KeypadSlash ), // e0 35 Keypad / - DEADKEY_EXTENDED,// e0 36 - KEY ( kHIDUsage_KeyboardPrintScreen ), // e0 37 Print Screen - KEY ( kHIDUsage_KeyboardRightAlt ), // e0 38 Right Alt - DEADKEY_EXTENDED,// e0 39 - DEADKEY_EXTENDED,// e0 3a - DEADKEY_EXTENDED,// e0 3b - DEADKEY_EXTENDED,// e0 3c - DEADKEY_EXTENDED,// e0 3d - DEADKEY_EXTENDED,// e0 3e - DEADKEY_EXTENDED,// e0 3f - DEADKEY_EXTENDED,// e0 40 - DEADKEY_EXTENDED,// e0 41 - DEADKEY_EXTENDED,// e0 42 - DEADKEY_EXTENDED,// e0 43 - DEADKEY_EXTENDED,// e0 44 - KEY ( kHIDUsage_KeyboardPause ), // e0 45* Pause - KEY ( kHIDUsage_KeyboardPause ), // e0 46* Break(Ctrl-Pause) - KEY ( kHIDUsage_KeyboardHome ), // e0 47 Home - KEY ( kHIDUsage_KeyboardUpArrow ), // e0 48 Up Arrow - KEY ( kHIDUsage_KeyboardPageUp ), // e0 49 Page Up - DEADKEY_EXTENDED,// e0 4a - KEY ( kHIDUsage_KeyboardLeftArrow ), // e0 4b Left Arrow - DEADKEY_EXTENDED,// e0 4c - KEY ( kHIDUsage_KeyboardRightArrow ), // e0 4d Right Arrow + DEADKEY,// e0 18 + 0x42, // e0 19 Scan Next Track (hp Fn+F12) + DEADKEY,// e0 1a + DEADKEY,// e0 1b + 0x4c, // e0 1c Keypad Enter + 0x3e, // e0 1d Right Control + DEADKEY,// e0 1e + DEADKEY,// e0 1f + 0x4a, // e0 20 Mute (hp Fn+F7) + DEADKEY,// e0 21 Calculator + 0x34, // e0 22 Play/Pause (hp Fn+F11) + DEADKEY,// e0 23 + DEADKEY,// e0 24 Stop + DEADKEY,// e0 25 + DEADKEY,// e0 26 + DEADKEY,// e0 27 + DEADKEY,// e0 28 + DEADKEY,// e0 29 + DEADKEY,// e0 2a + DEADKEY,// e0 2b + DEADKEY,// e0 2c + DEADKEY,// e0 2d + 0x49, // e0 2e Volume Down (hp Fn+F8) + DEADKEY,// e0 2f + 0x48, // e0 30 Volume Up (hp Fn+F9) + DEADKEY,// e0 31 + DEADKEY,// e0 32 WWW Home + DEADKEY,// e0 33 + DEADKEY,// e0 34 + 0x4b, // e0 35 Keypad / + DEADKEY,// e0 36 + 0x69, // e0 37 Print Screen + 0x3d, // e0 38 Right Alt + DEADKEY,// e0 39 + DEADKEY,// e0 3a + DEADKEY,// e0 3b + DEADKEY,// e0 3c + DEADKEY,// e0 3d + DEADKEY,// e0 3e + DEADKEY,// e0 3f + DEADKEY,// e0 40 + DEADKEY,// e0 41 + DEADKEY,// e0 42 + DEADKEY,// e0 43 + DEADKEY,// e0 44 + 0x71, // e0 45* Pause + DEADKEY,// e0 46* Break(Ctrl-Pause) + 0x73, // e0 47 Home + 0x7e, // e0 48 Up Arrow + 0x74, // e0 49 Page Up + DEADKEY,// e0 4a + 0x7b, // e0 4b Left Arrow + DEADKEY,// e0 4c + 0x7c, // e0 4d Right Arrow BRIGHTNESS_UP, // e0 4e acer up - KEY ( kHIDUsage_KeyboardEnd ), // e0 4f End - KEY ( kHIDUsage_KeyboardDownArrow ), // e0 50 Down Arrow - KEY ( kHIDUsage_KeyboardPageDown ), // e0 51 Page Down - MEDIA ( kHIDUsage_Csmr_Eject ), // e0 52 Insert = Eject - KEY ( kHIDUsage_KeyboardDeleteForward ), // e0 53 Delete - DEADKEY_EXTENDED,// e0 54 - DEADKEY_EXTENDED,// e0 55 - DEADKEY_EXTENDED,// e0 56 - DEADKEY_EXTENDED,// e0 57 - DEADKEY_EXTENDED,// e0 58 + 0x77, // e0 4f End + 0x7d, // e0 50 Down Arrow + 0x79, // e0 51 Page Down + 0x92, // e0 52 Insert = Eject + 0x75, // e0 53 Delete + DEADKEY,// e0 54 + DEADKEY,// e0 55 + DEADKEY,// e0 56 + DEADKEY,// e0 57 + DEADKEY,// e0 58 BRIGHTNESS_UP, // e0 59 acer up for my acer - DEADKEY_EXTENDED,// e0 5a - KEY ( kHIDUsage_KeyboardLeftGUI ), // e0 5b Left GUI(Windows) - KEY ( kHIDUsage_KeyboardRightGUI ), // e0 5c Right GUI(Windows) - KEY ( kHIDUsage_KeyboardApplication ), // e0 5d App( Windows context menu key ) - { kHIDPage_GenericDesktop, kHIDUsage_GD_SystemPowerDown }, // e0 5e System Power / Keyboard Power - { kHIDPage_GenericDesktop, kHIDUsage_GD_SystemSleep },// e0 5f System Sleep (hp Fn+F1) - DEADKEY_EXTENDED,// e0 60 - DEADKEY_EXTENDED,// e0 61 - DEADKEY_EXTENDED,// e0 62 - { kHIDPage_GenericDesktop, kHIDUsage_GD_SystemWakeUp },// e0 63 System Wake - DEADKEY_EXTENDED,// e0 64 - MEDIA ( kHIDUsage_Csmr_ACSearch ),// e0 65 WWW Search - MEDIA ( kHIDUsage_Csmr_ACBookmarks ),// e0 66 WWW Favorites - MEDIA ( kHIDUsage_Csmr_ACRefresh ),// e0 67 WWW Refresh - MEDIA ( kHIDUsage_Csmr_ACStop ),// e0 68 WWW Stop - MEDIA ( kHIDUsage_Csmr_ACForward ),// e0 69 WWW Forward - MEDIA ( kHIDUsage_Csmr_ACBack ),// e0 6a WWW Back - DEADKEY_EXTENDED,// e0 6b My Computer - MEDIA ( kHIDUsage_Csmr_ALEmailReader ),// e0 6c Mail - DEADKEY_EXTENDED,// e0 6d Media Select + DEADKEY,// e0 5a + 0x37, // e0 5b Left GUI(Windows) + 0x36, // e0 5c Right GUI(Windows) + 0x6e, // e0 5d App( Windows context menu key ) + 0x7f, // e0 5e System Power / Keyboard Power + DEADKEY,// e0 5f System Sleep (hp Fn+F1) + DEADKEY,// e0 60 + DEADKEY,// e0 61 + DEADKEY,// e0 62 + DEADKEY,// e0 63 System Wake + DEADKEY,// e0 64 + DEADKEY,// e0 65 WWW Search + DEADKEY,// e0 66 WWW Favorites + DEADKEY,// e0 67 WWW Refresh + DEADKEY,// e0 68 WWW Stop + DEADKEY,// e0 69 WWW Forward + DEADKEY,// e0 6a WWW Back + DEADKEY,// e0 6b My Computer + DEADKEY,// e0 6c Mail + DEADKEY,// e0 6d Media Select #ifndef PROBOOK BRIGHTNESS_UP, // e0 6e acer up BRIGHTNESS_DOWN, // e0 6f acer down #else - MEDIA ( 0x00 ), // e0 6e Video Mirror = hp Fn+F4 - DEADKEY_EXTENDED,// e0 6f Fn+Home + 0x70, // e0 6e Video Mirror = hp Fn+F4 + DEADKEY,// e0 6f Fn+Home #endif - DEADKEY_EXTENDED,// e0 70 - DEADKEY_EXTENDED,// e0 71 - DEADKEY_EXTENDED,// e0 72 - DEADKEY_EXTENDED,// e0 73 - DEADKEY_EXTENDED,// e0 74 - DEADKEY_EXTENDED,// e0 75 - DEADKEY_EXTENDED,// e0 76 + DEADKEY,// e0 70 + DEADKEY,// e0 71 + DEADKEY,// e0 72 + DEADKEY,// e0 73 + DEADKEY,// e0 74 + DEADKEY,// e0 75 + DEADKEY,// e0 76 #ifndef PROBOOK BRIGHTNESS_DOWN, // e0 77 lg down BRIGHTNESS_UP, // e0 78 lg up #else - DEADKEY_EXTENDED,// e0 77 - DEADKEY_EXTENDED,// e0 78 WiFi on/off button on HP ProBook + DEADKEY,// e0 77 + DEADKEY,// e0 78 WiFi on/off button on HP ProBook #endif - DEADKEY_EXTENDED,// e0 79 - DEADKEY_EXTENDED,// e0 7a - DEADKEY_EXTENDED,// e0 7b - DEADKEY_EXTENDED,// e0 7c - DEADKEY_EXTENDED,// e0 7d - DEADKEY_EXTENDED,// e0 7e - DEADKEY_EXTENDED,// e0 7f - DEADKEY_EXTENDED,// e0 80 - DEADKEY_EXTENDED,// e0 81 - DEADKEY_EXTENDED,// e0 82 - DEADKEY_EXTENDED,// e0 83 - DEADKEY_EXTENDED,// e0 84 - DEADKEY_EXTENDED,// e0 85 - DEADKEY_EXTENDED,// e0 86 - DEADKEY_EXTENDED,// e0 87 - DEADKEY_EXTENDED,// e0 88 - DEADKEY_EXTENDED,// e0 89 - DEADKEY_EXTENDED,// e0 8a - DEADKEY_EXTENDED,// e0 8b - DEADKEY_EXTENDED,// e0 8c - DEADKEY_EXTENDED,// e0 8d - DEADKEY_EXTENDED,// e0 8e - DEADKEY_EXTENDED,// e0 8f - DEADKEY_EXTENDED,// e0 90 - DEADKEY_EXTENDED,// e0 91 - DEADKEY_EXTENDED,// e0 92 - DEADKEY_EXTENDED,// e0 93 - DEADKEY_EXTENDED,// e0 94 - DEADKEY_EXTENDED,// e0 95 - DEADKEY_EXTENDED,// e0 96 - DEADKEY_EXTENDED,// e0 97 - DEADKEY_EXTENDED,// e0 98 - DEADKEY_EXTENDED,// e0 99 - DEADKEY_EXTENDED,// e0 9a - DEADKEY_EXTENDED,// e0 9b - DEADKEY_EXTENDED,// e0 9c - DEADKEY_EXTENDED,// e0 9d - DEADKEY_EXTENDED,// e0 9e - DEADKEY_EXTENDED,// e0 9f - DEADKEY_EXTENDED,// e0 a0 - DEADKEY_EXTENDED,// e0 a1 - DEADKEY_EXTENDED,// e0 a2 - DEADKEY_EXTENDED,// e0 a3 - DEADKEY_EXTENDED,// e0 a4 - DEADKEY_EXTENDED,// e0 a5 - DEADKEY_EXTENDED,// e0 a6 - DEADKEY_EXTENDED,// e0 a7 - DEADKEY_EXTENDED,// e0 a8 - DEADKEY_EXTENDED,// e0 a9 - DEADKEY_EXTENDED,// e0 aa - DEADKEY_EXTENDED,// e0 ab - DEADKEY_EXTENDED,// e0 ac - DEADKEY_EXTENDED,// e0 ad - DEADKEY_EXTENDED,// e0 ae - DEADKEY_EXTENDED,// e0 af - DEADKEY_EXTENDED,// e0 b0 - DEADKEY_EXTENDED,// e0 b1 - DEADKEY_EXTENDED,// e0 b2 - DEADKEY_EXTENDED,// e0 b3 - DEADKEY_EXTENDED,// e0 b4 - DEADKEY_EXTENDED,// e0 b5 - DEADKEY_EXTENDED,// e0 b6 - DEADKEY_EXTENDED,// e0 b7 - DEADKEY_EXTENDED,// e0 b8 - DEADKEY_EXTENDED,// e0 b9 - DEADKEY_EXTENDED,// e0 ba - DEADKEY_EXTENDED,// e0 bb - DEADKEY_EXTENDED,// e0 bc - DEADKEY_EXTENDED,// e0 bd - DEADKEY_EXTENDED,// e0 be - DEADKEY_EXTENDED,// e0 bf - DEADKEY_EXTENDED,// e0 c0 - DEADKEY_EXTENDED,// e0 c1 - DEADKEY_EXTENDED,// e0 c2 - DEADKEY_EXTENDED,// e0 c3 - DEADKEY_EXTENDED,// e0 c4 - DEADKEY_EXTENDED,// e0 c5 - DEADKEY_EXTENDED,// e0 c6 - DEADKEY_EXTENDED,// e0 c7 - DEADKEY_EXTENDED,// e0 c8 - DEADKEY_EXTENDED,// e0 c9 - DEADKEY_EXTENDED,// e0 ca - DEADKEY_EXTENDED,// e0 cb - DEADKEY_EXTENDED,// e0 cc - DEADKEY_EXTENDED,// e0 cd - DEADKEY_EXTENDED,// e0 ce - DEADKEY_EXTENDED,// e0 cf - DEADKEY_EXTENDED,// e0 d0 - DEADKEY_EXTENDED,// e0 d1 - DEADKEY_EXTENDED,// e0 d2 - DEADKEY_EXTENDED,// e0 d3 - DEADKEY_EXTENDED,// e0 d4 - DEADKEY_EXTENDED,// e0 d5 - DEADKEY_EXTENDED,// e0 d6 - DEADKEY_EXTENDED,// e0 d7 - DEADKEY_EXTENDED,// e0 d8 - DEADKEY_EXTENDED,// e0 d9 - DEADKEY_EXTENDED,// e0 da - DEADKEY_EXTENDED,// e0 db - DEADKEY_EXTENDED,// e0 dc - DEADKEY_EXTENDED,// e0 dd - DEADKEY_EXTENDED,// e0 de - DEADKEY_EXTENDED,// e0 df - DEADKEY_EXTENDED,// e0 e0 - DEADKEY_EXTENDED,// e0 e1 - DEADKEY_EXTENDED,// e0 e2 - DEADKEY_EXTENDED,// e0 e3 - DEADKEY_EXTENDED,// e0 e4 - DEADKEY_EXTENDED,// e0 e5 - DEADKEY_EXTENDED,// e0 e6 - DEADKEY_EXTENDED,// e0 e7 - DEADKEY_EXTENDED,// e0 e8 - DEADKEY_EXTENDED,// e0 e9 - DEADKEY_EXTENDED,// e0 ea - DEADKEY_EXTENDED,// e0 eb - DEADKEY_EXTENDED,// e0 ec - DEADKEY_EXTENDED,// e0 ed - DEADKEY_EXTENDED,// e0 ee - DEADKEY_EXTENDED,// e0 ef - DEADKEY_EXTENDED,// e0 f0 // Note: codes e0f0 through e0ff are reserved for ACPI callback - DEADKEY_EXTENDED,// e0 f1 - DEADKEY_EXTENDED,// e0 f2 - DEADKEY_EXTENDED,// e0 f3 - DEADKEY_EXTENDED,// e0 f4 - DEADKEY_EXTENDED,// e0 f5 - DEADKEY_EXTENDED,// e0 f6 - DEADKEY_EXTENDED,// e0 f7 - DEADKEY_EXTENDED,// e0 f8 - DEADKEY_EXTENDED,// e0 f9 - DEADKEY_EXTENDED,// e0 fa - DEADKEY_EXTENDED,// e0 fb - DEADKEY_EXTENDED,// e0 fc - DEADKEY_EXTENDED,// e0 fd - DEADKEY_EXTENDED,// e0 fe - DEADKEY_EXTENDED // e0 ff // End reserved + DEADKEY,// e0 79 + DEADKEY,// e0 7a + DEADKEY,// e0 7b + DEADKEY,// e0 7c + DEADKEY,// e0 7d + DEADKEY,// e0 7e + DEADKEY,// e0 7f + DEADKEY,// e0 80 + DEADKEY,// e0 81 + DEADKEY,// e0 82 + DEADKEY,// e0 83 + DEADKEY,// e0 84 + DEADKEY,// e0 85 + DEADKEY,// e0 86 + DEADKEY,// e0 87 + DEADKEY,// e0 88 + DEADKEY,// e0 89 + DEADKEY,// e0 8a + DEADKEY,// e0 8b + DEADKEY,// e0 8c + DEADKEY,// e0 8d + DEADKEY,// e0 8e + DEADKEY,// e0 8f + DEADKEY,// e0 90 + DEADKEY,// e0 91 + DEADKEY,// e0 92 + DEADKEY,// e0 93 + DEADKEY,// e0 94 + DEADKEY,// e0 95 + DEADKEY,// e0 96 + DEADKEY,// e0 97 + DEADKEY,// e0 98 + DEADKEY,// e0 99 + DEADKEY,// e0 9a + DEADKEY,// e0 9b + DEADKEY,// e0 9c + DEADKEY,// e0 9d + DEADKEY,// e0 9e + DEADKEY,// e0 9f + DEADKEY,// e0 a0 + DEADKEY,// e0 a1 + DEADKEY,// e0 a2 + DEADKEY,// e0 a3 + DEADKEY,// e0 a4 + DEADKEY,// e0 a5 + DEADKEY,// e0 a6 + DEADKEY,// e0 a7 + DEADKEY,// e0 a8 + DEADKEY,// e0 a9 + DEADKEY,// e0 aa + DEADKEY,// e0 ab + DEADKEY,// e0 ac + DEADKEY,// e0 ad + DEADKEY,// e0 ae + DEADKEY,// e0 af + DEADKEY,// e0 b0 + DEADKEY,// e0 b1 + DEADKEY,// e0 b2 + DEADKEY,// e0 b3 + DEADKEY,// e0 b4 + DEADKEY,// e0 b5 + DEADKEY,// e0 b6 + DEADKEY,// e0 b7 + DEADKEY,// e0 b8 + DEADKEY,// e0 b9 + DEADKEY,// e0 ba + DEADKEY,// e0 bb + DEADKEY,// e0 bc + DEADKEY,// e0 bd + DEADKEY,// e0 be + DEADKEY,// e0 bf + DEADKEY,// e0 c0 + DEADKEY,// e0 c1 + DEADKEY,// e0 c2 + DEADKEY,// e0 c3 + DEADKEY,// e0 c4 + DEADKEY,// e0 c5 + DEADKEY,// e0 c6 + DEADKEY,// e0 c7 + DEADKEY,// e0 c8 + DEADKEY,// e0 c9 + DEADKEY,// e0 ca + DEADKEY,// e0 cb + DEADKEY,// e0 cc + DEADKEY,// e0 cd + DEADKEY,// e0 ce + DEADKEY,// e0 cf + DEADKEY,// e0 d0 + DEADKEY,// e0 d1 + DEADKEY,// e0 d2 + DEADKEY,// e0 d3 + DEADKEY,// e0 d4 + DEADKEY,// e0 d5 + DEADKEY,// e0 d6 + DEADKEY,// e0 d7 + DEADKEY,// e0 d8 + DEADKEY,// e0 d9 + DEADKEY,// e0 da + DEADKEY,// e0 db + DEADKEY,// e0 dc + DEADKEY,// e0 dd + DEADKEY,// e0 de + DEADKEY,// e0 df + DEADKEY,// e0 e0 + DEADKEY,// e0 e1 + DEADKEY,// e0 e2 + DEADKEY,// e0 e3 + DEADKEY,// e0 e4 + DEADKEY,// e0 e5 + DEADKEY,// e0 e6 + DEADKEY,// e0 e7 + DEADKEY,// e0 e8 + DEADKEY,// e0 e9 + DEADKEY,// e0 ea + DEADKEY,// e0 eb + DEADKEY,// e0 ec + DEADKEY,// e0 ed + DEADKEY,// e0 ee + DEADKEY,// e0 ef + DEADKEY,// e0 f0 // Note: codes e0f0 through e0ff are reserved for ACPI callback + DEADKEY,// e0 f1 + DEADKEY,// e0 f2 + DEADKEY,// e0 f3 + DEADKEY,// e0 f4 + DEADKEY,// e0 f5 + DEADKEY,// e0 f6 + DEADKEY,// e0 f7 + DEADKEY,// e0 f8 + DEADKEY,// e0 f9 + DEADKEY,// e0 fa + DEADKEY,// e0 fb + DEADKEY,// e0 fc + DEADKEY,// e0 fd + DEADKEY,// e0 fe + DEADKEY // e0 ff // End reserved }; /////////////////////////////////////////////////////////////////////////////////// @@ -613,7 +605,7 @@ static const VoodooPS2HidElement ExtendedPS2ToHIDStockMap[ADB_CONVERTER_LEN] { #define kMaskLeftFn 0x0100 #define kMaskWindowsContext 0x0200 -static const UInt16 _PS2flagsStock[256*2] = +static const UInt16 _PS2flagsStock[ADB_CONVERTER_LEN] = { // flags/modifier key AT ANSI Key-Legend 0x00, // 00 diff --git a/VoodooPS2Keyboard/VoodooPS2EventDriver.hpp b/VoodooPS2Keyboard/VoodooPS2EventDriver.hpp deleted file mode 100644 index d773d3ca..00000000 --- a/VoodooPS2Keyboard/VoodooPS2EventDriver.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// -// HIDPS2EventDriver.hpp -// HIDPS2Keyboard -// -// Created by Gwydien on 8/27/23. -// Copyright © 2023 coolstar. All rights reserved. -// - -#ifndef HIDPS2EventDriver_hpp -#define HIDPS2EventDriver_hpp - -#include - -class VoodooPS2KeyboardHIDEventDriver : public IOHIDEventService -{ - OSDeclareDefaultStructors( VoodooPS2KeyboardHIDEventDriver ); - friend class VoodooPS2KeyboardHIDWrapper; - -public: - bool start(IOService *provider) override { - IOHIDInterface *interface = OSDynamicCast(IOHIDInterface, provider); - if (!IOHIDEventService::start(provider)) { - return false; - } - - registerService(); - return interface->open(this, 0, nullptr, nullptr); - } -}; - -#endif /* HIDPS2EventDriver_hpp */ diff --git a/VoodooPS2Keyboard/VoodooPS2Keyboard-Info.plist b/VoodooPS2Keyboard/VoodooPS2Keyboard-Info.plist index ca4e7058..7e224756 100644 --- a/VoodooPS2Keyboard/VoodooPS2Keyboard-Info.plist +++ b/VoodooPS2Keyboard/VoodooPS2Keyboard-Info.plist @@ -22,31 +22,6 @@ ${MODULE_VERSION} IOKitPersonalities - VoodooPS2HIDEventDriver - - CFBundleIdentifier - com.1Revenger1.PS2Keyboard - DeviceUsagePairs - - - DeviceUsage - 1 - DeviceUsagePage - 12 - - - IOClass - VoodooPS2KeyboardHIDEventDriver - IOProbeScore - 8000 - IOPropertyMatch - - Transport - PS2 - - IOProviderClass - IOHIDInterface - ApplePS2Keyboard CFBundleIdentifier diff --git a/VoodooPS2Keyboard/VoodooPS2Keyboard.cpp b/VoodooPS2Keyboard/VoodooPS2Keyboard.cpp index ab90c7b9..fe47247e 100644 --- a/VoodooPS2Keyboard/VoodooPS2Keyboard.cpp +++ b/VoodooPS2Keyboard/VoodooPS2Keyboard.cpp @@ -20,6 +20,12 @@ * @APPLE_LICENSE_HEADER_END@ */ +// enable for keyboard debugging +#ifdef DEBUG_MSG +//#define DEBUG_VERBOSE +#define DEBUG_LITE +#endif + #include #include @@ -28,8 +34,10 @@ #include #include +#include "ApplePS2ToADBMap.h" #include "VoodooPS2Controller.h" #include "VoodooPS2Keyboard.h" +#include "ApplePS2ToADBMap.h" #include "AppleACPIPS2Nub.h" #include @@ -37,7 +45,10 @@ // Constants for Info.plist settings #define kSleepPressTime "SleepPressTime" +#define kHIDFKeyMode "HIDFKeyMode" #define kHIDF12EjectDelay "HIDF12EjectDelay" +#define kFunctionKeysStandard "Function Keys Standard" +#define kFunctionKeysSpecial "Function Keys Special" #define kRemapPrntScr "RemapPrntScr" #define kNumLockSupport "NumLockSupport" #define kNumLockOnAtBoot "NumLockOnAtBoot" @@ -47,12 +58,54 @@ #define kMakeApplicationKeyAppleFN "Make Application key into Apple Fn key" #define kMakeRightModsHangulHanja "Make right modifier keys into Hangul and Hanja" #define kUseISOLayoutKeyboard "Use ISO layout keyboard" +#define kLogScanCodes "LogScanCodes" + +#define kBrightnessHack "BrightnessHack" +#define kMacroInversion "Macro Inversion" +#define kMacroTranslation "Macro Translation" +#define kMaxMacroTime "MaximumMacroTime" + +// Definitions for Macro Inversion data format +//REVIEW: This should really be defined as some sort of structure +#define kIgnoreBytes 2 // first two bytes of macro data are ignored (always 0xffff) +#define kOutputBytes 2 // two bytes of Macro Inversion are used to specify output +#define kModifierBytes 4 // 4 bytes specify modifier key match criteria +#define kOutputBytesOffset (kIgnoreBytes+0) +#define kModifierBytesOffset (kIgnoreBytes+kOutputBytes+0) +#define kPrefixBytes (kIgnoreBytes+kOutputBytes+kModifierBytes) +#define kSequenceBytesOffset (kPrefixBytes+0) +#define kMinMacroInversion (kPrefixBytes+2) + +// Constants for other services to communicate with + +#define kIOHIDSystem "IOHIDSystem" // ============================================================================= // ApplePS2Keyboard Class Implementation // -OSDefineMetaClassAndStructors(ApplePS2Keyboard, IOService); +// get some keyboard id information from IOHIDFamily/IOHIDKeyboard.h and Gestalt.h +//#define APPLEPS2KEYBOARD_DEVICE_TYPE 205 // Generic ISO keyboard +#define APPLEPS2KEYBOARD_DEVICE_TYPE 3 // Unknown ANSI keyboard + +OSDefineMetaClassAndStructors(ApplePS2Keyboard, IOHIKeyboard); + +UInt32 ApplePS2Keyboard::deviceType() +{ + OSNumber *xml_handlerID; + UInt32 ret_id; + + if ( (xml_handlerID = OSDynamicCast( OSNumber, getProperty("alt_handler_id"))) ) + ret_id = xml_handlerID->unsigned32BitValue(); + else + ret_id = APPLEPS2KEYBOARD_DEVICE_TYPE; + + return ret_id; +} + +UInt32 ApplePS2Keyboard::interfaceID() { return NX_EVS_DEVICE_INTERFACE_ADB; } + +UInt32 ApplePS2Keyboard::maxKeyCodes() { return NX_NUMKEYCODES; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -75,7 +128,7 @@ static const char* parseHex(const char *psz, char term1, char term2, unsigned& o return psz; } -static bool parseRemap(const char *psz, UInt16 &scanFrom, UInt32& scanTo) +static bool parseRemap(const char *psz, UInt16 &scanFrom, UInt16& scanTo) { // psz is of the form: "scanfrom=scanto", examples: // non-extended: "1d=3a" @@ -88,7 +141,7 @@ static bool parseRemap(const char *psz, UInt16 &scanFrom, UInt32& scanTo) return false; scanFrom = n; psz = parseHex(psz+1, '\n', ';', n); - if (NULL == psz) + if (NULL == psz || n > 0xFFFF) return false; scanTo = n; return true; @@ -120,20 +173,35 @@ bool ApplePS2Keyboard::init(OSDictionary * dict) _sleepEjectTimer = 0; _cmdGate = 0; + _fkeymode = 0; + _fkeymodesupported = false; + _keysStandard = 0; + _keysSpecial = 0; _f12ejectdelay = 250; // default is 250 ms + // initialize ACPI support for keyboard backlight + _provider = 0; + _backlightLevels = 0; + + _logscancodes = 0; + _brightnessHack = false; + + // initalize macro translation + _macroInversion = 0; + _macroTranslation = 0; + _macroBuffer = 0; + _macroCurrent = 0; + _macroMax = 0; + _macroMaxTime = 25000000ULL; + _macroTimer = 0; + _ignoreCapsLedChange = false; // start out with all keys up bzero(_keyBitVector, sizeof(_keyBitVector)); // make separate copy of ADB translation table. - for (int i = 0; i < ADB_CONVERTER_LEN; i++) { - _PS2ToHIDMap[i].usagePage = kHIDPage_KeyboardOrKeypad; - _PS2ToHIDMap[i].usage = PS2ToHIDMapStock[i]; - } - - bcopy(ExtendedPS2ToHIDStockMap, &_PS2ToHIDMap[256], sizeof(ExtendedPS2ToHIDStockMap)); + bcopy(PS2ToADBMapStock, _PS2ToADBMapMapped, sizeof(_PS2ToADBMapMapped)); // Setup the PS2 -> PS2 scan code mapper for (int i = 0; i < countof(_PS2ToPS2Map); i++) @@ -142,7 +210,6 @@ bool ApplePS2Keyboard::init(OSDictionary * dict) // first half of map is normal scan codes, second half is extended scan codes (e0) _PS2ToPS2Map[i] = i; } - bcopy(_PS2flagsStock, _PS2flags, sizeof(_PS2flags)); return true; @@ -196,9 +263,45 @@ ApplePS2Keyboard* ApplePS2Keyboard::probe(IOService * provider, SInt32 * score) loadBreaklessPS2(config, "Breakless PS2"); // now load PS2 -> ADB configuration data - loadCustomHIDMap(config, "Custom ADB Map"); + loadCustomADBMap(config, "Custom ADB Map"); + + // determine if _fkeymode property should be handled in setParamProperties + _keysStandard = OSDynamicCast(OSArray, config->getObject(kFunctionKeysStandard)); + _keysSpecial = OSDynamicCast(OSArray, config->getObject(kFunctionKeysSpecial)); + _fkeymodesupported = _keysStandard && _keysSpecial; + if (_fkeymodesupported) + { + setProperty(kHIDFKeyMode, (uint64_t)0, 64); + _keysStandard->retain(); + _keysSpecial->retain(); + loadCustomPS2Map(_keysSpecial); + } + else + { + _keysStandard = NULL; + _keysSpecial = NULL; + } + + // load custom macro data + _macroTranslation = loadMacroData(config, kMacroTranslation); + _macroInversion = loadMacroData(config, kMacroInversion); + if (_macroInversion) + { + int max = 0; + for (OSData** p = _macroInversion; *p; p++) + { + int length = (*p)->getLength()-kPrefixBytes; + if (length > max) + max = length; + } + _macroBuffer = new UInt8[max*kPacketLength]; + _macroMax = max; + } } + // now copy to our PS2ToADBMap -- working copy... + bcopy(_PS2ToADBMapMapped, _PS2ToADBMap, sizeof(_PS2ToADBMap)); + // populate rest of values via setParamProperties setParamPropertiesGated(config); OSSafeReleaseNULL(config); @@ -278,6 +381,66 @@ bool ApplePS2Keyboard::start(IOService * provider) return false; } + // get IOACPIPlatformDevice for Device (PS2K) + //REVIEW: should really look at the parent chain for IOACPIPlatformDevice instead. + _provider = (IOACPIPlatformDevice*)IORegistryEntry::fromPath("IOService:/AppleACPIPlatformExpert/PS2K"); + + // + // get keyboard backlight levels for ACPI based backlight keys + // + + OSObject* result = 0; + if (_provider) do + { + // check for brightness methods + if (kIOReturnSuccess != _provider->validateObject("KKCL") || kIOReturnSuccess != _provider->validateObject("KKCM") || kIOReturnSuccess != _provider->validateObject("KKQC")) + { + DEBUG_LOG("ps2bl: KKCL, KKCM, KKQC methods not found in DSDT\n"); + break; + } + + // methods are there, so now try to collect brightness levels + if (kIOReturnSuccess != _provider->evaluateObject("KKCL", &result)) + { + DEBUG_LOG("ps2bl: KKCL returned error\n"); + break; + } + OSArray* array = OSDynamicCast(OSArray, result); + if (!array) + { + DEBUG_LOG("ps2bl: KKCL returned non-array package\n"); + break; + } + int count = array->getCount(); + if (count < 2) + { + DEBUG_LOG("ps2bl: KKCL returned invalid package\n"); + break; + } + _backlightCount = count; + _backlightLevels = new int[_backlightCount]; + if (!_backlightLevels) + { + DEBUG_LOG("ps2bl: _backlightLevels new int[] failed\n"); + break; + } + for (int i = 0; i < _backlightCount; i++) + { + OSNumber* num = OSDynamicCast(OSNumber, array->getObject(i)); + int brightness = num ? num->unsigned32BitValue() : 0; + _backlightLevels[i] = brightness; + } +#ifdef DEBUG_VERBOSE + DEBUG_LOG("ps2bl: Keyboard backlight levels: { "); + for (int i = 0; i < _backlightCount; i++) + DEBUG_LOG("%d, ", _backlightLevels[i]); + DEBUG_LOG("}\n"); +#endif + break; + } while (false); + + OSSafeReleaseNULL(result); + // // Lock the controller during initialization // @@ -290,27 +453,20 @@ bool ApplePS2Keyboard::start(IOService * provider) initKeyboard(); -// // -// // Set NumLock State to On (if specified). -// // -// -// if (_numLockOnAtBoot) -// setNumLock(true); + // + // Set NumLock State to On (if specified). + // + + if (_numLockOnAtBoot) + setNumLock(true); pWorkLoop->addEventSource(_sleepEjectTimer); pWorkLoop->addEventSource(_cmdGate); - // - // Construct HID Wrapper - // - _hidWrapper = OSTypeAlloc(VoodooPS2KeyboardHIDWrapper); - if (_hidWrapper == nullptr || - !_hidWrapper->init() || - !_hidWrapper->attach(this) || - !_hidWrapper->start(this)) { - IOLog("%s: HID Wrapper fail :(", getName()); - return nullptr; - } + // _macroTimer is used in for macro inversion + _macroTimer = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &ApplePS2Keyboard::onMacroTimer)); + if (_macroTimer) + pWorkLoop->addEventSource(_macroTimer); // // Install our driver's interrupt handler, for asynchronous data delivery. @@ -331,6 +487,11 @@ bool ApplePS2Keyboard::start(IOService * provider) _device->installPowerControlAction( this, OSMemberFunctionCast(PS2PowerControlAction,this, &ApplePS2Keyboard::setDevicePowerState )); _powerControlHandlerInstalled = true; + + // + // Tell ACPIPS2Nub that we are interested in ACPI notifications + // + //setProperty(kDeliverNotifications, true); DEBUG_LOG("ApplePS2Keyboard::start leaving.\n"); @@ -354,8 +515,7 @@ void ApplePS2Keyboard::loadCustomPS2Map(OSArray* pArray) if (';' == *psz) continue; // otherwise, try to parse it - UInt16 scanIn; - UInt32 scanOut; + UInt16 scanIn, scanOut; if (!parseRemap(psz, scanIn, scanOut)) { IOLog("VoodooPS2Keyboard: invalid custom PS2 map entry: \"%s\"\n", psz); @@ -414,7 +574,7 @@ void ApplePS2Keyboard::loadBreaklessPS2(OSDictionary* dict, const char* name) } } -void ApplePS2Keyboard::loadCustomHIDMap(OSDictionary* dict, const char* name) +void ApplePS2Keyboard::loadCustomADBMap(OSDictionary* dict, const char* name) { OSArray* pArray = OSDynamicCast(OSArray, dict->getObject(name)); if (NULL != pArray) @@ -430,27 +590,77 @@ void ApplePS2Keyboard::loadCustomHIDMap(OSDictionary* dict, const char* name) if (';' == *psz) continue; // otherwise, try to parse it - UInt16 scanIn; - UInt32 hidOut; - if (!parseRemap(psz, scanIn, hidOut)) + UInt16 scanIn, adbOut; + if (!parseRemap(psz, scanIn, adbOut)) { IOLog("VoodooPS2Keyboard: invalid custom ADB map entry: \"%s\"\n", psz); continue; } // must be normal scan code or extended, nothing else, adbOut is only a byte UInt8 exIn = scanIn >> 8; - if (exIn != 0 && exIn != 0xe0) + if ((exIn != 0 && exIn != 0xe0) || adbOut > 0xFF) { IOLog("VoodooPS2Keyboard: scan code invalid for ADB map entry: \"%s\"\n", psz); continue; } // modify PS2 to ADB map per remap entry int index = (scanIn & 0xff) + (exIn == 0xe0 ? ADB_CONVERTER_EX_START : 0); - assert(index < countof(_PS2ToHIDMap)); - _PS2ToHIDMap[index].usagePage = hidOut >> 16; - _PS2ToHIDMap[index].usage = hidOut & 0xFFFF; + assert(index < countof(_PS2ToADBMapMapped)); + _PS2ToADBMapMapped[index] = adbOut; + } + } +} + +OSData** ApplePS2Keyboard::loadMacroData(OSDictionary* dict, const char* name) +{ + OSData** result = 0; + OSArray* pArray = OSDynamicCast(OSArray, dict->getObject(name)); + if (NULL != pArray) + { + // count valid entries + int total = 0; + int count = pArray->getCount(); + for (int i = 0; i < count; i++) + { + if (OSData* pData = OSDynamicCast(OSData, pArray->getObject(i))) + { + int length = pData->getLength(); + if (length >= kMinMacroInversion && !(length & 0x01)) + { + const UInt8* p = static_cast(pData->getBytesNoCopy()); + if (p[0] == 0xFF && p[1] == 0xFF) + total++; + } + } + } + if (total) + { + // store valid entries + result = new OSData*[total+1]; + if (result) + { + bzero(result, sizeof(char*)*(total+1)); + int index = 0; + for (int i = 0; i < count; i++) + { + if (OSData* pData = OSDynamicCast(OSData, pArray->getObject(i))) + { + int length = pData->getLength(); + if (length >= kMinMacroInversion && !(length & 0x01)) + { + const UInt8* p = static_cast(pData->getBytesNoCopy()); + if (p[0] == 0xFF && p[1] == 0xFF) + { + result[index++] = pData; + pData->retain(); + } + } + } + } + } } } + return result; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -474,6 +684,29 @@ void ApplePS2Keyboard::setParamPropertiesGated(OSDictionary * dict) _f12ejectdelay = num->unsigned32BitValue(); setProperty(kHIDF12EjectDelay, _f12ejectdelay, 32); } + // get time between keys part of a macro "inversion" + if (OSNumber* num = OSDynamicCast(OSNumber, dict->getObject(kMaxMacroTime))) + { + _macroMaxTime = num->unsigned64BitValue(); + setProperty(kMaxMacroTime, _macroMaxTime, 64); + } + + if (_fkeymodesupported) + { + // get function key mode + UInt32 oldfkeymode = _fkeymode; + if (OSNumber* num = OSDynamicCast(OSNumber, dict->getObject(kHIDFKeyMode))) + { + _fkeymode = num->unsigned32BitValue(); + setProperty(kHIDFKeyMode, _fkeymode, 32); + } + if (oldfkeymode != _fkeymode) + { + OSArray* keys = _fkeymode ? _keysStandard : _keysSpecial; + assert(keys); + loadCustomPS2Map(keys); + } + } // // Configure user preferences from Info.plist @@ -481,11 +714,12 @@ void ApplePS2Keyboard::setParamPropertiesGated(OSDictionary * dict) OSBoolean* xml = OSDynamicCast(OSBoolean, dict->getObject(kSwapCapsLockLeftControl)); if (xml) { if (xml->isTrue()) { - _PS2ToHIDMap[0x3a].usage = PS2ToHIDMapStock[0x1d]; - _PS2ToHIDMap[0x1d].usage = PS2ToHIDMapStock[0x3a]; - } else { - _PS2ToHIDMap[0x3a].usage = PS2ToHIDMapStock[0x3a]; - _PS2ToHIDMap[0x1d].usage = PS2ToHIDMapStock[0x1d]; + _PS2ToADBMap[0x3a] = _PS2ToADBMapMapped[0x1d]; + _PS2ToADBMap[0x1d] = _PS2ToADBMapMapped[0x3a]; + } + else { + _PS2ToADBMap[0x3a] = _PS2ToADBMapMapped[0x3a]; + _PS2ToADBMap[0x1d] = _PS2ToADBMapMapped[0x1d]; } setProperty(kSwapCapsLockLeftControl, xml->isTrue() ? kOSBooleanTrue : kOSBooleanFalse); } @@ -494,20 +728,29 @@ void ApplePS2Keyboard::setParamPropertiesGated(OSDictionary * dict) if (xml) { if (xml->isTrue()) { _swapcommandoption = true; - _PS2ToHIDMap[0x38].usage = kHIDUsage_KeyboardLeftGUI; // Left Alt -> Left GUI - _PS2ToHIDMap[0x15b].usage = kHIDUsage_KeyboardLeftAlt; // Left GUI -> Left Alt - _PS2ToHIDMap[0x138].usage = kHIDUsage_KeyboardRightGUI; // Right Alt -> Right GUI - _PS2ToHIDMap[0x15c].usage = kHIDUsage_KeyboardRightAlt; // Right GUI -> Right Alt - } else { + _PS2ToADBMap[0x38] = _PS2ToADBMapMapped[0x15b]; + _PS2ToADBMap[0x15b] = _PS2ToADBMapMapped[0x38]; + _PS2ToADBMap[0x138] = _PS2ToADBMapMapped[0x15c]; + _PS2ToADBMap[0x15c] = _PS2ToADBMapMapped[0x138]; + } + else { _swapcommandoption = false; - _PS2ToHIDMap[0x38].usage = kHIDUsage_KeyboardLeftAlt; - _PS2ToHIDMap[0x15b].usage = kHIDUsage_KeyboardLeftGUI; - _PS2ToHIDMap[0x138].usage = kHIDUsage_KeyboardRightAlt; - _PS2ToHIDMap[0x15c].usage = kHIDUsage_KeyboardRightGUI; + _PS2ToADBMap[0x38] = _PS2ToADBMapMapped[0x38]; + _PS2ToADBMap[0x15b] = _PS2ToADBMapMapped[0x15b]; + _PS2ToADBMap[0x138] = _PS2ToADBMapMapped[0x138]; + _PS2ToADBMap[0x15c] = _PS2ToADBMapMapped[0x15c]; } setProperty(kSwapCommandOption, xml->isTrue() ? kOSBooleanTrue : kOSBooleanFalse); } + // special hack for HP Envy brightness + xml = OSDynamicCast(OSBoolean, dict->getObject(kBrightnessHack)); + if (xml && xml->isTrue()) + { + //REVIEW: should really read the key assignments via Info.plist instead of hardcoding to F2/F3 + _brightnessHack = true; + } + if ((xml = OSDynamicCast(OSBoolean, dict->getObject(kRemapPrntScr)))) { _remapPrntScr = xml->getValue(); @@ -525,30 +768,48 @@ void ApplePS2Keyboard::setParamPropertiesGated(OSDictionary * dict) _numLockOnAtBoot = xml->getValue(); setProperty(kNumLockOnAtBoot, _numLockOnAtBoot); } - + + // these two options are mutually exclusive + // kMakeApplicationKeyAppleFN is ignored if kMakeApplicationKeyRightWindows is set + bool temp = false; xml = OSDynamicCast(OSBoolean, dict->getObject(kMakeApplicationKeyRightWindows)); if (xml) { if (xml->isTrue()) { - _PS2ToHIDMap[0x15d].usage = _swapcommandoption ? kHIDUsage_KeyboardRightAlt : kHIDUsage_KeyboardRightGUI; + _PS2ToADBMap[0x15d] = _swapcommandoption ? 0x3d : 0x36; // ADB = right-option/right-command + temp = true; } else { - _PS2ToHIDMap[0x15d].usage = kHIDUsage_KeyboardApplication; + _PS2ToADBMap[0x15d] = _PS2ToADBMapMapped[0x15d]; } setProperty(kMakeApplicationKeyRightWindows, xml->isTrue() ? kOSBooleanTrue : kOSBooleanFalse); } + // not implemented yet (Note: maybe not true any more) + // Apple Fn key works well, but no combined key action was made. + xml = OSDynamicCast(OSBoolean, dict->getObject(kMakeApplicationKeyAppleFN)); + if (xml) { + if (!temp) { + if (xml->isTrue()) { + _PS2ToADBMap[0x15d] = 0x3f; // ADB = AppleFN + } + else { + _PS2ToADBMap[0x15d] = _PS2ToADBMapMapped[0x15d]; + } + } + setProperty(kMakeApplicationKeyAppleFN, xml->isTrue() ? kOSBooleanTrue : kOSBooleanFalse); + } xml = OSDynamicCast(OSBoolean, dict->getObject(kMakeRightModsHangulHanja)); if (xml) { if (xml->isTrue()) { - _PS2ToHIDMap[0x138].usage = kHIDUsage_KeyboardLANG1; // Right alt becomes Hangul - _PS2ToHIDMap[0x11d].usage = kHIDUsage_KeyboardLANG2; // Right control becomes Hanja + _PS2ToADBMap[0x138] = _PS2ToADBMapMapped[0xf2]; // Right alt becomes Hangul + _PS2ToADBMap[0x11d] = _PS2ToADBMapMapped[0xf1]; // Right control becomes Hanja } else { if (_swapcommandoption) - _PS2ToHIDMap[0x138].usage = kHIDUsage_KeyboardRightGUI; + _PS2ToADBMap[0x138] = _PS2ToADBMapMapped[0x15c]; else - _PS2ToHIDMap[0x138].usage = kHIDUsage_KeyboardRightAlt; - _PS2ToHIDMap[0x11d].usage = kHIDUsage_KeyboardRightControl; + _PS2ToADBMap[0x138] = _PS2ToADBMapMapped[0x138]; + _PS2ToADBMap[0x11d] = _PS2ToADBMapMapped[0x11d]; } setProperty(kMakeRightModsHangulHanja, xml->isTrue() ? kOSBooleanTrue : kOSBooleanFalse); } @@ -558,15 +819,34 @@ void ApplePS2Keyboard::setParamPropertiesGated(OSDictionary * dict) xml = OSDynamicCast(OSBoolean, dict->getObject(kUseISOLayoutKeyboard)); if (xml) { if (xml->isTrue()) { - _PS2ToHIDMap[0x29].usage = kHIDUsage_KeyboardNonUSBackslash; - _PS2ToHIDMap[0x56].usage = kHIDUsage_KeyboardGraveAccentAndTilde; + _PS2ToADBMap[0x29] = _PS2ToADBMapMapped[0x56]; //Europe2 '¤º' + _PS2ToADBMap[0x56] = _PS2ToADBMapMapped[0x29]; //Grave '~' } else { - _PS2ToHIDMap[0x29].usage = kHIDUsage_KeyboardGraveAccentAndTilde; - _PS2ToHIDMap[0x56].usage = kHIDUsage_KeyboardNonUSBackslash; + _PS2ToADBMap[0x29] = _PS2ToADBMapMapped[0x29]; + _PS2ToADBMap[0x56] = _PS2ToADBMapMapped[0x56]; } setProperty(kUseISOLayoutKeyboard, xml->isTrue() ? kOSBooleanTrue : kOSBooleanFalse); } + + if (OSNumber* num = OSDynamicCast(OSNumber, dict->getObject(kLogScanCodes))) { + _logscancodes = num->unsigned32BitValue(); + setProperty(kLogScanCodes, num); + } +} + +IOReturn ApplePS2Keyboard::setParamProperties(OSDictionary *dict) +{ + ////IOReturn result = super::setParamProperties(dict); + if (_cmdGate) + { + // syncronize through workloop... + ////_cmdGate->runAction(OSMemberFunctionCast(IOCommandGate::Action, this, &ApplePS2Keyboard::setParamPropertiesGated), dict); + setParamPropertiesGated(dict); + } + + return super::setParamProperties(dict); + ////return result; } IOReturn ApplePS2Keyboard::setProperties(OSObject *props) @@ -593,11 +873,6 @@ void ApplePS2Keyboard::stop(IOService * provider) assert(_device == provider); - if (_hidWrapper) { - _hidWrapper->terminate(); - _hidWrapper->release(); - } - // // Disable the keyboard itself, so that it may stop reporting key events. // @@ -620,6 +895,12 @@ void ApplePS2Keyboard::stop(IOService * provider) _sleepEjectTimer->release(); _sleepEjectTimer = 0; } + if (_macroTimer) + { + pWorkLoop->removeEventSource(_macroTimer); + _macroTimer->release(); + _macroTimer = 0; + } } // @@ -642,6 +923,43 @@ void ApplePS2Keyboard::stop(IOService * provider) OSSafeReleaseNULL(_device); + // + // Release ACPI provider for PS2K ACPI device + // + OSSafeReleaseNULL(_provider); + + // + // Release data related to keyboard backlight + // + if (_backlightLevels) + { + delete[] _backlightLevels; + _backlightLevels = 0; + } + + OSSafeReleaseNULL(_keysStandard); + OSSafeReleaseNULL(_keysSpecial); + + if (_macroInversion) + { + for (OSData** p = _macroInversion; *p; p++) + (*p)->release(); + delete[] _macroInversion; + _macroInversion = 0; + } + if (_macroTranslation) + { + for (OSData** p = _macroTranslation; *p; p++) + (*p)->release(); + delete[] _macroTranslation; + _macroTranslation = 0; + } + if (_macroBuffer) + { + delete[] _macroBuffer; + _macroBuffer = 0; + } + super::stop(provider); } @@ -669,17 +987,29 @@ IOReturn ApplePS2Keyboard::message(UInt32 type, IOService* provider, void* argum { // mark packet with timestamp clock_get_uptime((uint64_t*)(&packet[kPacketTimeOffset])); - dispatchKeyboardEventWithPacket(packet); + if (!_macroInversion || !invertMacros(packet)) + { + // normal packet + dispatchKeyboardEventWithPacket(packet); + } } if (3 == packet[0] || 4 == packet[0]) { // code 3 and 4 indicate send both make and break packet[0] -= 2; clock_get_uptime((uint64_t*)(&packet[kPacketTimeOffset])); - dispatchKeyboardEventWithPacket(packet); + if (!_macroInversion || !invertMacros(packet)) + { + // normal packet (make) + dispatchKeyboardEventWithPacket(packet); + } clock_get_uptime((uint64_t*)(&packet[kPacketTimeOffset])); packet[1] |= 0x80; // break code - dispatchKeyboardEventWithPacket(packet); + if (!_macroInversion || !invertMacros(packet)) + { + // normal packet (break) + dispatchKeyboardEventWithPacket(packet); + } } } } @@ -713,7 +1043,7 @@ IOReturn ApplePS2Keyboard::message(UInt32 type, IOService* provider, void* argum if (!keystroke->eatKey) { // the key is consumed keystroke->eatKey = true; -// dispatchKeyboardEventX(keystroke->adbKeyCode, keystroke->goingDown, keystroke->time); + dispatchKeyboardEventX(keystroke->adbKeyCode, keystroke->goingDown, keystroke->time); } } break; @@ -726,6 +1056,10 @@ IOReturn ApplePS2Keyboard::message(UInt32 type, IOService* provider, void* argum PS2InterruptResult ApplePS2Keyboard::interruptOccurred(UInt8 data) // PS2InterruptAction { + ////IOLog("ps2interrupt: scanCode = %02x\n", data); + ////uint64_t time; + ////clock_get_uptime(&time); + ////IOLog("ps2interrupt(%lld): scanCode = %02x\n", time, data); // // This will be invoked automatically from our device when asynchronous @@ -843,8 +1177,11 @@ void ApplePS2Keyboard::packetReady() UInt8* packet = _ringBuffer.tail(); if (0x00 != packet[0]) { - // normal packet - dispatchKeyboardEventWithPacket(packet); + if (!_macroInversion || !invertMacros(packet)) + { + // normal packet + dispatchKeyboardEventWithPacket(packet); + } } else { @@ -855,6 +1192,188 @@ void ApplePS2Keyboard::packetReady() } } +bool ApplePS2Keyboard::compareMacro(const UInt8* buffer, const UInt8* data, int count) +{ + while (count--) + { + if (buffer[0] != data[0] || buffer[1] != data[1]) + return false; + buffer += kPacketLength; + data += kPacketKeyDataLength; + } + return true; +} + +bool ApplePS2Keyboard::invertMacros(const UInt8* packet) +{ + assert(_macroInversion); + + if (!_macroTimer || !_macroBuffer) + return false; + + if (_macroCurrent > 0) + { + // cancel macro conversion if packet arrives too late + uint64_t now_ns; + absolutetime_to_nanoseconds(*(uint64_t*)(&packet[kPacketTimeOffset]), &now_ns); + uint64_t prev; + absolutetime_to_nanoseconds(*(uint64_t*)(&_macroBuffer[(_macroCurrent-1)*kPacketLength+kPacketTimeOffset]), &prev); + if (now_ns-prev > _macroMaxTime) + dispatchInvertBuffer(); +#if 0 // for testing min/max between macro segments + uint64_t diff = now_ns-prev; + static uint64_t diffmin = UINT64_MAX, diffmax = 0; + if (diff > diffmax) diffmax = diff; + if (diff < diffmin) diffmin = diff; + IOLog("diffmin=%lld, diffmax=%lld\n", diffmin, diffmax); +#endif + } + + // add current packet to macro buffer for comparison + memcpy(_macroBuffer+_macroCurrent*kPacketLength, packet, kPacketLength); + int buffered = _macroCurrent+1; + int total = buffered*kPacketKeyDataLength; + // compare against macro inversions + for (OSData** p = _macroInversion; *p; p++) + { + int length = (*p)->getLength()-kPrefixBytes; + if (total <= length) + { + const UInt8* data = static_cast((*p)->getBytesNoCopy()); + if (compareMacro(_macroBuffer, data+kSequenceBytesOffset, buffered)) + { + if (total == length) + { + // get modifier mask/compare from macro definition + UInt16 mask = (static_cast(data[kModifierBytesOffset+0]) << 8) + data[kModifierBytesOffset+1]; + UInt16 compare = (static_cast(data[kModifierBytesOffset+2]) << 8) + data[kModifierBytesOffset+3]; + if ((0xFFFF == compare && (_PS2modifierState & mask)) || ((_PS2modifierState & mask) == compare)) + { + // exact match causes macro inversion + // grab bytes from macro definition + _macroBuffer[0] = data[kOutputBytesOffset+0]; + _macroBuffer[1] = data[kOutputBytesOffset+1]; + // dispatch constructed packet (timestamp is stamp on first macro packet) + dispatchKeyboardEventWithPacket(_macroBuffer); + cancelTimer(_macroTimer); + _macroCurrent = 0; + return true; + } + } + else + { + // partial match, keep waiting for full match + cancelTimer(_macroTimer); + setTimerTimeout(_macroTimer, _macroMaxTime); + _macroCurrent++; + return true; + } + } + } + } + // no match, so... empty macro buffer that may have been existing... + if (_macroCurrent > 0) + dispatchInvertBuffer(); + + return false; +} + +void ApplePS2Keyboard::onMacroTimer() +{ + DEBUG_LOG("ApplePS2Keyboard::onMacroTimer\n"); + + // timers have a very high priority, packets may have been placed in the + // input queue already. + + // by calling packetReady, these packets are processed before dealing with + // the timer (the packets may have arrived before the timer) + packetReady(); + + // after all packets have been processed, ok to check for time expiration + if (_macroCurrent > 0) + { + uint64_t now_abs, now_ns; + clock_get_uptime(&now_abs); + absolutetime_to_nanoseconds(now_abs, &now_ns); + uint64_t prev; + absolutetime_to_nanoseconds(*(uint64_t*)(&_macroBuffer[(_macroCurrent-1)*kPacketLength+kPacketTimeOffset]), &prev); + if (now_ns-prev > _macroMaxTime) + dispatchInvertBuffer(); + } +} + +void ApplePS2Keyboard::dispatchInvertBuffer() +{ + UInt8* packet = _macroBuffer; + for (int i = 0; i < _macroCurrent; i++) + { + // dispatch constructed packet + dispatchKeyboardEventWithPacket(packet); + packet += kPacketLength; + } + _macroCurrent = 0; + cancelTimer(_macroTimer); +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// +// Note: trying for ACPI backlight control for ASUS notebooks +// +// This one did work, so leaving this in. It is done in a generic way such that +// it can be used on more than just ASUS laptops, provided you can figure out +// how to implememnt the KKQC, KKCM, and KKCL methods. +// + +void ApplePS2Keyboard::modifyKeyboardBacklight(int keyCode, bool goingDown) +{ + assert(_provider); + assert(_backlightLevels); + + // get current brightness level + UInt32 result; + if (kIOReturnSuccess != _provider->evaluateInteger("KKQC", &result)) + { + DEBUG_LOG("ps2bl: KKQC returned error\n"); + return; + } + int current = result; +#ifdef DEBUG_VERBOSE + if (goingDown) + DEBUG_LOG("ps2bl: Current keyboard backlight: %d\n", current); +#endif + // calculate new brightness level, find current in table >= entry in table + // note first two entries in table are ac-power/battery + int index = 0; + while (index < _backlightCount) + { + if (_backlightLevels[index] >= current) + break; + ++index; + } + // move to next or previous + index += (keyCode == 0x4e ? +1 : -1); + if (index >= _backlightCount) + index = _backlightCount - 1; + if (index < 0) + index = 0; +#ifdef DEBUG_VERBOSE + if (goingDown) + DEBUG_LOG("ps2bl: setting keyboard backlight %d\n", _backlightLevels[index]); +#endif + OSNumber* num = OSNumber::withNumber(_backlightLevels[index], 32); + if (!num) + { + DEBUG_LOG("ps2bl: OSNumber::withNumber failed\n"); + return; + } + if (goingDown && kIOReturnSuccess != _provider->evaluateObject("KKCM", NULL, (OSObject**)&num, 1)) + { + DEBUG_LOG("ps2bl: KKCM returned error\n"); + } + num->release(); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - void ApplePS2Keyboard::onSleepEjectTimer() @@ -873,7 +1392,7 @@ void ApplePS2Keyboard::onSleepEjectTimer() { uint64_t now_abs; clock_get_uptime(&now_abs); - dispatchKeyboardEventX(kHIDPage_Consumer, kHIDUsage_Csmr_Eject, true, now_abs); + dispatchKeyboardEventX(0x92, true, now_abs); break; } } @@ -888,11 +1407,17 @@ bool ApplePS2Keyboard::dispatchKeyboardEventWithPacket(const UInt8* packet) UInt8 extended = packet[0] - 1; UInt8 scanCode = packet[1]; + +#ifdef DEBUG_VERBOSE + DEBUG_LOG("%s: PS/2 scancode %s 0x%x\n", getName(), extended ? "extended" : "", scanCode); +#endif unsigned keyCodeRaw = scanCode & ~kSC_UpBit; bool goingDown = !(scanCode & kSC_UpBit); unsigned keyCode; uint64_t now_abs = *(uint64_t*)(&packet[kPacketTimeOffset]); + uint64_t now_ns; + absolutetime_to_nanoseconds(now_abs, &now_ns); // // Convert the scan code into a key code index. @@ -910,20 +1435,36 @@ bool ApplePS2Keyboard::dispatchKeyboardEventWithPacket(const UInt8* packet) if (scanCode == 0xf2 || scanCode == 0xf1) { clock_get_uptime(&now_abs); - dispatchKeyboardEventX(_PS2ToHIDMap[scanCode], true, now_abs); + dispatchKeyboardEventX(_PS2ToADBMap[scanCode], true, now_abs); clock_get_uptime(&now_abs); - dispatchKeyboardEventX(_PS2ToHIDMap[scanCode], false, now_abs); + dispatchKeyboardEventX(_PS2ToADBMap[scanCode], false, now_abs); return true; } // Allow PS2 -> PS2 map to work, look in normal part of the table keyCode = _PS2ToPS2Map[keyCodeRaw]; + +#ifdef DEBUG_VERBOSE + if (keyCode != keyCodeRaw) + DEBUG_LOG("%s: keycode translated from=0x%02x to=0x%04x\n", getName(), keyCodeRaw, keyCode); +#endif } else { // allow PS2 -> PS2 map to work, look in extended part of the table keyCodeRaw += KBV_NUM_SCANCODES; keyCode = _PS2ToPS2Map[keyCodeRaw]; + +#ifdef DEBUG_VERBOSE + if (keyCode != keyCodeRaw) + DEBUG_LOG("%s: keycode translated from=0xe0%02x to=0x%04x\n", getName(), keyCodeRaw, keyCode); +#endif + // handle special cases + switch (keyCodeRaw) + { + case 0x012a: // header or trailer for PrintScreen + return false; + } } // tracking modifier key state @@ -933,15 +1474,85 @@ bool ApplePS2Keyboard::dispatchKeyboardEventWithPacket(const UInt8* packet) goingDown ? _PS2modifierState |= mask : _PS2modifierState &= ~mask; } + // codes e0f0 through e0ff can be used to call back into ACPI methods on this device + if (keyCode >= 0x01f0 && keyCode <= 0x01ff && _provider != NULL) + { + // evaluate RKA[0-F] for these keys + char method[5] = "RKAx"; + char n = keyCode - 0x01f0; + method[3] = n < 10 ? n + '0' : n - 10 + 'A'; + if (OSNumber* num = OSNumber::withNumber(goingDown, 32)) + { + // call ACPI RKAx(Arg0=goingDown) + _provider->evaluateObject(method, NULL, (OSObject**)&num, 1); + num->release(); + } + } + // handle special cases switch (keyCode) { + case 0x45: // NumLock + if (_numLockSupport && (scanCode == 0xc5)) // NumLock -> Up + { + setNumLock(!numLock()); + return true; + } + else if (_numLockSupport && (scanCode == 0x45)) // NumLock -> Down + return false; + break; + + case 0x4e: // Numpad+ + case 0x4a: // Numpad- + if (_backlightLevels && checkModifierState(kMaskLeftControl|kMaskLeftAlt)) + { + // Ctrl+Alt+Numpad(+/-) => use to manipulate keyboard backlight + modifyKeyboardBacklight(keyCode, goingDown); + keyCode = 0; + } + else if (_brightnessHack && checkModifierState(kMaskLeftControl|kMaskLeftShift)) + { + // Ctrl+Shift+NumPad(+/0) => manipulate brightness (special hack for HP Envy) + // Fn+F2 generates e0 ab and so does Fn+F3 (we will null those out in ps2 map) + static unsigned keys[] = { 0x2a, 0x1d }; + // if Option key is down don't pull up on the Shift keys + int state = checkModifierState(kMaskLeftWindows) ? 1 : 0; + for (int i = state; i < countof(keys); i++) + if (KBV_IS_KEYDOWN(keys[i])) + dispatchKeyboardEventX(_PS2ToADBMap[keys[i]], false, now_abs); + dispatchKeyboardEventX(keyCode == 0x4e ? 0x90 : 0x91, goingDown, now_abs); + for (int i = state; i < countof(keys); i++) + if (KBV_IS_KEYDOWN(keys[i])) + dispatchKeyboardEventX(_PS2ToADBMap[keys[i]], true, now_abs); + keyCode = 0; + } + break; + + case 0x0153: // delete + // check for Ctrl+Alt+Delete? (three finger salute) + if (checkModifierState(kMaskLeftControl|kMaskLeftAlt)) + { + keyCode = 0; + if (!goingDown) + { + // Note: If OS X thinks the Command and Control keys are down at the time of + // receiving an ADB 0x7f (power button), it will unconditionaly and unsafely + // reboot the computer, much like the old PC/AT Ctrl+Alt+Delete! + // That's why we make sure Control (0x3b) and Alt (0x37) are up!! + dispatchKeyboardEventX(0x37, false, now_abs); + dispatchKeyboardEventX(0x3b, false, now_abs); + dispatchKeyboardEventX(0x7f, true, now_abs); + dispatchKeyboardEventX(0x7f, false, now_abs); + } + } + break; + case 0x015f: // sleep keyCode = 0; if (goingDown) { _timerFunc = kTimerSleep; - if (!_maxsleeppresstime) + if (_fkeymode || !_maxsleeppresstime) onSleepEjectTimer(); else setTimerTimeout(_sleepEjectTimer, (uint64_t)_maxsleeppresstime * 1000000); @@ -951,78 +1562,287 @@ bool ApplePS2Keyboard::dispatchKeyboardEventWithPacket(const UInt8* packet) cancelTimer(_sleepEjectTimer); } break; + + //REVIEW: this is getting a bit ugly + case 0x0054: // SysRq (PrntScr when combined with Alt modifier -left or right-) + if (!_remapPrntScr) + break; + case 0x0128: // alternate that cannot fnkeys toggle (discrete trackpad toggle) + { + + // PrntScr is handled specially by some keyboard devices. + // See: 5.19 on https://www.win.tue.nl/~aeb/linux/kbd/scancodes-5.html#mtek +#ifdef DEBUG + UInt16 debug_originalModifiers = _PS2modifierState; +#endif + // Force Alt (Left) key to be down when receiving this keycode, dont rely on KB firmware + _PS2modifierState &= ~kMaskRightAlt; + _PS2modifierState |= kMaskLeftAlt; + keyCode = 0x0137; // Rewrite keycode + +#ifdef DEBUG + IOLog("VoodooPS2Keyboard: special PrntScr: modifiersBefore=%#.4X modifiersAfter=%#.4X\n", debug_originalModifiers, _PS2modifierState); +#endif + + // Fall to the original PrntScr handling case + } + case 0x0137: // prt sc/sys rq + { + if (!_remapPrntScr) + break; + + /* Supported Voodoo PrntScr Key combinations: + PrntScr Enable/Disable touchpad + Windows+PrntScr Enable/Disable touchpad+keyboard + Ctrl+Alt+PrntScr Reset and enable touchpad + Shift+PrntScr Send SysRq scancode to the kernel + + Notes: + - Alt+Windows combo seems to be masked out by some keyboard devices and dont produce any ScanCode. + Dont rely on it. + */ + + unsigned origKeyCode = keyCode; + keyCode = 0; // Handle all these keycode variants internally + +#ifdef DEBUG + bool debug_control = checkModifierStateAny(kMaskLeftControl|kMaskRightControl); + bool debug_alt = checkModifierStateAny(kMaskLeftAlt|kMaskRightAlt); + bool debug_shift = checkModifierStateAny(kMaskLeftShift|kMaskRightShift); + bool debug_windows = checkModifierStateAny(kMaskLeftWindows|kMaskRightWindows); + + IOLog("VoodooPS2Keyboard: PrtScr:: goingDown=%s control=%s alt=%s shift=%s windows=%s modifiers=%d\n", + goingDown ? "Yes" : "No", + debug_control ? "Yes" : "No", + debug_alt ? "Yes" : "No", + debug_shift ? "Yes" : "No", + debug_windows ? "Yes" : "No", + _PS2modifierState); +#endif + + if (!goingDown) + break; + + if (checkModifierStateAny(kMaskLeftControl|kMaskRightControl)) + { + // Shift is ignored from this point onwards + if (checkModifierStateAny(kMaskLeftAlt|kMaskRightAlt)) + { + // Ctrl+Alt+PrntScr + IOLog("VoodooPS2Keyboard: Sending RESET signal to touchpad."); // Dont wrap into a DEBUG compilation condition since this should be a workaroung to be used on faulty states only + int val = 1; + _device->dispatchMessage(kPS2M_resetTouchpad, &val); // Reset touchpad + } + } + else + { + if (checkModifierState(kMaskLeftShift) || checkModifierState(kMaskRightShift)) + { + // Shift+PrntScr, no other modifiers present +#ifdef DEBUG + IOLog("VoodooPS2Keyboard: Sending SysRq virtual scancode 0x58"); +#endif + dispatchKeyboardEventX(0x58, true, now_abs); // Send SysRq to the kernel + dispatchKeyboardEventX(0x58, false, now_abs); + } + else + { + if (checkModifierStateAny(kMaskRightShift|kMaskLeftShift|kMaskRightAlt|kMaskLeftAlt)) + break; // Eat combinations where Ctrl is Up and Alt or Shift are Down (!Ctrl+[Alt|Shift]) + + bool enabled; + if (checkModifierStateAny(kMaskLeftWindows|kMaskRightWindows)) + { + // Windows+PrntScr + // Disable keyboard input along with the touchpad using Windows(Option)+prtsc, useful for 2-in-1 applications. +#ifdef DEBUG + IOLog("VoodooPS2Keyboard: Toggling keyboard+Touchpad enabled state."); +#endif + enabled = _disableInput; + _disableInput = !_disableInput; + _device->dispatchMessage(kPS2M_setDisableTouchpad, &enabled); // Sync Keyboard and Touchpad enabled states + } + else + { + // No other modifiers pressed down +#ifdef DEBUG + IOLog("VoodooPS2Keyboard: Toggling Touchpad enabled state."); +#endif + // Touchpad enable/disable: get current enabled status, and toggle it + _device->dispatchMessage(kPS2M_getDisableTouchpad, &enabled); + enabled = !enabled; + _device->dispatchMessage(kPS2M_setDisableTouchpad, &enabled); + } + } + + break; + } + + if (origKeyCode != 0x0137) + break; // do not fall through for 0x0128 + // fall through + } + case 0x0127: // alternate for fnkeys toggle (discrete fnkeys toggle) + keyCode = 0; + if (!goingDown) + break; + if (_fkeymodesupported) + { + // modify HIDFKeyMode via IOService... IOHIDSystem + if (IOService* service = IOService::waitForMatchingService(serviceMatching(kIOHIDSystem), 0)) + { + const OSObject* num = OSNumber::withNumber(!_fkeymode, 32); + const OSString* key = OSString::withCString(kHIDFKeyMode); + if (num && key) + { + if (OSDictionary* dict = OSDictionary::withObjects(&num, &key, 1)) + { + service->setProperties(dict); + dict->release(); + } + } + OSSafeReleaseNULL(num); + OSSafeReleaseNULL(key); + service->release(); + } + } + break; +#ifdef DEBUG + default: + IOLog("VoodooPS2Keyboard: Unhandled keycode: %#.4X\n", keyCode); +#endif } // If keyboard input is disabled drop the key code.. if (_disableInput && goingDown) keyCode=0; +#ifdef DEBUG + // allow hold Alt+numpad keys to type in arbitrary ADB key code + static int genADB = -1; + if (goingDown && checkModifierState(kMaskLeftAlt) && + ((keyCodeRaw >= 0x47 && keyCodeRaw <= 0x52 && keyCodeRaw != 0x4e && keyCodeRaw != 0x4a) || + (keyCodeRaw >= 0x02 && keyCodeRaw <= 0x0B))) + { + // map numpad scan codes to digits + static int map1[0x52-0x47+1] = { 7, 8, 9, -1, 4, 5, 6, -1, 1, 2, 3, 0 }; + static int map2[0x0B-0x02+1] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; + if (-1 == genADB) + genADB = 0; + int digit = keyCodeRaw >= 0x47 ? map1[keyCodeRaw-0x47] : map2[keyCodeRaw-0x02]; + if (-1 != digit) + genADB = genADB * 10 + digit; + DEBUG_LOG("%s: genADB = %d\n", getName(), genADB); + keyCode = 0; // eat it + } +#endif + // We have a valid key event -- dispatch it to our superclass. // map scan code to Apple code - const VoodooPS2HidElement &hidKeyCode = _PS2ToHIDMap[keyCode]; -// bool eatKey = false; + UInt8 adbKeyCode = _PS2ToADBMap[keyCode]; + bool eatKey = false; // special cases - if (hidKeyCode.usage == kHIDUsage_Csmr_Eject && hidKeyCode.usagePage == kHIDPage_Consumer) { - if (0 == _PS2modifierState) - { - if (goingDown) + switch (adbKeyCode) + { + case 0x92: // eject + if (0 == _PS2modifierState) { -// eatKey = true; - _timerFunc = kTimerEject; - if (!_f12ejectdelay) - onSleepEjectTimer(); + if (goingDown) + { + eatKey = true; + _timerFunc = kTimerEject; + if (!_f12ejectdelay) + onSleepEjectTimer(); + else + setTimerTimeout(_sleepEjectTimer, (uint64_t)_f12ejectdelay * 1000000); + } else - setTimerTimeout(_sleepEjectTimer, (uint64_t)_f12ejectdelay * 1000000); - } - else - { - cancelTimer(_sleepEjectTimer); + { + cancelTimer(_sleepEjectTimer); + } } - } + break; } + +#ifdef DEBUG_VERBOSE + if (adbKeyCode == DEADKEY && 0 != keyCode) + DEBUG_LOG("%s: Unknown ADB key for PS2 scancode: 0x%x\n", getName(), scanCode); + else + DEBUG_LOG("%s: ADB key code 0x%x %s\n", getName(), adbKeyCode, goingDown?"down":"up"); +#endif -#ifdef DEBUG - uint16_t debugCode = keyCode > KBV_NUM_SCANCODES ? (keyCode & 0xFF) | 0xe000 : keyCode; - IOLog("%s: Sending key %x = Page %x Usage %x %s\n", getName(), debugCode, hidKeyCode.usagePage, hidKeyCode.usage, goingDown ? "down" : "up"); +#ifdef DEBUG_LITE + int logscancodes = 2; +#else + int logscancodes = _logscancodes; #endif + if (logscancodes==2 || (logscancodes==1 && goingDown)) + { + if (keyCode == keyCodeRaw) + IOLog("%s: sending key %x=%x %s\n", getName(), keyCode > KBV_NUM_SCANCODES ? (keyCode & 0xFF) | 0xe000 : keyCode, adbKeyCode, goingDown?"down":"up"); + else + IOLog("%s: sending key %x=%x, %x=%x %s\n", getName(), keyCodeRaw > KBV_NUM_SCANCODES ? (keyCodeRaw & 0xFF) | 0xe000 : keyCodeRaw, keyCode > KBV_NUM_SCANCODES ? (keyCode & 0xFF) | 0xe000 : keyCode, keyCode > KBV_NUM_SCANCODES ? (keyCode & 0xFF) | 0xe000 : keyCode, adbKeyCode, goingDown?"down":"up"); + } // allow mouse/trackpad driver to have time of last keyboard activity // used to implement "PalmNoAction When Typing" and "OutsizeZoneNoAction When Typing" -// PS2KeyInfo info; -// info.time = now_ns; -// info.adbKeyCode = hidKeyCode.usage; -// info.goingDown = goingDown; -// info.eatKey = eatKey; -// -// _device->dispatchMessage(kPS2M_notifyKeyPressed, &info); + PS2KeyInfo info; + info.time = now_ns; + info.adbKeyCode = adbKeyCode; + info.goingDown = goingDown; + info.eatKey = eatKey; - // Convert ALT + Brightness to Keyboard Brightness - if (hidKeyCode.usagePage == kHIDPage_AppleVendorTopCase && checkModifierState(kMaskLeftAlt)) { - // Release left alt before sending brightness keys. macOS otherwise ignores the keypress - VoodooPS2HidElement altElem = _PS2ToHIDMap[0x38]; - dispatchKeyboardEventX(altElem, false, now_abs); - - if (hidKeyCode.usage == kHIDUsage_AV_TopCase_BrightnessUp) { - dispatchKeyboardEventX(kHIDPage_AppleVendorTopCase, kHIDUsage_AV_TopCase_IlluminationUp, goingDown, now_abs); - dispatchKeyboardEventX(altElem, true, now_abs); - return true; - } else if (hidKeyCode.usage == kHIDUsage_AV_TopCase_BrightnessDown) { - dispatchKeyboardEventX(kHIDPage_AppleVendorTopCase, kHIDUsage_AV_TopCase_IlluminationDown, goingDown, now_abs); - dispatchKeyboardEventX(altElem, true, now_abs); - return true; + _device->dispatchMessage(kPS2M_notifyKeyPressed, &info); + + //REVIEW: work around for caps lock bug on Sierra 10.12... + if (adbKeyCode == 0x39 && version_major >= 16) + { + // Mojave 10.14 only needs a part of the workaround: + // https://github.com/RehabMan/OS-X-Voodoo-PS2-Controller/issues/142#issuecomment-529813842 + if (goingDown || version_major >= 18) + { + DEBUG_LOG("%s: Caps Lock goingDown: 0x%x\n", getName(), goingDown); + _ignoreCapsLedChange = true; + clock_get_uptime(&now_abs); + dispatchKeyboardEventX(adbKeyCode, true, now_abs); + clock_get_uptime(&now_abs); + dispatchKeyboardEventX(adbKeyCode, false, now_abs); } + if (goingDown && version_major < 18) { + static bool firsttime = true; + if (!firsttime) + { + clock_get_uptime(&now_abs); + dispatchKeyboardEventX(adbKeyCode, true, now_abs); + clock_get_uptime(&now_abs); + dispatchKeyboardEventX(adbKeyCode, false, now_abs); + } + firsttime = false; + } + return true; } - - if (hidKeyCode.usage != 0 && hidKeyCode.usagePage != 0) + + if (keyCode && !info.eatKey) { // dispatch to HID system if (goingDown || !(_PS2flags[keyCodeRaw] & kBreaklessKey)) - dispatchKeyboardEventX(hidKeyCode, goingDown, now_abs); + dispatchKeyboardEventX(adbKeyCode, goingDown, now_abs); if (goingDown && (_PS2flags[keyCodeRaw] & kBreaklessKey)) - dispatchKeyboardEventX(hidKeyCode, false, now_abs); + dispatchKeyboardEventX(adbKeyCode, false, now_abs); } + +#ifdef DEBUG + if (0x38 == keyCode && !goingDown && -1 != genADB) // Alt going up + { + // dispatch typed adb code + dispatchKeyboardEventX(genADB, true, now_abs); + dispatchKeyboardEventX(genADB, false, now_abs); + DEBUG_LOG("%s: sending typed ADB code 0x%x\n", getName(), genADB); + genADB = -1; + } +#endif return true; } @@ -1072,14 +1892,18 @@ void ApplePS2Keyboard::setLEDs(UInt8 ledState) // It is safe to issue this request from the interrupt/completion context. // - PS2Request* request = _device->allocateRequest(2); + PS2Request* request = _device->allocateRequest(4); // (set LEDs command) - request->commands[0].command = kPS2C_SendCommandAndCompareAck; + request->commands[0].command = kPS2C_WriteDataPort; request->commands[0].inOrOut = kDP_SetKeyboardLEDs; - request->commands[1].command = kPS2C_SendCommandAndCompareAck; - request->commands[1].inOrOut = ledState; - request->commandsCount = 2; + request->commands[1].command = kPS2C_ReadDataPortAndCompare; + request->commands[1].inOrOut = kSC_Acknowledge; + request->commands[2].command = kPS2C_WriteDataPort; + request->commands[2].inOrOut = ledState; + request->commands[3].command = kPS2C_ReadDataPortAndCompare; + request->commands[3].inOrOut = kSC_Acknowledge; + request->commandsCount = 4; _device->submitRequest(request); } @@ -1097,16 +1921,270 @@ void ApplePS2Keyboard::setKeyboardEnable(bool enable) // // (keyboard enable/disable command) - TPS2Request<1> request; - request.commands[0].command = kPS2C_SendCommandAndCompareAck; + TPS2Request<2> request; + request.commands[0].command = kPS2C_WriteDataPort; request.commands[0].inOrOut = enable ? kDP_Enable : kDP_SetDefaults; - request.commandsCount = 1; + request.commands[1].command = kPS2C_ReadDataPortAndCompare; + request.commands[1].inOrOut = kSC_Acknowledge; + request.commandsCount = 2; assert(request.commandsCount <= countof(request.commands)); _device->submitRequestAndBlock(&request); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +const unsigned char * ApplePS2Keyboard::defaultKeymapOfLength(UInt32 * length) +{ + // + // Keymap data borrowed and modified from IOHIDFamily/IOHIDKeyboard.cpp + // references http://www.xfree.org/current/dumpkeymap.1.html + // http://www.tamasoft.co.jp/en/general-info/unicode.html + // + static const unsigned char appleUSAKeyMap[] = { + 0x00,0x00, // use byte unit. + + + // modifier definition + 0x0b, //Number of modifier keys. + // ( modifier , num of keys, ADB keycodes... ) + // ( 0x00 , 0x01 , 0x39 ) + //0x00,0x01,0x39, //NX_MODIFIERKEY_ALPHALOCK, uses one byte, ADB keycode is 0x39 + //13,0x01,0x39,//NX_MODIFIERKEY_ALPHALOCK_STATELESS + NX_MODIFIERKEY_SHIFT, 0x01,0x38, + NX_MODIFIERKEY_CONTROL, 0x01,0x3b, + NX_MODIFIERKEY_ALTERNATE, 0x01,0x3a, + NX_MODIFIERKEY_COMMAND, 0x01,0x37, + NX_MODIFIERKEY_NUMERICPAD, 0x15,0x52,0x41,0x4c,0x53,0x54,0x55,0x45,0x58,0x57,0x56,0x5b,0x5c,0x43,0x4b,0x51,0x7b,0x7d,0x7e,0x7c,0x4e,0x59, + NX_MODIFIERKEY_HELP, 0x01,0x72, + NX_MODIFIERKEY_SECONDARYFN, 0x01,0x3f, // Apple's Fn key + NX_MODIFIERKEY_RSHIFT, 0x01,0x3c, + NX_MODIFIERKEY_RCONTROL, 0x01,0x3e, + NX_MODIFIERKEY_RALTERNATE, 0x01,0x3d, + NX_MODIFIERKEY_RCOMMAND, 0x01,0x36, + + + // ADB virtual key definitions + 0xa2, // number of key definitions + // ( modifier mask , generated character{char_set,char_code}... ) + // ( 0x0d[has 3bit modifiers], {0x00,0x3c}, {0x00,0x3e}, ... total 2^3 characters ) + 0x0d,0x00,0x61,0x00,0x41,0x00,0x01,0x00,0x01,0x00,0xca,0x00,0xc7,0x00,0x01,0x00,0x01, //00 A + 0x0d,0x00,0x73,0x00,0x53,0x00,0x13,0x00,0x13,0x00,0xfb,0x00,0xa7,0x00,0x13,0x00,0x13, //01 S + 0x0d,0x00,0x64,0x00,0x44,0x00,0x04,0x00,0x04,0x01,0x44,0x01,0xb6,0x00,0x04,0x00,0x04, //02 D + 0x0d,0x00,0x66,0x00,0x46,0x00,0x06,0x00,0x06,0x00,0xa6,0x01,0xac,0x00,0x06,0x00,0x06, //03 F + 0x0d,0x00,0x68,0x00,0x48,0x00,0x08,0x00,0x08,0x00,0xe3,0x00,0xeb,0x00,0x00,0x18,0x00, //04 H + 0x0d,0x00,0x67,0x00,0x47,0x00,0x07,0x00,0x07,0x00,0xf1,0x00,0xe1,0x00,0x07,0x00,0x07, //05 G + 0x0d,0x00,0x7a,0x00,0x5a,0x00,0x1a,0x00,0x1a,0x00,0xcf,0x01,0x57,0x00,0x1a,0x00,0x1a, //06 Z + 0x0d,0x00,0x78,0x00,0x58,0x00,0x18,0x00,0x18,0x01,0xb4,0x01,0xce,0x00,0x18,0x00,0x18, //07 X + 0x0d,0x00,0x63,0x00,0x43,0x00,0x03,0x00,0x03,0x01,0xe3,0x01,0xd3,0x00,0x03,0x00,0x03, //08 C + 0x0d,0x00,0x76,0x00,0x56,0x00,0x16,0x00,0x16,0x01,0xd6,0x01,0xe0,0x00,0x16,0x00,0x16, //09 V + 0x02,0x00,0x3c,0x00,0x3e, //0a NON-US-BACKSLASH on ANSI and JIS keyboards GRAVE on ISO + 0x0d,0x00,0x62,0x00,0x42,0x00,0x02,0x00,0x02,0x01,0xe5,0x01,0xf2,0x00,0x02,0x00,0x02, //0b B + 0x0d,0x00,0x71,0x00,0x51,0x00,0x11,0x00,0x11,0x00,0xfa,0x00,0xea,0x00,0x11,0x00,0x11, //0c Q + 0x0d,0x00,0x77,0x00,0x57,0x00,0x17,0x00,0x17,0x01,0xc8,0x01,0xc7,0x00,0x17,0x00,0x17, //0d W + 0x0d,0x00,0x65,0x00,0x45,0x00,0x05,0x00,0x05,0x00,0xc2,0x00,0xc5,0x00,0x05,0x00,0x05, //0e E + 0x0d,0x00,0x72,0x00,0x52,0x00,0x12,0x00,0x12,0x01,0xe2,0x01,0xd2,0x00,0x12,0x00,0x12, //0f R + 0x0d,0x00,0x79,0x00,0x59,0x00,0x19,0x00,0x19,0x00,0xa5,0x01,0xdb,0x00,0x19,0x00,0x19, //10 Y + 0x0d,0x00,0x74,0x00,0x54,0x00,0x14,0x00,0x14,0x01,0xe4,0x01,0xd4,0x00,0x14,0x00,0x14, //11 T + 0x0a,0x00,0x31,0x00,0x21,0x01,0xad,0x00,0xa1, //12 1 + 0x0e,0x00,0x32,0x00,0x40,0x00,0x32,0x00,0x00,0x00,0xb2,0x00,0xb3,0x00,0x00,0x00,0x00, //13 2 + 0x0a,0x00,0x33,0x00,0x23,0x00,0xa3,0x01,0xba, //14 3 + 0x0a,0x00,0x34,0x00,0x24,0x00,0xa2,0x00,0xa8, //15 4 + 0x0e,0x00,0x36,0x00,0x5e,0x00,0x36,0x00,0x1e,0x00,0xb6,0x00,0xc3,0x00,0x1e,0x00,0x1e, //16 6 + 0x0a,0x00,0x35,0x00,0x25,0x01,0xa5,0x00,0xbd, //17 5 + 0x0a,0x00,0x3d,0x00,0x2b,0x01,0xb9,0x01,0xb1, //18 EQUALS + 0x0a,0x00,0x39,0x00,0x28,0x00,0xac,0x00,0xab, //19 9 + 0x0a,0x00,0x37,0x00,0x26,0x01,0xb0,0x01,0xab, //1a 7 + 0x0e,0x00,0x2d,0x00,0x5f,0x00,0x1f,0x00,0x1f,0x00,0xb1,0x00,0xd0,0x00,0x1f,0x00,0x1f, //1b MINUS + 0x0a,0x00,0x38,0x00,0x2a,0x00,0xb7,0x00,0xb4, //1c 8 + 0x0a,0x00,0x30,0x00,0x29,0x00,0xad,0x00,0xbb, //1d 0 + 0x0e,0x00,0x5d,0x00,0x7d,0x00,0x1d,0x00,0x1d,0x00,0x27,0x00,0xba,0x00,0x1d,0x00,0x1d, //1e RIGHTBRACKET + 0x0d,0x00,0x6f,0x00,0x4f,0x00,0x0f,0x00,0x0f,0x00,0xf9,0x00,0xe9,0x00,0x0f,0x00,0x0f, //1f O + 0x0d,0x00,0x75,0x00,0x55,0x00,0x15,0x00,0x15,0x00,0xc8,0x00,0xcd,0x00,0x15,0x00,0x15, //20 U + 0x0e,0x00,0x5b,0x00,0x7b,0x00,0x1b,0x00,0x1b,0x00,0x60,0x00,0xaa,0x00,0x1b,0x00,0x1b, //21 LEFTBRACKET + 0x0d,0x00,0x69,0x00,0x49,0x00,0x09,0x00,0x09,0x00,0xc1,0x00,0xf5,0x00,0x09,0x00,0x09, //22 I + 0x0d,0x00,0x70,0x00,0x50,0x00,0x10,0x00,0x10,0x01,0x70,0x01,0x50,0x00,0x10,0x00,0x10, //23 P + 0x10,0x00,0x0d,0x00,0x03, //24 RETURN + 0x0d,0x00,0x6c,0x00,0x4c,0x00,0x0c,0x00,0x0c,0x00,0xf8,0x00,0xe8,0x00,0x0c,0x00,0x0c, //25 L + 0x0d,0x00,0x6a,0x00,0x4a,0x00,0x0a,0x00,0x0a,0x00,0xc6,0x00,0xae,0x00,0x0a,0x00,0x0a, //26 J + 0x0a,0x00,0x27,0x00,0x22,0x00,0xa9,0x01,0xae, //27 APOSTROPHE + 0x0d,0x00,0x6b,0x00,0x4b,0x00,0x0b,0x00,0x0b,0x00,0xce,0x00,0xaf,0x00,0x0b,0x00,0x0b, //28 K + 0x0a,0x00,0x3b,0x00,0x3a,0x01,0xb2,0x01,0xa2, //29 SEMICOLON + 0x0e,0x00,0x5c,0x00,0x7c,0x00,0x1c,0x00,0x1c,0x00,0xe3,0x00,0xeb,0x00,0x1c,0x00,0x1c, //2a BACKSLASH + 0x0a,0x00,0x2c,0x00,0x3c,0x00,0xcb,0x01,0xa3, //2b COMMA + 0x0a,0x00,0x2f,0x00,0x3f,0x01,0xb8,0x00,0xbf, //2c SLASH + 0x0d,0x00,0x6e,0x00,0x4e,0x00,0x0e,0x00,0x0e,0x00,0xc4,0x01,0xaf,0x00,0x0e,0x00,0x0e, //2d N + 0x0d,0x00,0x6d,0x00,0x4d,0x00,0x0d,0x00,0x0d,0x01,0x6d,0x01,0xd8,0x00,0x0d,0x00,0x0d, //2e M + 0x0a,0x00,0x2e,0x00,0x3e,0x00,0xbc,0x01,0xb3, //2f PERIOD + 0x02,0x00,0x09,0x00,0x19, //30 TAB + 0x0c,0x00,0x20,0x00,0x00,0x00,0x80,0x00,0x00, //31 SPACE + 0x0a,0x00,0x60,0x00,0x7e,0x00,0x60,0x01,0xbb, //32 GRAVE on ANSI and JIS keyboards, NON-US-BACKSLASH on ISO + 0x02,0x00,0x7f,0x00,0x08, //33 BACKSPACE + 0xff, //34 PLAY/PAUSE + 0x02,0x00,0x1b,0x00,0x7e, //35 ESCAPE + 0xff, //36 RGUI + 0xff, //37 LGUI + 0xff, //38 LSHIFT + 0xff, //39 CAPSLOCK + 0xff, //3a LALT + 0xff, //3b LCTRL + 0xff, //3c RSHIFT + 0xff, //3d RALT + 0xff, //3e RCTRL + 0xff, //3f Apple Fn key + 0x00,0xfe,0x36, //40 F17 + 0x00,0x00,0x2e, //41 KEYPAD_PERIOD + 0xff, //42 NEXT TRACK or FAST + 0x00,0x00,0x2a, //43 KEYPAD_MULTIPLY + 0xff, //44 + 0x00,0x00,0x2b, //45 KEYPAD_PLUS + 0xff, //46 + 0x00,0x00,0x1b, //47 CLEAR + 0xff, //48 VOLUME UP + 0xff, //49 VOLUME DOWN + 0xff, //4a MUTE + 0x0e,0x00,0x2f,0x00,0x5c,0x00,0x2f,0x00,0x1c,0x00,0x2f,0x00,0x5c,0x00,0x00,0x0a,0x00, //4b KEYPAD_DIVIDE + 0x00,0x00,0x0d, //4c Apple Fn + Return = ENTER //XX03 + 0xff, //4d PREVIOUS TRACK or REWIND + 0x00,0x00,0x2d, //4e KEYPAD_MINUS + 0x00,0xfe,0x37, //4f F18 + 0x00,0xfe,0x38, //50 F19 + 0x0e,0x00,0x3d,0x00,0x7c,0x00,0x3d,0x00,0x1c,0x00,0x3d,0x00,0x7c,0x00,0x00,0x18,0x46, //51 KEYPAD_EQUALS + 0x00,0x00,0x30, //52 KEYPAD_0 + 0x00,0x00,0x31, //53 KEYPAD_1 + 0x00,0x00,0x32, //54 KEYPAD_2 + 0x00,0x00,0x33, //55 KEYPAD_3 + 0x00,0x00,0x34, //56 KEYPAD_4 + 0x00,0x00,0x35, //57 KEYPAD_5 + 0x00,0x00,0x36, //58 KEYPAD_6 + 0x00,0x00,0x37, //59 KEYPAD_7 + 0x00,0xfe,0x39, //5a F20 + 0x00,0x00,0x38, //5b KEYPAD_8 + 0x00,0x00,0x39, //5c KEYPAD_9 + 0xff, //0x02,0x00,0xa5,0x00,0x7c, //5d JIS JAPANESE YEN + 0xff, //0x00,0x00,0x5f, //5e JIS JAPANESE RO + 0xff, //0x00,0x00,0x2c, //5f KEYPAD_COMMA, JIS only + 0x00,0xfe,0x24, //60 F5 + 0x00,0xfe,0x25, //61 F6 + 0x00,0xfe,0x26, //62 F7 + 0x00,0xfe,0x22, //63 F3 + 0x00,0xfe,0x27, //64 F8 + 0x00,0xfe,0x28, //65 F9 + 0xff, //66 JIS JAPANESE EISU, KOREAN HANJA + 0x00,0xfe,0x2a, //67 F11 + 0xff, //68 JIS JAPANESE KANA, KOREAN HANGUL + 0x00,0xfe,0x32, //69 F13 + 0x00,0xfe,0x35, //6a F16 + 0x00,0xfe,0x33, //6b F14 + 0xff, //6c + 0x00,0xfe,0x29, //6d F10 + 0xff, //6e + 0x00,0xfe,0x2b, //6f F12 + 0xff, //70 + 0x00,0xfe,0x34, //71 F15 + 0xff, //72 HELP + 0x00,0xfe,0x2e, //73 HOME + 0x00,0xfe,0x30, //74 PAGEUP + 0x00,0xfe,0x2d, //75 DELETE + 0x00,0xfe,0x23, //76 F4 + 0x00,0xfe,0x2f, //77 END + 0x00,0xfe,0x21, //78 F2 + 0x00,0xfe,0x31, //79 PAGEDOWN + 0x00,0xfe,0x20, //7a F1 + 0x00,0x01,0xac, //7b LEFT ARROW + 0x00,0x01,0xae, //7c RIGHT ARROW + 0x00,0x01,0xaf, //7d DOWN ARROW + 0x00,0x01,0xad, //7e UP ARROW + 0x00,0x00,0x00, //7f POWER + 0x00,0x00,0x00, + 0x00,0x00,0x00, //81 Spotlight + 0x00,0x00,0x00, //82 Dashboard + 0x00,0x00,0x00, //83 Launchpad + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, //90 Main Brightness Up + 0x00,0x00,0x00, //91 Main Brightness Down + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, + 0x00,0x00,0x00, // a0 Exposes All + 0x00,0x00,0x00, // a1 Expose Desktop + + + // key sequence definition + // I tested some key sequence "Command + Shift + '['", but it doesn't work well. + // No one sequence was used on key deff table now. + 0x11, // number of of sequence definitions + // ( num of keys, generated sequence characters(char_set,char_code)... ) + // ( 0x02 , {0xff,0x04}, {0x00,0x31}, ) + 0x02,0xff,0x04,0x00,0x31, // Command + '1' + 0x02,0xff,0x04,0x00,0x32, // Command + '2' + 0x02,0xff,0x04,0x00,0x33, // Command + '3' + 0x02,0xff,0x04,0x00,0x34, // Command + '4' + 0x02,0xff,0x04,0x00,0x35, // Command + '5' + 0x02,0xff,0x04,0x00,0x36, // Command + '6' + 0x02,0xff,0x04,0x00,0x37, // Command + '7' + 0x02,0xff,0x04,0x00,0x38, // Command + '8' + 0x02,0xff,0x04,0x00,0x39, // Command + '9' + 0x02,0xff,0x04,0x00,0x30, // Command + '0' + 0x02,0xff,0x04,0x00,0x2d, // Command + '-' + 0x02,0xff,0x04,0x00,0x3d, // Command + '=' + 0x02,0xff,0x04,0x00,0x70, // Command + 'p' + 0x02,0xff,0x04,0x00,0x5d, // Command + ']' + 0x02,0xff,0x04,0x00,0x5b, // Command + '[' + 0x03,0xff,0x04,0xff,0x01,0x00,0x5b, // Command + Shift + '[' + 0x03,0xff,0x04,0xff,0x01,0x00,0x5d, // Command + shift + ']' + + + // special key definition + 0x0e, // number of special keys + // ( NX_KEYTYPE, Virtual ADB code ) + NX_KEYTYPE_CAPS_LOCK, 0x39, + NX_KEYTYPE_HELP, 0x72, + NX_POWER_KEY, 0x7f, + NX_KEYTYPE_MUTE, 0x4a, + NX_KEYTYPE_SOUND_UP, 0x48, + NX_KEYTYPE_SOUND_DOWN, 0x49, + // remove arrow keys as special keys. They are generating double up/down scroll events + // in both carbon and coco apps. + //NX_UP_ARROW_KEY, 0x7e, // ADB is 3e raw, 7e virtual (KMAP) + //NX_DOWN_ARROW_KEY, 0x7d, // ADB is 0x3d raw, 7d virtual + NX_KEYTYPE_NUM_LOCK, 0x47, // ADB combines with CLEAR key for numlock + NX_KEYTYPE_VIDMIRROR, 0x70, + NX_KEYTYPE_PLAY, 0x34, + NX_KEYTYPE_NEXT, 0x42, // if this event repeated, act as NX_KEYTYPE_FAST + NX_KEYTYPE_PREVIOUS, 0x4d, // if this event repeated, act as NX_KEYTYPE_REWIND + NX_KEYTYPE_BRIGHTNESS_UP, 0x90, + NX_KEYTYPE_BRIGHTNESS_DOWN, 0x91, + NX_KEYTYPE_EJECT, 0x92, + }; + + *length = sizeof(appleUSAKeyMap); + return appleUSAKeyMap; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + void ApplePS2Keyboard::setDevicePowerState( UInt32 whatToDo ) { switch ( whatToDo ) @@ -1135,10 +2213,12 @@ void ApplePS2Keyboard::initKeyboard() // Reset the keyboard to its default state. // - TPS2Request<1> request; - request.commands[0].command = kPS2C_SendCommandAndCompareAck; + TPS2Request<2> request; + request.commands[0].command = kPS2C_WriteDataPort; request.commands[0].inOrOut = kDP_SetDefaults; - request.commandsCount = 1; + request.commands[1].command = kPS2C_ReadDataPortAndCompare; + request.commands[1].inOrOut = kSC_Acknowledge; + request.commandsCount = 2; assert(request.commandsCount <= countof(request.commands)); _device->submitRequestAndBlock(&request); diff --git a/VoodooPS2Keyboard/VoodooPS2Keyboard.h b/VoodooPS2Keyboard/VoodooPS2Keyboard.h index d0dc226d..797120f9 100644 --- a/VoodooPS2Keyboard/VoodooPS2Keyboard.h +++ b/VoodooPS2Keyboard/VoodooPS2Keyboard.h @@ -25,8 +25,7 @@ #include #include "../VoodooPS2Controller/ApplePS2KeyboardDevice.h" -#include "VoodooPS2KeyboardHIDWrapper.hpp" -#include "ApplePS2ToHIDMap.h" +#include #include @@ -69,9 +68,9 @@ #define kPacketTimeOffset 8 #define kPacketKeyDataLength 2 -class EXPORT ApplePS2Keyboard : public IOService +class EXPORT ApplePS2Keyboard : public IOHIKeyboard { - typedef IOService super; + typedef IOHIKeyboard super; OSDeclareDefaultStructors(ApplePS2Keyboard); private: @@ -87,10 +86,16 @@ class EXPORT ApplePS2Keyboard : public IOService // for keyboard remapping UInt16 _PS2modifierState; - UInt16 _PS2ToPS2Map[KBV_NUM_SCANCODES]; - UInt16 _PS2flags[KBV_NUM_SCANCODES]; - VoodooPS2HidElement _PS2ToHIDMap[512]; + UInt16 _PS2ToPS2Map[KBV_NUM_SCANCODES*2]; + UInt16 _PS2flags[KBV_NUM_SCANCODES*2]; + UInt8 _PS2ToADBMap[ADB_CONVERTER_LEN]; + UInt8 _PS2ToADBMapMapped[ADB_CONVERTER_LEN]; + UInt32 _fkeymode; + bool _fkeymodesupported; + OSArray* _keysStandard; + OSArray* _keysSpecial; bool _swapcommandoption; + int _logscancodes; UInt32 _f12ejectdelay; enum { kTimerSleep, kTimerEject } _timerFunc; bool _remapPrntScr; @@ -100,21 +105,37 @@ class EXPORT ApplePS2Keyboard : public IOService // dealing with sleep key delay IOTimerEventSource* _sleepEjectTimer; UInt32 _maxsleeppresstime; + + // ACPI support for keyboard backlight + IOACPIPlatformDevice * _provider; + int * _backlightLevels; + int _backlightCount; + + // special hack for Envy brightness access, while retaining F2/F3 functionality + bool _brightnessHack; // Toggle keyboard input along with touchpad when Windows+printscreen is pressed bool _disableInput; + // macro processing + OSData** _macroTranslation; + OSData** _macroInversion; + UInt8* _macroBuffer; + int _macroMax; + int _macroCurrent; + uint64_t _macroMaxTime; + IOTimerEventSource* _macroTimer; + // fix caps lock led bool _ignoreCapsLedChange; - - VoodooPS2KeyboardHIDWrapper *_hidWrapper {nullptr}; virtual bool dispatchKeyboardEventWithPacket(const UInt8* packet); virtual void setLEDs(UInt8 ledState); virtual void setKeyboardEnable(bool enable); virtual void initKeyboard(); virtual void setDevicePowerState(UInt32 whatToDo); - + void modifyKeyboardBacklight(int adbKeyCode, bool goingDown); + void modifyScreenBrightness(int adbKeyCode, bool goingDown); inline bool checkModifierState(UInt16 mask) { return mask == (_PS2modifierState & mask); } inline bool checkModifierStateAny(UInt16 mask) @@ -122,18 +143,24 @@ class EXPORT ApplePS2Keyboard : public IOService void loadCustomPS2Map(OSArray* pArray); void loadBreaklessPS2(OSDictionary* dict, const char* name); - void loadCustomHIDMap(OSDictionary* dict, const char* name); + void loadCustomADBMap(OSDictionary* dict, const char* name); void setParamPropertiesGated(OSDictionary* dict); void onSleepEjectTimer(void); + + static OSData** loadMacroData(OSDictionary* dict, const char* name); + static void freeMacroData(OSData** data); + void onMacroTimer(void); + bool invertMacros(const UInt8* packet); + void dispatchInvertBuffer(); + static bool compareMacro(const UInt8* packet, const UInt8* data, int count); protected: - void setAlphaLockFeedback(bool locked); - void setNumLockFeedback(bool locked); - - inline void dispatchKeyboardEventX(const VoodooPS2HidElement &elem, bool goingDown, uint64_t time) - { dispatchKeyboardEventX(elem.usagePage, elem.usage, goingDown, time); } - inline void dispatchKeyboardEventX(uint16_t usagePage, uint32_t usage, bool goingDown, uint64_t time) - { if (_hidWrapper) _hidWrapper->dispatchKeyboardEvent(time, usagePage, usage, goingDown); } + const unsigned char * defaultKeymapOfLength(UInt32 * length) override; + void setAlphaLockFeedback(bool locked) override; + void setNumLockFeedback(bool locked) override; + UInt32 maxKeyCodes() override; + inline void dispatchKeyboardEventX(unsigned int keyCode, bool goingDown, uint64_t time) + { dispatchKeyboardEvent(keyCode, goingDown, *(AbsoluteTime*)&time); } inline void setTimerTimeout(IOTimerEventSource* timer, uint64_t time) { timer->setTimeout(*(AbsoluteTime*)&time); } inline void cancelTimer(IOTimerEventSource* timer) @@ -149,6 +176,10 @@ class EXPORT ApplePS2Keyboard : public IOService virtual PS2InterruptResult interruptOccurred(UInt8 scanCode); virtual void packetReady(); + UInt32 deviceType() override; + UInt32 interfaceID() override; + + IOReturn setParamProperties(OSDictionary* dict) override; IOReturn setProperties (OSObject *props) override; IOReturn message(UInt32 type, IOService* provider, void* argument) override; diff --git a/VoodooPS2Keyboard/VoodooPS2KeyboardHIDWrapper.cpp b/VoodooPS2Keyboard/VoodooPS2KeyboardHIDWrapper.cpp deleted file mode 100644 index e6b3c377..00000000 --- a/VoodooPS2Keyboard/VoodooPS2KeyboardHIDWrapper.cpp +++ /dev/null @@ -1,134 +0,0 @@ -// -// VoodooPS2KeyboardHIDWrapper.cpp -// VoodooPS2Keyboard -// -// Created by Gwydien on 8/28/23. -// Copyright © 2023 Acidanthera. All rights reserved. -// - -#include "VoodooPS2KeyboardHIDWrapper.hpp" -#include -#include - -OSDefineMetaClassAndStructors(VoodooPS2KeyboardHIDWrapper, IOHIDDevice); -OSDefineMetaClassAndStructors(VoodooPS2KeyboardHIDEventDriver, IOHIDEventService); - -static constexpr uint8_t ReportDescriptor[] = { - 0x05, 0x01, // Usage Page (Generic Desktop) - 0x09, 0x06, // USAGE (Keyboard) - 0xa1, 0x01, // COLLECTION (Application) - 0x85, 0x01, // REPORT_ID (Keyboard) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) - 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x01, // LOGICAL_MAXIMUM (1) - 0x75, 0x01, // REPORT_SIZE (1) - 0x95, 0x08, // REPORT_COUNT (8) - 0x81, 0x02, // INPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x08, // REPORT_SIZE (8) - 0x81, 0x03, // INPUT (Cnst,Var,Abs) - 0x95, 0x05, // REPORT_COUNT (5) - 0x75, 0x01, // REPORT_SIZE (1) - 0x05, 0x08, // USAGE_PAGE (LEDs) - 0x19, 0x01, // USAGE_MINIMUM (Num Lock) - 0x29, 0x05, // USAGE_MAXIMUM (Kana) - 0x91, 0x02, // OUTPUT (Data,Var,Abs) - 0x95, 0x01, // REPORT_COUNT (1) - 0x75, 0x03, // REPORT_SIZE (3) - 0x91, 0x03, // OUTPUT (Cnst,Var,Abs) - 0x95, 0x06, // REPORT_COUNT (6) - 0x75, 0x08, // REPORT_SIZE (8) - 0x15, 0x00, // LOGICAL_MINIMUM (0) - 0x25, 0x65, // LOGICAL_MAXIMUM (101) - 0x05, 0x07, // USAGE_PAGE (Keyboard) - 0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated)) - 0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application) - 0x81, 0x00, // INPUT (Data,Ary,Abs) - 0xc0, // END_COLLECTION -}; - -bool VoodooPS2KeyboardHIDWrapper::start(IOService *provider) { - setProperty(kIOHIDBuiltInKey, kOSBooleanTrue); - setProperty("HIDDefaultBehavior", kOSBooleanTrue); - setProperty("AppleVendorSupported", kOSBooleanTrue); - - registerService(); - if (!IOHIDDevice::start(provider)) return false; - - return true; -} - -void VoodooPS2KeyboardHIDWrapper::stop(IOService *provider) { - return IOHIDDevice::stop(provider); -} - -void VoodooPS2KeyboardHIDWrapper::dispatchKeyboardEvent(AbsoluteTime time, uint16_t usagePage, uint16_t usage, uint8_t value) { - if (eventDriver != nullptr) { - eventDriver->dispatchKeyboardEvent(time, usagePage, usage, value); - } -} - -bool VoodooPS2KeyboardHIDWrapper::handleOpen(IOService *forClient, IOOptionBits options, void *arg) { - VoodooPS2KeyboardHIDEventDriver *temp = OSDynamicCast(VoodooPS2KeyboardHIDEventDriver, forClient); - if (eventDriver == nullptr && temp != nullptr && IOHIDDevice::handleOpen(forClient, options, arg)) { - eventDriver = temp; - return true; - } - - return IOHIDDevice::handleOpen(forClient, options, arg); -} - -void VoodooPS2KeyboardHIDWrapper::handleClose(IOService *forClient, IOOptionBits options) { - if (forClient == eventDriver) { - eventDriver = nullptr; - } - - IOHIDDevice::handleClose(forClient, options); -} - -IOReturn VoodooPS2KeyboardHIDWrapper::newReportDescriptor(IOMemoryDescriptor **descriptor) const { - IOBufferMemoryDescriptor *buffer = IOBufferMemoryDescriptor::inTaskWithOptions(kernel_task, 0, sizeof(ReportDescriptor)); - - if (buffer == NULL) return kIOReturnNoResources; - buffer->writeBytes(0, ReportDescriptor, sizeof(ReportDescriptor)); - *descriptor = buffer; - - return kIOReturnSuccess; -} - -OSString* VoodooPS2KeyboardHIDWrapper::newManufacturerString() const { - return OSString::withCString("Acidanthera"); -} - -OSNumber* VoodooPS2KeyboardHIDWrapper::newPrimaryUsageNumber() const { - return OSNumber::withNumber(kHIDUsage_GD_Keyboard, 32); -} - -OSNumber* VoodooPS2KeyboardHIDWrapper::newPrimaryUsagePageNumber() const { - return OSNumber::withNumber(kHIDPage_GenericDesktop, 32); -} - -/* - * Apple vendor is needed for keyboard backlight filters to attach. - * To prevent Apple event drivers from attaching, use a bogus - * product ID. - */ - -OSNumber* VoodooPS2KeyboardHIDWrapper::newVendorIDNumber() const { - // Apple Vendor needed for - return OSNumber::withNumber(1452, 16); -} - -OSNumber* VoodooPS2KeyboardHIDWrapper::newProductIDNumber() const { - return OSNumber::withNumber(0x9999, 32); -} - -OSString* VoodooPS2KeyboardHIDWrapper::newProductString() const { - return OSString::withCString("PS2 Keyboard"); -} - -OSString* VoodooPS2KeyboardHIDWrapper::newTransportString() const { - return OSString::withCString("PS2"); -} diff --git a/VoodooPS2Keyboard/VoodooPS2KeyboardHIDWrapper.hpp b/VoodooPS2Keyboard/VoodooPS2KeyboardHIDWrapper.hpp deleted file mode 100644 index 9008013d..00000000 --- a/VoodooPS2Keyboard/VoodooPS2KeyboardHIDWrapper.hpp +++ /dev/null @@ -1,39 +0,0 @@ -// -// VoodooPS2KeyboardHIDWrapper.hpp -// VoodooPS2Keyboard -// -// Created by Gwydien on 8/28/23. -// Copyright © 2023 Acidanthera. All rights reserved. -// - -#ifndef VoodooPS2KeyboardHIDWrapper_hpp -#define VoodooPS2KeyboardHIDWrapper_hpp - -#include -#include "VoodooPS2EventDriver.hpp" - -class VoodooPS2KeyboardHIDWrapper : public IOHIDDevice { - OSDeclareDefaultStructors(VoodooPS2KeyboardHIDWrapper); -public: - bool start(IOService *start) override; - void stop(IOService *start) override; - bool handleOpen(IOService *forClient, IOOptionBits options, void *arg) override; - void handleClose(IOService *forClient, IOOptionBits options) override; - - IOReturn newReportDescriptor(IOMemoryDescriptor **descriptor) const override; - - virtual OSString* newManufacturerString() const override; - virtual OSNumber* newPrimaryUsageNumber() const override; - virtual OSNumber* newPrimaryUsagePageNumber() const override; - virtual OSString* newProductString() const override; - virtual OSString* newTransportString() const override; - virtual OSNumber* newVendorIDNumber() const override; - virtual OSNumber* newProductIDNumber() const override; - - void dispatchKeyboardEvent(AbsoluteTime time, uint16_t usagePage, uint16_t usage, uint8_t value); - -private: - VoodooPS2KeyboardHIDEventDriver *eventDriver {nullptr}; -}; - -#endif /* VoodooPS2KeyboardHIDWrapper_hpp */