 /**    
  ****************************************************************************************************
  * @file    fm33lg0xx_fl_vrefp.c
  * @author  FMSH Application Team
  * @brief   Src file of VREFP FL Module
  ****************************************************************************************************
  * @attention
  *
  * Copyright (c) 2022, SHANGHAI FUDAN MICROELECTRONICS GROUP CO., LTD.(FUDAN MICROELECTRONICS./ FUDAN MICRO.)    
  * All rights reserved.    
  *    
  * Processor:                   FM33LG0xxA    
  * http:                        http://www.fmdevelopers.com.cn/    
  *    
  * Redistribution and use in source and binary forms, with or without    
  * modification, are permitted provided that the following conditions are met    
  *    
  * 1. Redistributions of source code must retain the above copyright notice,    
  *    this list of conditions and the following disclaimer.    
  *    
  * 2. Redistributions in binary form must reproduce the above copyright notice,    
  *    this list of conditions and the following disclaimer in the documentation    
  *    and/or other materials provided with the distribution.    
  *    
  * 3. Neither the name of the copyright holder nor the names of its contributors    
  *    may be used to endorse or promote products derived from this software    
  *    without specific prior written permission.    
  *    
  * 4. To provide the most up-to-date information, the revision of our documents     
  *    on the World Wide Web will be the most Current. Your printed copy may be      
  *    an earlier revision. To verify you have the latest information avaliable,    
  *    refer to: http://www.fmdevelopers.com.cn/.    
  *    
  * THIS SOFTWARE IS PROVIDED BY FUDAN MICRO "AS IS" AND ANY EXPRESSED     
  * ORIMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES     
  * OF MERCHANTABILITY NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE    
  * ARE DISCLAIMED.IN NO EVENT SHALL FUDAN MICRO OR ITS CONTRIBUTORS BE LIABLE     
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL     
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS     
  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER    
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,     
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISINGIN ANY WAY OUT OF THE     
  * USE OF THIS SOFTWARE, EVEN IF ADVISED OFTHE POSSIBILITY OF SUCH DAMAGE.    
 */    

/* Includes ------------------------------------------------------------------*/
#include "fm33lg0xx_fl.h"

/** @addtogroup FM33LG0XX_FL_Driver
  * @{
  */

/** @addtogroup VREFP
  * @{
  */


#ifdef FL_VREFP_DRIVER_ENABLED

/* Private macros ------------------------------------------------------------*/
/** @addtogroup VREFP_FL_Private_Macros
  * @{
  */
#define         IS_VREFP_INSTANCE(INTANCE)                       ((INTANCE) == VREFP)

#define         IS_FL_VREFP_VOLTAGETRIM(__VALUE__)               (((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_2P0V_TRIM)||\
                                                                 ((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_2P5V_TRIM)||\
                                                                 ((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_3P0V_TRIM)||\
                                                                 ((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_4P5V_TRIM)||\
                                                                 ((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_1P5V_TRIM))

#define         IS_FL_VREFP_OUTPUTVOLTAGE(__VALUE__)             (((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_2P0V)||\
                                                                 ((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_2P5V)||\
                                                                 ((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_3P0V)||\
                                                                 ((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_4P5V)||\
                                                                 ((__VALUE__) == FL_VREFP_OUTPUT_VOLTAGE_1P5V))

#define         IS_FL_VREFP_ENABLEPERIOD(__VALUE__)              (((__VALUE__) == FL_VREFP_ENABLE_PERIOD_1MS)||\
                                                                 ((__VALUE__) == FL_VREFP_ENABLE_PERIOD_4MS)||\
                                                                 ((__VALUE__) == FL_VREFP_ENABLE_PERIOD_16MS)||\
                                                                 ((__VALUE__) == FL_VREFP_ENABLE_PERIOD_32MS)||\
                                                                 ((__VALUE__) == FL_VREFP_ENABLE_PERIOD_64MS)||\
                                                                 ((__VALUE__) == FL_VREFP_ENABLE_PERIOD_256MS)||\
                                                                 ((__VALUE__) == FL_VREFP_ENABLE_PERIOD_1000MS)||\
                                                                 ((__VALUE__) == FL_VREFP_ENABLE_PERIOD_4000MS))

#define         IS_FL_VREFP_DRIVINGTIME(__VALUE__)               (((__VALUE__) == FL_VREFP_DRIVING_TIME_4LSCLK)||\
                                                                 ((__VALUE__) == FL_VREFP_DRIVING_TIME_8LSCLK)||\
                                                                 ((__VALUE__) == FL_VREFP_DRIVING_TIME_16LSCLK)||\
                                                                 ((__VALUE__) == FL_VREFP_DRIVING_TIME_32LSCLK)||\
                                                                 ((__VALUE__) == FL_VREFP_DRIVING_TIME_64LSCLK)||\
                                                                 ((__VALUE__) == FL_VREFP_DRIVING_TIME_128LSCLK)||\
                                                                 ((__VALUE__) == FL_VREFP_DRIVING_TIME_256LSCLK)||\
                                                                 ((__VALUE__) == FL_VREFP_DRIVING_TIME_512LSCLK))

#define         IS_FL_VREFP_WORKMODE(__VALUE__)                  (((__VALUE__) == FL_VREFP_WORK_MODE_CONTINUOUS)||\
                                                                 ((__VALUE__) == FL_VREFP_WORK_MODE_PERIODIC))

/**
  * @}
  */

/* Exported functions --------------------------------------------------------*/
/** @addtogroup VREFP_FL_EF_Init
  * @{
  */

/**
  * @brief  关闭VREFP外设总线时钟
  *
  * @param  VREFPx 外设入口地址
  *
  * @retval ErrorStatus枚举值
  *         -FL_PASS 配置成功
  *         -FL_FAIL 配置过程发生错误
  */
FL_ErrorStatus FL_VREFP_DeInit(VREFP_Type *VREFPx)
{
    assert_param(IS_VREFP_INSTANCE(VREFPx));
    return FL_PASS;
}
/**
  * @brief  根据 VREFP_InitStruct初始化对应外设入口地址的寄存器值.
  *
  * @note   WWTD使能后将无法关闭，直到下一次芯片复位
  *
  * @param  VREFPx 外设入口地址
  *
  * @param  VREFP_InitStruct 指向 @ref FL_VREFP_InitTypeDef 结构体的指针
  *
  * @retval ErrorStatus枚举值
  *         -FL_PASS 配置成功
  *         -FL_FAIL 配置过程发生错误
  */
FL_ErrorStatus FL_VREFP_Init(VREFP_Type *VREFPx, FL_VREFP_InitTypeDef *VREFP_InitStruct)
{
    FL_ErrorStatus status = FL_PASS;
    /* 入口参数检查 */
    assert_param(IS_VREFP_INSTANCE(VREFPx));
    assert_param(IS_FL_VREFP_VOLTAGETRIM(VREFP_InitStruct->voltageTrim));
    assert_param(IS_FL_VREFP_OUTPUTVOLTAGE(VREFP_InitStruct->outputVoltage));
    assert_param(IS_FL_VREFP_ENABLEPERIOD(VREFP_InitStruct->timeOfPeriod));
    assert_param(IS_FL_VREFP_DRIVINGTIME(VREFP_InitStruct->timeOfDriving));
    assert_param(IS_FL_VREFP_WORKMODE(VREFP_InitStruct->mode));
    /* 开启总线时钟 */
    FL_CMU_EnableGroup1BusClock(FL_CMU_GROUP1_BUSCLK_PMU);
    /* 配置VREFP输出电压TRIM值 */
    FL_VREFP_WriteOutputVoltageTrim(VREFPx, VREFP_InitStruct->voltageTrim);
    /* 配置VREFP输出电压 */
    FL_VREFP_SetOutputVoltage(VREFPx, VREFP_InitStruct->outputVoltage);
    /* 配置输出模式 */
    FL_VREFP_SetWorkMode(VREFPx, VREFP_InitStruct->mode);
    /* 间歇模式下使能周期 */
    FL_VREFP_SetEnablePeriod(VREFPx, VREFP_InitStruct->timeOfPeriod);
    /* 间歇模式下单次驱动时间 */
    FL_VREFP_SetDrivingTime(VREFPx, VREFP_InitStruct->timeOfDriving);
    /* 启动VREFP */
    FL_VREFP_Enable(VREFPx);
    return status;
}
/**
  * @brief  设置 VREFP_InitStruct 为默认配置
  *
  * @param  VREFP_InitStruct 指向需要将值设置为默认配置的结构体 @ref FL_VREFP_InitTypeDef 结构体
  *
  * @retval None
  */
void FL_VREFP_StructInit(FL_VREFP_InitTypeDef *VREFP_InitStruct)
{
    VREFP_InitStruct->voltageTrim = FL_VREFP_OUTPUT_VOLTAGE_3P0V_TRIM;
    VREFP_InitStruct->outputVoltage = FL_VREFP_OUTPUT_VOLTAGE_3P0V;
    VREFP_InitStruct->mode = FL_VREFP_WORK_MODE_CONTINUOUS;
    VREFP_InitStruct->timeOfPeriod = FL_VREFP_ENABLE_PERIOD_1MS;
    VREFP_InitStruct->timeOfDriving = FL_VREFP_DRIVING_TIME_4LSCLK;
}

/**
  * @}
  */

#endif /* FL_VREFP_DRIVER_ENABLED */

/**
  * @}
  */

/**
  * @}
  */

/*************************(C) COPYRIGHT Fudan Microelectronics **** END OF FILE*************************/

