mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-04-22 04:24:48 +00:00
fusee-primary: deduplicate display initialization code
This commit is contained in:
parent
1eded071c3
commit
d29baa337e
4 changed files with 44 additions and 45 deletions
|
@ -17,6 +17,7 @@
|
|||
#include "log.h"
|
||||
|
||||
#include "../display/video_fb.h"
|
||||
#include "../di.h"
|
||||
#include "../uart.h"
|
||||
#include "vsprintf.h"
|
||||
|
||||
|
@ -31,6 +32,40 @@ ScreenLogLevel log_get_log_level() {
|
|||
return g_screen_log_level;
|
||||
}
|
||||
|
||||
static uint32_t g_framebuffer[1280*768] __attribute__((section(".framebuffer"))) = {0};
|
||||
static int g_log_display_reference_count = 0;
|
||||
|
||||
void log_setup_display() {
|
||||
if (g_log_display_reference_count++ == 0) {
|
||||
/* Zero-fill the framebuffer and register it as printk provider. */
|
||||
video_init(g_framebuffer);
|
||||
|
||||
/* Initialize the display. */
|
||||
display_init();
|
||||
|
||||
/* Set the framebuffer. */
|
||||
display_init_framebuffer(g_framebuffer);
|
||||
|
||||
/* Turn on the backlight after initializing the lfb */
|
||||
/* to avoid flickering. */
|
||||
display_backlight(true);
|
||||
}
|
||||
}
|
||||
|
||||
void log_cleanup_display() {
|
||||
if (--g_log_display_reference_count == 0) {
|
||||
/* Turn off the backlight. */
|
||||
display_backlight(false);
|
||||
|
||||
/* Terminate the display. */
|
||||
display_end();
|
||||
}
|
||||
}
|
||||
|
||||
void *log_get_display_framebuffer() {
|
||||
return g_framebuffer;
|
||||
}
|
||||
|
||||
void log_to_uart(const char *message) {
|
||||
uart_send(UART_B, message, strlen(message));
|
||||
}
|
||||
|
|
|
@ -36,6 +36,10 @@ extern ScreenLogLevel g_screen_log_level;
|
|||
|
||||
void log_set_log_level(ScreenLogLevel screen_log_level);
|
||||
ScreenLogLevel log_get_log_level();
|
||||
void log_setup_display();
|
||||
void log_cleanup_display();
|
||||
void *log_get_display_framebuffer();
|
||||
|
||||
void vprint(ScreenLogLevel screen_log_level, const char *fmt, va_list args);
|
||||
void print(ScreenLogLevel screen_log_level, const char* fmt, ...);
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "exception_handlers.h"
|
||||
#include "panic.h"
|
||||
#include "hwinit.h"
|
||||
#include "di.h"
|
||||
#include "timers.h"
|
||||
#include "fs_utils.h"
|
||||
#include "stage2.h"
|
||||
|
@ -31,7 +30,6 @@
|
|||
|
||||
extern void (*__program_exit_callback)(int rc);
|
||||
|
||||
static uint32_t g_framebuffer[1280*768] __attribute__((section(".framebuffer"))) = {0};
|
||||
static char g_bct0_buffer[BCTO_MAX_SIZE] __attribute__((section(".dram"))) = {0};
|
||||
|
||||
#define DEFAULT_BCT0 \
|
||||
|
@ -71,29 +69,6 @@ static const char *load_config(void) {
|
|||
return bct0;
|
||||
}
|
||||
|
||||
static void setup_display(void) {
|
||||
/* Zero-fill the framebuffer and register it as printk provider. */
|
||||
video_init(g_framebuffer);
|
||||
|
||||
/* Initialize the display. */
|
||||
display_init();
|
||||
|
||||
/* Set the framebuffer. */
|
||||
display_init_framebuffer(g_framebuffer);
|
||||
|
||||
/* Turn on the backlight after initializing the lfb */
|
||||
/* to avoid flickering. */
|
||||
display_backlight(true);
|
||||
}
|
||||
|
||||
static void cleanup_display(void) {
|
||||
/* Turn off the backlight. */
|
||||
display_backlight(false);
|
||||
|
||||
/* Terminate the display. */
|
||||
display_end();
|
||||
}
|
||||
|
||||
static void setup_env(void) {
|
||||
/* Initialize hardware. */
|
||||
nx_hwinit();
|
||||
|
@ -140,12 +115,12 @@ int main(void) {
|
|||
|
||||
if (bct0.log_level != SCREEN_LOG_LEVEL_NONE) {
|
||||
/* Initialize the display for debugging. */
|
||||
setup_display();
|
||||
log_setup_display();
|
||||
}
|
||||
|
||||
/* Say hello. */
|
||||
print(SCREEN_LOG_LEVEL_DEBUG | SCREEN_LOG_LEVEL_NO_PREFIX, "Welcome to Atmosph\xe8re Fus\xe9" "e!\n");
|
||||
print(SCREEN_LOG_LEVEL_DEBUG, "Using color linear framebuffer at 0x%p!\n", g_framebuffer);
|
||||
print(SCREEN_LOG_LEVEL_DEBUG, "Using color linear framebuffer at 0x%p!\n", log_get_display_framebuffer());
|
||||
|
||||
/* Run the MTC binary. */
|
||||
if (!stage2_run_mtc(&bct0)) {
|
||||
|
@ -174,7 +149,7 @@ int main(void) {
|
|||
mdelay(1000);
|
||||
|
||||
/* Terminate the display for debugging. */
|
||||
cleanup_display();
|
||||
log_cleanup_display();
|
||||
}
|
||||
|
||||
/* Finally, after the cleanup routines (__libc_fini_array, etc.) are called, jump to Stage2. */
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
#include "utils.h"
|
||||
#include "di.h"
|
||||
#include "se.h"
|
||||
#include "fuse.h"
|
||||
#include "pmc.h"
|
||||
|
@ -27,7 +26,6 @@
|
|||
#include "btn.h"
|
||||
#include "lib/log.h"
|
||||
#include "lib/vsprintf.h"
|
||||
#include "display/video_fb.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
|
@ -99,22 +97,9 @@ __attribute__ ((noreturn)) void generic_panic(void) {
|
|||
}
|
||||
|
||||
__attribute__((noreturn)) void fatal_error(const char *fmt, ...) {
|
||||
/* Forcefully initialize the screen if logging is disabled. */
|
||||
if (log_get_log_level() == SCREEN_LOG_LEVEL_NONE) {
|
||||
/* Zero-fill the framebuffer and register it as printk provider. */
|
||||
video_init((void *)0xC0000000);
|
||||
/* Forcefully initialize the screen if not already initialized. */
|
||||
log_setup_display();
|
||||
|
||||
/* Initialize the display. */
|
||||
display_init();
|
||||
|
||||
/* Set the framebuffer. */
|
||||
display_init_framebuffer((void *)0xC0000000);
|
||||
|
||||
/* Turn on the backlight after initializing the lfb */
|
||||
/* to avoid flickering. */
|
||||
display_backlight(true);
|
||||
}
|
||||
|
||||
/* Override the global logging level. */
|
||||
log_set_log_level(SCREEN_LOG_LEVEL_ERROR);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue