[drv_adc.c]Fix ADC channel Configuration bug for SMT32F0/L0/H7
This commit is contained in:
parent
3e8c03e934
commit
d211a27aff
|
@ -122,16 +122,23 @@ static rt_uint32_t stm32_adc_get_channel(rt_uint32_t channel)
|
||||||
case 15:
|
case 15:
|
||||||
stm32_channel = ADC_CHANNEL_15;
|
stm32_channel = ADC_CHANNEL_15;
|
||||||
break;
|
break;
|
||||||
|
#ifdef ADC_CHANNEL_16
|
||||||
case 16:
|
case 16:
|
||||||
stm32_channel = ADC_CHANNEL_16;
|
stm32_channel = ADC_CHANNEL_16;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case 17:
|
case 17:
|
||||||
stm32_channel = ADC_CHANNEL_17;
|
stm32_channel = ADC_CHANNEL_17;
|
||||||
break;
|
break;
|
||||||
#if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4)
|
#ifdef ADC_CHANNEL_18
|
||||||
case 18:
|
case 18:
|
||||||
stm32_channel = ADC_CHANNEL_18;
|
stm32_channel = ADC_CHANNEL_18;
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
|
#ifdef ADC_CHANNEL_19
|
||||||
|
case 19:
|
||||||
|
stm32_channel = ADC_CHANNEL_19;
|
||||||
|
break;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,10 +157,22 @@ static rt_err_t stm32_get_adc_value(struct rt_adc_device *device, rt_uint32_t ch
|
||||||
|
|
||||||
rt_memset(&ADC_ChanConf, 0, sizeof(ADC_ChanConf));
|
rt_memset(&ADC_ChanConf, 0, sizeof(ADC_ChanConf));
|
||||||
|
|
||||||
#if defined(SOC_SERIES_STM32F1)
|
#ifndef ADC_CHANNEL_16
|
||||||
|
if (channel == 16)
|
||||||
|
{
|
||||||
|
LOG_E("ADC channel must not be 16.");
|
||||||
|
return -RT_ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ADC channel number is up to 17 */
|
||||||
|
#if !defined(ADC_CHANNEL_18)
|
||||||
if (channel <= 17)
|
if (channel <= 17)
|
||||||
#elif defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) \
|
/* ADC channel number is up to 19 */
|
||||||
|| defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0)
|
#elif defined(ADC_CHANNEL_19)
|
||||||
|
if (channel <= 19)
|
||||||
|
/* ADC channel number is up to 18 */
|
||||||
|
#else
|
||||||
if (channel <= 18)
|
if (channel <= 18)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@ -162,10 +181,11 @@ static rt_err_t stm32_get_adc_value(struct rt_adc_device *device, rt_uint32_t ch
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if defined(SOC_SERIES_STM32F1)
|
#if !defined(ADC_CHANNEL_18)
|
||||||
LOG_E("ADC channel must be between 0 and 17.");
|
LOG_E("ADC channel must be between 0 and 17.");
|
||||||
#elif defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32F2) || defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) \
|
#elif defined(ADC_CHANNEL_19)
|
||||||
|| defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32G0)
|
LOG_E("ADC channel must be between 0 and 19.");
|
||||||
|
#else
|
||||||
LOG_E("ADC channel must be between 0 and 18.");
|
LOG_E("ADC channel must be between 0 and 18.");
|
||||||
#endif
|
#endif
|
||||||
return -RT_ERROR;
|
return -RT_ERROR;
|
||||||
|
|
Loading…
Reference in New Issue