123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- #ifndef BME280_DEFS_H_
- #define BME280_DEFS_H_
- #ifdef __KERNEL__
- #include <linux/types.h>
- #include <linux/kernel.h>
- #else
- #include <stdint.h>
- #include <stddef.h>
- #endif
- #if !defined(UINT8_C) && !defined(INT8_C)
- #define INT8_C(x) S8_C(x)
- #define UINT8_C(x) U8_C(x)
- #endif
- #if !defined(UINT16_C) && !defined(INT16_C)
- #define INT16_C(x) S16_C(x)
- #define UINT16_C(x) U16_C(x)
- #endif
- #if !defined(INT32_C) && !defined(UINT32_C)
- #define INT32_C(x) S32_C(x)
- #define UINT32_C(x) U32_C(x)
- #endif
- #if !defined(INT64_C) && !defined(UINT64_C)
- #define INT64_C(x) S64_C(x)
- #define UINT64_C(x) U64_C(x)
- #endif
- #ifndef NULL
- #ifdef __cplusplus
- #define NULL 0
- #else
- #define NULL ((void *) 0)
- #endif
- #endif
- #ifndef BME280_64BIT_ENABLE
- #ifndef BME280_32BIT_ENABLE
- #define BME280_32BIT_ENABLE
- #ifndef BME280_FLOAT_ENABLE
- #endif
- #endif
- #endif
- #ifndef TRUE
- #define TRUE UINT8_C(1)
- #endif
- #ifndef FALSE
- #define FALSE UINT8_C(0)
- #endif
- #define BME280_I2C_ADDR_PRIM UINT8_C(0x76)
- #define BME280_I2C_ADDR_SEC UINT8_C(0x77)
- #define BME280_CHIP_ID UINT8_C(0x60)
- #define BME280_CHIP_ID_ADDR UINT8_C(0xD0)
- #define BME280_RESET_ADDR UINT8_C(0xE0)
- #define BME280_TEMP_PRESS_CALIB_DATA_ADDR UINT8_C(0x88)
- #define BME280_HUMIDITY_CALIB_DATA_ADDR UINT8_C(0xE1)
- #define BME280_PWR_CTRL_ADDR UINT8_C(0xF4)
- #define BME280_CTRL_HUM_ADDR UINT8_C(0xF2)
- #define BME280_CTRL_MEAS_ADDR UINT8_C(0xF4)
- #define BME280_CONFIG_ADDR UINT8_C(0xF5)
- #define BME280_DATA_ADDR UINT8_C(0xF7)
- #define BME280_OK INT8_C(0)
- #define BME280_E_NULL_PTR INT8_C(-1)
- #define BME280_E_DEV_NOT_FOUND INT8_C(-2)
- #define BME280_E_INVALID_LEN INT8_C(-3)
- #define BME280_E_COMM_FAIL INT8_C(-4)
- #define BME280_E_SLEEP_MODE_FAIL INT8_C(-5)
- #define BME280_E_NVM_COPY_FAILED INT8_C(-6)
- #define BME280_W_INVALID_OSR_MACRO INT8_C(1)
- #define BME280_TEMP_PRESS_CALIB_DATA_LEN UINT8_C(26)
- #define BME280_HUMIDITY_CALIB_DATA_LEN UINT8_C(7)
- #define BME280_P_T_H_DATA_LEN UINT8_C(8)
- #define BME280_SLEEP_MODE UINT8_C(0x00)
- #define BME280_FORCED_MODE UINT8_C(0x01)
- #define BME280_NORMAL_MODE UINT8_C(0x03)
- #define BME280_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb)
- #define BME280_SET_BITS(reg_data, bitname, data) \
- ((reg_data & ~(bitname##_MSK)) | \
- ((data << bitname##_POS) & bitname##_MSK))
- #define BME280_SET_BITS_POS_0(reg_data, bitname, data) \
- ((reg_data & ~(bitname##_MSK)) | \
- (data & bitname##_MSK))
- #define BME280_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
- (bitname##_POS))
- #define BME280_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
- #define BME280_SENSOR_MODE_MSK UINT8_C(0x03)
- #define BME280_SENSOR_MODE_POS UINT8_C(0x00)
- #define BME280_CTRL_HUM_MSK UINT8_C(0x07)
- #define BME280_CTRL_HUM_POS UINT8_C(0x00)
- #define BME280_CTRL_PRESS_MSK UINT8_C(0x1C)
- #define BME280_CTRL_PRESS_POS UINT8_C(0x02)
- #define BME280_CTRL_TEMP_MSK UINT8_C(0xE0)
- #define BME280_CTRL_TEMP_POS UINT8_C(0x05)
- #define BME280_FILTER_MSK UINT8_C(0x1C)
- #define BME280_FILTER_POS UINT8_C(0x02)
- #define BME280_STANDBY_MSK UINT8_C(0xE0)
- #define BME280_STANDBY_POS UINT8_C(0x05)
- #define BME280_PRESS UINT8_C(1)
- #define BME280_TEMP UINT8_C(1 << 1)
- #define BME280_HUM UINT8_C(1 << 2)
- #define BME280_ALL UINT8_C(0x07)
- #define BME280_OSR_PRESS_SEL UINT8_C(1)
- #define BME280_OSR_TEMP_SEL UINT8_C(1 << 1)
- #define BME280_OSR_HUM_SEL UINT8_C(1 << 2)
- #define BME280_FILTER_SEL UINT8_C(1 << 3)
- #define BME280_STANDBY_SEL UINT8_C(1 << 4)
- #define BME280_ALL_SETTINGS_SEL UINT8_C(0x1F)
- #define BME280_NO_OVERSAMPLING UINT8_C(0x00)
- #define BME280_OVERSAMPLING_1X UINT8_C(0x01)
- #define BME280_OVERSAMPLING_2X UINT8_C(0x02)
- #define BME280_OVERSAMPLING_4X UINT8_C(0x03)
- #define BME280_OVERSAMPLING_8X UINT8_C(0x04)
- #define BME280_OVERSAMPLING_16X UINT8_C(0x05)
- #define BME280_MEAS_OFFSET UINT16_C(1250)
- #define BME280_MEAS_DUR UINT16_C(2300)
- #define BME280_PRES_HUM_MEAS_OFFSET UINT16_C(575)
- #define BME280_MEAS_SCALING_FACTOR UINT16_C(1000)
- #define BME280_STANDBY_TIME_0_5_MS (0x00)
- #define BME280_STANDBY_TIME_62_5_MS (0x01)
- #define BME280_STANDBY_TIME_125_MS (0x02)
- #define BME280_STANDBY_TIME_250_MS (0x03)
- #define BME280_STANDBY_TIME_500_MS (0x04)
- #define BME280_STANDBY_TIME_1000_MS (0x05)
- #define BME280_STANDBY_TIME_10_MS (0x06)
- #define BME280_STANDBY_TIME_20_MS (0x07)
- #define BME280_FILTER_COEFF_OFF (0x00)
- #define BME280_FILTER_COEFF_2 (0x01)
- #define BME280_FILTER_COEFF_4 (0x02)
- #define BME280_FILTER_COEFF_8 (0x03)
- #define BME280_FILTER_COEFF_16 (0x04)
- #define BME280_STATUS_REG_ADDR (0xF3)
- #define BME280_SOFT_RESET_COMMAND (0xB6)
- #define BME280_STATUS_IM_UPDATE (0x01)
- enum bme280_intf {
-
- BME280_SPI_INTF,
-
- BME280_I2C_INTF
- };
- typedef int8_t (*bme280_com_fptr_t)(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len);
- typedef void (*bme280_delay_fptr_t)(uint32_t period);
- struct bme280_calib_data
- {
-
-
- uint16_t dig_t1;
- int16_t dig_t2;
- int16_t dig_t3;
- uint16_t dig_p1;
- int16_t dig_p2;
- int16_t dig_p3;
- int16_t dig_p4;
- int16_t dig_p5;
- int16_t dig_p6;
- int16_t dig_p7;
- int16_t dig_p8;
- int16_t dig_p9;
- uint8_t dig_h1;
- int16_t dig_h2;
- uint8_t dig_h3;
- int16_t dig_h4;
- int16_t dig_h5;
- int8_t dig_h6;
- int32_t t_fine;
-
- };
- #ifdef BME280_FLOAT_ENABLE
- struct bme280_data
- {
-
- double pressure;
-
- double temperature;
-
- double humidity;
- };
- #else
- struct bme280_data
- {
-
- uint32_t pressure;
-
- int32_t temperature;
-
- uint32_t humidity;
- };
- #endif
- struct bme280_uncomp_data
- {
-
- uint32_t pressure;
-
- uint32_t temperature;
-
- uint32_t humidity;
- };
- struct bme280_settings
- {
-
- uint8_t osr_p;
-
- uint8_t osr_t;
-
- uint8_t osr_h;
-
- uint8_t filter;
-
- uint8_t standby_time;
- };
- struct bme280_dev
- {
-
- uint8_t chip_id;
-
- uint8_t dev_id;
-
- enum bme280_intf intf;
-
- bme280_com_fptr_t read;
-
- bme280_com_fptr_t write;
-
- bme280_delay_fptr_t delay_ms;
-
- struct bme280_calib_data calib_data;
-
- struct bme280_settings settings;
- };
- #endif
|