boards/common/blxxxpill: Add internal ADC lines
This commit is contained in:
parent
54822ab5be
commit
4e87682ba1
@ -74,9 +74,13 @@ extern "C" {
|
|||||||
{ .dev = 0, .pin = GPIO_PIN(PORT_A, 7), .chan = 7 }, \
|
{ .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, 0), .chan = 8 }, \
|
||||||
{ .dev = 0, .pin = GPIO_PIN(PORT_B, 1), .chan = 9 }, \
|
{ .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
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -57,10 +57,22 @@ static inline void prep(adc_t line)
|
|||||||
{
|
{
|
||||||
mutex_lock(&locks[adc_config[line].dev]);
|
mutex_lock(&locks[adc_config[line].dev]);
|
||||||
periph_clk_en(APB2, (RCC_APB2ENR_ADC1EN << 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)
|
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));
|
periph_clk_dis(APB2, (RCC_APB2ENR_ADC1EN << adc_config[line].dev));
|
||||||
mutex_unlock(&locks[adc_config[line].dev]);
|
mutex_unlock(&locks[adc_config[line].dev]);
|
||||||
}
|
}
|
||||||
@ -78,7 +90,9 @@ int adc_init(adc_t line)
|
|||||||
prep(line);
|
prep(line);
|
||||||
|
|
||||||
/* configure the pin */
|
/* configure the pin */
|
||||||
|
if (adc_config[line].pin != GPIO_UNDEF) {
|
||||||
gpio_init_analog(adc_config[line].pin);
|
gpio_init_analog(adc_config[line].pin);
|
||||||
|
}
|
||||||
/* set clock prescaler to get the maximal possible ADC clock value */
|
/* set clock prescaler to get the maximal possible ADC clock value */
|
||||||
for (clk_div = 2; clk_div < 8; clk_div += 2) {
|
for (clk_div = 2; clk_div < 8; clk_div += 2) {
|
||||||
if ((CLOCK_CORECLOCK / clk_div) <= MAX_ADC_SPEED) {
|
if ((CLOCK_CORECLOCK / clk_div) <= MAX_ADC_SPEED) {
|
||||||
@ -109,15 +123,11 @@ int adc_init(adc_t line)
|
|||||||
/* start sampling from software */
|
/* start sampling from software */
|
||||||
dev(line)->CR2 |= ADC_CR2_EXTTRIG | ADC_CR2_EXTSEL;
|
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 */
|
|
||||||
if (adc_config[line].chan == 16 || adc_config[line].chan == 17) {
|
|
||||||
/* check if the internal channels are configured to use ADC1 */
|
/* check if the internal channels are configured to use ADC1 */
|
||||||
|
if (adc_config[line].chan == 16 || adc_config[line].chan == 17) {
|
||||||
if (dev(line) != ADC1) {
|
if (dev(line) != ADC1) {
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev(line)->CR2 |= ADC_CR2_TSVREFE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free the device again */
|
/* free the device again */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user