You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
3.6 KiB
C
149 lines
3.6 KiB
C
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
|
|
#include "ALLinclude.h"
|
|
|
|
void F_KEYIO_Init(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|
|
|
/* Enable the GPIO_LED Clock */
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
|
|
/* Configure the KEY pin */
|
|
GPIO_InitStruct.Pin = PIN_Key;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
HAL_GPIO_Init(PORT_Key, &GPIO_InitStruct);
|
|
|
|
/* Configure the Power hold pin */
|
|
GPIO_InitStruct.Pin = PIN_Power;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
HAL_GPIO_Init(PORT_Power, &GPIO_InitStruct);
|
|
|
|
/* Configure the CHRG pin */
|
|
GPIO_InitStruct.Pin = PIN_STDBY;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
HAL_GPIO_Init(PORT_STDBY, &GPIO_InitStruct);
|
|
|
|
/* Configure the STDBY pin */
|
|
GPIO_InitStruct.Pin = PIN_STDBY;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
HAL_GPIO_Init(PORT_STDBY, &GPIO_InitStruct);
|
|
|
|
#if 0
|
|
GPIO_InitStruct.Pin = PIN_MODE;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
|
HAL_GPIO_Init(PORT_MODE, &GPIO_InitStruct);
|
|
#endif
|
|
/* Configure the test pin */
|
|
GPIO_InitStruct.Pin = PIN_Test_rx;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
|
|
|
HAL_GPIO_Init(PORT_Test_rx, &GPIO_InitStruct);
|
|
|
|
}
|
|
|
|
void APP_ConfigureEXTI(void)
|
|
{
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE(); /* Enable GPIOA clock */
|
|
|
|
GPIO_InitStruct.Mode = GPIO_MODE_EVT_FALLING; /* GPIO mode is a falling edge event */
|
|
GPIO_InitStruct.Pull = GPIO_PULLUP; /* pull up */
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; /* The speed is high */
|
|
GPIO_InitStruct.Pin = PIN_Key;
|
|
HAL_GPIO_Init(PORT_Key, &GPIO_InitStruct);
|
|
|
|
}
|
|
|
|
void TaskKeyOnOff(void *pvParamters)
|
|
{
|
|
static uint16_t TimerKeyQD;
|
|
uint8_t keycode,keycodeBK;
|
|
#define keycodeOnOff 0x01
|
|
#define keycodemode 0x02
|
|
TypedefID_T ret = eCmdEventIdel;
|
|
for(;;)
|
|
{
|
|
keycode = 0;
|
|
ret =eCmdEventIdel;
|
|
if(HAL_GPIO_ReadPin(PORT_Key,PIN_Key) == GPIO_PIN_SET)
|
|
{
|
|
keycode|=keycodeOnOff;
|
|
}
|
|
#if 0
|
|
if(HAL_GPIO_ReadPin(PORT_MODE,PIN_MODE) == GPIO_PIN_RESET)
|
|
{
|
|
keycode|=keycodemode;
|
|
}
|
|
#endif
|
|
if(keycode)
|
|
{
|
|
if(TimerKeyQD<0xFFFF)TimerKeyQD++;
|
|
if(TimerKeyQD == 2*1000/10)//2Second
|
|
{
|
|
if(keycodeBK == keycodeOnOff)
|
|
{
|
|
ret = eCmdKeyONOFFlongPress;
|
|
}
|
|
#if 0
|
|
else if(keycodeBK == keycodemode)
|
|
{
|
|
ret = eCmdKeyModelongPress;
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(TimerKeyQD > 5 && TimerKeyQD<100)
|
|
{
|
|
if(keycodeBK == keycodeOnOff)
|
|
{
|
|
ret = eCmdKeyONOFFShortPress;
|
|
}
|
|
#if 0
|
|
else if(keycodeBK == keycodemode)
|
|
{
|
|
ret = eCmdKeyModeShortPress;
|
|
}
|
|
#endif
|
|
}
|
|
TimerKeyQD = 0;
|
|
}
|
|
keycodeBK = keycode;
|
|
|
|
if(ret!=eCmdEventIdel)
|
|
{
|
|
SendCmd(ret);
|
|
//For Test
|
|
// TypedefID_T CmdRegister = 1;
|
|
// xQueueSend(at_CmdRGB,&CmdRegister,portMAX_DELAY);
|
|
}
|
|
|
|
//return ret;
|
|
vTaskDelay(10);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/************************ (C) COPYRIGHT MS *****END OF FILE******************/
|
|
|