L 1 "..\FWLib\SC32F1XXX_Lib\src\sc32f1xxx_op.c"
N/**
N ******************************************************************************
N * @file    SC32f1xxx_OP.c
N * @author  SOC AE Team
N * @version V1.9.0
N * @date    2025-06-20
N * @brief   OP function module
N ******************************************************************************
N * @attention
N *
N *1.This software is supplied by SinOne Microelectronics Co.,Ltd. and is only 
N *intended for use with SinOne products. No other uses are authorized. This 
N *software is owned by SinOne Microelectronics Co.,Ltd. and is protected under 
N *all applicable laws, including copyright laws. 
N *2.The software which is for guidance only aims at providing customers with 
N *coding information regarding their products in order for them to save time. 
N *As a result, SinOne shall not be held liable for any direct, indirect or 
N *consequential damages with respect to any claims arising from the content of 
N *such software and/or the use made by customers of the coding information 
N *contained herein in connection with their products.
N *
N *  COPYRIGHT 2025 SinOne Microelectronics
N ******************************************************************************
N */
N/* Includes ------------------------------------------------------------------*/
N#if defined (SC32f12xx) 
X#if 0L 
S#include "sc32f1xxx_op.h"
S/** @defgroup OP_Exported_Functions_Group1 Configuration of the OP computation unit functions
S *  @brief   Configuration of the OP computation unit functions
S *
S@verbatim
S ===============================================================================
S                     ##### OP configuration functions #####
S ===============================================================================
S@endverbatim
S  * @{
S  */
S
S/**
S * @brief  DeInitialize the OP peripheral registers to their default reset values.
S * @param  OPx[out]:  can be select the OPx peripheral.
S *                SC32f12xx Selection range(OP)
S *               - OP: OP can be select the OPx peripheral.
S *               - OP0: select the OP0 peripheral
S *               - OP1: select the OP1 peripheral
S *               - OP2: select the OP2 peripheral
S * @retval None
S */
Svoid OP_DeInit ( OP_TypeDef* OPx )
S{
S#if defined (SC32f12xx) 
S    uint32_t tmpreg;
S    /* Check the parameters */
S    assert_param ( IS_OP_ALL_PERIPH ( OPx ) );
S
S    if ( OPx == OP )
S    {
S        /* Get the OPx OP_CON value */
S        tmpreg = OPx->OP_CON;
S
S        /* Set OPFS bit to OP_FreqSelect value */
S        tmpreg &= 0x00000000;
S
S        /* Write to OPx OP_CON */
S        OPx->OP_CON = ( uint32_t ) tmpreg;
S    }
S
S#endif
S}
S
S
S/**
S * @brief  DeInitializes the OP peripheral
S * @param  OPx[out]:  can be select the OPx peripheral.
S *                SC32f12xx Selection range(OP)
S *               - OP: OP can be select the OPx peripheral.
S *               - OP_0: select the OP0 peripheral
S *               - OP_1: select the OP1 peripheral
S *               - OP_2: select the OP2 peripheral
S * @param  OP_InitStruct[out]:Pointer to structure OP_InitTypeDef, to be initialized.
S * @retval None
S */
Svoid OP_Init ( OP_TypeDef* OPx, OP_InitTypeDef* OP_InitStruct )
S{
S#if defined (SC32f12xx)
S    uint32_t tmpreg;
S    /* Check the parameters */
S    assert_param ( IS_OP_ALL_PERIPH ( OPx ) );
S    assert_param ( IS_OP_Output ( Output ) );
S    assert_param ( IS_OP_Negative ( Negative ) );
S    assert_param ( IS_OP_Posittive ( Posittive ) );
S    assert_param ( IS_OP_PGAGain ( PGAGain ) );
S    assert_param ( IS_OP_FDBResisrance ( FDBResisrance ) );
S    assert_param ( IS_OP_ShortCircuit ( ShortCircuit ) );
S
S    /*---------------------------- OPx OP_CON Configuration ------------------------*/
S    /* Get the OPx OP_CON value */
S    tmpreg = OPx->OP_CON;
S
S    /* Clear OPFS bits */
S    tmpreg &= ( uint32_t ) ~ ( OP_CON_OPOSEL | OP_CON_OPNSEL | OP_CON_OPPSEL
S                               | OP_CON_PGAGAIN | OP_CON_FDBRSEL | OP_CON_PGAOFC );
S    /* Set OPFS bit to OP_FreqSelect value */
S    tmpreg |= ( uint32_t ) ( OP_InitStruct->OP_FDBResisrance | OP_InitStruct->OP_Negative | OP_InitStruct->OP_Output |
S                             OP_InitStruct->OP_PGAGain | OP_InitStruct->OP_Posittive | OP_InitStruct->OP_ShortCircuit );
S
S    /* Write to OPx OP_CON */
S    OPx->OP_CON = tmpreg;
S
S#endif
S}
S
S/**
S * @brief  Enables or disables the specified OP peripheral.
S * @param  OPx[out]:  can be select the OPx peripheral.
S *                SC32f12xx Selection range(OP)
S *               - OP: OP can be select the OPx peripheral.
S *               - OP_0: select the OP0 peripheral
S *               - OP_1: select the OP1 peripheral
S *               - OP_2: select the OP2 peripheral
S * @param  NewState[in]: new state of the OPx peripheral.
S *                  - DISABLE:Function disable
S *                  - ENABLE:Function enable
S * @retval None
S */
Svoid OP_Cmd ( OP_TypeDef* OPx, FunctionalState NewState )
S{
S#if defined (SC32f12xx)
S    /* Check the parameters */
S    assert_param ( IS_OP_ALL_PERIPH ( OPx ) );
S    assert_param ( IS_FUNCTIONAL_STATE ( NewState ) );
S
S    if ( NewState != DISABLE )
S    {
S        /* Enable the OP Function */
S        OPx->OP_CON |= OP_CON_ENOP;
S    }
S    else
S    {
S        /* Disable the OP Function */
S        OPx->OP_CON &= ( uint16_t ) ~OP_CON_ENOP;
S    }
S
S#endif
S}
S
S/**
S  * @brief  Configure the trimming value of the OPAMP.
S * @param  OPx[out]:  can be select the OPx peripheral.
S *                SC32f12xx Selection range(OP)
S *               - OP: OP can be select the OPx peripheral.
S *               - OP_0: select the OP0 peripheral
S *               - OP_1: select the OP1 peripheral
S *               - OP_2: select the OP2 peripheral
S  * @param  OP_TrimValueH[in]: the trimming value(high).
S  * @param  OP_TrimValueL[in]: the trimming value(low).
S  * @retval None
S  */
Svoid OP_OffsetTrimConfig ( OP_TypeDef* OPx,  uint32_t OP_TrimValueH, uint32_t OP_TrimValueL )
S{
S#if defined (SC32f12xx)
S    uint32_t tmpreg = 0;
S
S    /* Check the parameters */
S    assert_param ( IS_OP_ALL_PERIPH ( OPx ) );
S
S
S    /*!< Get the OPAMPx_CSR register value */
S    tmpreg = OPx->OP_CON;
S
S    /*!< Clear the trimming bits */
S    tmpreg &= ( uint32_t ) ~ ( ( OP_CON_TRIMOFFSETP | OP_CON_TRIMOFFSETN ) );
S
S    /*!< Configure the new trimming value */
S    tmpreg |= ( uint32_t ) ( ( OP_TrimValueL << OP_CON_TRIMOFFSETP_Pos ) | ( OP_TrimValueH << OP_CON_TRIMOFFSETN_Pos ) );
S
S    /*!< Write to OPAMPx_CSR register */
S    OPx->OP_CON = tmpreg;
S
S#endif
S}
S
S/**
S  * @brief  OP gain selection.
S * @param  OPx[out]:  can be select the OPx peripheral.
S *                SC32f12xx Selection range(OP) 
S *               - OP: OP can be select the OPx peripheral.
S *               - OP_0: select the OP0 peripheral
S *               - OP_1: select the OP1 peripheral
S *               - OP_2: select the OP2 peripheral
S  * @param  OPGain[in]: Gain multiple.
S *                SC32f12xx Selection range(OP_PGAGain_NonInvert8_Invert7,OP_PGAGain_NonInvert16_Invert15,OP_PGAGain_NonInvert32_Invert31,OP_PGAGain_NonInvert64_Invert63) 
S  *                  - OP_PGAGain_NonInvert4_Invert3:The OP inverting input gain is 4/3 times
S  *                  - OP_PGAGain_NonInvert8_Invert7:The OP inverting input gain is 8/7 times
S  *                  - OP_PGAGain_NonInvert16_Invert15:The OP inverting input gain is 16/15 times
S  *                  - OP_PGAGain_NonInvert32_Invert31:The OP in-phase input gain is 32/31 times
S  *                  - OP_PGAGain_NonInvert64_Invert63:The OP in-phase input gain is 64/63 times
S  * @retval None
S  */
Svoid OP_GainSelection ( OP_TypeDef* OPx, OP_PGAGain_TypeDef PGAGain )
S{
S#if defined (SC32f12xx)
S    /* Check the parameters */
S    assert_param ( IS_OP_ALL_PERIPH ( OPx ) );
S    assert_param ( IS_OP_PGAGain ( PGAGain ) );
S
S
S    OPx->OP_CON &= ~ ( OP_CON_PGAGAIN );
S    OPx->OP_CON |= PGAGain;
S
S#endif
S
S}
S
S/**
S * @}
S */
S/**
S  * @brief  OP Output port selection.
S * @param  OPx[out]:  can be select the OPx peripheral.
S *                SC32f12xx Selection range(OP)
S *               - OP: OP can be select the OPx peripheral.
S *               - OP_0: select the OP0 peripheral
S *               - OP_1: select the OP1 peripheral
S *               - OP_2: select the OP2 peripheral
S  * @param  OPOutput[in]: Output port selection.
S  *                  - OP_Output_OFF:The OP Output  OFF
S  *                  - OP_Output_ON:The OP Output  ON
S  * @retval None
S  */
Svoid OP_OutputSelection ( OP_TypeDef* OPx, OP_Output_TypeDef OPOutput )
S{
S#if defined (SC32f12xx)
S    /* Check the parameters */
S    assert_param ( IS_OP_ALL_PERIPH ( OPx ) );
S    assert_param ( IS_OP_Output ( OPOutput ) );
S
S
S    OPx->OP_CON &= ~ ( OP_CON_OPOSEL );
S    OPx->OP_CON |= OPOutput;
S
S#endif
S}
S#if defined (SC32f12xx)
S/**
S * @brief  Check whether the OP check value is written correctly
S * @retval Set state:
S *               - SUCCESS
S *               - ERROR
S */
SErrorStatus OP_OffsetSet(OP_TypeDef* OPx)
S{
S		uint8_t OPx_Readoffset0,OPx_Readoffset1,OPx_Readoffset2,OPx_Readoffset3;
S	  uint16_t OPx_offsetchecksum0,OPx_offsetchecksum1;
S	  OPx_Readoffset0 =  *((uint8_t *)0X08C00000+0x480);
S	  OPx_Readoffset1 =  *((uint8_t *)0X08C00000+0x481);
S	  OPx_Readoffset2 =  *((uint8_t *)0X08C00000+0x482);
S	  OPx_Readoffset3 =  *((uint8_t *)0X08C00000+0x483);
S	  OPx_offsetchecksum0 = (*((uint8_t *)0X08C00000+0x480))+(*((uint8_t *)0X08C00000+0x481))+(*((uint8_t *)0X08C00000+0x482))+(*((uint8_t *)0X08C00000+0x483));
S	  OPx_offsetchecksum1 = ((*((uint8_t *)0X08C00000+0x484))<<8)|(*((uint8_t *)0X08C00000+0x485));
S    if (( OPx_Readoffset0==0x55 )&&( OPx_Readoffset2==0x55 )&&(OPx_offsetchecksum0==OPx_offsetchecksum1))
S    {
S	      uint32_t tmpreg = 0;
S        /*!< Get the OPAMPx_CSR register value */
S       tmpreg = OPx->OP_CON;
S
S       /*!< Clear the trimming bits */
S       tmpreg &= ( uint32_t ) ~ ( ( OP_CON_TRIMOFFSETN | OP_CON_TRIMOFFSETP ) );
S
S       /*!< Configure the new trimming value */
S       tmpreg |= ( uint32_t ) ( ( OPx_Readoffset3 << OP_CON_TRIMOFFSETN_Pos ) | ( OPx_Readoffset1 << OP_CON_TRIMOFFSETP_Pos ) );
S
S       /*!< Write to OPAMPx_CSR register */
S        OPx->OP_CON = tmpreg;
S        return SUCCESS;
S    }
S    else
S    {
S        return ERROR;
S    }
S}
S
S#endif
N#endif
N/**
N * @}
N */
N/**
N * @}
N */
N
N/**
N * @}
N */
N
N///************************ (C) COPYRIGHT SOC Microelectronics *****END OF FILE****/
