bmp280.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * Ciastkolog.pl (https://github.com/ciastkolog)
  3. *
  4. */
  5. /**
  6. * The MIT License (MIT)
  7. * Copyright (c) 2016 sheinz (https://github.com/sheinz)
  8. * Copyright (c) 2020  Jinan Bosai Network Technology Co., Ltd.
  9. */
  10. #ifndef __BMP280_H__
  11. #define __BMP280_H__
  12. // #include "stm32f0xx_hal.h"
  13. #include <stdint.h>
  14. #include <stdbool.h>
  15. /**
  16. * BMP280 or BME280 address is 0x77 if SDO pin is high, and is 0x76 if
  17. * SDO pin is low.
  18. */
  19. #define BMP280_I2C_ADDRESS_0 0x76
  20. #define BMP280_I2C_ADDRESS_1 0x77
  21. #define BMP280_CHIP_ID 0x58 /* BMP280 has chip-id 0x58 */
  22. #define BME280_CHIP_ID 0x60 /* BME280 has chip-id 0x60 */
  23. /**
  24. * Mode of BMP280 module operation.
  25. * Forced - Measurement is initiated by user.
  26. * Normal - Continues measurement.
  27. */
  28. typedef enum {
  29. BMP280_MODE_SLEEP = 0,
  30. BMP280_MODE_FORCED = 1,
  31. BMP280_MODE_NORMAL = 3
  32. } BMP280_Mode;
  33. typedef enum {
  34. BMP280_FILTER_OFF = 0,
  35. BMP280_FILTER_2 = 1,
  36. BMP280_FILTER_4 = 2,
  37. BMP280_FILTER_8 = 3,
  38. BMP280_FILTER_16 = 4
  39. } BMP280_Filter;
  40. /**
  41. * Pressure oversampling settings
  42. */
  43. typedef enum {
  44. BMP280_SKIPPED = 0, /* no measurement */
  45. BMP280_ULTRA_LOW_POWER = 1, /* oversampling x1 */
  46. BMP280_LOW_POWER = 2, /* oversampling x2 */
  47. BMP280_STANDARD = 3, /* oversampling x4 */
  48. BMP280_HIGH_RES = 4, /* oversampling x8 */
  49. BMP280_ULTRA_HIGH_RES = 5 /* oversampling x16 */
  50. } BMP280_Oversampling;
  51. /**
  52. * Stand by time between measurements in normal mode
  53. */
  54. typedef enum {
  55. BMP280_STANDBY_05 = 0, /* stand by time 0.5ms */
  56. BMP280_STANDBY_62 = 1, /* stand by time 62.5ms */
  57. BMP280_STANDBY_125 = 2, /* stand by time 125ms */
  58. BMP280_STANDBY_250 = 3, /* stand by time 250ms */
  59. BMP280_STANDBY_500 = 4, /* stand by time 500ms */
  60. BMP280_STANDBY_1000 = 5, /* stand by time 1s */
  61. BMP280_STANDBY_2000 = 6, /* stand by time 2s BMP280, 10ms BME280 */
  62. BMP280_STANDBY_4000 = 7, /* stand by time 4s BMP280, 20ms BME280 */
  63. } BMP280_StandbyTime;
  64. /**
  65. * Configuration parameters for BMP280 module.
  66. * Use function bmp280_init_default_params to use default configuration.
  67. */
  68. typedef struct {
  69. BMP280_Mode mode;
  70. BMP280_Filter filter;
  71. BMP280_Oversampling oversampling_pressure;
  72. BMP280_Oversampling oversampling_temperature;
  73. BMP280_StandbyTime standby;
  74. } bmp280_params_t;
  75. typedef struct {
  76. uint16_t dig_T1;
  77. int16_t dig_T2;
  78. int16_t dig_T3;
  79. uint16_t dig_P1;
  80. int16_t dig_P2;
  81. int16_t dig_P3;
  82. int16_t dig_P4;
  83. int16_t dig_P5;
  84. int16_t dig_P6;
  85. int16_t dig_P7;
  86. int16_t dig_P8;
  87. int16_t dig_P9;
  88. /* Humidity compensation for BME280 */
  89. uint8_t dig_H1;
  90. int16_t dig_H2;
  91. uint8_t dig_H3;
  92. int16_t dig_H4;
  93. int16_t dig_H5;
  94. int8_t dig_H6;
  95. bmp280_params_t params;
  96. uint8_t id; /* Chip ID */
  97. } BMP280_HandleTypedef;
  98. /**
  99. * Initialize default parameters.
  100. * Default configuration:
  101. * mode: NORAML
  102. * filter: OFF
  103. * oversampling: x4
  104. * standby time: 250ms
  105. */
  106. void bmp280_init_default_params(bmp280_params_t *params);
  107. /**
  108. * Initialize BMP280 module, probes for the device, soft resets the device,
  109. * reads the calibration constants, and configures the device using the supplied
  110. * parameters. Returns true on success otherwise false.
  111. *
  112. * The I2C address is assumed to have been initialized in the dev, and
  113. * may be either BMP280_I2C_ADDRESS_0 or BMP280_I2C_ADDRESS_1. If the I2C
  114. * address is unknown then try initializing each in turn.
  115. *
  116. * This may be called again to soft reset the device and initialize it again.
  117. */
  118. bool bmp280_init(BMP280_HandleTypedef *dev, bmp280_params_t *params);
  119. /**
  120. * Start measurement in forced mode.
  121. * The module remains in forced mode after this call.
  122. * Do not call this method in normal mode.
  123. */
  124. bool bmp280_force_measurement(void);
  125. /**
  126. * Check if BMP280 is busy with measuring temperature/pressure.
  127. * Return true if BMP280 is busy.
  128. */
  129. bool bmp280_is_measuring(void);
  130. /**
  131. * Read compensated temperature and pressure data:
  132. *
  133. * Temperature in degrees Celsius times 100.
  134. *
  135. * Pressure in Pascals in fixed point 24 bit integer 8 bit fraction format.
  136. *
  137. * Humidity is optional and only read for the BME280, in percent relative
  138. * humidity as a fixed point 22 bit interger and 10 bit fraction format.
  139. */
  140. bool bmp280_read_fixed(BMP280_HandleTypedef *dev, int32_t *temperature,
  141. uint32_t *pressure);
  142. /**
  143. * Read compensated temperature and pressure data:
  144. * Temperature in degrees Celsius.
  145. * Pressure in Pascals.
  146. * Humidity is optional and only read for the BME280, in percent relative
  147. * humidity.
  148. */
  149. bool bmp280_read_float(BMP280_HandleTypedef *dev, float *temperature,
  150. float *pressure, float* asl);
  151. #endif // __BMP280_H__