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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 #include "drv_spi_master.h"
39 #include "spi_specifics.h"
40 
61 #define BAROMETER8_REG_INTERRUPT_CFG 0x0B
62 #define BAROMETER8_REG_THS_P_L 0x0C
63 #define BAROMETER8_REG_THS_P_H 0x0D
64 #define BAROMETER8_REG_IF_CTRL 0x0E
65 #define BAROMETER8_REG_WHO_AM_I 0x0F
66 #define BAROMETER8_REG_CTRL_REG1 0x10
67 #define BAROMETER8_REG_CTRL_REG2 0x11
68 #define BAROMETER8_REG_CTRL_REG3 0x12
69 #define BAROMETER8_REG_FIFO_CTRL 0x14
70 #define BAROMETER8_REG_FIFO_WTM 0x15
71 #define BAROMETER8_REG_REF_P_L 0x16
72 #define BAROMETER8_REG_REF_P_H 0x17
73 #define BAROMETER8_REG_I3C_IF_CTRL 0x19
74 #define BAROMETER8_REG_RPDS_L 0x1A
75 #define BAROMETER8_REG_RPDS_H 0x1B
76 #define BAROMETER8_REG_INT_SOURCE 0x24
77 #define BAROMETER8_REG_FIFO_STATUS1 0x25
78 #define BAROMETER8_REG_FIFO_STATUS2 0x26
79 #define BAROMETER8_REG_STATUS 0x27
80 #define BAROMETER8_REG_PRESSURE_OUT_XL 0x28
81 #define BAROMETER8_REG_PRESSURE_OUT_L 0x29
82 #define BAROMETER8_REG_PRESSURE_OUT_H 0x2A
83 #define BAROMETER8_REG_TEMP_OUT_L 0x2B
84 #define BAROMETER8_REG_TEMP_OUT_H 0x2C
85 #define BAROMETER8_REG_FIFO_DATA_OUT_PRESS_XL 0x78
86 #define BAROMETER8_REG_FIFO_DATA_OUT_PRESS_L 0x79
87 #define BAROMETER8_REG_FIFO_DATA_OUT_PRESS_H 0x7A
88  // barometer8_reg
90 
105 #define BAROMETER8_DISABLE_I2C_AND_I3C 0x40
106 #define BAROMETER8_ENABLE_SPI_READ 0x20
107 #define BAROMETER8_SDA_PULL_UP 0x10
108 #define BAROMETER8_CS_PULL_UP_DISC 0x02
109 
114 #define BAROMETER8_WHO_AM_I 0xB4
115 
120 #define BAROMETER8_ODR_PD_OR_ONE_SHOT 0x00
121 #define BAROMETER8_ODR_1HZ 0x08
122 #define BAROMETER8_ODR_4HZ 0x10
123 #define BAROMETER8_ODR_10HZ 0x18
124 #define BAROMETER8_ODR_25HZ 0x20
125 #define BAROMETER8_ODR_50HZ 0x28
126 #define BAROMETER8_ODR_75HZ 0x30
127 #define BAROMETER8_ODR_100HZ 0x38
128 #define BAROMETER8_ODR_200HZ 0x40
129 #define BAROMETER8_ODR_BIT_MASK 0x78
130 #define BAROMETER8_AVG_4 0x00
131 #define BAROMETER8_AVG_8 0x01
132 #define BAROMETER8_AVG_16 0x02
133 #define BAROMETER8_AVG_32 0x03
134 #define BAROMETER8_AVG_64 0x04
135 #define BAROMETER8_AVG_128 0x05
136 #define BAROMETER8_AVG_512 0x07
137 #define BAROMETER8_AVG_BIT_MASK 0x07
138 
143 #define BAROMETER8_BOOT_NORMAL 0x00
144 #define BAROMETER8_REBOOT_MEMORY 0x80
145 #define BAROMETER8_FS_MODE_1 0x00
146 #define BAROMETER8_FS_MODE_2 0x40
147 #define BAROMETER8_LFPF_CFG_ODR_4 0x00
148 #define BAROMETER8_LFPF_CFG_ODR_9 0x20
149 #define BAROMETER8_DISABLE_LPFP 0x00
150 #define BAROMETER8_ENABLE_LPFP 0x10
151 #define BAROMETER8_BDU_CONTINUOUS 0x00
152 #define BAROMETER8_BDU_MSB_LSB_READ 0x08
153 #define BAROMETER8_SWRESET 0x04
154 #define BAROMETER8_ONESHOT_IDLE 0x00
155 #define BAROMETER8_ONESHOT_NEW_DATA 0x01
156 
161 #define BAROMETER8_STATUS_T_OR 0x20
162 #define BAROMETER8_STATUS_P_OR 0x10
163 #define BAROMETER8_STATUS_T_DA 0x02
164 #define BAROMETER8_STATUS_P_DA 0x01
165 
170 #define BAROMETER8_PRESSURE_FS_MODE_1_RES 4096.0
171 #define BAROMETER8_PRESSURE_FS_MODE_2_RES 2048.0
172 #define BAROMETER8_TEMPERATURE_RES 0.01
173 
179 #define BAROMETER8_SET_DEVICE_ADDRESS 0x5C
180 
189 #define BAROMETER8_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
190 #define BAROMETER8_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
191  // barometer8_set
193 
208 #define BAROMETER8_MAP_MIKROBUS( cfg, mikrobus ) \
209  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
210  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
211  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
212  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
213  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
214  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
215  // barometer8_map // barometer8
218 
223 typedef enum
224 {
229 
234 typedef err_t ( *barometer8_master_io_t )( struct barometer8_s*, uint8_t, uint8_t*, uint8_t );
240 typedef struct barometer8_s
241 {
242  i2c_master_t i2c;
243  spi_master_t spi;
245  uint8_t slave_address;
246  pin_name_t chip_select;
252  uint8_t ctrl_reg2;
255 
260 typedef struct
261 {
262  pin_name_t scl;
263  pin_name_t sda;
264  pin_name_t miso;
265  pin_name_t mosi;
266  pin_name_t sck;
267  pin_name_t cs;
269  uint32_t i2c_speed;
270  uint8_t i2c_address;
272  uint32_t spi_speed;
273  spi_master_mode_t spi_mode;
274  spi_master_chip_select_polarity_t cs_polarity;
279 
284 typedef enum
285 {
287  BAROMETER8_ERROR = -1
288 
290 
307 
323 
338 
352 
367 err_t barometer8_generic_write ( barometer8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
368 
383 err_t barometer8_generic_read ( barometer8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
384 
397 err_t barometer8_write_register ( barometer8_t *ctx, uint8_t reg, uint8_t data_in );
398 
411 err_t barometer8_read_register ( barometer8_t *ctx, uint8_t reg, uint8_t *data_out );
412 
424 
436 
449 err_t barometer8_read_data ( barometer8_t *ctx, float *pressure, float *temperature );
450 
451 #ifdef __cplusplus
452 }
453 #endif
454 #endif // BAROMETER8_H
455  // barometer8
457 
458 // ------------------------------------------------------------------------ END
barometer8_cfg_t::spi_speed
uint32_t spi_speed
Definition: barometer8.h:272
barometer8_cfg_setup
void barometer8_cfg_setup(barometer8_cfg_t *cfg)
Barometer 8 configuration object setup function.
barometer8_s::drv_sel
barometer8_drv_t drv_sel
Definition: barometer8.h:247
barometer8_drv_interface_selection
void barometer8_drv_interface_selection(barometer8_cfg_t *cfg, barometer8_drv_t drv_sel)
Barometer 8 driver interface setup function.
barometer8_cfg_t::scl
pin_name_t scl
Definition: barometer8.h:262
BAROMETER8_ERROR
@ BAROMETER8_ERROR
Definition: barometer8.h:287
barometer8_cfg_t
Barometer 8 Click configuration object.
Definition: barometer8.h:261
barometer8_s::read_f
barometer8_master_io_t read_f
Definition: barometer8.h:250
barometer8_cfg_t::miso
pin_name_t miso
Definition: barometer8.h:264
spi_specifics.h
This file contains SPI specific macros, functions, etc.
barometer8_s
Barometer 8 Click context object.
Definition: barometer8.h:241
barometer8_s::spi
spi_master_t spi
Definition: barometer8.h:243
barometer8_s::write_f
barometer8_master_io_t write_f
Definition: barometer8.h:249
barometer8_cfg_t::sda
pin_name_t sda
Definition: barometer8.h:263
barometer8_default_cfg
err_t barometer8_default_cfg(barometer8_t *ctx)
Barometer 8 default configuration function.
barometer8_write_register
err_t barometer8_write_register(barometer8_t *ctx, uint8_t reg, uint8_t data_in)
Barometer 8 write register function.
BAROMETER8_DRV_SEL_I2C
@ BAROMETER8_DRV_SEL_I2C
Definition: barometer8.h:226
barometer8_s::ctrl_reg2
uint8_t ctrl_reg2
Definition: barometer8.h:252
BAROMETER8_OK
@ BAROMETER8_OK
Definition: barometer8.h:286
barometer8_init
err_t barometer8_init(barometer8_t *ctx, barometer8_cfg_t *cfg)
Barometer 8 initialization function.
barometer8_generic_write
err_t barometer8_generic_write(barometer8_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Barometer 8 data writing function.
barometer8_read_data
err_t barometer8_read_data(barometer8_t *ctx, float *pressure, float *temperature)
Barometer 8 read data function.
barometer8_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: barometer8.h:274
barometer8_generic_read
err_t barometer8_generic_read(barometer8_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Barometer 8 data reading function.
barometer8_t
struct barometer8_s barometer8_t
Barometer 8 Click context object.
barometer8_cfg_t::mosi
pin_name_t mosi
Definition: barometer8.h:265
barometer8_s::chip_select
pin_name_t chip_select
Definition: barometer8.h:246
barometer8_check_communication
err_t barometer8_check_communication(barometer8_t *ctx)
Barometer 8 check communication function.
barometer8_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: barometer8.h:273
barometer8_software_reset
err_t barometer8_software_reset(barometer8_t *ctx)
Barometer 8 software reset function.
barometer8_cfg_t::i2c_address
uint8_t i2c_address
Definition: barometer8.h:270
barometer8_s::i2c
i2c_master_t i2c
Definition: barometer8.h:242
barometer8_drv_t
barometer8_drv_t
Barometer 8 Click driver selector.
Definition: barometer8.h:224
barometer8_cfg_t::drv_sel
barometer8_drv_t drv_sel
Definition: barometer8.h:276
barometer8_return_value_t
barometer8_return_value_t
Barometer 8 Click return value data.
Definition: barometer8.h:285
barometer8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: barometer8.h:269
barometer8_read_register
err_t barometer8_read_register(barometer8_t *ctx, uint8_t reg, uint8_t *data_out)
Barometer 8 read register function.
barometer8_s::slave_address
uint8_t slave_address
Definition: barometer8.h:245
BAROMETER8_DRV_SEL_SPI
@ BAROMETER8_DRV_SEL_SPI
Definition: barometer8.h:225
barometer8_cfg_t::cs
pin_name_t cs
Definition: barometer8.h:267
barometer8_master_io_t
err_t(* barometer8_master_io_t)(struct barometer8_s *, uint8_t, uint8_t *, uint8_t)
Barometer 8 Click driver interface.
Definition: barometer8.h:234
barometer8_cfg_t::sck
pin_name_t sck
Definition: barometer8.h:266