Recover changes
This commit is contained in:
165
Source/rewrite-hoc-clk/common/src/battery.cpp
Normal file
165
Source/rewrite-hoc-clk/common/src/battery.cpp
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* Copyright (c) Souldbminer, Lightos_ and Horizon OC Contributors
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <switch.h>
|
||||
#include <cstring>
|
||||
#include "battery.h"
|
||||
|
||||
// Internal PSM service handle
|
||||
static Service g_psmService = {0};
|
||||
static bool g_batteryInfoInitialized = false;
|
||||
|
||||
static const char* s_chargerTypeStrings[] = {
|
||||
"None",
|
||||
"Power Delivery",
|
||||
"USB-C @ 1.5A",
|
||||
"USB-C @ 3.0A",
|
||||
"USB-DCP",
|
||||
"USB-CDP",
|
||||
"USB-SDP",
|
||||
"Apple @ 0.5A",
|
||||
"Apple @ 1.0A",
|
||||
"Apple @ 2.0A",
|
||||
};
|
||||
|
||||
static const char* s_powerRoleStrings[] = {
|
||||
"Unknown",
|
||||
"Sink",
|
||||
"Source",
|
||||
};
|
||||
|
||||
static const char* s_pdStateStrings[] = {
|
||||
"Unknown",
|
||||
"New PDO Received",
|
||||
"No PD Source",
|
||||
"RDO Accepted"
|
||||
};
|
||||
|
||||
// Internal PSM command implementations
|
||||
static Result psmGetBatteryChargeInfoFields(BatteryChargeInfo *out) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatchOut(&g_psmService, 17, *out);
|
||||
}
|
||||
|
||||
static Result psmEnableBatteryCharging_internal(void) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatch(&g_psmService, 2);
|
||||
}
|
||||
|
||||
static Result psmDisableBatteryCharging_internal(void) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatch(&g_psmService, 3);
|
||||
}
|
||||
|
||||
static Result psmEnableFastBatteryCharging_internal(void) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatch(&g_psmService, 10);
|
||||
}
|
||||
|
||||
static Result psmDisableFastBatteryCharging_internal(void) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return serviceDispatch(&g_psmService, 11);
|
||||
}
|
||||
|
||||
Result batteryInfoInitialize(void) {
|
||||
if (g_batteryInfoInitialized)
|
||||
return 0;
|
||||
|
||||
Result rc = psmInitialize();
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
memcpy(&g_psmService, psmGetServiceSession(), sizeof(Service));
|
||||
g_batteryInfoInitialized = true;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void batteryInfoExit(void) {
|
||||
if (g_batteryInfoInitialized) {
|
||||
psmExit();
|
||||
memset(&g_psmService, 0, sizeof(Service));
|
||||
g_batteryInfoInitialized = false;
|
||||
}
|
||||
}
|
||||
|
||||
Result batteryInfoGetChargeInfo(BatteryChargeInfo *out) {
|
||||
if (!out)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_BadInput);
|
||||
|
||||
return psmGetBatteryChargeInfoFields(out);
|
||||
}
|
||||
|
||||
Result batteryInfoGetChargePercentage(u32 *out) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return psmGetBatteryChargePercentage(out);
|
||||
}
|
||||
|
||||
Result batteryInfoIsEnoughPowerSupplied(bool *out) {
|
||||
if (!g_batteryInfoInitialized)
|
||||
return MAKERESULT(Module_Libnx, LibnxError_NotInitialized);
|
||||
|
||||
return psmIsEnoughPowerSupplied(out);
|
||||
}
|
||||
|
||||
Result batteryInfoEnableCharging(void) {
|
||||
return psmEnableBatteryCharging_internal();
|
||||
}
|
||||
|
||||
Result batteryInfoDisableCharging(void) {
|
||||
return psmDisableBatteryCharging_internal();
|
||||
}
|
||||
|
||||
Result batteryInfoEnableFastCharging(void) {
|
||||
return psmEnableFastBatteryCharging_internal();
|
||||
}
|
||||
|
||||
Result batteryInfoDisableFastCharging(void) {
|
||||
return psmDisableFastBatteryCharging_internal();
|
||||
}
|
||||
|
||||
const char* batteryInfoGetChargerTypeString(BatteryChargerType type) {
|
||||
if (type < 0 || type > ChargerType_Apple_2000mA)
|
||||
return "Unknown";
|
||||
|
||||
return s_chargerTypeStrings[type];
|
||||
}
|
||||
|
||||
const char* batteryInfoGetPowerRoleString(BatteryPowerRole role) {
|
||||
if (role < PowerRole_Sink || role > PowerRole_Source)
|
||||
return s_powerRoleStrings[0];
|
||||
|
||||
return s_powerRoleStrings[role];
|
||||
}
|
||||
|
||||
const char* batteryInfoGetPDStateString(BatteryPDControllerState state) {
|
||||
if (state < PDState_NewPDO || state > PDState_AcceptedRDO)
|
||||
return s_pdStateStrings[0];
|
||||
|
||||
return s_pdStateStrings[state];
|
||||
}
|
||||
@@ -88,12 +88,29 @@ static const DockedTimings g_dockedTimings1080p[] = {
|
||||
// technically you can go to 476hz, but in practice, why would you?
|
||||
};
|
||||
|
||||
// These timings *should* work but are untested
|
||||
static const HandheldTimings g_handheldTimingsRETRO[] = {
|
||||
{72, 136, 72, 1, 660, 9, 78000},
|
||||
{72, 136, 72, 1, 443, 9, 77985},
|
||||
{72, 136, 72, 1, 270, 9, 78000},
|
||||
{72, 136, 72, 1, 128, 9, 77990},
|
||||
{72, 136, 72, 1, 10, 9, 78000}
|
||||
{72, 136, 72, 1, 660, 9, 78000}, // 40Hz
|
||||
{72, 136, 72, 1, 612, 9, 77982}, // 41Hz
|
||||
{72, 136, 72, 1, 567, 9, 77994}, // 42Hz
|
||||
{72, 136, 72, 1, 524, 9, 78002}, // 43Hz
|
||||
{72, 136, 72, 1, 483, 9, 78012}, // 44Hz
|
||||
{72, 136, 72, 1, 443, 9, 77985}, // 45Hz
|
||||
{72, 136, 72, 1, 406, 9, 78016}, // 46Hz
|
||||
{72, 136, 72, 1, 370, 9, 78020}, // 47Hz
|
||||
{72, 136, 72, 1, 335, 9, 78000}, // 48Hz
|
||||
{72, 136, 72, 1, 302, 9, 78008}, // 49Hz
|
||||
{72, 136, 72, 1, 270, 9, 78000}, // 50Hz
|
||||
{72, 136, 72, 1, 239, 9, 77979}, // 51Hz
|
||||
{72, 136, 72, 1, 210, 9, 78000}, // 52Hz
|
||||
{72, 136, 72, 1, 182, 9, 78016}, // 53Hz
|
||||
{72, 136, 72, 1, 154, 9, 77976}, // 54Hz
|
||||
{72, 136, 72, 1, 128, 9, 77990}, // 55Hz
|
||||
{72, 136, 72, 1, 103, 9, 78008}, // 56Hz
|
||||
{72, 136, 72, 1, 78, 9, 77976}, // 57Hz
|
||||
{72, 136, 72, 1, 55, 9, 78010}, // 58Hz
|
||||
{72, 136, 72, 1, 32, 9, 77998}, // 59Hz
|
||||
{72, 136, 72, 1, 10, 9, 78000}, // 60Hz
|
||||
};
|
||||
|
||||
static const MinMaxRefreshRate g_handheldModeRefreshRate = {40, 80};
|
||||
@@ -543,10 +560,6 @@ bool DisplayRefresh_SetRate(uint32_t new_refreshRate) {
|
||||
|
||||
uint32_t fd = 0;
|
||||
|
||||
if (g_config.isLite && g_config.isPossiblySpoofedRetro) {
|
||||
g_config.isRetroSUPER = false; // Would check flag file here in original, but i dont care lol
|
||||
}
|
||||
|
||||
if (g_config.isRetroSUPER && !g_config.isDocked) {
|
||||
return _setNvDispHandheldRefreshRate(new_refreshRate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user