feat(os): 添加 uC/OS-II 实时操作系统支持

- 在项目中集成 uC/OS-II 源代码和配置文件
- 修改 CMakeLists.txt 以包含 uC/OS-II 相关路径和源文件
- 更新 main.c 以使用 uC/OS-II 创建任务和管理调度
- 移除原有的裸机程序结构,为使用操作系统做准备
This commit is contained in:
ZZY
2025-06-30 10:57:53 +08:00
parent d939449267
commit 301e094671
15 changed files with 1193 additions and 258 deletions

View File

@ -185,7 +185,7 @@ static inline void lcd_set_region(int pos_x, int pos_y, int size_x, int size_y)
LCD_WRITE_INDEX(0x2c);
}
static int lcd_draw_point(ge_render_t* ctx, const ge_render_pos2_t* pos, uint16_t color) {
static int lcd_draw_point(ge_render_t* ctx, const ge_render_pos2_t* pos, ge_render_color_t color) {
(void)ctx;
Assert(pos != NULL);
lcd_set_region(pos->x, pos->y, 1, 1);
@ -200,7 +200,8 @@ static int lcd_draw_point(ge_render_t* ctx, const ge_render_pos2_t* pos, uint16_
return 0;
}
static int lcd_draw_rect(ge_render_t* ctx, const ge_render_rect_t* rect, uint16_t color) {
__unused
static int lcd_draw_rect(ge_render_t* ctx, const ge_render_rect_t* rect, ge_render_color_t color) {
(void)ctx;
const int pos_x = rect ? rect->pos.x : 0;
const int pos_y = rect ? rect->pos.y : 0;
@ -230,97 +231,103 @@ static int lcd_draw_rect(ge_render_t* ctx, const ge_render_rect_t* rect, uint16_
#define SCREEN_HEIGHT 128
#define SCREEN_WIDTH 128
#define HEAD_CANARY 0xDEAD
#define TAIL_CANARY 0xBEEF
typedef enum {
GE_RENDER_EVEN_LINES, // 渲染偶数数行
GE_RENDER_ODD_LINES, // 渲染奇数数行
} ge_render_field_t;
static struct ge_content {
typedef struct ge_context {
ge_render_field_t current_field;
uint16_t head_canary;
uint16_t screen_buffer[SCREEN_HEIGHT / 2][SCREEN_WIDTH];
uint16_t tail_canary;
} ge_content;
static ge_render_field_t current_field = GE_RENDER_EVEN_LINES;
} ge_context_t;
#define CTX_BUF(ctx) (((struct ge_content*)ctx->context)->screen_buffer)
#define CTX_BUF_PTR(ctx, x, y) ((uint16_t*)CTX_BUF(ctx) + SCREEN_WIDTH * (y) + (x))
#define HEAD_CANARY 0xDEAD
#define TAIL_CANARY 0xBEEF
static int init(ge_render_t* ctx, const ge_render_pos2_t* init_screen_size) {
static int init(ge_render_t* render, const ge_render_pos2_t* init_screen_size) {
(void)init_screen_size;
init_lcd();
/**
* set canary
*/
((struct ge_content*)ctx->context)->head_canary = HEAD_CANARY;
((struct ge_content*)ctx->context)->tail_canary = TAIL_CANARY;
ge_context_t* ctx = (ge_context_t*) render->context;
ctx->head_canary = HEAD_CANARY;
ctx->tail_canary = TAIL_CANARY;
return 0;
}
static int flush(ge_render_t* ctx) {
AssertFmt(((struct ge_content*)ctx->context)->head_canary == HEAD_CANARY, "Invalid head canary");
AssertFmt(((struct ge_content*)ctx->context)->tail_canary == TAIL_CANARY, "Invalid tail canary");
uint16_t* buffer = ((struct ge_content*)ctx->context)->screen_buffer;
static int flush(ge_render_t* render) {
ge_context_t* ctx = (ge_context_t*) render->context;
AssertFmt(ctx->head_canary == HEAD_CANARY, "Invalid head canary");
AssertFmt(ctx->tail_canary == TAIL_CANARY, "Invalid tail canary");
const ge_render_field_t current_field = ctx->current_field;
const int start_y = (current_field == GE_RENDER_EVEN_LINES) ? 0 : 1;
for (int buffer_y = 0; buffer_y < ctx->screen_size.y / 2; buffer_y++) {
for (int buffer_y = 0; buffer_y < render->screen_size.y / 2; buffer_y++) {
const int screen_y = start_y + buffer_y * 2;
// 设置当前行区域 (1行高)
lcd_set_region(0, screen_y, ctx->screen_size.y, 1);
lcd_set_region(0, screen_y, render->screen_size.y, 1);
GE_FAST_SET_OFF(LCD_CS);
GE_FAST_SET_ON(LCD_DC);
// 传输整行数据
uint16_t* line_ptr = buffer + buffer_y * ctx->screen_size.x;
for (int x = 0; x < ctx->screen_size.x; x++) {
lcd_write_byte(*line_ptr >> 8); // 高字节
lcd_write_byte(*line_ptr & 0xFF); // 低字节
line_ptr++;
for (int x = 0; x < render->screen_size.x; x++) {
const uint16_t data = ctx->screen_buffer[buffer_y][x];
lcd_write_byte(data >> 8); // 高字节
lcd_write_byte(data & 0xFF); // 低字节
}
GE_FAST_SET_ON(LCD_CS);
}
// 切换模式
current_field = (current_field == GE_RENDER_EVEN_LINES) ?
ctx->current_field = (current_field == GE_RENDER_EVEN_LINES) ?
GE_RENDER_ODD_LINES : GE_RENDER_EVEN_LINES;
return 0;
}
static inline int check_need_flush(ge_render_t* ctx, const ge_render_pos2_t* pos) {
static inline int check_need_flush(ge_render_t* render, const ge_render_pos2_t* pos) {
const int isOdd = pos->y % 2;
const int isNeedOdd = (current_field == GE_RENDER_ODD_LINES) ? 1 : 0;
const int isNeedOdd =
(((ge_context_t*) render->context)->current_field == GE_RENDER_ODD_LINES) ? 1 : 0;
return isOdd == isNeedOdd;
}
static inline int should_render_line(int y) {
return (y % 2) == (current_field == GE_RENDER_ODD_LINES);
static inline int should_render_line(ge_render_t* render, int y) {
return (y % 2) == (((ge_context_t*) render->context)->current_field == GE_RENDER_ODD_LINES);
}
static int buf_draw_rect(ge_render_t* ctx, const ge_render_rect_t* rect, uint16_t color) {
Assert(ctx != NULL && rect != NULL);
static int buf_draw_rect(ge_render_t* render, const ge_render_rect_t* rect, ge_render_color_t color) {
Assert(render != NULL && rect != NULL);
// 只更新属于当前场的行
for (int y = rect->pos.y; y < rect->pos.y + rect->size.y; y++) {
if (!should_render_line(y)) {
if (!should_render_line(render, y)) {
continue;
}
for (int x = rect->pos.x; x < rect->pos.x + rect->size.x; x++) {
*CTX_BUF_PTR(ctx, x, y / 2) = color;
((ge_context_t*)render->context)->screen_buffer[y/2][x] = color;
}
}
return 0;
}
static ge_context_t ge_context = {
.current_field = GE_RENDER_EVEN_LINES,
.head_canary = HEAD_CANARY,
.tail_canary = TAIL_CANARY,
};
ge_render_t ge_render = {
.context = &ge_content,
.context = &ge_context,
.screen_size = {
.x = 128,
.y = 128,
.x = SCREEN_WIDTH,
.y = SCREEN_HEIGHT,
},
.init_func = init,