add g8s sensor support Nuttx on stm32f407-discovery

This commit is contained in:
zhr
2022-07-26 18:43:39 +08:00
parent 71f00ec06f
commit 21dce4f25e
10 changed files with 97 additions and 6 deletions

View File

@@ -64,6 +64,7 @@ config SENSOR_ZG09
endif
endif
config SENSOR_G8S
bool "Using g8-s"
default n
@@ -99,10 +100,31 @@ config SENSOR_G8S
endif
if ADD_NUTTX_FETURES
config SENSOR_DEVICE_G8S_DEV
string "CO2 device name"
default "/dev/ttyS1"
---help---
If USART1 is selected, then fill in /dev/ttyS1 here.
endif
if ADD_RTTHREAD_FETURES
config SENSOR_G8S_DRIVER_EXTUART
bool "Using extra uart to support g8-s"
default y
config SENSOR_DEVICE_G8S_DEV
string "g8-s device uart path"
default "/dev/uart2_dev2"
depends on !SENSOR_G8S_DRIVER_EXTUART
if SENSOR_G8S_DRIVER_EXTUART
config SENSOR_DEVICE_G8S_DEV
string "g8-s device extra uart path"
default "/dev/extuart_dev4"
config SENSOR_DEVICE_G8S_DEV_EXT_PORT
int "if G8S device using extuart, choose port"
default "4"
endif
endif
endif

View File

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

View File

@@ -37,6 +37,7 @@ 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;
@@ -47,6 +48,26 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
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;
sdev->fd = PrivOpen(SENSOR_DEVICE_G8S_DEV, O_RDWR);
if (sdev->fd < 0) {
printf("open %s error\n", SENSOR_DEVICE_G8S_DEV);
return -1;
}
struct SerialDataCfg cfg;
cfg.serial_baud_rate = BAUD_RATE_9600;
cfg.serial_data_bits = DATA_BITS_8;
@@ -67,7 +88,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
return result;
}
#endif
/**
* @description: Read sensor device
* @param sdev - sensor device pointer