Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/modules/bmx280thpi2c Split the BMP280 / BME280 driver in...
details: https://anonhg.NetBSD.org/src/rev/4fa8f2800e44
branches: trunk
changeset: 372494:4fa8f2800e44
user: brad <brad%NetBSD.org@localhost>
date: Sat Dec 03 01:04:42 2022 +0000
description:
Split the BMP280 / BME280 driver into common code and create I2C and
SPI attachments.
diffstat:
distrib/sets/lists/debug/module.mi | 4 +-
distrib/sets/lists/modules/mi | 4 +-
share/man/man4/bmx280thp.4 | 15 +-
share/man/man4/spi.4 | 4 +-
sys/conf/files | 6 +-
sys/dev/i2c/bmx280.c | 1145 --------------------------
sys/dev/i2c/bmx280reg.h | 96 --
sys/dev/i2c/bmx280thpi2c.c | 264 +++++
sys/dev/i2c/bmx280var.h | 88 -
sys/dev/i2c/files.i2c | 7 +-
sys/dev/ic/bmx280.c | 1013 +++++++++++++++++++++++
sys/dev/ic/bmx280reg.h | 96 ++
sys/dev/ic/bmx280var.h | 94 ++
sys/dev/spi/bmx280thpspi.c | 205 ++++
sys/dev/spi/files.spi | 6 +-
sys/modules/Makefile | 3 +-
sys/modules/bmx280thp/Makefile | 2 +-
sys/modules/bmx280thp/bmx280thp.ioconf | 5 -
sys/modules/bmx280thpi2c/Makefile | 11 +
sys/modules/bmx280thpi2c/bmx280thpi2c.ioconf | 8 +
20 files changed, 1728 insertions(+), 1348 deletions(-)
diffs (truncated from 3257 to 300 lines):
diff -r 7f25d165374d -r 4fa8f2800e44 distrib/sets/lists/debug/module.mi
--- a/distrib/sets/lists/debug/module.mi Fri Dec 02 19:23:15 2022 +0000
+++ b/distrib/sets/lists/debug/module.mi Sat Dec 03 01:04:42 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: module.mi,v 1.22 2022/11/21 21:24:01 brad Exp $
+# $NetBSD: module.mi,v 1.23 2022/12/03 01:04:43 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
@@ -24,6 +24,8 @@
./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@/bmx280thpi2c modules-base-kernel kmod,debug
+./usr/libdata/debug/@MODULEDIR@/bmx280thpi2c/bmx280thpi2c.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 7f25d165374d -r 4fa8f2800e44 distrib/sets/lists/modules/mi
--- a/distrib/sets/lists/modules/mi Fri Dec 02 19:23:15 2022 +0000
+++ b/distrib/sets/lists/modules/mi Sat Dec 03 01:04:42 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.156 2022/11/21 21:24:01 brad Exp $
+# $NetBSD: mi,v 1.157 2022/12/03 01:04:43 brad Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -33,6 +33,8 @@
./@MODULEDIR@/blowfish/blowfish.kmod modules-base-kernel kmod
./@MODULEDIR@/bmx280thp modules-base-kernel kmod
./@MODULEDIR@/bmx280thp/bmx280thp.kmod modules-base-kernel kmod
+./@MODULEDIR@/bmx280thpi2c modules-base-kernel kmod
+./@MODULEDIR@/bmx280thpi2c/bmx280thpi2c.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 7f25d165374d -r 4fa8f2800e44 share/man/man4/bmx280thp.4
--- a/share/man/man4/bmx280thp.4 Fri Dec 02 19:23:15 2022 +0000
+++ b/share/man/man4/bmx280thp.4 Sat Dec 03 01:04:42 2022 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: bmx280thp.4,v 1.4 2022/11/23 23:49:23 wiz Exp $
+.\" $NetBSD: bmx280thp.4,v 1.5 2022/12/03 01:04:42 brad Exp $
.\"
.\" Copyright (c) 2022 Brad Spencer <brad%anduin.eldar.org@localhost>
.\"
@@ -23,6 +23,9 @@
.Sh SYNOPSIS
.Cd "bmx280thp* at iic? addr 0x76"
.Cd "bmx280thp* at iic? addr 0x77"
+
+.Cd "bmx280thp* at spi? slave 0"
+.Cd "bmx280thp* at spi? slave 1"
.Sh DESCRIPTION
The
.Nm
@@ -35,8 +38,14 @@
.Ar addr
argument selects the address at the
.Xr iic 4
+bus and the
+.Nm
+.Ar slave
+argument selects which chip select will be used on the
+.Xr spi 4
bus.
-The precision of the measurement can be changed through
+The precision of the measurement which is related to the over
+sampling performed on the measurement can be changed through
.Xr sysctl 8
nodes.
.Sh SYSCTL VARIABLES
@@ -82,6 +91,7 @@
.Sh SEE ALSO
.Xr envsys 4 ,
.Xr iic 4 ,
+.Xr spi 4 ,
.Xr envstat 8 ,
.Xr sysctl 8
.Sh HISTORY
@@ -98,4 +108,3 @@
.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 7f25d165374d -r 4fa8f2800e44 share/man/man4/spi.4
--- a/share/man/man4/spi.4 Fri Dec 02 19:23:15 2022 +0000
+++ b/share/man/man4/spi.4 Sat Dec 03 01:04:42 2022 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: spi.4,v 1.12 2021/12/07 17:50:27 brad Exp $
+.\" $NetBSD: spi.4,v 1.13 2022/12/03 01:04:42 brad Exp $
.\"
.\" Copyright (c) 2006 Urbana-Champaign Independent Media Center.
.\" Copyright (c) 2006 Garrett D'Amore.
@@ -131,6 +131,8 @@
.Tn SPI
drivers:
.Bl -tag -width mcp23s17gpio(4) -offset indent
+.It Xr bmx280thp 4
+Bosch BMP280 / BME280 sensor.
.It Xr m25p 4
STMicroelectronics M25P family of NOR flash devices.
.It Xr mcp23s17gpio 4
diff -r 7f25d165374d -r 4fa8f2800e44 sys/conf/files
--- a/sys/conf/files Fri Dec 02 19:23:15 2022 +0000
+++ b/sys/conf/files Sat Dec 03 01:04:42 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1303 2022/11/05 17:31:38 jmcneill Exp $
+# $NetBSD: files,v 1.1304 2022/12/03 01:04:42 brad Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20171118
@@ -437,6 +437,10 @@
device scmd
file dev/ic/scmd.c scmd
+# Bosch BMP280 / BME280 sensor (attaches via I2C or SPI)
+device bmx280thp
+file dev/ic/bmx280.c bmx280thp
+
# Generic HID support (used by USB, bluetooth and i2c)
include "dev/hid/files.hid"
diff -r 7f25d165374d -r 4fa8f2800e44 sys/dev/i2c/bmx280.c
--- a/sys/dev/i2c/bmx280.c Fri Dec 02 19:23:15 2022 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1145 +0,0 @@
-/* $NetBSD: bmx280.c,v 1.6 2022/12/01 02:29:37 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.6 2022/12/01 02:29:37 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 <sys/proc.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,
- },
- {
- .text = 5,
- .mask = BMX280_FILTER_VALUE_5,
- },
- {
- .text = 11,
- .mask = BMX280_FILTER_VALUE_11,
- },
- {
- .text = 22,
- .mask = BMX280_FILTER_VALUE_22,
- }
-};
-
-static uint8_t
-bmx280_osrs_text_to_mask(int t)
-{
- int i;
- uint8_t m = 0;
-
- for (i = 0; i < __arraycount(bmx280_osrs); i++) {
- if (t == bmx280_osrs[i].text) {
- m = bmx280_osrs[i].mask;
- break;
- }
- }
-
- return m;
-}
-
-static uint8_t
-bmx280_irr_text_to_mask(int t)
-{
- int i;
- uint8_t m = 0;
-
- for (i = 0; i < __arraycount(bmx280_irr); i++) {
- if (t == bmx280_irr[i].text) {
- m = bmx280_irr[i].mask;
- break;
- }
- }
-
- return m;
-}
-
-int
-bmx280_verify_sysctl(SYSCTLFN_ARGS)
-{
- int error, t;
- struct sysctlnode node;
-
- node = *rnode;
- t = *(int *)rnode->sysctl_data;
- node.sysctl_data = &t;
- error = sysctl_lookup(SYSCTLFN_CALL(&node));
- if (error || newp == NULL)
Home |
Main Index |
Thread Index |
Old Index