You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ma...@apache.org on 2022/04/11 22:55:13 UTC
[incubator-nuttx] 07/08: boards: cxd56xx: Add board function for scd41 sensor driver
This is an automated email from the ASF dual-hosted git repository.
masayuki pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 81534df8a3c44d516f8b5814c9d321e74104fc5b
Author: SPRESENSE <41...@users.noreply.github.com>
AuthorDate: Mon Apr 11 20:11:45 2022 +0900
boards: cxd56xx: Add board function for scd41 sensor driver
Add board function for SCD41 CO2, temperature and humidity sensor driver.
---
boards/arm/cxd56xx/common/src/Make.defs | 4 ++
boards/arm/cxd56xx/common/src/cxd56_scd41_i2c.c | 72 ++++++++++++++++++++++
boards/arm/cxd56xx/common/src/cxd56_sensors.c | 3 +
boards/arm/cxd56xx/spresense/include/board.h | 1 +
boards/arm/cxd56xx/spresense/include/cxd56_scd41.h | 71 +++++++++++++++++++++
5 files changed, 151 insertions(+)
diff --git a/boards/arm/cxd56xx/common/src/Make.defs b/boards/arm/cxd56xx/common/src/Make.defs
index 0dae761637..572a772536 100644
--- a/boards/arm/cxd56xx/common/src/Make.defs
+++ b/boards/arm/cxd56xx/common/src/Make.defs
@@ -110,6 +110,10 @@ ifeq ($(CONFIG_SENSORS_RPR0521RS_SCU),y)
CSRCS += cxd56_rpr0521rs_scu.c
endif
+ifeq ($(CONFIG_SENSORS_SCD41),y)
+CSRCS += cxd56_scd41_i2c.c
+endif
+
ifeq ($(CONFIG_NETDEVICES),y)
CSRCS += cxd56_netinit.c
endif
diff --git a/boards/arm/cxd56xx/common/src/cxd56_scd41_i2c.c b/boards/arm/cxd56xx/common/src/cxd56_scd41_i2c.c
new file mode 100644
index 0000000000..d3f0b15e23
--- /dev/null
+++ b/boards/arm/cxd56xx/common/src/cxd56_scd41_i2c.c
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * boards/arm/cxd56xx/common/src/cxd56_scd41_i2c.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdio.h>
+#include <debug.h>
+#include <errno.h>
+
+#include <nuttx/board.h>
+
+#include <nuttx/sensors/scd41.h>
+
+#include "cxd56_i2c.h"
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+#if defined(CONFIG_I2C) && defined(CONFIG_SENSORS_SCD41)
+
+int board_scd41_initialize(FAR const char *devpath, int bus)
+{
+ int ret;
+ FAR struct i2c_master_s *i2c;
+
+ sninfo("Initializing SCD41...\n");
+
+ /* Initialize i2c device */
+
+ i2c = cxd56_i2cbus_initialize(bus);
+ if (!i2c)
+ {
+ snerr("ERROR: Failed to initialize i2c%d.\n", bus);
+ return -ENODEV;
+ }
+
+ ret = scd41_register_i2c(devpath, i2c);
+ if (ret < 0)
+ {
+ snerr("Error registering SCD41.\n");
+ }
+
+ return ret;
+}
+
+#endif
diff --git a/boards/arm/cxd56xx/common/src/cxd56_sensors.c b/boards/arm/cxd56xx/common/src/cxd56_sensors.c
index a01a6d634f..26fe4b58d8 100644
--- a/boards/arm/cxd56xx/common/src/cxd56_sensors.c
+++ b/boards/arm/cxd56xx/common/src/cxd56_sensors.c
@@ -216,6 +216,9 @@ static struct sensor_device_s sensor_device[] =
#if defined(CONFIG_SENSORS_BH1745NUC) || defined(CONFIG_SENSORS_BH1745NUC_SCU)
_I2C_DEVICE(bh1745nuc, "/dev/color"), /* Color */
#endif
+#if defined(CONFIG_SENSORS_SCD41)
+ _I2C_DEVICE(scd41, "/dev/co2"), /* CO2 */
+#endif
};
/****************************************************************************
diff --git a/boards/arm/cxd56xx/spresense/include/board.h b/boards/arm/cxd56xx/spresense/include/board.h
index 20cce16a99..af64cfd1c4 100644
--- a/boards/arm/cxd56xx/spresense/include/board.h
+++ b/boards/arm/cxd56xx/spresense/include/board.h
@@ -61,6 +61,7 @@
#include "cxd56_kx022.h"
#include "cxd56_lt1pa01.h"
#include "cxd56_rpr0521rs.h"
+#include "cxd56_scd41.h"
#include "cxd56_sensors.h"
#include "cxd56_isx012.h"
diff --git a/boards/arm/cxd56xx/spresense/include/cxd56_scd41.h b/boards/arm/cxd56xx/spresense/include/cxd56_scd41.h
new file mode 100644
index 0000000000..4a7243a12d
--- /dev/null
+++ b/boards/arm/cxd56xx/spresense/include/cxd56_scd41.h
@@ -0,0 +1,71 @@
+/****************************************************************************
+ * boards/arm/cxd56xx/spresense/include/cxd56_scd41.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_SCD41_H
+#define __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_SCD41_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_scd41_initialize
+ *
+ * Description:
+ * Initialize SCD41 i2c driver and register the SCD41 device.
+ *
+ ****************************************************************************/
+
+#if defined (CONFIG_SENSORS_SCD41)
+int board_scd41_initialize(FAR const char *devpath, int bus);
+#endif
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __BOARDS_ARM_CXD56XX_SPRESENSE_INCLUDE_CXD56_SCD41_H */