Skip to content

Commit

Permalink
up to latest commit 5
Browse files Browse the repository at this point in the history
Signed-off-by: Fra <[email protected]>
  • Loading branch information
Alexyo21 committed Aug 4, 2024
1 parent d9fe838 commit 5cc94b5
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 10 deletions.
1 change: 1 addition & 0 deletions sysmodules/rosalina/source/luma_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ static size_t LumaConfig_SaveLumaIniConfigToStr(char *out, const CfgData *cfg)
(int)cfg->ntpTzOffetMinutes,

(int)cfg->topScreenFilter.cct, (int)cfg->bottomScreenFilter.cct,
(int)cfg->topScreenFilter.colorCurveCorrection, (int)cfg->bottomScreenFilter.colorCurveCorrection,
topScreenFilterGammaStr, bottomScreenFilterGammaStr,
topScreenFilterContrastStr, bottomScreenFilterContrastStr,
topScreenFilterBrightnessStr, bottomScreenFilterBrightnessStr,
Expand Down
5 changes: 5 additions & 0 deletions sysmodules/rosalina/source/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
u32 menuCombo = 0;
bool isHidInitialized = false;
u32 mcuFwVersion = 0;
u8 mcuInfoTable[9] = {0};
bool mcuInfoTableRead = false;
bool rosalinaOpen = false;

void menuToggleLeds(void)
Expand Down Expand Up @@ -282,6 +284,9 @@ static Result menuUpdateMcuInfo(void)
MCUHWC_ReadRegister(0x27, volumeSlider + 0, 1); // Raw volume slider state
MCUHWC_ReadRegister(0x09, volumeSlider + 1, 1); // Volume slider state

if (!mcuInfoTableRead)
mcuInfoTableRead = R_SUCCEEDED(MCUHWC_ReadRegister(0x7F, mcuInfoTable, sizeof(mcuInfoTable)));

svcCloseHandle(*mcuHwcHandlePtr);
return res;
}
Expand Down
12 changes: 8 additions & 4 deletions sysmodules/rosalina/source/menus.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,18 @@ void RosalinaMenu_ShowDebugInfo(void)
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)
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)
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)))
{
u32 clkDiv = 1 << (1 + (speedInfo.sdClkCtrl & 0xFF));
Expand Down
71 changes: 65 additions & 6 deletions sysmodules/rosalina/source/menus/screen_filters.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "luminance.h"
#include "menus/miscellaneous.h"
#include "menus/screen_filters.h"
#include "menus/screen_filters_srgb_tables.h"
#include "draw.h"
#include "redshift/colorramp.h"
#include "menus/sysconfig.h"
Expand Down Expand Up @@ -62,6 +63,7 @@ static inline bool ScreenFiltersMenu_IsDefaultSettingsFilter(const ScreenFilter
ok = ok && filter->gamma == 1.0f;
ok = ok && filter->contrast == 1.0f;
ok = ok && filter->brightness == 0.0f;
ok = ok && filter->colorCurveCorrection == 0;
return ok;
}

Expand Down Expand Up @@ -98,7 +100,7 @@ static u8 ScreenFilterMenu_CalculatePolynomialColorLutComponent(const float coef
return (u8)CLAMP(levelInt, 0, 255); // clamp again just to be sure
}

static void ScreenFilterMenu_WritePolynomialColorLut(bool top, const float coeffs[][3], bool invert, float gamma, u32 dim)
static void ScreenFilterMenu_WritePolynomialColorLut(bool top, u8 curveCorrection, const float coeffs[][3], bool invert, float gamma, u32 dim)
{
if(configExtra.suppressLeds)
{
Expand All @@ -113,9 +115,15 @@ static void ScreenFilterMenu_WritePolynomialColorLut(bool top, const float coeff
for (int i = 0; i <= 255; i++) {
Pixel px;
int inLevel = invert ? 255 - i : i;
px.r = ScreenFilterMenu_CalculatePolynomialColorLutComponent(coeffs, 0, gamma, dim, inLevel);
px.g = ScreenFilterMenu_CalculatePolynomialColorLutComponent(coeffs, 1, gamma, dim, inLevel);
px.b = ScreenFilterMenu_CalculatePolynomialColorLutComponent(coeffs, 2, gamma, dim, inLevel);
const u8 (*tbl)[3] = curveCorrection == 2 ? ctrToSrgbTableTop : ctrToSrgbTableBottom;

u8 inLevelR = curveCorrection > 0 ? tbl[inLevel][0] : inLevel;
u8 inLevelG = curveCorrection > 0 ? tbl[inLevel][1] : inLevel;
u8 inLevelB = curveCorrection > 0 ? tbl[inLevel][2] : inLevel;

px.r = ScreenFilterMenu_CalculatePolynomialColorLutComponent(coeffs, 0, gamma, dim, inLevelR);
px.g = ScreenFilterMenu_CalculatePolynomialColorLutComponent(coeffs, 1, gamma, dim, inLevelG);
px.b = ScreenFilterMenu_CalculatePolynomialColorLutComponent(coeffs, 2, gamma, dim, inLevelB);
px.z = 0;

if (top)
Expand All @@ -141,7 +149,7 @@ static void ScreenFiltersMenu_ApplyColorSettings(bool top)
{ a * wp[0], a * wp[1], a * wp[2] }, // x^1
};

ScreenFilterMenu_WritePolynomialColorLut(top, poly, inv, g, 1);
ScreenFilterMenu_WritePolynomialColorLut(top, filter->colorCurveCorrection, poly, inv, g, 1);
}

static void ScreenFiltersMenu_SetCct(u16 cct)
Expand All @@ -152,6 +160,30 @@ static void ScreenFiltersMenu_SetCct(u16 cct)
ScreenFiltersMenu_ApplyColorSettings(false);
}

static void ScreenFiltersMenu_UpdateEntries(void)
{
if (topScreenFilter.colorCurveCorrection == 0 || bottomScreenFilter.colorCurveCorrection == 0)
{
screenFiltersMenu.items[10].title = "Adjust both screens color curve to sRGB";
screenFiltersMenu.items[10].method = &ScreenFiltersMenu_SetSrgbColorCurves;
}
else
{
screenFiltersMenu.items[10].title = "Restore both screens color curve";
screenFiltersMenu.items[10].method = &ScreenFiltersMenu_RestoreColorCurves;
}
}
static void ScreenFiltersMenu_SetColorCurveCorrection(bool top, u8 colorCurveCorrection)
{
if (top)
topScreenFilter.colorCurveCorrection = colorCurveCorrection;
else
bottomScreenFilter.colorCurveCorrection = colorCurveCorrection;

ScreenFiltersMenu_ApplyColorSettings(top);
ScreenFiltersMenu_UpdateEntries();
}

Menu screenFiltersMenu = {
"Screen filters menu",
{
Expand All @@ -165,7 +197,8 @@ Menu screenFiltersMenu = {
{ "[2300K] Warm Incandescent", METHOD, .method = &ScreenFiltersMenu_SetWarmIncandescent },
{ "[1900K] Candle", METHOD, .method = &ScreenFiltersMenu_SetCandle },
{ "[1200K] Ember", METHOD, .method = &ScreenFiltersMenu_SetEmber },
{ "Advanced configuration", METHOD, .method = &ScreenFiltersMenu_AdvancedConfiguration },
{ "Adjust both screen color curve to sRGB", METHOD, .method = &ScreenFiltersMenu_SetSrgbColorCurves },
{ "Advanced configuration...", METHOD, .method = &ScreenFiltersMenu_AdvancedConfiguration },
{},
}
};
Expand All @@ -176,6 +209,12 @@ void ScreenFiltersMenu_Set##name(void)\
ScreenFiltersMenu_SetCct(temp);\
}

#define DEF_SRGB_SETTER(top, profile, name)\
void ScreenFiltersMenu_##name(void)\
{\
ScreenFiltersMenu_SetColorCurveCorrection(top, profile);\
}

void ScreenFiltersMenu_RestoreSettings(void)
{
// Precondition: menu has not been entered
Expand Down Expand Up @@ -237,6 +276,9 @@ void ScreenFiltersMenu_LoadConfig(void)
svcGetSystemInfo(&out, 0x10000, 0x107);
topScreenFilter.invert = (bool)out;

svcGetSystemInfo(&out, 0x10000, 0x10D);
topScreenFilter.colorCurveCorrection = (u8)out;

svcGetSystemInfo(&out, 0x10000, 0x108);
bottomScreenFilter.cct = (u16)out;
if (bottomScreenFilter.cct < 1000 || bottomScreenFilter.cct > 25100)
Expand All @@ -259,6 +301,11 @@ void ScreenFiltersMenu_LoadConfig(void)

svcGetSystemInfo(&out, 0x10000, 0x10C);
bottomScreenFilter.invert = (bool)out;

svcGetSystemInfo(&out, 0x10000, 0x10E);
bottomScreenFilter.colorCurveCorrection = (u8)out;

ScreenFiltersMenu_UpdateEntries();
}

DEF_CCT_SETTER(6500, Default)
Expand All @@ -273,6 +320,18 @@ DEF_CCT_SETTER(2300, WarmIncandescent)
DEF_CCT_SETTER(1900, Candle)
DEF_CCT_SETTER(1200, Ember)

void ScreenFiltersMenu_SetSrgbColorCurves(void)
{
ScreenFiltersMenu_SetColorCurveCorrection(true, 1);
ScreenFiltersMenu_SetColorCurveCorrection(false, 2);
}

void ScreenFiltersMenu_RestoreColorCurves(void)
{
ScreenFiltersMenu_SetColorCurveCorrection(true, 0);
ScreenFiltersMenu_SetColorCurveCorrection(false, 0);
}

static void ScreenFiltersMenu_ClampFilter(ScreenFilter *filter)
{
filter->cct = CLAMP(filter->cct, 1000, 25100);
Expand Down

0 comments on commit 5cc94b5

Please sign in to comment.