/*
 * @Author       : stark1898y 1658608470@qq.com
 * @Date         : 2024-09-13 13:05:36
 * @LastEditors  : stark1898y 1658608470@qq.com
 * @LastEditTime : 2024-09-13 13:05:37
 * @FilePath     : \JT-DT-YD4N02A_RTT_MRS\bsp\inc\bsp_adc.h
 * @Description  :
 *
 * Copyright (c) 2024 by yzy, All Rights Reserved.
 */
#ifndef __BSP_ADC_H__
#define __BSP_ADC_H__

#include "board.h"

//#define TEST_BSP_ADC

#define GAS_POWER_SWITCH_GPIO_PIN  GPIO_Pin_9
#define GAS_POWER_SWITCH_GPIO_PORT GPIOC

#define GAS_POWER_OPEN         GPIO_WriteBit(GAS_POWER_SWITCH_GPIO_PORT, GAS_POWER_SWITCH_GPIO_PIN, Bit_SET)    
#define GAS_POWER_CLOSE        GPIO_WriteBit(GAS_POWER_SWITCH_GPIO_PORT, GAS_POWER_SWITCH_GPIO_PIN, Bit_RESET)
// ADC要采集的通道个数
#define NUM_OF_CHANNEL              (2U)
// ADC要采集的次数
#define ADC_TIMES                   (30U)
#define ADC_BUFFER_SIZE             (NUM_OF_CHANNEL * ADC_TIMES)

// ADC GPIO 宏定义
#define USED_ADC_GPIO_PORT          GPIOA
#define USED_ADC_GPIO_CLK_ENABLE()  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE)

// ADC 序号宏定义
#define USED_ADC                    ADC1
#define USED_ADC_CLK_ENABLE()       RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

// ADC DMA 通道宏定义，这里我们使用DMA传输
#define USED_ADC_DR_ADDRESS         ((uint32_t)&USED_ADC->RDATAR)
#define USED_ADC_DMA_CLK_ENABLE()   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
#define USED_ADC_DMA_STREAM         DMA1_Channel1

/***************************12V输入的检测，用来实现掉电检测****************************/
#define VIN_ADC_GPIO_PIN               GPIO_Pin_0
#define VIN_ADC_CHANNEL                ADC_Channel_0

#define GAS_ADC_GPIO_PIN               GPIO_Pin_5
#define GAS_ADC_GPIO_PORT              GPIOC
#define GAS_ADC_CHANNEL                ADC_Channel_15
typedef enum
{
    kVinAdc = 0U,
    kGasAdc,
} TeAdcIndex;

// 存储采集的数据
extern uint16_t adc_buffer[ADC_BUFFER_SIZE];

int BSP_ADC_Init(void);

float Get_ADC_Average(TeAdcIndex index);
float Get_ADC_Voltage(TeAdcIndex index);


#endif // !__BSP_ADC_H__
