drivers: add flanterm
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
baf8c4c7e5
commit
0592f4d746
15 changed files with 4477 additions and 3 deletions
60
drivers/term/fbcon.c
Normal file
60
drivers/term/fbcon.c
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/common.h>
|
||||
#include <kernel/requests.h>
|
||||
#include <kernel/mem.h>
|
||||
#include <kernel/page.h>
|
||||
#include <kernel/tty.h>
|
||||
#include <lib/stdio.h>
|
||||
|
||||
#include "flanterm.h"
|
||||
#include "fb.h"
|
||||
|
||||
static struct flanterm_context *ft_ctx;
|
||||
|
||||
static void fbcon_putchar(struct tty *tty, char c)
|
||||
{
|
||||
flanterm_write(ft_ctx, &c, 1);
|
||||
|
||||
if (c == '\n') {
|
||||
c = '\r';
|
||||
flanterm_write(ft_ctx, &c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static char fbcon_getchar(struct tty *tty)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct tty_serial_ops fbcon_serial_ops = {
|
||||
.serial_putchar = fbcon_putchar,
|
||||
.serial_getchar = fbcon_getchar,
|
||||
};
|
||||
|
||||
void fbcon_init(void)
|
||||
{
|
||||
if (!fb_res || !fb_res->framebuffer_count)
|
||||
return;
|
||||
|
||||
struct limine_framebuffer *fb = fb_res->framebuffers[0];
|
||||
size_t fb_size = fb->pitch * fb->height;
|
||||
void *fb_virt = map_mmio_dev((paddr_t)TO_PHYS(fb->address), fb_size);
|
||||
|
||||
if (!fb_virt)
|
||||
return;
|
||||
|
||||
ft_ctx = flanterm_fb_init(
|
||||
NULL, NULL, fb_virt, fb->width, fb->height, fb->pitch, fb->red_mask_size, fb->red_mask_shift, fb->green_mask_size,
|
||||
fb->green_mask_shift, fb->blue_mask_size, fb->blue_mask_shift, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0,
|
||||
0, 0, 0, 0, FLANTERM_FB_ROTATE_0);
|
||||
|
||||
if (!ft_ctx)
|
||||
return;
|
||||
|
||||
struct tty *fbtty = tty_create("tty1", NULL);
|
||||
|
||||
fbtty->serial_ops = fbcon_serial_ops;
|
||||
tty_printf = fbtty;
|
||||
|
||||
kinfo("fbcon: framebuffer console initialized (%lux%lu)\n", fb->width, fb->height);
|
||||
}
|
||||
Loading…
Reference in a new issue