upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
bmpx8x.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2017 Intel Corporation.
4  *
5  * This driver was rewritten based on the original driver written by:
6  * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
7  *
8  * The MIT License
9  *
10  * Permission is hereby granted, free of charge, to any person obtaining
11  * a copy of this software and associated documentation files (the
12  * "Software"), to deal in the Software without restriction, including
13  * without limitation the rights to use, copy, modify, merge, publish,
14  * distribute, sublicense, and/or sell copies of the Software, and to
15  * permit persons to whom the Software is furnished to do so, subject to
16  * the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be
19  * included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28  */
29 #pragma once
30 
31 #include <unistd.h>
32 #include <string.h>
33 
34 #include <mraa/i2c.h>
35 
36 #include "upm.h"
37 
38 #include "bmpx8x_defs.h"
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 
56  typedef struct _bmpx8x_context {
57  mraa_i2c_context i2c;
58 
59  // our oversampling (precision)
60  BMPX8X_OSS_T oversampling;
61 
62  // compensated temperature and pressure
63  float temperature;
64  int pressure;
65 
66  // compensation coefficients
67  int16_t ac1;
68  int16_t ac2;
69  int16_t ac3;
70  uint16_t ac4;
71  uint16_t ac5;
72  uint16_t ac6;
73  int16_t b1;
74  int16_t b2;
75  int16_t mb;
76  int16_t mc;
77  int16_t md;
78  } *bmpx8x_context;
79 
80 
91  bmpx8x_context bmpx8x_init(int bus, int addr);
92 
98  void bmpx8x_close(bmpx8x_context dev);
99 
106  uint8_t bmpx8x_get_chip_id(const bmpx8x_context dev);
107 
120  upm_result_t bmpx8x_devinit(const bmpx8x_context dev,
121  BMPX8X_OSS_T oss);
122 
133  upm_result_t bmpx8x_reset(const bmpx8x_context dev);
134 
141  upm_result_t bmpx8x_update(const bmpx8x_context dev);
142 
152  BMPX8X_OSS_T oss);
153 
161  int bmpx8x_get_pressure(const bmpx8x_context dev);
162 
170  float bmpx8x_get_temperature(const bmpx8x_context dev);
171 
182  float altitude);
183 
195  float bmpx8x_get_altitude(const bmpx8x_context dev, int sealevel);
196 
204  uint8_t bmpx8x_read_reg(const bmpx8x_context dev, uint8_t reg);
205 
214  int bmpx8x_read_regs(const bmpx8x_context dev, uint8_t reg,
215  uint8_t *buffer, int len);
216 
225  upm_result_t bmpx8x_write_reg(const bmpx8x_context dev,
226  uint8_t reg, uint8_t val);
227 
228 #ifdef __cplusplus
229 }
230 #endif
Definition: bmpx8x.h:56
bmpx8x_context bmpx8x_init(int bus, int addr)
Definition: bmpx8x.c:77
upm_result_t bmpx8x_reset(const bmpx8x_context dev)
Definition: bmpx8x.c:168
uint8_t bmpx8x_read_reg(const bmpx8x_context dev, uint8_t reg)
Definition: bmpx8x.c:329
upm_result_t bmpx8x_update(const bmpx8x_context dev)
Definition: bmpx8x.c:188
float bmpx8x_get_temperature(const bmpx8x_context dev)
Definition: bmpx8x.c:302
int bmpx8x_read_regs(const bmpx8x_context dev, uint8_t reg, uint8_t *buffer, int len)
Definition: bmpx8x.c:336
int bmpx8x_get_sealevel_pressure(const bmpx8x_context dev, float altitude)
Definition: bmpx8x.c:309
upm_result_t bmpx8x_devinit(const bmpx8x_context dev, BMPX8X_OSS_T oss)
Definition: bmpx8x.c:143
int bmpx8x_get_pressure(const bmpx8x_context dev)
Definition: bmpx8x.c:295
upm_result_t bmpx8x_write_reg(const bmpx8x_context dev, uint8_t reg, uint8_t val)
Definition: bmpx8x.c:347
void bmpx8x_close(bmpx8x_context dev)
Definition: bmpx8x.c:133
float bmpx8x_get_altitude(const bmpx8x_context dev, int sealevel)
Definition: bmpx8x.c:317
void bmpx8x_set_oversampling(const bmpx8x_context dev, BMPX8X_OSS_T oss)
Definition: bmpx8x.c:180
uint8_t bmpx8x_get_chip_id(const bmpx8x_context dev)
Definition: bmpx8x.c:161
struct _bmpx8x_context * bmpx8x_context