rosalina: add system info menu with TN/IPS screen detection in it

This commit is contained in:
TuxSH 2024-08-14 22:48:33 +02:00
parent 85c1997f2b
commit f0be624792
4 changed files with 99 additions and 19 deletions

View File

@ -70,6 +70,9 @@ extern bool isHidInitialized;
extern u32 mcuFwVersion; extern u32 mcuFwVersion;
extern u8 mcuInfoTable[9]; extern u8 mcuInfoTable[9];
extern bool mcuInfoTableRead; extern bool mcuInfoTableRead;
extern const char *topScreenType;
extern const char *bottomScreenType;
extern bool areScreenTypesInitialized;
// From main.c // From main.c
extern bool isN3DS; extern bool isN3DS;

View File

@ -41,5 +41,7 @@ void RosalinaMenu_PowerOff(void);
void RosalinaMenu_Reboot(void); void RosalinaMenu_Reboot(void);
void RosalinaMenu_Cheats(void); void RosalinaMenu_Cheats(void);
void RosalinaMenu_ShowSystemInfo();
bool rosalinaMenuShouldShowDebugInfo(void); bool rosalinaMenuShouldShowDebugInfo(void);
void RosalinaMenu_ShowDebugInfo(void); void RosalinaMenu_ShowDebugInfo(void);

View File

@ -46,6 +46,10 @@ u32 mcuFwVersion = 0;
u8 mcuInfoTable[9] = {0}; u8 mcuInfoTable[9] = {0};
bool mcuInfoTableRead = false; bool mcuInfoTableRead = false;
const char *topScreenType = NULL;
const char *bottomScreenType = NULL;
bool areScreenTypesInitialized = false;
// libctru redefinition: // libctru redefinition:
bool hidShouldUseIrrst(void) bool hidShouldUseIrrst(void)
@ -235,6 +239,50 @@ static Result menuUpdateMcuInfo(void)
return res; return res;
} }
static const char *menuGetScreenTypeStr(u8 vendorId)
{
switch (vendorId)
{
case 1: return "IPS"; // SHARP
case 12: return "TN"; // JDN
default: return "unknown";
}
}
static void menuReadScreenTypes(void)
{
if (areScreenTypesInitialized)
return;
if (!isN3DS)
{
// Old3DS never have IPS screens and GetVendors is not implemented
topScreenType = "TN";
bottomScreenType = "TN";
areScreenTypesInitialized = true;
}
else
{
srvSetBlockingPolicy(true);
Result res = gspLcdInit();
if (R_SUCCEEDED(res))
{
u8 vendors = 0;
if (R_SUCCEEDED(GSPLCD_GetVendors(&vendors)))
{
topScreenType = menuGetScreenTypeStr(vendors >> 4);
bottomScreenType = menuGetScreenTypeStr(vendors & 0xF);
areScreenTypesInitialized = true;
}
gspLcdExit();
}
srvSetBlockingPolicy(false);
}
}
static inline u32 menuAdvanceCursor(u32 pos, u32 numItems, s32 displ) static inline u32 menuAdvanceCursor(u32 pos, u32 numItems, s32 displ)
{ {
return (pos + numItems + displ) % numItems; return (pos + numItems + displ) % numItems;
@ -272,7 +320,7 @@ void menuThreadMain(void)
if(isN3DS) if(isN3DS)
N3DSMenu_UpdateStatus(); N3DSMenu_UpdateStatus();
while (!isServiceUsable("ac:u") || !isServiceUsable("hid:USER") || !isServiceUsable("gsp::Gpu") || !isServiceUsable("cdc:CHK")) while (!isServiceUsable("ac:u") || !isServiceUsable("hid:USER") || !isServiceUsable("gsp::Gpu") || !isServiceUsable("gsp::Lcd") || !isServiceUsable("cdc:CHK"))
svcSleepThread(250 * 1000 * 1000LL); svcSleepThread(250 * 1000 * 1000LL);
handleShellOpened(); handleShellOpened();
@ -280,6 +328,8 @@ void menuThreadMain(void)
hidInit(); // assume this doesn't fail hidInit(); // assume this doesn't fail
isHidInitialized = true; isHidInitialized = true;
menuReadScreenTypes();
while(!preTerminationRequested) while(!preTerminationRequested)
{ {
svcSleepThread(50 * 1000 * 1000LL); svcSleepThread(50 * 1000 * 1000LL);
@ -385,6 +435,14 @@ static void menuDraw(Menu *menu, u32 selected)
int n = sprintf(ipBuffer, "%hhu.%hhu.%hhu.%hhu", addr[0], addr[1], addr[2], addr[3]); int n = sprintf(ipBuffer, "%hhu.%hhu.%hhu.%hhu", addr[0], addr[1], addr[2], addr[3]);
Draw_DrawString(SCREEN_BOT_WIDTH - 10 - SPACING_X * n, 10, COLOR_WHITE, ipBuffer); Draw_DrawString(SCREEN_BOT_WIDTH - 10 - SPACING_X * n, 10, COLOR_WHITE, ipBuffer);
} }
#if 0
else if (areScreenTypesInitialized)
{
char screenTypesBuffer[32];
int n = sprintf(screenTypesBuffer, "T: %s | B: %s", topScreenType, bottomScreenType);
Draw_DrawString(SCREEN_BOT_WIDTH - 10 - SPACING_X * n, 10, COLOR_WHITE, screenTypesBuffer);
}
#endif
else else
Draw_DrawFormattedString(SCREEN_BOT_WIDTH - 10 - SPACING_X * 15, 10, COLOR_WHITE, "%15s", ""); Draw_DrawFormattedString(SCREEN_BOT_WIDTH - 10 - SPACING_X * 15, 10, COLOR_WHITE, "%15s", "");

View File

@ -59,6 +59,7 @@ Menu rosalinaMenu = {
{ "Save settings", METHOD, .method = &RosalinaMenu_SaveSettings }, { "Save settings", METHOD, .method = &RosalinaMenu_SaveSettings },
{ "Power off", METHOD, .method = &RosalinaMenu_PowerOff }, { "Power off", METHOD, .method = &RosalinaMenu_PowerOff },
{ "Reboot", METHOD, .method = &RosalinaMenu_Reboot }, { "Reboot", METHOD, .method = &RosalinaMenu_Reboot },
{ "System info", METHOD, .method = &RosalinaMenu_ShowSystemInfo },
{ "Credits", METHOD, .method = &RosalinaMenu_ShowCredits }, { "Credits", METHOD, .method = &RosalinaMenu_ShowCredits },
{ "Debug info", METHOD, .method = &RosalinaMenu_ShowDebugInfo, .visibility = &rosalinaMenuShouldShowDebugInfo }, { "Debug info", METHOD, .method = &RosalinaMenu_ShowDebugInfo, .visibility = &rosalinaMenuShouldShowDebugInfo },
{}, {},
@ -96,6 +97,37 @@ void RosalinaMenu_SaveSettings(void)
while(!(waitInput() & KEY_B) && !menuShouldExit); while(!(waitInput() & KEY_B) && !menuShouldExit);
} }
void RosalinaMenu_ShowSystemInfo(void)
{
u32 kver = osGetKernelVersion();
do
{
Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Rosalina -- System info");
u32 posY = 30;
if (areScreenTypesInitialized)
{
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Top screen type: %s\n", topScreenType);
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Bottom screen type: %s\n\n", bottomScreenType);
}
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Kernel version: %lu.%lu-%lu\n\n", GET_VERSION_MAJOR(kver), GET_VERSION_MINOR(kver), GET_VERSION_REVISION(kver));
if (mcuFwVersion != 0 && mcuInfoTableRead)
{
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "MCU FW version: %lu.%lu\n", GET_VERSION_MAJOR(mcuFwVersion), GET_VERSION_MINOR(mcuFwVersion));
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "PMIC vendor: %hhu\n", mcuInfoTable[1]);
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Battery vendor: %hhu\n\n", mcuInfoTable[2]);
}
Draw_FlushFramebuffer();
Draw_Unlock();
}
while(!(waitInput() & KEY_B) && !menuShouldExit);
}
void RosalinaMenu_ShowDebugInfo(void) void RosalinaMenu_ShowDebugInfo(void)
{ {
Draw_Lock(); Draw_Lock();
@ -111,7 +143,6 @@ void RosalinaMenu_ShowDebugInfo(void)
u32 kextPa = (u32)((u64)kextAddrSize >> 32); u32 kextPa = (u32)((u64)kextAddrSize >> 32);
u32 kextSize = (u32)kextAddrSize; u32 kextSize = (u32)kextAddrSize;
u32 kernelVer = osGetKernelVersion();
FS_SdMmcSpeedInfo speedInfo; FS_SdMmcSpeedInfo speedInfo;
do do
@ -119,24 +150,10 @@ void RosalinaMenu_ShowDebugInfo(void)
Draw_Lock(); Draw_Lock();
Draw_DrawString(10, 10, COLOR_TITLE, "Rosalina -- Debug info"); Draw_DrawString(10, 10, COLOR_TITLE, "Rosalina -- Debug info");
u32 posY = Draw_DrawString(10, 30, COLOR_WHITE, memoryMap); u32 posY = 30;
posY = Draw_DrawString(10, posY, COLOR_WHITE, memoryMap);
posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Kernel ext PA: %08lx - %08lx\n\n", kextPa, kextPa + kextSize); posY = Draw_DrawFormattedString(10, posY, COLOR_WHITE, "Kernel ext PA: %08lx - %08lx\n\n", kextPa, kextPa + kextSize);
posY = Draw_DrawFormattedString(
10, posY, COLOR_WHITE, "Kernel version: %lu.%lu-%lu\n",
GET_VERSION_MAJOR(kernelVer), GET_VERSION_MINOR(kernelVer), GET_VERSION_REVISION(kernelVer)
);
if (mcuFwVersion != 0 && mcuInfoTableRead)
{
posY = Draw_DrawFormattedString(
10, posY, COLOR_WHITE, "MCU FW version: %lu.%lu (PMIC vendor: %hhu)\n",
GET_VERSION_MAJOR(mcuFwVersion), GET_VERSION_MINOR(mcuFwVersion),
mcuInfoTable[1]
);
posY = Draw_DrawFormattedString(
10, posY, COLOR_WHITE, "Battery: vendor: %hhu gauge IC ver.: %hhu.%hhu RCOMP: %hhu\n",
mcuInfoTable[2], mcuInfoTable[3], mcuInfoTable[4], mcuInfoTable[4]
);
}
if (R_SUCCEEDED(FSUSER_GetSdmcSpeedInfo(&speedInfo))) if (R_SUCCEEDED(FSUSER_GetSdmcSpeedInfo(&speedInfo)))
{ {
u32 clkDiv = 1 << (1 + (speedInfo.sdClkCtrl & 0xFF)); u32 clkDiv = 1 << (1 + (speedInfo.sdClkCtrl & 0xFF));