/**
  ******************************************************************************
  * @file    ys32md211_opamp.c
  * @author  YSPRING Application Team
  * @version V1.0.1
  * @date    2023.3.20
  * @brief   This file provides firmware functions to manage the following 
  *          functionalities of the Operational amplifiers (OPAMP) peripheral:           
  *           + OPAMP activation
  *
  *  @verbatim  
  *  
  ============================================================================== 
                          ##### OPAMP features #####
  ============================================================================== 
    [..] The device integrates up to 2 operational amplifiers OPAMP1, OPAMP2.
             
    [..] The input range is 0V to VCCA, and the output range is 0.2V to VCCA-0.2V.
                             
    [..] The Offset voltage less than 3 mV.
            
                          ##### How to use this driver ##### 
  ============================================================================== 
    [..]
    (#) Enable the OPAMP interface clock using 
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_OPA1, ENABLE); 
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_OPA2, ENABLE); 				
    (#) OPAMP pins configuration
       (++) Enable the clock for the OPAMP GPIOs using the following function:
            RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOx, ENABLE);   
       (++) Configure these OPAMP pins in analog mode using GPIO_Init();  
    (#) Activate the OPAMP peripheral using OPAMP_Cmd() function.
              
    @endverbatim
  *    
  ******************************************************************************
  */

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

/** @addtogroup YS32MD211_StdPeriph_Driver
  * @{
  */

/** @defgroup OPAMP 
  * @brief OPAMP driver modules
  * @{
  */ 

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* ---------------------- OPAMP registers bit mask ----------------------------*/

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/** @defgroup OPAMP_Private_Functions
  * @{
  */

/** @defgroup OPAMP_Group1 activation function
 *  @brief   Activation function
 *
@verbatim   
  ==============================================================================
            ##### OPAMP activation function #####
  ==============================================================================  

@endverbatim
  * @{
  */

/**
  * @brief  Enables or disables the specified OPAMP peripheral.
  * @param  OPAMPx: This parameter is OPAMP.
  * @param  NewState: new state of the OPAMP peripheral. 
  *          This parameter can be: ENABLE or DISABLE.
  * @retval None
  */
void OPAMP_Cmd(uint32_t OPAMPx, FunctionalState NewState)
{
  /* Check the parameters */
  assert_param(IS_OPAMP_ALL_PERIPH(OPAMPx));
  assert_param(IS_FUNCTIONAL_STATE(NewState));

  if (NewState != DISABLE)
  {
    /* Enable the OPAMP peripheral */
		if(OPAMPx == OPAMP1)
		{
			OPA->CR1 |= (uint32_t)OPA_CR1_OPA1EN;
		}
		else
		{
			OPA->CR1 |= (uint32_t)OPA_CR1_OPA2EN;
		}
  }
  else
  {
    /* Disable the OPAMP peripheral */
		if(OPAMPx == OPAMP1)
		{
			OPA->CR1 &= (uint32_t)~OPA_CR1_OPA1EN;
		}
		else
		{
			OPA->CR1 &= (uint32_t)~OPA_CR1_OPA2EN;
		}		
  }
}

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

/**
  * @}
  */

