diff --git a/components/drivers/include/drivers/adc.h b/components/drivers/include/drivers/adc.h index 2e4da26819..b332c94538 100644 --- a/components/drivers/include/drivers/adc.h +++ b/components/drivers/include/drivers/adc.h @@ -12,17 +12,18 @@ #ifndef __ADC_H__ #define __ADC_H__ + #include -#define RT_ADC_INTERN_CH_TEMPER ((rt_uint32_t)-1) -#define RT_ADC_INTERN_CH_VREF ((rt_uint32_t)-2) -#define RT_ADC_INTERN_CH_VBAT ((rt_uint32_t)-3) +#define RT_ADC_INTERN_CH_TEMPER (-1) +#define RT_ADC_INTERN_CH_VREF (-2) +#define RT_ADC_INTERN_CH_VBAT (-3) struct rt_adc_device; struct rt_adc_ops { - rt_err_t (*enabled)(struct rt_adc_device *device, rt_uint32_t channel, rt_bool_t enabled); - rt_err_t (*convert)(struct rt_adc_device *device, rt_uint32_t channel, rt_uint32_t *value); + rt_err_t (*enabled)(struct rt_adc_device *device, rt_int8_t channel, rt_bool_t enabled); + rt_err_t (*convert)(struct rt_adc_device *device, rt_int8_t channel, rt_uint32_t *value); rt_uint8_t (*get_resolution)(struct rt_adc_device *device); rt_int16_t (*get_vref) (struct rt_adc_device *device); }; @@ -43,10 +44,9 @@ typedef enum } rt_adc_cmd_t; rt_err_t rt_hw_adc_register(rt_adc_device_t adc,const char *name, const struct rt_adc_ops *ops, const void *user_data); - -rt_uint32_t rt_adc_read(rt_adc_device_t dev, rt_uint32_t channel); -rt_err_t rt_adc_enable(rt_adc_device_t dev, rt_uint32_t channel); -rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_uint32_t channel); -rt_int16_t rt_adc_voltage(rt_adc_device_t dev, rt_uint32_t channel); +rt_uint32_t rt_adc_read(rt_adc_device_t dev, rt_int8_t channel); +rt_err_t rt_adc_enable(rt_adc_device_t dev, rt_int8_t channel); +rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_int8_t channel); +rt_int16_t rt_adc_voltage(rt_adc_device_t dev, rt_int8_t channel); #endif /* __ADC_H__ */ diff --git a/components/drivers/misc/adc.c b/components/drivers/misc/adc.c index 29dbb86f96..0f96198cef 100644 --- a/components/drivers/misc/adc.c +++ b/components/drivers/misc/adc.c @@ -115,7 +115,7 @@ rt_err_t rt_hw_adc_register(rt_adc_device_t device, const char *name, const stru return result; } -rt_uint32_t rt_adc_read(rt_adc_device_t dev, rt_uint32_t channel) +rt_uint32_t rt_adc_read(rt_adc_device_t dev, rt_int8_t channel) { rt_uint32_t value; @@ -126,7 +126,7 @@ rt_uint32_t rt_adc_read(rt_adc_device_t dev, rt_uint32_t channel) return value; } -rt_err_t rt_adc_enable(rt_adc_device_t dev, rt_uint32_t channel) +rt_err_t rt_adc_enable(rt_adc_device_t dev, rt_int8_t channel) { rt_err_t result = RT_EOK; @@ -144,7 +144,7 @@ rt_err_t rt_adc_enable(rt_adc_device_t dev, rt_uint32_t channel) return result; } -rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_uint32_t channel) +rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_int8_t channel) { rt_err_t result = RT_EOK; @@ -162,7 +162,7 @@ rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_uint32_t channel) return result; } -rt_int16_t rt_adc_voltage(rt_adc_device_t dev, rt_uint32_t channel) +rt_int16_t rt_adc_voltage(rt_adc_device_t dev, rt_int8_t channel) { rt_uint32_t value = 0; rt_int16_t vref = 0, voltage = 0;