#ifndef __LKS32MC09X_OPA_H__
#define __LKS32MC09X_OPA_H__

#include "lks32mc09x_reg.h"

#define OPA_CHANNEL_0 0 ///< 运放0
#define OPA_CHANNEL_1 1 ///< 运放1
#define OPA_CHANNEL_2 2 ///< 运放2
#define OPA_CHANNEL_3 3 ///< 运放3
/**
 * @brief OPA初始化结构体句柄，初始化时请定义该句柄，并用其它地址来传参
 */
typedef struct
{
    uint32_t OPA_IT;    ///< 运放偏置电流调节
    uint32_t OPA_Gain;  ///< 运放闭环增益
    uint32_t OPA_CLEna; ///< 运放闭环使能: Enable, Disable
} OPA_InitTypeDef;

/**
 * @brief OPA 增益(4个运放可以独立设置)
 */
#define OPA_GAIN_33 0x00 ///< 反馈电阻660k:20k
#define OPA_GAIN_16 0x01 ///< 反馈电阻640k:40k
#define OPA_GAIN_8  0x02 ///< 反馈电阻320k:40k
#define OPA_GAIN_4  0x03 ///< 反馈电阻160k:40k

/**
 * @brief OPA 偏置电流(4个运放共用同一个偏置电流)
 */
#define OPA_IT_1_0 0x00 ///< OPA 偏置电流×1
#define OPA_IT_1_2 0x01 ///< OPA 偏置电流×1.2
#define OPA_IT_1_5 0x02 ///< OPA 偏置电流×1.5
#define OPA_IT_2_0 0x03 ///< OPA 偏置电流×2

/**
 * @brief OPA_OUT_CMP信号来源配置
 */
#define OPA_OUT_CMP_OUT0P 0x00 ///< 将OPA0输出正端输出到OPA_OUT_CMP
#define OPA_OUT_CMP_OUT1P 0x01 ///< 将OPA1输出正端输出到OPA_OUT_CMP
#define OPA_OUT_CMP_OUT2P 0x02 ///< 将OPA2输出正端输出到OPA_OUT_CMP
#define OPA_OUT_CMP_OUT3P 0x03 ///< 将OPA3输出正端输出到OPA_OUT_CMP
#define OPA_OUT_CMP_OUT0N 0x04 ///< 将OPA0输出负端输出到OPA_OUT_CMP
#define OPA_OUT_CMP_OUT1N 0x05 ///< 将OPA1输出负端输出到OPA_OUT_CMP
#define OPA_OUT_CMP_OUT2N 0x06 ///< 将OPA2输出负端输出到OPA_OUT_CMP
#define OPA_OUT_CMP_OUT3N 0x07 ///< 将OPA3输出负端输出到OPA_OUT_CMP
/**
 * @brief OPA 使能
 * @param OPA_CHANNEL_x OPA通道
 */
void OPA_Enable(uint32_t OPA_CHANNEL_x);
/**
 * @brief OPA 失能
 * @param OPA_CHANNEL_x OPA通道
 */
void OPA_Disable(uint32_t OPA_CHANNEL_x);
/**
 * @brief OPA 增益设置
 * @param OPA_CHANNEL_x OPA通道
 * @param OPA_GAIN_x OPA增益
 */
void OPA_SetGain(uint32_t OPA_CHANNEL_x, uint32_t OPA_GAIN_x);
/**
 * @brief OPA 偏置电流设置
 * @param OPA_CHANNEL_x OPA通道
 * @param OPA_IT_x OPA偏置电流
 */
void OPA_SetIt(uint32_t OPA_IT_x);
/**
 * @brief OPA 输出信号选择（使能输出到GPIO）
 * @param OPA_OUT_CMP_x OPA_OUT_CMP信号来源配置
 * @param Out2Gpio OPA_OUT_CMP输出到IO使能，P2.7
 */
void OPA_OutCmpSignal(uint32_t OPA_OUT_CMP_x, uint32_t Out2Gpio);
#endif
