altitude3  2.0.0.0
altitude3.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 ALTITUDE3_H
36 #define ALTITUDE3_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_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 #include "math.h"
53 #include "string.h"
54 
55 // -------------------------------------------------------------- PUBLIC MACROS
65 #define ALTITUDE3_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
68 
74 #define ALTITUDE3_RETVAL uint8_t
75 
76 #define ALTITUDE3_OK 0x00
77 #define ALTITUDE3_INIT_ERROR 0xFF
78 
80 #define ALTITUDE3_SLAVE_ADDR 0x63
81 
82 #define ALTITUDE3_LOW_POWER_T_FIRST 0x609C
83 #define ALTITUDE3_LOW_POWER_P_FIRST 0x401A
84 #define ALTITUDE3_NORMAL_T_FIRST 0x6825
85 #define ALTITUDE3_NORMAL_P_FIRST 0x48A3
86 #define ALTITUDE3_LOW_NOISE_T_FIRST 0x70DF
87 #define ALTITUDE3_LOW_NOISE_P_FIRST 0x5059
88 #define ALTITUDE3_ULTRA_LOW_NOISE_T_FIRST 0x7866
89 #define ALTITUDE3_ULTRA_LOW_NOISE_P_FIRST 0x58E0
90 
91 #define ALTITUDE3_OK 0x00
92 #define ALTITUDE3_T_FIRST_ORDER 0x01
93 #define ALTITUDE3_P_FIRST_ORDER 0x02
94 #define ALTITUDE3_INITIALIZED 0x03
95 #define ALTITUDE3_ERROR 0xFF
96  // End group macro
98 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106 
107  uint32_t min_delay_us;
108  uint16_t sensor_const[ 4 ];
109  uint32_t p_pa_calib[ 3 ];
110  float lut_lower;
111  float lut_upper;
112  double quadr_factor;
113  uint16_t offst_factor;
114 
116 
117 typedef struct
118 {
119  //Sensor data
120 
121  int8_t temperature;
122  uint32_t pressure;
123  int16_t altitude;
124 
125 } sensor_data_t;
126 
130 typedef struct
131 {
132  // Modules
133 
134  i2c_master_t i2c;
135 
136  // ctx variable
137 
138  uint8_t slave_address;
139 
140  uint8_t update_check;
141 
143 
144 } altitude3_t;
145 
149 typedef struct
150 {
151  // Communication gpio pins
152 
153  pin_name_t scl;
154  pin_name_t sda;
155 
156  // static variable
157 
158  uint32_t i2c_speed;
159  uint8_t i2c_address;
160 
162 
164  // End types group
166 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
167 
173 #ifdef __cplusplus
174 extern "C"{
175 #endif
176 
186 
196 
205 
216 void altitude3_generic_write ( altitude3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
217 
229 void altitude3_generic_read ( altitude3_t *ctx, uint8_t *reg_buf, uint8_t *data_buf, uint8_t len );
230 
241 uint8_t altitude3_measurement_mode ( altitude3_t *ctx, uint16_t mode_cmd );
242 
252 
265 uint8_t altitude3_read_adc_results ( altitude3_t *ctx, uint8_t read_order, int16_t *temperature, uint32_t *pressure );
266 
276 
290 uint8_t altitude3_get_data ( altitude3_t *ctx, uint8_t read_order );
291 
292 #ifdef __cplusplus
293 }
294 #endif
295 #endif // _ALTITUDE3_H_
296  // End public_function group
299 
300 // ------------------------------------------------------------------------- END
altitude3_cfg_t::i2c_address
uint8_t i2c_address
Definition: altitude3.h:159
altitude3_read_adc_results
uint8_t altitude3_read_adc_results(altitude3_t *ctx, uint8_t read_order, int16_t *temperature, uint32_t *pressure)
Read AD Conversion function.
altitude3_generic_write
void altitude3_generic_write(altitude3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
altitude3_param_t::lut_upper
float lut_upper
Definition: altitude3.h:111
altitude3_param_t
Definition: altitude3.h:105
altitude3_get_data
uint8_t altitude3_get_data(altitude3_t *ctx, uint8_t read_order)
Get Data function.
altitude3_cfg_setup
void altitude3_cfg_setup(altitude3_cfg_t *cfg)
Config Object Initialization function.
ALTITUDE3_RETVAL
#define ALTITUDE3_RETVAL
Definition: altitude3.h:74
altitude3_t
Click ctx object definition.
Definition: altitude3.h:131
altitude3_cfg_t::update_check_cfg
uint8_t update_check_cfg
Definition: altitude3.h:161
altitude3_measurement_mode
uint8_t altitude3_measurement_mode(altitude3_t *ctx, uint16_t mode_cmd)
Set Measurement Mode function.
altitude3_t::sens_data
sensor_data_t sens_data
Definition: altitude3.h:142
altitude3_generic_read
void altitude3_generic_read(altitude3_t *ctx, uint8_t *reg_buf, uint8_t *data_buf, uint8_t len)
Generic read function.
altitude3_t::slave_address
uint8_t slave_address
Definition: altitude3.h:138
sensor_data_t::pressure
uint32_t pressure
Definition: altitude3.h:122
altitude3_init_cfg
void altitude3_init_cfg(altitude3_t *ctx, altitude3_param_t *s)
Init configuration function.
altitude3_cfg_t::sda
pin_name_t sda
Definition: altitude3.h:154
altitude3_soft_reset
void altitude3_soft_reset(altitude3_t *ctx)
Software Reset function.
altitude3_cfg_t
Click configuration structure definition.
Definition: altitude3.h:150
sensor_data_t::temperature
int8_t temperature
Definition: altitude3.h:121
altitude3_param_t::min_delay_us
uint32_t min_delay_us
Definition: altitude3.h:107
altitude3_param_t::offst_factor
uint16_t offst_factor
Definition: altitude3.h:113
sensor_data_t::altitude
int16_t altitude
Definition: altitude3.h:123
altitude3_param_t::lut_lower
float lut_lower
Definition: altitude3.h:110
altitude3_cfg_t::scl
pin_name_t scl
Definition: altitude3.h:153
altitude3_param_t::quadr_factor
double quadr_factor
Definition: altitude3.h:112
altitude3_default_cfg
void altitude3_default_cfg(altitude3_t *ctx)
Click Default Configuration function.
sensor_data_t
Definition: altitude3.h:118
altitude3_init
ALTITUDE3_RETVAL altitude3_init(altitude3_t *ctx, altitude3_cfg_t *cfg)
Initialization function.
altitude3_t::update_check
uint8_t update_check
Definition: altitude3.h:140
altitude3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: altitude3.h:158
altitude3_t::i2c
i2c_master_t i2c
Definition: altitude3.h:134