feat(school_stm32): 添加基础的 STM32F103RCT6 项目结构
- 创建了项目的基本目录结构和文件 - 添加了 CMakeLists.txt 和 Makefile 构建配置 - 创建了 main.c 文件,实现了简单的 LED 闪烁和按键检测功能 - 集成了 SEGGER RTT 库 - 添加了 .gitignore 文件,排除了不必要的生成文件
This commit is contained in:
88
libs/ge_interface/ge_input.c
Normal file
88
libs/ge_interface/ge_input.c
Normal file
@ -0,0 +1,88 @@
|
||||
#include <main.h>
|
||||
#include "ge_interface.h"
|
||||
#include "include/ge_kfifo.h"
|
||||
|
||||
#define SCAN_BTN(lnum, hnum) do { \
|
||||
/*GE_SET_OFF(KEY_L ## hnum);*/ \
|
||||
if (GE_IS_BIN_PRESSD(H ## hnum)) \
|
||||
event.num = GE_ITYPE_KEY_L ## lnum ## H ## hnum, \
|
||||
ctx->func_send(ctx, event); \
|
||||
} while(0)
|
||||
|
||||
void input_btn_func(ge_input_t* ctx) {
|
||||
ge_input_event_t event;
|
||||
|
||||
if (GE_IS_BIN_PRESSD(1)) event.num = GE_ITYPE_KEY_1, ctx->func_send(ctx, event);
|
||||
if (GE_IS_BIN_PRESSD(2)) event.num = GE_ITYPE_KEY_2, ctx->func_send(ctx, event);
|
||||
if (GE_IS_BIN_PRESSD(3)) event.num = GE_ITYPE_KEY_3, ctx->func_send(ctx, event);
|
||||
if (GE_IS_BIN_PRESSD(4)) event.num = GE_ITYPE_KEY_4, ctx->func_send(ctx, event);
|
||||
|
||||
GE_SET_OFF(KEY_L1);
|
||||
SCAN_BTN(1, 1);
|
||||
SCAN_BTN(1, 2);
|
||||
SCAN_BTN(1, 3);
|
||||
SCAN_BTN(1, 4);
|
||||
HAL_Delay(10);
|
||||
GE_SET_ON(KEY_L1);
|
||||
|
||||
GE_SET_OFF(KEY_L2);
|
||||
SCAN_BTN(2, 1);
|
||||
SCAN_BTN(2, 2);
|
||||
SCAN_BTN(2, 3);
|
||||
SCAN_BTN(2, 4);
|
||||
HAL_Delay(10);
|
||||
GE_SET_ON(KEY_L2);
|
||||
|
||||
GE_SET_OFF(KEY_L3);
|
||||
SCAN_BTN(3, 1);
|
||||
SCAN_BTN(3, 2);
|
||||
SCAN_BTN(3, 3);
|
||||
SCAN_BTN(3, 4);
|
||||
HAL_Delay(10);
|
||||
GE_SET_ON(KEY_L3);
|
||||
|
||||
GE_SET_OFF(KEY_L4);
|
||||
SCAN_BTN(4, 1);
|
||||
SCAN_BTN(4, 2);
|
||||
SCAN_BTN(4, 3);
|
||||
SCAN_BTN(4, 4);
|
||||
HAL_Delay(10);
|
||||
GE_SET_ON(KEY_L4);
|
||||
}
|
||||
|
||||
DECLARE_GE_KFIFO(ge_input_fifo, ge_input_event_t, 16, ge_input_fifo_t);
|
||||
|
||||
int ge_input_send (ge_input_t* ctx, ge_input_event_t event) {
|
||||
struct ge_input_fifo_t* fifo = (struct ge_input_fifo_t*)ctx->context;
|
||||
if (ge_kfifo_is_full(fifo)) {
|
||||
return -1;
|
||||
}
|
||||
ge_kfifo_put(fifo, event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ge_input_peek (ge_input_t* ctx, ge_input_event_t* event) {
|
||||
struct ge_input_fifo_t* fifo = (struct ge_input_fifo_t*)ctx->context;
|
||||
if (ge_kfifo_is_empty(fifo)) {
|
||||
return -1;
|
||||
}
|
||||
ge_kfifo_peek(fifo, event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ge_input_recv (ge_input_t* ctx, ge_input_event_t* event) {
|
||||
struct ge_input_fifo_t* fifo = (struct ge_input_fifo_t*)ctx->context;
|
||||
if (ge_kfifo_is_empty(fifo)) {
|
||||
return -1;
|
||||
}
|
||||
ge_kfifo_get(fifo, event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ge_input_t ge_input = {
|
||||
.context = &ge_input_fifo,
|
||||
|
||||
.func_send = ge_input_send,
|
||||
.func_peek = ge_input_peek,
|
||||
.func_recv = ge_input_recv,
|
||||
};
|
Reference in New Issue
Block a user