/*! * \file xc_drv_pga.c * * \brief Target pga implementation * * \copyright Revised BSD License, see section \ref LICENSE. * * \code * * _ __ _ ________ _ * | |/ /(_)___ / ____/ /_ (_)___ * | // / __ \/ / / __ \/ / __ \ * / |/ / / / / /___/ / / / / /_/ / * /_/|_/_/_/ /_/\____/_/ /_/_/ .___/ * /_/ * (C) 2022-2025 XinChip * * \endcode * * \author ( XinChip ) Alex-J * * \author ( XinChip ) */ /*----------------------------------------------------------------------------------- INCLUDE HEADE FILES ------------------------------------------------------------------------------------*/ #include "xc_drv_pga.h" #include "xc60xx.h" #include "xc_reg_cpr.h" /*------------------------------------------------------------------------------------ Macros -------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------ Global Variables -------------------------------------------------------------------------------------*/ /** * @brief xc_pga_init * @details * @param void * @retval void */ void xc_pga_init(PGA_InitCfg_t *pga_cfg) { /*opa level 1 gain +20DB*/ cpr_opa_ctrl_reg__micgain_2__setf(pga_cfg->gain2); /*opa level 2 gain +22.6DB*/ cpr_opa_ctrl_reg__volr_2__setf(pga_cfg->volr2); /*bias register controls current and difference MIC*/ cpr_opa_ctrl_reg__resadj__setf(pga_cfg->resadj); /*Comparator hysteresis voltage control*/ cpr_opa_ctrl_reg__cmp_ctrl__setf(pga_cfg->cmp_ctrl); /*Comparator current control*/ cpr_opa_ctrl_reg__cmp_ibc__setf(pga_cfg->cmp_ibc); /*temperature sensor*/ cpr_opa_ctrl_reg__en_temp_sensor__setf(pga_cfg->en_temp_sensor); /*open pdbias*/ cpr_opa_ctrl_reg__pdbias__setf(pga_cfg->bias); cpr_opa_ctrl_reg__opa_ctrl__setf(pga_cfg->opa_ctrl); /*opa pd signal*/ cpr_opa_ctrl_reg__pdopa__setf(pga_cfg->pdopa); cpr_opa_ctrl_reg__micgain__setf(pga_cfg->micgain); } /** ******************************************************************************************** * @brief xc_pga_micgain_2_set * @details * @param micgain2 (BIT0) £ºinput First-order gain ( PGA_MIC_GAIN2_ENABLE - PGA_MIC_GAIN2_DISABLE) * @retval void ********************************************************************************************* **/ void xc_pga_micgain_2_set(uint8_t micgain2) { cpr_opa_ctrl_reg__micgain_2__setf(micgain2); } /** ******************************************************************************************** * @brief xc_pga_volr2_set * @details * @param volr2 (BIT0 - BIT3) £ºinput Two-stage gain ( PGA_VOLR2_GAIN_0_0DB - PGA_VOLR2_GAIN_0_0DB) * @retval void ********************************************************************************************* **/ void xc_pga_volr2_set(uint8_t volr2) { cpr_opa_ctrl_reg__volr_2__setf(volr2); } /** ******************************************************************************************** * @brief xc_pga_resadj_set * @details * @param resadj (BIT0 - BIT4) BIT2 -BIT4 :ELECTRICITY (PGA_ELECTRICITY_LEVEL0 - PGA_ELECTRICITY_LEVEL7) BIT1:pga input (SINGLE or PGA_DIFFERENCE) BIT0:unused * @retval void ********************************************************************************************* **/ void xc_pga_resadj_set(uint8_t resadj) { cpr_opa_ctrl_reg__resadj__setf(resadj); } /** ******************************************************************************************** * @brief xc_pga_cmp_ctrl_set * @details * @param cmp_ctrl : CMP_CTRL_VOLTAGE_LEVEL0 - CMP_CTRL_VOLTAGE_LEVEL3 * @retval void ********************************************************************************************* **/ void xc_pga_cmp_ctrl_set(uint8_t cmp_ctrl) { cpr_opa_ctrl_reg__cmp_ctrl__setf(cmp_ctrl); } /** ******************************************************************************************** * @brief xc_pga_cmp_ibc_set * @details * @param cmp_ibc : CMP_IBC_ELECTRICITY_LEVEL0 - CMP_IBC_ELECTRICITY_LEVEL3 * @retval void ********************************************************************************************* **/ void xc_pga_cmp_ibc_set(uint8_t cmp_ibc) { cpr_opa_ctrl_reg__cmp_ibc__setf(cmp_ibc); } /** ******************************************************************************************** * @brief xc_pga_temp_sensor_enable * @details * @param en_temp_sensor : TEMP_SENSOR_ENABLE / TEMP_SENSOR_DISABLE * @retval void ********************************************************************************************* **/ void xc_pga_temp_sensor_enable(uint8_t en_temp_sensor) { cpr_opa_ctrl_reg__en_temp_sensor__setf(en_temp_sensor); } /** ******************************************************************************************** * @brief xc_pga_volr_set * @details unused * @param volr * @retval void ********************************************************************************************* **/ void xc_pga_volr_set(uint8_t volr) { cpr_opa_ctrl_reg__volr__setf(volr); } /** ******************************************************************************************** * @brief xc_pga_pdbias_set * @details * @param pdbias :pdbias signal : 1:PD 0:EN * @retval void ********************************************************************************************* **/ void xc_pga_pdbias_set(uint8_t pdbias) { cpr_opa_ctrl_reg__pdbias__setf(pdbias); } /** ******************************************************************************************** * @brief xc_pga_opa_ctrl_set * @details * @param opa_ctrl (BIT0 - BIT2) BIT2:(pdopa signal : 1:pd 0:en) BIT1:(pdopa signal input swap: 1:enable 0:disable) BIT0:(pdopa CTRL ELECTRICITY: 1:min 0:max) * @retval void ********************************************************************************************* **/ void xc_pga_opa_ctrl_set(uint8_t opa_ctrl) { cpr_opa_ctrl_reg__opa_ctrl__setf(opa_ctrl); } /** ********************************************************************************************** * @brief xc_pga_pdopa_set * @details * @param pdopa signal : 1:pd 0:en * @retval void ********************************************************************************************** */ void xc_pga_pdopa_set(uint8_t pdopa) { cpr_opa_ctrl_reg__pdopa__setf(pdopa); } /** ********************************************************************************************** * @brief xc_pga_micgain_set * @details unused * @param micgain * @retval void ********************************************************************************************** */ void xc_pga_micgain_set(uint8_t micgain) { cpr_opa_ctrl_reg__micgain__setf(micgain); }