barometer 2.0.0.0
barometer.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to 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 MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef BAROMETER_H
36#define BAROMETER_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55#include "drv_spi_master.h"
56
57// -------------------------------------------------------------- PUBLIC MACROS
68#define BAROMETER_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
72 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
73 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
74 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
75 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
82#define BAROMETER_MASTER_I2C 0
83#define BAROMETER_MASTER_SPI 1
90#define BAROMETER_RETVAL uint8_t
91
92#define BAROMETER_OK 0x00
93#define BAROMETER_INIT_ERROR 0xFF
100 #define BAROMETER_I2C_ADDRESS_0 0x5C
107 #define BAROMETER_I2C_ADDRESS_1 0x5D
114 #define BAROMETER_REF_P_XL 0x08
115 #define BAROMETER_REF_P_L 0x09
116 #define BAROMETER_REF_P_H 0x0A
123 #define BAROMETER_WHO_AM_I 0x0F
130 #define BAROMETER_RES_CONF 0x10
131 #define BAROMETER_CTRL_REG1 0x20
132 #define BAROMETER_CTRL_REG2 0x21
133 #define BAROMETER_CTRL_REG3 0x22
134 #define BAROMETER_CTRL_REG4 0x23
135 #define BAROMETER_INTERRUPT_CFG 0x24
136 #define BAROMETER_INT_SOURCE 0x25
137 #define BAROMETER_STATUS_REG 0x27
138 #define BAROMETER_PRESS_OUT_XL 0x28
139 #define BAROMETER_PRESS_OUT_L 0x29
140 #define BAROMETER_PRESS_OUT_H 0x2A
141 #define BAROMETER_TEMP_OUT_L 0x2B
142 #define BAROMETER_TEMP_OUT_H 0x2C
143 #define BAROMETER_FIFO_CTRL 0x2E
144 #define BAROMETER_FIFO_STATUS 0x2F
145 #define BAROMETER_THS_P_L 0x30
146 #define BAROMETER_THS_P_H 0x31
147 #define BAROMETER_RPDS_L 0x39
148 #define BAROMETER_RPDS_H 0x3A
149 #define BAROMETER_DEVICE_ID 0xBD
156 #define BAROMETER_DEFAULT_CONFIG 0xB0
157 #define BAROMETER_CONFIG_ACTIVE_MODE 0x80
160 // End group macro
161
162// --------------------------------------------------------------- PUBLIC TYPES
163
172typedef uint8_t barometer_select_t;
173
177typedef void ( *barometer_master_io_t )( struct barometer_s*, uint8_t, uint8_t*, uint8_t );
178
182typedef struct barometer_s
183{
184 digital_out_t cs;
185
186 // Input pins
187
188 digital_in_t rdy;
189
190 // Modules
191
192 i2c_master_t i2c;
193 spi_master_t spi;
194
195 // ctx variable
196
198 pin_name_t chip_select;
202
204
208typedef struct
209{
210 // Communication gpio pins
211
212 pin_name_t scl;
213 pin_name_t sda;
214 pin_name_t miso;
215 pin_name_t mosi;
216 pin_name_t sck;
217 pin_name_t cs;
218
219 // Additional gpio pins
220
221 pin_name_t rdy;
222
223 // static variable
224
225 uint32_t i2c_speed;
226 uint8_t i2c_address;
227
228 uint32_t spi_speed;
229 spi_master_mode_t spi_mode;
230 spi_master_chip_select_polarity_t cs_polarity;
231
233
235
236 // End types group
237// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
243#ifdef __cplusplus
244extern "C"{
245#endif
246
256
265
279
290void barometer_generic_write ( barometer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
291
302void barometer_generic_read ( barometer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
303
316uint8_t barometer_read_data( barometer_t *ctx, uint8_t address );
317
326
338
350
362
374
386
397
398#ifdef __cplusplus
399}
400#endif
401#endif // _BAROMETER_H_
402
403 // End public_function group
405
406// ------------------------------------------------------------------------- END
#define BAROMETER_RETVAL
Definition barometer.h:90
void barometer_cfg_setup(barometer_cfg_t *cfg)
Config Object Initialization function.
uint8_t barometer_check_status(barometer_t *ctx)
Check sensor status function.
void barometer_generic_write(barometer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t barometer_check_id(barometer_t *ctx)
Check sensor id - Who Am I function.
void barometer_set_active(barometer_t *ctx)
Sets the module active function.
uint8_t barometer_check_interrupt(barometer_t *ctx)
State of interrupt pin function.
float barometer_get_pressure(barometer_t *ctx)
Read pressure in milibars function.
void barometer_generic_read(barometer_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t barometer_read_data(barometer_t *ctx, uint8_t address)
Generic read 8-bit data function.
float barometer_get_temperature_f(barometer_t *ctx)
Read temperature in degrees of Fahrenheit function.
float barometer_get_temperature_c(barometer_t *ctx)
Read temperature in degrees Celsius function.
BAROMETER_RETVAL barometer_init(barometer_t *ctx, barometer_cfg_t *cfg)
Initialization function.
void barometer_default_cfg(barometer_t *ctx)
Click Default Configuration function.
struct barometer_s barometer_t
Click ctx object definition.
uint8_t barometer_select_t
Communication type.
Definition barometer.h:172
void(* barometer_master_io_t)(struct barometer_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition barometer.h:177
Click configuration structure definition.
Definition barometer.h:209
uint32_t i2c_speed
Definition barometer.h:225
spi_master_chip_select_polarity_t cs_polarity
Definition barometer.h:230
pin_name_t sck
Definition barometer.h:216
spi_master_mode_t spi_mode
Definition barometer.h:229
pin_name_t mosi
Definition barometer.h:215
uint32_t spi_speed
Definition barometer.h:228
pin_name_t scl
Definition barometer.h:212
pin_name_t rdy
Definition barometer.h:221
pin_name_t miso
Definition barometer.h:214
pin_name_t sda
Definition barometer.h:213
pin_name_t cs
Definition barometer.h:217
barometer_select_t sel
Definition barometer.h:232
uint8_t i2c_address
Definition barometer.h:226
Click ctx object definition.
Definition barometer.h:183
digital_out_t cs
Definition barometer.h:184
barometer_master_io_t write_f
Definition barometer.h:199
spi_master_t spi
Definition barometer.h:193
barometer_select_t master_sel
Definition barometer.h:201
barometer_master_io_t read_f
Definition barometer.h:200
i2c_master_t i2c
Definition barometer.h:192
uint8_t slave_address
Definition barometer.h:197
pin_name_t chip_select
Definition barometer.h:198
digital_in_t rdy
Definition barometer.h:188