mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
update
This commit is contained in:
38
software/bootloader/BSP/KEY/key.c
Normal file
38
software/bootloader/BSP/KEY/key.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#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 : PA0 */
|
||||
GPIO_InitStruct.Pin = KEYB_PIN;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(KEYB_PORT, &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 && !KEYB)
|
||||
{
|
||||
delay_ms(3);//ensure the key is down
|
||||
if(!KEYB) keyvalue = 1;
|
||||
if(keyvalue) key_up = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
delay_ms(3);//ensure the key is up
|
||||
if(KEYB)
|
||||
key_up = 1;
|
||||
}
|
||||
return keyvalue;
|
||||
}
|
||||
|
||||
23
software/bootloader/BSP/KEY/key.h
Normal file
23
software/bootloader/BSP/KEY/key.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef __KEY_H__
|
||||
#define __KEY_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "main.h"
|
||||
|
||||
//KEY1
|
||||
#define KEYB_PORT GPIOA
|
||||
#define KEYB_PIN GPIO_PIN_0
|
||||
#define KEYB HAL_GPIO_ReadPin(KEYB_PORT,KEYB_PIN)
|
||||
|
||||
void Key_Port_Init(void);
|
||||
uint8_t KeyScan(uint8_t mode);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user