Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/modules/sgp40mox A driver for the Sensirion SGP40 MOx ga...



details:   https://anonhg.NetBSD.org/src/rev/91066dcfa308
branches:  trunk
changeset: 989495:91066dcfa308
user:      brad <brad%NetBSD.org@localhost>
date:      Thu Oct 14 13:54:45 2021 +0000

description:
A driver for the Sensirion SGP40 MOx gas sensor.  An example of this
chip from Adafruit is:

https://www.adafruit.com/product/4829

This is a moderately priced gas sensor that can detect volatile
organic compounds in the air.  The driver uses the 3-clause BSD
licensed VOC algorithm provided by Sensirion to turn the raw sensor
metric into a VOC index which can indicate the quality of the air in a
particular indoor environment.  All published functions of the chip
are supported and one unpublished feature.

diffstat:

 distrib/sets/lists/debug/module.mi    |    4 +-
 distrib/sets/lists/man/mi             |    5 +-
 distrib/sets/lists/modules/mi         |    4 +-
 share/man/man4/Makefile               |    6 +-
 share/man/man4/sgp40mox.4             |  107 ++++
 sys/dev/i2c/files.i2c                 |    8 +-
 sys/dev/i2c/sensirion_arch_config.h   |   33 +
 sys/dev/i2c/sensirion_voc_algorithm.c |  809 ++++++++++++++++++++++++++++++++++
 sys/dev/i2c/sensirion_voc_algorithm.h |  191 ++++++++
 sys/dev/i2c/sgp40.c                   |  802 +++++++++++++++++++++++++++++++++
 sys/dev/i2c/sgp40reg.h                |   50 ++
 sys/dev/i2c/sgp40var.h                |   61 ++
 sys/modules/Makefile                  |    3 +-
 sys/modules/sgp40mox/Makefile         |   12 +
 sys/modules/sgp40mox/sgp40mox.ioconf  |    8 +
 15 files changed, 2095 insertions(+), 8 deletions(-)

diffs (truncated from 2237 to 300 lines):

diff -r a2a7d9b68d30 -r 91066dcfa308 distrib/sets/lists/debug/module.mi
--- a/distrib/sets/lists/debug/module.mi        Thu Oct 14 13:50:36 2021 +0000
+++ b/distrib/sets/lists/debug/module.mi        Thu Oct 14 13:54:45 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: module.mi,v 1.13 2021/10/04 07:04:39 brad Exp $
+# $NetBSD: module.mi,v 1.14 2021/10/14 13:54:46 brad Exp $
 ./usr/libdata/debug/@MODULEDIR@                                        modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/accf_dataready                 modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/accf_dataready/accf_dataready.kmod.debug       modules-base-kernel     kmod,debug
@@ -332,6 +332,8 @@
 ./usr/libdata/debug/@MODULEDIR@/securelevel/securelevel.kmod.debug     modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/sequencer                              modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/sequencer/sequencer.kmod.debug         modules-base-kernel     kmod,debug
+./usr/libdata/debug/@MODULEDIR@/sgp40mox                               modules-base-kernel     kmod,debug
+./usr/libdata/debug/@MODULEDIR@/sgp40mox/sgp40mox.kmod.debug           modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/sht4xtemp                              modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/sht4xtemp/sht4xtemp.kmod.debug         modules-base-kernel     kmod,debug
 ./usr/libdata/debug/@MODULEDIR@/si70xxtemp                             modules-base-kernel     kmod,debug
diff -r a2a7d9b68d30 -r 91066dcfa308 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Thu Oct 14 13:50:36 2021 +0000
+++ b/distrib/sets/lists/man/mi Thu Oct 14 13:54:45 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1727 2021/10/12 04:55:19 msaitoh Exp $
+# $NetBSD: mi,v 1.1728 2021/10/14 13:54:46 brad Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1720,6 +1720,7 @@
 ./usr/share/man/cat4/sgimips/pic.0             man-sys-catman          .cat
 ./usr/share/man/cat4/sgimips/sq.0              man-sys-catman          .cat
 ./usr/share/man/cat4/sgimips/wdsc.0            man-sys-catman          .cat
+./usr/share/man/cat4/sgp40mox.0                        man-sys-catman          .cat
 ./usr/share/man/cat4/sgsmix.0                  man-sys-catman          .cat
 ./usr/share/man/cat4/shb.0                     man-sys-catman          .cat
 ./usr/share/man/cat4/shmif.0                   man-sys-catman          .cat
@@ -4895,6 +4896,7 @@
 ./usr/share/man/html4/sgimips/pic.html         man-sys-htmlman         html
 ./usr/share/man/html4/sgimips/sq.html          man-sys-htmlman         html
 ./usr/share/man/html4/sgimips/wdsc.html                man-sys-htmlman         html
+./usr/share/man/html4/sgp40mox.html            man-sys-htmlman         html
 ./usr/share/man/html4/sgsmix.html              man-sys-htmlman         html
 ./usr/share/man/html4/shb.html                 man-sys-htmlman         html
 ./usr/share/man/html4/shmif.html               man-sys-htmlman         html
@@ -7976,6 +7978,7 @@
 ./usr/share/man/man4/sgimips/pic.4             man-sys-man             .man
 ./usr/share/man/man4/sgimips/sq.4              man-sys-man             .man
 ./usr/share/man/man4/sgimips/wdsc.4            man-sys-man             .man
+./usr/share/man/man4/sgp40mox.4                        man-sys-man             .man
 ./usr/share/man/man4/sgsmix.4                  man-sys-man             .man
 ./usr/share/man/man4/shb.4                     man-sys-man             .man
 ./usr/share/man/man4/shmif.4                   man-sys-man             .man
diff -r a2a7d9b68d30 -r 91066dcfa308 distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi     Thu Oct 14 13:50:36 2021 +0000
+++ b/distrib/sets/lists/modules/mi     Thu Oct 14 13:54:45 2021 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.147 2021/10/03 17:27:02 brad Exp $
+# $NetBSD: mi,v 1.148 2021/10/14 13:54:46 brad Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -397,6 +397,8 @@
 ./@MODULEDIR@/securelevel/securelevel.kmod     modules-base-kernel     kmod
 ./@MODULEDIR@/sequencer                                modules-base-kernel     kmod
 ./@MODULEDIR@/sequencer/sequencer.kmod         modules-base-kernel     kmod
+./@MODULEDIR@/sgp40mox                         modules-base-kernel     kmod
+./@MODULEDIR@/sgp40mox/sgp40mox.kmod           modules-base-kernel     kmod
 ./@MODULEDIR@/sht4xtemp                                modules-base-kernel     kmod
 ./@MODULEDIR@/sht4xtemp/sht4xtemp.kmod         modules-base-kernel     kmod
 ./@MODULEDIR@/si70xxtemp                       modules-base-kernel     kmod
diff -r a2a7d9b68d30 -r 91066dcfa308 share/man/man4/Makefile
--- a/share/man/man4/Makefile   Thu Oct 14 13:50:36 2021 +0000
+++ b/share/man/man4/Makefile   Thu Oct 14 13:54:45 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.717 2021/10/12 04:55:19 msaitoh Exp $
+#      $NetBSD: Makefile,v 1.718 2021/10/14 13:54:45 brad Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/18/93
 
 MAN=   aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -56,8 +56,8 @@
        rnd.4 route.4 rs5c372rtc.4 rtk.4 rtsx.4 rtw.4 rtwn.4 rum.4 run.4 \
        s390rtc.4 satalink.4 sbus.4 schide.4 \
        scsi.4 sctp.4 sd.4 se.4 seeprom.4 sem.4 \
-       ses.4 sf.4 sfb.4 sgsmix.4 shb.4 shmif.4 shpcic.4 sht4xtemp.4 si70xxtemp.4 \
-       siisata.4 siop.4 sip.4 siside.4 sk.4 sl.4 slide.4 \
+       ses.4 sf.4 sfb.4 sgp40mox.4 sgsmix.4 shb.4 shmif.4 shpcic.4 sht4xtemp.4 \
+       si70xxtemp.4 siisata.4 siop.4 sip.4 siside.4 sk.4 sl.4 slide.4 \
        sm.4 smscphy.4 smsh.4 sn.4 sony.4 spc.4 speaker.4 spif.4 sqphy.4 \
        srt.4 ss.4 \
        ssdfb.4 st.4 ste.4 stge.4 sti.4 stpcide.4 sv.4 \
diff -r a2a7d9b68d30 -r 91066dcfa308 share/man/man4/sgp40mox.4
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/sgp40mox.4 Thu Oct 14 13:54:45 2021 +0000
@@ -0,0 +1,107 @@
+.\" $NetBSD: sgp40mox.4,v 1.1 2021/10/14 13:54:45 brad Exp $
+.\"
+.\" Copyright (c) 2021 Brad Spencer <brad%anduin.eldar.org@localhost>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd October 7, 2021
+.Dt SGP40MOX 4
+.Os
+.Sh NAME
+.Nm sgp40mox
+.Nd Driver for Sensirion SGP40 MOx gas sensor
+.Sh SYNOPSIS
+.Cd "sgp40mox* at iic? addr 0x59"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides an air quality measurement from the SGP40
+sensor via the
+.Xr envsys 4
+framework.
+The
+.Nm
+.Ar addr
+argument selects the address at the
+.Xr iic 4
+bus.
+The crc validity and temperature and %RH compensation can be changed through
+.Xr sysctl 8
+nodes.
+.Pp
+In order to calculate the VOC index, the volatile organic compounds index, which
+is the measure of air quality the sensor is polled once a second and the raw sensor
+value is fed into the Sensirion VOC algorithm.  This VOC algorithm used in this driver
+is licensed under a 3 clause BSD license and was pulled from the Sensirion Github
+repository at
+.Rs
+.%U https://github.com/Sensirion/embedded-sgp
+.Re
+.Sh SYSCTL VARIABLES
+The following
+.Xr sysctl 3
+variables are provided:
+.Bl -tag -width indent
+.It Li hw.sgp40mox0.compensation.temperature
+This should be set to the temperature in Celsius of the environment that the sensor
+is in.  The valid values are from -45 to 130 degrees Celsius.
+.It Li hw.sgp40mox0.compensation.humidity
+This should be set to the %RH of the environment that the sensor is in.  The valid
+values are from 0 to 100.
+.Pp
+For the best performance of the VOC algorithm it is important that the temperature
+and %RH compensation values be current and set using the
+.Xr sysctl 3
+variables mentioned above.
+This data will need to be pulled from another source, such as a another sensor in
+the environment that the SGP40 is in.
+.It Li hw.sgp40mox0.ignorecrc
+If set, the crc calculation will be ignored on the calls to the chip for the purposes
+of measurement.
+.It Li hw.sgp40mox0.debug
+If the driver is compiled with
+.Dv SGP40_DEBUG ,
+this node will appear and can be used to set the debugging level.
+.It Li hw.sgp40mox0.readattempts
+To read the air quality metric from the chip requires that the command be sent,
+then a delay must be observed before a read can be done to get the values
+back.
+The delays are documented in the data sheet for the chip.
+The driver will attempt to read back the values readattempts number of
+times.
+The default is 10 which should be more than enough for most purposes.
+.El
+.Sh SEE ALSO
+.Xr envsys 4 ,
+.Xr iic 4 ,
+.Xr envstat 8 ,
+.Xr sysctl 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Nx 10.0 .
+.Sh AUTHORS
+.An -nosplit
+The
+.Nm
+driver was written by
+.An Brad Spencer Aq Mt brad%anduin.eldar.org@localhost .
+.Sh BUGS
+The driver does not make complete use of the VOC algorithm.  In particular, there is no
+need to restart the algorithm from scratch if there is a stoppage of polling for less than
+10 minutes.  The driver does not have the ability to determine that, and therefore
+assumes that the sensor is completely cold each time the driver attaches to the chip.
+.Pp
+The temperature and humidity compensation could be allowed to contain fractional degrees Celsius
+and %RH.  The driver only supports setting whole numbers for either of those.
diff -r a2a7d9b68d30 -r 91066dcfa308 sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c     Thu Oct 14 13:50:36 2021 +0000
+++ b/sys/dev/i2c/files.i2c     Thu Oct 14 13:54:45 2021 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i2c,v 1.117 2021/10/03 17:27:02 brad Exp $
+#      $NetBSD: files.i2c,v 1.118 2021/10/14 13:54:46 brad Exp $
 
 obsolete defflag       opt_i2cbus.h            I2C_SCAN
 define i2cbus { }
@@ -400,6 +400,12 @@
 attach sht4xtemp at iic
 file dev/i2c/sht4x.c                           sht4xtemp
 
+# Sensirion SGP40 MOx gas sensor
+device sgp40mox
+attach sgp40mox at iic
+file dev/i2c/sgp40.c                           sgp40mox
+file dev/i2c/sensirion_voc_algorithm.c         sgp40mox
+
 # Philips PCA955x GPIO
 device pcagpio: leds
 attach pcagpio at iic
diff -r a2a7d9b68d30 -r 91066dcfa308 sys/dev/i2c/sensirion_arch_config.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/sensirion_arch_config.h       Thu Oct 14 13:54:45 2021 +0000
@@ -0,0 +1,33 @@
+/*     $NetBSD: sensirion_arch_config.h,v 1.1 2021/10/14 13:54:46 brad Exp $   */
+
+/*
+ * Copyright (c) 2021 Brad Spencer <brad%anduin.eldar.org@localhost>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGL`IGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+/* The Sensirion code wants a file called sensirion_arch_config.h.  This
+   is the shim for NetBSD
+*/
+
+#ifndef SENSIRION_ARCH_CONFIG_H
+#define SENSIRION_ARCH_CONFIG_H
+
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+
+
+#endif /* SENSIRION_ARCH_CONFIG_H */
diff -r a2a7d9b68d30 -r 91066dcfa308 sys/dev/i2c/sensirion_voc_algorithm.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/sensirion_voc_algorithm.c     Thu Oct 14 13:54:45 2021 +0000
@@ -0,0 +1,809 @@
+/*
+ *     $NetBSD: sensirion_voc_algorithm.c,v 1.1 2021/10/14 13:54:46 brad Exp $
+ */
+
+/*
+ * Copyright (c) 2021, Sensirion AG
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Sensirion AG nor the names of its
+ *   contributors may be used to endorse or promote products derived from
+ *   this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "sensirion_voc_algorithm.h"
+



Home | Main Index | Thread Index | Old Index