rt-thread/bsp/essemi/es8p508x/libraries/Library/Include/lib_adc.h

240 lines
6.9 KiB
C
Raw Normal View History

2019-11-07 10:00:14 +08:00
/***************************************************************
*Copyright (C), 2017, Shanghai Eastsoft Microelectronics Co., Ltd
*<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lib_timer.c
*<EFBFBD><EFBFBD> <EFBFBD>ߣ<EFBFBD> Liut
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> V1.00
*<EFBFBD><EFBFBD> <EFBFBD>ڣ<EFBFBD> 2017/07/14
*<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ADCģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*<EFBFBD><EFBFBD> ע<EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ES8P508xоƬ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧϰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾʹ<EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><EFBFBD>ջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><EFBFBD>κη<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ρ<EFBFBD>
***************************************************************/
#ifndef __LIBADC_H__
#define __LIBADC_H__
#include "ES8P508x.h"
#include "type.h"
/* <20>ڲ<EFBFBD><DAB2>ο<EFBFBD><CEBF><EFBFBD>ѹѡ<D1B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BFBD>ο<EFBFBD><CEBF><EFBFBD>ѹ<EFBFBD><D1B9>VDD<44><44>ѹ
ADC_VrefP_Exter = 0x3 , //<2F><><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD><CEBF><EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD>ⲿ<EFBFBD>ο<EFBFBD><CEBF><EFBFBD>ѹ
}ADC_TYPE_VREFP;
/* <20><><EFBFBD><EFBFBD>ģʽѡ<CABD><D1A1> */
typedef enum
{
ADC_SMPS_SOFT = 0, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
ADC_SMPS_HARD = 1, /* Ӳ<><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
}ADC_TYPE_SMPS;
/* ת<><D7AA><EFBFBD>ٶ<EFBFBD>ѡ<EFBFBD><D1A1> */
typedef enum
{
ADC_ConvSpeed_Low = 0x0 , //ADת<44><D7AA><EFBFBD>ٶȣ<D9B6><C8A3><EFBFBD><EFBFBD><EFBFBD>
ADC_ConvSpeed_High = 0x1 , //ADת<44><D7AA><EFBFBD>ٶȣ<D9B6><C8A3><EFBFBD><EFBFBD><EFBFBD>
}ADC_TYPE_HSEN;
/* ADCͨ<43><CDA8>ѡ<EFBFBD><D1A1> */
typedef enum
{
ADC_CHS_AIN0 = 0, /* ͨ<><CDA8> 0 */
ADC_CHS_AIN1 = 1, /* ͨ<><CDA8> 1 */
ADC_CHS_AIN2 = 2, /* ͨ<><CDA8> 2 */
ADC_CHS_AIN3 = 3, /* ͨ<><CDA8> 3 */
ADC_CHS_AIN4 = 4, /* ͨ<><CDA8> 4 */
ADC_CHS_AIN5 = 5, /* ͨ<><CDA8> 5 */
ADC_CHS_AIN6 = 6, /* ͨ<><CDA8> 6 */
ADC_CHS_AIN7 = 7, /* ͨ<><CDA8> 7 */
ADC_CHS_AIN8 = 8, /* ͨ<><CDA8> 8 */
ADC_CHS_AIN9 = 9, /* ͨ<><CDA8> 9 */
ADC_CHS_AIN10 = 10, /* ͨ<><CDA8> 10 */
ADC_CHS_AIN11 = 11, /* ͨ<><CDA8> 11 */
ADC_CHS_AIN12 = 12, /* ͨ<><CDA8> 12 */
ADC_CHS_AIN13 = 13, /* ͨ<><CDA8> 13 */
ADC_CHS_AIN14 = 14, /* ͨ<><CDA8> 14 */
ADC_CHS_AIN15 = 15, /* ͨ<><CDA8> 15 */
}ADC_TYPE_CHS;
/*ADC core<72><65><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>λ*/
typedef enum
{
ADC_LP_86ua = 2, //ADC Core <20><><EFBFBD><EFBFBD>Ϊ86<38><36><EFBFBD>Ƽ<EFBFBD>ʹ<EFBFBD><CAB9>
ADC_LP_215ua = 0, //ADC Core <20><><EFBFBD><EFBFBD>Ϊ215uA
ADC_LP_120ua = 1, //ADC Core <20><><EFBFBD><EFBFBD>Ϊ120uA
ADC_LP_70ua = 3, //ADC Core <20><><EFBFBD><EFBFBD>Ϊ70uA
}ADC_TYPE_BUFLP;
/*ADC <20><><EFBFBD><EFBFBD>buff<66><66><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>λ*/
typedef enum
{
ADC_BUFF_0ua = 0, //ADC <20><><EFBFBD><EFBFBD>buff<66><66><EFBFBD><EFBFBD>Ϊ0uA<75><41><EFBFBD>Ƽ<EFBFBD>ʹ<EFBFBD><CAB9>
ADC_BUFF_34ua = 1, //ADC <20><><EFBFBD><EFBFBD>buff<66><66><EFBFBD><EFBFBD>Ϊ34uA
ADC_BUFF_95ua = 2, //ADC <20><><EFBFBD><EFBFBD>buff<66><66><EFBFBD><EFBFBD>Ϊ95uA
}ADC_TYPE_BUFEN;
/* ADC IF ״̬ */
typedef enum
{
ADC_IF = 0x01,
ADC_IF_ACPMIN = 0x02,
ADC_IF_ACPMAX =0x04,
ADC_IF_ACPOVER = 0x08,
}ADC_TYPE_IF;
/* ADC IE ״̬ */
typedef enum
{
ADC_IE = 0x01,
ADC_IE_ACPMIN = 0x02,
ADC_IE_ACPMAX =0x04,
ADC_IE_ACPOVER = 0x08,
}ADC_TYPE_IE;
/* ADC<44><43>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ýṹ<C3BD><EFBFBD><E5B6A8> */
typedef struct
{
ADC_TYPE_CLKS ADC_ClkS; //ADCCON1:bit3 ADCʱ<43><CAB1>Դѡ<D4B4><D1A1>
ADC_TYPE_CLKDIV ADC_ClkDiv; //ADCCON1:bit2-0 ADCʱ<43><CAB1>ԴԤ<D4B4><D4A4>Ƶ
ADC_TYPE_VREFP ADC_VrefP; //ADCCON1:bit9-8 ADC<44><43><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD><CEBF><EFBFBD>ѹѡ<D1B9><D1A1>
ADC_TYPE_SMPS ADC_SampS; //ADCCON1:bit12 ADC<44><43><EFBFBD><EFBFBD>ģʽѡ<CABD><D1A1>
ADC_TYPE_CHS ADC_ChS; //ADCCHS:bit0-3 ADCģ<43><C4A3>ͨ<EFBFBD><CDA8>ѡ<EFBFBD><D1A1>
//ADC_TYPE_VREF_SEL VREF_SEL; //<2F>ο<EFBFBD><CEBF><EFBFBD>ѹѡ<D1B9><D1A1>
uint8_t ST; //Ӳ<><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽΪӲ<CEAA><D3B2>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>) 0~31
TYPE_FUNCEN ADC_VREFN; //<2F><><EFBFBD><EFBFBD><EFBFBD>ο<EFBFBD><CEBF><EFBFBD>ѹѡ<D1B9><D1A1>λ
TYPE_FUNCEN ADC_VRBUF_EN;
}ADC_InitStruType;
/* <20>Զ<EFBFBD><D4B6>Ƚϵͷ<CFB5>ֵ ѡ<><D1A1>*/
typedef enum
{
ADC_ACP_MIN_MIN = 0x0, /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD>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BD><CAB1>Դ */
typedef enum
{
ADC_ACPC_CLKS_PCLK = 0, /* PCLK */
ADC_ACPC_CLKS_LRC = 1, /* LRC(32KHz) */
}ADC_TYPE_ACPC_CLKS;
typedef FuncState ADC_TYPE_CHOP_EN1, ADC_TYPE_CHOP_EN;
typedef FuncState ADC_TYPE_VREF_EN,ADC_TYPE_IREF_EN;
typedef FuncState ADC_TYPE_EN,ADC_TYPE_ACP_EN;
/* <20>Զ<EFBFBD><D4B6>ȽϹ<C8BD><CFB9>ܳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><E1B9B9>*/
typedef struct
{
ADC_TYPE_ACP_EN ACP_EN; /* <20>Զ<EFBFBD><D4B6>ȽϹ<C8BD><CFB9><EFBFBD>ʹ<EFBFBD><CAB9>λ*/
uint16_t ACPC_OVER_TIME; /* <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>(<28><>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ó<EFBFBD>0) 0~0x9c3 */
ADC_TYPE_ACPC_TIMES ACPC_TIMES; /* <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6>Ƚϴ<C8BD><CFB4><EFBFBD>(<28><><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>) */
uint16_t ACPC_MIN_TARGET; /* ƽ<><C6BD>ֵ<EFBFBD><D6B5><EFBFBD>ͷ<EFBFBD>ֵ (<28><><EFBFBD><EFBFBD>0xfff<66>ر<EFBFBD>) 0~0xfff */
uint16_t ACPC_MAX_TARGET; /* ƽ<><C6BD>ֵ<EFBFBD><D6B5><EFBFBD>߷<EFBFBD>ֵ (<28><><EFBFBD><EFBFBD>0x0<78>ر<EFBFBD>) 0~0xfff */
}ADC_ACP_TypeDef;
/************ADCģ<43><C4A3><EFBFBD><EFBFBD><EAB6A8>***********/
/* ADCʹ<43>ܿ<EFBFBD><DCBF><EFBFBD> */
#define ADC_Enable() (ADC->CON0.EN = 0x1)
#define ADC_Disable() (ADC->CON0.EN = 0x0)
/* <20>Զ<EFBFBD><D4B6>ȽϹ<C8BD><CFB9><EFBFBD>ʹ<EFBFBD><CAB9>*/
#define ADC_ACP_Enable() (ADC->CON0.ACP_EN = 1)
#define ADC_ACP_Disable() (ADC->CON0.ACP_EN = 0)
/* ADC<44><43>ʼת<CABC><D7AA> */
#define ADC_Start() (ADC->CON0.TRIG = 0x1)
/* ADC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define ADC_SampStart() (ADC->CON1.SMPON = 0x1)
#define ADC_SampStop() (ADC->CON1.SMPON = 0x0)
/* ADC VDD<44><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define ADC_VDD5_FLAG_Enable() (ADC->CHS.VDD5_FLAG_EN = 0x1)
#define ADC_VDD5_FLAG_Disable() (ADC->CHS.VDD5_FLAG_EN = 0x0)
/* ADC<44>ж<EFBFBD>ʹ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD> */
#define ADC_IE_Enable() (ADC->IE.IE = 0x1)
#define ADC_IE_Disable() (ADC->IE.IE = 0x0)
#define ADC_ACPMINIE_Enable() (ADC->IE.ACPMINIE = 1)
#define ADC_ACPMINIE_Disable() (ADC->IE.ACPMINIE = 0)
#define ADC_ACPMAXIE_Enable() (ADC->IE.ACPMAXIE = 1)
#define ADC_ACPMAXIE_Disable() (ADC->IE.ACPMAXIE = 0)
#define ADC_ACPOVIE_Enable() (ADC->IE.ACPOVIE = 1)
#define ADC_ACPOVIE_Disable() (ADC->IE.ACPOVIE = 0)
/************ADCģ<43><EFBFBD><E9BAAF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>***********/
void ADC_Init(ADC_InitStruType * ADC_InitStruct);
void ADC_Set_CH(ADC_TYPE_CHS AdcCH);
uint16_t ADC_GetConvValue(void);
FlagStatus ADC_GetConvStatus(void);
ErrorStatus ADC_ACPConfig(ADC_ACP_TypeDef *ADC_ACP_InitStruct);
ErrorStatus ADC_SoftStart(void);
ErrorStatus ADC_SoftStop(void);
uint16_t ADC_GetACPMeanValue(void);
uint16_t ADC_GetACPMinValue(void);
uint16_t ADC_GetACPMaxValue(void);
FlagStatus ADC_GetFlagStatus(ADC_TYPE_IF IFName);
ITStatus ADC_GetITStatus(ADC_TYPE_IE IEName);
ErrorStatus ADC_ClearIFStatus(ADC_TYPE_IF IFName);
void ADC_Reset(void);
#endif
/*************************END OF FILE**********************/