@@ -98,7 +98,7 @@ static rt_uint8_t stm32_adc_get_resolution(struct rt_adc_device *device)
|
||||
|
||||
static rt_uint32_t stm32_adc_get_channel(rt_uint32_t channel)
|
||||
{
|
||||
rt_uint32_t stm32_channel = 0;
|
||||
rt_uint32_t stm32_channel = RT_UINT32_MAX;
|
||||
|
||||
switch (channel)
|
||||
{
|
||||
@@ -167,6 +167,11 @@ static rt_uint32_t stm32_adc_get_channel(rt_uint32_t channel)
|
||||
case 19:
|
||||
stm32_channel = ADC_CHANNEL_19;
|
||||
break;
|
||||
#endif
|
||||
#ifdef ADC_CHANNEL_TEMPSENSOR
|
||||
case 32:
|
||||
stm32_channel = ADC_CHANNEL_TEMPSENSOR;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -191,37 +196,11 @@ static rt_err_t stm32_adc_get_value(struct rt_adc_device *device, rt_uint32_t ch
|
||||
|
||||
rt_memset(&ADC_ChanConf, 0, sizeof(ADC_ChanConf));
|
||||
|
||||
#ifndef ADC_CHANNEL_16
|
||||
if (channel == 16)
|
||||
/* set stm32 ADC channel */
|
||||
ADC_ChanConf.Channel = stm32_adc_get_channel(channel);
|
||||
if (ADC_ChanConf.Channel == RT_UINT32_MAX)
|
||||
{
|
||||
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)
|
||||
/* ADC channel number is up to 19 */
|
||||
#elif defined(ADC_CHANNEL_19)
|
||||
if (channel <= 19)
|
||||
/* ADC channel number is up to 18 */
|
||||
#else
|
||||
if (channel <= 18)
|
||||
#endif
|
||||
{
|
||||
/* set stm32 ADC channel */
|
||||
ADC_ChanConf.Channel = stm32_adc_get_channel(channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if !defined(ADC_CHANNEL_18)
|
||||
LOG_E("ADC channel must be between 0 and 17.");
|
||||
#elif defined(ADC_CHANNEL_19)
|
||||
LOG_E("ADC channel must be between 0 and 19.");
|
||||
#else
|
||||
LOG_E("ADC channel must be between 0 and 18.");
|
||||
#endif
|
||||
LOG_E("ADC channel%d isn't exist", channel);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user