RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
+ ADC 的协作图:

结构体

struct  rt_adc_ops
 
struct  rt_adc_device
 

宏定义

#define RT_ADC_INTERN_CH_TEMPER   (-1)
 
#define RT_ADC_INTERN_CH_VREF   (-2)
 
#define RT_ADC_INTERN_CH_VBAT   (-3)
 

类型定义

typedef struct rt_adc_devicert_adc_device_t
 

枚举

enum  rt_adc_cmd_t { RT_ADC_CMD_ENABLE = RT_DEVICE_CTRL_BASE(ADC) + 1 , RT_ADC_CMD_DISABLE = RT_DEVICE_CTRL_BASE(ADC) + 2 , RT_ADC_CMD_GET_RESOLUTION = RT_DEVICE_CTRL_BASE(ADC) + 3 , RT_ADC_CMD_GET_VREF = RT_DEVICE_CTRL_BASE(ADC) + 4 }
 

函数

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_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)
 

详细描述

ADC driver api

Example

#define ADC_DEV_NAME "adc1"
#define ADC_DEV_CHANNEL 5
#define REFER_VOLTAGE 330
#define CONVERT_BITS (1 << 12)
static int adc_vol_sample(int argc, char *argv[])
{
rt_adc_device_t adc_dev;
rt_uint32_t value, vol;
rt_err_t ret = RT_EOK;
adc_dev = (rt_adc_device_t)rt_device_find(ADC_DEV_NAME);
if (adc_dev == RT_NULL)
{
rt_kprintf("adc sample run failed! can't find %s device!\n", ADC_DEV_NAME);
return -RT_ERROR;
}
ret = rt_adc_enable(adc_dev, ADC_DEV_CHANNEL);
value = rt_adc_read(adc_dev, ADC_DEV_CHANNEL);
rt_kprintf("the value is :%d \n", value);
vol = value * REFER_VOLTAGE / CONVERT_BITS;
rt_kprintf("the voltage is :%d.%02d \n", vol / 100, vol % 100);
ret = rt_adc_disable(adc_dev, ADC_DEV_CHANNEL);
return ret;
}
MSH_CMD_EXPORT(adc_vol_sample, adc voltage convert sample);
rt_err_t rt_adc_enable(rt_adc_device_t dev, rt_int8_t channel)
enable the adc channel
rt_uint32_t rt_adc_read(rt_adc_device_t dev, rt_int8_t channel)
read the adc value
struct rt_adc_device * rt_adc_device_t
定义 adc.h:91
rt_err_t rt_adc_disable(rt_adc_device_t dev, rt_int8_t channel)
disable the adc channel
rt_device_t rt_device_find(const char *name)
#define rt_kprintf(...)
#define MSH_CMD_EXPORT(...)
rt_base_t rt_err_t
unsigned int rt_uint32_t
#define RT_NULL

宏定义说明

◆ RT_ADC_INTERN_CH_TEMPER

#define RT_ADC_INTERN_CH_TEMPER   (-1)

在文件 adc.h68 行定义.

◆ RT_ADC_INTERN_CH_VREF

#define RT_ADC_INTERN_CH_VREF   (-2)

在文件 adc.h69 行定义.

◆ RT_ADC_INTERN_CH_VBAT

#define RT_ADC_INTERN_CH_VBAT   (-3)

在文件 adc.h70 行定义.

类型定义说明

◆ rt_adc_device_t

typedef struct rt_adc_device* rt_adc_device_t

在文件 adc.h91 行定义.

枚举类型说明

◆ rt_adc_cmd_t

枚举值
RT_ADC_CMD_ENABLE RT_DEVICE_CTRL_BASE(ADC) + 1 
RT_ADC_CMD_DISABLE RT_DEVICE_CTRL_BASE(ADC) + 2 
RT_ADC_CMD_GET_RESOLUTION RT_DEVICE_CTRL_BASE(ADC) + 3 
RT_ADC_CMD_GET_VREF RT_DEVICE_CTRL_BASE(ADC) + 4 

在文件 adc.h93 行定义.

94{
97 RT_ADC_CMD_GET_RESOLUTION = RT_DEVICE_CTRL_BASE(ADC) + 3, /* get the resolution in bits */
98 RT_ADC_CMD_GET_VREF = RT_DEVICE_CTRL_BASE(ADC) + 4, /* get reference voltage */
rt_adc_cmd_t
定义 adc.h:94
@ RT_ADC_CMD_GET_VREF
定义 adc.h:98
@ RT_ADC_CMD_DISABLE
定义 adc.h:96
@ RT_ADC_CMD_ENABLE
定义 adc.h:95
@ RT_ADC_CMD_GET_RESOLUTION
定义 adc.h:97
#define RT_DEVICE_CTRL_BASE(Type)

函数说明

◆ rt_hw_adc_register()

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 )

register the adc device

参数
adcadc device
namedevice name
opsdevice ops
user_datadevice private data
返回
rt_err_t error code

◆ rt_adc_read()

rt_uint32_t rt_adc_read ( rt_adc_device_t dev,
rt_int8_t channel )

read the adc value

参数
devadc device
channeladc channel
返回
rt_uint32_t adc value

◆ rt_adc_enable()

rt_err_t rt_adc_enable ( rt_adc_device_t dev,
rt_int8_t channel )

enable the adc channel

参数
devadc device
channeladc channel
返回
rt_err_t error code

◆ rt_adc_disable()

rt_err_t rt_adc_disable ( rt_adc_device_t dev,
rt_int8_t channel )

disable the adc channel

参数
devadc device
channeladc channel
返回
rt_err_t error code

◆ rt_adc_voltage()

rt_int16_t rt_adc_voltage ( rt_adc_device_t dev,
rt_int8_t channel )

get the adc resolution

参数
devadc device
channeladc channel
返回
rt_int16_t adc resolution