printk.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // Created by longjin on 2022/1/21.
  3. //
  4. #pragma once
  5. #define PAD_ZERO 1 // 0填充
  6. #define LEFT 2 // 靠左对齐
  7. #define RIGHT 4 // 靠右对齐
  8. #define PLUS 8 // 在正数前面显示加号
  9. #define SPACE 16
  10. #define SPECIAL 32 // 在八进制数前面显示 '0o',在十六进制数前面显示 '0x' 或 '0X'
  11. #define SMALL 64 // 十进制以上数字显示小写字母
  12. #define SIGN 128 // 显示符号位
  13. #define is_digit(c) ((c) >= '0' && (c) <= '9') // 用来判断是否是数字的宏
  14. // 字体颜色的宏定义
  15. #define WHITE 0x00ffffff //白
  16. #define BLACK 0x00000000 //黑
  17. #define RED 0x00ff0000 //红
  18. #define ORANGE 0x00ff8000 //橙
  19. #define YELLOW 0x00ffff00 //黄
  20. #define GREEN 0x0000ff00 //绿
  21. #define BLUE 0x000000ff //蓝
  22. #define INDIGO 0x0000ffff //靛
  23. #define PURPLE 0x008000ff //紫
  24. // 异常的宏定义
  25. #define EPOS_OVERFLOW 1 // 坐标溢出
  26. #define EFB_MISMATCH 2 // 帧缓冲区与指定的屏幕大小不匹配
  27. #define EUNSUPPORTED 3 // 当前操作暂不被支持
  28. #include "font.h"
  29. #include "glib.h"
  30. //#include "linkage.h"
  31. #include <stdarg.h>
  32. struct printk_screen_info
  33. {
  34. int width, height; //屏幕大小
  35. int max_x, max_y; // 最大x、y字符数
  36. int x, y; //光标位置
  37. int char_size_x, char_size_y;
  38. uint *FB_address; //帧缓冲区首地址
  39. unsigned long FB_length; // 帧缓冲区长度(乘以4才是字节数)
  40. };
  41. extern unsigned char font_ascii[256][16]; //导出ascii字体的bitmap(8*16大小) ps:位于font.h中
  42. /**
  43. * @brief 初始化printk的屏幕信息
  44. *
  45. * @param char_size_x 字符的列坐标
  46. * @param char_size_y 字符的行坐标
  47. */
  48. int printk_init(const int char_size_x, const int char_size_y);
  49. /**
  50. * @brief Set the printk pos object
  51. *
  52. * @param x 列坐标
  53. * @param y 行坐标
  54. */
  55. int set_printk_pos(const int x, const int y);
  56. /**
  57. * @brief 将字符串按照fmt和args中的内容进行格式化,然后保存到buf中
  58. *
  59. * @param buf 结果缓冲区
  60. * @param fmt 格式化字符串
  61. * @param args 内容
  62. * @return 最终字符串的长度
  63. */
  64. static int vsprintf(char *buf, const char *fmt, va_list args);
  65. /**
  66. * @brief 将数字按照指定的要求转换成对应的字符串(2~36进制)
  67. *
  68. * @param str 要返回的字符串
  69. * @param num 要打印的数值
  70. * @param base 基数
  71. * @param field_width 区域宽度
  72. * @param precision 精度
  73. * @param flags 标志位
  74. */
  75. static char *write_num(char *str,ul num, int base, int field_width, int precision, int flags);
  76. static char *write_float_point_num(char *str, double num, int field_width, int precision, int flags);
  77. /**
  78. * @brief 在屏幕上指定位置打印字符
  79. *
  80. * @param fb 帧缓存线性地址
  81. * @param Xsize 行分辨率
  82. * @param x 左上角列像素点位置
  83. * @param y 左上角行像素点位置
  84. * @param FRcolor 字体颜色
  85. * @param BKcolor 背景颜色
  86. * @param font 字符的bitmap
  87. */
  88. static void putchar(uint *fb, int Xsize, int x, int y, unsigned int FRcolor, unsigned int BKcolor, unsigned char font);
  89. /**
  90. * @brief 格式化打印字符串
  91. *
  92. * @param FRcolor 前景色
  93. * @param BKcolor 背景色
  94. * @param ... 格式化字符串
  95. */
  96. #define printk(...) printk_color(WHITE, BLACK, __VA_ARGS__)
  97. int printk_color(unsigned int FRcolor, unsigned int BKcolor, const char *fmt, ...);
  98. /**
  99. * @brief 滚动窗口(尚不支持向下滚动)
  100. *
  101. * @param direction 方向,向上滑动为true,否则为false
  102. * @param pixels 要滑动的像素数量
  103. * @param animation 是否包含滑动动画
  104. */
  105. int scroll(bool direction, int pixels, bool animation);
  106. /**
  107. * @brief 清屏
  108. *
  109. */
  110. int cls();
  111. /**
  112. * @brief 获取VBE帧缓冲区长度
  113. */
  114. ul get_VBE_FB_length();
  115. /**
  116. * @brief 设置pos变量中的VBE帧缓存区的线性地址
  117. * @param virt_addr VBE帧缓存区线性地址
  118. */
  119. void set_pos_VBE_FB_addr(uint* virt_addr);
  120. uint* get_pos_VBE_FB_addr();
  121. /**
  122. * @brief 使能滚动动画
  123. *
  124. */
  125. void printk_enable_animation();
  126. /**
  127. * @brief 禁用滚动动画
  128. *
  129. */
  130. void printk_disable_animation();
  131. /**
  132. * @brief 格式化字符串并输出到buf
  133. *
  134. * @param buf 输出缓冲区
  135. * @param fmt 格式
  136. * @param ... 参数
  137. * @return int 字符串长度
  138. */
  139. int sprintk(char *buf, const char *fmt, ...);