drivers: adc: STM32 Add common path
Enable common path for internal voltage voltage reference source. Signed-off-by: Eug Krashtan <eug.krashtan@gmail.com>
This commit is contained in:
parent
2b8c123a3b
commit
c045cbd336
1 changed files with 28 additions and 0 deletions
|
@ -202,6 +202,11 @@ static const uint32_t table_samp_time[] = {
|
|||
};
|
||||
#endif
|
||||
|
||||
/* Bugfix for STM32G4 HAL */
|
||||
#if !defined(ADC_CHANNEL_TEMPSENSOR)
|
||||
#define ADC_CHANNEL_TEMPSENSOR ADC_CHANNEL_TEMPSENSOR_ADC1
|
||||
#endif
|
||||
|
||||
/* External channels (maximum). */
|
||||
#define STM32_CHANNEL_COUNT 20
|
||||
|
||||
|
@ -461,6 +466,10 @@ static int adc_stm32_read_async(const struct device *dev,
|
|||
|
||||
static int adc_stm32_check_acq_time(uint16_t acq_time)
|
||||
{
|
||||
if (acq_time == ADC_ACQ_TIME_MAX) {
|
||||
return ARRAY_SIZE(acq_time_tbl) - 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (acq_time == ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS,
|
||||
acq_time_tbl[i])) {
|
||||
|
@ -476,6 +485,20 @@ static int adc_stm32_check_acq_time(uint16_t acq_time)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable internal voltage reference source
|
||||
*/
|
||||
static void adc_stm32_set_common_path(const struct device *dev)
|
||||
{
|
||||
const struct adc_stm32_cfg *config =
|
||||
(const struct adc_stm32_cfg *)dev->config;
|
||||
ADC_TypeDef *adc = (ADC_TypeDef *)config->base;
|
||||
(void) adc; /* Avoid 'unused variable' warning for some families */
|
||||
|
||||
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(adc),
|
||||
LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
}
|
||||
|
||||
static void adc_stm32_setup_speed(const struct device *dev, uint8_t id,
|
||||
uint8_t acq_time_index)
|
||||
{
|
||||
|
@ -544,6 +567,11 @@ static int adc_stm32_channel_setup(const struct device *dev,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (channel_cfg->channel_id == ADC_CHANNEL_TEMPSENSOR ||
|
||||
channel_cfg->channel_id == ADC_CHANNEL_VREFINT) {
|
||||
adc_stm32_set_common_path(dev);
|
||||
}
|
||||
|
||||
adc_stm32_setup_speed(dev, channel_cfg->channel_id,
|
||||
acq_time_index);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue