pressure5 2.0.0.0
pressure5.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 PRESSURE5_H
36#define PRESSURE5_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 PRESSURE5_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
83#define PRESSURE5_MASTER_I2C 0
84#define PRESSURE5_MASTER_SPI 1
91#define PRESSURE5_RETVAL uint8_t
92
93#define PRESSURE5_OK 0x00
94#define PRESSURE5_INIT_ERROR 0xFF
101#define PRESSURE5_REG_DEVICE_ID 0x00
102#define PRESSURE5_REG_ERROR 0x02
103#define PRESSURE5_REG_PRESSURE_DATA_0 0x04
104#define PRESSURE5_REG_PRESSURE_DATA_1 0x05
105#define PRESSURE5_REG_PRESSURE_DATA_2 0x06
106#define PRESSURE5_REG_TEMPERATURE_DATA_0 0x07
107#define PRESSURE5_REG_TEMPERATURE_DATA_1 0x08
108#define PRESSURE5_REG_TEMPERATURE_DATA_2 0x09
109#define PRESSURE5_REG_SENSOR_TIME_0 0x0C
110#define PRESSURE5_REG_SENSOR_TIME_1 0x0D
111#define PRESSURE5_REG_SENSOR_TIME_2 0x0E
112#define PRESSURE5_REG_EVENT 0x10
113#define PRESSURE5_REG_INT_STATUS 0x11
114#define PRESSURE5_REG_FIFO_LENGTH 0x13
115#define PRESSURE5_REG_FIFO_DATA 0x14
116#define PRESSURE5_REG_FIFO_WATERMARK_0 0x15
117#define PRESSURE5_REG_FIFO_WATERMARK_1 0x16
118#define PRESSURE5_REG_FIFO_CONFIG_1 0x17
119#define PRESSURE5_REG_FIFO_CONFIG_2 0x18
120#define PRESSURE5_REG_INT_CTRL 0x19
121#define PRESSURE5_REG_IF_CONFIG 0x1A
122#define PRESSURE5_REG_POWER_CTRL 0x1B
123#define PRESSURE5_REG_OSR 0x1C
124#define PRESSURE5_REG_ODR 0x1D
125#define PRESSURE5_REG_CONFIGURATION 0x1F
126#define PRESSURE5_REG_COMMAND 0x7E
133#define PRESSURE5_FCFG_FIFO_ENABLE 0x01
134#define PRESSURE5_FCFG_FIFO_DISABLE 0x00
135#define PRESSURE5_FCFG_FIFO_STOP_ON_FULL_ENABLE 0x02
136#define PRESSURE5_FCFG_FIFO_STOP_ON_FULL_DISABLE 0x00
137#define PRESSURE5_FCFG_FIFO_TIME_ENABLE 0x04
138#define PRESSURE5_FCFG_FIFO_TIME_DISABLE 0x00
139#define PRESSURE5_FCFG_FIFO_PRESSURE_STORE_ENABLE 0x08
140#define PRESSURE5_FCFG_FIFO_PRESSURE_STORE_DISABLE 0x00
141#define PRESSURE5_FCFG_FIFO_TEMP_STORE_ENABLE 0x10
142#define PRESSURE5_FCFG_FIFO_TEMP_STORE_DISABLE 0x00
149#define PRESSURE5_INTCFG_INT_OUTPUT_PUSH_PULL 0x00
150#define PRESSURE5_INTCFG_INT_OUTPUT_OPEN_DRAIN 0x01
151#define PRESSURE5_INTCFG_INT_LEVEL_ACTIVE_HIGH 0x02
152#define PRESSURE5_INTCFG_INT_LEVEL_ACTIVE_LOW 0x00
153#define PRESSURE5_INTCFG_INT_LATCH_ENABLE 0x04
154#define PRESSURE5_INTCFG_INT_LATCH_DISABLE 0x00
155#define PRESSURE5_INTCFG_FIFO_WTM_ENABLE 0x08
156#define PRESSURE5_INTCFG_FIFO_WTM_DISABLE 0x00
157#define PRESSURE5_INTCFG_FIFO_FULL_ENABLE 0x10
158#define PRESSURE5_INTCFG_FIFO_FULL_DISABLE 0x00
159#define PRESSURE5_INTCFG_DATA_READY_ENABLE 0x20
160#define PRESSURE5_INTCFG_DATA_READY_DISABLE 0x00
167#define PRESSURE5_IFCFG_SPI_4_WIRE 0x00
168#define PRESSURE5_IFCFG_SPI_3_WIRE 0x01
169#define PRESSURE5_IFCFG_I2C_WATCHDOG_ENABLE 0x02
170#define PRESSURE5_IFCFG_I2C_WATCHDOG_DISABLE 0x00
171#define PRESSURE5_IFCFG_I2C_WATCHDOG_SHORT_1p25ms 0x00
172#define PRESSURE5_IFCFG_I2C_WATCHDOG_LONG_40ms 0x04
179#define PRESSURE5_PCTRL_PRESSURE_SENSOR_DISABLE 0x00
180#define PRESSURE5_PCTRL_PRESSURE_SENSOR_ENABLE 0x01
181#define PRESSURE5_PCTRL_TEMP_SENSOR_DISABLE 0x00
182#define PRESSURE5_PCTRL_TEMP_SENSOR_ENABLE 0x02
183#define PRESSURE5_PCTRL_MODE_SLEEP 0x00
184#define PRESSURE5_PCTRL_MODE_FORCED 0x10
185#define PRESSURE5_PCTRL_MODE_NORMAL 0x30
192#define PRESSURE5_OSR_PRESSURE_x1 0x00
193#define PRESSURE5_OSR_PRESSURE_x2 0x01
194#define PRESSURE5_OSR_PRESSURE_x4 0x02
195#define PRESSURE5_OSR_PRESSURE_x8 0x03
196#define PRESSURE5_OSR_PRESSURE_x16 0x04
197#define PRESSURE5_OSR_PRESSURE_x32 0x05
198#define PRESSURE5_OSR_TEMP_x1 0x00 >> 1
199#define PRESSURE5_OSR_TEMP_x2 0x10 >> 1
200#define PRESSURE5_OSR_TEMP_x4 0x20 >> 1
201#define PRESSURE5_OSR_TEMP_x8 0x30 >> 1
202#define PRESSURE5_OSR_TEMP_x16 0x40 >> 1
203#define PRESSURE5_OSR_TEMP_x32 0x50 >> 1
210#define PRESSURE5_ODR_200 0x00
211#define PRESSURE5_ODR_100 0x01
212#define PRESSURE5_ODR_50 0x02
213#define PRESSURE5_ODR_25 0x03
214#define PRESSURE5_ODR_12p5 0x04
215#define PRESSURE5_ODR_6p25 0x05
216#define PRESSURE5_ODR_3p1 0x06
217#define PRESSURE5_ODR_1p5 0x07
218#define PRESSURE5_ODR_0p75 0x08
219#define PRESSURE5_ODR_0p39 0x09
220#define PRESSURE5_ODR_0p2 0x0A
221#define PRESSURE5_ODR_0p1 0x0B
222#define PRESSURE5_ODR_0p05 0x0C
223#define PRESSURE5_ODR_0p02 0x0D
224#define PRESSURE5_ODR_0p01 0x0E
225#define PRESSURE5_ODR_0p006 0x0F
226#define PRESSURE5_ODR_0p003 0x10
227#define PRESSURE5_ODR_0p0015 0x11
234#define PRESSURE5_CFG_FILTER_COEFF_0 0x00
235#define PRESSURE5_CFG_FILTER_COEFF_1 0x01 << 1
236#define PRESSURE5_CFG_FILTER_COEFF_3 0x02 << 1
237#define PRESSURE5_CFG_FILTER_COEFF_7 0x03 << 1
238#define PRESSURE5_CFG_FILTER_COEFF_15 0x04 << 1
239#define PRESSURE5_CFG_FILTER_COEFF_31 0x05 << 1
240#define PRESSURE5_CFG_FILTER_COEFF_63 0x06 << 1
241#define PRESSURE5_CFG_FILTER_COEFF_127 0x07 << 1
248#define PRESSURE5_CMD_EXTMODE_EN_MIDDLE 0x34
249#define PRESSURE5_CMD_FIFO_FLUSH 0xB0
250#define PRESSURE5_CMD_SOFTWARE_RESET 0xB6
257#define PRESSURE5_DEVICE_SLAVE_ADDR_GND 0x76
258#define PRESSURE5_DEVICE_SLAVE_ADDR_VCC 0x77
265#define PRESSURE5_TEMPERATURE_RAW_DATA 0x07
266#define PRESSURE5_PRESSURE_RAW_DATA 0x04
273#define PRESSURE5_DEVICE_ID 0x50
276 // End group macro
277// --------------------------------------------------------------- PUBLIC TYPES
286typedef uint8_t pressure5_select_t;
287
291typedef void ( *pressure5_master_io_t )( struct pressure5_s*, uint8_t, uint8_t*, uint8_t );
292
296typedef struct pressure5_s
297{
298 // Output pins
299
300 digital_out_t cs;
301
302 // Input pins
303
304 digital_in_t int_pin;
305
306 // Modules
307
308 i2c_master_t i2c;
309 spi_master_t spi;
310
311 // ctx variable
312
314 pin_name_t chip_select;
318
320
324typedef struct
325{
326 // Communication gpio pins
327
328 pin_name_t scl;
329 pin_name_t sda;
330 pin_name_t miso;
331 pin_name_t mosi;
332 pin_name_t sck;
333 pin_name_t cs;
334
335 // Additional gpio pins
336
337 pin_name_t int_pin;
338
339 // static variable
340
341 uint32_t i2c_speed;
342 uint8_t i2c_address;
343
344 uint32_t spi_speed;
345 spi_master_mode_t spi_mode;
346 spi_master_chip_select_polarity_t cs_polarity;
347
349
351
352typedef struct
353{
354 uint16_t t1;
355 uint16_t t2;
356 int8_t t3;
357
358 int16_t p1;
359 int16_t p2;
360 int8_t p3;
361 int8_t p4;
362 uint16_t p5;
363 uint16_t p6;
364 int8_t p7;
365 int8_t p8;
366 int16_t p9;
367 int8_t p10;
368 int8_t p11;
369
371
372
373typedef struct
374{
375 float t1;
376 float t2;
377 float t3;
378
379 float p1;
380 float p2;
381 float p3;
382 float p4;
383 float p5;
384 float p6;
385 float p7;
386 float p8;
387 float p9;
388 float p10;
389 float p11;
390
392
393 // End types group
394
395// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
401#ifdef __cplusplus
402extern "C"{
403#endif
404
414
423
432
442void pressure5_generic_write ( pressure5_t *ctx, uint8_t reg, uint8_t reg_data);
443
452uint8_t pressure5_generic_read ( pressure5_t *ctx, uint8_t reg );
464void pressure5_read ( pressure5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
490uint32_t pressure5_get_raw_data ( pressure5_t *ctx, uint8_t data_addr );
521
522
523
524
525#ifdef __cplusplus
526}
527#endif
528#endif // _PRESSURE5_H_
529
530 // End public_function group
532
533// ------------------------------------------------------------------------- END
#define PRESSURE5_RETVAL
Definition pressure5.h:91
PRESSURE5_RETVAL pressure5_init(pressure5_t *ctx, pressure5_cfg_t *cfg)
Initialization function.
void pressure5_generic_write(pressure5_t *ctx, uint8_t reg, uint8_t reg_data)
Generic write function.
void pressure5_update_coefficient(pressure5_t *ctx)
Update calibration coefficients.
void pressure5_cfg_setup(pressure5_cfg_t *cfg)
Config Object Initialization function.
void pressure5_read(pressure5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Function for read more bytes from register.
uint8_t pressure5_get_interrupt_state(pressure5_t *ctx)
Get Interrupt pin state.
uint32_t pressure5_get_raw_data(pressure5_t *ctx, uint8_t data_addr)
Get (Temperature or Pressure) Raw data.
float pressure5_get_temperature_data(pressure5_t *ctx)
Get Temperature data in C.
uint8_t pressure5_generic_read(pressure5_t *ctx, uint8_t reg)
Generic read function.
void pressure5_software_reset(pressure5_t *ctx)
Software Reset.
void pressure5_default_cfg(pressure5_t *ctx)
Click Default Configuration function.
float pressure5_get_pressure_data(pressure5_t *ctx)
Get Pressure data in mBar.
struct pressure5_s pressure5_t
Click ctx object definition.
void(* pressure5_master_io_t)(struct pressure5_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition pressure5.h:291
uint8_t pressure5_select_t
Communication type.
Definition pressure5.h:286
Click configuration structure definition.
Definition pressure5.h:325
pressure5_select_t sel
Definition pressure5.h:348
uint32_t i2c_speed
Definition pressure5.h:341
spi_master_chip_select_polarity_t cs_polarity
Definition pressure5.h:346
pin_name_t sck
Definition pressure5.h:332
spi_master_mode_t spi_mode
Definition pressure5.h:345
pin_name_t mosi
Definition pressure5.h:331
uint32_t spi_speed
Definition pressure5.h:344
pin_name_t scl
Definition pressure5.h:328
pin_name_t int_pin
Definition pressure5.h:337
pin_name_t miso
Definition pressure5.h:330
pin_name_t sda
Definition pressure5.h:329
pin_name_t cs
Definition pressure5.h:333
uint8_t i2c_address
Definition pressure5.h:342
Definition pressure5.h:353
uint16_t t2
Definition pressure5.h:355
int8_t p4
Definition pressure5.h:361
int8_t p3
Definition pressure5.h:360
int16_t p9
Definition pressure5.h:366
int16_t p2
Definition pressure5.h:359
int8_t p11
Definition pressure5.h:368
int8_t p7
Definition pressure5.h:364
int16_t p1
Definition pressure5.h:358
uint16_t t1
Definition pressure5.h:354
uint16_t p6
Definition pressure5.h:363
int8_t p8
Definition pressure5.h:365
int8_t t3
Definition pressure5.h:356
int8_t p10
Definition pressure5.h:367
uint16_t p5
Definition pressure5.h:362
Definition pressure5.h:374
float p3
Definition pressure5.h:381
float p5
Definition pressure5.h:383
float p1
Definition pressure5.h:379
float p11
Definition pressure5.h:389
float p8
Definition pressure5.h:386
float p7
Definition pressure5.h:385
float t3
Definition pressure5.h:377
float p9
Definition pressure5.h:387
float p6
Definition pressure5.h:384
float t2
Definition pressure5.h:376
float t1
Definition pressure5.h:375
float p4
Definition pressure5.h:382
float p2
Definition pressure5.h:380
float p10
Definition pressure5.h:388
Click ctx object definition.
Definition pressure5.h:297
digital_out_t cs
Definition pressure5.h:300
spi_master_t spi
Definition pressure5.h:309
pressure5_select_t master_sel
Definition pressure5.h:317
digital_in_t int_pin
Definition pressure5.h:304
i2c_master_t i2c
Definition pressure5.h:308
pressure5_master_io_t write_f
Definition pressure5.h:315
uint8_t slave_address
Definition pressure5.h:313
pressure5_master_io_t read_f
Definition pressure5.h:316
pin_name_t chip_select
Definition pressure5.h:314