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

结构体

struct  rt_dac_ops
 
struct  rt_dac_device
 

类型定义

typedef struct rt_dac_devicert_dac_device_t
 

枚举

enum  rt_dac_cmd_t { RT_DAC_CMD_ENABLE = RT_DEVICE_CTRL_BASE(DAC) + 0 , RT_DAC_CMD_DISABLE = RT_DEVICE_CTRL_BASE(DAC) + 1 , RT_DAC_CMD_GET_RESOLUTION = RT_DEVICE_CTRL_BASE(DAC) + 2 }
 

函数

rt_err_t rt_hw_dac_register (rt_dac_device_t dac, const char *name, const struct rt_dac_ops *ops, const void *user_data)
 
rt_err_t rt_dac_write (rt_dac_device_t dev, rt_uint32_t channel, rt_uint32_t value)
 
rt_err_t rt_dac_enable (rt_dac_device_t dev, rt_uint32_t channel)
 
rt_err_t rt_dac_disable (rt_dac_device_t dev, rt_uint32_t channel)
 

详细描述

DAC driver api

Example

#include <rtthread.h>
#include <rtdevice.h>
#include <stdlib.h>
#define DAC_DEV_NAME "dac1"
#define DAC_DEV_CHANNEL 1
#define REFER_VOLTAGE 330
#define CONVERT_BITS (1 << 12)
static int dac_vol_sample(int argc, char *argv[])
{
rt_dac_device_t dac_dev;
rt_uint32_t value, vol;
rt_err_t ret = RT_EOK;
dac_dev = (rt_dac_device_t)rt_device_find(DAC_DEV_NAME);
if (dac_dev == RT_NULL)
{
rt_kprintf("dac sample run failed! can't find %s device!\n", DAC_DEV_NAME);
return -RT_ERROR;
}
ret = rt_dac_enable(dac_dev, DAC_DEV_CHANNEL);
value = atoi(argv[1]);
rt_dac_write(dac_dev, DAC_DEV_NAME, DAC_DEV_CHANNEL, value);
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_dac_disable(dac_dev, DAC_DEV_CHANNEL);
return ret;
}
MSH_CMD_EXPORT(dac_vol_sample, dac voltage convert sample);
rt_err_t rt_dac_write(rt_dac_device_t dev, rt_uint32_t channel, rt_uint32_t value)
set the value of DAC
struct rt_dac_device * rt_dac_device_t
定义 dac.h:90
rt_err_t rt_dac_disable(rt_dac_device_t dev, rt_uint32_t channel)
disable the DAC channel
rt_err_t rt_dac_enable(rt_dac_device_t dev, rt_uint32_t channel)
enable the DAC channel
rt_device_t rt_device_find(const char *name)
#define rt_kprintf(...)
rt_err_t rt_thread_mdelay(rt_int32_t ms)
This function will let current thread delay for some milliseconds.
#define MSH_CMD_EXPORT(...)
rt_base_t rt_err_t
unsigned int rt_uint32_t
#define RT_NULL

类型定义说明

◆ rt_dac_device_t

typedef struct rt_dac_device* rt_dac_device_t

在文件 dac.h90 行定义.

枚举类型说明

◆ rt_dac_cmd_t

枚举值
RT_DAC_CMD_ENABLE RT_DEVICE_CTRL_BASE(DAC) + 0 
RT_DAC_CMD_DISABLE RT_DEVICE_CTRL_BASE(DAC) + 1 
RT_DAC_CMD_GET_RESOLUTION RT_DEVICE_CTRL_BASE(DAC) + 2 

在文件 dac.h92 行定义.

93{
rt_dac_cmd_t
定义 dac.h:93
@ RT_DAC_CMD_ENABLE
定义 dac.h:94
@ RT_DAC_CMD_DISABLE
定义 dac.h:95
@ RT_DAC_CMD_GET_RESOLUTION
定义 dac.h:96
#define RT_DEVICE_CTRL_BASE(Type)

函数说明

◆ rt_hw_dac_register()

rt_err_t rt_hw_dac_register ( rt_dac_device_t dac,
const char * name,
const struct rt_dac_ops * ops,
const void * user_data )

Register a DAC device

参数
dacDAC device
nameDAC name
opsthe operations of DAC device
user_datadevice private data
返回
rt_err_t error code

◆ rt_dac_write()

rt_err_t rt_dac_write ( rt_dac_device_t dev,
rt_uint32_t channel,
rt_uint32_t value )

set the value of DAC

参数
devDAC device
channelDAC channel
valuethe value of DAC
返回
rt_err_t error code

◆ rt_dac_enable()

rt_err_t rt_dac_enable ( rt_dac_device_t dev,
rt_uint32_t channel )

enable the DAC channel

参数
devDAC device
channelDAC channel
返回
rt_err_t error code

◆ rt_dac_disable()

rt_err_t rt_dac_disable ( rt_dac_device_t dev,
rt_uint32_t channel )

disable the DAC channel

参数
devDAC device
channelDAC channel
返回
rt_err_t error code