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