upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
ms5803.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2016 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <upm.h>
30 
31 #include <mraa/i2c.h>
32 #include <mraa/spi.h>
33 #include <mraa/gpio.h>
34 
35 #include "ms5803_defs.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
52  typedef struct _ms5803_context {
53  mraa_i2c_context i2c;
54  mraa_spi_context spi;
55  // CS pin, if we are using one
56  mraa_gpio_context gpio;
57 
58  // whether we are doing I2C or SPI
59  bool isSPI;
60 
61  // stored calibration coefficients
62  uint16_t C[MS5803_MAX_COEFFICIENTS];
63 
64  // the command sent to chip depending on OSR configuration for
65  // temperature and pressure measurement.
66  MS5803_CMD_T temperatureCmd;
67  MS5803_OSR_T temperatureDelay;
68 
69  MS5803_CMD_T pressureCmd;
70  MS5803_OSR_T pressureDelay;
71 
72  // compensated temperature in C
73  float temperature;
74  // compensated pressure in millibars
75  float pressure;
76  } *ms5803_context;
77 
90  ms5803_context ms5803_init(unsigned int bus, int address, int cs_pin);
91 
97  void ms5803_close(ms5803_context dev);
98 
105  upm_result_t ms5803_reset(const ms5803_context dev);
106 
114  upm_result_t ms5803_update(const ms5803_context dev);
115 
126  void ms5803_set_temperature_osr(const ms5803_context dev,
127  MS5803_OSR_T osr);
128 
139  void ms5803_set_pressure_osr(const ms5803_context dev,
140  MS5803_OSR_T osr);
141 
150  float ms5803_get_temperature(const ms5803_context dev);
151 
160  float ms5803_get_pressure(const ms5803_context dev);
161 
171  upm_result_t ms5803_load_coefficients(const ms5803_context dev);
172 
185  upm_result_t ms5803_bus_read(const ms5803_context dev, uint8_t cmd,
186  uint8_t *data, uint8_t len);
187 
200  upm_result_t ms5803_bus_write(const ms5803_context dev, uint8_t cmd,
201  uint8_t *data, uint8_t len);
202 
203 #ifdef __cplusplus
204 }
205 #endif
Definition: ms5803.h:52