#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_kprintf(
"dac sample run failed! can't find %s device!\n", DAC_DEV_NAME);
return -RT_ERROR;
}
value = atoi(argv[1]);
rt_dac_write(dac_dev, DAC_DEV_NAME, DAC_DEV_CHANNEL, value);
vol = value * REFER_VOLTAGE / CONVERT_BITS;
rt_kprintf(
"the voltage is :%d.%02d \n", vol / 100, vol % 100);
return ret;
}
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
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)
rt_err_t rt_thread_mdelay(rt_int32_t ms)
This function will let current thread delay for some milliseconds.
#define MSH_CMD_EXPORT(...)