2023-12-03 17:08:00 +08:00
|
|
|
|
#ifndef TTY_H
|
|
|
|
|
#define TTY_H
|
|
|
|
|
|
|
|
|
|
#include <types.h>
|
2023-12-13 02:24:25 +08:00
|
|
|
|
#include <kernel/memm.h>
|
2023-12-03 17:08:00 +08:00
|
|
|
|
|
|
|
|
|
typedef enum __tty_type
|
|
|
|
|
{
|
2024-01-23 04:42:58 +08:00
|
|
|
|
tty_type_invalid = 0,
|
2023-12-03 17:08:00 +08:00
|
|
|
|
// 用于在内核刚刚被引导,只有bootloader提供的显示功能时使用
|
2024-01-20 23:50:03 +08:00
|
|
|
|
tty_type_raw_framebuffer = 1,
|
2023-12-03 17:08:00 +08:00
|
|
|
|
// 用于图形功能初始化后,直接连接图形接口
|
2024-01-20 23:50:03 +08:00
|
|
|
|
tty_type_display = 2,
|
2023-12-03 17:08:00 +08:00
|
|
|
|
// 用于图形终端的终端模拟器
|
2024-01-22 00:48:56 +08:00
|
|
|
|
tty_type_vterm = 3,
|
2023-12-03 17:08:00 +08:00
|
|
|
|
} 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,
|
2023-12-03 17:08:00 +08:00
|
|
|
|
} 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;
|
2023-12-03 17:08:00 +08:00
|
|
|
|
tty_type type;
|
|
|
|
|
tty_typeinfo typeinfo;
|
|
|
|
|
tty_mode mode;
|
2024-01-22 00:48:56 +08:00
|
|
|
|
bool enabled;
|
2023-12-03 17:08:00 +08:00
|
|
|
|
tty_text_state text;
|
|
|
|
|
} tty;
|
|
|
|
|
|
|
|
|
|
// tty控制器
|
2023-12-13 02:24:25 +08:00
|
|
|
|
typedef struct __tty_controller_t
|
2023-12-03 17:08:00 +08:00
|
|
|
|
{
|
|
|
|
|
#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;
|
2023-12-03 17:08:00 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 初始化tty控制器
|
|
|
|
|
*
|
|
|
|
|
*/
|
2023-12-13 02:24:25 +08:00
|
|
|
|
tty_controller_t *tty_controller_new();
|
2023-12-03 17:08:00 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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);
|
2023-12-03 17:08:00 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief 通过tty id获取一个tty
|
|
|
|
|
*
|
|
|
|
|
* @param id
|
|
|
|
|
* @return tty** 二级指针方便判断这个tty是否删除,返回空指针表示当前没有这个tty
|
|
|
|
|
*/
|
|
|
|
|
tty **tty_get(usize id);
|
|
|
|
|
|
2024-01-20 23:50:03 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief 获取tty的id
|
2024-03-05 23:34:02 +08:00
|
|
|
|
*
|
|
|
|
|
* @return usize
|
2024-01-20 23:50:03 +08:00
|
|
|
|
*/
|
|
|
|
|
usize tty_get_id(tty *__tty);
|
|
|
|
|
|
2023-12-03 17:08:00 +08:00
|
|
|
|
/**
|
|
|
|
|
* @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)
|
2023-12-03 17:08:00 +08:00
|
|
|
|
|
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类型的tty,framebuffer已被其它raw_framebuffer
|
|
|
|
|
* 类型的tty占用
|
|
|
|
|
*/
|
|
|
|
|
bool tty_enable(tty *ttyx);
|
|
|
|
|
void tty_disable(tty *ttyx);
|
|
|
|
|
|
2023-12-03 17:08:00 +08:00
|
|
|
|
#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();
|
2023-12-03 17:08:00 +08:00
|
|
|
|
|
|
|
|
|
#endif
|