add d124 and zg09 sensor support Nuttx on stm32f407-discovery

This commit is contained in:
wgzAIIT
2021-12-29 16:13:23 +08:00
parent 97eccb0b36
commit bd31aad3ef
16 changed files with 168 additions and 13 deletions

View File

@@ -34,6 +34,11 @@ config SENSOR_ZG09
endif
if ADD_NUTTX_FETURES
config SENSOR_DEVICE_ZG09_DEV
string "CO2 device name"
default "/dev/ttyS1"
---help---
If USART1 is selected, then fill in /dev/ttyS1 here.
endif

View File

@@ -0,0 +1,4 @@
############################################################################
# APP_Framework/Framework/sensor/co2/Make.defs
############################################################################
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/co2/*/Make.defs)

View File

@@ -0,0 +1,6 @@
############################################################################
# APP_Framework/Framework/sensor/co2/zg09/Make.defs
############################################################################
ifneq ($(CONFIG_SENSOR_ZG09),)
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/co2/zg09
endif

View File

@@ -1,3 +1,13 @@
SRC_FILES := zg09.c
include $(KERNEL_ROOT)/.config
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Make.defs
CSRCS += zg09.c
include $(APPDIR)/Application.mk
endif
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_FILES := zg09.c
include $(KERNEL_ROOT)/compiler.mk
endif
include $(KERNEL_ROOT)/compiler.mk

View File

@@ -38,6 +38,25 @@ static struct SensorProductInfo info =
* @param sdev - sensor device pointer
* @return success: 1 , failure: other
*/
#ifdef ADD_NUTTX_FETURES
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
sdev->fd = PrivOpen(SENSOR_DEVICE_ZG09_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_ZG09_DEV);
return -1;
}
result = sdev->done->ioctl(sdev, SENSOR_DEVICE_PASSIVE);
if (result != 0){
printf("SensorDeviceOpen:ioctl failed, status=%d\n", result);
}
return result;
}
#else
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
@@ -70,6 +89,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
return result;
}
#endif
/**
* @description: Read sensor device

View File

@@ -34,6 +34,11 @@ config SENSOR_D124
endif
if ADD_NUTTX_FETURES
config SENSOR_DEVICE_D124_DEV
string "D124 device name"
default "/dev/ttyS1"
---help---
If USART1 is selected, then fill in /dev/ttyS1 here.
endif

View File

@@ -0,0 +1,4 @@
############################################################################
# APP_Framework/Framework/sensor/voice/Make.defs
############################################################################
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/voice/*/Make.defs)

View File

@@ -0,0 +1,6 @@
############################################################################
# APP_Framework/Framework/sensor/voice/d124/Make.defs
############################################################################
ifneq ($(CONFIG_SENSOR_D124),)
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/voice/d124
endif

View File

@@ -1,3 +1,12 @@
SRC_FILES := d124.c
include $(KERNEL_ROOT)/.config
include $(KERNEL_ROOT)/compiler.mk
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Make.defs
CSRCS += d124.c
include $(APPDIR)/Application.mk
endif
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
SRC_FILES := d124.c
include $(KERNEL_ROOT)/compiler.mk
endif

View File

@@ -51,6 +51,35 @@ static void *ReadTask(void *parameter)
* @param sdev - sensor device pointer
* @return success: 1 , failure: other
*/
#ifdef ADD_NUTTX_FETURES
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
result = PrivMutexCreate(&buff_lock, NULL);
if (result != 0){
printf("SensorDeviceOpen:mutex create failed, status=%d\n", result);
}
sdev->fd = PrivOpen(SENSOR_DEVICE_D124_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("SensorDeviceOpen:open %s error\n", SENSOR_DEVICE_D124_DEV);
return -1;
}
attr.priority = 20;
attr.stacksize = 2048;
result = PrivTaskCreate(&active_task_id, &attr, &ReadTask, sdev);
if (result != 0){
printf("SensorDeviceOpen:task create failed, status=%d\n", result);
}
PrivTaskStartup(&active_task_id);
return result;
}
#else
static int SensorDeviceOpen(struct SensorDevice *sdev)
{
int result = 0;
@@ -90,6 +119,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
return result;
}
#endif
/**
* @description: Close D124 sensor device