forked from xuos/xiuos
add d124 and zg09 sensor support Nuttx on stm32f407-discovery
This commit is contained in:
parent
97eccb0b36
commit
bd31aad3ef
|
@ -18,7 +18,9 @@
|
||||||
* @date 2021.04.23
|
* @date 2021.04.23
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <user_api.h>
|
#ifdef ADD_XIUOS_FETURES
|
||||||
|
# include <user_api.h>
|
||||||
|
#endif
|
||||||
#include <sensor.h>
|
#include <sensor.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -34,6 +34,11 @@ config SENSOR_ZG09
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ADD_NUTTX_FETURES
|
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
|
endif
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
############################################################################
|
||||||
|
# APP_Framework/Framework/sensor/co2/Make.defs
|
||||||
|
############################################################################
|
||||||
|
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/co2/*/Make.defs)
|
|
@ -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
|
|
@ -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
|
|
||||||
|
|
|
@ -38,6 +38,25 @@ static struct SensorProductInfo info =
|
||||||
* @param sdev - sensor device pointer
|
* @param sdev - sensor device pointer
|
||||||
* @return success: 1 , failure: other
|
* @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)
|
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -70,6 +89,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: Read sensor device
|
* @description: Read sensor device
|
||||||
|
|
|
@ -34,6 +34,11 @@ config SENSOR_D124
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ADD_NUTTX_FETURES
|
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
|
endif
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
############################################################################
|
||||||
|
# APP_Framework/Framework/sensor/voice/Make.defs
|
||||||
|
############################################################################
|
||||||
|
include $(wildcard $(APPDIR)/../../../APP_Framework/Framework/sensor/voice/*/Make.defs)
|
|
@ -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
|
|
@ -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
|
||||||
|
|
|
@ -51,6 +51,35 @@ static void *ReadTask(void *parameter)
|
||||||
* @param sdev - sensor device pointer
|
* @param sdev - sensor device pointer
|
||||||
* @return success: 1 , failure: other
|
* @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)
|
static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -90,6 +119,7 @@ static int SensorDeviceOpen(struct SensorDevice *sdev)
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: Close D124 sensor device
|
* @description: Close D124 sensor device
|
||||||
|
|
|
@ -21,11 +21,11 @@
|
||||||
#ifndef TRANSFORM_H
|
#ifndef TRANSFORM_H
|
||||||
#define TRANSFORM_H
|
#define TRANSFORM_H
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <nuttx/pthread.h>
|
||||||
#include <semaphore.h>
|
#include <nuttx/semaphore.h>
|
||||||
|
#include <nuttx/time.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
typedef uint8_t uint8;
|
typedef uint8_t uint8;
|
||||||
typedef uint16_t uint16;
|
typedef uint16_t uint16;
|
||||||
|
|
|
@ -588,6 +588,10 @@ config NSH_DISABLE_XD
|
||||||
default y if DEFAULT_SMALL
|
default y if DEFAULT_SMALL
|
||||||
default n if !DEFAULT_SMALL
|
default n if !DEFAULT_SMALL
|
||||||
|
|
||||||
|
config NSH_DISABLE_CO2ZG09
|
||||||
|
bool "Disable the co2 function of the sensor zg09"
|
||||||
|
default n
|
||||||
|
|
||||||
config NSH_DISABLE_PM1_0PS5308
|
config NSH_DISABLE_PM1_0PS5308
|
||||||
bool "Disable the pm1.0 function of the sensor ps5308"
|
bool "Disable the pm1.0 function of the sensor ps5308"
|
||||||
default n
|
default n
|
||||||
|
@ -600,6 +604,10 @@ config NSH_DISABLE_PM10PS5308
|
||||||
bool "Disable the pm10 function of the sensor ps5308"
|
bool "Disable the pm10 function of the sensor ps5308"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
|
config NSH_DISABLE_VOICED124
|
||||||
|
bool "Disable the voice function of the sensor d124"
|
||||||
|
default n
|
||||||
|
|
||||||
config NSH_DISABLE_TEMPHS300X
|
config NSH_DISABLE_TEMPHS300X
|
||||||
bool "Disable the temperature function of the sensor Hs300x"
|
bool "Disable the temperature function of the sensor Hs300x"
|
||||||
default n
|
default n
|
||||||
|
|
|
@ -1403,6 +1403,10 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb,
|
||||||
FAR void *arg);
|
FAR void *arg);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_APPLICATION_SENSOR_CO2_ZG09) && !defined(CONFIG_NSH_DISABLE_CO2ZG09)
|
||||||
|
int cmd_Co2Zg09(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308) && !defined(CONFIG_NSH_DISABLE_PM1_0PS5308)
|
#if defined(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308) && !defined(CONFIG_NSH_DISABLE_PM1_0PS5308)
|
||||||
int cmd_Pm10Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
int cmd_Pm10Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1415,6 +1419,10 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb,
|
||||||
int cmd_Pm100Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
int cmd_Pm100Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_APPLICATION_SENSOR_VOICE_D124) && !defined(CONFIG_NSH_DISABLE_VOICED124)
|
||||||
|
int cmd_VoiceD124(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X) && !defined(CONFIG_NSH_DISABLE_TEMPHS300X)
|
#if defined(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X) && !defined(CONFIG_NSH_DISABLE_TEMPHS300X)
|
||||||
int cmd_TempHs300x(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
int cmd_TempHs300x(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -52,6 +52,21 @@
|
||||||
|
|
||||||
extern int FrameworkInit(void);
|
extern int FrameworkInit(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: cmd_Co2Zg09
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_APPLICATION_SENSOR_CO2_ZG09) && !defined(CONFIG_NSH_DISABLE_CO2ZG09)
|
||||||
|
extern void Co2Zg09(void);
|
||||||
|
int cmd_Co2Zg09(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
|
{
|
||||||
|
printf("Hello, world!\n");
|
||||||
|
FrameworkInit();
|
||||||
|
Co2Zg09();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: cmd_Pm10Ps5308
|
* Name: cmd_Pm10Ps5308
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -97,6 +112,21 @@ int cmd_Pm100Ps5308(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: cmd_VoiceD124
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#if defined(CONFIG_APPLICATION_SENSOR_VOICE_D124) && !defined(CONFIG_NSH_DISABLE_VOICED124)
|
||||||
|
extern void VoiceD124(void);
|
||||||
|
int cmd_VoiceD124(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||||
|
{
|
||||||
|
printf("Hello, world!\n");
|
||||||
|
FrameworkInit();
|
||||||
|
VoiceD124();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: cmd_TempHs300x
|
* Name: cmd_TempHs300x
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
|
@ -580,24 +580,32 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||||
{ "xd", cmd_xd, 3, 3, "<hex-address> <byte-count>" },
|
{ "xd", cmd_xd, 3, 3, "<hex-address> <byte-count>" },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_APPLICATION_SENSOR_CO2_ZG09) && !defined(CONFIG_NSH_DISABLE_CO2ZG09)
|
||||||
|
{ "zg09", cmd_Co2Zg09, 1, 1, "[get co2 concentration with sensor ZG09.]" },
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308) && !defined(CONFIG_NSH_DISABLE_PM1_0PS5308)
|
#if defined(CONFIG_APPLICATION_SENSOR_PM1_0_PS5308) && !defined(CONFIG_NSH_DISABLE_PM1_0PS5308)
|
||||||
{ "pm1.0", cmd_Pm10Ps5308, 1, 1, "[get pm1.0 with sensor Ps5308]" },
|
{ "pm1.0", cmd_Pm10Ps5308, 1, 1, "[get pm1.0 with sensor Ps5308.]" },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308) && !defined(CONFIG_NSH_DISABLE_PM2_5PS5308)
|
#if defined(CONFIG_APPLICATION_SENSOR_PM2_5_PS5308) && !defined(CONFIG_NSH_DISABLE_PM2_5PS5308)
|
||||||
{ "pm2.5", cmd_Pm25Ps5308, 1, 1, "[get pm2.5with sensor Ps5308]" },
|
{ "pm2.5", cmd_Pm25Ps5308, 1, 1, "[get pm2.5with sensor Ps5308.]" },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_APPLICATION_SENSOR_PM10_PS5308) && !defined(CONFIG_NSH_DISABLE_PM10PS5308)
|
#if defined(CONFIG_APPLICATION_SENSOR_PM10_PS5308) && !defined(CONFIG_NSH_DISABLE_PM10PS5308)
|
||||||
{ "pm10", cmd_Pm100Ps5308, 1, 1, "[get pm10 with sensor Ps5308]" },
|
{ "pm10", cmd_Pm100Ps5308, 1, 1, "[get pm10 with sensor Ps5308.]" },
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_APPLICATION_SENSOR_VOICE_D124) && !defined(CONFIG_NSH_DISABLE_VOICED124)
|
||||||
|
{ "d124", cmd_VoiceD124, 1, 1, "[get decibel of noise with sensor D124.]" },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X) && !defined(CONFIG_NSH_DISABLE_TEMPHS300X)
|
#if defined(CONFIG_APPLICATION_SENSOR_TEMPERATURE_HS300X) && !defined(CONFIG_NSH_DISABLE_TEMPHS300X)
|
||||||
{ "temp", cmd_TempHs300x, 1, 1, "[Get humidity with sensor HS300x]" },
|
{ "temp", cmd_TempHs300x, 1, 1, "[get temperature with sensor HS300x.]" },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X) && !defined(CONFIG_NSH_DISABLE_HUMIHS300X)
|
#if defined(CONFIG_APPLICATION_SENSOR_HUMIDITY_HS300X) && !defined(CONFIG_NSH_DISABLE_HUMIHS300X)
|
||||||
{ "humi", cmd_HumiHs300x, 1, 1, "[Get temperature with sensor HS300x]" },
|
{ "humi", cmd_HumiHs300x, 1, 1, "[get humidity with sensor HS300x.]" },
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ NULL, NULL, 1, 1, NULL }
|
{ NULL, NULL, 1, 1, NULL }
|
||||||
|
|
Loading…
Reference in New Issue