hocclk: format code

use clang format file provided for optimal formatting
This commit is contained in:
souldbminersmwc committed 2026-06-04 19:52:11 -04:00
1 parent c6a8884c14
commit 88bfa9a4ec
118 files changed
+7111 -9615

No files matched your search

+12 -22
View File
@@ -12,9 +12,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
/* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
@@ -24,60 +24,50 @@
* --------------------------------------------------------------------------
*/
#include <stdatomic.h>
#include "apm_ext.h"
#include <stdatomic.h>
static Service g_apmSrv;
static Service g_apmSysSrv;
static atomic_size_t g_refCnt;
Result apmExtInitialize(void)
{
Result apmExtInitialize(void) {
g_refCnt++;
if (serviceIsActive(&g_apmSrv))
{
if (serviceIsActive(&g_apmSrv)) {
return 0;
}
Result rc = 0;
rc = smGetService(&g_apmSrv, "apm");
if(R_SUCCEEDED(rc))
{
if (R_SUCCEEDED(rc)) {
rc = smGetService(&g_apmSysSrv, "apm:sys");
}
if (R_FAILED(rc))
{
if (R_FAILED(rc)) {
apmExtExit();
}
return rc;
}
void apmExtExit(void)
{
if (--g_refCnt == 0)
{
void apmExtExit(void) {
if (--g_refCnt == 0) {
serviceClose(&g_apmSrv);
serviceClose(&g_apmSysSrv);
}
}
Result apmExtGetPerformanceMode(u32* out_mode)
{
Result apmExtGetPerformanceMode(u32 *out_mode) {
return serviceDispatchOut(&g_apmSrv, 1, *out_mode);
}
Result apmExtSysRequestPerformanceMode(u32 mode)
{
Result apmExtSysRequestPerformanceMode(u32 mode) {
return serviceDispatchIn(&g_apmSysSrv, 0, mode);
}
Result apmExtGetCurrentPerformanceConfiguration(u32* out_conf)
{
Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf) {
return serviceDispatchOut(&g_apmSysSrv, 7, *out_conf);
}
+7 -9
View File
@@ -12,9 +12,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
/* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
@@ -24,12 +24,10 @@
* --------------------------------------------------------------------------
*/
#pragma once
#ifdef __cplusplus
extern "C"
{
extern "C" {
#endif
#include <switch.h>
@@ -37,19 +35,19 @@ extern "C"
Result apmExtInitialize(void);
void apmExtExit(void);
Result apmExtGetPerformanceMode(u32* out_mode);
Result apmExtGetPerformanceMode(u32 *out_mode);
Result apmExtSysRequestPerformanceMode(u32 mode);
Result apmExtGetCurrentPerformanceConfiguration(u32* out_conf);
Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf);
Result apmExtSysRequestPerformanceMode(u32 mode);
Result apmExtSysSetCpuBoostMode(u32 mode);
Result apmExtGetPerformanceMode(u32 *out_mode);
Result apmExtGetCurrentPerformanceConfiguration(u32 *out_conf);
inline bool apmExtIsCPUBoosted(u32 conf_id) { // CPU boosted to 1785 MHz
inline bool apmExtIsCPUBoosted(u32 conf_id) { // CPU boosted to 1785 MHz
return (conf_id == 0x92220009 || conf_id == 0x9222000A);
};
inline bool apmExtIsBoostMode(u32 conf_id) { // GPU throttled to 76.8 MHz
inline bool apmExtIsBoostMode(u32 conf_id) { // GPU throttled to 76.8 MHz
return (conf_id >= 0x92220009 && conf_id <= 0x9222000C);
};
@@ -12,9 +12,9 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
/* --------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <p-sam@d3vs.net>, <natinusala@gmail.com>, <m4x@m4xw.net>
@@ -24,26 +24,24 @@
* --------------------------------------------------------------------------
*/
#include <hocclk/apm.h>
HocClkApmConfiguration hocclk_g_apm_configurations[] = {
{0x00010000, 1020000000, 384000000, 1600000000},
{0x00010001, 1020000000, 768000000, 1600000000},
{0x00010002, 1224000000, 691200000, 1600000000},
{0x00020000, 1020000000, 230400000, 1600000000},
{0x00020001, 1020000000, 307200000, 1600000000},
{0x00020002, 1224000000, 230400000, 1600000000},
{0x00020003, 1020000000, 307200000, 1331200000},
{0x00020004, 1020000000, 384000000, 1331200000},
{0x00020005, 1020000000, 307200000, 1065600000},
{0x00020006, 1020000000, 384000000, 1065600000},
{0x92220007, 1020000000, 460800000, 1600000000},
{0x92220008, 1020000000, 460800000, 1331200000},
{0x92220009, 1785000000, 76800000, 1600000000},
{0x9222000A, 1785000000, 76800000, 1331200000},
{0x9222000B, 1020000000, 76800000, 1600000000},
{0x9222000C, 1020000000, 76800000, 1331200000},
{0, 0, 0, 0},
{ 0x00010000, 1020000000, 384000000, 1600000000 },
{ 0x00010001, 1020000000, 768000000, 1600000000 },
{ 0x00010002, 1224000000, 691200000, 1600000000 },
{ 0x00020000, 1020000000, 230400000, 1600000000 },
{ 0x00020001, 1020000000, 307200000, 1600000000 },
{ 0x00020002, 1224000000, 230400000, 1600000000 },
{ 0x00020003, 1020000000, 307200000, 1331200000 },
{ 0x00020004, 1020000000, 384000000, 1331200000 },
{ 0x00020005, 1020000000, 307200000, 1065600000 },
{ 0x00020006, 1020000000, 384000000, 1065600000 },
{ 0x92220007, 1020000000, 460800000, 1600000000 },
{ 0x92220008, 1020000000, 460800000, 1331200000 },
{ 0x92220009, 1785000000, 76800000, 1600000000 },
{ 0x9222000A, 1785000000, 76800000, 1331200000 },
{ 0x9222000B, 1020000000, 76800000, 1600000000 },
{ 0x9222000C, 1020000000, 76800000, 1331200000 },
{ 0, 0, 0, 0 },
};
@@ -15,16 +15,17 @@
*
*/
#include "integrations.hpp"
#include <sys/stat.h>
#include <SaltyNX.h>
#include "integrations.hpp"
#include "process_management.hpp"
#include <sys/stat.h>
namespace integrations {
namespace {
NxFpsSharedBlock* gNxFps = nullptr;
NxFpsSharedBlock *gNxFps = nullptr;
SharedMemory gSharedMemory = {};
bool gSharedMemoryUsed = false;
Handle gRemoteSharedMemory = 1;
@@ -38,7 +39,8 @@ namespace integrations {
svcCloseHandle(saltysd);
break;
}
if (i == 66) return false;
if (i == 66)
return false;
svcSleepThread(1'000'000);
}
@@ -56,7 +58,7 @@ namespace integrations {
void SearchSharedMemoryBlock(uintptr_t base) {
ptrdiff_t search_offset = 0;
while (search_offset < 0x1000) {
gNxFps = (NxFpsSharedBlock*)(base + search_offset);
gNxFps = (NxFpsSharedBlock *)(base + search_offset);
if (gNxFps->MAGIC == 0x465053)
return;
search_offset += 4;
@@ -74,21 +76,21 @@ namespace integrations {
gSharedMemoryUsed = true;
}
}
} // namespace
bool GetSysDockState() {
struct stat st = {0};
struct stat st = { 0 };
return stat("sdmc:/atmosphere/contents/42000000000000A0/flags/boot2.flag", &st) == 0;
}
bool GetSaltyNXState() {
struct stat st = {0};
struct stat st = { 0 };
return stat("sdmc:/atmosphere/contents/0000000000534C56/flags/boot2.flag", &st) == 0;
}
bool GetRETROSuperStatus() {
struct stat st = {0};
return stat("sdmc:/config/horizon-oc/retro.flag", &st) == 0; // TODO: unhardcode this
struct stat st = { 0 };
return stat("sdmc:/config/horizon-oc/retro.flag", &st) == 0; // TODO: unhardcode this
}
void LoadSaltyNX() {
@@ -143,13 +145,15 @@ namespace integrations {
resolutionLookup = 1;
return 0;
} else if (resolutionLookup == 1) {
if (gNxFps->renderCalls[0].calls != 0xFFFF) resolutionLookup = 2;
else return 0;
if (gNxFps->renderCalls[0].calls != 0xFFFF)
resolutionLookup = 2;
else
return 0;
}
return gNxFps->renderCalls[0].height == 0 ? gNxFps->viewportCalls[0].height : gNxFps->renderCalls[0].height;
}
return 0;
}
}
} // namespace integrations
@@ -17,8 +17,8 @@
#pragma once
#include <switch.h>
#include <hocclk.h>
#include <switch.h>
namespace integrations {
@@ -39,9 +39,9 @@ namespace integrations {
uint8_t SetActiveBuffers;
union {
struct {
bool handheld: 1;
bool docked: 1;
unsigned int reserved: 6;
bool handheld : 1;
bool docked : 1;
unsigned int reserved : 6;
} NX_PACKED ds;
uint8_t general;
} displaySync;
@@ -66,4 +66,4 @@ namespace integrations {
u8 GetSaltyNXFPS();
u16 GetSaltyNXResolutionHeight();
}
} // namespace integrations
@@ -15,14 +15,13 @@
*
*/
#include "notification.h"
namespace notification {
void writeNotification(const std::string& message) {
static const char* flagPath = "sdmc:/config/ultrahand/flags/NOTIFICATIONS.flag";
void writeNotification(const std::string &message) {
static const char *flagPath = "sdmc:/config/ultrahand/flags/NOTIFICATIONS.flag";
FILE* flagFile = fopen(flagPath, "r");
FILE *flagFile = fopen(flagPath, "r");
if (!flagFile) {
return;
}
@@ -31,7 +30,7 @@ namespace notification {
std::string filename = "hoc-" + std::to_string(std::time(nullptr)) + ".notify";
std::string fullPath = "sdmc:/config/ultrahand/notifications/" + filename;
FILE* file = fopen(fullPath.c_str(), "w");
FILE *file = fopen(fullPath.c_str(), "w");
if (file) {
fprintf(file, "{\n");
fprintf(file, " \"text\": \"%s\",\n", message.c_str());
@@ -40,4 +39,4 @@ namespace notification {
fclose(file);
}
}
}
} // namespace notification
@@ -12,14 +12,14 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#pragma once
#include <string>
#include <ctime>
#include <cstdio>
#include <ctime>
#include <string>
namespace notification {
void writeNotification(const std::string& message);
void writeNotification(const std::string &message);
}
+38 -39
View File
@@ -12,7 +12,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#pragma once
@@ -26,24 +26,23 @@
*/
/*
* Switch Power domains (max77620):
* Name | Usage | uV step | uV min | uV default | uV max | Init
*-------+---------------+---------+--------+------------+---------+------------------
* sd0 | SoC | 12500 | 600000 | 625000 | 1400000 | 1.125V (pkg1.1)
* sd1 | SDRAM | 12500 | 600000 | 1125000 | 1125000 | 1.1V (pkg1.1)
* sd2 | ldo{0-1, 7-8} | 12500 | 600000 | 1325000 | 1350000 | 1.325V (pcv)
* sd3 | 1.8V general | 12500 | 600000 | 1800000 | 1800000 |
* ldo0 | Display Panel | 25000 | 800000 | 1200000 | 1200000 | 1.2V (pkg1.1)
* ldo1 | XUSB, PCIE | 25000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
* ldo2 | SDMMC1 | 50000 | 800000 | 1800000 | 3300000 |
* ldo3 | GC ASIC | 50000 | 800000 | 3100000 | 3100000 | 3.1V (pcv)
* ldo4 | RTC | 12500 | 800000 | 850000 | 850000 | 0.85V (AO, pcv)
* ldo5 | GC Card | 50000 | 800000 | 1800000 | 1800000 | 1.8V (pcv)
* ldo6 | Touch, ALS | 50000 | 800000 | 2900000 | 2900000 | 2.9V (pcv)
* ldo7 | XUSB | 50000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
* ldo8 | XUSB, DP, MCU | 50000 | 800000 | 1050000 | 2800000 | 1.05V/2.8V (pcv)
*/
* Switch Power domains (max77620):
* Name | Usage | uV step | uV min | uV default | uV max | Init
*-------+---------------+---------+--------+------------+---------+------------------
* sd0 | SoC | 12500 | 600000 | 625000 | 1400000 | 1.125V (pkg1.1)
* sd1 | SDRAM | 12500 | 600000 | 1125000 | 1125000 | 1.1V (pkg1.1)
* sd2 | ldo{0-1, 7-8} | 12500 | 600000 | 1325000 | 1350000 | 1.325V (pcv)
* sd3 | 1.8V general | 12500 | 600000 | 1800000 | 1800000 |
* ldo0 | Display Panel | 25000 | 800000 | 1200000 | 1200000 | 1.2V (pkg1.1)
* ldo1 | XUSB, PCIE | 25000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
* ldo2 | SDMMC1 | 50000 | 800000 | 1800000 | 3300000 |
* ldo3 | GC ASIC | 50000 | 800000 | 3100000 | 3100000 | 3.1V (pcv)
* ldo4 | RTC | 12500 | 800000 | 850000 | 850000 | 0.85V (AO, pcv)
* ldo5 | GC Card | 50000 | 800000 | 1800000 | 1800000 | 1.8V (pcv)
* ldo6 | Touch, ALS | 50000 | 800000 | 2900000 | 2900000 | 2.9V (pcv)
* ldo7 | XUSB | 50000 | 800000 | 1050000 | 1050000 | 1.05V (pcv)
* ldo8 | XUSB, DP, MCU | 50000 | 800000 | 1050000 | 2800000 | 1.05V/2.8V (pcv)
*/
// GPIOs T210: 3: 3.3V, 5: CPU PMIC, 6: GPU PMIC, 7: DSI/VI 1.2V powered by ldo0.
@@ -66,15 +65,15 @@
*/
/*
* MAX77620_AME_GPIO: control GPIO modes (bits 0 - 7 correspond to GPIO0 - GPIO7); 0 -> GPIO, 1 -> alt-mode
* MAX77620_REG_GPIOx: 0x9 sets output and enable
*/
* MAX77620_AME_GPIO: control GPIO modes (bits 0 - 7 correspond to GPIO0 - GPIO7); 0 -> GPIO, 1 -> alt-mode
* MAX77620_REG_GPIOx: 0x9 sets output and enable
*/
typedef enum {
PcvPowerDomain_Max77620_Sd0 = 0,
PcvPowerDomain_Max77620_Sd1 = 1,
PcvPowerDomain_Max77620_Sd2 = 2,
PcvPowerDomain_Max77620_Sd3 = 3,
PcvPowerDomain_Max77620_Sd0 = 0,
PcvPowerDomain_Max77620_Sd1 = 1,
PcvPowerDomain_Max77620_Sd2 = 2,
PcvPowerDomain_Max77620_Sd3 = 3,
PcvPowerDomain_Max77620_Ldo0 = 4,
PcvPowerDomain_Max77620_Ldo1 = 5,
PcvPowerDomain_Max77620_Ldo2 = 6,
@@ -84,18 +83,18 @@ typedef enum {
PcvPowerDomain_Max77620_Ldo6 = 10,
PcvPowerDomain_Max77620_Ldo7 = 11,
PcvPowerDomain_Max77620_Ldo8 = 12,
PcvPowerDomain_Max77621_Cpu = 13,
PcvPowerDomain_Max77621_Gpu = 14,
PcvPowerDomain_Max77812_Cpu = 15,
PcvPowerDomain_Max77812_Gpu = 16,
PcvPowerDomain_Max77621_Cpu = 13,
PcvPowerDomain_Max77621_Gpu = 14,
PcvPowerDomain_Max77812_Cpu = 15,
PcvPowerDomain_Max77812_Gpu = 16,
PcvPowerDomain_Max77812_Dram = 17,
} PowerDomain;
typedef enum {
PcvPowerDomainId_Max77620_Sd0 = 0x3A000080,
PcvPowerDomainId_Max77620_Sd1 = 0x3A000081, // vdd2
PcvPowerDomainId_Max77620_Sd2 = 0x3A000082,
PcvPowerDomainId_Max77620_Sd3 = 0x3A000083,
PcvPowerDomainId_Max77620_Sd0 = 0x3A000080,
PcvPowerDomainId_Max77620_Sd1 = 0x3A000081, // vdd2
PcvPowerDomainId_Max77620_Sd2 = 0x3A000082,
PcvPowerDomainId_Max77620_Sd3 = 0x3A000083,
PcvPowerDomainId_Max77620_Ldo0 = 0x3A0000A0,
PcvPowerDomainId_Max77620_Ldo1 = 0x3A0000A1,
PcvPowerDomainId_Max77620_Ldo2 = 0x3A0000A2,
@@ -105,9 +104,9 @@ typedef enum {
PcvPowerDomainId_Max77620_Ldo6 = 0x3A0000A6,
PcvPowerDomainId_Max77620_Ldo7 = 0x3A0000A7,
PcvPowerDomainId_Max77620_Ldo8 = 0x3A0000A8,
PcvPowerDomainId_Max77621_Cpu = 0x3A000003,
PcvPowerDomainId_Max77621_Gpu = 0x3A000004,
PcvPowerDomainId_Max77812_Cpu = 0x3A000003,
PcvPowerDomainId_Max77812_Gpu = 0x3A000004,
PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq
PcvPowerDomainId_Max77621_Cpu = 0x3A000003,
PcvPowerDomainId_Max77621_Gpu = 0x3A000004,
PcvPowerDomainId_Max77812_Cpu = 0x3A000003,
PcvPowerDomainId_Max77812_Gpu = 0x3A000004,
PcvPowerDomainId_Max77812_Dram = 0x3A000005, // vddq
} PowerDomainId;
@@ -24,19 +24,20 @@
* --------------------------------------------------------------------------
*/
#include "process_management.hpp"
#include "../file/file_utils.hpp"
#include "../file/errors.hpp"
#include <cstring>
#include "../file/errors.hpp"
#include "../file/file_utils.hpp"
#include "process_management.hpp"
namespace processManagement {
namespace {
constexpr u64 Qlaunch = 0x0100000000001000ULL;
constexpr u64 Qlaunch = 0x0100000000001000ULL;
constexpr u32 IsQlaunch = 0x20f;
Service pdmqryClone;
}
} // namespace
void Initialize() {
Result rc = 0;
@@ -50,11 +51,10 @@ namespace processManagement {
rc = pdmqryInitialize();
ASSERT_RESULT_OK(rc, "pdmqryInitialize");
Service* pdmqrySrv = pdmqryGetServiceSession();
Service *pdmqrySrv = pdmqryGetServiceSession();
serviceClone(pdmqrySrv, &pdmqryClone);
serviceClose(pdmqrySrv);
memcpy(pdmqrySrv, &pdmqryClone, sizeof(Service));
}
void WaitForQLaunch() {
@@ -62,12 +62,12 @@ namespace processManagement {
u64 pid = 0;
do {
rc = pmdmntGetProcessId(&pid, Qlaunch);
svcSleepThread(50 * 1000000ULL); // 50ms
svcSleepThread(50 * 1000000ULL); // 50ms
} while (R_FAILED(rc));
}
// Ty to Masa for this function!
Result isApplicationOutOfFocus(bool* outOfFocus) {
Result isApplicationOutOfFocus(bool *outOfFocus) {
static s32 last_total_entries = 0;
static bool isOutOfFocus = false;
s32 total_entries = 0;
@@ -77,12 +77,15 @@ namespace processManagement {
u64 PIDnow;
Result rc = pmdmntGetApplicationProcessId(&PIDnow);
if(R_FAILED(rc)) return rc;
if (R_FAILED(rc))
return rc;
rc = pmdmntGetProgramId(&TIDnow, PIDnow);
if(R_FAILED(rc)) return rc;
if (R_FAILED(rc))
return rc;
rc = pdmqryGetAvailablePlayEventRange(&total_entries, &start_entry_index, &end_entry_index);
if (R_FAILED(rc)) return rc;
if (R_FAILED(rc))
return rc;
if (total_entries == last_total_entries) {
*outOfFocus = isOutOfFocus;
return 0;
@@ -92,13 +95,16 @@ namespace processManagement {
PdmPlayEvent events[16];
s32 out = 0;
s32 start_entry = end_entry_index - 15;
if (start_entry < 0) start_entry = 0;
if (start_entry < 0)
start_entry = 0;
rc = pdmqryQueryPlayEvent(start_entry, events, sizeof(events) / sizeof(events[0]), &out);
if (R_FAILED(rc)) return rc;
if (out == 0) return 1;
if (R_FAILED(rc))
return rc;
if (out == 0)
return 1;
int itr = -1;
for (int i = out-1; i >= 0; i--) {
for (int i = out - 1; i >= 0; i--) {
if (events[i].play_event_type != PdmPlayEventType_Applet)
continue;
if (events[i].event_data.applet.applet_id != AppletId_application)
@@ -112,8 +118,6 @@ namespace processManagement {
TID.parts.part[0] = events[i].event_data.applet.program_id[1];
TID.parts.part[1] = events[i].event_data.applet.program_id[0];
if (TID.full != (TIDnow & ~0xFFF))
continue;
else {
@@ -121,9 +125,11 @@ namespace processManagement {
break;
}
}
if (itr == -1) return 1;
if (itr == -1)
return 1;
bool isOut = events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus || events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus4;
bool isOut = events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus ||
events[itr].event_data.applet.event_type == PdmAppletEventType_OutOfFocus4;
*outOfFocus = isOut;
isOutOfFocus = isOut;
return 0;
@@ -158,4 +164,4 @@ namespace processManagement {
pdmqryExit();
}
}
} // namespace processManagement
@@ -24,7 +24,6 @@
* --------------------------------------------------------------------------
*/
#pragma once
#include <switch.h>
@@ -33,7 +32,7 @@ namespace processManagement {
void Initialize();
void WaitForQLaunch();
u64 GetCurrentApplicationId();
Result isApplicationOutOfFocus(bool* outOfFocus);
Result isApplicationOutOfFocus(bool *outOfFocus);
void Exit();
}
} // namespace processManagement
+38 -23
View File
@@ -12,44 +12,55 @@
*
* 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 "psm_ext.h"
const char* PsmPowerRoleToStr(PsmPowerRole role) {
const char *PsmPowerRoleToStr(PsmPowerRole role) {
switch (role) {
case PsmPowerRole_Sink: return "Sink";
case PsmPowerRole_Source: return "Source";
default: return "Unknown";
case PsmPowerRole_Sink:
return "Sink";
case PsmPowerRole_Source:
return "Source";
default:
return "Unknown";
}
}
const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type) {
const char *PsmInfoChargerTypeToStr(PsmInfoChargerType type) {
switch (type) {
case PsmInfoChargerType_None: return "None";
case PsmInfoChargerType_PD: return "USB-C PD";
case PsmInfoChargerType_None:
return "None";
case PsmInfoChargerType_PD:
return "USB-C PD";
case PsmInfoChargerType_TypeC_1500mA:
case PsmInfoChargerType_TypeC_3000mA: return "USB-C";
case PsmInfoChargerType_DCP: return "USB DCP";
case PsmInfoChargerType_CDP: return "USB CDP";
case PsmInfoChargerType_SDP: return "USB SDP";
case PsmInfoChargerType_TypeC_3000mA:
return "USB-C";
case PsmInfoChargerType_DCP:
return "USB DCP";
case PsmInfoChargerType_CDP:
return "USB CDP";
case PsmInfoChargerType_SDP:
return "USB SDP";
case PsmInfoChargerType_Apple_500mA:
case PsmInfoChargerType_Apple_1000mA:
case PsmInfoChargerType_Apple_2000mA: return "Apple";
default: return "Unknown";
case PsmInfoChargerType_Apple_2000mA:
return "Apple";
default:
return "Unknown";
}
}
bool PsmIsChargerConnected(const PsmChargeInfo* info) {
bool PsmIsChargerConnected(const PsmChargeInfo *info) {
return info->ChargerType != PsmInfoChargerType_None;
}
bool PsmIsCharging(const PsmChargeInfo* info) {
bool PsmIsCharging(const PsmChargeInfo *info) {
return PsmIsChargerConnected(info) && ((info->unk_x14 >> 8) & 1);
}
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) {
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo *info) {
if (!PsmIsChargerConnected(info))
return PsmBatteryState_Discharging;
if (!PsmIsCharging(info))
@@ -57,11 +68,15 @@ PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info) {
return PsmBatteryState_FastCharging;
}
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info) {
const char *PsmGetBatteryStateIcon(const PsmChargeInfo *info) {
switch (PsmGetBatteryState(info)) {
case PsmBatteryState_Discharging: return "\u25c0"; // ◀
case PsmBatteryState_ChargingPaused:return "| |";
case PsmBatteryState_FastCharging: return "\u25b6"; // ▶
default: return "?";
case PsmBatteryState_Discharging:
return "\u25c0"; // ◀
case PsmBatteryState_ChargingPaused:
return "| |";
case PsmBatteryState_FastCharging:
return "\u25b6"; // ▶
default:
return "?";
}
}
+44 -51
View File
@@ -12,7 +12,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#pragma once
@@ -20,75 +20,68 @@
#include <switch.h>
typedef enum {
PsmPDC_NewPDO = 1, //Received new Power Data Object
PsmPDC_NoPD = 2, //No Power Delivery source is detected
PsmPDC_AcceptedRDO = 3 //Received and accepted Request Data Object
} PsmChargeInfoPDC; //BM92T series
PsmPDC_NewPDO = 1, // Received new Power Data Object
PsmPDC_NoPD = 2, // No Power Delivery source is detected
PsmPDC_AcceptedRDO = 3 // Received and accepted Request Data Object
} PsmChargeInfoPDC; // BM92T series
typedef enum { PsmPowerRole_Sink = 1, PsmPowerRole_Source = 2 } PsmPowerRole;
const char *PsmPowerRoleToStr(PsmPowerRole role);
typedef enum {
PsmPowerRole_Sink = 1,
PsmPowerRole_Source = 2
} PsmPowerRole;
const char* PsmPowerRoleToStr(PsmPowerRole role);
typedef enum {
PsmInfoChargerType_None = 0,
PsmInfoChargerType_PD = 1,
PsmInfoChargerType_None = 0,
PsmInfoChargerType_PD = 1,
PsmInfoChargerType_TypeC_1500mA = 2,
PsmInfoChargerType_TypeC_3000mA = 3,
PsmInfoChargerType_DCP = 4,
PsmInfoChargerType_CDP = 5,
PsmInfoChargerType_SDP = 6,
PsmInfoChargerType_Apple_500mA = 7,
PsmInfoChargerType_DCP = 4,
PsmInfoChargerType_CDP = 5,
PsmInfoChargerType_SDP = 6,
PsmInfoChargerType_Apple_500mA = 7,
PsmInfoChargerType_Apple_1000mA = 8,
PsmInfoChargerType_Apple_2000mA = 9
} PsmInfoChargerType;
const char* PsmInfoChargerTypeToStr(PsmInfoChargerType type);
const char *PsmInfoChargerTypeToStr(PsmInfoChargerType type);
typedef enum {
PsmFlags_NoHub = BIT(0), //If hub is disconnected
PsmFlags_Rail = BIT(8), //At least one Joy-con is charging from rail
PsmFlags_SPDSRC = BIT(12), //OTG
PsmFlags_ACC = BIT(16) //Accessory
PsmFlags_NoHub = BIT(0), // If hub is disconnected
PsmFlags_Rail = BIT(8), // At least one Joy-con is charging from rail
PsmFlags_SPDSRC = BIT(12), // OTG
PsmFlags_ACC = BIT(16) // Accessory
} PsmChargeInfoFlags;
typedef struct {
int32_t InputCurrentLimit; //Input (Sink) current limit in mA
int32_t VBUSCurrentLimit; //Output (Source/VBUS/OTG) current limit in mA
int32_t ChargeCurrentLimit; //Battery charging current limit in mA (512mA when Docked, 768mA when BatteryTemperature < 17.0 C)
int32_t ChargeVoltageLimit; //Battery charging voltage limit in mV (3952mV when BatteryTemperature >= 51.0 C)
int32_t unk_x10; //Possibly an emum, getting the same value as PowerRole in all tested cases
int32_t unk_x14; //Possibly flags
PsmChargeInfoPDC PDCState; //Power Delivery Controller State
int32_t BatteryTemperature; //Battery temperature in milli C
int32_t RawBatteryCharge; //Raw battery charged capacity per cent-mille (i.e. 100% = 100000 pcm)
int32_t VoltageAvg; //Voltage avg in mV (more in Notes)
int32_t BatteryAge; //Battery age (capacity full / capacity design) per cent-mille (i.e. 100% = 100000 pcm)
int32_t InputCurrentLimit; // Input (Sink) current limit in mA
int32_t VBUSCurrentLimit; // Output (Source/VBUS/OTG) current limit in mA
int32_t ChargeCurrentLimit; // Battery charging current limit in mA (512mA when Docked, 768mA when BatteryTemperature < 17.0 C)
int32_t ChargeVoltageLimit; // Battery charging voltage limit in mV (3952mV when BatteryTemperature >= 51.0 C)
int32_t unk_x10; // Possibly an emum, getting the same value as PowerRole in all tested cases
int32_t unk_x14; // Possibly flags
PsmChargeInfoPDC PDCState; // Power Delivery Controller State
int32_t BatteryTemperature; // Battery temperature in milli C
int32_t RawBatteryCharge; // Raw battery charged capacity per cent-mille (i.e. 100% = 100000 pcm)
int32_t VoltageAvg; // Voltage avg in mV (more in Notes)
int32_t BatteryAge; // Battery age (capacity full / capacity design) per cent-mille (i.e. 100% = 100000 pcm)
PsmPowerRole PowerRole;
PsmInfoChargerType ChargerType;
int32_t ChargerVoltageLimit; //Charger and external device voltage limit in mV
int32_t ChargerCurrentLimit; //Charger and external device current limit in mA
PsmChargeInfoFlags Flags; //Unknown flags
int32_t ChargerVoltageLimit; // Charger and external device voltage limit in mV
int32_t ChargerCurrentLimit; // Charger and external device current limit in mA
PsmChargeInfoFlags Flags; // Unknown flags
} PsmChargeInfo;
typedef enum {
Psm_EnableBatteryCharging = 2,
Psm_DisableBatteryCharging = 3,
Psm_EnableFastBatteryCharging = 10,
Psm_DisableFastBatteryCharging = 11,
Psm_GetBatteryChargeInfoFields = 17,
Psm_EnableBatteryCharging = 2,
Psm_DisableBatteryCharging = 3,
Psm_EnableFastBatteryCharging = 10,
Psm_DisableFastBatteryCharging = 11,
Psm_GetBatteryChargeInfoFields = 17,
} IPsmServerCmd;
bool PsmIsChargerConnected(const PsmChargeInfo* info);
bool PsmIsCharging(const PsmChargeInfo* info);
bool PsmIsChargerConnected(const PsmChargeInfo *info);
bool PsmIsCharging(const PsmChargeInfo *info);
typedef enum {
PsmBatteryState_Discharging,
PsmBatteryState_ChargingPaused,
PsmBatteryState_FastCharging
} PsmBatteryState;
typedef enum { PsmBatteryState_Discharging, PsmBatteryState_ChargingPaused, PsmBatteryState_FastCharging } PsmBatteryState;
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo* info);
const char* PsmGetBatteryStateIcon(const PsmChargeInfo* info);
PsmBatteryState PsmGetBatteryState(const PsmChargeInfo *info);
const char *PsmGetBatteryStateIcon(const PsmChargeInfo *info);
+5 -7
View File
@@ -12,11 +12,12 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#define NX_SERVICE_ASSUME_NON_DOMAIN
#include <switch.h>
#include "../util/service_guard.h"
#include "pwm.h"
@@ -32,18 +33,15 @@ void _pwmCleanup(void) {
serviceClose(&g_pwmSrv);
}
Service* pwmGetServiceSession(void) {
Service *pwmGetServiceSession(void) {
return &g_pwmSrv;
}
Result pwmOpenSession2(PwmChannelSession *out, u32 device_code) {
return serviceDispatchIn(&g_pwmSrv, 2, device_code,
.out_num_objects = 1,
.out_objects = &out->s,
);
return serviceDispatchIn(&g_pwmSrv, 2, device_code, .out_num_objects = 1, .out_objects = &out->s, );
}
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double* out) {
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double *out) {
return serviceDispatchOut(&c->s, 7, *out);
}
+4 -4
View File
@@ -12,7 +12,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#pragma once
@@ -29,11 +29,11 @@ typedef struct {
Result pwmInitialize(void);
void pwmExit(void);
Service* pwmGetServiceSession(void);
Service *pwmGetServiceSession(void);
Result pwmOpenSession2(PwmChannelSession *out, u32 device_code);
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double* out);
Result pwmChannelSessionGetDutyCycle(PwmChannelSession *c, double *out);
void pwmChannelSessionClose(PwmChannelSession *c);
#ifdef __cplusplus
} // extern "C"
} // extern "C"
#endif
+10 -8
View File
@@ -12,13 +12,15 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#pragma once
#include <switch.h>
#include "pcv_types.h"
typedef struct {
Service s;
} RgltrSession;
@@ -27,12 +29,12 @@ Result rgltrInitialize(void);
void rgltrExit(void);
Service* rgltrGetServiceSession(void);
Service *rgltrGetServiceSession(void);
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id);
void rgltrCloseSession(RgltrSession* session);
Result rgltrGetVoltage(RgltrSession* session, u32 *out_volt);
Result rgltrOpenSession(RgltrSession *session_out, PowerDomainId module_id);
void rgltrCloseSession(RgltrSession *session);
Result rgltrGetVoltage(RgltrSession *session, u32 *out_volt);
Result rgltrGetPowerModuleNumLimit(u32 *out);
Result rgltrGetVoltageEnabled(RgltrSession* session, u32 *out);
Result rgltrRequestVoltage(RgltrSession* session, u32 microvolt);
Result rgltrCancelVoltageRequest(RgltrSession* session);
Result rgltrGetVoltageEnabled(RgltrSession *session, u32 *out);
Result rgltrRequestVoltage(RgltrSession *session, u32 microvolt);
Result rgltrCancelVoltageRequest(RgltrSession *session);
@@ -12,13 +12,15 @@
*
* 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 "rgltr.h"
#include "rgltr_services.h" // for extern Service g_rgltrSrv, etc.
// Global service handle
Service g_rgltrSrv;
@@ -33,18 +35,12 @@ void rgltrExit(void) {
serviceClose(&g_rgltrSrv);
}
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id) {
Result rgltrOpenSession(RgltrSession *session_out, PowerDomainId module_id) {
const u32 in = (u32)module_id;
return serviceDispatchIn(
&g_rgltrSrv,
0,
in,
.out_num_objects = 1,
.out_objects = &session_out->s
);
return serviceDispatchIn(&g_rgltrSrv, 0, in, .out_num_objects = 1, .out_objects = &session_out->s);
}
Result rgltrGetVoltage(RgltrSession* session, u32* out_volt) {
Result rgltrGetVoltage(RgltrSession *session, u32 *out_volt) {
u32 temp = 0;
Result rc = serviceDispatchOut(&session->s, 4, temp);
if (R_SUCCEEDED(rc)) {
@@ -53,14 +49,14 @@ Result rgltrGetVoltage(RgltrSession* session, u32* out_volt) {
return rc;
}
Result rgltrRequestVoltage(RgltrSession* session, u32 microvolt) {
Result rgltrRequestVoltage(RgltrSession *session, u32 microvolt) {
return serviceDispatchIn(&session->s, 5, microvolt);
}
Result rgltrCancelVoltageRequest(RgltrSession* session) {
Result rgltrCancelVoltageRequest(RgltrSession *session) {
return serviceDispatch(&session->s, 6);
}
void rgltrCloseSession(RgltrSession* session) {
void rgltrCloseSession(RgltrSession *session) {
serviceClose(&session->s);
}
@@ -12,21 +12,23 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
#pragma once
#include <switch.h> // for Service, Result, hosversionBefore(), smGetService(), serviceClose(), etc.
#include "rgltr.h" // for RgltrSession, PowerDomainId, etc.
#include "rgltr.h" // for RgltrSession, PowerDomainId, etc.
extern Service g_rgltrSrv;
Result rgltrInitialize(void);
void rgltrExit(void);
void rgltrExit(void);
Result rgltrOpenSession(RgltrSession* session_out, PowerDomainId module_id);
Result rgltrOpenSession(RgltrSession *session_out, PowerDomainId module_id);
Result rgltrGetVoltage(RgltrSession* session, u32* out_volt);
Result rgltrGetVoltage(RgltrSession *session, u32 *out_volt);
void rgltrCloseSession(RgltrSession* session);
void rgltrCloseSession(RgltrSession *session);