barometer8 2.0.0.0
barometer8.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef BAROMETER8_H
29#define BAROMETER8_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_spi_master.h"
53#include "spi_specifics.h"
54
75#define BAROMETER8_REG_INTERRUPT_CFG 0x0B
76#define BAROMETER8_REG_THS_P_L 0x0C
77#define BAROMETER8_REG_THS_P_H 0x0D
78#define BAROMETER8_REG_IF_CTRL 0x0E
79#define BAROMETER8_REG_WHO_AM_I 0x0F
80#define BAROMETER8_REG_CTRL_REG1 0x10
81#define BAROMETER8_REG_CTRL_REG2 0x11
82#define BAROMETER8_REG_CTRL_REG3 0x12
83#define BAROMETER8_REG_FIFO_CTRL 0x14
84#define BAROMETER8_REG_FIFO_WTM 0x15
85#define BAROMETER8_REG_REF_P_L 0x16
86#define BAROMETER8_REG_REF_P_H 0x17
87#define BAROMETER8_REG_I3C_IF_CTRL 0x19
88#define BAROMETER8_REG_RPDS_L 0x1A
89#define BAROMETER8_REG_RPDS_H 0x1B
90#define BAROMETER8_REG_INT_SOURCE 0x24
91#define BAROMETER8_REG_FIFO_STATUS1 0x25
92#define BAROMETER8_REG_FIFO_STATUS2 0x26
93#define BAROMETER8_REG_STATUS 0x27
94#define BAROMETER8_REG_PRESSURE_OUT_XL 0x28
95#define BAROMETER8_REG_PRESSURE_OUT_L 0x29
96#define BAROMETER8_REG_PRESSURE_OUT_H 0x2A
97#define BAROMETER8_REG_TEMP_OUT_L 0x2B
98#define BAROMETER8_REG_TEMP_OUT_H 0x2C
99#define BAROMETER8_REG_FIFO_DATA_OUT_PRESS_XL 0x78
100#define BAROMETER8_REG_FIFO_DATA_OUT_PRESS_L 0x79
101#define BAROMETER8_REG_FIFO_DATA_OUT_PRESS_H 0x7A
102
103 // barometer8_reg
104
119#define BAROMETER8_DISABLE_I2C_AND_I3C 0x40
120#define BAROMETER8_ENABLE_SPI_READ 0x20
121#define BAROMETER8_SDA_PULL_UP 0x10
122#define BAROMETER8_CS_PULL_UP_DISC 0x02
123
128#define BAROMETER8_WHO_AM_I 0xB4
129
134#define BAROMETER8_ODR_PD_OR_ONE_SHOT 0x00
135#define BAROMETER8_ODR_1HZ 0x08
136#define BAROMETER8_ODR_4HZ 0x10
137#define BAROMETER8_ODR_10HZ 0x18
138#define BAROMETER8_ODR_25HZ 0x20
139#define BAROMETER8_ODR_50HZ 0x28
140#define BAROMETER8_ODR_75HZ 0x30
141#define BAROMETER8_ODR_100HZ 0x38
142#define BAROMETER8_ODR_200HZ 0x40
143#define BAROMETER8_ODR_BIT_MASK 0x78
144#define BAROMETER8_AVG_4 0x00
145#define BAROMETER8_AVG_8 0x01
146#define BAROMETER8_AVG_16 0x02
147#define BAROMETER8_AVG_32 0x03
148#define BAROMETER8_AVG_64 0x04
149#define BAROMETER8_AVG_128 0x05
150#define BAROMETER8_AVG_512 0x07
151#define BAROMETER8_AVG_BIT_MASK 0x07
152
157#define BAROMETER8_BOOT_NORMAL 0x00
158#define BAROMETER8_REBOOT_MEMORY 0x80
159#define BAROMETER8_FS_MODE_1 0x00
160#define BAROMETER8_FS_MODE_2 0x40
161#define BAROMETER8_LFPF_CFG_ODR_4 0x00
162#define BAROMETER8_LFPF_CFG_ODR_9 0x20
163#define BAROMETER8_DISABLE_LPFP 0x00
164#define BAROMETER8_ENABLE_LPFP 0x10
165#define BAROMETER8_BDU_CONTINUOUS 0x00
166#define BAROMETER8_BDU_MSB_LSB_READ 0x08
167#define BAROMETER8_SWRESET 0x04
168#define BAROMETER8_ONESHOT_IDLE 0x00
169#define BAROMETER8_ONESHOT_NEW_DATA 0x01
170
175#define BAROMETER8_STATUS_T_OR 0x20
176#define BAROMETER8_STATUS_P_OR 0x10
177#define BAROMETER8_STATUS_T_DA 0x02
178#define BAROMETER8_STATUS_P_DA 0x01
179
184#define BAROMETER8_PRESSURE_FS_MODE_1_RES 4096.0
185#define BAROMETER8_PRESSURE_FS_MODE_2_RES 2048.0
186#define BAROMETER8_TEMPERATURE_RES 0.01
187
193#define BAROMETER8_SET_DEVICE_ADDRESS 0x5C
194
203#define BAROMETER8_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
204#define BAROMETER8_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
205
206 // barometer8_set
207
222#define BAROMETER8_MAP_MIKROBUS( cfg, mikrobus ) \
223 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
224 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
225 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
226 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
227 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
228 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
229
230 // barometer8_map
231 // barometer8
232
243
248typedef err_t ( *barometer8_master_io_t )( struct barometer8_s*, uint8_t, uint8_t*, uint8_t );
269
274typedef struct
275{
276 pin_name_t scl;
277 pin_name_t sda;
278 pin_name_t miso;
279 pin_name_t mosi;
280 pin_name_t sck;
281 pin_name_t cs;
283 uint32_t i2c_speed;
284 uint8_t i2c_address;
286 uint32_t spi_speed;
287 spi_master_mode_t spi_mode;
288 spi_master_chip_select_polarity_t cs_polarity;
293
304
321
337
352
366
381err_t barometer8_generic_write ( barometer8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
382
397err_t barometer8_generic_read ( barometer8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
398
411err_t barometer8_write_register ( barometer8_t *ctx, uint8_t reg, uint8_t data_in );
412
425err_t barometer8_read_register ( barometer8_t *ctx, uint8_t reg, uint8_t *data_out );
426
438
450
463err_t barometer8_read_data ( barometer8_t *ctx, float *pressure, float *temperature );
464
465#ifdef __cplusplus
466}
467#endif
468#endif // BAROMETER8_H
469
470 // barometer8
471
472// ------------------------------------------------------------------------ END
struct barometer8_s barometer8_t
Barometer 8 Click context object.
barometer8_return_value_t
Barometer 8 Click return value data.
Definition barometer8.h:299
@ BAROMETER8_ERROR
Definition barometer8.h:301
@ BAROMETER8_OK
Definition barometer8.h:300
err_t(* barometer8_master_io_t)(struct barometer8_s *, uint8_t, uint8_t *, uint8_t)
Barometer 8 Click driver interface.
Definition barometer8.h:248
barometer8_drv_t
Barometer 8 Click driver selector.
Definition barometer8.h:238
@ BAROMETER8_DRV_SEL_I2C
Definition barometer8.h:240
@ BAROMETER8_DRV_SEL_SPI
Definition barometer8.h:239
err_t barometer8_init(barometer8_t *ctx, barometer8_cfg_t *cfg)
Barometer 8 initialization function.
err_t barometer8_check_communication(barometer8_t *ctx)
Barometer 8 check communication function.
err_t barometer8_write_register(barometer8_t *ctx, uint8_t reg, uint8_t data_in)
Barometer 8 write register function.
void barometer8_cfg_setup(barometer8_cfg_t *cfg)
Barometer 8 configuration object setup function.
err_t barometer8_default_cfg(barometer8_t *ctx)
Barometer 8 default configuration function.
err_t barometer8_read_register(barometer8_t *ctx, uint8_t reg, uint8_t *data_out)
Barometer 8 read register function.
err_t barometer8_read_data(barometer8_t *ctx, float *pressure, float *temperature)
Barometer 8 read data function.
void barometer8_drv_interface_selection(barometer8_cfg_t *cfg, barometer8_drv_t drv_sel)
Barometer 8 driver interface setup function.
err_t barometer8_generic_read(barometer8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Barometer 8 data reading function.
err_t barometer8_generic_write(barometer8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Barometer 8 data writing function.
err_t barometer8_software_reset(barometer8_t *ctx)
Barometer 8 software reset function.
This file contains SPI specific macros, functions, etc.
Barometer 8 Click configuration object.
Definition barometer8.h:275
uint32_t i2c_speed
Definition barometer8.h:283
spi_master_chip_select_polarity_t cs_polarity
Definition barometer8.h:288
pin_name_t sck
Definition barometer8.h:280
spi_master_mode_t spi_mode
Definition barometer8.h:287
pin_name_t mosi
Definition barometer8.h:279
uint32_t spi_speed
Definition barometer8.h:286
pin_name_t scl
Definition barometer8.h:276
pin_name_t miso
Definition barometer8.h:278
pin_name_t sda
Definition barometer8.h:277
barometer8_drv_t drv_sel
Definition barometer8.h:290
pin_name_t cs
Definition barometer8.h:281
uint8_t i2c_address
Definition barometer8.h:284
Barometer 8 Click context object.
Definition barometer8.h:255
spi_master_t spi
Definition barometer8.h:257
barometer8_master_io_t read_f
Definition barometer8.h:264
uint8_t ctrl_reg2
Definition barometer8.h:266
i2c_master_t i2c
Definition barometer8.h:256
uint8_t slave_address
Definition barometer8.h:259
barometer8_master_io_t write_f
Definition barometer8.h:263
barometer8_drv_t drv_sel
Definition barometer8.h:261
pin_name_t chip_select
Definition barometer8.h:260