boards/common/blxxxpill: Add internal ADC lines

This commit is contained in:
Hoernchen20 2020-04-18 16:57:29 +02:00
parent 54822ab5be
commit 4e87682ba1
2 changed files with 21 additions and 7 deletions

View File

@ -74,9 +74,13 @@ extern "C" {
{ .dev = 0, .pin = GPIO_PIN(PORT_A, 7), .chan = 7 }, \
{ .dev = 0, .pin = GPIO_PIN(PORT_B, 0), .chan = 8 }, \
{ .dev = 0, .pin = GPIO_PIN(PORT_B, 1), .chan = 9 }, \
/* ADC Temperature channel */ \
{ .dev = 0, .pin = GPIO_UNDEF, .chan = 16 }, \
/* ADC VREF channel */ \
{ .dev = 0, .pin = GPIO_UNDEF, .chan = 17 }, \
}
#define ADC_NUMOF 10
#define ADC_NUMOF 12
/** @} */
/**

View File

@ -57,10 +57,22 @@ static inline void prep(adc_t line)
{
mutex_lock(&locks[adc_config[line].dev]);
periph_clk_en(APB2, (RCC_APB2ENR_ADC1EN << adc_config[line].dev));
/* check if this channel is an internal ADC channel, if so
* enable the internal temperature and Vref */
if (adc_config[line].chan == 16 || adc_config[line].chan == 17) {
dev(line)->CR2 |= ADC_CR2_TSVREFE;
}
}
static inline void done(adc_t line)
{
/* check if this channel is an internal ADC channel, if so
* disable the internal temperature and Vref */
if (adc_config[line].chan == 16 || adc_config[line].chan == 17) {
dev(line)->CR2 &= ~ADC_CR2_TSVREFE;
}
periph_clk_dis(APB2, (RCC_APB2ENR_ADC1EN << adc_config[line].dev));
mutex_unlock(&locks[adc_config[line].dev]);
}
@ -78,7 +90,9 @@ int adc_init(adc_t line)
prep(line);
/* configure the pin */
gpio_init_analog(adc_config[line].pin);
if (adc_config[line].pin != GPIO_UNDEF) {
gpio_init_analog(adc_config[line].pin);
}
/* set clock prescaler to get the maximal possible ADC clock value */
for (clk_div = 2; clk_div < 8; clk_div += 2) {
if ((CLOCK_CORECLOCK / clk_div) <= MAX_ADC_SPEED) {
@ -109,15 +123,11 @@ int adc_init(adc_t line)
/* start sampling from software */
dev(line)->CR2 |= ADC_CR2_EXTTRIG | ADC_CR2_EXTSEL;
/* check if this channel is an internal ADC channel, if so
* enable the internal temperature and Vref */
/* check if the internal channels are configured to use ADC1 */
if (adc_config[line].chan == 16 || adc_config[line].chan == 17) {
/* check if the internal channels are configured to use ADC1 */
if (dev(line) != ADC1) {
return -3;
}
dev(line)->CR2 |= ADC_CR2_TSVREFE;
}
/* free the device again */