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 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define ALTITUDE_SLAVE_ADDR 0x60
53 
59 #define ALTITUDE_REG_STATUS 0x0
60 #define ALTITUDE_REG_OUT_P_MSB 0x1
61 #define ALTITUDE_REG_OUT_P_CSB 0x2
62 #define ALTITUDE_REG_OUT_P_LSB 0x3
63 #define ALTITUDE_REG_OUT_T_MSB 0x4
64 #define ALTITUDE_REG_OUT_T_LSB 0x5
65 #define ALTITUDE_REG_DR_STATUS 0x6
66 #define ALTITUDE_REG_OUT_P_DELTA_MSB 0x7
67 #define ALTITUDE_REG_OUT_P_DELTA_CSB 0x8
68 #define ALTITUDE_REG_OUT_P_DELTA_LSB 0x9
69 #define ALTITUDE_REG_OUT_T_DELTA_MSB 0xA
70 #define ALTITUDE_REG_OUT_T_DELTA_LSB 0xB
71 #define ALTITUDE_REG_WHO_AM_I 0xC
72 #define ALTITUDE_REG_FIFO_STATUS 0xD
73 #define ALTITUDE_REG_FIFO_DATA 0xE
74 #define ALTITUDE_REG_FIFO_SETUP 0xF
75 #define ALTITUDE_REG_TIME_DLY 0x10
76 #define ALTITUDE_REG_SYSMOD 0x11
77 #define ALTITUDE_REG_INT_SOURCE 0x12
78 #define ALTITUDE_REG_PT_DATA_CFG 0x13
79 #define ALTITUDE_REG_BAR_IN_MSB 0x14
80 #define ALTITUDE_REG_BAR_IN_LSB 0x15
81 #define ALTITUDE_REG_P_TGT_MSB 0x16
82 #define ALTITUDE_REG_P_TGT_LSB 0x17
83 #define ALTITUDE_REG_T_TGT 0x18
84 #define ALTITUDE_REG_P_WND_MSB 0x19
85 #define ALTITUDE_REG_P_WND_LSB 0x1A
86 #define ALTITUDE_REG_T_WND 0x1B
87 #define ALTITUDE_REG_P_MIN_MSB 0x1C
88 #define ALTITUDE_REG_P_MIN_CSB 0x1D
89 #define ALTITUDE_REG_P_MIN_LSB 0x1E
90 #define ALTITUDE_REG_T_MIN_MSB 0x1F
91 #define ALTITUDE_REG_T_MIN_LSB 0x20
92 #define ALTITUDE_REG_P_MAX_MSB 0x21
93 #define ALTITUDE_REG_P_MAX_CSB 0x22
94 #define ALTITUDE_REG_P_MAX_LSB 0x23
95 #define ALTITUDE_REG_T_MAX_MSB 0x24
96 #define ALTITUDE_REG_T_MAX_LSB 0x25
97 #define ALTITUDE_REG_CTRL1 0x26
98 #define ALTITUDE_REG_CTRL2 0x27
99 #define ALTITUDE_REG_CTRL3 0x28
100 #define ALTITUDE_REG_CTRL4 0x29
101 #define ALTITUDE_REG_CTRL5 0x2A
102 #define ALTITUDE_REG_OFF_P 0x2B
103 #define ALTITUDE_REG_OFF_T 0x2C
104 #define ALTITUDE_REG_OFF_H 0x2D
105 
111 #define ALTITUDE_STATUS_FLAG_TDR 0x2
112 #define ALTITUDE_STATUS_FLAG_PDR 0x4
113 #define ALTITUDE_STATUS_FLAG_PTDR 0x8
114 #define ALTITUDE_STATUS_FLAG_TOW 0x20
115 #define ALTITUDE_STATUS_FLAG_POW 0x40
116 #define ALTITUDE_STATUS_FLAG_PTOW 0x80
117 
123 #define ALTITUDE_INT_SOURCE_FLAG_DRDY 0x80
124 #define ALTITUDE_INT_SOURCE_FLAG_FIFO 0x40
125 #define ALTITUDE_INT_SOURCE_FLAG_PW 0x20
126 #define ALTITUDE_INT_SOURCE_FLAG_TW 0x10
127 #define ALTITUDE_INT_SOURCE_FLAG_PTH 0x8
128 #define ALTITUDE_INT_SOURCE_FLAG_TTH 0x4
129 #define ALTITUDE_INT_SOURCE_FLAG_PCHG 0x2
130 #define ALTITUDE_INT_SOURCE_FLAG_TCHG 0x1
131 
142 #define ALTITUDE_CTRL1_SBYB 0x1
143 #define ALTITUDE_CTRL1_OST 0x2
144 #define ALTITUDE_CTRL1_CLR 0x3
145 #define ALTITUDE_CTRL1_RST 0x4
146 #define ALTITUDE_CTRL1_RAW 0x40
147 #define ALTITUDE_CTRL1_ALT 0x80
148 #define ALTITUDE_CTRL1_BAR 0x0
149 
155 #define ALTITUDE_CTRL1_OS1_6MS 0x0
156 #define ALTITUDE_CTRL1_OS2_10MS 0x8
157 #define ALTITUDE_CTRL1_OS4_18MS 0x10
158 #define ALTITUDE_CTRL1_OS8_34MS 0x18
159 #define ALTITUDE_CTRL1_OS16_66MS 0x20
160 #define ALTITUDE_CTRL1_OS32_130MS 0x28
161 #define ALTITUDE_CTRL1_OS64_258MS 0x30
162 #define ALTITUDE_CTRL1_OS128_512MS 0x38
163 
169 #define ALTITUDE_CTRL3_INT1_POL_HIGH 0x20
170 #define ALTITUDE_CTRL3_INT1_OD 0x10
171 #define ALTITUDE_CTRL3_INT2_POL_HIGH 0x2
172 #define ALTITUDE_CTRL3_INT2_OD 0x1
173 
179 #define ALTITUDE_CTRL4_INT_EN_DRDY 0x80
180 #define ALTITUDE_CTRL4_INT_EN_FIFO 0x40
181 #define ALTITUDE_CTRL4_INT_EN_PW 0x20
182 #define ALTITUDE_CTRL4_INT_EN_TW 0x10
183 #define ALTITUDE_CTRL4_INT_EN_PTH 0x8
184 #define ALTITUDE_CTRL4_INT_EN_TTH 0x4
185 #define ALTITUDE_CTRL4_INT_EN_PCHG 0x2
186 #define ALTITUDE_CTRL4_INT_EN_TCHG 0x1
187 #define ALTITUDE_CTRL4_INT_DIS_ALL 0x0
188 
194 #define ALTITUDE_CTRL5_INT1_DRDY 0x80
195 #define ALTITUDE_CTRL5_INT2_DRDY 0x0
196 #define ALTITUDE_CTRL5_INT1_FIFO 0x40
197 #define ALTITUDE_CTRL5_INT2_FIFO 0x0
198 #define ALTITUDE_CTRL5_INT1_PW 0x20
199 #define ALTITUDE_CTRL5_INT2_PW 0x0
200 #define ALTITUDE_CTRL5_INT1_TW 0x10
201 #define ALTITUDE_CTRL5_INT2_TW 0x0
202 #define ALTITUDE_CTRL5_INT1_PTH 0x8
203 #define ALTITUDE_CTRL5_INT2_PTH 0x0
204 #define ALTITUDE_CTRL5_INT1_TTH 0x4
205 #define ALTITUDE_CTRL5_INT2_TTH 0x0
206 #define ALTITUDE_CTRL5_INT1_PCHG 0x2
207 #define ALTITUDE_CTRL5_INT2_PCHG 0x0
208 #define ALTITUDE_CTRL5_INT1_TCHG 0x1
209 #define ALTITUDE_CTRL5_INT2_TCHG 0x0
210 
216 #define ALTITUDE_F_SETUP_FIFO_DISABLE 0x0
217 #define ALTITUDE_F_SETUP_FIFO_CIRCULAR_BUFF 0x40
218 #define ALTITUDE_F_SETUP_FIFO_STOP_MODE 0x80
219 
225 #define ALTITUDE_PT_DATA_DR_EVENT_EN 0x4
226 #define ALTITUDE_PT_DATA_PD_EVENT_EN 0x2
227 #define ALTITUDE_PT_DATA_TD_EVENT_EN 0x1
228 #define ALTITUDE_PT_DATA_ALL_EVENTS_DIS 0x0
229  // End control group
232 
237 #define ALTITUDE_DEVICE_ID 0xC4
238 
244 #define ALTITUDE_NDATA_TRANSFER_MIN 1
245 #define ALTITUDE_NDATA_TRANSFER_MAX 32
246 
252 #define ALTITUDE_MAP_MIKROBUS( cfg, mikrobus ) \
253  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
254  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
255  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_INT ); \
256  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_CS )
257  // End macros group
260 // --------------------------------------------------------------- PUBLIC TYPES
269 typedef enum
270 {
271  ALTITUDE_OK = 0x0,
275 
277 
281 typedef enum
282 {
285 
287 
291 typedef enum
292 {
295 
297 
301 typedef struct
302 {
303  // Interrupt pins.
304  digital_in_t it1;
305  digital_in_t it2;
306 
307  // Module.
308  i2c_master_t i2c;
309 
310  // Module slave address.
311  uint8_t slave_addr;
312 
313 } altitude_t;
314 
318 typedef struct
319 {
320  // Communication gpio pins.
321  pin_name_t scl;
322  pin_name_t sda;
323 
324  // Additional gpio pins.
325  pin_name_t it1;
326  pin_name_t it2;
327 
328  // Configuration variables.
329  uint32_t i2c_speed;
330  uint8_t i2c_addr;
331 
333  // End types group
335 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
341 #ifdef __cplusplus
342 extern "C"{
343 #endif
344 
354 
366 
377 
389 altitude_err_t altitude_generic_single_write( altitude_t *ctx, uint8_t reg_addr, uint8_t data_in );
390 
403 altitude_err_t altitude_generic_multiple_write( altitude_t *ctx, uint8_t reg_addr, uint8_t *data_in, uint8_t n_data );
404 
417 altitude_err_t altitude_generic_multiple_read( altitude_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint8_t n_data );
418 
428 
438 
447 
458 uint8_t altitude_get_drdy_status( altitude_t *ctx, uint8_t flag_mask );
459 
470 uint8_t altitude_get_int_status( altitude_t *ctx, uint8_t flag_mask );
471 
483 
495 
506 
517 
528 
529 #ifdef __cplusplus
530 }
531 #endif
532 #endif // _ALTITUDE_H_
533  // End public_function group
536 
537 // ------------------------------------------------------------------------ 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:283
altitude_cfg_t::it2
pin_name_t it2
Definition: altitude.h:326
ALTITUDE_ERR_INIT_DRV
@ ALTITUDE_ERR_INIT_DRV
Definition: altitude.h:272
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:302
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:294
altitude_cfg_t::it1
pin_name_t it1
Definition: altitude.h:325
altitude_t::it1
digital_in_t it1
Definition: altitude.h:304
altitude_sens_mode_t
altitude_sens_mode_t
Click sensor modes.
Definition: altitude.h:292
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:271
altitude_cfg_t
Click configuration structure definition.
Definition: altitude.h:319
altitude_sw_reset
void altitude_sw_reset(altitude_t *ctx)
Software Reset function.
altitude_cfg_t::scl
pin_name_t scl
Definition: altitude.h:321
altitude_t::it2
digital_in_t it2
Definition: altitude.h:305
ALTITUDE_ERR_ADDR
@ ALTITUDE_ERR_ADDR
Definition: altitude.h:273
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:311
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:329
altitude_t::i2c
i2c_master_t i2c
Definition: altitude.h:308
ALTITUDE_ERR_NDATA
@ ALTITUDE_ERR_NDATA
Definition: altitude.h:274
ALTITUDE_SYSMOD_ACTIVE
@ ALTITUDE_SYSMOD_ACTIVE
Definition: altitude.h:284
ALTITUDE_SENSMOD_BAROMETER
@ ALTITUDE_SENSMOD_BAROMETER
Definition: altitude.h:293
altitude_sys_mode_t
altitude_sys_mode_t
Click system modes.
Definition: altitude.h:282
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:322
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:270
altitude_cfg_t::i2c_addr
uint8_t i2c_addr
Definition: altitude.h:330
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.