如下是在将安富莱的dac8563模块对接到潘多拉开发板RT-Thread SPI设备框架中时导出到RT-Thread的自定义MSH命令,需要注意的是MSH传入的是字符串,需要自行对字符串进行解析处理。
#include "stdlib.h" /* 使用其中的函数:atoi(); */
#include "string.h" /* 使用其中的函数:strncmp(); */
static void dac8563_spi_sample(int argc, char *argv[])
{
int16_t i16_volt = 0;
rt_kprintf("input para is: %s %s %s \n", argv[0], argv[1], argv[2]);
if (3 != argc)
{
rt_kprintf("error cmd! please input as: (A 5000) \n");
return;
}
if (!strncmp("A", argv[1], 1)) //两个字符串在比较的长度内都相等则返回0
{
i16_volt = atoi(argv[2]);
DAC8563_set_output_volt(WRITE_AND_UPDATE_DAC_A, i16_volt);
}
else if (!strncmp("B", argv[1], 1))
{
i16_volt = atoi(argv[2]);
DAC8563_set_output_volt(WRITE_AND_UPDATE_DAC_B, i16_volt);
}
}
/* 导出到 msh 命令列表中 */
MSH_CMD_EXPORT(dac8563_spi_sample, spi dac8563 sample);
在MSH中输入的指令如下所示:
- 命令的名称为