feat: first commit

This commit is contained in:
不吃油炸鸡
2025-08-02 19:53:22 +08:00
commit db264d34e1
528 changed files with 366793 additions and 0 deletions

45
bootloader/BSP/KEY/key.c Normal file
View File

@@ -0,0 +1,45 @@
#include "key.h"
#include "delay.h"
void Key_Port_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
/*Configure GPIO pin : PA5 */
GPIO_InitStruct.Pin = KEY1_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(KEY1_PORT, &GPIO_InitStruct);
/*Configure GPIO pin : PA4 */
GPIO_InitStruct.Pin = GPIO_PIN_4;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
uint8_t KeyScan(uint8_t mode)
{
static uint8_t key_up = 1;
uint8_t keyvalue=0;
if(mode) key_up = 1;
if( key_up && ((!KEY1) || KEY2))
{
delay_ms(3);//ensure the key is down
if(!KEY1) keyvalue = 1;
else if(KEY2) keyvalue = 2;
if(keyvalue) key_up = 0;
}
else
{
delay_ms(3);//ensure the key is up
if(KEY1 && (!KEY2))
key_up = 1;
}
return keyvalue;
}

30
bootloader/BSP/KEY/key.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef __KEY_H__
#define __KEY_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "main.h"
//KEY1
#define KEY1_PORT GPIOA
#define KEY1_PIN GPIO_PIN_5
#define KEY1 HAL_GPIO_ReadPin(KEY1_PORT,KEY1_PIN)
//KEY_Wake
#define KEY2_PORT GPIOA
#define KEY2_PIN GPIO_PIN_4
#define KEY2 HAL_GPIO_ReadPin(KEY2_PORT,KEY2_PIN)
void Key_Port_Init(void);
void Key_Interrupt_Callback(void);
uint8_t KeyScan(uint8_t mode);
#ifdef __cplusplus
}
#endif
#endif