From 8291985f421bc76024de0efc774fdd39f29f1179 Mon Sep 17 00:00:00 2001 From: Alexander Hartmann Date: Wed, 9 Mar 2016 13:51:04 +0100 Subject: [PATCH] added support to configure the brightnes for screen init to BOOTCTR9 section --- README.md | 2 ++ bootloader/include/config.h | 1 + bootloader/include/screen.h | 1 + bootloader/source/config.c | 2 ++ bootloader/source/main.c | 15 +++++++++------ bootloader/source/screen.c | 33 ++++++++++++++++++++++----------- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 68fbd8b..b5405d1 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,8 @@ This section includes some BootCTR9 only configurations: * This is the same as fileLog, but the log is showen on the bottom screen, instead of written to a file * screenEnabled * This configures if the screen should be enabled directly at boot +* screenBrightness + * This configures the brightness that us used for screen initialisation ## How do I update it? diff --git a/bootloader/include/config.h b/bootloader/include/config.h index 4cbffff..8f79a46 100644 --- a/bootloader/include/config.h +++ b/bootloader/include/config.h @@ -25,6 +25,7 @@ typedef struct { bool fileLog; bool screenLog; unsigned int screenEnabled; + unsigned int screenBrightness; } loaderConfiguration; diff --git a/bootloader/include/screen.h b/bootloader/include/screen.h index c12b44a..21ff39d 100644 --- a/bootloader/include/screen.h +++ b/bootloader/include/screen.h @@ -1,6 +1,7 @@ #include "common.h" typedef void (*arm11Function)(void); +void setStartBrightness(u32 _brightness); void screenInit(); void screenDeinit(); void __attribute__((naked)) disable_lcds(); diff --git a/bootloader/source/config.c b/bootloader/source/config.c index c5d55fc..70db162 100644 --- a/bootloader/source/config.c +++ b/bootloader/source/config.c @@ -130,6 +130,8 @@ int handlerLoaderConfiguration(void *user, const char *section, const char *name pconfig->screenLog = myAtoi(value); } else if (MATCH(pconfig->section, "screenEnabled")) { pconfig->screenEnabled = myAtoi(value); + } else if (MATCH(pconfig->section, "screenBrightness")) { + pconfig->screenBrightness = numberToInt(value); } return 1; } diff --git a/bootloader/source/main.c b/bootloader/source/main.c index 84f0592..fe68439 100644 --- a/bootloader/source/main.c +++ b/bootloader/source/main.c @@ -24,8 +24,9 @@ #define DEFAULT_SCREEN_LOADER 1 /* 0 - use payloadConfiguration in the end, 1 - screen init at start */ #define DEFAULT_LOG_FILE 0 #define DEFAULT_LOG_SCREEN 0 -#define DEFAULT_SPLASH 0 /* 0 - disabled, 1 - splash screen, 2 - asciiSplash */ -#define DEFAULT_SPLASH_IMAGE {0} +#define DEFAULT_BOOTSPLASH 0 /* 0 - disabled, 1 - splash screen, 2 - asciiSplash */ +#define DEFAULT_BOOTSPLASH_IMAGE {0} +#define DEFAULT_BRIGHTNESS 0xFF #define INI_FILE "/arm9loaderhax/boot_config.ini" #define INI_FILE_BOOTCTR "/boot_config.ini" @@ -85,7 +86,7 @@ int main() { configuration app = { .section = DEFAULT_SECTION, .path = DEFAULT_PATH, - .splashDelay = DEFAULT_KEYDELAY, + .splashDelay = DEFAULT_SPLASHDELAY, .payload = DEFAULT_PAYLOAD, .offset = DEFAULT_OFFSET, .splash = DEFAULT_SPLASH, @@ -94,12 +95,13 @@ int main() { }; loaderConfiguration loader = { .section = LOADER_SECTION, - .keyDelay = DEFAULT_SPLASHDELAY, - .bootsplash = DEFAULT_SPLASH, - .bootsplash_image = DEFAULT_SPLASH_IMAGE, + .keyDelay = DEFAULT_KEYDELAY, + .bootsplash = DEFAULT_BOOTSPLASH, + .bootsplash_image = DEFAULT_BOOTSPLASH_IMAGE, .fileLog = DEFAULT_LOG_FILE, .screenLog = DEFAULT_LOG_SCREEN, .screenEnabled = DEFAULT_SCREEN, + .screenBrightness = DEFAULT_BRIGHTNESS, }; FATFS fs; FIL payload; @@ -108,6 +110,7 @@ int main() { { iniparse(INI_FILE,handlerLoaderConfiguration,&loader); initLog(loader.fileLog, loader.screenLog); + setStartBrightness(loader.screenBrightness); initScreen(loader.screenEnabled); if(loader.screenEnabled) diff --git a/bootloader/source/screen.c b/bootloader/source/screen.c index e6eaec8..c58cf9d 100644 --- a/bootloader/source/screen.c +++ b/bootloader/source/screen.c @@ -1,9 +1,20 @@ #include "screen.h" #include "i2c.h" +#define DEFAULT_BRIGHTNESS 0x39 +#define FB_TOP_LEFT 0x18300000 +#define FB_TOP_RIGHT 0x18300000 +#define FB_BOTTOM 0x18346500 + //got code for disabeling from CakesForeveryWan -volatile u32 *a11_entry = (volatile u32 *)0x1FFFFFF8; +volatile u32 *a11_entry = (volatile u32 *)0x1FFFFFF8; +volatile u32 brightness = DEFAULT_BRIGHTNESS; bool screenInitialized=false; + +void setStartBrightness(u32 _brightness) +{ + brightness=_brightness; +} void screenInit() { if(*((u8*)0x101401C0) == 0x0&&screenInitialized==false) @@ -53,8 +64,8 @@ void __attribute__((naked)) disable_lcds() void regSet(); void __attribute__ ((naked)) enable_lcd() { - //__asm__ ("ldr r0,=0x1FFF4D80\n\t mov sp, r0"); - regSet(); + //__asm__ ("ldr r0,=_stack\n\t mov sp, r0"); + regSet(); } void regSet() @@ -157,10 +168,10 @@ void regSet() *((volatile u32*)0x10202a04) = 0x00000000; // color fill disable *((volatile u32*)0x1020200C) &= 0xFFFEFFFE;// wtf register - *((volatile u32*)0x10202240) = 0xFF; + *((volatile u32*)0x10202240) = brightness; *((volatile u32*)0x10202244) = 0x1023E; - *((volatile u32*)0x10202A40) = 0xFF; + *((volatile u32*)0x10202A40) = brightness; *((volatile u32*)0x10202A44) = 0x1023E; // After hm call cmd 0x00160042 to acquire rights @@ -219,13 +230,13 @@ void regSet() *((volatile u32*)0x1040059C) = 0x00000000; //(122860 log) - *((volatile u32*)0x10400468) = 0x18300000; - *((volatile u32*)0x1040046c) = 0x18300000; - *((volatile u32*)0x10400494) = 0x18300000; - *((volatile u32*)0x10400498) = 0x18300000; + *((volatile u32*)0x10400468) = FB_TOP_LEFT; + *((volatile u32*)0x1040046c) = FB_TOP_LEFT; + *((volatile u32*)0x10400494) = FB_TOP_RIGHT; + *((volatile u32*)0x10400498) = FB_TOP_RIGHT; - *((volatile u32*)0x10400568) = 0x18300000 + 0x46500; - *((volatile u32*)0x1040056c) = 0x18300000 + 0x46500; + *((volatile u32*)0x10400568) = FB_BOTTOM; + *((volatile u32*)0x1040056c) = FB_BOTTOM; *((volatile u32*)0x10400478) = 0x00000001; *((volatile u32*)0x10400578) = 0x00000001;