adc 驱动: 适配温度接口 & 逻辑小改

Signed-off-by: a1012112796 <1012112796@qq.com>
This commit is contained in:
2023-01-14 10:36:14 +08:00
parent ba71d92b5b
commit 9ebd4970a0

View File

@@ -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) 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) switch (channel)
{ {
@@ -167,6 +167,11 @@ static rt_uint32_t stm32_adc_get_channel(rt_uint32_t channel)
case 19: case 19:
stm32_channel = ADC_CHANNEL_19; stm32_channel = ADC_CHANNEL_19;
break; break;
#endif
#ifdef ADC_CHANNEL_TEMPSENSOR
case 32:
stm32_channel = ADC_CHANNEL_TEMPSENSOR;
break;
#endif #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)); rt_memset(&ADC_ChanConf, 0, sizeof(ADC_ChanConf));
#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)
/* 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 */ /* set stm32 ADC channel */
ADC_ChanConf.Channel = stm32_adc_get_channel(channel); ADC_ChanConf.Channel = stm32_adc_get_channel(channel);
} if (ADC_ChanConf.Channel == RT_UINT32_MAX)
else
{ {
#if !defined(ADC_CHANNEL_18) LOG_E("ADC channel%d isn't exist", channel);
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
return -RT_ERROR; return -RT_ERROR;
} }