kernel-dev/include/kernel/tty.h

167 lines
3.5 KiB
C
Raw Permalink Normal View History

#ifndef TTY_H
#define TTY_H
#include <types.h>
2023-12-13 02:24:25 +08:00
#include <kernel/memm.h>
typedef enum __tty_type
{
2024-01-23 04:42:58 +08:00
tty_type_invalid = 0,
// 用于在内核刚刚被引导只有bootloader提供的显示功能时使用
tty_type_raw_framebuffer = 1,
// 用于图形功能初始化后,直接连接图形接口
tty_type_display = 2,
// 用于图形终端的终端模拟器
2024-01-22 00:48:56 +08:00
tty_type_vterm = 3,
} tty_type;
typedef enum __framebuffer_pixel_type
{
rgb,
bgr,
} framebuffer_pixel_type;
// 在不同的tty类型下提供相应的使用显示功能的信息
typedef union __tty_typeinfo
{
struct __framebuffer
{
void *pointer;
usize width, height;
framebuffer_pixel_type pixtype;
u8 pixsize;
} raw_framebuffer;
} tty_typeinfo;
typedef struct __framebuffer framebuffer;
// tty模式
// 分为文本模式和图形模式
// 文本模式中的字符由tty模块渲染
typedef enum __tty_mode
{
2024-01-23 04:42:58 +08:00
tty_mode_invalid = 0,
tty_mode_text = 1,
tty_mode_graphics = 2,
} tty_mode;
typedef struct __tty_text_state
{
usize line, column;
usize width, height;
volatile u8 lock;
} tty_text_state;
// tty对象
typedef struct __tty
{
usize id;
2024-01-23 04:42:58 +08:00
usize width, height;
tty_type type;
tty_typeinfo typeinfo;
tty_mode mode;
2024-01-22 00:48:56 +08:00
bool enabled;
tty_text_state text;
} tty;
// tty控制器
2023-12-13 02:24:25 +08:00
typedef struct __tty_controller_t
{
#define TTY_MAX_NUM 128
tty *ttys[TTY_MAX_NUM];
bool map[TTY_MAX_NUM];
2024-01-22 00:48:56 +08:00
tty *enabled[TTY_MAX_NUM];
2023-12-13 02:24:25 +08:00
} tty_controller_t;
/**
* @brief tty控制器
*
*/
2023-12-13 02:24:25 +08:00
tty_controller_t *tty_controller_new();
/**
* @brief tty
*
* @param __tty nullptr使kmalloc申请内存
* @param type
* @return tty* tty对象的地址tty数量超过TTY_MAX_NUM返回nullptr
* __tty是否是nullptr
*/
2023-12-13 02:24:25 +08:00
tty *tty_new(tty_type type, tty_mode mode);
/**
* @brief tty id获取一个tty
*
* @param id
* @return tty** 便tty是否删除tty
*/
tty **tty_get(usize id);
/**
* @brief tty的id
2024-03-05 23:34:02 +08:00
*
* @return usize
*/
usize tty_get_id(tty *__tty);
/**
* @brief type为raw_framebuffer时设置帧缓冲区
*
* @param ttyx
* @param fb
*/
void tty_set_framebuffer(tty *ttyx, framebuffer *fb);
/**
* @brief mode为text时打印ascii文字
*
* @param ttyx
* @param string
*/
void tty_text_print(tty *ttyx, char *string, u32 color, u32 bgcolor);
2024-01-14 21:48:15 +08:00
#define gen_color(r, g, b) (((r) << 16) | ((g) << 8) | (b))
2024-03-05 23:34:02 +08:00
#define WHITE gen_color(0xee, 0xee, 0xee)
#define BLACK gen_color(0, 0, 0)
#define RED gen_color(0xee, 0x22, 0x22)
#define GREEN gen_color(0x22, 0xee, 0x22)
#define BLUE gen_color(0x22, 0x22, 0xee)
#define YELLOW gen_color(0xee, 0xee, 0x22)
#define ORANGE gen_color(0xee, 0xaa, 0x22)
#define PURPLE gen_color(0xee, 0, 0xee)
#define PINK gen_color(0xee, 0x44, 0x66)
#define GRAY gen_color(0xaa, 0xaa, 0xaa)
2024-01-23 04:42:58 +08:00
usize tty_get_width(tty *ttyx);
usize tty_get_height(tty *ttyx);
tty_type tty_get_type(tty *ttyx);
tty_mode tty_get_mode(tty *ttyx);
bool tty_is_enabled(tty *ttyx);
2024-01-22 00:48:56 +08:00
/**
* @brief tty
2024-03-05 23:34:02 +08:00
*
* @param ttyx
2024-01-22 00:48:56 +08:00
* @return true
* @return false
* raw_framebuffer类型的ttyframebuffer已被其它raw_framebuffer
* tty占用
*/
bool tty_enable(tty *ttyx);
void tty_disable(tty *ttyx);
#define TTY_FONT_SCALE 2
2024-01-14 21:48:15 +08:00
typedef struct __tty_font_t
{
2024-04-15 20:41:16 +08:00
bool initialized;
2024-01-14 21:48:15 +08:00
u16 char_width, char_height;
u64 **font;
} tty_font_t;
tty_font_t *tty_get_font();
#endif