forked from xuos/xiuos
feat support DAC driver for aiit-arm32-board and stm32f407-st-discovery
This commit is contained in:
@@ -18,5 +18,16 @@ menu "test app"
|
||||
default "/dev/adc1_dev"
|
||||
endif
|
||||
endif
|
||||
|
||||
menuconfig USER_TEST_DAC
|
||||
bool "Config test dac"
|
||||
default n
|
||||
if USER_TEST_DAC
|
||||
if ADD_XIUOS_FETURES
|
||||
config DAC_DEV_DRIVER
|
||||
string "Set DAC dev path"
|
||||
default "/dev/dac_dev"
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endmenu
|
||||
|
||||
@@ -8,4 +8,8 @@ ifeq ($(CONFIG_USER_TEST_ADC),y)
|
||||
SRC_FILES += test_adc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_USER_TEST_DAC),y)
|
||||
SRC_FILES += test_dac.c
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
@@ -52,7 +52,9 @@ void test_adc()
|
||||
|
||||
printf("adc sample %u value integer %u decimal %u\n", adc_sample, (uint16)adc_value, adc_value_decimal);
|
||||
|
||||
PrivClose(adc_fd);
|
||||
|
||||
return;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
test_adc, test_adc, read 3.3 voltage data from adc);
|
||||
// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
// test_adc, test_adc, read 3.3 voltage data from adc);
|
||||
|
||||
60
APP_Framework/Applications/app_test/test_dac.c
Normal file
60
APP_Framework/Applications/app_test/test_dac.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: test_dac.c
|
||||
* @brief: a application of dac function
|
||||
* @version: 2.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2022/1/11
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
void test_dac()
|
||||
{
|
||||
int dac_fd;
|
||||
uint16 dac_set_value = 800;
|
||||
uint16 dac_sample, dac_value_decimal = 0;
|
||||
float dac_value;
|
||||
|
||||
dac_fd = PrivOpen(DAC_DEV_DRIVER, O_RDWR);
|
||||
if (dac_fd < 0) {
|
||||
KPrintf("open dac fd error %d\n", dac_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
struct PrivIoctlCfg ioctl_cfg;
|
||||
ioctl_cfg.ioctl_driver_type = DAC_TYPE;
|
||||
ioctl_cfg.args = &dac_set_value;
|
||||
if (0 != PrivIoctl(dac_fd, OPE_CFG, &ioctl_cfg)) {
|
||||
KPrintf("ioctl dac fd error %d\n", dac_fd);
|
||||
PrivClose(dac_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
PrivRead(dac_fd, &dac_sample, 2);
|
||||
|
||||
dac_value = (float)dac_sample * (3.3 / 4096);//Vref+ need to be 3.3V
|
||||
|
||||
dac_value_decimal = (dac_value - (uint16)dac_value) * 1000;
|
||||
|
||||
printf("dac sample %u value integer %u decimal %u\n", dac_sample, (uint16)dac_value, dac_value_decimal);
|
||||
|
||||
PrivClose(dac_fd);
|
||||
|
||||
return;
|
||||
}
|
||||
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN),
|
||||
test_dac, test_dac, set digital data to dac);
|
||||
@@ -155,6 +155,7 @@ int PrivIoctl(int fd, int cmd, void *args)
|
||||
ret = ioctl(fd, cmd, ioctl_cfg->args);
|
||||
break;
|
||||
case ADC_TYPE:
|
||||
case DAC_TYPE:
|
||||
ret = ioctl(fd, cmd, ioctl_cfg->args);
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -139,6 +139,7 @@ enum IoctlDriverType
|
||||
I2C_TYPE,
|
||||
PIN_TYPE,
|
||||
ADC_TYPE,
|
||||
DAC_TYPE,
|
||||
DEFAULT_TYPE,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user