1 /*        $NetBSD: bmx280var.h,v 1.1 2022/12/03 01:04:43 brad Exp $   */
2 
3 /*
4  * Copyright (c) 2022 Brad Spencer <brad@anduin.eldar.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _DEV_IC_BMX280VAR_H_
20 #define _DEV_IC_BMX280VAR_H_
21 
22 #define BMX280_NUM_SENSORS    3
23 #define BMX280_TEMP_SENSOR 0
24 #define BMX280_PRESSURE_SENSOR 1
25 #define BMX280_HUMIDITY_SENSOR 2
26 
27 struct bmx280_calibration_blob {
28           uint16_t dig_T1;
29           int16_t dig_T2;
30           int16_t dig_T3;
31 
32           uint16_t dig_P1;
33           int16_t dig_P2;
34           int16_t dig_P3;
35           int16_t dig_P4;
36           int16_t dig_P5;
37           int16_t dig_P6;
38           int16_t dig_P7;
39           int16_t dig_P8;
40           int16_t dig_P9;
41           uint8_t dig_H1;
42           int16_t dig_H2;
43           uint8_t dig_H3;
44           int16_t dig_H4;
45           int16_t dig_H5;
46           int8_t dig_H6;
47 };
48 
49 struct bmx280_sc {
50           int                 sc_bmx280debug;
51           device_t  sc_dev;
52           i2c_tag_t           sc_tag;
53           i2c_addr_t          sc_addr;
54           struct spi_handle *sc_sh;
55           kmutex_t  sc_mutex;
56           int                 sc_numsensors;
57           struct sysmon_envsys *sc_sme;
58           struct sysctllog *sc_bmx280log;
59           envsys_data_t       sc_sensors[BMX280_NUM_SENSORS];
60           struct bmx280_calibration_blob          sc_cal_blob;
61           bool                sc_has_humidity;
62           int                 sc_readattempts;
63           int                 sc_osrs_t;
64           int                 sc_osrs_p;
65           int                 sc_osrs_h;
66           int                 sc_irr_samples;
67           uint8_t             sc_previous_irr;
68           bool                sc_bmx280dump;
69           int                 sc_waitfactor_t;
70           int                 sc_waitfactor_p;
71           int                 sc_waitfactor_h;
72           void                (*sc_func_attach)(struct bmx280_sc *);
73           int                 (*sc_func_acquire_bus)(struct bmx280_sc *);
74           void                (*sc_func_release_bus)(struct bmx280_sc *);
75           int                 (*sc_func_read_register)(struct bmx280_sc *, uint8_t, uint8_t *, size_t);
76           int                 (*sc_func_write_register)(struct bmx280_sc *, uint8_t *, size_t);
77 };
78 
79 struct bmx280_sensor {
80           const char     *desc;
81           enum envsys_units type;
82 };
83 
84 struct bmx280_osrs_list {
85           const int text;
86           uint8_t             mask;
87 };
88 
89 struct bmx280_irr_list {
90           const int text;
91           uint8_t             mask;
92 };
93 
94 #endif
95