1 /* $NetBSD: bmx280var.h,v 1.3 2025/09/13 16:16:40 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 2022 Brad Spencer <brad (at) 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 51 struct bmx280_accessfuncs { 52 int (*acquire_bus)(struct bmx280_sc *); 53 void (*release_bus)(struct bmx280_sc *); 54 int (*read_reg)(struct bmx280_sc *, uint8_t, uint8_t *, 55 size_t); 56 int (*write_reg)(struct bmx280_sc *, uint8_t *, size_t); 57 }; 58 59 struct bmx280_sc { 60 int sc_bmx280debug; 61 device_t sc_dev; 62 const struct bmx280_accessfuncs *sc_funcs; 63 64 kmutex_t sc_mutex; 65 int sc_numsensors; 66 struct sysmon_envsys *sc_sme; 67 struct sysctllog *sc_bmx280log; 68 envsys_data_t sc_sensors[BMX280_NUM_SENSORS]; 69 struct bmx280_calibration_blob sc_cal_blob; 70 bool sc_has_humidity; 71 int sc_readattempts; 72 int sc_osrs_t; 73 int sc_osrs_p; 74 int sc_osrs_h; 75 int sc_irr_samples; 76 uint8_t sc_previous_irr; 77 bool sc_bmx280dump; 78 int sc_waitfactor_t; 79 int sc_waitfactor_p; 80 int sc_waitfactor_h; 81 }; 82 83 struct bmx280_sensor { 84 const char *desc; 85 enum envsys_units type; 86 }; 87 88 struct bmx280_osrs_list { 89 const int text; 90 uint8_t mask; 91 }; 92 93 struct bmx280_irr_list { 94 const int text; 95 uint8_t mask; 96 }; 97 98 extern const struct device_compatible_entry bmx280_compat_data[]; 99 100 void bmx280_attach(struct bmx280_sc *); 101 int bmx280_detach(struct bmx280_sc *, int); 102 103 #endif 104