altitude  2.0.0.0
altitude.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 _ALTITUDE_H_
36 #define _ALTITUDE_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_in.h"
53 #include "drv_i2c_master.h"
54 
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define ALTITUDE_SLAVE_ADDR 0x60
67 
73 #define ALTITUDE_REG_STATUS 0x0
74 #define ALTITUDE_REG_OUT_P_MSB 0x1
75 #define ALTITUDE_REG_OUT_P_CSB 0x2
76 #define ALTITUDE_REG_OUT_P_LSB 0x3
77 #define ALTITUDE_REG_OUT_T_MSB 0x4
78 #define ALTITUDE_REG_OUT_T_LSB 0x5
79 #define ALTITUDE_REG_DR_STATUS 0x6
80 #define ALTITUDE_REG_OUT_P_DELTA_MSB 0x7
81 #define ALTITUDE_REG_OUT_P_DELTA_CSB 0x8
82 #define ALTITUDE_REG_OUT_P_DELTA_LSB 0x9
83 #define ALTITUDE_REG_OUT_T_DELTA_MSB 0xA
84 #define ALTITUDE_REG_OUT_T_DELTA_LSB 0xB
85 #define ALTITUDE_REG_WHO_AM_I 0xC
86 #define ALTITUDE_REG_FIFO_STATUS 0xD
87 #define ALTITUDE_REG_FIFO_DATA 0xE
88 #define ALTITUDE_REG_FIFO_SETUP 0xF
89 #define ALTITUDE_REG_TIME_DLY 0x10
90 #define ALTITUDE_REG_SYSMOD 0x11
91 #define ALTITUDE_REG_INT_SOURCE 0x12
92 #define ALTITUDE_REG_PT_DATA_CFG 0x13
93 #define ALTITUDE_REG_BAR_IN_MSB 0x14
94 #define ALTITUDE_REG_BAR_IN_LSB 0x15
95 #define ALTITUDE_REG_P_TGT_MSB 0x16
96 #define ALTITUDE_REG_P_TGT_LSB 0x17
97 #define ALTITUDE_REG_T_TGT 0x18
98 #define ALTITUDE_REG_P_WND_MSB 0x19
99 #define ALTITUDE_REG_P_WND_LSB 0x1A
100 #define ALTITUDE_REG_T_WND 0x1B
101 #define ALTITUDE_REG_P_MIN_MSB 0x1C
102 #define ALTITUDE_REG_P_MIN_CSB 0x1D
103 #define ALTITUDE_REG_P_MIN_LSB 0x1E
104 #define ALTITUDE_REG_T_MIN_MSB 0x1F
105 #define ALTITUDE_REG_T_MIN_LSB 0x20
106 #define ALTITUDE_REG_P_MAX_MSB 0x21
107 #define ALTITUDE_REG_P_MAX_CSB 0x22
108 #define ALTITUDE_REG_P_MAX_LSB 0x23
109 #define ALTITUDE_REG_T_MAX_MSB 0x24
110 #define ALTITUDE_REG_T_MAX_LSB 0x25
111 #define ALTITUDE_REG_CTRL1 0x26
112 #define ALTITUDE_REG_CTRL2 0x27
113 #define ALTITUDE_REG_CTRL3 0x28
114 #define ALTITUDE_REG_CTRL4 0x29
115 #define ALTITUDE_REG_CTRL5 0x2A
116 #define ALTITUDE_REG_OFF_P 0x2B
117 #define ALTITUDE_REG_OFF_T 0x2C
118 #define ALTITUDE_REG_OFF_H 0x2D
119 
125 #define ALTITUDE_STATUS_FLAG_TDR 0x2
126 #define ALTITUDE_STATUS_FLAG_PDR 0x4
127 #define ALTITUDE_STATUS_FLAG_PTDR 0x8
128 #define ALTITUDE_STATUS_FLAG_TOW 0x20
129 #define ALTITUDE_STATUS_FLAG_POW 0x40
130 #define ALTITUDE_STATUS_FLAG_PTOW 0x80
131 
137 #define ALTITUDE_INT_SOURCE_FLAG_DRDY 0x80
138 #define ALTITUDE_INT_SOURCE_FLAG_FIFO 0x40
139 #define ALTITUDE_INT_SOURCE_FLAG_PW 0x20
140 #define ALTITUDE_INT_SOURCE_FLAG_TW 0x10
141 #define ALTITUDE_INT_SOURCE_FLAG_PTH 0x8
142 #define ALTITUDE_INT_SOURCE_FLAG_TTH 0x4
143 #define ALTITUDE_INT_SOURCE_FLAG_PCHG 0x2
144 #define ALTITUDE_INT_SOURCE_FLAG_TCHG 0x1
145 
156 #define ALTITUDE_CTRL1_SBYB 0x1
157 #define ALTITUDE_CTRL1_OST 0x2
158 #define ALTITUDE_CTRL1_CLR 0x3
159 #define ALTITUDE_CTRL1_RST 0x4
160 #define ALTITUDE_CTRL1_RAW 0x40
161 #define ALTITUDE_CTRL1_ALT 0x80
162 #define ALTITUDE_CTRL1_BAR 0x0
163 
169 #define ALTITUDE_CTRL1_OS1_6MS 0x0
170 #define ALTITUDE_CTRL1_OS2_10MS 0x8
171 #define ALTITUDE_CTRL1_OS4_18MS 0x10
172 #define ALTITUDE_CTRL1_OS8_34MS 0x18
173 #define ALTITUDE_CTRL1_OS16_66MS 0x20
174 #define ALTITUDE_CTRL1_OS32_130MS 0x28
175 #define ALTITUDE_CTRL1_OS64_258MS 0x30
176 #define ALTITUDE_CTRL1_OS128_512MS 0x38
177 
183 #define ALTITUDE_CTRL3_INT1_POL_HIGH 0x20
184 #define ALTITUDE_CTRL3_INT1_OD 0x10
185 #define ALTITUDE_CTRL3_INT2_POL_HIGH 0x2
186 #define ALTITUDE_CTRL3_INT2_OD 0x1
187 
193 #define ALTITUDE_CTRL4_INT_EN_DRDY 0x80
194 #define ALTITUDE_CTRL4_INT_EN_FIFO 0x40
195 #define ALTITUDE_CTRL4_INT_EN_PW 0x20
196 #define ALTITUDE_CTRL4_INT_EN_TW 0x10
197 #define ALTITUDE_CTRL4_INT_EN_PTH 0x8
198 #define ALTITUDE_CTRL4_INT_EN_TTH 0x4
199 #define ALTITUDE_CTRL4_INT_EN_PCHG 0x2
200 #define ALTITUDE_CTRL4_INT_EN_TCHG 0x1
201 #define ALTITUDE_CTRL4_INT_DIS_ALL 0x0
202 
208 #define ALTITUDE_CTRL5_INT1_DRDY 0x80
209 #define ALTITUDE_CTRL5_INT2_DRDY 0x0
210 #define ALTITUDE_CTRL5_INT1_FIFO 0x40
211 #define ALTITUDE_CTRL5_INT2_FIFO 0x0
212 #define ALTITUDE_CTRL5_INT1_PW 0x20
213 #define ALTITUDE_CTRL5_INT2_PW 0x0
214 #define ALTITUDE_CTRL5_INT1_TW 0x10
215 #define ALTITUDE_CTRL5_INT2_TW 0x0
216 #define ALTITUDE_CTRL5_INT1_PTH 0x8
217 #define ALTITUDE_CTRL5_INT2_PTH 0x0
218 #define ALTITUDE_CTRL5_INT1_TTH 0x4
219 #define ALTITUDE_CTRL5_INT2_TTH 0x0
220 #define ALTITUDE_CTRL5_INT1_PCHG 0x2
221 #define ALTITUDE_CTRL5_INT2_PCHG 0x0
222 #define ALTITUDE_CTRL5_INT1_TCHG 0x1
223 #define ALTITUDE_CTRL5_INT2_TCHG 0x0
224 
230 #define ALTITUDE_F_SETUP_FIFO_DISABLE 0x0
231 #define ALTITUDE_F_SETUP_FIFO_CIRCULAR_BUFF 0x40
232 #define ALTITUDE_F_SETUP_FIFO_STOP_MODE 0x80
233 
239 #define ALTITUDE_PT_DATA_DR_EVENT_EN 0x4
240 #define ALTITUDE_PT_DATA_PD_EVENT_EN 0x2
241 #define ALTITUDE_PT_DATA_TD_EVENT_EN 0x1
242 #define ALTITUDE_PT_DATA_ALL_EVENTS_DIS 0x0
243  // End control group
246 
251 #define ALTITUDE_DEVICE_ID 0xC4
252 
258 #define ALTITUDE_NDATA_TRANSFER_MIN 1
259 #define ALTITUDE_NDATA_TRANSFER_MAX 32
260 
266 #define ALTITUDE_MAP_MIKROBUS( cfg, mikrobus ) \
267  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
268  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
269  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_INT ); \
270  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_CS )
271  // End macros group
274 // --------------------------------------------------------------- PUBLIC TYPES
283 typedef enum
284 {
285  ALTITUDE_OK = 0x0,
289 
291 
295 typedef enum
296 {
299 
301 
305 typedef enum
306 {
309 
311 
315 typedef struct
316 {
317  // Interrupt pins.
318  digital_in_t it1;
319  digital_in_t it2;
320 
321  // Module.
322  i2c_master_t i2c;
323 
324  // Module slave address.
325  uint8_t slave_addr;
326 
327 } altitude_t;
328 
332 typedef struct
333 {
334  // Communication gpio pins.
335  pin_name_t scl;
336  pin_name_t sda;
337 
338  // Additional gpio pins.
339  pin_name_t it1;
340  pin_name_t it2;
341 
342  // Configuration variables.
343  uint32_t i2c_speed;
344  uint8_t i2c_addr;
345 
347  // End types group
349 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
355 #ifdef __cplusplus
356 extern "C"{
357 #endif
358 
368 
380 
391 
403 altitude_err_t altitude_generic_single_write( altitude_t *ctx, uint8_t reg_addr, uint8_t data_in );
404 
417 altitude_err_t altitude_generic_multiple_write( altitude_t *ctx, uint8_t reg_addr, uint8_t *data_in, uint8_t n_data );
418 
431 altitude_err_t altitude_generic_multiple_read( altitude_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint8_t n_data );
432 
442 
452 
461 
472 uint8_t altitude_get_drdy_status( altitude_t *ctx, uint8_t flag_mask );
473 
484 uint8_t altitude_get_int_status( altitude_t *ctx, uint8_t flag_mask );
485 
497 
509 
520 
531 
542 
543 #ifdef __cplusplus
544 }
545 #endif
546 #endif // _ALTITUDE_H_
547  // End public_function group
550 
551 // ------------------------------------------------------------------------ END
altitude_get_int1_pin
uint8_t altitude_get_int1_pin(altitude_t *ctx)
INT1 Pin Get function.
ALTITUDE_SYSMOD_STANDBY
@ ALTITUDE_SYSMOD_STANDBY
Definition: altitude.h:297
altitude_cfg_t::it2
pin_name_t it2
Definition: altitude.h:340
ALTITUDE_ERR_INIT_DRV
@ ALTITUDE_ERR_INIT_DRV
Definition: altitude.h:286
altitude_generic_single_write
altitude_err_t altitude_generic_single_write(altitude_t *ctx, uint8_t reg_addr, uint8_t data_in)
Generic Single Write function.
altitude_t
Click contex object definition.
Definition: altitude.h:316
altitude_cfg_setup
void altitude_cfg_setup(altitude_cfg_t *cfg)
Configuration Object Setup function.
altitude_set_system_mode
void altitude_set_system_mode(altitude_t *ctx, altitude_sys_mode_t mode)
System Mode Set function.
ALTITUDE_SENSMOD_ALTIMETER
@ ALTITUDE_SENSMOD_ALTIMETER
Definition: altitude.h:308
altitude_cfg_t::it1
pin_name_t it1
Definition: altitude.h:339
altitude_t::it1
digital_in_t it1
Definition: altitude.h:318
altitude_sens_mode_t
altitude_sens_mode_t
Click sensor modes.
Definition: altitude.h:306
altitude_get_pressure
float altitude_get_pressure(altitude_t *ctx)
Pressure Get function.
altitude_init
altitude_err_t altitude_init(altitude_t *ctx, altitude_cfg_t *cfg)
Click Initialization function.
ALTITUDE_OK
@ ALTITUDE_OK
Definition: altitude.h:285
altitude_cfg_t
Click configuration structure definition.
Definition: altitude.h:333
altitude_sw_reset
void altitude_sw_reset(altitude_t *ctx)
Software Reset function.
altitude_cfg_t::scl
pin_name_t scl
Definition: altitude.h:335
altitude_t::it2
digital_in_t it2
Definition: altitude.h:319
ALTITUDE_ERR_ADDR
@ ALTITUDE_ERR_ADDR
Definition: altitude.h:287
altitude_set_sensor_mode
void altitude_set_sensor_mode(altitude_t *ctx, altitude_sens_mode_t mode)
Sensor Mode Set function.
altitude_get_int2_pin
uint8_t altitude_get_int2_pin(altitude_t *ctx)
INT2 Pin Get function.
altitude_t::slave_addr
uint8_t slave_addr
Definition: altitude.h:325
altitude_default_cfg
void altitude_default_cfg(altitude_t *ctx)
Click Default Configuration function.
altitude_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: altitude.h:343
altitude_t::i2c
i2c_master_t i2c
Definition: altitude.h:322
ALTITUDE_ERR_NDATA
@ ALTITUDE_ERR_NDATA
Definition: altitude.h:288
ALTITUDE_SYSMOD_ACTIVE
@ ALTITUDE_SYSMOD_ACTIVE
Definition: altitude.h:298
ALTITUDE_SENSMOD_BAROMETER
@ ALTITUDE_SENSMOD_BAROMETER
Definition: altitude.h:307
altitude_sys_mode_t
altitude_sys_mode_t
Click system modes.
Definition: altitude.h:296
altitude_generic_multiple_write
altitude_err_t altitude_generic_multiple_write(altitude_t *ctx, uint8_t reg_addr, uint8_t *data_in, uint8_t n_data)
Generic Mutiple Write function.
altitude_get_drdy_status
uint8_t altitude_get_drdy_status(altitude_t *ctx, uint8_t flag_mask)
Data Ready Status Get function.
altitude_generic_multiple_read
altitude_err_t altitude_generic_multiple_read(altitude_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint8_t n_data)
Generic Multiple Read function.
altitude_cfg_t::sda
pin_name_t sda
Definition: altitude.h:336
altitude_get_temperature
float altitude_get_temperature(altitude_t *ctx)
Temperature Get function.
altitude_err_t
altitude_err_t
Click error codes.
Definition: altitude.h:284
altitude_cfg_t::i2c_addr
uint8_t i2c_addr
Definition: altitude.h:344
altitude_get_altitude
float altitude_get_altitude(altitude_t *ctx)
Altitude Get function.
altitude_get_int_status
uint8_t altitude_get_int_status(altitude_t *ctx, uint8_t flag_mask)
Interrupt Status Get function.