diff --git a/board/apple/board-n61ap.c b/board/apple/board-n61ap.c index 51d9ff1..ccde932 100644 --- a/board/apple/board-n61ap.c +++ b/board/apple/board-n61ap.c @@ -11,21 +11,21 @@ int n61ap_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info n61ap_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int n61ap_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 752, - .height = 1334, - .stride = 4, - .address = (void *)0x83e900000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &n61ap_fb); +#endif return 0; } diff --git a/board/samsung/board-a105f.c b/board/samsung/board-a105f.c index 69b11ee..c283b31 100644 --- a/board/samsung/board-a105f.c +++ b/board/samsung/board-a105f.c @@ -22,21 +22,21 @@ int a105f_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info a105f_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int a105f_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 720, - .height = 1520, - .stride = 4, - .address = (void *)0xec000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &a105f_fb); +#endif return 0; } diff --git a/board/samsung/board-a127f.c b/board/samsung/board-a127f.c index 5f2d3f1..ee8a168 100644 --- a/board/samsung/board-a127f.c +++ b/board/samsung/board-a127f.c @@ -20,21 +20,21 @@ int a127f_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info a127f_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int a127f_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 720, - .height = 1600, - .stride = 4, - .address = (void *)0xfa000000, - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &a127f_fb); +#endif return 0; } diff --git a/board/samsung/board-a336b.c b/board/samsung/board-a336b.c index 35f330a..65d1b0f 100644 --- a/board/samsung/board-a336b.c +++ b/board/samsung/board-a336b.c @@ -22,21 +22,21 @@ int a33x_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info a33x_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int a33x_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1080, - .height = 2400, - .stride = 4, - .address = (void *)0x0fa200000, - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &a33x_fb); +#endif return 0; } diff --git a/board/samsung/board-c1s.c b/board/samsung/board-c1s.c index 34e79c6..00fb5f7 100755 --- a/board/samsung/board-c1s.c +++ b/board/samsung/board-c1s.c @@ -22,21 +22,21 @@ int c1s_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info c1s_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int c1s_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1080, - .height = 2400, - .stride = 4, - .address = (void *)0xf1000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &c1s_fb); +#endif return 0; } diff --git a/board/samsung/board-dreamlte.c b/board/samsung/board-dreamlte.c index 3d52532..6e940f7 100644 --- a/board/samsung/board-dreamlte.c +++ b/board/samsung/board-dreamlte.c @@ -113,21 +113,21 @@ int dreamlte_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info dreamlte_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int dreamlte_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1440, - .height = 2960, - .stride = 4, - .address = (void *)0xcc000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &dreamlte_fb); +#endif return 0; } diff --git a/board/samsung/board-g0s.c b/board/samsung/board-g0s.c index cf67a42..06967e6 100755 --- a/board/samsung/board-g0s.c +++ b/board/samsung/board-g0s.c @@ -82,21 +82,21 @@ int g0s_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info g0s_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int g0s_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1080, - .height = 2340, - .stride = 4, - .address = (void *)0xf6200000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &g0s_fb); +#endif return 0; } diff --git a/board/samsung/board-gta4xl.c b/board/samsung/board-gta4xl.c index 168bac7..f87213b 100644 --- a/board/samsung/board-gta4xl.c +++ b/board/samsung/board-gta4xl.c @@ -24,21 +24,21 @@ int gta4xl_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info gta4xl_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int gta4xl_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1200, - .height = 2000, - .stride = 4, - .address = (void *)0xca000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, >a4xl_fb); +#endif return 0; } diff --git a/board/samsung/board-j4lte.c b/board/samsung/board-j4lte.c index 2e966a4..19d8990 100644 --- a/board/samsung/board-j4lte.c +++ b/board/samsung/board-j4lte.c @@ -24,21 +24,21 @@ int j4lte_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info j4lte_fb = { + .format = FB_FORMAT_BGRA8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int j4lte_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 720, - .height = 1280, - .stride = 4, - .address = (void *)0x67000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &j4lte_fb); +#endif return 0; } diff --git a/board/samsung/board-j5lte.c b/board/samsung/board-j5lte.c index eeb5c73..7d06f67 100644 --- a/board/samsung/board-j5lte.c +++ b/board/samsung/board-j5lte.c @@ -27,21 +27,21 @@ int j5lte_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info j5lte_fb = { + .format = FB_FORMAT_RGB888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int j5lte_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 720, - .height = 1280, - .stride = 3, - .address = (void *)0x8e000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &j5lte_fb); +#endif return 0; } diff --git a/board/samsung/board-jackpotlte.c b/board/samsung/board-jackpotlte.c index db6ad6e..73da814 100644 --- a/board/samsung/board-jackpotlte.c +++ b/board/samsung/board-jackpotlte.c @@ -24,21 +24,21 @@ int jackpotlte_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info jackpotlte_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int jackpotlte_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1080, - .height = 2200, - .stride = 4, - .address = (void *)0xec000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &jackpotlte_fb); +#endif return 0; } diff --git a/board/samsung/board-noblelte.c b/board/samsung/board-noblelte.c index c3a92c6..f95b3cb 100644 --- a/board/samsung/board-noblelte.c +++ b/board/samsung/board-noblelte.c @@ -24,21 +24,21 @@ int noblelte_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info noblelte_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int noblelte_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1440, - .height = 2560, - .stride = 4, - .address = (void *)0xe2a00000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &noblelte_fb); +#endif return 0; } diff --git a/board/samsung/board-r8s.c b/board/samsung/board-r8s.c index 114fe7d..48f4ff4 100644 --- a/board/samsung/board-r8s.c +++ b/board/samsung/board-r8s.c @@ -24,21 +24,21 @@ int r8s_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info r8s_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int r8s_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1080, - .height = 2400, - .stride = 4, - .address = (void *)0xf1000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &r8s_fb); +#endif return 0; } diff --git a/board/samsung/board-starlte.c b/board/samsung/board-starlte.c index 1cf1a0b..51b7d2f 100644 --- a/board/samsung/board-starlte.c +++ b/board/samsung/board-starlte.c @@ -24,21 +24,21 @@ int starlte_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info starlte_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int starlte_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1440, - .height = 2960, - .stride = 4, - .address = (void *)0xcc000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &starlte_fb); +#endif return 0; } diff --git a/board/samsung/board-x1s.c b/board/samsung/board-x1s.c index c8fcac8..8de8518 100644 --- a/board/samsung/board-x1s.c +++ b/board/samsung/board-x1s.c @@ -24,21 +24,21 @@ int x1s_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info x1s_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int x1s_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1440, - .height = 3200, - .stride = 4, - .address = (void *)0xf1000000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &x1s_fb); +#endif return 0; } diff --git a/board/samsung/board-zeroflte.c b/board/samsung/board-zeroflte.c index dbf01f5..1d0fd8d 100644 --- a/board/samsung/board-zeroflte.c +++ b/board/samsung/board-zeroflte.c @@ -24,21 +24,21 @@ int zeroflte_late_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info zeroflte_fb = { + .format = FB_FORMAT_ARGB8888, + .width = CONFIG_FRAMEBUFFER_WIDTH, + .height = CONFIG_FRAMEBUFFER_HEIGHT, + .stride = CONFIG_FRAMEBUFFER_STRIDE, + .address = (void *)CONFIG_FRAMEBUFFER_BASE +}; +#endif + int zeroflte_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1440, - .height = 2560, - .stride = 4, - .address = (void *)0xe2a00000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &zeroflte_fb); +#endif return 0; } diff --git a/board/volla/board-algiz.c b/board/volla/board-algiz.c index 32eae46..a3af0f4 100755 --- a/board/volla/board-algiz.c +++ b/board/volla/board-algiz.c @@ -12,21 +12,21 @@ int algiz_init(void) return 0; } +#ifdef CONFIG_SIMPLE_FB +static struct video_info algiz_fb = { + .format = FB_FORMAT_ARGB8888, + .width = 1080, + .height = 2400, + .stride = 4, + .address = (void *)0x7d010000 +}; +#endif + int algiz_drv(void) { - struct { - int width; - int height; - int stride; - void *address; - } simplefb_data = { - .width = 1080, - .height = 2400, - .stride = 4, - .address = (void *)0x7d010000 - }; - - REGISTER_DRIVER("simplefb", simplefb_probe, &simplefb_data); +#ifdef CONFIG_SIMPLE_FB + REGISTER_DRIVER("simplefb", simplefb_probe, &algiz_fb); +#endif return 0; } diff --git a/include/lib/simplefb.h b/include/lib/simplefb.h index bf00644..784b799 100644 --- a/include/lib/simplefb.h +++ b/include/lib/simplefb.h @@ -10,18 +10,6 @@ #include -extern void __simplefb_raw_print(volatile char *fb, char *text, int text_x, - int text_y, int width, int stride); -extern void simplefb_probe(void *data); -extern struct video *video_info; - -struct video { - int width; - int height; - int stride; - void *address; -}; - typedef struct _color { unsigned char r; unsigned char g; @@ -29,11 +17,27 @@ typedef struct _color { unsigned char a; } color; +typedef enum { + FB_FORMAT_RGB888, + FB_FORMAT_ARGB8888, + FB_FORMAT_BGRA8888, +} video_format; + +struct video_info { + video_format format; + int width; + int height; + int stride; + void *address; +}; + +extern void __simplefb_raw_print(volatile char *fb, const char *text, int text_x, + int text_y, color text_color); +extern void simplefb_probe(void *data); + typedef struct _font_params { int width; int height; } font_params; -font_params get_font_params(void); - #endif // SIMPLEFB_H_ diff --git a/lib/debug/debug.c b/lib/debug/debug.c index 714983c..1a158dd 100644 --- a/lib/debug/debug.c +++ b/lib/debug/debug.c @@ -19,75 +19,80 @@ #define NANOPRINTF_USE_BINARY_FORMAT_SPECIFIERS 1 #define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 1 #define NANOPRINTF_USE_ALT_FORM_FLAG 1 - #include #define PRINTK_BUFFER_SIZE 256 long int debug_linecount = 0; +extern void uart_puts(const char *s); -void uart_puts(const char *s); +typedef struct { + const char *prefix; + color text_color; +} log_style_t; -// Global log level that controls the verbosity -static int global_loglevel = CONFIG_LOGLEVEL; +static const color red = {255, 0, 0, 255}; +static const color orange = {255, 165, 0, 255}; +static const color yellow = {255, 255, 0, 255}; +static const color cyan = {0, 255, 255, 255}; +static const color green = {0, 255, 0, 255}; +static const color gray = {128, 128, 128, 255}; +static const color amber = {255, 192, 0, 255}; + +static inline log_style_t get_log_style(int level) +{ + static const log_style_t styles[] = { + [KERN_EMERG] = {"[EMERG] ", red}, + [KERN_ALERT] = {"[ALERT] ", orange}, + [KERN_CRIT] = {"[CRIT] ", yellow}, + [KERN_ERR] = {"[ERROR] ", red}, + [KERN_WARNING] = {"[WARN] ", yellow}, + [KERN_NOTICE] = {"[NOTICE] ", green}, + [KERN_INFO] = {"[INFO] ", amber}, + [KERN_DEBUG] = {"[DEBUG] ", gray} + }; + + return (level >= 0 && level < sizeof(styles)/sizeof(styles[0])) ? + styles[level] : (log_style_t){"[UNKNOWN] ", {255, 255, 255, 255}}; +} + +static inline void uart_output(const char *prefix, const char *message) +{ +#ifdef CONFIG_UART_DEBUG + uart_puts(prefix); + uart_puts(message); + uart_puts("\r"); +#endif +} + +static inline void fb_output(const char *prefix, const char *message, color text_color) +{ +#ifdef CONFIG_SIMPLE_FB + const int y_pos = 5; + const int prefix_width = strlen(prefix) * SCALED_FONTW; + + __simplefb_raw_print((char*)CONFIG_FRAMEBUFFER_BASE, prefix, 0, y_pos, text_color); + __simplefb_raw_print((char*)CONFIG_FRAMEBUFFER_BASE, message, prefix_width, y_pos, gray); +#endif +} void printk(int log_level, const char *fmt, ...) { - static char print_buffer[PRINTK_BUFFER_SIZE]; +#if !defined(CONFIG_UART_DEBUG) && !defined(CONFIG_SIMPLE_FB) + return; +#endif + + if (log_level > CONFIG_LOGLEVEL) return; + va_list args; + static char print_buffer[PRINTK_BUFFER_SIZE]; - if (log_level > global_loglevel) - return; - - char *prefix; - switch (log_level) { - case KERN_EMERG: - prefix = "[EMERG] "; - break; - case KERN_ALERT: - prefix = "[ALERT] "; - break; - case KERN_CRIT: - prefix = "[CRIT] "; - break; - case KERN_ERR: - prefix = "[ERROR] "; - break; - case KERN_WARNING: - prefix = "[WARN] "; - break; - case KERN_NOTICE: - prefix = "[NOTICE] "; - break; - case KERN_INFO: - prefix = "[INFO] "; - break; - case KERN_DEBUG: - prefix = "[DEBUG] "; - break; - default: - prefix = "[LOG] "; - break; - } + const log_style_t style = get_log_style(log_level); va_start(args, fmt); npf_vsnprintf(print_buffer, sizeof(print_buffer), fmt, args); va_end(args); -#ifdef CONFIG_UART_DEBUG - uart_puts(prefix); - uart_puts(print_buffer); - uart_puts("\r"); -#endif - -#ifdef CONFIG_SIMPLE_FB - // Actually the first line's Y pos. Scales in __simplefb_raw_print - int y_pos = 5; - int prefix_width = strlen(prefix) * SCALED_FONTW; - - __simplefb_raw_print((char*)CONFIG_FRAMEBUFFER_BASE, prefix, 0, y_pos, - CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE); - __simplefb_raw_print((char*)CONFIG_FRAMEBUFFER_BASE, print_buffer, prefix_width, y_pos, - CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE); -#endif + uart_output(style.prefix, print_buffer); + fb_output(style.prefix, print_buffer, style.text_color); } diff --git a/lib/simplefb/simplefb.c b/lib/simplefb/simplefb.c index b3f0ea4..397fe3f 100644 --- a/lib/simplefb/simplefb.c +++ b/lib/simplefb/simplefb.c @@ -10,42 +10,58 @@ #include #include +struct video_info *fb_info; + static void clean_fbmem(void *fb, int width, int height, int stride) { memset(fb, 0x0, (width * height * stride)); } -// RGB888 format -/* - * Unlike ARGB8888, we explicitly use 3 bytes to represent each pixel, making sure - * no extra padding byte is added. - */ static void draw_pixel(volatile char *fb, int x, int y, int width, int stride, color c) { + // Check bounds to prevent drawing outside the framebuffer + if (x < 0 || x >= width || y < 0 || y >= fb_info->height) + return; + long int location = (x * stride) + (y * width * stride); -#ifdef CONFIG_FRAMEBUFFER_BGRA - *(fb + location) = c.b; - *(fb + location + 2) = c.r; -#else - *(fb + location) = c.r; - *(fb + location + 2) = c.b; -#endif - *(fb + location + 1) = c.g; -#if CONFIG_FRAMEBUFFER_STRIDE == 4 - *(fb + location + 3) = c.a; -#endif + switch (fb_info->format) { + case FB_FORMAT_ARGB8888: + *(fb + location) = c.b; + *(fb + location + 1) = c.g; + *(fb + location + 2) = c.r; + *(fb + location + 3) = c.a; + break; + case FB_FORMAT_BGRA8888: + *(fb + location) = c.r; + *(fb + location + 1) = c.g; + *(fb + location + 2) = c.b; + *(fb + location + 3) = c.a; + break; + case FB_FORMAT_RGB888: + *(fb + location) = c.b; + *(fb + location + 1) = c.g; + *(fb + location + 2) = c.r; + break; + } } -static int current_y = 0; -void __simplefb_raw_print(volatile char *fb, char *text, int text_x, int text_y, - int width, int stride) +void __simplefb_raw_print(volatile char *fb, const char *text, int text_x, int text_y, + color text_color) { int l = strlen(text); int current_x = text_x; - current_y = current_y == 0 ? text_y : current_y; + int current_y = text_y; - int max_x = width - SCALED_FONTW; + static int last_y = 0; + if (last_y == 0) { + last_y = text_y; + } else { + current_y = last_y; + } + + + int max_x = fb_info->width - SCALED_FONTW; for (int i = 0; i < l; i++) { // Special characters handling @@ -54,6 +70,9 @@ void __simplefb_raw_print(volatile char *fb, char *text, int text_x, int text_y, current_x = text_x; current_y += SCALED_FONTH; break; + case '\r': + current_x = text_x; + break; } // Non-printable chars @@ -65,6 +84,12 @@ void __simplefb_raw_print(volatile char *fb, char *text, int text_x, int text_y, current_y += SCALED_FONTH; } + if (current_y >= fb_info->height - SCALED_FONTH) { + clean_fbmem((char*)fb_info->address, fb_info->width, fb_info->height, fb_info->stride); + current_x = text_x; + current_y = 5; + } + int ix = font_index(text[i]); unsigned char *img = letters[ix]; @@ -78,7 +103,7 @@ void __simplefb_raw_print(volatile char *fb, char *text, int text_x, int text_y, for (int dx = 0; dx < SCALE_FACTOR; dx++) { draw_pixel(fb, current_x + x * SCALE_FACTOR + dx, current_y + y * SCALE_FACTOR + dy, - width, stride, (color){255, 255, 255}); + fb_info->width, fb_info->stride, text_color); } } } @@ -86,14 +111,13 @@ void __simplefb_raw_print(volatile char *fb, char *text, int text_x, int text_y, } current_x += SCALED_FONTW; } + last_y = current_y; } void simplefb_probe(void *data) { - struct video *fb_info = data; + fb_info = data; clean_fbmem((char*)fb_info->address, fb_info->width, fb_info->height, fb_info->stride); - - /* TODO: Introduce a full drivers framework that allows proper exiting */ }