application: use macro to get ADC channel registers

This commit is contained in:
King Kévin 2017-10-09 09:46:11 +02:00
parent 5f3473257d
commit b95994027f
1 changed files with 4 additions and 7 deletions

View File

@ -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