2022-03-26 20:51:40 +08:00

136 lines
4.0 KiB
C
Raw Blame History

/********************************** (C) COPYRIGHT *******************************
* File Name : KEY.c
* Author : WCH
* Version : V1.2
* Date : 2022/01/18
* Description :
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* SPDX-License-Identifier: Apache-2.0
*******************************************************************************/
/******************************************************************************/
/* ͷ<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> */
#include "HAL.h"
/**************************************************************************************************
* GLOBAL VARIABLES
**************************************************************************************************/
static uint8_t halKeySavedKeys; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ѯ<EFBFBD>Ƿ<EFBFBD><C7B7>м<EFBFBD>ֵ<EFBFBD>仯 */
/**************************************************************************************************
* FUNCTIONS - Local
**************************************************************************************************/
static halKeyCBack_t pHalKeyProcessFunction; /* callback function */
/**************************************************************************************************
* @fn HAL_KeyInit
*
* @brief Initilize Key Service
*
* @param none
*
* @return None
**************************************************************************************************/
void HAL_KeyInit(void)
{
/* Initialize previous key to 0 */
halKeySavedKeys = 0;
/* Initialize callback function */
pHalKeyProcessFunction = NULL;
KEY1_DIR;
KEY1_PU;
KEY2_DIR;
KEY2_PU;
}
/**************************************************************************************************
* @fn HalKeyConfig
*
* @brief Configure the Key serivce
*
* @param cback - pointer to the CallBack function
*
* @return None
**************************************************************************************************/
void HalKeyConfig(halKeyCBack_t cback)
{
/* Register the callback fucntion */
pHalKeyProcessFunction = cback;
tmos_start_task(halTaskID, HAL_KEY_EVENT, HAL_KEY_POLLING_VALUE); /* Kick off polling */
}
/**************************************************************************************************
* @fn HalKeyRead
*
* @brief Read the current value of a key
*
* @param None
*
* @return keys - current keys status
**************************************************************************************************/
uint8_t HalKeyRead(void)
{
uint8_t keys = 0;
if(HAL_PUSH_BUTTON1())
{ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
keys |= HAL_KEY_SW_1;
}
if(HAL_PUSH_BUTTON2())
{ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
keys |= HAL_KEY_SW_2;
}
if(HAL_PUSH_BUTTON3())
{ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
keys |= HAL_KEY_SW_3;
}
if(HAL_PUSH_BUTTON4())
{ //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1
keys |= HAL_KEY_SW_4;
}
return keys;
}
/**************************************************************************************************
* @fn HAL_KeyPoll
*
* @brief Called by hal_driver to poll the keys
*
* @param None
*
* @return None
**************************************************************************************************/
void HAL_KeyPoll(void)
{
uint8_t keys = 0;
if(HAL_PUSH_BUTTON1())
{
keys |= HAL_KEY_SW_1;
}
if(HAL_PUSH_BUTTON2())
{
keys |= HAL_KEY_SW_2;
}
if(HAL_PUSH_BUTTON3())
{
keys |= HAL_KEY_SW_3;
}
if(HAL_PUSH_BUTTON4())
{
keys |= HAL_KEY_SW_4;
}
if(keys == halKeySavedKeys)
{ /* Exit - since no keys have changed */
return;
}
halKeySavedKeys = keys; /* Store the current keys for comparation next time */
/* Invoke Callback if new keys were depressed */
if(keys && (pHalKeyProcessFunction))
{
(pHalKeyProcessFunction)(keys);
}
}
/******************************** endfile @ key ******************************/