pressure3  2.0.0.0
pressure3.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 PRESSURE3_H
36 #define PRESSURE3_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 PRESSURE3_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.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76 
82 #define PRESSURE3_MASTER_I2C 0
83 #define PRESSURE3_MASTER_SPI 1
84 
90 #define PRESSURE3_RETVAL uint8_t
91 
92 #define PRESSURE3_OK 0x00
93 #define PRESSURE3_INIT_ERROR 0xFF
94 
100 #define PRESSURE3_I2C_SELECT 0
101 #define PRESSURE3_SPI_SELECT 1
102 #define PRESSURE3_SPI_CMD_WRITE 0x7F
103 #define PRESSURE3_SPI_CMD_READ 0x80
104 
110 #define PRESSURE3_I2C_ADDRESS 0x76
111 #define PRESSURE3_REG_PSR_B2 0x00
112 #define PRESSURE3_REG_PSR_B1 0x01
113 #define PRESSURE3_REG_PSR_B0 0x02
114 #define PRESSURE3_REG_TMP_B2 0x03
115 #define PRESSURE3_REG_TMP_B1 0x04
116 #define PRESSURE3_REG_TMP_B0 0x05
117 #define PRESSURE3_REG_PRS_CFG 0x06
118 #define PRESSURE3_REG_TMP_CFG 0x07
119 #define PRESSURE3_REG_MEAS_CFG 0x08
120 #define PRESSURE3_REG_CFG_REG 0x09
121 #define PRESSURE3_REG_INT_STS 0x0A
122 #define PRESSURE3_REG_FIFO_STS 0x0B
123 #define PRESSURE3_REG_RESET 0x0C
124 #define PRESSURE3_REG_PRODUCT_ID 0x0D
125 #define PRESSURE3_REG_COEF_C0_MBS 0x10
126 #define PRESSURE3_REG_COEF_C0_LBS_C1_MBS 0x11
127 #define PRESSURE3_REG_COEF_C1_LBS 0x12
128 #define PRESSURE3_REG_COEF_C00_MBS 0x13
129 #define PRESSURE3_REG_COEF_C00_LSB 0x14
130 #define PRESSURE3_REG_COEF_C00_XLSB_C10_MSB 0x15
131 #define PRESSURE3_REG_COEF_C10_LSB 0x16
132 #define PRESSURE3_REG_COEF_C10_XLSB 0x17
133 #define PRESSURE3_REG_COEF_C01_MSB 0x18
134 #define PRESSURE3_REG_COEF_C01_LSB 0x19
135 #define PRESSURE3_REG_COEF_C11_MSB 0x1A
136 #define PRESSURE3_REG_COEF_C11_LSB 0x1B
137 #define PRESSURE3_REG_COEF_C20_MSB 0x1C
138 #define PRESSURE3_REG_COEF_C20_LSB 0x1D
139 #define PRESSURE3_REG_COEF_C21_MSB 0x1E
140 #define PRESSURE3_REG_COEF_C21_LSB 0x1F
141 #define PRESSURE3_REG_COEF_C30_MSB 0x20
142 #define PRESSURE3_REG_COEF_C30_LSB 0x21
143 #define PRESSURE3_REG_COEF_SRCE 0x28
144 
150 #define PRESSURE3_BIT_MASK_PM_RATE_1_PER_SEC 0x00
151 #define PRESSURE3_BIT_MASK_PM_RATE_2_PER_SEC 0x10
152 #define PRESSURE3_BIT_MASK_PM_RATE_4_PER_SEC 0x20
153 #define PRESSURE3_BIT_MASK_PM_RATE_8_PER_SEC 0x30
154 #define PRESSURE3_BIT_MASK_PM_RATE_16_PER_SEC 0x40
155 #define PRESSURE3_BIT_MASK_PM_RATE_32_PER_SEC 0x50
156 #define PRESSURE3_BIT_MASK_PM_RATE_64_PER_SEC 0x60
157 #define PRESSURE3_BIT_MASK_PM_RATE_128_PER_SEC 0x70
158 #define PRESSURE3_BIT_MASK_PM_PRC_1_PER_SEC 0x00
159 #define PRESSURE3_BIT_MASK_PM_PRC_2_PER_SEC 0x01
160 #define PRESSURE3_BIT_MASK_PM_PRC_4_PER_SEC 0x02
161 #define PRESSURE3_BIT_MASK_PM_PRC_8_PER_SEC 0x03
162 #define PRESSURE3_BIT_MASK_PM_PRC_16_PER_SEC 0x04
163 #define PRESSURE3_BIT_MASK_PM_PRC_32_PER_SEC 0x05
164 #define PRESSURE3_BIT_MASK_PM_PRC_64_PER_SEC 0x06
165 #define PRESSURE3_BIT_MASK_PM_PRC_128_PER_SEC 0x07
166 
172 #define PRESSURE3_BIT_MASK_TMP_EXT_INTERNAL_SENSOR 0x00
173 #define PRESSURE3_BIT_MASK_TMP_EXT_EXTERNAL_SENSOR 0x80
174 #define PRESSURE3_BIT_MASK_TMP_RATE_1_PER_SEC 0x00
175 #define PRESSURE3_BIT_MASK_TMP_RATE_2_PER_SEC 0x10
176 #define PRESSURE3_BIT_MASK_TMP_RATE_4_PER_SEC 0x20
177 #define PRESSURE3_BIT_MASK_TMP_RATE_8_PER_SEC 0x30
178 #define PRESSURE3_BIT_MASK_TMP_RATE_16_PER_SEC 0x40
179 #define PRESSURE3_BIT_MASK_TMP_RATE_32_PER_SEC 0x50
180 #define PRESSURE3_BIT_MASK_TMP_RATE_64_PER_SEC 0x60
181 #define PRESSURE3_BIT_MASK_TMP_RATE_128_PER_SEC 0x70
182 #define PRESSURE3_BIT_MASK_TMP_PRC_1_PER_SEC 0x00
183 #define PRESSURE3_BIT_MASK_TMP_PRC_2_PER_SEC 0x01
184 #define PRESSURE3_BIT_MASK_TMP_PRC_4_PER_SEC 0x02
185 #define PRESSURE3_BIT_MASK_TMP_PRC_8_PER_SEC 0x03
186 #define PRESSURE3_BIT_MASK_TMP_PRC_16_PER_SEC 0x04
187 #define PRESSURE3_BIT_MASK_TMP_PRC_32_PER_SEC 0x05
188 #define PRESSURE3_BIT_MASK_TMP_PRC_64_PER_SEC 0x06
189 #define PRESSURE3_BIT_MASK_TMP_PRC_128_PER_SEC 0x07
190 
196 #define PRESSURE3_BIT_MASK_MEAS_CFG_COEF_RDY_AVB 0x80
197 #define PRESSURE3_BIT_MASK_MEAS_CFG_COEF_RDY_NO_AVB 0x00
198 #define PRESSURE3_BIT_MASK_MEAS_CFG_SENSOR_RDY_CMP 0x40
199 #define PRESSURE3_BIT_MASK_MEAS_CFG_SENSOR_RDY_NO_CMP 0x00
200 #define PRESSURE3_BIT_MASK_MEAS_CFG_TMP_RDY 0x20
201 #define PRESSURE3_BIT_MASK_MEAS_CFG_PRS_RDY 0x10
202 #define PRESSURE3_BIT_MASK_MEAS_CFG_MEAS_CTRL_IDLE 0x00
203 #define PRESSURE3_BIT_MASK_MEAS_CFG_MEAS_CTRL_PRS 0x01
204 #define PRESSURE3_BIT_MASK_MEAS_CFG_MEAS_CTRL_TMP 0x02
205 #define PRESSURE3_BIT_MASK_MEAS_CFG_MEAS_CTRL_CNT_PRS 0x05
206 #define PRESSURE3_BIT_MASK_MEAS_CFG_MEAS_CTRL_CNT_TMP 0x06
207 #define PRESSURE3_BIT_MASK_MEAS_CFG_MEAS_CTRL_CNT_PRS_TMP 0x07
208 
214 #define PRESSURE3_BIT_MASK_CFG_REG_INT_HL_LOW 0x00
215 #define PRESSURE3_BIT_MASK_CFG_REG_INT_HL_HIGH 0x80
216 #define PRESSURE3_BIT_MASK_CFG_REG_INT_FIFO_DISABLE 0x00
217 #define PRESSURE3_BIT_MASK_CFG_REG_INT_FIFO_ENABLE 0x40
218 #define PRESSURE3_BIT_MASK_CFG_REG_INT_TMP_DISABLE 0x00
219 #define PRESSURE3_BIT_MASK_CFG_REG_INT_TMP_ENABLE 0x20
220 #define PRESSURE3_BIT_MASK_CFG_REG_INT_PRS_DISABLE 0x00
221 #define PRESSURE3_BIT_MASK_CFG_REG_INT_PRS_ENABLE 0x10
222 #define PRESSURE3_BIT_MASK_CFG_REG_T_SHIFT_NO_SHIFT 0x00
223 #define PRESSURE3_BIT_MASK_CFG_REG_T_SHIFT_SHIFT 0x08
224 #define PRESSURE3_BIT_MASK_CFG_REG_P_SHIFT_NO_SHIFT 0x00
225 #define PRESSURE3_BIT_MASK_CFG_REG_P_SHIFT_SHIFT 0x04
226 #define PRESSURE3_BIT_MASK_CFG_REG_FIFO_EN_DISABLE 0x00
227 #define PRESSURE3_BIT_MASK_CFG_REG_FIFO_EN_ENABLE 0x02
228 #define PRESSURE3_BIT_MASK_CFG_REG_SPI_MODE_DISABLE 0x00
229 #define PRESSURE3_BIT_MASK_CFG_REG_SPI_MODE_ENABLE 0x01
230 
236 #define PRESSURE3_BIT_MASK_INT_STS_INT_FIFO_FULL_NO_ACTIVE 0x00
237 #define PRESSURE3_BIT_MASK_INT_STS_INT_FIFO_FULL_ACTIVE 0x04
238 #define PRESSURE3_BIT_MASK_INT_STS_INT_TMP_NO_ACTIVE 0x00
239 #define PRESSURE3_BIT_MASK_INT_STS_INT_TMP_ACTIVE 0x02
240 #define PRESSURE3_BIT_MASK_INT_STS_INT_PRS_NO_ACTIVE 0x00
241 #define PRESSURE3_BIT_MASK_INT_STS_INT_PRS_ACTIVE 0x01
242 
248 #define PRESSURE3_BIT_MASK_FIFO_STS_FIFO_FULL_NO 0x00
249 #define PRESSURE3_BIT_MASK_FIFO_STS_FIFO_FULL_FULL 0x02
250 #define PRESSURE3_BIT_MASK_FIFO_STS_FIFO_EMPTY_NO 0x00
251 #define PRESSURE3_BIT_MASK_FIFO_STS_FIFO_EMPTY_EMPTY 0x01
252 
258 #define PRESSURE3_BIT_MASK_RESET_SOFT_RST 0x09
259 
265 #define PRESSURE3_BIT_MASK_TMP_COEF_SRCE_INTERNAL_SENSOR 0x00
266 #define PRESSURE3_BIT_MASK_TMP_COEF_SRCE_EXTERNAL_SENSOR 0x80
267  // End group macro
270 // --------------------------------------------------------------- PUBLIC TYPES
279 typedef uint8_t pressure3_select_t;
280 
284 typedef void ( *pressure3_master_io_t )( struct pressure3_s*, uint8_t, uint8_t*, uint8_t );
285 
289 typedef struct
290 {
291  int16_t coeff_c0;
292  int16_t coeff_c1;
293  int32_t coeff_c00;
294  int32_t coeff_c10;
295  int16_t coeff_c01;
296  int16_t coeff_c11;
297  int16_t coeff_c20;
298  int16_t coeff_c21;
299  int16_t coeff_c30;
300 
302 
306 typedef struct pressure3_s
307 {
308  // Output pins
309 
310  digital_out_t cs;
311 
312  // Input pins
313 
314  digital_in_t int_pin;
315 
316  // Modules
317 
318  i2c_master_t i2c;
319  spi_master_t spi;
320 
321  // ctx variable
322 
323  uint8_t slave_address;
324  pin_name_t chip_select;
328 
330 
334 typedef struct
335 {
336  // Communication gpio pins
337 
338  pin_name_t scl;
339  pin_name_t sda;
340  pin_name_t miso;
341  pin_name_t mosi;
342  pin_name_t sck;
343  pin_name_t cs;
344 
345  // Additional gpio pins
346 
347  pin_name_t int_pin;
348 
349  // static variable
350 
351  uint32_t i2c_speed;
352  uint8_t i2c_address;
353 
354  uint32_t spi_speed;
355  spi_master_mode_t spi_mode;
356  spi_master_chip_select_polarity_t cs_polarity;
357 
359 
361  // End types group
363 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
369 #ifdef __cplusplus
370 extern "C"{
371 #endif
372 
382 
392 
401 
412 void pressure3_generic_write ( pressure3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
413 
424 void pressure3_generic_read ( pressure3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
425 
436 void pressure3_get_t_p_data ( pressure3_t *ctx, float *temperature, float *presure, pressure3_coeff_t *coeff_struct );
437 
448 
457 int32_t pressure3_get_measurement_data ( pressure3_t *ctx, uint8_t mbs_reg_addr );
458 
489 void pressure3_set_pressure_configuration ( pressure3_t *ctx, uint8_t press_config );
490 
500 
532 void pressure3_set_temperature_configuration ( pressure3_t *ctx, uint8_t temp_config );
533 
543 
552 void pressure3_set_operating_mode( pressure3_t *ctx, uint8_t operation_mode );
553 
563 
572 void pressure3_set_configuration ( pressure3_t *ctx,uint8_t confg_data );
573 
583 
593 
603 
613 
614 #ifdef __cplusplus
615 }
616 #endif
617 #endif // _PRESSURE3_H_
618  // End public_function group
621 
622 // ------------------------------------------------------------------------- END
pressure3_cfg_t::miso
pin_name_t miso
Definition: pressure3.h:340
PRESSURE3_RETVAL
#define PRESSURE3_RETVAL
Definition: pressure3.h:90
pressure3_s::i2c
i2c_master_t i2c
Definition: pressure3.h:318
pressure3_cfg_t::cs
pin_name_t cs
Definition: pressure3.h:343
pressure3_s
Click ctx object definition.
Definition: pressure3.h:307
pressure3_master_io_t
void(* pressure3_master_io_t)(struct pressure3_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition: pressure3.h:284
pressure3_get_measurement_data
int32_t pressure3_get_measurement_data(pressure3_t *ctx, uint8_t mbs_reg_addr)
Read the coefficients value for calculation function.
pressure3_set_pressure_configuration
void pressure3_set_pressure_configuration(pressure3_t *ctx, uint8_t press_config)
Set the pressure configuration function.
pressure3_s::write_f
pressure3_master_io_t write_f
Definition: pressure3.h:325
pressure3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: pressure3.h:356
pressure3_get_interrupt_status
uint8_t pressure3_get_interrupt_status(pressure3_t *ctx)
Get the interrupt status function.
pressure3_get_coefficients
void pressure3_get_coefficients(pressure3_t *ctx, pressure3_coeff_t *coeff_struct)
Get coefficients.
pressure3_soft_reset
void pressure3_soft_reset(pressure3_t *ctx)
Soft reset function.
pressure3_set_temperature_configuration
void pressure3_set_temperature_configuration(pressure3_t *ctx, uint8_t temp_config)
Set the temperature configuration function.
pressure3_get_pressure_configuration
uint8_t pressure3_get_pressure_configuration(pressure3_t *ctx)
Get the pressure configuration function.
pressure3_default_cfg
void pressure3_default_cfg(pressure3_t *ctx)
Click Default Configuration function.
pressure3_s::read_f
pressure3_master_io_t read_f
Definition: pressure3.h:326
pressure3_set_configuration
void pressure3_set_configuration(pressure3_t *ctx, uint8_t confg_data)
Set the configuration function.
pressure3_cfg_setup
void pressure3_cfg_setup(pressure3_cfg_t *cfg)
Config Object Initialization function.
pressure3_s::chip_select
pin_name_t chip_select
Definition: pressure3.h:324
pressure3_cfg_t::int_pin
pin_name_t int_pin
Definition: pressure3.h:347
pressure3_cfg_t::scl
pin_name_t scl
Definition: pressure3.h:338
pressure3_coeff_t::coeff_c11
int16_t coeff_c11
Definition: pressure3.h:296
pressure3_select_t
uint8_t pressure3_select_t
Communication type.
Definition: pressure3.h:279
pressure3_cfg_t::sda
pin_name_t sda
Definition: pressure3.h:339
pressure3_cfg_t::mosi
pin_name_t mosi
Definition: pressure3.h:341
pressure3_coeff_t::coeff_c30
int16_t coeff_c30
Definition: pressure3.h:299
pressure3_get_configuration
uint8_t pressure3_get_configuration(pressure3_t *ctx)
Get the configuration function.
pressure3_get_temperature_configuration
uint8_t pressure3_get_temperature_configuration(pressure3_t *ctx)
Get the temperature configuration function.
pressure3_coeff_t::coeff_c00
int32_t coeff_c00
Definition: pressure3.h:293
pressure3_s::int_pin
digital_in_t int_pin
Definition: pressure3.h:314
pressure3_coeff_t::coeff_c10
int32_t coeff_c10
Definition: pressure3.h:294
pressure3_get_fifo_status
uint8_t pressure3_get_fifo_status(pressure3_t *ctx)
Get the FIFO Status function.
pressure3_coeff_t::coeff_c20
int16_t coeff_c20
Definition: pressure3.h:297
pressure3_coeff_t::coeff_c21
int16_t coeff_c21
Definition: pressure3.h:298
pressure3_coeff_t
Coefficients structure.
Definition: pressure3.h:290
pressure3_generic_read
void pressure3_generic_read(pressure3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
pressure3_coeff_t::coeff_c0
int16_t coeff_c0
Definition: pressure3.h:291
pressure3_cfg_t::i2c_address
uint8_t i2c_address
Definition: pressure3.h:352
pressure3_s::master_sel
pressure3_select_t master_sel
Definition: pressure3.h:327
pressure3_set_operating_mode
void pressure3_set_operating_mode(pressure3_t *ctx, uint8_t operation_mode)
Get the sensor operating mode function.
pressure3_get_operating_mode
uint8_t pressure3_get_operating_mode(pressure3_t *ctx)
Get the sensor operating mode function.
pressure3_coeff_t::coeff_c1
int16_t coeff_c1
Definition: pressure3.h:292
pressure3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: pressure3.h:355
pressure3_s::spi
spi_master_t spi
Definition: pressure3.h:319
pressure3_cfg_t
Click configuration structure definition.
Definition: pressure3.h:335
pressure3_cfg_t::sck
pin_name_t sck
Definition: pressure3.h:342
pressure3_generic_write
void pressure3_generic_write(pressure3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
pressure3_coeff_t::coeff_c01
int16_t coeff_c01
Definition: pressure3.h:295
pressure3_get_t_p_data
void pressure3_get_t_p_data(pressure3_t *ctx, float *temperature, float *presure, pressure3_coeff_t *coeff_struct)
Get temperature pressure.
pressure3_s::cs
digital_out_t cs
Definition: pressure3.h:310
pressure3_cfg_t::sel
pressure3_select_t sel
Definition: pressure3.h:358
pressure3_t
struct pressure3_s pressure3_t
Click ctx object definition.
pressure3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: pressure3.h:351
pressure3_init
PRESSURE3_RETVAL pressure3_init(pressure3_t *ctx, pressure3_cfg_t *cfg)
Initialization function.
pressure3_cfg_t::spi_speed
uint32_t spi_speed
Definition: pressure3.h:354
pressure3_s::slave_address
uint8_t slave_address
Definition: pressure3.h:323