adc.h 1.75 KB
#ifndef ADC_H
#define ADC_H

#include "libwismart.h"
#include "ch.h"

#include "stm32f10x_gpio.h"
#include "stm32f10x_adc.h"

#define DBG(fmt,...)          		if(1){printf("[ADC] "fmt"\r\n", ##__VA_ARGS__);}else{({});}

#define ADCbatt_MIN_VALUE		(0)
#define ADCbatt_MAX_VALUE		(0xfff)
#define ADCbatt_VREF_PLUS		(3300)
#define ADCbatt_VREF_MINUS		(0)

#define ADCsound_MIN_VALUE		(0)
#define ADCsound_MAX_VALUE		(0xfff) /* 12-bit adc */
#define ADCsound_VREF_PLUS		(2800) 	/*  Vref+ is connected with Vdda (3.3v) */
#define ADCsound_VREF_MINUS		(0) 	/*  Vref- is connected with Vssa (0v) */

#define ADCbatt				ADC1
#define ADCbatt_RCC			RCC_APB2Periph_ADC1			/* */
#define ADCbatt_DIVIDER		RCC_PCLK2_Div4				/* Can be 2/4/6/8. PCLK2 runs at 32Mhz, and max ADC clock is 14Mhz */
#define ADCbatt_CHANNEL 	ADC_Channel_12				/* 0/17 */
#define ADCbatt_SAMPLETIME 	ADC_SampleTime_239Cycles5
#define ADCbatt_GPIO_PIN	GPIO_Pin_2
#define ADCbatt_GPIO_PORT	GPIOC
#define ADCbatt_GPIO_RCC	RCC_APB2Periph_GPIOC
#define ADCbatt_GPIO_STR	"PC2"

#define ADCsound			ADC2
#define ADCsound_RCC		RCC_APB2Periph_ADC2			/* */
#define ADCsound_DIVIDER	RCC_PCLK2_Div4				/* Can be 2/4/6/8. PCLK2 runs at 32Mhz, and max ADC clock is 14Mhz */
#define ADCsound_CHANNEL 	ADC_Channel_11				/* 0/17 */
#define ADCsound_SAMPLETIME ADC_SampleTime_239Cycles5
#define ADCsound_GPIO_PIN	GPIO_Pin_2
#define ADCsound_GPIO_PORT	GPIOA
#define ADCsound_GPIO_RCC	RCC_APB2Periph_GPIOA
#define ADCsound_GPIO_STR	"PA2"

void adc_batt_init(void);
uint32_t adc_batt_process(void);
uint16_t adc_batt_read(void);
void adc_batt_peripheralInit(void);

void adc_sound_init(void);
uint32_t adc_sound_process(void);
uint16_t adc_sound_read(void);
void adc_sound_peripheralInit(void);

#endif