pressure 2.0.0.0
pressure.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 _PRESSURE_H_
36#define _PRESSURE_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
72#define PRESSURE_REG_REF_P_XLB 0x8 // Reference pressure (LSB)
73#define PRESSURE_REG_REF_P_LSB 0x9 // Reference pressure (middle)
74#define PRESSURE_REG_REF_P_MSB 0xA // Reference pressure (MSB)
75#define PRESSURE_REG_DEVICE_ID 0xF // Device identification
76#define PRESSURE_REG_RES_CFG 0x10 // Pressure resolution
77#define PRESSURE_REG_CTRL_REG1 0x20 // Control register 1
78#define PRESSURE_REG_CTRL_REG2 0x21 // Control register 2
79#define PRESSURE_REG_CTRL_REG3 0x22 // Control register 3
80#define PRESSURE_REG_INT_CFG 0x23 // Interrupt configuration
81#define PRESSURE_REG_INT_SOURCE 0x24 // Interrupt source
82#define PRESSURE_REG_THSH_P_LSB 0x25 // Threshold pressure (LSB)
83#define PRESSURE_REG_THSH_P_MSB 0x26 // Threshold pressure (MSB)
84#define PRESSURE_REG_STATUS 0x27 // Status register
85#define PRESSURE_REG_PRESS_OUT_XLB 0x28 // Pressure data (LSB)
86#define PRESSURE_REG_PRESS_OUT_LSB 0x29 // Pressure data (middle)
87#define PRESSURE_REG_PRESS_OUT_MSB 0x2A // Pressure data (MSB)
88#define PRESSURE_REG_TEMP_OUT_LSB 0x2B // Temperature data (LSB)
89#define PRESSURE_REG_TEMP_OUT_MSB 0x2C // Temperature data (MSB)
90#define PRESSURE_REG_AMP_CTRL 0x30 // Analog front and control
97#define PRESSURE_WHO_AM_I 0xBB
109#define PRESSURE_SET_RES_AVG_1 0x0
110#define PRESSURE_SET_RES_AVG_2 0x1
111#define PRESSURE_SET_RES_AVG_4 0x2
112#define PRESSURE_SET_RES_AVG_8 0x3
113#define PRESSURE_SET_RES_AVG_16 0x4
114#define PRESSURE_SET_RES_AVG_32 0x5
115#define PRESSURE_SET_RES_AVG_64 0x6
116#define PRESSURE_SET_RES_AVG_128 0x7
117#define PRESSURE_SET_RES_AVG_256 0x8
118#define PRESSURE_SET_RES_AVG_384 0x9
119#define PRESSURE_SET_RES_AVG_512 0xA
126#define PRESSURE_SET_PWR_UP_DEV 0x80
127#define PRESSURE_SET_PWR_UP_INT 0x8
128#define PRESSURE_SET_BLOCK_DATA_UPDATE 0x4
129#define PRESSURE_SET_PWR_UP_DELTA_PRESS 0x2
130#define PRESSURE_SET_SPI_3_WIRE 0x1
137#define PRESSURE_SET_REBOOT_MEM_CONTENT 0x80
138#define PRESSURE_SET_SW_RESET 0x4
139#define PRESSURE_SET_AUTOZERO_EN 0x2
140#define PRESSURE_SET_ONESHOT_EN 0x1
141#define PRESSURE_SET_NORMAL_MODE 0x0
148#define PRESSURE_SET_INT_ACT_LOW 0x80
149#define PRESSURE_SET_INT_OPEN_DRAIN 0x40
150#define PRESSURE_SET_INT_GND 0x0
151#define PRESSURE_SET_INT_PRESS_HIGH 0x1
152#define PRESSURE_SET_INT_PRESS_LOW 0x2
153#define PRESSURE_SET_INT_P_LOW_OR_HIGH 0x3
154#define PRESSURE_SET_INT_DATA_RDY 0x4
155#define PRESSURE_SET_INT_TRI_STATE 0x7
158 // End settings group
159
169#define PRESSURE_FLAG_MASK_P_DATA_OR 0x20
170#define PRESSURE_FLAG_MASK_T_DATA_OR 0x10
171#define PRESSURE_FLAG_MASK_P_DATA_RDY 0x2
172#define PRESSURE_FLAG_MASK_T_DATA_RDY 0x1
179#define PRESSURE_FLAG_MASK_INT_ACT 0x4
180#define PRESSURE_FLAG_MASK_DIFF_P_LOW 0x2
181#define PRESSURE_FLAG_MASK_DIFF_P_HIGH 0x1
184 // End status group
185
190#define PRESSURE_DATA_NUMBER_MIN 1
191#define PRESSURE_DATA_NUMBER_MAX 49
194 // End registers group
195
200#define PRESSURE_MAP_MIKROBUS( cfg, mikrobus ) \
201 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
202 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
203 cfg.sdo = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
204 cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
205 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT ); \
206 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
207 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
210 // End macros group
211// --------------------------------------------------------------- PUBLIC TYPES
220typedef void ( *pressure_master_transfer_t )( struct pressure_s*, uint8_t, uint8_t*, uint8_t );
221
233
243
259
269
273typedef struct pressure_s
274{
275 // Output pin
276 digital_out_t cs;
277
278 // Interrupt pin.
279 digital_in_t int_pin;
280
281 // Modules.
282 i2c_master_t i2c;
283 spi_master_t spi;
284
285 // Context variables.
286 uint8_t slave_addr;
287 pin_name_t chip_select;
290
292
296typedef struct
297{
298 // Communication gpio pins.
299 pin_name_t cs;
300 pin_name_t sck;
301 pin_name_t sdo;
302 pin_name_t sdi;
303 pin_name_t scl;
304 pin_name_t sda;
305
306 // Additional gpio pins.
307 pin_name_t int_pin;
308
309 // Configuration variables.
311 uint32_t i2c_speed;
312 uint32_t spi_speed;
313 spi_master_mode_t spi_mode;
314 spi_master_chip_select_polarity_t cs_polarity;
315
317
319
320 // End types group
321// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
327#ifdef __cplusplus
328extern "C"{
329#endif
330
340void
342
359
368void
370
385 uint8_t data_in );
386
404 uint8_t *data_in, uint8_t n_data );
405
423 uint8_t *data_out, uint8_t n_data );
424
434uint8_t
436
445void
447
456void
458
467void
469
480void
482
492void
494
503void
505
514void
516
526float
528
539float
541
553uint8_t
554pressure_get_status( pressure_t *ctx, uint8_t bit_mask );
555
567uint8_t
569
570#ifdef __cplusplus
571}
572#endif
573#endif // _PRESSURE_H_
574
575 // End public_function group
577
578// ------------------------------------------------------------------------ END
float pressure_get_pressure(pressure_t *ctx)
Pressure Get function.
void pressure_sw_reset(pressure_t *ctx)
Software Reset function.
pressure_err_t pressure_init(pressure_t *ctx, pressure_cfg_t *cfg)
Click Initialization function.
void pressure_pwr_ctrl(pressure_t *ctx, pressure_pwr_ctrl_t state)
Device Power Control function.
void pressure_cfg_setup(pressure_cfg_t *cfg)
Configuration Object Setup function.
void pressure_pwr_ctrl_delta_pressure(pressure_t *ctx, pressure_pwr_ctrl_t state)
Delta Pressure Power Control function.
pressure_err_t pressure_generic_multiple_write(pressure_t *ctx, uint8_t reg_addr, uint8_t *data_in, uint8_t n_data)
Generic Multiple Write function.
pressure_err_t pressure_generic_single_write(pressure_t *ctx, uint8_t reg_addr, uint8_t data_in)
Generic Single Write function.
void pressure_default_cfg(pressure_t *ctx)
Click Default Configuration function.
void pressure_set_odr(pressure_t *ctx, pressure_odr_t odr)
Output Data Rate Set function.
void pressure_pwr_ctrl_interrupt(pressure_t *ctx, pressure_pwr_ctrl_t state)
Interrupt Power Control function.
uint8_t pressure_get_status(pressure_t *ctx, uint8_t bit_mask)
Status Get function.
uint8_t pressure_read_id(pressure_t *ctx)
ID Read function.
float pressure_get_temperature(pressure_t *ctx)
Temperature Get function.
void pressure_reboot_memory(pressure_t *ctx)
Memory Reboot function.
uint8_t pressure_get_int_pin(pressure_t *ctx)
INT Pin Get function.
void pressure_block_data_update(pressure_t *ctx, pressure_pwr_ctrl_t state)
Data Update Block function.
pressure_err_t pressure_generic_multiple_read(pressure_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint8_t n_data)
Generic Multiple Read function.
struct pressure_s pressure_t
Click context object definition.
pressure_drv_select_t
Click driver selector definition.
Definition pressure.h:238
void(* pressure_master_transfer_t)(struct pressure_s *, uint8_t, uint8_t *, uint8_t)
Click master transfer function definition.
Definition pressure.h:220
pressure_err_t
Click error code definition.
Definition pressure.h:226
pressure_pwr_ctrl_t
Click power control definition.
Definition pressure.h:264
pressure_odr_t
Click output data rate definition.
Definition pressure.h:248
@ PRESSURE_DRV_SEL_I2C
Definition pressure.h:239
@ PRESSURE_DRV_SEL_SPI
Definition pressure.h:240
@ PRESSURE_ERR_ADDR
Definition pressure.h:229
@ PRESSURE_OK
Definition pressure.h:227
@ PRESSURE_ERR_INIT_DRV
Definition pressure.h:228
@ PRESSURE_ERR_NDATA
Definition pressure.h:230
@ PRESSURE_PWR_DOWN
Definition pressure.h:265
@ PRESSURE_PWR_UP
Definition pressure.h:266
@ PRESSURE_ODR_P12HZ_T1HZ
Definition pressure.h:252
@ PRESSURE_ODR_P25HZ_T25HZ
Definition pressure.h:256
@ PRESSURE_ODR_P1HZ_T1HZ
Definition pressure.h:250
@ PRESSURE_ODR_P7HZ_T7HZ
Definition pressure.h:254
@ PRESSURE_ODR_P7HZ_T1HZ
Definition pressure.h:251
@ PRESSURE_ODR_P12HZ_T12HZ
Definition pressure.h:255
@ PRESSURE_ODR_P25HZ_T1HZ
Definition pressure.h:253
@ PRESSURE_ODR_ONE_SHOT
Definition pressure.h:249
Click configuration structure definition.
Definition pressure.h:297
bool i2c_addr
Definition pressure.h:310
pin_name_t sdi
Definition pressure.h:302
uint32_t i2c_speed
Definition pressure.h:311
spi_master_chip_select_polarity_t cs_polarity
Definition pressure.h:314
pin_name_t sck
Definition pressure.h:300
spi_master_mode_t spi_mode
Definition pressure.h:313
pressure_drv_select_t drv_sel
Definition pressure.h:316
uint32_t spi_speed
Definition pressure.h:312
pin_name_t sdo
Definition pressure.h:301
pin_name_t scl
Definition pressure.h:303
pin_name_t int_pin
Definition pressure.h:307
pin_name_t sda
Definition pressure.h:304
pin_name_t cs
Definition pressure.h:299
Click context object definition.
Definition pressure.h:274
digital_out_t cs
Definition pressure.h:276
spi_master_t spi
Definition pressure.h:283
digital_in_t int_pin
Definition pressure.h:279
i2c_master_t i2c
Definition pressure.h:282
uint8_t slave_addr
Definition pressure.h:286
pressure_master_transfer_t write
Definition pressure.h:288
pressure_master_transfer_t read
Definition pressure.h:289
pin_name_t chip_select
Definition pressure.h:287