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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_in.h"
49 #include "drv_i2c_master.h"
50 
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define ALTITUDE_SLAVE_ADDR 0x60
63 
69 #define ALTITUDE_REG_STATUS 0x0
70 #define ALTITUDE_REG_OUT_P_MSB 0x1
71 #define ALTITUDE_REG_OUT_P_CSB 0x2
72 #define ALTITUDE_REG_OUT_P_LSB 0x3
73 #define ALTITUDE_REG_OUT_T_MSB 0x4
74 #define ALTITUDE_REG_OUT_T_LSB 0x5
75 #define ALTITUDE_REG_DR_STATUS 0x6
76 #define ALTITUDE_REG_OUT_P_DELTA_MSB 0x7
77 #define ALTITUDE_REG_OUT_P_DELTA_CSB 0x8
78 #define ALTITUDE_REG_OUT_P_DELTA_LSB 0x9
79 #define ALTITUDE_REG_OUT_T_DELTA_MSB 0xA
80 #define ALTITUDE_REG_OUT_T_DELTA_LSB 0xB
81 #define ALTITUDE_REG_WHO_AM_I 0xC
82 #define ALTITUDE_REG_FIFO_STATUS 0xD
83 #define ALTITUDE_REG_FIFO_DATA 0xE
84 #define ALTITUDE_REG_FIFO_SETUP 0xF
85 #define ALTITUDE_REG_TIME_DLY 0x10
86 #define ALTITUDE_REG_SYSMOD 0x11
87 #define ALTITUDE_REG_INT_SOURCE 0x12
88 #define ALTITUDE_REG_PT_DATA_CFG 0x13
89 #define ALTITUDE_REG_BAR_IN_MSB 0x14
90 #define ALTITUDE_REG_BAR_IN_LSB 0x15
91 #define ALTITUDE_REG_P_TGT_MSB 0x16
92 #define ALTITUDE_REG_P_TGT_LSB 0x17
93 #define ALTITUDE_REG_T_TGT 0x18
94 #define ALTITUDE_REG_P_WND_MSB 0x19
95 #define ALTITUDE_REG_P_WND_LSB 0x1A
96 #define ALTITUDE_REG_T_WND 0x1B
97 #define ALTITUDE_REG_P_MIN_MSB 0x1C
98 #define ALTITUDE_REG_P_MIN_CSB 0x1D
99 #define ALTITUDE_REG_P_MIN_LSB 0x1E
100 #define ALTITUDE_REG_T_MIN_MSB 0x1F
101 #define ALTITUDE_REG_T_MIN_LSB 0x20
102 #define ALTITUDE_REG_P_MAX_MSB 0x21
103 #define ALTITUDE_REG_P_MAX_CSB 0x22
104 #define ALTITUDE_REG_P_MAX_LSB 0x23
105 #define ALTITUDE_REG_T_MAX_MSB 0x24
106 #define ALTITUDE_REG_T_MAX_LSB 0x25
107 #define ALTITUDE_REG_CTRL1 0x26
108 #define ALTITUDE_REG_CTRL2 0x27
109 #define ALTITUDE_REG_CTRL3 0x28
110 #define ALTITUDE_REG_CTRL4 0x29
111 #define ALTITUDE_REG_CTRL5 0x2A
112 #define ALTITUDE_REG_OFF_P 0x2B
113 #define ALTITUDE_REG_OFF_T 0x2C
114 #define ALTITUDE_REG_OFF_H 0x2D
115 
121 #define ALTITUDE_STATUS_FLAG_TDR 0x2
122 #define ALTITUDE_STATUS_FLAG_PDR 0x4
123 #define ALTITUDE_STATUS_FLAG_PTDR 0x8
124 #define ALTITUDE_STATUS_FLAG_TOW 0x20
125 #define ALTITUDE_STATUS_FLAG_POW 0x40
126 #define ALTITUDE_STATUS_FLAG_PTOW 0x80
127 
133 #define ALTITUDE_INT_SOURCE_FLAG_DRDY 0x80
134 #define ALTITUDE_INT_SOURCE_FLAG_FIFO 0x40
135 #define ALTITUDE_INT_SOURCE_FLAG_PW 0x20
136 #define ALTITUDE_INT_SOURCE_FLAG_TW 0x10
137 #define ALTITUDE_INT_SOURCE_FLAG_PTH 0x8
138 #define ALTITUDE_INT_SOURCE_FLAG_TTH 0x4
139 #define ALTITUDE_INT_SOURCE_FLAG_PCHG 0x2
140 #define ALTITUDE_INT_SOURCE_FLAG_TCHG 0x1
141 
152 #define ALTITUDE_CTRL1_SBYB 0x1
153 #define ALTITUDE_CTRL1_OST 0x2
154 #define ALTITUDE_CTRL1_CLR 0x3
155 #define ALTITUDE_CTRL1_RST 0x4
156 #define ALTITUDE_CTRL1_RAW 0x40
157 #define ALTITUDE_CTRL1_ALT 0x80
158 #define ALTITUDE_CTRL1_BAR 0x0
159 
165 #define ALTITUDE_CTRL1_OS1_6MS 0x0
166 #define ALTITUDE_CTRL1_OS2_10MS 0x8
167 #define ALTITUDE_CTRL1_OS4_18MS 0x10
168 #define ALTITUDE_CTRL1_OS8_34MS 0x18
169 #define ALTITUDE_CTRL1_OS16_66MS 0x20
170 #define ALTITUDE_CTRL1_OS32_130MS 0x28
171 #define ALTITUDE_CTRL1_OS64_258MS 0x30
172 #define ALTITUDE_CTRL1_OS128_512MS 0x38
173 
179 #define ALTITUDE_CTRL3_INT1_POL_HIGH 0x20
180 #define ALTITUDE_CTRL3_INT1_OD 0x10
181 #define ALTITUDE_CTRL3_INT2_POL_HIGH 0x2
182 #define ALTITUDE_CTRL3_INT2_OD 0x1
183 
189 #define ALTITUDE_CTRL4_INT_EN_DRDY 0x80
190 #define ALTITUDE_CTRL4_INT_EN_FIFO 0x40
191 #define ALTITUDE_CTRL4_INT_EN_PW 0x20
192 #define ALTITUDE_CTRL4_INT_EN_TW 0x10
193 #define ALTITUDE_CTRL4_INT_EN_PTH 0x8
194 #define ALTITUDE_CTRL4_INT_EN_TTH 0x4
195 #define ALTITUDE_CTRL4_INT_EN_PCHG 0x2
196 #define ALTITUDE_CTRL4_INT_EN_TCHG 0x1
197 #define ALTITUDE_CTRL4_INT_DIS_ALL 0x0
198 
204 #define ALTITUDE_CTRL5_INT1_DRDY 0x80
205 #define ALTITUDE_CTRL5_INT2_DRDY 0x0
206 #define ALTITUDE_CTRL5_INT1_FIFO 0x40
207 #define ALTITUDE_CTRL5_INT2_FIFO 0x0
208 #define ALTITUDE_CTRL5_INT1_PW 0x20
209 #define ALTITUDE_CTRL5_INT2_PW 0x0
210 #define ALTITUDE_CTRL5_INT1_TW 0x10
211 #define ALTITUDE_CTRL5_INT2_TW 0x0
212 #define ALTITUDE_CTRL5_INT1_PTH 0x8
213 #define ALTITUDE_CTRL5_INT2_PTH 0x0
214 #define ALTITUDE_CTRL5_INT1_TTH 0x4
215 #define ALTITUDE_CTRL5_INT2_TTH 0x0
216 #define ALTITUDE_CTRL5_INT1_PCHG 0x2
217 #define ALTITUDE_CTRL5_INT2_PCHG 0x0
218 #define ALTITUDE_CTRL5_INT1_TCHG 0x1
219 #define ALTITUDE_CTRL5_INT2_TCHG 0x0
220 
226 #define ALTITUDE_F_SETUP_FIFO_DISABLE 0x0
227 #define ALTITUDE_F_SETUP_FIFO_CIRCULAR_BUFF 0x40
228 #define ALTITUDE_F_SETUP_FIFO_STOP_MODE 0x80
229 
235 #define ALTITUDE_PT_DATA_DR_EVENT_EN 0x4
236 #define ALTITUDE_PT_DATA_PD_EVENT_EN 0x2
237 #define ALTITUDE_PT_DATA_TD_EVENT_EN 0x1
238 #define ALTITUDE_PT_DATA_ALL_EVENTS_DIS 0x0
239  // End control group
242 
247 #define ALTITUDE_DEVICE_ID 0xC4
248 
254 #define ALTITUDE_NDATA_TRANSFER_MIN 1
255 #define ALTITUDE_NDATA_TRANSFER_MAX 32
256 
262 #define ALTITUDE_MAP_MIKROBUS( cfg, mikrobus ) \
263  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
264  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
265  cfg.it1 = MIKROBUS( mikrobus, MIKROBUS_INT ); \
266  cfg.it2 = MIKROBUS( mikrobus, MIKROBUS_CS )
267  // End macros group
270 // --------------------------------------------------------------- PUBLIC TYPES
279 typedef enum
280 {
281  ALTITUDE_OK = 0x0,
285 
287 
291 typedef enum
292 {
295 
297 
301 typedef enum
302 {
305 
307 
311 typedef struct
312 {
313  // Interrupt pins.
314  digital_in_t it1;
315  digital_in_t it2;
316 
317  // Module.
318  i2c_master_t i2c;
319 
320  // Module slave address.
321  uint8_t slave_addr;
322 
323 } altitude_t;
324 
328 typedef struct
329 {
330  // Communication gpio pins.
331  pin_name_t scl;
332  pin_name_t sda;
333 
334  // Additional gpio pins.
335  pin_name_t it1;
336  pin_name_t it2;
337 
338  // Configuration variables.
339  uint32_t i2c_speed;
340  uint8_t i2c_addr;
341 
343  // End types group
345 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
351 #ifdef __cplusplus
352 extern "C"{
353 #endif
354 
364 
376 
387 
399 altitude_err_t altitude_generic_single_write( altitude_t *ctx, uint8_t reg_addr, uint8_t data_in );
400 
413 altitude_err_t altitude_generic_multiple_write( altitude_t *ctx, uint8_t reg_addr, uint8_t *data_in, uint8_t n_data );
414 
427 altitude_err_t altitude_generic_multiple_read( altitude_t *ctx, uint8_t reg_addr, uint8_t *data_out, uint8_t n_data );
428 
438 
448 
457 
468 uint8_t altitude_get_drdy_status( altitude_t *ctx, uint8_t flag_mask );
469 
480 uint8_t altitude_get_int_status( altitude_t *ctx, uint8_t flag_mask );
481 
493 
505 
516 
527 
538 
539 #ifdef __cplusplus
540 }
541 #endif
542 #endif // _ALTITUDE_H_
543  // End public_function group
546 
547 // ------------------------------------------------------------------------ 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:293
altitude_cfg_t::it2
pin_name_t it2
Definition: altitude.h:336
ALTITUDE_ERR_INIT_DRV
@ ALTITUDE_ERR_INIT_DRV
Definition: altitude.h:282
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:312
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:304
altitude_cfg_t::it1
pin_name_t it1
Definition: altitude.h:335
altitude_t::it1
digital_in_t it1
Definition: altitude.h:314
altitude_sens_mode_t
altitude_sens_mode_t
Click sensor modes.
Definition: altitude.h:302
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:281
altitude_cfg_t
Click configuration structure definition.
Definition: altitude.h:329
altitude_sw_reset
void altitude_sw_reset(altitude_t *ctx)
Software Reset function.
altitude_cfg_t::scl
pin_name_t scl
Definition: altitude.h:331
altitude_t::it2
digital_in_t it2
Definition: altitude.h:315
ALTITUDE_ERR_ADDR
@ ALTITUDE_ERR_ADDR
Definition: altitude.h:283
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:321
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:339
altitude_t::i2c
i2c_master_t i2c
Definition: altitude.h:318
ALTITUDE_ERR_NDATA
@ ALTITUDE_ERR_NDATA
Definition: altitude.h:284
ALTITUDE_SYSMOD_ACTIVE
@ ALTITUDE_SYSMOD_ACTIVE
Definition: altitude.h:294
ALTITUDE_SENSMOD_BAROMETER
@ ALTITUDE_SENSMOD_BAROMETER
Definition: altitude.h:303
altitude_sys_mode_t
altitude_sys_mode_t
Click system modes.
Definition: altitude.h:292
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:332
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:280
altitude_cfg_t::i2c_addr
uint8_t i2c_addr
Definition: altitude.h:340
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.