- 新增 button4_4 按钮输入模块,实现 4x4 按钮矩阵的扫描和处理 - 添加 ge_timer 模块,提供基本的定时功能 - 优化 ge_render 模块,调整屏幕尺寸的类型 - 修复 init_lcd 函数的定义,使其返回类型为 void
116 lines
2.5 KiB
C
116 lines
2.5 KiB
C
// #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;
|
|
}
|
|
|