add hs300x and ps5308 sensor support Nuttx on stm32f407-discovery

This commit is contained in:
wgzAIIT
2021-12-28 16:45:44 +08:00
parent 7ecf1af00f
commit d59acc2e03
61 changed files with 14578 additions and 126 deletions

View File

@@ -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

View File

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

View File

@@ -1,4 +1,4 @@
ifeq ($(CONFIG_SENSOR_HS300X),y)
ifeq ($(CONFIG_SENSOR_HS300X_TEMPERATURE),y)
SRC_DIR += hs300x_temp
endif

View File

@@ -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

View File

@@ -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

View File

@@ -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 =