Refactor screen functions, completely fix config not saving bug

This commit is contained in:
Aurora Wright
2017-06-06 02:12:18 +02:00
parent 21db0d45bd
commit 31f4419eec
7 changed files with 35 additions and 52 deletions

View File

@@ -57,19 +57,20 @@ bool readConfig(void)
return ret;
}
void writeConfig(bool isPayloadLaunch)
void writeConfig(bool isConfigOptions)
{
if(isPayloadLaunch) configData.config = (configData.config & 0xFFFFFF80) | (oldConfig & 0x7F);
/* If the configuration is different from previously, overwrite it.
Just the no-forcing flag being set is not enough */
if(needConfig != CREATE_CONFIGURATION && (configData.config & 0xFFFFFFBF) == oldConfig) return;
if(needConfig != CREATE_CONFIGURATION && ((isConfigOptions && (configData.config & 0xFFFFFF00) == (oldConfig & 0xFFFFFF00)) ||
(!isConfigOptions && (configData.config & 0xBF) == (oldConfig & 0xFF)))) return;
if(needConfig == CREATE_CONFIGURATION)
{
memcpy(configData.magic, "CONF", 4);
configData.formatVersionMajor = CONFIG_VERSIONMAJOR;
configData.formatVersionMinor = CONFIG_VERSIONMINOR;
needConfig = MODIFY_CONFIGURATION;
}
if(!fileWrite(&configData, CONFIG_FILE, sizeof(CfgData)))
@@ -387,6 +388,8 @@ void configMenu(bool oldPinStatus, u32 oldPinMode)
if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode);
else if(oldPinStatus) fileDelete(PIN_FILE);
writeConfig(true);
while(HID_PAD & PIN_BUTTONS);
wait(2000ULL);
}

View File

@@ -69,5 +69,5 @@ typedef enum ConfigurationStatus
} ConfigurationStatus;
bool readConfig(void);
void writeConfig(bool isPayloadLaunch);
void writeConfig(bool isConfigOptions);
void configMenu(bool oldPinStatus, u32 oldPinMode);

View File

@@ -33,7 +33,6 @@
#include "screen.h"
#include "draw.h"
#include "utils.h"
#include "config.h"
#include "fatfs/ff.h"
#include "buttons.h"
#include "firm.h"
@@ -167,8 +166,6 @@ void loadPayload(u32 pressed, const char *payloadPath)
if(payloadSize <= 0x200 || !checkFirmPayload(payloadSize)) return;
writeConfig(true);
if(isSdMode) sprintf(absPath, "sdmc:/luma/%s", path);
else sprintf(absPath, "nand:/rw/luma/%s", path);

View File

@@ -35,7 +35,19 @@
#include "i2c.h"
#include "utils.h"
struct fb fbs[2];
struct fb fbs[2] =
{
{
.top_left = (u8 *)0x18300000,
.top_right = (u8 *)0x18300000,
.bottom = (u8 *)0x18346500,
},
{
.top_left = (u8 *)0x18400000,
.top_right = (u8 *)0x18400000,
.bottom = (u8 *)0x18446500,
},
};
static const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26};
@@ -78,25 +90,6 @@ void clearScreens(bool isAlternate)
invokeArm11Function(CLEAR_SCREENS);
}
static void initScreensSequence(void)
{
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[MULTICONFIG(BRIGHTNESS)];
invokeArm11Function(INIT_SCREENS_SEQUENCE);
}
static void setupFramebuffers(void)
{
fbs[0].top_left = (u8 *)0x18300000;
fbs[1].top_left = (u8 *)0x18400000;
fbs[0].top_right = (u8 *)0x18300000;
fbs[1].top_right = (u8 *)0x18400000;
fbs[0].bottom = (u8 *)0x18346500;
fbs[1].bottom = (u8 *)0x18446500;
memcpy((void *)ARM11_PARAMETERS_ADDRESS, fbs, sizeof(fbs));
invokeArm11Function(SETUP_FRAMEBUFFERS);
}
void initScreens(void)
{
static bool needToSetup = true;
@@ -105,14 +98,15 @@ void initScreens(void)
{
if(!ARESCREENSINITIALIZED)
{
initScreensSequence();
*(vu32 *)ARM11_PARAMETERS_ADDRESS = brightness[MULTICONFIG(BRIGHTNESS)];
memcpy((void *)(ARM11_PARAMETERS_ADDRESS + 4), fbs, sizeof(fbs));
invokeArm11Function(INIT_SCREENS);
//Turn on backlight
i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A);
}
else updateBrightness(MULTICONFIG(BRIGHTNESS));
setupFramebuffers();
needToSetup = false;
}

View File

@@ -53,8 +53,7 @@ struct fb {
typedef enum
{
INIT_SCREENS_SEQUENCE = 0,
SETUP_FRAMEBUFFERS,
INIT_SCREENS = 0,
CLEAR_SCREENS,
SWAP_FRAMEBUFFERS,
UPDATE_BRIGHTNESS,