pressure11 2.0.0.0
pressure11.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 PRESSURE11_H
36#define PRESSURE11_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 PRESSURE11_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 )
82#define PRESSURE11_MASTER_I2C 0
83#define PRESSURE11_MASTER_SPI 1
90#define PRESSURE11_RETVAL uint8_t
91
92#define PRESSURE11_OK 0x00
93#define PRESSURE11_INIT_ERROR 0xFF
94
95#define DEVICE_ERROR 0x02
96#define DEVICE_OK 0x00
103#define PRESSURE11_I_AM 0xB1
110#define PRESSURE11_REG_INTERRUPT 0x0B
111#define PRESSURE11_REG_THS_P_L 0x0C
112#define PRESSURE11_REG_THS_P_H 0x0D
113#define PRESSURE11_REG_WHO_AM_I 0x0F
114#define PRESSURE11_REG_CTRL_REG1 0x10
115#define PRESSURE11_REG_CTRL_REG2 0x11
116#define PRESSURE11_REG_CTRL_REG3 0x12
117#define PRESSURE11_REG_FIFO_CTRL 0x14
118#define PRESSURE11_REG_REF_P_XL 0x15
119#define PRESSURE11_REG_REF_P_L 0x16
120#define PRESSURE11_REG_REF_P_H 0x17
121#define PRESSURE11_REG_RPDS_L 0x18
122#define PRESSURE11_REG_RPDS_H 0x19
123#define PRESSURE11_REG_RES_CONF 0x1A
124#define PRESSURE11_REG_INT_SOURCE 0x25
125#define PRESSURE11_REG_FIFO_STATUS 0x26
126#define PRESSURE11_REG_STATUS 0x27
127#define PRESSURE11_REG_PRESS_OUT_XL 0x28
128#define PRESSURE11_REG_PRESS_OUT_L 0x29
129#define PRESSURE11_REG_PRESS_OUT_H 0x2A
130#define PRESSURE11_REG_TEMP_OUT_L 0x2B
131#define PRESSURE11_REG_TEMP_OUT_H 0x2C
132#define PRESSURE11_REG_LPFP_RES 0x33
139#define PRESSURE11_CFG_INTERRUPT_AUTORIFP 0x80
140#define PRESSURE11_CFG_INTERRUPT_RESET_ARP 0x40
141#define PRESSURE11_CFG_INTERRUPT_AUTOZERO 0x20
142#define PRESSURE11_CFG_INTERRUPT_RESET_AZ 0x10
143#define PRESSURE11_CFG_INTERRUPT_DIFF_EN 0x08
144#define PRESSURE11_CFG_INTERRUPT_LIR 0x04
145#define PRESSURE11_CFG_INTERRUPT_PLE 0x02
146#define PRESSURE11_CFG_INTERRUPT_PHE 0x01
147#define PRESSURE11_CFG_INTERRUPT_DISABLE_ALL 0x00
154#define PRESSURE11_CTRL_1_ODR_1_HZ 0x10
155#define PRESSURE11_CTRL_1_ODR_10_HZ 0x20
156#define PRESSURE11_CTRL_1_ODR_25_HZ 0x30
157#define PRESSURE11_CTRL_1_ODR_50_HZ 0x40
158#define PRESSURE11_CTRL_1_ODR_75_HZ 0x50
159#define PRESSURE11_CTRL_1_EN_LPFP 0x08
160#define PRESSURE11_CTRL_1_LPFP_CFG 0x04
161#define PRESSURE11_CTRL_1_BDU 0x02
162#define PRESSURE11_CTRL_1_SIM 0x01
163#define PRESSURE11_CTRL_1_DISABLE_ALL 0x00
170#define PRESSURE11_CTRL_2_BOOT 0x80
171#define PRESSURE11_CTRL_2_FIFO_EN 0x40
172#define PRESSURE11_CTRL_2_STOP_ON_FTH 0x20
173#define PRESSURE11_CTRL_2_IF_ADD_INC 0x10
174#define PRESSURE11_CTRL_2_I2C_DIS 0x08
175#define PRESSURE11_CTRL_2_SWRESET 0x04
176#define PRESSURE11_CTRL_2_ONE_SHOT 0x01
177#define PRESSURE11_CTRL_2_DISABLE_ALL 0x00
184#define PRESSURE11_CTRL_3_INT_H_L 0x80
185#define PRESSURE11_CTRL_3_PP_OD 0x40
186#define PRESSURE11_CTRL_3_F_FSS5 0x20
187#define PRESSURE11_CTRL_3_F_FTH 0x10
188#define PRESSURE11_CTRL_3_F_OVR 0x08
189#define PRESSURE11_CTRL_3_DRDY 0x04
190#define PRESSURE11_CTRL_3_INT_PRESS_LOW_OR_HIGH 0x03
191#define PRESSURE11_CTRL_3_INT_PRESS_LOW 0x02
192#define PRESSURE11_CTRL_3_INT_PRESS_HIGH 0x01
193#define PRESSURE11_CTRL_3_DISABLE_ALL 0x00
200#define PRESSURE11_CTRL_FIFO_BYPASS_TO_FIFO_MODE 0xE0
201#define PRESSURE11_CTRL_FIFO_DYNAMIC_STREAM_MODE 0xC0
202#define PRESSURE11_CTRL_FIFO_BYPASS_TO_STREAM_MODE 0x80
203#define PRESSURE11_CTRL_FIFO_STREAM_TO_FIFO_MODE 0x60
204#define PRESSURE11_CTRL_FIFO_STREAM_MODE 0x40
205#define PRESSURE11_CTRL_FIFO_FIFO_MODE 0x20
206#define PRESSURE11_CTRL_FIFO_BYPASS_MODE 0x00
213#define PRESSURE11_INT_SOURCE_BOOT_STATUS 0x80
214#define PRESSURE11_INT_SOURCE_IA 0x04
215#define PRESSURE11_INT_SOURCE_PL 0x02
216#define PRESSURE11_INT_SOURCE_PH 0x01
223#define PRESSURE11_STATUS_FTH_FIFO 0x80
224#define PRESSURE11_STATUS_OVR 0x40
225#define PRESSURE11_STATUS_FIFO_32_UNREAD_SAMPLES 0x20
226#define PRESSURE11_STATUS_FIFO_31_UNREAD_SAMPLES 0x1F
227#define PRESSURE11_STATUS_FIFO_30_UNREAD_SAMPLES 0x1E
228#define PRESSURE11_STATUS_FIFO_29_UNREAD_SAMPLES 0x1D
229#define PRESSURE11_STATUS_FIFO_28_UNREAD_SAMPLES 0x1C
230#define PRESSURE11_STATUS_FIFO_27_UNREAD_SAMPLES 0x1B
231#define PRESSURE11_STATUS_FIFO_26_UNREAD_SAMPLES 0x1A
232#define PRESSURE11_STATUS_FIFO_25_UNREAD_SAMPLES 0x19
233#define PRESSURE11_STATUS_FIFO_24_UNREAD_SAMPLES 0x18
234#define PRESSURE11_STATUS_FIFO_23_UNREAD_SAMPLES 0x17
235#define PRESSURE11_STATUS_FIFO_22_UNREAD_SAMPLES 0x16
236#define PRESSURE11_STATUS_FIFO_21_UNREAD_SAMPLES 0x15
237#define PRESSURE11_STATUS_FIFO_20_UNREAD_SAMPLES 0x14
238#define PRESSURE11_STATUS_FIFO_19_UNREAD_SAMPLES 0x13
239#define PRESSURE11_STATUS_FIFO_18_UNREAD_SAMPLES 0x12
240#define PRESSURE11_STATUS_FIFO_17_UNREAD_SAMPLES 0x11
241#define PRESSURE11_STATUS_FIFO_16_UNREAD_SAMPLES 0x10
242#define PRESSURE11_STATUS_FIFO_15_UNREAD_SAMPLES 0x0F
243#define PRESSURE11_STATUS_FIFO_14_UNREAD_SAMPLES 0x0E
244#define PRESSURE11_STATUS_FIFO_13_UNREAD_SAMPLES 0x0D
245#define PRESSURE11_STATUS_FIFO_12_UNREAD_SAMPLES 0x0C
246#define PRESSURE11_STATUS_FIFO_11_UNREAD_SAMPLES 0x0B
247#define PRESSURE11_STATUS_FIFO_10_UNREAD_SAMPLES 0x0A
248#define PRESSURE11_STATUS_FIFO_9_UNREAD_SAMPLES 0x09
249#define PRESSURE11_STATUS_FIFO_8_UNREAD_SAMPLES 0x08
250#define PRESSURE11_STATUS_FIFO_7_UNREAD_SAMPLES 0x07
251#define PRESSURE11_STATUS_FIFO_6_UNREAD_SAMPLES 0x06
252#define PRESSURE11_STATUS_FIFO_5_UNREAD_SAMPLES 0x05
253#define PRESSURE11_STATUS_FIFO_4_UNREAD_SAMPLES 0x04
254#define PRESSURE11_STATUS_FIFO_3_UNREAD_SAMPLES 0x03
255#define PRESSURE11_STATUS_FIFO_2_UNREAD_SAMPLES 0x02
256#define PRESSURE11_STATUS_FIFO_1_UNREAD_SAMPLES 0x01
257#define PRESSURE11_STATUS_FIFO_EMPTY 0x00
264#define PRESSURE11_STATUS_T_OR 0x20
265#define PRESSURE11_STATUS_P_OR 0x10
266#define PRESSURE11_STATUS_T_DA 0x02
267#define PRESSURE11_STATUS_P_DA 0x01
274#define PRESSURE11_DEVICE_SLAVE_ADDR_GND 0x5C
275#define PRESSURE11_DEVICE_SLAVE_ADDR_VDD 0x5D
278// End group macro
279// --------------------------------------------------------------- PUBLIC TYPES
288typedef uint8_t pressure11_select_t;
289
293typedef void ( *pressure11_master_io_t )( struct pressure11_s*, uint8_t, uint8_t*, uint8_t );
294
298typedef struct pressure11_s
299{
300 // Output pins
301
302 digital_out_t cs;
303
304 // Input pins
305
306 digital_in_t int_pin;
307
308 // Modules
309
310 i2c_master_t i2c;
311 spi_master_t spi;
312
313 // ctx variable
314
316 pin_name_t chip_select;
317
321
323
327typedef struct
328{
329 // Communication gpio pins
330
331 pin_name_t scl;
332 pin_name_t sda;
333 pin_name_t miso;
334 pin_name_t mosi;
335 pin_name_t sck;
336 pin_name_t cs;
337
338 // Additional gpio pins
339
340 pin_name_t int_pin;
341
342 // static variable
343
344 uint32_t i2c_speed;
345 uint8_t i2c_address;
346
347 uint32_t spi_speed;
348 spi_master_mode_t spi_mode;
349 spi_master_chip_select_polarity_t cs_polarity;
350
352
354
355 // End types group
356// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
362#ifdef __cplusplus
363extern "C"{
364#endif
365
375
385
396void pressure11_generic_write ( pressure11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
397
408void pressure11_generic_read ( pressure11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
409
418
427
436
445
446#ifdef __cplusplus
447}
448#endif
449#endif // _PRESSURE11_H_
450
451 // End public_function group
453
454// ------------------------------------------------------------------------- END
#define PRESSURE11_RETVAL
Definition pressure11.h:90
float pressure11_get_pressure(pressure11_t *ctx)
Functions for pressure reading.
uint8_t pressure11_get_interrupt(pressure11_t *ctx)
Functions for read int pin.
uint8_t pressure11_check_id(pressure11_t *ctx)
Functions for cheking commuincation with the chip and checking its ID.
float pressure11_get_temperature(pressure11_t *ctx)
Functions for temperature reading.
void pressure11_generic_read(pressure11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void pressure11_cfg_setup(pressure11_cfg_t *cfg)
Config Object Initialization function.
void pressure11_generic_write(pressure11_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
PRESSURE11_RETVAL pressure11_init(pressure11_t *ctx, pressure11_cfg_t *cfg)
Initialization function.
void(* pressure11_master_io_t)(struct pressure11_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition pressure11.h:293
struct pressure11_s pressure11_t
Click ctx object definition.
uint8_t pressure11_select_t
Communication type.
Definition pressure11.h:288
Click configuration structure definition.
Definition pressure11.h:328
uint32_t i2c_speed
Definition pressure11.h:344
spi_master_chip_select_polarity_t cs_polarity
Definition pressure11.h:349
pin_name_t sck
Definition pressure11.h:335
spi_master_mode_t spi_mode
Definition pressure11.h:348
pin_name_t mosi
Definition pressure11.h:334
uint32_t spi_speed
Definition pressure11.h:347
pin_name_t scl
Definition pressure11.h:331
pin_name_t int_pin
Definition pressure11.h:340
pin_name_t miso
Definition pressure11.h:333
pin_name_t sda
Definition pressure11.h:332
pressure11_select_t sel
Definition pressure11.h:351
pin_name_t cs
Definition pressure11.h:336
uint8_t i2c_address
Definition pressure11.h:345
Click ctx object definition.
Definition pressure11.h:299
digital_out_t cs
Definition pressure11.h:302
spi_master_t spi
Definition pressure11.h:311
pressure11_master_io_t read_f
Definition pressure11.h:319
digital_in_t int_pin
Definition pressure11.h:306
i2c_master_t i2c
Definition pressure11.h:310
pressure11_select_t master_sel
Definition pressure11.h:320
uint8_t slave_address
Definition pressure11.h:315
pin_name_t chip_select
Definition pressure11.h:316
pressure11_master_io_t write_f
Definition pressure11.h:318