xref: /DragonOS/kernel/src/common/printk.h (revision dd9f1fc1a42406461e6f0d38cce1e56e22a1a15f)
1 //
2 // Created by longjin on 2022/1/21.
3 //
4 #pragma once
5 #pragma GCC push_options
6 #pragma GCC optimize("O0")
7 #define PAD_ZERO 1 // 0填充
8 #define LEFT 2     // 靠左对齐
9 #define RIGHT 4    // 靠右对齐
10 #define PLUS 8     // 在正数前面显示加号
11 #define SPACE 16
12 #define SPECIAL 32 // 在八进制数前面显示 '0o',在十六进制数前面显示 '0x' 或 '0X'
13 #define SMALL 64   // 十进制以上数字显示小写字母
14 #define SIGN 128   // 显示符号位
15 
16 #define is_digit(c) ((c) >= '0' && (c) <= '9') // 用来判断是否是数字的宏
17 
18 // 字体颜色的宏定义
19 #define WHITE 0x00ffffff  //白
20 #define BLACK 0x00000000  //黑
21 #define RED 0x00ff0000    //红
22 #define ORANGE 0x00ff8000 //橙
23 #define YELLOW 0x00ffff00 //黄
24 #define GREEN 0x0000ff00  //绿
25 #define BLUE 0x000000ff   //蓝
26 #define INDIGO 0x0000ffff //靛
27 #define PURPLE 0x008000ff //紫
28 
29 // 异常的宏定义
30 #define EPOS_OVERFLOW 1 // 坐标溢出
31 #define EFB_MISMATCH 2  // 帧缓冲区与指定的屏幕大小不匹配
32 #define EUNSUPPORTED 3  // 当前操作暂不被支持
33 
34 #include "font.h"
35 #include "glib.h"
36 #include <libs/libUI/screen_manager.h>
37 #include <stdarg.h>
38 
39 extern unsigned char font_ascii[256][16]; //导出ascii字体的bitmap(8*16大小) ps:位于font.h
40 
41 
42 /**
43  * @brief 将字符串按照fmt和args中的内容进行格式化,然后保存到buf中
44  *
45  * @param buf 结果缓冲区
46  * @param fmt 格式化字符串
47  * @param args 内容
48  * @return 最终字符串的长度
49  */
50 int vsprintf(char *buf, const char *fmt, va_list args);
51 
52 /**
53  * @brief 将字符串按照fmt和args中的内容进行格式化,截取字符串前buf_size-1,保存到buf中
54  *
55  * @param buf 结果缓冲区,大小为buf_size
56  * @param fmt 格式化字符串
57  * @param buf_size 缓冲区长度
58  * @param args 内容
59  * @return 最终字符串的长度
60  */
61 int vsnprintf(char *buf, const char *fmt, int buf_size, va_list args);
62 
63 /**
64  * @brief 格式化打印字符串
65  *
66  * @param FRcolor 前景色
67  * @param BKcolor 背景色
68  * @param ... 格式化字符串
69  */
70 
71 #define printk(...) printk_color(WHITE, BLACK, __VA_ARGS__)
72 
73 int printk_color(unsigned int FRcolor, unsigned int BKcolor, const char *fmt, ...);
74 
75 /**
76  * @brief 格式化字符串并输出到buf
77  *
78  * @param buf 输出缓冲区
79  * @param fmt 格式
80  * @param ... 参数
81  * @return int 字符串长度
82  */
83 int sprintk(char *buf, const char *fmt, ...);
84 #pragma GCC pop_options