2025-04-12 13:58:43 +08:00
|
|
|
|
/*
|
|
|
|
|
* @Author : stark1898y 1658608470@qq.com
|
|
|
|
|
* @Date : 2024-12-30 10:11:28
|
|
|
|
|
* @LastEditors : stark1898y 1658608470@qq.com
|
|
|
|
|
* @LastEditTime : 2025-04-08 16:39:05
|
2025-06-09 14:02:45 +08:00
|
|
|
|
* @FilePath : \BLE_DCF_TYQ_CH592F\HAL\KEY.c
|
2025-04-12 13:58:43 +08:00
|
|
|
|
* @Description :
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2025 by yzy, All Rights Reserved.
|
|
|
|
|
*/
|
2024-12-02 16:26:55 +08:00
|
|
|
|
/********************************** (C) COPYRIGHT *******************************
|
|
|
|
|
* File Name : KEY.c
|
|
|
|
|
* Author : WCH
|
|
|
|
|
* Version : V1.2
|
|
|
|
|
* Date : 2022/01/18
|
|
|
|
|
* Description :
|
|
|
|
|
*********************************************************************************
|
|
|
|
|
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
2025-04-12 13:58:43 +08:00
|
|
|
|
* Attention: This software (modified or not) and binary are used for
|
2024-12-02 16:26:55 +08:00
|
|
|
|
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/* ͷ<>ļ<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 ******************************/
|