feat(ge_interface): 添加按钮输入功能并优化定时器

- 新增 button4_4 按钮输入模块,实现 4x4 按钮矩阵的扫描和处理
- 添加 ge_timer 模块,提供基本的定时功能
- 优化 ge_render 模块,调整屏幕尺寸的类型
- 修复 init_lcd 函数的定义,使其返回类型为 void
This commit is contained in:
ZZY
2025-06-29 20:46:15 +08:00
parent 52097a36ee
commit d939449267
8 changed files with 192 additions and 6 deletions

View File

@ -0,0 +1,115 @@
// #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;
}

View File

@ -0,0 +1,30 @@
#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

View File

@ -0,0 +1,25 @@
#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