Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/envstat A driver for the Bosch BMP280 / BME280 temp...
details: https://anonhg.NetBSD.org/src/rev/023c20e2ed91
branches: trunk
changeset: 372396:023c20e2ed91
user: brad <brad%NetBSD.org@localhost>
date: Mon Nov 21 21:24:00 2022 +0000
description:
A driver for the Bosch BMP280 / BME280 temperature, humidity and
atmospheric pressure sensor. This is an inexpensive to moderately
expensive chip available from a large number of places. The driver
supports all aspects of the two chips, except for the repeating read
mode which would allow for sub-second queries, such as fall detection
or perhaps even as an altimeter. This driver also only supports the
I2C interface and not the SPI interface.
The BME280, the one with humidity, is not fully tested at this point,
awaiting upon a breakout board and may not show proper humidity.
diffstat:
distrib/sets/lists/debug/module.mi | 4 +-
distrib/sets/lists/man/mi | 5 +-
distrib/sets/lists/modules/mi | 4 +-
share/man/man4/Makefile | 4 +-
share/man/man4/bmx280thp.4 | 89 ++
sys/dev/i2c/bmx280.c | 1074 ++++++++++++++++++++++++++++++++
sys/dev/i2c/bmx280reg.h | 96 ++
sys/dev/i2c/bmx280var.h | 85 ++
sys/dev/i2c/files.i2c | 7 +-
sys/dev/sysmon/sysmon_envsys_tables.c | 5 +-
sys/modules/Makefile | 3 +-
sys/modules/bmx280thp/Makefile | 11 +
sys/modules/bmx280thp/bmx280thp.ioconf | 8 +
sys/sys/envsys.h | 3 +-
usr.sbin/envstat/envstat.8 | 4 +-
usr.sbin/envstat/envstat.c | 51 +-
16 files changed, 1440 insertions(+), 13 deletions(-)
diffs (truncated from 1642 to 300 lines):
diff -r fe3e642ae16a -r 023c20e2ed91 distrib/sets/lists/debug/module.mi
--- a/distrib/sets/lists/debug/module.mi Mon Nov 21 19:07:36 2022 +0000
+++ b/distrib/sets/lists/debug/module.mi Mon Nov 21 21:24:00 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: module.mi,v 1.21 2022/11/17 19:20:06 brad Exp $
+# $NetBSD: module.mi,v 1.22 2022/11/21 21:24:01 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
@@ -22,6 +22,8 @@
./usr/libdata/debug/@MODULEDIR@/blake2s/blake2s.kmod.debug modules-base-kernel kmod,debug
./usr/libdata/debug/@MODULEDIR@/blowfish modules-base-kernel kmod,debug
./usr/libdata/debug/@MODULEDIR@/blowfish/blowfish.kmod.debug modules-base-kernel kmod,debug
+./usr/libdata/debug/@MODULEDIR@/bmx280thp modules-base-kernel kmod,debug
+./usr/libdata/debug/@MODULEDIR@/bmx280thp/bmx280thp.kmod.debug modules-base-kernel kmod,debug
./usr/libdata/debug/@MODULEDIR@/bpf modules-base-kernel kmod,debug
./usr/libdata/debug/@MODULEDIR@/bpf/bpf.kmod.debug modules-base-kernel kmod,debug
./usr/libdata/debug/@MODULEDIR@/bpf_filter modules-base-kernel kmod,debug
diff -r fe3e642ae16a -r 023c20e2ed91 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Mon Nov 21 19:07:36 2022 +0000
+++ b/distrib/sets/lists/man/mi Mon Nov 21 21:24:00 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1755 2022/11/17 19:20:06 brad Exp $
+# $NetBSD: mi,v 1.1756 2022/11/21 21:24:01 brad Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -965,6 +965,7 @@
./usr/share/man/cat4/bio.0 man-sys-catman .cat
./usr/share/man/cat4/bktr.0 man-sys-catman .cat
./usr/share/man/cat4/bluetooth.0 man-sys-catman .cat
+./usr/share/man/cat4/bmx280thp.0 man-sys-catman .cat
./usr/share/man/cat4/bmtphy.0 man-sys-catman .cat
./usr/share/man/cat4/bnx.0 man-sys-catman .cat
./usr/share/man/cat4/boca.0 man-sys-catman .cat
@@ -4237,6 +4238,7 @@
./usr/share/man/html4/bio.html man-sys-htmlman html
./usr/share/man/html4/bktr.html man-sys-htmlman html
./usr/share/man/html4/bluetooth.html man-sys-htmlman html
+./usr/share/man/html4/bmx280thp.html man-sys-htmlman html
./usr/share/man/html4/bmtphy.html man-sys-htmlman html
./usr/share/man/html4/bnx.html man-sys-htmlman html
./usr/share/man/html4/boca.html man-sys-htmlman html
@@ -7275,6 +7277,7 @@
./usr/share/man/man4/bio.4 man-sys-man .man
./usr/share/man/man4/bktr.4 man-sys-man .man
./usr/share/man/man4/bluetooth.4 man-sys-man .man
+./usr/share/man/man4/bmx280thp.4 man-sys-man .man
./usr/share/man/man4/bmtphy.4 man-sys-man .man
./usr/share/man/man4/bnx.4 man-sys-man .man
./usr/share/man/man4/boca.4 man-sys-man .man
diff -r fe3e642ae16a -r 023c20e2ed91 distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi Mon Nov 21 19:07:36 2022 +0000
+++ b/distrib/sets/lists/modules/mi Mon Nov 21 21:24:00 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.155 2022/11/17 19:20:06 brad Exp $
+# $NetBSD: mi,v 1.156 2022/11/21 21:24:01 brad Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -31,6 +31,8 @@
./@MODULEDIR@/blake2s/blake2s.kmod modules-base-kernel kmod
./@MODULEDIR@/blowfish modules-base-kernel kmod
./@MODULEDIR@/blowfish/blowfish.kmod modules-base-kernel kmod
+./@MODULEDIR@/bmx280thp modules-base-kernel kmod
+./@MODULEDIR@/bmx280thp/bmx280thp.kmod modules-base-kernel kmod
./@MODULEDIR@/bpf modules-base-kernel kmod
./@MODULEDIR@/bpf/bpf.kmod modules-base-kernel kmod
./@MODULEDIR@/bpf_filter modules-base-kernel kmod
diff -r fe3e642ae16a -r 023c20e2ed91 share/man/man4/Makefile
--- a/share/man/man4/Makefile Mon Nov 21 19:07:36 2022 +0000
+++ b/share/man/man4/Makefile Mon Nov 21 21:24:00 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.729 2022/11/17 19:20:05 brad Exp $
+# $NetBSD: Makefile,v 1.730 2022/11/21 21:24:00 brad Exp $
# @(#)Makefile 8.1 (Berkeley) 6/18/93
MAN= aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -11,7 +11,7 @@
auacer.4 audio.4 audiocs.4 auich.4 \
auixp.4 autri.4 auvia.4 awi.4 \
battery_pmu.4 bba.4 bce.4 bcsp.4 be.4 bge.4 bnx.4 bha.4 \
- bio.4 bktr.4 bluetooth.4 bmtphy.4 bpf.4 bpfjit.4 \
+ bio.4 bktr.4 bluetooth.4 bmx280thp.4 bmtphy.4 bpf.4 bpfjit.4 \
brgphy.4 bridge.4 bthidev.4 bthub.4 btkbd.4 \
btmagic.4 btms.4 btsco.4 btuart.4 \
bwfm.4 bwi.4 \
diff -r fe3e642ae16a -r 023c20e2ed91 share/man/man4/bmx280thp.4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/bmx280thp.4 Mon Nov 21 21:24:00 2022 +0000
@@ -0,0 +1,89 @@
+.\" $NetBSD: bmx280thp.4,v 1.1 2022/11/21 21:24:00 brad Exp $
+.\"
+.\" Copyright (c) 2022 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 November 19, 2022
+.Dt BMX280THP 4
+.Os
+.Sh NAME
+.Nm bmx280thp
+.Nd Driver for Bosch BMP280/BME280 sensor chip via I2C bus
+.Sh SYNOPSIS
+.Cd "bmx280thp* at iic? addr 0x76"
+.Cd "bmx280thp* at iic? addr 0x77"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides measurements from the BMP280 and BME280 temperature,
+humidity and barometric pressure sensors via the
+.Xr envsys 4
+framework.
+The
+.Nm
+.Ar addr
+argument selects the address at the
+.Xr iic 4
+bus.
+The percision of the measurement can be changed through
+.Xr sysctl 8
+nodes.
+.Sh SYSCTL VARIABLES
+The following
+.Xr sysctl 3
+variables are provided:
+.Bl -tag -width indent
+.It Li hw.bmx280thp0.osrs_t
+.It Li hw.bmx280thp0.osrs_p
+.It Li hw.bmx280thp0.osrs_h
+These control oversampling of temperature, pressure and humidity. The
+valid values are 1, 2, 4, 8, and 16 times oversample. Humidity is only
+available if the chip is a BME280.
+.It Li hw.bmx280thp0.irr_samples
+IRR is a filter that can be used to reduce the noise in the
+measurement. The value values are 1 (or off), 2, 5, 11 and 22 samples
+to reach >= 75% of the step response.
+.It Li hw.bmx280thp0.debug
+.It Li hw.bmx280thp0.dump_calibration
+If the driver is compiled with
+.Dv BMX280_DEBUG ,
+these nodes will appear and can be used to set the debugging level and
+provide the calibration constants, upon refresh, that are stored in the
+chip. Since the constants are fixed, this is a boolean node and will
+reset back to false once one dump has been performed.
+.It Li hw.bmx280thp0.readattempts
+A status register tells the driver if the chip is busy with a measurement.
+This status register must be polled and readattempts is the number of times
+that this poll will be performed.
+The default is 25 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 support the continuous read mode that the BMP280
+and BME280 has. This driver does not support the SPI interface.
diff -r fe3e642ae16a -r 023c20e2ed91 sys/dev/i2c/bmx280.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/bmx280.c Mon Nov 21 21:24:00 2022 +0000
@@ -0,0 +1,1074 @@
+/* $NetBSD: bmx280.c,v 1.1 2022/11/21 21:24:01 brad Exp $ */
+
+/*
+ * Copyright (c) 2022 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.1 2022/11/21 21:24:01 brad Exp $");
+
+/*
+ Driver for the Bosch BMP280/BME280 temperature, humidity (sometimes) and
+ (usually barometric) pressure sensor
+*/
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/module.h>
+#include <sys/sysctl.h>
+#include <sys/mutex.h>
+
+#include <dev/sysmon/sysmonvar.h>
+#include <dev/i2c/i2cvar.h>
+#include <dev/i2c/bmx280reg.h>
+#include <dev/i2c/bmx280var.h>
+
+
+static int bmx280_write_register(i2c_tag_t, i2c_addr_t,
+ uint8_t *, size_t);
+static int bmx280_read_register(i2c_tag_t, i2c_addr_t, uint8_t *,
+ uint8_t *, size_t);
+static void bmx280_store_raw_blob_tp(struct bmx280_sc *, uint8_t *);
+static void bmx280_store_raw_blob_h(struct bmx280_sc *, uint8_t *);
+static int bmx280_poke(i2c_tag_t, i2c_addr_t, bool);
+static int bmx280_match(device_t, cfdata_t, void *);
+static void bmx280_attach(device_t, device_t, void *);
+static int bmx280_detach(device_t, int);
+static void bmx280_refresh(struct sysmon_envsys *, envsys_data_t *);
+static int bmx280_verify_sysctl(SYSCTLFN_ARGS);
+static int bmx280_verify_sysctl_osrs(SYSCTLFN_ARGS);
+static int bmx280_verify_sysctl_irr(SYSCTLFN_ARGS);
+
+#define BMX280_DEBUG
+#ifdef BMX280_DEBUG
+#define DPRINTF(s, l, x) \
+ do { \
+ if (l <= s->sc_bmx280debug) \
+ printf x; \
+ } while (/*CONSTCOND*/0)
+#else
+#define DPRINTF(s, l, x)
+#endif
+
+CFATTACH_DECL_NEW(bmx280thp, sizeof(struct bmx280_sc),
+ bmx280_match, bmx280_attach, bmx280_detach, NULL);
+
+static struct bmx280_sensor bmx280_sensors[] = {
+ {
+ .desc = "temperature",
+ .type = ENVSYS_STEMP,
+ },
+ {
+ .desc = "pressure",
+ .type = ENVSYS_PRESSURE,
+ },
+ {
+ .desc = "humidity",
+ .type = ENVSYS_SRELHUMIDITY,
+ }
+};
+
+static struct bmx280_osrs_list bmx280_osrs[] = {
+ {
+ .text = 1,
+ .mask = BMX280_OSRS_TP_VALUE_X1,
+ },
+ {
+ .text = 2,
+ .mask = BMX280_OSRS_TP_VALUE_X2,
+ },
+ {
+ .text = 4,
+ .mask = BMX280_OSRS_TP_VALUE_X4,
+ },
+ {
+ .text = 8,
+ .mask = BMX280_OSRS_TP_VALUE_X8,
+ },
+ {
+ .text = 16,
+ .mask = BMX280_OSRS_TP_VALUE_X16,
+ }
+};
+
+static struct bmx280_irr_list bmx280_irr[] = {
+ {
+ .text = 1,
+ .mask = BMX280_FILTER_VALUE_OFF,
+ },
+ {
+ .text = 2,
+ .mask = BMX280_FILTER_VALUE_2,
+ },
Home |
Main Index |
Thread Index |
Old Index