Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSI GC20 SUPPORT #299

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "source/libstratosphere"]
path = source/libstratosphere
[submodule "source/Atmosphere-libs"]
path = source/Atmosphere-libs
url = https://github.com/Atmosphere-NX/Atmosphere-libs.git
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ATMOSPHERE_OS_HORIZON"
],
"compilerPath": "${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-g++",
"cStandard": "gnu18",
"cStandard": "gnu17",
"cppStandard": "gnu++20",
"intelliSenseMode": "gcc-arm64"
}
Expand Down
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ OUT_DIR := out
COMMON_DIR := common

all: build
rm -rf $(OUT_DIR)
mkdir -p $(OUT_DIR)/atmosphere/contents/690000000000000D/flags
mkdir -p $(OUT_DIR)/config/sys-con
mkdir -p $(OUT_DIR)/switch/
touch $(OUT_DIR)/atmosphere/contents/690000000000000D/flags/boot2.flag
cp $(SOURCE_DIR)/Sysmodule/sys-con.nsp $(OUT_DIR)/atmosphere/contents/690000000000000D/exefs.nsp
cp $(SOURCE_DIR)/AppletCompanion/sys-con.nro $(OUT_DIR)/switch/sys-con.nro
cp -r $(COMMON_DIR)/. $(OUT_DIR)/
@rm -rf $(OUT_DIR)
@mkdir -p $(OUT_DIR)/atmosphere/contents/690000000000000D/flags
@mkdir -p $(OUT_DIR)/config/sys-con
@mkdir -p $(OUT_DIR)/switch/
@touch $(OUT_DIR)/atmosphere/contents/690000000000000D/flags/boot2.flag
@cp $(SOURCE_DIR)/Sysmodule/sys-con.nsp $(OUT_DIR)/atmosphere/contents/690000000000000D/exefs.nsp
@cp $(SOURCE_DIR)/AppletCompanion/sys-con.nro $(OUT_DIR)/switch/sys-con.nro
@cp -r $(COMMON_DIR)/. $(OUT_DIR)/
@echo [DONE] sys-con compiled successfully. All files have been placed in $(OUT_DIR)/

build:
$(MAKE) -C $(SOURCE_DIR)
@$(MAKE) --no-print-directory -C $(SOURCE_DIR)

clean:
$(MAKE) -C $(SOURCE_DIR) clean
rm -rf $(OUT_DIR)
@$(MAKE) --no-print-directory -C $(SOURCE_DIR) clean
@rm -rf $(OUT_DIR)

mrproper:
$(MAKE) -C $(SOURCE_DIR) mrproper
rm -rf $(OUT_DIR)
@$(MAKE) --no-print-directory -C $(SOURCE_DIR) mrproper
@rm -rf $(OUT_DIR)

17 changes: 3 additions & 14 deletions source/AppletCompanion/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -161,44 +161,33 @@ endif
all: $(BUILD)

$(BUILD):
@echo building applet companion ...
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory \
-C $@ -f $(CURDIR)/Makefile \
makeNRO
applet

clean:
@echo cleaning applet companion ...
@rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf

# Makefile commands
#---------------------------------------------------------------------------------
else
.PHONY: makeNRO makeNSP
.PHONY: applet

DEPENDS := $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
makeNRO: $(OUTPUT).nro

makeNSP: $(OUTPUT).nsp

#TODO: add an option to make exefs.nsp instead of $(OUTPUT).nsp
applet: $(OUTPUT).nro

ifeq ($(strip $(NO_NACP)),)
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
else
$(OUTPUT).nro : $(OUTPUT).elf
endif



$(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm

$(OUTPUT).nso : $(OUTPUT).elf

$(OUTPUT).elf : $(OFILES)

$(OFILES_SRC) : $(HFILES_BIN)
Expand Down
1 change: 1 addition & 0 deletions source/Atmosphere-libs
Submodule Atmosphere-libs added at 2c3cce
14 changes: 8 additions & 6 deletions source/ControllerSwitch/SwitchAbstractedPadHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ Result SwitchAbstractedPadHandler::InitAbstractedPadState()
m_state = {0};
m_abstractedPadID = getUniqueId();
m_state.type = BIT(0);
m_state.npadInterfaceType = NpadInterfaceType_USB;
m_state.npadInterfaceType = HidNpadInterfaceType_USB;
m_state.flags = 0xff;
m_state.state.batteryCharge = 4;
m_state.state.battery_level = 4;
ControllerConfig *config = GetController()->GetConfig();
m_state.singleColorBody = config->bodyColor.rgbaValue;
m_state.singleColorButtons = config->buttonsColor.rgbaValue;
Expand Down Expand Up @@ -129,7 +129,7 @@ void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData
daxis_y += data.buttons[14] ? -1.0f : 0.0f; //DDOWN
daxis_x += data.buttons[15] ? -1.0f : 0.0f; //DLEFT

ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_state.state.joysticks[JOYSTICK_LEFT].dx, &m_state.state.joysticks[JOYSTICK_LEFT].dy);
ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_state.state.analog_stick_l.x, &m_state.state.analog_stick_l.y);
}
else
{
Expand All @@ -138,10 +138,10 @@ void SwitchAbstractedPadHandler::FillAbstractedState(const NormalizedButtonData
m_state.state.buttons |= (data.buttons[14] ? KEY_DDOWN : 0);
m_state.state.buttons |= (data.buttons[15] ? KEY_DLEFT : 0);

ConvertAxisToSwitchAxis(data.sticks[0].axis_x, data.sticks[0].axis_y, 0, &m_state.state.joysticks[JOYSTICK_LEFT].dx, &m_state.state.joysticks[JOYSTICK_LEFT].dy);
ConvertAxisToSwitchAxis(data.sticks[0].axis_x, data.sticks[0].axis_y, 0, &m_state.state.analog_stick_l.x, &m_state.state.analog_stick_l.y);
}

ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_state.state.joysticks[JOYSTICK_RIGHT].dx, &m_state.state.joysticks[JOYSTICK_RIGHT].dy);
ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_state.state.analog_stick_r.x, &m_state.state.analog_stick_r.y);

m_state.state.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0);
m_state.state.buttons |= (data.buttons[17] ? KEY_HOME : 0);
Expand Down Expand Up @@ -170,14 +170,16 @@ void SwitchAbstractedPadHandler::UpdateOutput()
if (R_SUCCEEDED(m_controller->OutputBuffer()))
return;

/*
if (DoesControllerSupport(m_controller->GetType(), SUPPORTS_RUMBLE))
{
Result rc;
HidVibrationValue value;
rc = hidGetActualVibrationValue(&m_vibrationDeviceHandle, &value);
rc = hidGetActualVibrationValue(m_vibrationDeviceHandle, &value);
if (R_SUCCEEDED(rc))
GetController()->SetRumble(static_cast<uint8_t>(value.amp_high * 255.0f), static_cast<uint8_t>(value.amp_low * 255.0f));
}
*/

svcSleepThread(1e+7L);
}
24 changes: 13 additions & 11 deletions source/ControllerSwitch/SwitchHDLHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,25 @@ void SwitchHDLHandler::Exit()

Result SwitchHDLHandler::InitHdlState()
{
m_hdlHandle = 0;
m_hdlHandle = {0};
m_deviceInfo = {0};
m_hdlState = {0};

// Set the controller type to Pro-Controller, and set the npadInterfaceType.
m_deviceInfo.deviceType = HidDeviceType_FullKey15;
m_deviceInfo.npadInterfaceType = NpadInterfaceType_USB;
m_deviceInfo.npadInterfaceType = HidNpadInterfaceType_USB;
// Set the controller colors. The grip colors are for Pro-Controller on [9.0.0+].
ControllerConfig *config = m_controller->GetConfig();
m_deviceInfo.singleColorBody = config->bodyColor.rgbaValue;
m_deviceInfo.singleColorButtons = config->buttonsColor.rgbaValue;
m_deviceInfo.colorLeftGrip = config->leftGripColor.rgbaValue;
m_deviceInfo.colorRightGrip = config->rightGripColor.rgbaValue;

m_hdlState.batteryCharge = 4; // Set battery charge to full.
m_hdlState.joysticks[JOYSTICK_LEFT].dx = 0x1234;
m_hdlState.joysticks[JOYSTICK_LEFT].dy = -0x1234;
m_hdlState.joysticks[JOYSTICK_RIGHT].dx = 0x5678;
m_hdlState.joysticks[JOYSTICK_RIGHT].dy = -0x5678;
m_hdlState.battery_level = 4; // Set battery charge to full.
m_hdlState.analog_stick_l.x = 0x1234;
m_hdlState.analog_stick_l.y = -0x1234;
m_hdlState.analog_stick_r.x = 0x5678;
m_hdlState.analog_stick_r.y = -0x5678;

if (m_controller->IsControllerActive())
return hiddbgAttachHdlsVirtualDevice(&m_hdlHandle, &m_deviceInfo);
Expand Down Expand Up @@ -139,7 +139,7 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data)
daxis_x *= ratio;
daxis_y *= ratio;

ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_hdlState.joysticks[JOYSTICK_LEFT].dx, &m_hdlState.joysticks[JOYSTICK_LEFT].dy);
ConvertAxisToSwitchAxis(daxis_x, daxis_y, 0, &m_hdlState.analog_stick_l.x, &m_hdlState.analog_stick_l.y);
}
else
{
Expand All @@ -148,10 +148,10 @@ void SwitchHDLHandler::FillHdlState(const NormalizedButtonData &data)
m_hdlState.buttons |= (data.buttons[14] ? KEY_DDOWN : 0);
m_hdlState.buttons |= (data.buttons[15] ? KEY_DLEFT : 0);

ConvertAxisToSwitchAxis(data.sticks[0].axis_x, data.sticks[0].axis_y, 0, &m_hdlState.joysticks[JOYSTICK_LEFT].dx, &m_hdlState.joysticks[JOYSTICK_LEFT].dy);
ConvertAxisToSwitchAxis(data.sticks[0].axis_x, data.sticks[0].axis_y, 0, &m_hdlState.analog_stick_l.x, &m_hdlState.analog_stick_l.y);
}

ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_hdlState.joysticks[JOYSTICK_RIGHT].dx, &m_hdlState.joysticks[JOYSTICK_RIGHT].dy);
ConvertAxisToSwitchAxis(data.sticks[1].axis_x, data.sticks[1].axis_y, 0, &m_hdlState.analog_stick_r.x, &m_hdlState.analog_stick_r.y);

m_hdlState.buttons |= (data.buttons[16] ? KEY_CAPTURE : 0);
m_hdlState.buttons |= (data.buttons[17] ? KEY_HOME : 0);
Expand Down Expand Up @@ -185,15 +185,17 @@ void SwitchHDLHandler::UpdateOutput()
if (R_SUCCEEDED(m_controller->OutputBuffer()))
return;

/*
// Process rumble values if supported
if (DoesControllerSupport(m_controller->GetType(), SUPPORTS_RUMBLE))
{
Result rc;
HidVibrationValue value;
rc = hidGetActualVibrationValue(&m_vibrationDeviceHandle, &value);
rc = hidGetActualVibrationValue(m_vibrationDeviceHandle, &value);
if (R_SUCCEEDED(rc))
m_controller->SetRumble(static_cast<uint8_t>(value.amp_high * 255.0f), static_cast<uint8_t>(value.amp_low * 255.0f));
}
*/

svcSleepThread(1e+7L);
}
2 changes: 1 addition & 1 deletion source/ControllerSwitch/SwitchHDLHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class SwitchHDLHandler : public SwitchVirtualGamepadHandler
{
private:
u64 m_hdlHandle;
HiddbgHdlsHandle m_hdlHandle;
HiddbgHdlsDeviceInfo m_deviceInfo;
HiddbgHdlsState m_hdlState;

Expand Down
4 changes: 2 additions & 2 deletions source/ControllerSwitch/SwitchVirtualGamepadHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class SwitchVirtualGamepadHandler
{
protected:
u32 m_vibrationDeviceHandle;
//HidVibrationDeviceHandle m_vibrationDeviceHandle;
std::unique_ptr<IController> m_controller;

alignas(ams::os::ThreadStackAlignment) u8 input_thread_stack[0x1000];
Expand Down Expand Up @@ -52,5 +52,5 @@ class SwitchVirtualGamepadHandler

//Get the raw controller pointer
inline IController *GetController() { return m_controller.get(); }
inline u32 *GetVibrationHandle() { return &m_vibrationDeviceHandle; }
//inline HidVibrationDeviceHandle *GetVibrationHandle() { return &m_vibrationDeviceHandle; }
};
25 changes: 16 additions & 9 deletions source/Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
COMPONENTS := libstratosphere AppletCompanion Sysmodule
Libstrat := Atmosphere-libs/libstratosphere
COMPONENTS := $(Libstrat) AppletCompanion Sysmodule
TOPTARGETS := all clean mrproper

.PHONY: $(TOPTARGETS) $(COMPONENTS)

all: $(COMPONENTS)

libstratosphere:
$(MAKE) -C $@
$(Libstrat):
@echo Building libstratosphere...
@$(MAKE) --no-print-directory -C $@

AppletCompanion:
$(MAKE) -C $@
@echo Building applet companion...
@$(MAKE) --no-print-directory -C $@

Sysmodule: libstratosphere
$(MAKE) -C $@
Sysmodule: $(Libstrat)
@echo Building sysmodule...
@$(MAKE) --no-print-directory -C $@

clean:
$(MAKE) -C AppletCompanion clean
$(MAKE) -C Sysmodule clean
@echo Cleaning applet companion...
@$(MAKE) --no-print-directory -C AppletCompanion clean
@echo Cleaning sysmodule...
@$(MAKE) --no-print-directory -C Sysmodule clean

mrproper: clean
$(MAKE) -C libstratosphere clean
@echo Cleaning libstratosphere...
@$(MAKE) --no-print-directory -C $(Libstrat) clean
9 changes: 4 additions & 5 deletions source/Sysmodule/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#---------------------------------------------------------------------------------
# pull in common stratosphere sysmodule configuration
#---------------------------------------------------------------------------------
include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../libstratosphere/config/templates/stratosphere.mk
include $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/../Atmosphere-libs/config/templates/stratosphere.mk

TARGET := sys-con
SOURCES += ../ControllerSwitch ../ControllerLib ../ControllerLib/Controllers ../inih
Expand Down Expand Up @@ -88,24 +88,23 @@ all: $(BUILD)

$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile sysmodule

#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).nsp $(TARGET).npdm $(TARGET).nso $(TARGET).elf


#---------------------------------------------------------------------------------
else
.PHONY: all
.PHONY: sysmodule

DEPENDS := $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT).nsp
sysmodule : $(OUTPUT).nsp

ifeq ($(strip $(APP_JSON)),)
$(OUTPUT).nsp : $(OUTPUT).nso
Expand Down
16 changes: 8 additions & 8 deletions source/Sysmodule/source/config_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,14 @@ namespace syscon::config

void ConfigChangedCheckThreadFunc(void *arg)
{
WriteToLog("Starting config check thread!");
LOG("Starting config check thread!");
do
{
if (R_SUCCEEDED(waitSingle(filecheckTimerWaiter, UINT64_MAX)))
{
if (config::CheckForFileChanges())
{
WriteToLog("File check succeeded! Loading configs...");
LOG("File check succeeded! Loading configs...");
config::LoadAllConfigs();
}
}
Expand All @@ -203,37 +203,37 @@ namespace syscon::config
LoadGlobalConfig(tempGlobalConfig);
}
else
WriteToLog("Failed to read from global config!");
LOG("Failed to read from global config!");

if (R_SUCCEEDED(ReadFromConfig(XBOXCONFIG)))
{
XboxController::LoadConfig(&tempConfig);
}
else
WriteToLog("Failed to read from xbox orig config!");
LOG("Failed to read from xbox orig config!");

if (R_SUCCEEDED(ReadFromConfig(XBOXONECONFIG)))
XboxOneController::LoadConfig(&tempConfig);
else
WriteToLog("Failed to read from xbox one config!");
LOG("Failed to read from xbox one config!");

if (R_SUCCEEDED(ReadFromConfig(XBOX360CONFIG)))
{
Xbox360Controller::LoadConfig(&tempConfig);
Xbox360WirelessController::LoadConfig(&tempConfig);
}
else
WriteToLog("Failed to read from xbox 360 config!");
LOG("Failed to read from xbox 360 config!");

if (R_SUCCEEDED(ReadFromConfig(DUALSHOCK3CONFIG)))
Dualshock3Controller::LoadConfig(&tempConfig);
else
WriteToLog("Failed to read from dualshock 3 config!");
LOG("Failed to read from dualshock 3 config!");

if (R_SUCCEEDED(ReadFromConfig(DUALSHOCK4CONFIG)))
Dualshock4Controller::LoadConfig(&tempConfig, tempColor);
else
WriteToLog("Failed to read from dualshock 4 config!");
LOG("Failed to read from dualshock 4 config!");
}

bool CheckForFileChanges()
Expand Down
Loading