feat(os): 添加 uC/OS-II 实时操作系统支持
- 在项目中集成 uC/OS-II 源代码和配置文件 - 修改 CMakeLists.txt 以包含 uC/OS-II 相关路径和源文件 - 更新 main.c 以使用 uC/OS-II 创建任务和管理调度 - 移除原有的裸机程序结构,为使用操作系统做准备
This commit is contained in:
@ -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,
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include "ge_resource.h"
|
||||
|
||||
typedef int ge_render_unit_t;
|
||||
typedef int ge_render_color_t;
|
||||
typedef uint16_t ge_render_color_t;
|
||||
|
||||
typedef struct ge_render_pos2 {
|
||||
ge_render_unit_t x;
|
||||
|
@ -1,115 +0,0 @@
|
||||
// #include "stm32f10x.h"
|
||||
// #include "led.h"
|
||||
// #include "usart.h"
|
||||
// #include "delay.h"
|
||||
// #include "button4_4.h"
|
||||
#define __GE_INPUT_IMPLIMEMT__
|
||||
#include "ge_mem_input.h"
|
||||
struct IO_PORT
|
||||
{
|
||||
GPIO_TypeDef *GPIO_x;
|
||||
unsigned short GPIO_pin;
|
||||
};
|
||||
|
||||
static struct IO_PORT KEY_OUT[4] = {
|
||||
{KEY_H1_GPIO_Port, KEY_H1_Pin},
|
||||
{KEY_H2_GPIO_Port, KEY_H2_Pin},
|
||||
{KEY_H3_GPIO_Port, KEY_H3_Pin},
|
||||
{KEY_H4_GPIO_Port, KEY_H4_Pin}
|
||||
};
|
||||
|
||||
static struct IO_PORT KEY_IN[4] = {
|
||||
{KEY_L1_GPIO_Port, KEY_L1_Pin},
|
||||
{KEY_L2_GPIO_Port, KEY_L2_Pin},
|
||||
{KEY_L3_GPIO_Port, KEY_L3_Pin},
|
||||
{KEY_L4_GPIO_Port, KEY_L4_Pin}
|
||||
};
|
||||
|
||||
int key[4][4];
|
||||
/*
|
||||
void Button4_4_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
unsigned char i;
|
||||
|
||||
RCC_APB2PeriphClockCmd(KEY_GPIO_CLK, ENABLE);
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
GPIO_InitStructure.GPIO_Pin = KEY_OUT[i].GPIO_pin;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
|
||||
GPIO_Init(KEY_OUT[i].GPIO_x, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
GPIO_InitStructure.GPIO_Pin = KEY_IN[i].GPIO_pin;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
|
||||
GPIO_Init(KEY_IN[i].GPIO_x, &GPIO_InitStructure);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
GPIO_SetBits(KEY_OUT[i].GPIO_x, KEY_OUT[i].GPIO_pin);
|
||||
}
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
key[i][0] = 0;
|
||||
key[i][1] = 0;
|
||||
key[i][2] = 0;
|
||||
key[i][3] = 0;
|
||||
}
|
||||
}
|
||||
*/
|
||||
//uint16_t key;
|
||||
|
||||
|
||||
|
||||
int Button4_4_Scan(void) {
|
||||
unsigned char i, j;
|
||||
|
||||
for(i = 0; i < 4; i++) {
|
||||
delay_ms(10);
|
||||
GPIO_ResetBits(KEY_OUT[i].GPIO_x, KEY_OUT[i].GPIO_pin);
|
||||
for(j = 0; j < 4; j++) {
|
||||
|
||||
delay_ms(10);
|
||||
if(GPIO_ReadInputDataBit(KEY_IN[j].GPIO_x, KEY_IN[j].GPIO_pin) == 0){
|
||||
|
||||
key[i][j] = 1;
|
||||
} else {
|
||||
|
||||
key[i][j] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GPIO_SetBits(KEY_OUT[i].GPIO_x, KEY_OUT[i].GPIO_pin);
|
||||
}
|
||||
|
||||
if(key[0][0] == 1) return 16;
|
||||
if(key[0][1] == 1) return 15;
|
||||
if(key[0][2] == 1) return 14;
|
||||
if(key[0][3] == 1) return 13;
|
||||
|
||||
if(key[1][0] == 1) return 12;
|
||||
if(key[1][1] == 1) return 11;
|
||||
if(key[1][2] == 1) return 10;
|
||||
if(key[1][3] == 1) return 9;
|
||||
|
||||
if(key[2][0] == 1) return 8;
|
||||
if(key[2][1] == 1) return 7;
|
||||
if(key[2][2] == 1) return 6;
|
||||
if(key[2][3] == 1) return 5;
|
||||
|
||||
if(key[3][0] == 1) return 4;
|
||||
if(key[3][1] == 1) return 3;
|
||||
if(key[3][2] == 1) return 2;
|
||||
if(key[3][3] == 1) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,30 +0,0 @@
|
||||
#ifndef __BUTTON4_4_H
|
||||
#define __BUTTON4_4_H
|
||||
|
||||
#define KEY_GPIO_CLK RCC_APB2Periph_GPIOC
|
||||
#define KEY_L1_Pin GPIO_Pin_0
|
||||
#define KEY_L1_GPIO_Port GPIOC
|
||||
#define KEY_L2_Pin GPIO_Pin_1
|
||||
#define KEY_L2_GPIO_Port GPIOC
|
||||
#define KEY_L3_Pin GPIO_Pin_2
|
||||
#define KEY_L3_GPIO_Port GPIOC
|
||||
#define KEY_L4_Pin GPIO_Pin_3
|
||||
#define KEY_L4_GPIO_Port GPIOC
|
||||
|
||||
#define KEY_H1_Pin GPIO_Pin_4
|
||||
#define KEY_H1_GPIO_Port GPIOC
|
||||
#define KEY_H2_Pin GPIO_Pin_5
|
||||
#define KEY_H2_GPIO_Port GPIOC
|
||||
#define KEY_H3_Pin GPIO_Pin_6
|
||||
#define KEY_H3_GPIO_Port GPIOC
|
||||
#define KEY_H4_Pin GPIO_Pin_7
|
||||
#define KEY_H4_GPIO_Port GPIOC
|
||||
|
||||
//#define BTN_GET_BIT(num, pos) ( (num) & ( 1 << (pos) ) )
|
||||
//#define BTN_SET_TRUE(num, pos) ( (num) |= ( 1 << (pos) ) )
|
||||
//#define BTN_SET_FALSE(num, pos) ( (num) &= ( ~( 1 << (pos) ) ) )
|
||||
|
||||
void Button4_4_Init(void);
|
||||
int Button4_4_Scan(void);
|
||||
|
||||
#endif
|
@ -1,25 +0,0 @@
|
||||
#ifndef __GE_MEM_INPUT_H__
|
||||
#define __GE_MEM_INPUT_H__
|
||||
|
||||
#include <main.h>
|
||||
#include <gpio.h>
|
||||
#include <stdint.h>
|
||||
#include "../ge_interface.h"
|
||||
int Button4_4_Scan(void);
|
||||
|
||||
#define delay_ms HAL_Delay
|
||||
#define GPIO_ReadInputDataBit HAL_GPIO_ReadPin
|
||||
#define GPIO_SetBits(port, pin) HAL_GPIO_WritePin(port, pin, 1)
|
||||
#define GPIO_ResetBits(port, pin) HAL_GPIO_WritePin(port, pin, 0)
|
||||
#ifdef __GE_INPUT_IMPLIMEMT__
|
||||
|
||||
void mem_input_btn_func(ge_input_t* ctx) {
|
||||
uint16_t code = Button4_4_Scan();
|
||||
ge_input_event_t event;
|
||||
event.num = GE_ITYPE_KEY_L1H1 + code;
|
||||
ctx->func_send(ctx, event);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user