mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-22 17:12:55 +08:00
260 lines
5.6 KiB
C
260 lines
5.6 KiB
C
|
/********************************** (C) COPYRIGHT *******************************
|
|||
|
* File Name : CH57x_adc.h
|
|||
|
* Author : WCH
|
|||
|
* Version : V1.2
|
|||
|
* Date : 2021/11/17
|
|||
|
* Description
|
|||
|
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
|
|||
|
* SPDX-License-Identifier: Apache-2.0
|
|||
|
*******************************************************************************/
|
|||
|
|
|||
|
#ifndef __CH58x_ADC_H__
|
|||
|
#define __CH58x_ADC_H__
|
|||
|
|
|||
|
#ifdef __cplusplus
|
|||
|
extern "C" {
|
|||
|
#endif
|
|||
|
|
|||
|
#define ROM_CFG_TMP_25C 0x7F014
|
|||
|
|
|||
|
/**
|
|||
|
* @brief adc single channel define
|
|||
|
*/
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
CH_EXTIN_0 = 0, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 0
|
|||
|
CH_EXTIN_1, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 1
|
|||
|
CH_EXTIN_2, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 2
|
|||
|
CH_EXTIN_3, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 3
|
|||
|
CH_EXTIN_4, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 4
|
|||
|
CH_EXTIN_5, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 5
|
|||
|
CH_EXTIN_8 = 8, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 8
|
|||
|
CH_EXTIN_9, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 9
|
|||
|
CH_EXTIN_12 = 12, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 12
|
|||
|
CH_EXTIN_13, // ADC <20>ⲿģ<E2B2BF><C4A3>ͨ<EFBFBD><CDA8> 13
|
|||
|
|
|||
|
CH_INTE_VBAT = 14, // ADC <20>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>ؼ<EFBFBD><D8BC><EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
CH_INTE_VTEMP = 15, // ADC <20>ڲ<EFBFBD><DAB2>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
|
|||
|
|
|||
|
} ADC_SingleChannelTypeDef;
|
|||
|
|
|||
|
/**
|
|||
|
* @brief adc differential channel define
|
|||
|
*/
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
CH_DIFF_0_2 = 0, // ADC <20><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8> #0-#2
|
|||
|
CH_DIFF_1_3, // ADC <20><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8> #1-#3
|
|||
|
|
|||
|
} ADC_DiffChannelTypeDef;
|
|||
|
|
|||
|
/**
|
|||
|
* @brief adc sampling clock
|
|||
|
*/
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
SampleFreq_3_2 = 0, // 3.2M <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>
|
|||
|
SampleFreq_8, // 8M <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>
|
|||
|
SampleFreq_5_33, // 5.33M <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>
|
|||
|
SampleFreq_4, // 4M <20><><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>
|
|||
|
} ADC_SampClkTypeDef;
|
|||
|
|
|||
|
/**
|
|||
|
* @brief adc signal PGA
|
|||
|
*/
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
ADC_PGA_1_4 = 0, // -12dB, 1/4<><34>
|
|||
|
ADC_PGA_1_2, // -6dB, 1/2<><32>
|
|||
|
ADC_PGA_0, // 0dB, 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
ADC_PGA_2, // 6dB, 2<><32>
|
|||
|
} ADC_SignalPGATypeDef;
|
|||
|
|
|||
|
/**
|
|||
|
* @brief Configuration DMA mode
|
|||
|
*/
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
ADC_Mode_Single = 0, // <20><><EFBFBD><EFBFBD>ģʽ
|
|||
|
ADC_Mode_LOOP, // ѭ<><D1AD>ģʽ
|
|||
|
} ADC_DMAModeTypeDef;
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ADC <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param d - refer to ADC_SingleChannelTypeDef
|
|||
|
*/
|
|||
|
#define ADC_ChannelCfg(d) (R8_ADC_CHANNEL = d)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ADC <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param d - refer to ADC_SampClkTypeDef
|
|||
|
*/
|
|||
|
#define ADC_SampClkCfg(d) (R8_ADC_CFG = R8_ADC_CFG & (~RB_ADC_CLK_DIV) | (d << 6))
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD> ADC <EFBFBD>ź<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param d - refer to ADC_SignalPGATypeDef
|
|||
|
*/
|
|||
|
#define ADC_PGACfg(d) (R8_ADC_CFG = R8_ADC_CFG & (~RB_ADC_PGA_GAIN) | (d << 4))
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD>¶ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Уֵ
|
|||
|
*
|
|||
|
* @param d - Уֵ
|
|||
|
*/
|
|||
|
#define ADC_TempCalibCfg(d) (R8_TEM_SENSOR = R8_TEM_SENSOR & (~RB_TEM_SEN_CALIB) | d)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD>ⲿ<EFBFBD>źŵ<EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param sp - refer to ADC_SampClkTypeDef
|
|||
|
* @param ga - refer to ADC_SignalPGATypeDef
|
|||
|
*/
|
|||
|
void ADC_ExtSingleChSampInit(ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD>ⲿ<EFBFBD>źŲ<EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param sp - refer to ADC_SampClkTypeDef
|
|||
|
* @param ga - refer to ADC_SignalPGATypeDef
|
|||
|
*/
|
|||
|
void ADC_ExtDiffChSampInit(ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
void TouchKey_ChSampInit(void);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD>ر<EFBFBD>TouchKey<EFBFBD><EFBFBD>Դ
|
|||
|
*/
|
|||
|
#define TouchKey_DisableTSPower() (R8_TKEY_CFG &= ~RB_TKEY_PWR_ON)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
void ADC_InterTSSampInit(void);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD>ر<EFBFBD><EFBFBD>¶ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
|||
|
*/
|
|||
|
#define ADC_DisableTSPower() (R8_TEM_SENSOR = 0)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ص<EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
void ADC_InterBATSampInit(void);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief ADCִ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @return ADCת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
uint16_t ADC_ExcutSingleConver(void);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴֵ<EFBFBD>,<EFBFBD><EFBFBD>ȡƫ<EFBFBD><EFBFBD>ֵ,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ADC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡУֵ
|
|||
|
*
|
|||
|
* @return ƫ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
signed short ADC_DataCalib_Rough(void);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief TouchKeyת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param charg - Touchkey<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>,5bits<EFBFBD><EFBFBD>Ч, t=charg*Tadc
|
|||
|
* @param disch - Touchkey<EFBFBD>ŵ<EFBFBD>ʱ<EFBFBD><EFBFBD>,3bits<EFBFBD><EFBFBD>Ч, t=disch*Tadc
|
|||
|
*
|
|||
|
* @return <EFBFBD><EFBFBD>ǰTouchKey<EFBFBD><EFBFBD>Ч<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
uint16_t TouchKey_ExcutSingleConver(uint8_t charg, uint8_t disch);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ADC<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param cycle - <EFBFBD><EFBFBD>λΪ 16<EFBFBD><EFBFBD>ϵͳʱ<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
void ADC_AutoConverCycle(uint8_t cycle);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMA<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @param s - <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMA<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
* @param startAddr - DMA <EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD>ַ
|
|||
|
* @param endAddr - DMA <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|||
|
* @param m - <EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMAģʽ
|
|||
|
*/
|
|||
|
void ADC_DMACfg(uint8_t s, uint16_t startAddr, uint16_t endAddr, ADC_DMAModeTypeDef m);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>棩
|
|||
|
*
|
|||
|
* @param ts_v - <EFBFBD><EFBFBD>ǰ<EFBFBD>¶ȴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
*
|
|||
|
* @return ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>棩
|
|||
|
*/
|
|||
|
int ADC_GetCurrentTS(uint16_t ts_v);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ȡADCת<EFBFBD><EFBFBD>ֵ
|
|||
|
*
|
|||
|
* @return ADCת<EFBFBD><EFBFBD>ֵ
|
|||
|
*/
|
|||
|
#define ADC_ReadConverValue() (R16_ADC_DATA)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief ADCִ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
#define ADC_StartUp() (R8_ADC_CONVERT = RB_ADC_START)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ȡADC<EFBFBD>ж<EFBFBD>״̬
|
|||
|
*/
|
|||
|
#define ADC_GetITStatus() (R8_ADC_INT_FLAG & RB_ADC_IF_EOC)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ADC<EFBFBD>жϱ<EFBFBD>־
|
|||
|
*/
|
|||
|
#define ADC_ClearITFlag() (R8_ADC_CONVERT = 0)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ȡADC DMA<EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
|
|||
|
*/
|
|||
|
#define ADC_GetDMAStatus() (R8_ADC_DMA_IF & RB_ADC_IF_DMA_END)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ADC DMA<EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
|
|||
|
*/
|
|||
|
#define ADC_ClearDMAFlag() (R8_ADC_DMA_IF |= RB_ADC_IF_DMA_END)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ADC
|
|||
|
*/
|
|||
|
#define ADC_StartDMA() (R8_ADC_CTRL_DMA |= RB_ADC_AUTO_EN)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief ֹͣ<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ADC
|
|||
|
*/
|
|||
|
#define ADC_StopDMA() (R8_ADC_CTRL_DMA &= ~RB_ADC_AUTO_EN)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD>ȡTouchKey<EFBFBD>ж<EFBFBD>״̬
|
|||
|
*/
|
|||
|
#define TouchKey_GetITStatus() (R8_ADC_INT_FLAG & RB_ADC_IF_EOC)
|
|||
|
|
|||
|
/**
|
|||
|
* @brief <EFBFBD><EFBFBD><EFBFBD><EFBFBD>TouchKey<EFBFBD>жϱ<EFBFBD>־
|
|||
|
*/
|
|||
|
#define TouchKey_ClearITFlag() (R8_TKEY_CTRL |= RB_TKEY_PWR_ON)
|
|||
|
|
|||
|
|
|||
|
#ifdef __cplusplus
|
|||
|
}
|
|||
|
#endif
|
|||
|
|
|||
|
#endif // __CH58x_ADC_H__
|