/*
 * @file hv_pm51_driver_Reg.h
 * @brief Header file of register read and write API.
 *
 * @verbatim
 * ==============================================================================
 *                        ##### How to use #####
 * ==============================================================================
 * (+) Use ()
 *
 * @endverbatim
 * @author HiView SoC Software Team
 * @version 1.0.0
 * @date 2023-03-01
 */

#ifndef __HV_PM51_DRIVER_REG_H__
#define __HV_PM51_DRIVER_REG_H__

#include "hv_pm51_Base.h"
#include "hv_pm51_Setting.h"
#include "HS_PAGE_HT7315_8051_reg.h"

#if PM51_DEBUG_DUMMY_REGS

#define PM51_DEBUG_PM_STATUS_NORMAL                     1
#define PM51_DEBUG_PM_STATUS_STANDBY                    2
#define PM51_DEBUG_RISC_BOOT_STATUS_NOT_BOOT            1
#define PM51_DEBUG_RISC_BOOT_STATUS_BOOTED              2
#define PM51_DEBUG_RISC_BOOT_STATUS_FAILED              3
#define PM51_DEBUG_WAKEUP_REASON_POWER_ON               1 
#define PM51_DEBUG_WAKEUP_REASON_HDMI_CABLE             2
#define PM51_DEBUG_WAKEUP_REASON_DP_CABLE               3
#define PM51_DEBUG_WAKEUP_REASON_TYPE_C_CABLE           4
#define PM51_DEBUG_WAKEUP_REASON_HDMI_TMDS              5
#define PM51_DEBUG_WAKEUP_REASON_HDMI_CEC               6
#define PM51_DEBUG_WAKEUP_REASON_DP_AUX                 7
#define PM51_DEBUG_WAKEUP_REASON_TYPE_C_CC_CMD          8
#define PM51_DEBUG_WAKEUP_REASON_KEY                    9
#define PM51_DEBUG_WAKEUP_REASON_IR                     10
#define PM51_DEBUG_WAKEUP_REASON_DP_GPIO                11
#define PM51_DEBUG_WAKEUP_REASON_STANDBY_TO_POWEROFF    12
#define PM51_DEBUG_LED_STATUS_ON                        1
#define PM51_DEBUG_LED_STATUS_OFF                       2
#define PM51_DEBUG_LED_STATUS_BREATH                    3
#define PM51_DEBUG_LED_MODE_ON                          1
#define PM51_DEBUG_LED_MODE_OFF                         2
#define PM51_DEBUG_AUTO_SEARCH_ON                       1
#define PM51_DEBUG_AUTO_SEARCH_OFF                      2
#define PM51_DEBUG_MAIN_CHANNEL_HDMI0                   1
#define PM51_DEBUG_MAIN_CHANNEL_HDMI1                   2
#define PM51_DEBUG_MAIN_CHANNEL_DP0                     3
#define PM51_DEBUG_MAIN_CHANNEL_DP1                     4
#define PM51_DEBUG_SUB_CHANNEL_HDMI0                    1
#define PM51_DEBUG_SUB_CHANNEL_HDMI1                    2
#define PM51_DEBUG_SUB_CHANNEL_DP0                      3
#define PM51_DEBUG_SUB_CHANNEL_DP1                      4

#define PM51_DEBUG_MAIN_VERSION_ADDR        HS_Standby__standby_mcu_reg__reg_stby_rega_ADDR
#define PM51_DEBUG_SUB_VERSION_ADDR         (HS_Standby__standby_mcu_reg__reg_stby_rega_ADDR+1)
#define PM51_DEBUG_PM_STATUS_ADDR           (HS_Standby__standby_mcu_reg__reg_stby_rega_ADDR+2)
#define PM51_DEBUG_RISC_BOOT_STATUS_ADDR    (HS_Standby__standby_mcu_reg__reg_stby_rega_ADDR+3)

#define PM51_DEBUG_WAKEUP_REASON_ADDR       HS_Standby__standby_mcu_reg__reg_stby_regb_ADDR
#define PM51_DEBUG_LED_STATUS_ADDR          (HS_Standby__standby_mcu_reg__reg_stby_regb_ADDR+2)
#define PM51_DEBUG_LED_MODE_ADDR            (HS_Standby__standby_mcu_reg__reg_stby_regb_ADDR+3)

#define PM51_DEBUG_AUTO_SEARCH_ADDR         HS_Standby__standby_mcu_reg__reg_stby_regc_ADDR
#define PM51_DEBUG_MAIN_CHANNEL_ADDR        (HS_Standby__standby_mcu_reg__reg_stby_regc_ADDR+1)
#define PM51_DEBUG_SUB_CHANNEL_ADDR         (HS_Standby__standby_mcu_reg__reg_stby_regc_ADDR+2)

#define PM51_DEBUG_ADC0_KEY_ADDR            (HS_Standby__standby_mcu_reg__reg_stby_regd_ADDR)
#define PM51_DEBUG_ADC1_KEY_ADDR            (HS_Standby__standby_mcu_reg__reg_stby_regd_ADDR+1)

#endif

/**
 * @brief Initialization for accessing APB registers of external bus.
 * @return None.
 */
void Hv_PM51_Reg_Init(void);

/**
 * @brief API for reading APB registers of external bus.
 * @param[in] ulRegAddr: 32bit register address.
 * @return value of 32bit register.
 */
ULONG32 Hv_PM51_Reg_Read(ULONG32 ulRegAddr) reentrant;

/**
 * @brief API for writing APB registers of external bus.
 * @param[in] ulRegAddr: 32bit register address.
 * @param[in] ulVal: 32bit register value. 
 * @return None.
 */
void Hv_PM51_Reg_Write(ULONG32 ulRegAddr, ULONG32 ulVal) reentrant;

/**
 * @brief API for reading array(only for 4 bytes array, and do not change byte order).
 * @param[in] ulRegAddr: 4 bytes array address.
 * @return value of 4 bytes array.
 */
ULONG32 Hv_PM51_Reg_ReadArray(ULONG32 ulRegAddr);

/**
 * @brief API for writing array(only for 4 bytes array, and do not change byte order).
 * @param[in] ulRegAddr: 4 bytes array address.
 * @param[in] ulVal: 4 bytes array value. 
 * @return None.
 */
void Hv_PM51_Reg_WriteArray(ULONG32 ulRegAddr, ULONG32 ulVal);

/**
 * @brief API for reading APB registers of external bus using mask.
 * @param[in] ulRegAddr: 32bit register address.
 * @param[in] ucBitStartLow: start bits of mask. 
 * @param[in] ucBitEndHigh: end bits of mask.  
 * @return value of 32bit register.
 */
ULONG32 Hv_PM51_Reg_ReadMask(ULONG32 ulRegAddr, UCHAR8 ucBitStartLow, UCHAR8 ucBitEndHigh);

/**
 * @brief API for writing APB registers of external bus using mask.
 * @param[in] ulRegAddr: 32bit register address.
 * @param[in] ucBitStartLow: start bits of mask. 
 * @param[in] ucBitEndHigh: end bits of mask.
 * @param[in] ulVal: 32bit register value.
 * @return None.
 */
void Hv_PM51_Reg_WriteMask(ULONG32 ulRegAddr, UCHAR8 ucBitStartLow, UCHAR8 ucBitEndHigh, ULONG32 ulVal);

/**
 * @brief API for reading APB registers of external bus with byte mode.
 * @param[in] ulRegAddr: 32bit register address.
 * @return byte value of register.
 */
UCHAR8 Hv_PM51_Reg_ReadByte(ULONG32 ulRegAddr) reentrant;

/**
 * @brief API for writing APB registers of external bus with byte mode.
 * @param[in] ulRegAddr: 32bit register address.
 * @param[in] ulVal: byte value of register.
 * @return None.
 */
void Hv_PM51_Reg_WriteByte(ULONG32 ulRegAddr, UCHAR8 ucVal) reentrant;

#endif
