/*
 * @file hv_pm51_app_Key.h
 * @brief Header file of keyboard  module.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+) Use ()
 *
 * @endverbatim
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2023-03-01
 */
 
#ifndef __HV_PM51_APP_KEY_H__
#define __HV_PM51_APP_KEY_H__

#include "hv_pm51_Setting.h"
#include "hv_pm51_Base.h"
#if ADC_KEY_ENABLE
#include "hv_pm51_driver_ADC.h"
#endif
#if GPIO_KEY_ENABLE
#include "hv_pm51_driver_GPIO.h"
#endif
#include "Keyboard.h"

typedef enum _KeyStatus
{
    E_KEY_IDEL,
    E_KEY_PUSHDONW,
    E_KEY_COMBO
} KeyStatus;

typedef enum _KeyLedStatus
{
    E_KEY_LED_ON,
    E_KEY_LED_OFF,
    E_KEY_LED_BREATH,
    E_KEY_LED_ONOFF,
    E_KEY_LED_ON1,
    E_KEY_LED_ON2,
    E_KEY_LED_ON3
} KeyLedStatus;

#if GPIO_KEY_ENABLE

typedef enum _GpioKeyVal
{
    E_KEY_VAL_0,
    E_KEY_VAL_1,
    E_KEY_VAL_2,
    E_KEY_VAL_3,
    E_KEY_VAL_4,
    E_KEY_VAL_5,
    E_KEY_VAL_6,
    E_KEY_VAL_7,
    E_KEY_VAL_MAX
} GpioKeyVal;

typedef struct _GpioKeyMap
{
    GpioEn enGpio;
    GpioKeyVal enKeyVal;    
}GpioKeyMap;

#endif



/**
 * @brief Initialization related to key.
 * @return None.
 */
void Hv_PM51_Key_Init(void);

#if ADC_KEY_ENABLE

/**
 * @brief Get ADC key value given a ADC key data. 
 * @param[in] enAdcNum: ADC port number.
 * @param[in] usAdcKeyData: ADC key data.
 * @return ADC key value.
 */
AdcKeyVal PM51_Key_GetAdcKeyVal(AdcNum enAdcNum, USHORT16 usAdcKeyData);

/**
 * @brief Handle key(adc) interrupt messages, obtain key values, 
 *          and send them to the message pool through the mailbox.
 * @param[in] enAdcNum: ADC port number.
 * @return None.
 */
void Hv_PM51_Key_Handler(AdcNum enAdcNum);

/**
 * @brief Detect the status of key(adc) release and send the release 
 *          key message to the message pool through mailbox.
 * @return None.
 */
void Hv_PM51_Key_TimerHandler(void);
/**
 * @brief Detect the status of Menu
 * @return status.
 */
xUCHAR8 PM51_Key_JudgeMenuSts(void);
/**
 * @brief Detect the status of factory mode key
 * @return status.
 */
xUCHAR8 PM51_Key_FactoryModeJudgeMenuSts(void);
/**
 * @brief set LED of KEY
 * @return None.
 */
void PM51_Key_SetLed(KeyLedStatus enKeyLedSts);

#elif GPIO_KEY_ENABLE
/**
 * @brief Handle key(GPIO) interrupt messages, and send key down and 
 *          key release message to the message pool through the mailbox.
 * @param[in] enGpio: GPIO port number.
 * @return None.
 */
void Hv_PM51_Key_Handler(GpioEn enGpio);
#endif

#endif
