/*******************************************************************************
 * @file     hv.h
 * @brief    High voltage module header file.
 * @version  V4.0.1
 * @date     30-July-2026
 *
 * @note
 * Copyright (C) 2022 Spintrol Electronic Technology (Shanghai) Co., Ltd.. All rights reserved.
 *
 * @attention
 * THIS SOFTWARE JUST PROVIDES CUSTOMERS WITH CODING INFORMATION REGARDING
 * THEIR PRODUCTS, WHICH AIMS AT SAVING TIME FOR THEM. SPINTROL SHALL NOT BE
 * LIABLE FOR THE USE OF THE SOFTWARE. SPINTROL DOES NOT GUARANTEE THE
 * CORRECTNESS OF THIS SOFTWARE AND RESERVES THE RIGHT TO MODIFY THE SOFTWARE
 * WITHOUT NOTIFICATION.
 *
 ******************************************************************************/

#ifndef HV_H
#define HV_H

#ifdef __cplusplus
extern "C" {
#endif


#include "epwr.h"
#include "spc1158_hv_bitfield.h"




/**
 *  @brief High Voltage Module Control Register Address Definition
 */
typedef enum
{
  HV_REG_GLBSTS                   = 0x00,   /*!< Global Status Register               */
  HV_REG_GLBSTSCLR                = 0x01,   /*!< Global Status Clear Register         */
  HV_REG_TZCTL                    = 0x02,   /*!< Trip-Zone Enable Register            */
  HV_REG_BUCKCTL0                 = 0x03,   /*!< Buck Control Register 0              */
  HV_REG_BUCKCTL1                 = 0x04,   /*!< Buck Control Register 1              */

  /* Registers For Engineering Test */
  HV_REG_ENGRKEY                  = 0x05,   /*!< Engineering Key Register             */
  HV_REG_BUCKTRIM0                = 0x06,   /*!< Buck Trim Register 0                 */
  HV_REG_BUCKTRIM1                = 0x07,   /*!< Buck Trim Register 1                 */
  HV_REG_BUCKTM0                  = 0x08,   /*!<                                      */
  HV_REG_BUCKTM1                  = 0x09,   /*!<                                      */
  HV_REG_TESTCTL                  = 0x0A,   /*!< Test Control Register                */
  HV_REG_TESTSEL                  = 0x0B,   /*!< Test Point Select Register           */
} HV_REGS;




/**
 *  @brief  High Voltage Module timeout count number
 */
#define HV_TIMEOUT_MAX            (100000U)




/**
 *  @brief  High Voltage Module SPI Interface Maximum Clock Frequency
 */
#define HV_SPI_MAX_CLK            (4000000)   /*!< 4 MHz */




/**
 *  @brief  High Voltage Module Control Command
 */
#define HV_CMD_READ_ID            (0x514E4944UL)
#define HV_CMD_WRITE              (0x5740005AUL)
#define HV_CMD_EXECUTE            (0x45786563UL)
#define HV_CMD_READ               (0x5240445AUL)
#define HV_CMD_RESET              (0x5253544EUL)




/**
 *  @brief  High Voltage Module Masked Response
 */
#define HV_RESP_READ_ID           (0x49445600UL)
#define HV_RESP_WRITE             (0x57A0005AUL)
#define HV_RESP_EXECUTE           (0x446F6E65UL)
#define HV_RESP_READ              (0x52A00000UL)
#define HV_RESP_RESET             (0x446F6E65UL)




/**
 *  @brief  High Voltage Module Register Address Check
 */
#define IS_HV_REG(u8Addr)         ((u8Addr) <= 0x0B)




/**
 *  @brief  High Voltage Module Public Function Declaration
 */
ErrorStatus HV_ComInit(uint32_t u32Baudrate);
ErrorStatus HV_Init(uint32_t u32Baudrate, uint8_t *pu8ID, uint32_t u32Timeout);

ErrorStatus HV_Handshake(uint8_t *pu8ID, uint32_t u32Timeout);
ErrorStatus HV_Command(uint32_t u32Req, uint32_t *pu32Resp);

ErrorStatus HV_WriteReg(uint8_t u8Addr, uint8_t u8Data);
ErrorStatus HV_ReadReg(uint8_t u8Addr, uint8_t *pu8Data);
ErrorStatus HV_WriteRegField(uint8_t u8Addr, uint8_t u8Mask, uint8_t u8FieldData);

ErrorStatus HV_InitReg(void);
ErrorStatus HV_ResetReg(void);

ErrorStatus HV_EnableVDDGAnalogTest(void);


#ifdef __cplusplus
}
#endif /* extern "C" */

#endif /* HV_H */


/******************* Copyright (C) 2022 Spintrol Electronic Technology (Shanghai) Co., Ltd. ***** END OF FILE ****/
