application: use macro to get ADC channel registers
This commit is contained in:
parent
5f3473257d
commit
b95994027f
|
@ -78,10 +78,7 @@ volatile bool photoresistor_flag = false; /**< flag set when ambient luminosity
|
||||||
/** @defgroup photoresistor_adc ADC used to ambient luminosity
|
/** @defgroup photoresistor_adc ADC used to ambient luminosity
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define PHOTORESISTOR_ADC_CHANNEL ADC_CHANNEL1 /**< ADC channel */
|
#define PHOTORESISTOR_ADC_CHANNEL 1 /**< 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 */
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/** RGB values for the WS2812B clock LEDs */
|
/** RGB values for the WS2812B clock LEDs */
|
||||||
|
@ -443,8 +440,8 @@ void main(void)
|
||||||
|
|
||||||
// setup ADC to photo-resistor voltage
|
// setup ADC to photo-resistor voltage
|
||||||
printf("setup brightness sensor: ");
|
printf("setup brightness sensor: ");
|
||||||
rcc_periph_clock_enable(PHOTORESISTOR_PORT_RCC); // enable clock for photo-resistor GPIO peripheral
|
rcc_periph_clock_enable(RCC_ADC12_IN(PHOTORESISTOR_ADC_CHANNEL)); // 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
|
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
|
rcc_periph_clock_enable(RCC_ADC1); // enable clock for ADC peripheral
|
||||||
adc_off(ADC1); // switch off ADC while configuring it
|
adc_off(ADC1); // switch off ADC while configuring it
|
||||||
// configuration is correct per default
|
// configuration is correct per default
|
||||||
|
@ -466,7 +463,7 @@ void main(void)
|
||||||
while (!adc_eoc(ADC1)); // wait until conversion finished
|
while (!adc_eoc(ADC1)); // wait until conversion finished
|
||||||
uint16_t ref_value = adc_read_regular(ADC1); // read internal reference 1.2V voltage value
|
uint16_t ref_value = adc_read_regular(ADC1); // read internal reference 1.2V voltage value
|
||||||
// now use interrupts to only measure ambient luminosity
|
// 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_set_regular_sequence(ADC1, 1, channels); // set now group
|
||||||
adc_enable_eoc_interrupt(ADC1); // enable interrupt for end of conversion
|
adc_enable_eoc_interrupt(ADC1); // enable interrupt for end of conversion
|
||||||
nvic_enable_irq(NVIC_ADC1_2_IRQ); // enable ADC interrupts
|
nvic_enable_irq(NVIC_ADC1_2_IRQ); // enable ADC interrupts
|
||||||
|
|
Loading…
Reference in New Issue