Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiashangning committed Feb 9, 2023
1 parent 28b273d commit 66b5bc8
Show file tree
Hide file tree
Showing 24 changed files with 53 additions and 68 deletions.
10 changes: 8 additions & 2 deletions BigSurface/BigSurface.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
2518A2F82734F6AA00B0D631 /* APDS9960Constants.h in Headers */ = {isa = PBXBuildFile; fileRef = 2518A2F52734F6AA00B0D631 /* APDS9960Constants.h */; };
2524C0A626F3233A00CAAF12 /* SurfaceButtonDriver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2524C0A426F3233A00CAAF12 /* SurfaceButtonDriver.cpp */; };
2524C0A726F3233A00CAAF12 /* SurfaceButtonDriver.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 2524C0A526F3233A00CAAF12 /* SurfaceButtonDriver.hpp */; };
25506BAA29929D7A007F59BF /* helpers.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 25506BA929929D7A007F59BF /* helpers.hpp */; };
259040E926FC065400D605D0 /* SurfaceButtonDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 259040E726FC065400D605D0 /* SurfaceButtonDevice.cpp */; };
259040EA26FC065400D605D0 /* SurfaceButtonDevice.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 259040E826FC065400D605D0 /* SurfaceButtonDevice.hpp */; };
259040EC26FC0BB200D605D0 /* HIDReport.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 259040EB26FC0BB200D605D0 /* HIDReport.hpp */; };
Expand Down Expand Up @@ -117,6 +118,7 @@
2518A2F52734F6AA00B0D631 /* APDS9960Constants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APDS9960Constants.h; sourceTree = "<group>"; };
2524C0A426F3233A00CAAF12 /* SurfaceButtonDriver.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SurfaceButtonDriver.cpp; sourceTree = "<group>"; };
2524C0A526F3233A00CAAF12 /* SurfaceButtonDriver.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SurfaceButtonDriver.hpp; sourceTree = "<group>"; };
25506BA929929D7A007F59BF /* helpers.hpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; path = helpers.hpp; sourceTree = "<group>"; };
25813612272D6A2800EED5C9 /* VoodooSerial.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = VoodooSerial.xcodeproj; path = VoodooSerial/VoodooSerial.xcodeproj; sourceTree = "<group>"; };
259040E726FC065400D605D0 /* SurfaceButtonDevice.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SurfaceButtonDevice.cpp; sourceTree = "<group>"; };
259040E826FC065400D605D0 /* SurfaceButtonDevice.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SurfaceButtonDevice.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -267,6 +269,7 @@
25DBA9762836A78900459629 /* SurfaceSerialHubDevices */,
2597316F2738B01F00A7F7C1 /* SurfaceBattery */,
25E5B4C52991ACE7007F21D4 /* SurfaceManagementEngine */,
25506BA929929D7A007F59BF /* helpers.hpp */,
25B97E43260BA33B00657C76 /* Info.plist */,
);
path = BigSurface;
Expand Down Expand Up @@ -493,6 +496,7 @@
25D907292736E2B2006D799F /* AmbientLightValue.hpp in Headers */,
2597318C2738B2BA00A7F7C1 /* SurfaceSMBusController.hpp in Headers */,
2518A2F82734F6AA00B0D631 /* APDS9960Constants.h in Headers */,
25506BAA29929D7A007F59BF /* helpers.hpp in Headers */,
2524C0A726F3233A00CAAF12 /* SurfaceButtonDriver.hpp in Headers */,
259731862738B01F00A7F7C1 /* SurfaceACAdapter.hpp in Headers */,
2597317D2738B01F00A7F7C1 /* KeyImplementations.hpp in Headers */,
Expand Down Expand Up @@ -721,7 +725,7 @@
CURRENT_PROJECT_VERSION = 1.1.0;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = K8RXBXZGN4;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_OPTIMIZATION_LEVEL = 3;
HEADER_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/../Dependencies/VoodooInput/Debug/VoodooInput.kext/Contents/Resources",
Expand All @@ -743,6 +747,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
RUN_CLANG_STATIC_ANALYZER = YES;
WARNING_CFLAGS = "";
WRAPPER_EXTENSION = kext;
};
name = Debug;
Expand Down Expand Up @@ -784,6 +789,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.xavier.BigSurface;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
WARNING_CFLAGS = "";
WRAPPER_EXTENSION = kext;
};
name = Release;
Expand Down Expand Up @@ -827,7 +833,7 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_OPTIMIZATION_LEVEL = 3;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1420"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include <libkern/libkern.h>
#include <VirtualSMCSDK/kern_vsmcapi.hpp>
#include <IOKit/acpi/IOACPIPlatformDevice.h>

class ALSForceBits : public VirtualSMCValue {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
// Copyright © 2021 Xia Shangning. All rights reserved.
//

#include <Headers/kern_util.hpp>

#include "SurfaceAmbientLightSensorDriver.hpp"
#include <Headers/kern_version.hpp>

#define super IOService
OSDefineMetaClassAndStructors(SurfaceAmbientLightSensorDriver, IOService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@
#ifndef SurfaceAmbientLightSensorDriver_hpp
#define SurfaceAmbientLightSensorDriver_hpp

#include <IOKit/IOService.h>
#include <IOKit/IOLib.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/acpi/IOACPIPlatformDevice.h>

#include "../../../Dependencies/VoodooGPIO/VoodooGPIO/VoodooGPIO.hpp"
#include "../../../Dependencies/VoodooSerial/VoodooSerial/utils/helpers.hpp"
#include "../../../Dependencies/VoodooSerial/VoodooSerial/utils/VoodooACPIResourcesParser/VoodooACPIResourcesParser.hpp"
#include "../../../Dependencies/VoodooSerial/VoodooSerial/ACPIParser/VoodooACPIResourcesParser.hpp"
#include "./../../Dependencies/VoodooSerial/VoodooSerial/VoodooI2C/VoodooI2CDevice/VoodooI2CDeviceNub.hpp"
#include <VirtualSMCSDK/kern_vsmcapi.hpp>
#include <Headers/kern_util.hpp>

#include "AmbientLightValue.hpp"
#include "APDS9960Constants.h"
Expand Down
4 changes: 0 additions & 4 deletions BigSurface/BigSurface/SurfaceBattery/BatteryManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
#include "SurfaceBattery.hpp"
#include "SurfaceACAdapter.hpp"
#include "BatteryManagerState.hpp"
#include <IOKit/IOService.h>
#include <IOKit/IOReportTypes.h>
#include <IOKit/acpi/IOACPIPlatformDevice.h>
#include <IOKit/pwr_mgt/IOPMPowerSource.h>
#include <IOKit/pwr_mgt/RootDomain.h>
#include <Headers/kern_util.hpp>
#include <stdatomic.h>
Expand Down
2 changes: 0 additions & 2 deletions BigSurface/BigSurface/SurfaceBattery/SurfaceACAdapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#ifndef SurfaceACAdapter_hpp
#define SurfaceACAdapter_hpp

#include <IOKit/IOService.h>
#include <IOKit/acpi/IOACPIPlatformDevice.h>
#include <IOKit/IOReportTypes.h>
#include "BatteryManagerState.hpp"

class SurfaceACAdapter {
Expand Down
2 changes: 0 additions & 2 deletions BigSurface/BigSurface/SurfaceBattery/SurfaceBattery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#include "SurfaceBattery.hpp"
#include <IOKit/battery/AppleSmartBatteryCommands.h>
#include <Headers/kern_util.hpp>
#include <Headers/kern_compat.hpp>

UInt32 SurfaceBattery::getNumberFromArray(OSArray *array, UInt32 index) {
auto number = OSDynamicCast(OSNumber, array->getObject(index));
Expand Down
4 changes: 0 additions & 4 deletions BigSurface/BigSurface/SurfaceBattery/SurfaceBattery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
#ifndef SurfaceBattery_hpp
#define SurfaceBattery_hpp

#include <IOKit/IOService.h>
#include <IOKit/IOReportTypes.h>
#include <IOKit/acpi/IOACPIPlatformDevice.h>
#include <IOKit/pwr_mgt/IOPMPowerSource.h>
#include <IOKit/pwr_mgt/RootDomain.h>
#include "BatteryManagerState.hpp"

class SurfaceBattery {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

#include <VirtualSMCSDK/kern_vsmcapi.hpp>
#include <Headers/kern_util.hpp>

#include "SurfaceBatteryDriver.hpp"
#include "KeyImplementations.hpp"
Expand Down
8 changes: 0 additions & 8 deletions BigSurface/BigSurface/SurfaceBattery/SurfaceBatteryDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@
#ifndef SurfaceBatteryDriver_hpp
#define SurfaceBatteryDriver_hpp

#include <IOKit/IOService.h>
#include <IOKit/IOReportTypes.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOInterruptEventSource.h>
#include <IOKit/pwr_mgt/IOPMPowerSource.h>
#include <IOKit/pwr_mgt/RootDomain.h>
#include <IOKit/IOTimerEventSource.h>

#include "BatteryManager.hpp"
#include "../SurfaceSerialHubDevices/SurfaceBatteryNub.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
#ifndef SurfaceSMBusController_hpp
#define SurfaceSMBusController_hpp

#include <IOKit/IOService.h>
#include <IOKit/IOSMBusController.h>
#include <IOKit/IOInterruptEventSource.h>
#include <IOKit/battery/AppleSmartBatteryCommands.h>

#include "../../../Dependencies/VoodooSerial/VoodooSerial/utils/helpers.hpp"
#include "BatteryManager.hpp"

class EXPORT SurfaceSMBusController : public IOSMBusController {
Expand Down
6 changes: 2 additions & 4 deletions BigSurface/BigSurface/SurfaceButton/SurfaceButtonDriver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
#ifndef SurfaceButtonDriver_hpp
#define SurfaceButtonDriver_hpp

#include <IOKit/IOLib.h>
#include <IOKit/IOService.h>
#include <IOKit/acpi/IOACPIPlatformDevice.h>

#include "../../../Dependencies/VoodooGPIO/VoodooGPIO/VoodooGPIO.hpp"
#include "../../../Dependencies/VoodooSerial/VoodooSerial/utils/VoodooACPIResourcesParser/VoodooACPIResourcesParser.hpp"
#include "../../../Dependencies/VoodooSerial/VoodooSerial/utils/helpers.hpp"
#include "../../../Dependencies/VoodooSerial/VoodooSerial/ACPIParser/VoodooACPIResourcesParser.hpp"
#include "../helpers.hpp"
#include "SurfaceButtonDevice.hpp"

#define BTN_CNT 3
Expand Down
12 changes: 1 addition & 11 deletions BigSurface/BigSurface/SurfaceManagementEngine/MEIProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@
#ifndef MEIProtocol_h
#define MEIProtocol_h

#ifndef EXPORT
#define EXPORT __attribute__((visibility("default")))
#endif

#ifndef BIT
#define BIT(nr) (1UL << (nr))
#endif

#ifndef GENMASK
#define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (64 - 1 - (h))))
#endif
#include "../helpers.hpp"

/*
* IPTS MEI constants and communication protocol ported from linux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#ifndef SurfaceManagementEngineClient_hpp
#define SurfaceManagementEngineClient_hpp

#include <IOKit/IOLocks.h>

#include "SurfaceManagementEngineDriver.hpp"

struct MEIClientMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@
#ifndef SurfaceManagementEngineDriver_hpp
#define SurfaceManagementEngineDriver_hpp

#include <IOKit/IOLib.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOCommandGate.h>
#include <IOKit/IOTimerEventSource.h>
#include <IOKit/IOInterruptEventSource.h>
#include <IOKit/IOFilterInterruptEventSource.h>
#include <IOKit/pci/IOPCIDevice.h>

Expand Down
2 changes: 1 addition & 1 deletion BigSurface/BigSurface/SurfaceSerialHub/SerialProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifndef SerialProtocol_h
#define SerialProtocol_h

#include <IOKit/IOLib.h>
#include "../helpers.hpp"

/* SSH Protocol Config see https://github.com/linux-surface/surface-aggregator-module/blob/master/doc/requests.txt for reference*/
#define SSH_TC_SAM 0x01 /* Generic system functionality, real-time clock. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//

#include "SurfaceSerialHubDriver.hpp"
#include "../../../Dependencies/VoodooSerial/VoodooSerial/utils/VoodooACPIResourcesParser/VoodooACPIResourcesParser.hpp"
#include "../../../Dependencies/VoodooSerial/VoodooSerial/ACPIParser/VoodooACPIResourcesParser.hpp"
#include "../SurfaceSerialHubDevices/SurfaceBatteryNub.hpp"
#include "../SurfaceSerialHubDevices/SurfaceHIDNub.hpp"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
#ifndef SurfaceSerialHubDriver_hpp
#define SurfaceSerialHubDriver_hpp

#include <IOKit/IOLib.h>
#include <IOKit/IOLocks.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOCommandGate.h>
#include <IOKit/acpi/IOACPIPlatformDevice.h>

#include "../../../Dependencies/VoodooGPIO/VoodooGPIO/VoodooGPIO.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#ifndef SurfaceBatteryNub_hpp
#define SurfaceBatteryNub_hpp

#include <IOKit/IOLib.h>
#include <IOKit/IOService.h>

#include "../SurfaceSerialHub/SurfaceSerialHubDriver.hpp"

#define BIX_LENGTH 119
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
#ifndef SurfaceHIDNub_hpp
#define SurfaceHIDNub_hpp

#include <IOKit/IOService.h>
#include <IOKit/IOWorkLoop.h>
#include <IOKit/IOInterruptEventSource.h>

#include "../SurfaceSerialHub/SurfaceSerialHubDriver.hpp"

enum SurfaceHIDDescriptorEntryType : UInt8 {
Expand Down
33 changes: 33 additions & 0 deletions BigSurface/BigSurface/helpers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// helpers.hpp
// BigSurface
//
// Created by Xavier on 2023/2/7.
// Copyright © 2023 Xia Shangning. All rights reserved.
//

#ifndef helpers_hpp
#define helpers_hpp

#include <IOKit/IOService.h>
#include <IOKit/IOLib.h>

#ifndef EXPORT
#define EXPORT __attribute__((visibility("default")))
#endif

#define kIOPMPowerOff 0
#define kIOPMNumberPowerStates 2

#define BIT(nr) (1UL << (nr))

#ifndef GENMASK
#define GENMASK(h, l) (((~0UL) << (l)) & (~0UL >> (64 - 1 - (h))))
#endif

static IOPMPowerState myIOPMPowerStates[kIOPMNumberPowerStates] = {
{1, kIOPMPowerOff, kIOPMPowerOff, kIOPMPowerOff, 0, 0, 0, 0, 0, 0, 0, 0},
{1, kIOPMPowerOn, kIOPMPowerOn, kIOPMPowerOn, 0, 0, 0, 0, 0, 0, 0, 0}
};

#endif /* helpers_hpp */

0 comments on commit 66b5bc8

Please sign in to comment.