mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +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 <20><><EFBFBD><EFBFBD> ADC <20><><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
|
||
*
|
||
* @param d - refer to ADC_SingleChannelTypeDef
|
||
*/
|
||
#define ADC_ChannelCfg(d) (R8_ADC_CHANNEL = d)
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD> ADC <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
||
*
|
||
* @param d - refer to ADC_SampClkTypeDef
|
||
*/
|
||
#define ADC_SampClkCfg(d) (R8_ADC_CFG = R8_ADC_CFG & (~RB_ADC_CLK_DIV) | (d << 6))
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD> ADC <20>ź<EFBFBD><C5BA><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 <20><><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD><EFBFBD>Уֵ
|
||
*
|
||
* @param d - Уֵ
|
||
*/
|
||
#define ADC_TempCalibCfg(d) (R8_TEM_SENSOR = R8_TEM_SENSOR & (~RB_TEM_SEN_CALIB) | d)
|
||
|
||
/**
|
||
* @brief <20>ⲿ<EFBFBD>źŵ<C5BA>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||
*
|
||
* @param sp - refer to ADC_SampClkTypeDef
|
||
* @param ga - refer to ADC_SignalPGATypeDef
|
||
*/
|
||
void ADC_ExtSingleChSampInit(ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga);
|
||
|
||
/**
|
||
* @brief <20>ⲿ<EFBFBD>źŲ<C5BA><C5B2><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||
*
|
||
* @param sp - refer to ADC_SampClkTypeDef
|
||
* @param ga - refer to ADC_SignalPGATypeDef
|
||
*/
|
||
void ADC_ExtDiffChSampInit(ADC_SampClkTypeDef sp, ADC_SignalPGATypeDef ga);
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||
*/
|
||
void TouchKey_ChSampInit(void);
|
||
|
||
/**
|
||
* @brief <20>ر<EFBFBD>TouchKey<65><79>Դ
|
||
*/
|
||
#define TouchKey_DisableTSPower() (R8_TKEY_CFG &= ~RB_TKEY_PWR_ON)
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD><EFBFBD>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||
*/
|
||
void ADC_InterTSSampInit(void);
|
||
|
||
/**
|
||
* @brief <20>ر<EFBFBD><D8B1>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
|
||
*/
|
||
#define ADC_DisableTSPower() (R8_TEM_SENSOR = 0)
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD>õ<EFBFBD><C3B5>ص<EFBFBD>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
|
||
*/
|
||
void ADC_InterBATSampInit(void);
|
||
|
||
/**
|
||
* @brief ADCִ<43>е<EFBFBD><D0B5><EFBFBD>ת<EFBFBD><D7AA>
|
||
*
|
||
* @return ADCת<43><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*/
|
||
uint16_t ADC_ExcutSingleConver(void);
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴֵ<DDB4>,<2C><>ȡƫ<C8A1><C6AB>ֵ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ADC<44><43><EFBFBD><EFBFBD><EFBFBD>ô˺<C3B4><CBBA><EFBFBD><EFBFBD><EFBFBD>ȡУֵ
|
||
*
|
||
* @return ƫ<><C6AB>
|
||
*/
|
||
signed short ADC_DataCalib_Rough(void);
|
||
|
||
/**
|
||
* @brief TouchKeyת<79><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* @param charg - Touchkey<65><79><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>,5bits<74><73>Ч, t=charg*Tadc
|
||
* @param disch - Touchkey<65>ŵ<EFBFBD>ʱ<EFBFBD><CAB1>,3bits<74><73>Ч, t=disch*Tadc
|
||
*
|
||
* @return <20><>ǰTouchKey<65><79>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD>
|
||
*/
|
||
uint16_t TouchKey_ExcutSingleConver(uint8_t charg, uint8_t disch);
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ADC<44><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* @param cycle - <20><>λΪ 16<31><36>ϵͳʱ<CDB3><CAB1>
|
||
*/
|
||
void ADC_AutoConverCycle(uint8_t cycle);
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD><EFBFBD>
|
||
*
|
||
* @param s - <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>DMA<4D><41><EFBFBD><EFBFBD>
|
||
* @param startAddr - DMA <20><>ʼ<EFBFBD><CABC>ַ
|
||
* @param endAddr - DMA <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
||
* @param m - <20><><EFBFBD><EFBFBD>DMAģʽ
|
||
*/
|
||
void ADC_DMACfg(uint8_t s, uint16_t startAddr, uint16_t endAddr, ADC_DMAModeTypeDef m);
|
||
|
||
/**
|
||
* @brief <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>棩
|
||
*
|
||
* @param ts_v - <20><>ǰ<EFBFBD>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||
*
|
||
* @return ת<><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>棩
|
||
*/
|
||
int ADC_GetCurrentTS(uint16_t ts_v);
|
||
|
||
/**
|
||
* @brief <20><>ȡADCת<43><D7AA>ֵ
|
||
*
|
||
* @return ADCת<43><D7AA>ֵ
|
||
*/
|
||
#define ADC_ReadConverValue() (R16_ADC_DATA)
|
||
|
||
/**
|
||
* @brief ADCִ<43>е<EFBFBD><D0B5><EFBFBD>ת<EFBFBD><D7AA>
|
||
*/
|
||
#define ADC_StartUp() (R8_ADC_CONVERT = RB_ADC_START)
|
||
|
||
/**
|
||
* @brief <20><>ȡADC<44>ж<EFBFBD>״̬
|
||
*/
|
||
#define ADC_GetITStatus() (R8_ADC_INT_FLAG & RB_ADC_IF_EOC)
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD>ADC<44>жϱ<D0B6>־
|
||
*/
|
||
#define ADC_ClearITFlag() (R8_ADC_CONVERT = 0)
|
||
|
||
/**
|
||
* @brief <20><>ȡADC DMA<4D><41><EFBFBD><EFBFBD>״̬
|
||
*/
|
||
#define ADC_GetDMAStatus() (R8_ADC_DMA_IF & RB_ADC_IF_DMA_END)
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD>ADC DMA<4D><41><EFBFBD>ɱ<EFBFBD>־
|
||
*/
|
||
#define ADC_ClearDMAFlag() (R8_ADC_DMA_IF |= RB_ADC_IF_DMA_END)
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD> ADC
|
||
*/
|
||
#define ADC_StartDMA() (R8_ADC_CTRL_DMA |= RB_ADC_AUTO_EN)
|
||
|
||
/**
|
||
* @brief ֹͣ<CDA3>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD> ADC
|
||
*/
|
||
#define ADC_StopDMA() (R8_ADC_CTRL_DMA &= ~RB_ADC_AUTO_EN)
|
||
|
||
/**
|
||
* @brief <20><>ȡTouchKey<65>ж<EFBFBD>״̬
|
||
*/
|
||
#define TouchKey_GetITStatus() (R8_ADC_INT_FLAG & RB_ADC_IF_EOC)
|
||
|
||
/**
|
||
* @brief <20><><EFBFBD><EFBFBD>TouchKey<65>жϱ<D0B6>־
|
||
*/
|
||
#define TouchKey_ClearITFlag() (R8_TKEY_CTRL |= RB_TKEY_PWR_ON)
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif
|
||
|
||
#endif // __CH58x_ADC_H__
|