48#include <linux/types.h>
49#include <linux/kernel.h>
59#if !defined(UINT8_C) && !defined(INT8_C)
60#define INT8_C(x) S8_C(x)
61#define UINT8_C(x) U8_C(x)
64#if !defined(UINT16_C) && !defined(INT16_C)
65#define INT16_C(x) S16_C(x)
66#define UINT16_C(x) U16_C(x)
69#if !defined(INT32_C) && !defined(UINT32_C)
70#define INT32_C(x) S32_C(x)
71#define UINT32_C(x) U32_C(x)
74#if !defined(INT64_C) && !defined(UINT64_C)
75#define INT64_C(x) S64_C(x)
76#define UINT64_C(x) U64_C(x)
85#define NULL ((void *) 0)
89#ifndef BME68X_DO_NOT_USE_FPU
96#ifndef BME68X_PERIOD_POLL
97#define BME68X_PERIOD_POLL UINT32_C(10000)
101#define BME68X_CHIP_ID UINT8_C(0x61)
104#define BME68X_PERIOD_RESET UINT32_C(10000)
107#define BME68X_I2C_ADDR_LOW UINT8_C(0x76)
110#define BME68X_I2C_ADDR_HIGH UINT8_C(0x77)
113#define BME68X_SOFT_RESET_CMD UINT8_C(0xb6)
117#define BME68X_OK INT8_C(0)
121#define BME68X_E_NULL_PTR INT8_C(-1)
124#define BME68X_E_COM_FAIL INT8_C(-2)
127#define BME68X_E_DEV_NOT_FOUND INT8_C(-3)
130#define BME68X_E_INVALID_LENGTH INT8_C(-4)
133#define BME68X_E_SELF_TEST INT8_C(-5)
137#define BME68X_W_DEFINE_OP_MODE INT8_C(1)
140#define BME68X_W_NO_NEW_DATA INT8_C(2)
143#define BME68X_W_DEFINE_SHD_HEATR_DUR INT8_C(3)
146#define BME68X_I_PARAM_CORR UINT8_C(1)
150#define BME68X_REG_COEFF3 UINT8_C(0x00)
153#define BME68X_REG_FIELD0 UINT8_C(0x1d)
156#define BME68X_REG_IDAC_HEAT0 UINT8_C(0x50)
159#define BME68X_REG_RES_HEAT0 UINT8_C(0x5a)
162#define BME68X_REG_GAS_WAIT0 UINT8_C(0x64)
165#define BME68X_REG_SHD_HEATR_DUR UINT8_C(0x6E)
168#define BME68X_REG_CTRL_GAS_0 UINT8_C(0x70)
171#define BME68X_REG_CTRL_GAS_1 UINT8_C(0x71)
174#define BME68X_REG_CTRL_HUM UINT8_C(0x72)
177#define BME68X_REG_CTRL_MEAS UINT8_C(0x74)
180#define BME68X_REG_CONFIG UINT8_C(0x75)
183#define BME68X_REG_MEM_PAGE UINT8_C(0xf3)
186#define BME68X_REG_UNIQUE_ID UINT8_C(0x83)
189#define BME68X_REG_COEFF1 UINT8_C(0x8a)
192#define BME68X_REG_CHIP_ID UINT8_C(0xd0)
195#define BME68X_REG_SOFT_RESET UINT8_C(0xe0)
198#define BME68X_REG_COEFF2 UINT8_C(0xe1)
201#define BME68X_REG_VARIANT_ID UINT8_C(0xF0)
206#define BME68X_ENABLE UINT8_C(0x01)
209#define BME68X_DISABLE UINT8_C(0x00)
214#define BME68X_VARIANT_GAS_LOW UINT8_C(0x00)
217#define BME68X_VARIANT_GAS_HIGH UINT8_C(0x01)
222#define BME68X_OS_NONE UINT8_C(0)
225#define BME68X_OS_1X UINT8_C(1)
228#define BME68X_OS_2X UINT8_C(2)
231#define BME68X_OS_4X UINT8_C(3)
234#define BME68X_OS_8X UINT8_C(4)
237#define BME68X_OS_16X UINT8_C(5)
242#define BME68X_FILTER_OFF UINT8_C(0)
245#define BME68X_FILTER_SIZE_1 UINT8_C(1)
248#define BME68X_FILTER_SIZE_3 UINT8_C(2)
251#define BME68X_FILTER_SIZE_7 UINT8_C(3)
254#define BME68X_FILTER_SIZE_15 UINT8_C(4)
257#define BME68X_FILTER_SIZE_31 UINT8_C(5)
260#define BME68X_FILTER_SIZE_63 UINT8_C(6)
263#define BME68X_FILTER_SIZE_127 UINT8_C(7)
268#define BME68X_ODR_0_59_MS UINT8_C(0)
271#define BME68X_ODR_62_5_MS UINT8_C(1)
274#define BME68X_ODR_125_MS UINT8_C(2)
277#define BME68X_ODR_250_MS UINT8_C(3)
280#define BME68X_ODR_500_MS UINT8_C(4)
283#define BME68X_ODR_1000_MS UINT8_C(5)
286#define BME68X_ODR_10_MS UINT8_C(6)
289#define BME68X_ODR_20_MS UINT8_C(7)
292#define BME68X_ODR_NONE UINT8_C(8)
297#define BME68X_SLEEP_MODE UINT8_C(0)
300#define BME68X_FORCED_MODE UINT8_C(1)
303#define BME68X_PARALLEL_MODE UINT8_C(2)
306#define BME68X_SEQUENTIAL_MODE UINT8_C(3)
311#define BME68X_MEM_PAGE0 UINT8_C(0x10)
314#define BME68X_MEM_PAGE1 UINT8_C(0x00)
319#define BME68X_LEN_COEFF_ALL UINT8_C(42)
322#define BME68X_LEN_COEFF1 UINT8_C(23)
325#define BME68X_LEN_COEFF2 UINT8_C(14)
328#define BME68X_LEN_COEFF3 UINT8_C(5)
331#define BME68X_LEN_FIELD UINT8_C(17)
334#define BME68X_LEN_FIELD_OFFSET UINT8_C(17)
337#define BME68X_LEN_CONFIG UINT8_C(5)
340#define BME68X_LEN_INTERLEAVE_BUFF UINT8_C(20)
345#define BME68X_IDX_T2_LSB (0)
348#define BME68X_IDX_T2_MSB (1)
351#define BME68X_IDX_T3 (2)
354#define BME68X_IDX_P1_LSB (4)
357#define BME68X_IDX_P1_MSB (5)
360#define BME68X_IDX_P2_LSB (6)
363#define BME68X_IDX_P2_MSB (7)
366#define BME68X_IDX_P3 (8)
369#define BME68X_IDX_P4_LSB (10)
372#define BME68X_IDX_P4_MSB (11)
375#define BME68X_IDX_P5_LSB (12)
378#define BME68X_IDX_P5_MSB (13)
381#define BME68X_IDX_P7 (14)
384#define BME68X_IDX_P6 (15)
387#define BME68X_IDX_P8_LSB (18)
390#define BME68X_IDX_P8_MSB (19)
393#define BME68X_IDX_P9_LSB (20)
396#define BME68X_IDX_P9_MSB (21)
399#define BME68X_IDX_P10 (22)
402#define BME68X_IDX_H2_MSB (23)
405#define BME68X_IDX_H2_LSB (24)
408#define BME68X_IDX_H1_LSB (24)
411#define BME68X_IDX_H1_MSB (25)
414#define BME68X_IDX_H3 (26)
417#define BME68X_IDX_H4 (27)
420#define BME68X_IDX_H5 (28)
423#define BME68X_IDX_H6 (29)
426#define BME68X_IDX_H7 (30)
429#define BME68X_IDX_T1_LSB (31)
432#define BME68X_IDX_T1_MSB (32)
435#define BME68X_IDX_GH2_LSB (33)
438#define BME68X_IDX_GH2_MSB (34)
441#define BME68X_IDX_GH1 (35)
444#define BME68X_IDX_GH3 (36)
447#define BME68X_IDX_RES_HEAT_VAL (37)
450#define BME68X_IDX_RES_HEAT_RANGE (39)
453#define BME68X_IDX_RANGE_SW_ERR (41)
458#define BME68X_DISABLE_GAS_MEAS UINT8_C(0x00)
461#define BME68X_ENABLE_GAS_MEAS_L UINT8_C(0x01)
464#define BME68X_ENABLE_GAS_MEAS_H UINT8_C(0x02)
469#define BME68X_ENABLE_HEATER UINT8_C(0x00)
472#define BME68X_DISABLE_HEATER UINT8_C(0x01)
477#define BME68X_MIN_TEMPERATURE INT16_C(0)
480#define BME68X_MAX_TEMPERATURE INT16_C(60)
483#define BME68X_MIN_PRESSURE UINT32_C(90000)
486#define BME68X_MAX_PRESSURE UINT32_C(110000)
489#define BME68X_MIN_HUMIDITY UINT32_C(20)
492#define BME68X_MAX_HUMIDITY UINT32_C(80)
496#define BME68X_MIN_TEMPERATURE INT16_C(0)
499#define BME68X_MAX_TEMPERATURE INT16_C(6000)
502#define BME68X_MIN_PRESSURE UINT32_C(90000)
505#define BME68X_MAX_PRESSURE UINT32_C(110000)
508#define BME68X_MIN_HUMIDITY UINT32_C(20000)
511#define BME68X_MAX_HUMIDITY UINT32_C(80000)
515#define BME68X_HEATR_DUR1 UINT16_C(1000)
516#define BME68X_HEATR_DUR2 UINT16_C(2000)
517#define BME68X_HEATR_DUR1_DELAY UINT32_C(1000000)
518#define BME68X_HEATR_DUR2_DELAY UINT32_C(2000000)
519#define BME68X_N_MEAS UINT8_C(6)
520#define BME68X_LOW_TEMP UINT8_C(150)
521#define BME68X_HIGH_TEMP UINT16_C(350)
525#define BME68X_NBCONV_MSK UINT8_C(0X0f)
528#define BME68X_FILTER_MSK UINT8_C(0X1c)
531#define BME68X_ODR3_MSK UINT8_C(0x80)
534#define BME68X_ODR20_MSK UINT8_C(0xe0)
537#define BME68X_OST_MSK UINT8_C(0Xe0)
540#define BME68X_OSP_MSK UINT8_C(0X1c)
543#define BME68X_OSH_MSK UINT8_C(0X07)
546#define BME68X_HCTRL_MSK UINT8_C(0x08)
549#define BME68X_RUN_GAS_MSK UINT8_C(0x30)
552#define BME68X_MODE_MSK UINT8_C(0x03)
555#define BME68X_RHRANGE_MSK UINT8_C(0x30)
558#define BME68X_RSERROR_MSK UINT8_C(0xf0)
561#define BME68X_NEW_DATA_MSK UINT8_C(0x80)
564#define BME68X_GAS_INDEX_MSK UINT8_C(0x0f)
567#define BME68X_GAS_RANGE_MSK UINT8_C(0x0f)
570#define BME68X_GASM_VALID_MSK UINT8_C(0x20)
573#define BME68X_HEAT_STAB_MSK UINT8_C(0x10)
576#define BME68X_MEM_PAGE_MSK UINT8_C(0x10)
579#define BME68X_SPI_RD_MSK UINT8_C(0x80)
582#define BME68X_SPI_WR_MSK UINT8_C(0x7f)
585#define BME68X_BIT_H1_DATA_MSK UINT8_C(0x0f)
590#define BME68X_FILTER_POS UINT8_C(2)
593#define BME68X_OST_POS UINT8_C(5)
596#define BME68X_OSP_POS UINT8_C(2)
599#define BME68X_ODR3_POS UINT8_C(7)
602#define BME68X_ODR20_POS UINT8_C(5)
605#define BME68X_RUN_GAS_POS UINT8_C(4)
608#define BME68X_HCTRL_POS UINT8_C(3)
611#define BME68X_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb)
614#define BME68X_SET_BITS(reg_data, bitname, data) \
615 ((reg_data & ~(bitname##_MSK)) | \
616 ((data << bitname##_POS) & bitname##_MSK))
619#define BME68X_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
623#define BME68X_SET_BITS_POS_0(reg_data, bitname, data) \
624 ((reg_data & ~(bitname##_MSK)) | \
625 (data & bitname##_MSK))
628#define BME68X_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
634#ifndef BME68X_INTF_RET_TYPE
635#define BME68X_INTF_RET_TYPE int8_t
643#ifndef BME68X_INTF_RET_SUCCESS
644#define BME68X_INTF_RET_SUCCESS INT8_C(0)
663typedef BME68X_INTF_RET_TYPE (*bme68x_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t length,
679typedef BME68X_INTF_RET_TYPE (*bme68x_write_fptr_t)(uint8_t reg_addr,
const uint8_t *reg_data, uint32_t length,
690typedef void (*bme68x_delay_us_fptr_t)(uint32_t period,
void *intf_ptr);
737#ifndef BME68X_USE_FPU
749 uint32_t gas_resistance;
762 float gas_resistance;
771struct bme68x_calib_data
841#ifndef BME68X_USE_FPU
852 uint8_t res_heat_range;
889struct bme68x_heatr_conf
901 uint16_t *heatr_temp_prof;
904 uint16_t *heatr_dur_prof;
913 uint16_t shared_heatr_dur;
944 enum bme68x_intf intf;
953 struct bme68x_calib_data calib;
956 bme68x_read_fptr_t read;
959 bme68x_write_fptr_t write;
962 bme68x_delay_us_fptr_t delay_us;
965 BME68X_INTF_RET_TYPE intf_rslt;