upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bmp280.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016-2017 Intel Corporation.
4  *
5  * The MIT License
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining
8  * a copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  */
26 #pragma once
27 
28 #include <stdlib.h>
29 #include <unistd.h>
30 #include <stdio.h>
31 #include <upm.h>
32 
33 #include <mraa/i2c.h>
34 #include <mraa/spi.h>
35 #include <mraa/gpio.h>
36 
37 #include "bmp280_regs.h"
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
54  typedef struct _bmp280_context {
55  mraa_i2c_context i2c;
56  mraa_gpio_context gpio;
57  mraa_spi_context spi;
58 
59  // are we doing SPI?
60  bool isSPI;
61 
62  // are we using a bme280?
63  bool isBME;
64 
65  // always stored in C
66  float temperature;
67 
68  // pressure in Pa
69  float pressure;
70 
71  // humidity (relative)
72  float humidity;
73 
74  // sea level pressure in hectoPascals (hPa)
75  float sea_level_hPA;
76 
77  // shared calibration data - set in temp conversion, used in
78  // pressure conversion.
79  int32_t t_fine;
80 
81  // current operating mode. BMP280_MODE_FORCED requires
82  // special attention in update()
83  BMP280_MODES_T mode;
84 
85  // calibration data temperature
86  uint16_t dig_T1;
87  int16_t dig_T2;
88  int16_t dig_T3;
89 
90  // calibration data pressure
91  uint16_t dig_P1;
92  int16_t dig_P2;
93  int16_t dig_P3;
94  int16_t dig_P4;
95  int16_t dig_P5;
96  int16_t dig_P6;
97  int16_t dig_P7;
98  int16_t dig_P8;
99  int16_t dig_P9;
100 
101  // calibration data humidity (BME280 only)
102  uint8_t dig_H1;
103  int16_t dig_H2;
104  uint8_t dig_H3;
105  int16_t dig_H4;
106  int16_t dig_H5;
107  int8_t dig_H6;
108  } *bmp280_context;
109 
130  bmp280_context bmp280_init(int bus, int addr, int cs);
131 
137  void bmp280_close(bmp280_context dev);
138 
145  upm_result_t bmp280_update(const bmp280_context dev);
146 
153  uint8_t bmp280_get_chip_id(const bmp280_context dev);
154 
160  void bmp280_reset(const bmp280_context dev);
161 
171  float bmp280_get_temperature(const bmp280_context dev);
172 
181  float bmp280_get_humidity(const bmp280_context dev);
182 
191  float bmp280_get_pressure(const bmp280_context dev);
192 
203  float seaLevelhPA);
204 
217  float bmp280_get_altitude(const bmp280_context dev);
218 
229  void bmp280_set_usage_mode(const bmp280_context dev,
230  BMP280_USAGE_MODE_T mode);
231 
242  BMP280_OSRS_T_T rate);
243 
254  BMP280_OSRS_P_T rate);
255 
266  BME280_OSRS_H_T rate);
267 
277  BMP280_T_SB_T tsb);
278 
288  void bmp280_set_filter(const bmp280_context dev, BMP280_FILTER_T filter);
289 
300  BMP280_MODES_T mode);
301 
308  uint8_t bmp280_get_status(const bmp280_context dev);
309 
317  uint8_t bmp280_read_reg(const bmp280_context dev, uint8_t reg);
318 
329  int bmp280_read_regs(const bmp280_context dev,
330  uint8_t reg, uint8_t *buffer, int len);
331 
341  upm_result_t bmp280_write_reg(const bmp280_context dev,
342  uint8_t reg, uint8_t val);
343 
344 #ifdef __cplusplus
345 }
346 #endif
bmp280_context bmp280_init(int bus, int addr, int cs)
Definition: bmp280.c:224
struct _bmp280_context * bmp280_context
uint8_t bmp280_get_status(const bmp280_context dev)
Definition: bmp280.c:680
void bmp280_set_measure_mode(const bmp280_context dev, BMP280_MODES_T mode)
Definition: bmp280.c:623
upm_result_t bmp280_update(const bmp280_context dev)
Definition: bmp280.c:359
void bmp280_set_oversample_rate_pressure(const bmp280_context dev, BMP280_OSRS_P_T rate)
Definition: bmp280.c:637
void bmp280_set_oversample_rate_humidity(const bmp280_context dev, BME280_OSRS_H_T rate)
Definition: bmp280.c:664
uint8_t bmp280_get_chip_id(const bmp280_context dev)
Definition: bmp280.c:558
uint8_t bmp280_read_reg(const bmp280_context dev, uint8_t reg)
Definition: bmp280.c:454
void bmp280_set_filter(const bmp280_context dev, BMP280_FILTER_T filter)
Definition: bmp280.c:598
float bmp280_get_temperature(const bmp280_context dev)
Definition: bmp280.c:573
float bmp280_get_altitude(const bmp280_context dev)
Definition: bmp280.c:445
void bmp280_set_oversample_rate_temperature(const bmp280_context dev, BMP280_OSRS_T_T rate)
Definition: bmp280.c:650
upm_result_t bmp280_write_reg(const bmp280_context dev, uint8_t reg, uint8_t val)
Definition: bmp280.c:524
int bmp280_read_regs(const bmp280_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: bmp280.c:482
void bmp280_set_usage_mode(const bmp280_context dev, BMP280_USAGE_MODE_T mode)
Definition: bmp280.c:687
float bmp280_get_pressure(const bmp280_context dev)
Definition: bmp280.c:580
void bmp280_close(bmp280_context dev)
Definition: bmp280.c:343
void bmp280_reset(const bmp280_context dev)
Definition: bmp280.c:565
void bmp280_set_timer_standby(const bmp280_context dev, BMP280_T_SB_T tsb)
Definition: bmp280.c:610
float bmp280_get_humidity(const bmp280_context dev)
Definition: bmp280.c:588
void bmp280_set_sea_level_pressure(const bmp280_context dev, float seaLevelhPA)
Definition: bmp280.c:437
Definition: bmp280.h:54