pressure4 2.0.0.0
pressure4.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 PRESSURE4_H
36#define PRESSURE4_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 PRESSURE4_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 )
81#define PRESSURE4_MASTER_I2C 0
82#define PRESSURE4_MASTER_SPI 1
89#define PRESSURE4_OK 0
90#define PRESSURE4_ERROR -1
97#define PRESSURE4_ADDR0 0x76
98#define PRESSURE4_ADDR1 0x77
99#define PRESSURE4_ID 0xD0
100#define PRESSURE4_RESET 0xE0
101#define PRESSURE4_STATUS 0xF3
102#define PRESSURE4_CTL_MEAS 0xF4
103#define PRESSURE4_CONFIG 0xF5
104#define PRESSURE4_PRESS_MSB 0xF7
105#define PRESSURE4_PRESS_LSB 0xF8
106#define PRESSURE4_PRESS_XLSB 0xF9
107#define PRESSURE4_TEMP_MSB 0xFA
108#define PRESSURE4_TEMP_LSB 0xFB
109#define PRESSURE4_TEMP_XLSB 0xFC
116#define PRESSURE4_CALIBRATION_DIG_T1 0x88
117#define PRESSURE4_CALIBRATION_DIG_T2 0x8A
118#define PRESSURE4_CALIBRATION_DIG_T3 0x8C
119#define PRESSURE4_CALIBRATION_DIG_P1 0x8E
120#define PRESSURE4_CALIBRATION_DIG_P2 0x90
121#define PRESSURE4_CALIBRATION_DIG_P3 0x92
122#define PRESSURE4_CALIBRATION_DIG_P4 0x94
123#define PRESSURE4_CALIBRATION_DIG_P5 0x96
124#define PRESSURE4_CALIBRATION_DIG_P6 0x98
125#define PRESSURE4_CALIBRATION_DIG_P7 0x9A
126#define PRESSURE4_CALIBRATION_DIG_P8 0x9C
127#define PRESSURE4_CALIBRATION_DIG_P9 0x9E
130 // End group macro
131// --------------------------------------------------------------- PUBLIC TYPES
140typedef void ( *pressure4_master_io_t )( struct pressure4_s*, uint8_t, uint8_t*, uint8_t );
141
145typedef struct pressure4_s
146{
147 // Output pins
148 digital_out_t cs;
149
150 // Modules
151 i2c_master_t i2c;
152 spi_master_t spi;
153
154 // ctx variable
156 pin_name_t chip_select;
159 uint8_t master_sel;
160
161 uint16_t dig_t1;
162 int16_t dig_t2;
163 int16_t dig_t3;
164
165 uint16_t dig_p1;
166 int16_t dig_p2;
167 int16_t dig_p3;
168 int16_t dig_p4;
169 int16_t dig_p5;
170 int16_t dig_p6;
171 int16_t dig_p7;
172 int16_t dig_p8;
173 int16_t dig_p9;
174
175 int32_t t_fine;
178
180
184typedef struct
185{
186 // Communication gpio pins
187 pin_name_t scl;
188 pin_name_t sda;
189 pin_name_t miso;
190 pin_name_t mosi;
191 pin_name_t sck;
192 pin_name_t cs;
193
194 // static variable
195 uint32_t i2c_speed;
196 uint8_t i2c_address;
197
198 uint32_t spi_speed;
199 spi_master_mode_t spi_mode;
200 spi_master_chip_select_polarity_t cs_polarity;
201
202 uint8_t sel;
203
205
206 // End types group
207// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
213#ifdef __cplusplus
214extern "C"{
215#endif
216
226
236
245
256void pressure4_generic_write ( pressure4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
257
268void pressure4_generic_read ( pressure4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
269
279void pressure4_write_reg_8_bit ( pressure4_t *ctx, uint8_t w_reg, uint8_t w_data );
280
289uint8_t pressure4_read_reg_8_bit ( pressure4_t *ctx, uint8_t r_reg );
290
299
308
317
326
327#ifdef __cplusplus
328}
329#endif
330#endif // _PRESSURE4_H_
331
332 // End public_function group
334
335// ------------------------------------------------------------------------- END
float pressure4_get_pressure(pressure4_t *ctx)
Get pressure function.
void pressure4_write_reg_8_bit(pressure4_t *ctx, uint8_t w_reg, uint8_t w_data)
8 bit writing function.
err_t pressure4_init(pressure4_t *ctx, pressure4_cfg_t *cfg)
Initialization function.
uint8_t pressure4_read_id(pressure4_t *ctx)
Read ID function.
uint8_t pressure4_get_status(pressure4_t *ctx)
Get status function.
void pressure4_generic_write(pressure4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
float pressure4_get_temperature(pressure4_t *ctx)
Get temperature function.
void pressure4_generic_read(pressure4_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t pressure4_read_reg_8_bit(pressure4_t *ctx, uint8_t r_reg)
8 bit reading function.
void pressure4_cfg_setup(pressure4_cfg_t *cfg)
Config Object Initialization function.
void pressure4_default_cfg(pressure4_t *ctx)
Click Default Configuration function.
void(* pressure4_master_io_t)(struct pressure4_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition pressure4.h:140
struct pressure4_s pressure4_t
Click ctx object definition.
Click configuration structure definition.
Definition pressure4.h:185
uint32_t i2c_speed
Definition pressure4.h:195
spi_master_chip_select_polarity_t cs_polarity
Definition pressure4.h:200
pin_name_t sck
Definition pressure4.h:191
spi_master_mode_t spi_mode
Definition pressure4.h:199
pin_name_t mosi
Definition pressure4.h:190
uint32_t spi_speed
Definition pressure4.h:198
uint8_t sel
Definition pressure4.h:202
pin_name_t scl
Definition pressure4.h:187
pin_name_t miso
Definition pressure4.h:189
pin_name_t sda
Definition pressure4.h:188
pin_name_t cs
Definition pressure4.h:192
uint8_t i2c_address
Definition pressure4.h:196
Click ctx object definition.
Definition pressure4.h:146
digital_out_t cs
Definition pressure4.h:148
int16_t dig_p5
Definition pressure4.h:169
float t1_calc_1
Definition pressure4.h:176
int16_t dig_p4
Definition pressure4.h:168
spi_master_t spi
Definition pressure4.h:152
int16_t dig_p6
Definition pressure4.h:170
int16_t dig_p9
Definition pressure4.h:173
int16_t dig_p8
Definition pressure4.h:172
int16_t dig_t3
Definition pressure4.h:163
int16_t dig_t2
Definition pressure4.h:162
float p3_calc_1
Definition pressure4.h:177
uint8_t master_sel
Definition pressure4.h:159
int16_t dig_p3
Definition pressure4.h:167
int16_t dig_p2
Definition pressure4.h:166
i2c_master_t i2c
Definition pressure4.h:151
int16_t dig_p7
Definition pressure4.h:171
pressure4_master_io_t read_f
Definition pressure4.h:158
int32_t t_fine
Definition pressure4.h:175
pressure4_master_io_t write_f
Definition pressure4.h:157
uint16_t dig_p1
Definition pressure4.h:165
uint8_t slave_address
Definition pressure4.h:155
uint16_t dig_t1
Definition pressure4.h:161
pin_name_t chip_select
Definition pressure4.h:156