pressure10 2.0.0.0
pressure10.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 PRESSURE10_H
36#define PRESSURE10_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 PRESSURE10_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.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
82#define PRESSURE10_MASTER_I2C 0
83#define PRESSURE10_MASTER_SPI 1
90#define PRESSURE10_RETVAL uint8_t
91
92#define PRESSURE10_OK 0x00
93#define PRESSURE10_INIT_ERROR 0xFF
100#define DEVICE_OK 0
101#define DEVICE_ERROR 1
108#define I2C_COMMUNICATION 1
109#define SPI_COMMUNICATION 0
116#define PRESSURE10_DEVICE_SLAVE_ADDR_0 0x48
117#define PRESSURE10_DEVICE_SLAVE_ADDR_1 0x49
124#define PRESSURE10_REG_WHO_I_AM 0x00
125#define PRESSURE10_REG_INFORMATION 0x01
126#define PRESSURE10_REG_FIFO_STATUS 0x02
127#define PRESSURE10_REG_STATUS 0x03
128#define PRESSURE10_REG_PRESSURE_OUT_LOW 0x04
129#define PRESSURE10_REG_PRESSURE_OUT_MID 0x05
130#define PRESSURE10_REG_PRESSURE_OUT_HIGH 0x06
131#define PRESSURE10_REG_TEMP_OUT_LOW 0x09
132#define PRESSURE10_REG_TEMP_OUT_HIGH 0x0A
133#define PRESSURE10_REG_DRDY_PIN_CRTL 0x0D
134#define PRESSURE10_REG_CONTROL_1 0x0E
135#define PRESSURE10_REG_CONTROL_2 0x0F
136#define PRESSURE10_REG_ACTION_CONTROL_1 0x10
137#define PRESSURE10_REG_ACTION_CONTROL_2 0x11
138#define PRESSURE10_REG_FIFO_CONTROL 0x12
139#define PRESSURE10_REG_AVERAGE_CONTROL 0x13
140#define PRESSURE10_REG_I2C_DISABLE 0x15
141#define PRESSURE10_REG_PRODUCT_NUMBER 0x1C
142#define PRESSURE10_CMD_PRESS_DETECTION 0x20
143#define PRESSURE10_CMD_TEMP_DETECTION 0x22
144#define PRESSURE10_CMD_SW_RESET 0x26
145#define PRESSURE10_CMD_PT_DETECTION 0x29
152#define PRESSURE10_DEF_WHO_I_AM 0x49
153#define PRESSURE10_DEF_INFO 0x31
154#define PRESSURE10_DEF_PRODUCT_NUM 0x40
161#define PRESSURE10_CTRLDRDY_AFEV_ENABLE 0x80
162#define PRESSURE10_CTRLDRDY_AFEV_DISABLE 0x00
163#define PRESSURE10_CTRLDRDY_ATDR_ENABLE 0x10
164#define PRESSURE10_CTRLDRDY_ATDR_DISABLE 0x00
165#define PRESSURE10_CTRLDRDY_APOR_ENABLE 0x04
166#define PRESSURE10_CTRLDRDY_APOR_DISABLE 0x00
167#define PRESSURE10_CTRLDRDY_APDY_ENABLE 0x01
168#define PRESSURE10_CTRLDRDY_APDY_DISABLE 0x00
175#define PRESSURE10_CTRL1_PDRP_LOW_ACTIVE 0x00
176#define PRESSURE10_CTRL1_PDRP_HIGH_ACTIVE 0x10
177#define PRESSURE10_CTRL1_PTAP_ULTRA_LOW_PWR 0x00
178#define PRESSURE10_CTRL1_PTAP_LOW_PWR 0x01
179#define PRESSURE10_CTRL1_PTAP_HIGH_ACCURACY 0x02
180#define PRESSURE10_CTRL1_PTAP_ULTRA_ACCURACY 0x03
187#define PRESSURE10_CTRL2_TMES_DISABLE 0x00
188#define PRESSURE10_CTRL2_TMES_ENABLE 0x80
189#define PRESSURE10_CTRL2_PMES_DISABLE 0x00
190#define PRESSURE10_CTRL2_PMES_ENABLE 0x20
191#define PRESSURE10_CTRL2_ODR_1HZ 0x00
192#define PRESSURE10_CTRL2_ODR_10HZ 0x04
193#define PRESSURE10_CTRL2_ODR_100HZ 0x08
194#define PRESSURE10_CTRL2_ODR_200HZ 0x0C
195#define PRESSURE10_CTRL2_MODE_REG_ACTION 0x00
196#define PRESSURE10_CTRL2_MODE_CONT_MEAS 0x01
197#define PRESSURE10_CTRL2_MODE_CMD_ACTION 0x02
204#define PRESSURE10_ACTRL1_TEMP_NO_MEAS 0x00
205#define PRESSURE10_ACTRL1_TEMP_MEAS 0x08
206#define PRESSURE10_ACTRL1_PRESS_NO_MEAS 0x00
207#define PRESSURE10_ACTRL1_PRESS_MEAS 0x02
214#define PRESSURE10_ACTRL2_SW_RESET_NONE 0x00
215#define PRESSURE10_ACTRL2_SW_RESET_EXECUTE 0x80
222#define PRESSURE10_AVCTRL_TFRQ_ONLY_FIRST_TIME 0x00
223#define PRESSURE10_AVCTRL_TFRQ_ONLY_EVERY_64_TIMES 0x08
224#define PRESSURE10_AVCTRL_TFRQ_ONLY_EVERY_32_TIMES 0x10
225#define PRESSURE10_AVCTRL_TFRQ_ONLY_EVERY_16_TIMES 0x18
226#define PRESSURE10_AVCTRL_TFRQ_ONLY_EVERY_8_TIMES 0x20
227#define PRESSURE10_AVCTRL_TFRQ_ONLY_EVERY_4_TIMES 0x28
228#define PRESSURE10_AVCTRL_TFRQ_ONLY_EVERY_2_TIMES 0x30
229#define PRESSURE10_AVCTRL_TFRQ_EVERY_TIME 0x38
230#define PRESSURE10_AVCTRL_AVG_NONE 0x00
231#define PRESSURE10_AVCTRL_AVG_X2 0x01
232#define PRESSURE10_AVCTRL_AVG_X4 0x02
233#define PRESSURE10_AVCTRL_AVG_X8 0x03
234#define PRESSURE10_AVCTRL_AVG_X16 0x04
235#define PRESSURE10_AVCTRL_AVG_X32 0x05
236#define PRESSURE10_AVCTRL_AVG_X64 0x06
237#define PRESSURE10_AVCTRL_AVG_X128 0x07
240 // End group macro
241// --------------------------------------------------------------- PUBLIC TYPES
247typedef struct
248{
249 uint8_t busy;
250 uint8_t temp_meas;
251 uint8_t data_over;
252 uint8_t press_meas;
254
255
259typedef uint8_t pressure10_select_t;
260
264typedef void ( *pressure10_master_io_t )( struct pressure10_s*, uint8_t, uint8_t*, uint8_t );
265
269typedef struct pressure10_s
270{
271 // Output pins
272
273 digital_out_t cs;
274
275 // Input pins
276
277 digital_in_t rdy;
278
279 // Modules
280
281 i2c_master_t i2c;
282 spi_master_t spi;
283
284 // ctx variable
285
287 pin_name_t chip_select;
291
293
297typedef struct
298{
299 // Communication gpio pins
300
301 pin_name_t scl;
302 pin_name_t sda;
303 pin_name_t miso;
304 pin_name_t mosi;
305 pin_name_t sck;
306 pin_name_t cs;
307
308 // Additional gpio pins
309
310 pin_name_t rdy;
311
312 // static variable
313
314 uint32_t i2c_speed;
315 uint8_t i2c_address;
316
317 uint32_t spi_speed;
318 spi_master_mode_t spi_mode;
319 spi_master_chip_select_polarity_t cs_polarity;
320
322
324
325 // End types group
326
327// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
333#ifdef __cplusplus
334extern "C"{
335#endif
336
346
355
364
375void pressure10_generic_write ( pressure10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
376
387void pressure10_generic_read ( pressure10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
388
394void pressure10_send_cmd ( pressure10_t *ctx, uint8_t cmd );
395
404
412
420
428
436void pressure10_control_cfg ( pressure10_t *ctx, uint8_t ctrl_reg, uint8_t wr_data );
437
446
447#ifdef __cplusplus
448}
449#endif
450#endif // _PRESSURE10_H_
451
452 // End public_function group
454
455// ------------------------------------------------------------------------- END
#define PRESSURE10_RETVAL
Definition pressure10.h:90
void pressure10_generic_write(pressure10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t pressure10_check_communication(pressure10_t *ctx)
Check communication.
float pressure10_get_pressure(pressure10_t *ctx)
Get Pressure data in mBar.
void pressure10_cfg_setup(pressure10_cfg_t *cfg)
Config Object Initialization function.
void pressure10_default_cfg(pressure10_t *ctx)
Click Default Configuration function.
PRESSURE10_RETVAL pressure10_init(pressure10_t *ctx, pressure10_cfg_t *cfg)
Initialization function.
float pressure10_get_temperature(pressure10_t *ctx)
Get Temperature data in C.
void pressure10_control_cfg(pressure10_t *ctx, uint8_t ctrl_reg, uint8_t wr_data)
Set the configuration in the control registers.
void pressure10_send_cmd(pressure10_t *ctx, uint8_t cmd)
Send command.
void pressure10_generic_read(pressure10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t pressure10_get_drdy_pin(pressure10_t *ctx)
Get DRDY pin state.
void pressure10_get_status(pressure10_t *ctx, pressure10_status_t *status_obj)
Get status function.
uint8_t pressure10_select_t
Communication type.
Definition pressure10.h:259
struct pressure10_s pressure10_t
Click ctx object definition.
void(* pressure10_master_io_t)(struct pressure10_s *, uint8_t, uint8_t *, uint8_t)
Master Input/Output type.
Definition pressure10.h:264
Click configuration structure definition.
Definition pressure10.h:298
pressure10_select_t sel
Definition pressure10.h:321
uint32_t i2c_speed
Definition pressure10.h:314
spi_master_chip_select_polarity_t cs_polarity
Definition pressure10.h:319
pin_name_t sck
Definition pressure10.h:305
spi_master_mode_t spi_mode
Definition pressure10.h:318
pin_name_t mosi
Definition pressure10.h:304
uint32_t spi_speed
Definition pressure10.h:317
pin_name_t scl
Definition pressure10.h:301
pin_name_t rdy
Definition pressure10.h:310
pin_name_t miso
Definition pressure10.h:303
pin_name_t sda
Definition pressure10.h:302
pin_name_t cs
Definition pressure10.h:306
uint8_t i2c_address
Definition pressure10.h:315
Click ctx object definition.
Definition pressure10.h:270
digital_out_t cs
Definition pressure10.h:273
pressure10_select_t master_sel
Definition pressure10.h:290
spi_master_t spi
Definition pressure10.h:282
pressure10_master_io_t read_f
Definition pressure10.h:289
pressure10_master_io_t write_f
Definition pressure10.h:288
i2c_master_t i2c
Definition pressure10.h:281
uint8_t slave_address
Definition pressure10.h:286
pin_name_t chip_select
Definition pressure10.h:287
digital_in_t rdy
Definition pressure10.h:277
Definition pressure10.h:248
uint8_t press_meas
Definition pressure10.h:252
uint8_t data_over
Definition pressure10.h:251
uint8_t temp_meas
Definition pressure10.h:250
uint8_t busy
Definition pressure10.h:249