From b95994027f14d85f6da1a7a91e9404839cb389bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 9 Oct 2017 09:46:11 +0200 Subject: [PATCH] application: use macro to get ADC channel registers --- application.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/application.c b/application.c index f446df4..0862e24 100644 --- a/application.c +++ b/application.c @@ -78,10 +78,7 @@ volatile bool photoresistor_flag = false; /**< flag set when ambient luminosity /** @defgroup photoresistor_adc ADC used to ambient luminosity * @{ */ -#define PHOTORESISTOR_ADC_CHANNEL ADC_CHANNEL1 /**< ADC channel */ -#define PHOTORESISTOR_PORT GPIOA /**< port on which the battery is connected */ -#define PHOTORESISTOR_PORT_RCC RCC_GPIOA /**< timer port peripheral clock */ -#define PHOTORESISTOR_PIN GPIO1 /**< pin of the port on which the battery is connected */ +#define PHOTORESISTOR_ADC_CHANNEL 1 /**< ADC channel */ /** @} */ /** RGB values for the WS2812B clock LEDs */ @@ -443,8 +440,8 @@ void main(void) // setup ADC to photo-resistor voltage printf("setup brightness sensor: "); - rcc_periph_clock_enable(PHOTORESISTOR_PORT_RCC); // enable clock for photo-resistor GPIO peripheral - gpio_set_mode(PHOTORESISTOR_PORT, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, PHOTORESISTOR_PIN); // set photo-resistor GPIO as analogue input for the ADC + rcc_periph_clock_enable(RCC_ADC12_IN(PHOTORESISTOR_ADC_CHANNEL)); // enable clock for photo-resistor GPIO peripheral + gpio_set_mode(ADC12_IN_PORT(PHOTORESISTOR_ADC_CHANNEL), GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, ADC12_IN_PIN(PHOTORESISTOR_ADC_CHANNEL)); // set photo-resistor GPIO as analogue input for the ADC rcc_periph_clock_enable(RCC_ADC1); // enable clock for ADC peripheral adc_off(ADC1); // switch off ADC while configuring it // configuration is correct per default @@ -466,7 +463,7 @@ void main(void) while (!adc_eoc(ADC1)); // wait until conversion finished uint16_t ref_value = adc_read_regular(ADC1); // read internal reference 1.2V voltage value // now use interrupts to only measure ambient luminosity - channels[0] = PHOTORESISTOR_ADC_CHANNEL; // only measure ambient luminosity + channels[0] = ADC_CHANNEL(PHOTORESISTOR_ADC_CHANNEL); // only measure ambient luminosity adc_set_regular_sequence(ADC1, 1, channels); // set now group adc_enable_eoc_interrupt(ADC1); // enable interrupt for end of conversion nvic_enable_irq(NVIC_ADC1_2_IRQ); // enable ADC interrupts