add hs300x and ps5308 sensor support Nuttx on stm32f407-discovery
This commit is contained in:
7
APP_Framework/Framework/sensor/Make.defs
Normal file
7
APP_Framework/Framework/sensor/Make.defs
Normal file
@@ -0,0 +1,7 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/sensor/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_SUPPORT_SENSOR_FRAMEWORK),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor
|
||||
endif
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/*/Make.defs)
|
||||
@@ -1,39 +1,49 @@
|
||||
SRC_FILES := sensor.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += sensor.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_HCHO),y)
|
||||
SRC_DIR += hcho
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_TVOC),y)
|
||||
SRC_DIR += tvoc
|
||||
endif
|
||||
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
|
||||
SRC_FILES := sensor.c
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_IAQ),y)
|
||||
SRC_DIR += iaq
|
||||
endif
|
||||
ifeq ($(CONFIG_SENSOR_HCHO),y)
|
||||
SRC_DIR += hcho
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_CH4),y)
|
||||
SRC_DIR += ch4
|
||||
endif
|
||||
ifeq ($(CONFIG_SENSOR_TVOC),y)
|
||||
SRC_DIR += tvoc
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_CO2),y)
|
||||
SRC_DIR += co2
|
||||
endif
|
||||
ifeq ($(CONFIG_SENSOR_IAQ),y)
|
||||
SRC_DIR += iaq
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_PM),y)
|
||||
SRC_DIR += pm
|
||||
endif
|
||||
ifeq ($(CONFIG_SENSOR_CH4),y)
|
||||
SRC_DIR += ch4
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_VOICE),y)
|
||||
SRC_DIR += voice
|
||||
endif
|
||||
ifeq ($(CONFIG_SENSOR_CO2),y)
|
||||
SRC_DIR += co2
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_TEMPERATURE),y)
|
||||
SRC_DIR += temperature
|
||||
endif
|
||||
ifeq ($(CONFIG_SENSOR_PM),y)
|
||||
SRC_DIR += pm
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_HUMIDITY),y)
|
||||
SRC_DIR += humidity
|
||||
endif
|
||||
ifeq ($(CONFIG_SENSOR_VOICE),y)
|
||||
SRC_DIR += voice
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
ifeq ($(CONFIG_SENSOR_TEMPERATURE),y)
|
||||
SRC_DIR += temperature
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSOR_HUMIDITY),y)
|
||||
SRC_DIR += humidity
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
config SENSOR_HS300X
|
||||
bool "Using HS300x"
|
||||
config SENSOR_HS300X_HUMIDITY
|
||||
bool "Using HS300x for humidity"
|
||||
default n
|
||||
|
||||
if SENSOR_HS300X
|
||||
if SENSOR_HS300X_HUMIDITY
|
||||
config SENSOR_DEVICE_HS300X
|
||||
string "HS300x sensor name"
|
||||
default "hs300x_1"
|
||||
@@ -22,7 +22,15 @@ config SENSOR_HS300X
|
||||
default 0x44
|
||||
endif
|
||||
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
config SENSOR_DEVICE_HS300X_DEV
|
||||
string "HS300x device name"
|
||||
default "/dev/i2c1"
|
||||
|
||||
config SENSOR_DEVICE_HS300X_I2C_ADDR
|
||||
hex "HS300x device i2c address"
|
||||
default 0x44
|
||||
|
||||
endif
|
||||
|
||||
|
||||
4
APP_Framework/Framework/sensor/humidity/Make.defs
Normal file
4
APP_Framework/Framework/sensor/humidity/Make.defs
Normal file
@@ -0,0 +1,4 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/sensor/humidity/Make.defs
|
||||
############################################################################
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/humidity/*/Make.defs)
|
||||
@@ -1,4 +1,4 @@
|
||||
ifeq ($(CONFIG_SENSOR_HS300X),y)
|
||||
ifeq ($(CONFIG_SENSOR_HS300X_HUMIDITY),y)
|
||||
SRC_DIR += hs300x_humi
|
||||
endif
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/sensor/humidity/hs300x_humi/Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_SENSOR_HS300X_HUMIDITY),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/humidity/hs300x_humi
|
||||
endif
|
||||
@@ -1,3 +1,13 @@
|
||||
SRC_FILES := hs300x_humi.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += hs300x_humi.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
|
||||
SRC_FILES := hs300x_humi.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
|
||||
endif
|
||||
@@ -36,6 +36,12 @@ static struct SensorProductInfo info =
|
||||
*/
|
||||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
|
||||
|
||||
return sdev->fd;
|
||||
|
||||
#else
|
||||
int result;
|
||||
uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR;
|
||||
|
||||
@@ -52,6 +58,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,6 +69,16 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
*/
|
||||
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||
{
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
int ret;
|
||||
ret = PrivRead(sdev->fd, sdev->buffer, len);
|
||||
if (ret != len ){
|
||||
perror("Failed to read data!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
//send i2c device start signal and address, need to implemente in OS i2c driver
|
||||
if (PrivWrite(sdev->fd, NULL, 0) != 1)
|
||||
return -1;
|
||||
@@ -73,6 +90,7 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct SensorDone done =
|
||||
|
||||
@@ -8,18 +8,36 @@ config SENSOR_PS5308
|
||||
string "PS5308 sensor name"
|
||||
default "ps5308_1"
|
||||
|
||||
config SENSOR_QUANTITY_PS5308_PM1_0
|
||||
string "PS5308 quantity PM1.0 name"
|
||||
default "pm1_0_1"
|
||||
config PS5308_PM1_0
|
||||
bool "Using pm1.0 function"
|
||||
default n
|
||||
|
||||
if PS5308_PM1_0
|
||||
config SENSOR_QUANTITY_PS5308_PM1_0
|
||||
string "PS5308 quantity PM1.0 name"
|
||||
default "pm1_0_1"
|
||||
endif
|
||||
|
||||
config PS5308_PM2_5
|
||||
bool "Using pm2.5 function"
|
||||
default n
|
||||
|
||||
if PS5308_PM2_5
|
||||
config SENSOR_QUANTITY_PS5308_PM2_5
|
||||
string "PS5308 quantity PM2.5 name"
|
||||
default "pm2_5_1"
|
||||
endif
|
||||
|
||||
config PS5308_PM10
|
||||
bool "Using pm10 function"
|
||||
default n
|
||||
|
||||
if PS5308_PM10
|
||||
config SENSOR_QUANTITY_PS5308_PM10
|
||||
string "PS5308 quantity PM10 name"
|
||||
default "pm10_1"
|
||||
endif
|
||||
|
||||
config SENSOR_QUANTITY_PS5308_PM2_5
|
||||
string "PS5308 quantity PM2.5 name"
|
||||
default "pm2_5_1"
|
||||
|
||||
config SENSOR_QUANTITY_PS5308_PM10
|
||||
string "PS5308 quantity PM10 name"
|
||||
default "pm10_1"
|
||||
|
||||
if ADD_XIUOS_FETURES
|
||||
config SENSOR_PS5308_DRIVER_EXTUART
|
||||
bool "Using extra uart to support PS5308"
|
||||
@@ -42,6 +60,11 @@ config SENSOR_PS5308
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
config SENSOR_DEVICE_PS5308_DEV
|
||||
string "PS5308 device name"
|
||||
default "/dev/ttyS1"
|
||||
---help---
|
||||
If USART1 is selected, then fill in /dev/ttyS1 here.
|
||||
|
||||
endif
|
||||
|
||||
|
||||
4
APP_Framework/Framework/sensor/pm/Make.defs
Normal file
4
APP_Framework/Framework/sensor/pm/Make.defs
Normal file
@@ -0,0 +1,4 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/sensor/pm/Make.defs
|
||||
############################################################################
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/pm/*/Make.defs)
|
||||
6
APP_Framework/Framework/sensor/pm/ps5308/Make.defs
Normal file
6
APP_Framework/Framework/sensor/pm/ps5308/Make.defs
Normal file
@@ -0,0 +1,6 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/sensor/pm/ps5308//Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_SENSOR_PS5308),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/pm/ps5308
|
||||
endif
|
||||
@@ -1,3 +1,11 @@
|
||||
SRC_FILES := ps5308.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += ps5308.c
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
|
||||
SRC_FILES := ps5308.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
@@ -51,6 +51,32 @@ 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;
|
||||
|
||||
result = PrivMutexCreate(&buff_lock, 0);
|
||||
if (result != 0){
|
||||
printf("SensorDeviceOpen:mutex create failed, status=%d\n", result);
|
||||
}
|
||||
|
||||
sdev->fd = open(SENSOR_DEVICE_PS5308_DEV, O_RDWR);
|
||||
if (sdev->fd < 0) {
|
||||
printf("SensorDeviceOpen:open %s error\n", SENSOR_DEVICE_PS5308_DEV);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = PrivTaskCreate(&active_task_id, NULL, &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;
|
||||
@@ -76,13 +102,14 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
cfg.port_configure = PORT_CFG_INIT;
|
||||
#endif
|
||||
|
||||
result = ioctl(sdev->fd, OPE_INT, &cfg);
|
||||
//result = PrivIoctl(sdev->fd, OPE_INT, &cfg);
|
||||
|
||||
PrivTaskCreate(&active_task_id, NULL, &ReadTask, sdev);
|
||||
PrivTaskStartup(&active_task_id);
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @description: Close PS5308 sensor device
|
||||
|
||||
@@ -151,12 +151,9 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
if (sdev->done->open != NULL)
|
||||
result = sdev->done->open(sdev);
|
||||
|
||||
if (result == 0) {
|
||||
if (result >= 0) {
|
||||
printf("Device %s open success.\n", sdev->name);
|
||||
}else{
|
||||
if (sdev->fd)
|
||||
PrivClose(sdev->fd);
|
||||
|
||||
printf("Device %s open failed(%d).\n", sdev->name, result);
|
||||
memset(sdev, 0, sizeof(struct SensorDevice));
|
||||
}
|
||||
@@ -173,13 +170,13 @@ static int SensorDeviceClose(struct SensorDevice *sdev)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (sdev->fd)
|
||||
if (sdev->fd >= 0)
|
||||
PrivClose(sdev->fd);
|
||||
|
||||
if (sdev->done->close != NULL)
|
||||
result = sdev->done->close(sdev);
|
||||
|
||||
if (result == 0)
|
||||
if (result >= 0)
|
||||
printf("%s successfully closed.\n", sdev->name);
|
||||
else
|
||||
printf("Closed %s failure.\n", sdev->name);
|
||||
@@ -276,7 +273,7 @@ int SensorQuantityOpen(struct SensorQuantity *quant)
|
||||
|
||||
if (sdev->ref_cnt == 0) {
|
||||
ret = SensorDeviceOpen(sdev);
|
||||
if (ret != 0) {
|
||||
if (ret < 0) {
|
||||
printf("%s: open sensor device failed\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
|
||||
config SENSOR_HS300X
|
||||
bool "Using HS300x"
|
||||
config SENSOR_HS300X_TEMPERATURE
|
||||
bool "Using HS300x for temperature"
|
||||
default n
|
||||
|
||||
if SENSOR_HS300X
|
||||
if SENSOR_HS300X_TEMPERATURE
|
||||
config SENSOR_DEVICE_HS300X
|
||||
string "HS300x sensor name"
|
||||
default "hs300x_1"
|
||||
@@ -23,6 +23,13 @@ config SENSOR_HS300X
|
||||
endif
|
||||
|
||||
if ADD_NUTTX_FETURES
|
||||
config SENSOR_DEVICE_HS300X_DEV
|
||||
string "HS300x device name"
|
||||
default "/dev/i2c1"
|
||||
|
||||
config SENSOR_DEVICE_HS300X_I2C_ADDR
|
||||
hex "HS300x device i2c address"
|
||||
default 0x44
|
||||
|
||||
endif
|
||||
|
||||
|
||||
4
APP_Framework/Framework/sensor/temperature/Make.defs
Normal file
4
APP_Framework/Framework/sensor/temperature/Make.defs
Normal file
@@ -0,0 +1,4 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/sensor/temperature//Make.defs
|
||||
############################################################################
|
||||
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/temperature/*/Make.defs)
|
||||
@@ -1,4 +1,4 @@
|
||||
ifeq ($(CONFIG_SENSOR_HS300X),y)
|
||||
ifeq ($(CONFIG_SENSOR_HS300X_TEMPERATURE),y)
|
||||
SRC_DIR += hs300x_temp
|
||||
endif
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
############################################################################
|
||||
# APP_Framework/Framework/sensor/temperature/hs300x_temp//Make.defs
|
||||
############################################################################
|
||||
ifneq ($(CONFIG_SENSOR_HS300X_TEMPERATURE),)
|
||||
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/sensor/temperature/hs300x_temp
|
||||
endif
|
||||
@@ -1,3 +1,12 @@
|
||||
SRC_FILES := hs300x_temp.c
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += hs300x_temp.c
|
||||
include $(APPDIR)/Application.mk
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIUOS_FETURES),y)
|
||||
SRC_FILES := hs300x_temp.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
|
||||
@@ -36,6 +36,12 @@ static struct SensorProductInfo info =
|
||||
*/
|
||||
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
{
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR);
|
||||
|
||||
return sdev->fd;
|
||||
|
||||
#else
|
||||
int result;
|
||||
uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR;
|
||||
|
||||
@@ -51,6 +57,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg);
|
||||
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,6 +68,16 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||
*/
|
||||
static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||
{
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
int ret;
|
||||
ret = PrivRead(sdev->fd, sdev->buffer, len);
|
||||
if (ret != len ){
|
||||
perror("Failed to read data!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
#else
|
||||
//send i2c device start signal and address, need to implemente in OS i2c driver
|
||||
if (PrivWrite(sdev->fd, NULL, 0) != 1)
|
||||
return -1;
|
||||
@@ -72,6 +89,7 @@ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct SensorDone done =
|
||||
|
||||
Reference in New Issue
Block a user