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 
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 
56 #include "math.h"
57 #include "string.h"
58 
59 // -------------------------------------------------------------- PUBLIC MACROS
69 #define ALTITUDE3_MAP_MIKROBUS( cfg, mikrobus ) \
70  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
71  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
72 
78 #define ALTITUDE3_RETVAL uint8_t
79 
80 #define ALTITUDE3_OK 0x00
81 #define ALTITUDE3_INIT_ERROR 0xFF
82 
84 #define ALTITUDE3_SLAVE_ADDR 0x63
85 
86 #define ALTITUDE3_LOW_POWER_T_FIRST 0x609C
87 #define ALTITUDE3_LOW_POWER_P_FIRST 0x401A
88 #define ALTITUDE3_NORMAL_T_FIRST 0x6825
89 #define ALTITUDE3_NORMAL_P_FIRST 0x48A3
90 #define ALTITUDE3_LOW_NOISE_T_FIRST 0x70DF
91 #define ALTITUDE3_LOW_NOISE_P_FIRST 0x5059
92 #define ALTITUDE3_ULTRA_LOW_NOISE_T_FIRST 0x7866
93 #define ALTITUDE3_ULTRA_LOW_NOISE_P_FIRST 0x58E0
94 
95 #define ALTITUDE3_OK 0x00
96 #define ALTITUDE3_T_FIRST_ORDER 0x01
97 #define ALTITUDE3_P_FIRST_ORDER 0x02
98 #define ALTITUDE3_INITIALIZED 0x03
99 #define ALTITUDE3_ERROR 0xFF
100  // End group macro
102 // --------------------------------------------------------------- PUBLIC TYPES
108 typedef struct
109 {
110 
111  uint32_t min_delay_us;
112  uint16_t sensor_const[ 4 ];
113  uint32_t p_pa_calib[ 3 ];
114  float lut_lower;
115  float lut_upper;
116  double quadr_factor;
117  uint16_t offst_factor;
118 
120 
121 typedef struct
122 {
123  //Sensor data
124 
125  int8_t temperature;
126  uint32_t pressure;
127  int16_t altitude;
128 
129 } sensor_data_t;
130 
134 typedef struct
135 {
136  // Modules
137 
138  i2c_master_t i2c;
139 
140  // ctx variable
141 
142  uint8_t slave_address;
143 
144  uint8_t update_check;
145 
147 
148 } altitude3_t;
149 
153 typedef struct
154 {
155  // Communication gpio pins
156 
157  pin_name_t scl;
158  pin_name_t sda;
159 
160  // static variable
161 
162  uint32_t i2c_speed;
163  uint8_t i2c_address;
164 
166 
168  // End types group
170 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
171 
177 #ifdef __cplusplus
178 extern "C"{
179 #endif
180 
190 
200 
209 
220 void altitude3_generic_write ( altitude3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
221 
233 void altitude3_generic_read ( altitude3_t *ctx, uint8_t *reg_buf, uint8_t *data_buf, uint8_t len );
234 
245 uint8_t altitude3_measurement_mode ( altitude3_t *ctx, uint16_t mode_cmd );
246 
256 
269 uint8_t altitude3_read_adc_results ( altitude3_t *ctx, uint8_t read_order, int16_t *temperature, uint32_t *pressure );
270 
280 
294 uint8_t altitude3_get_data ( altitude3_t *ctx, uint8_t read_order );
295 
296 #ifdef __cplusplus
297 }
298 #endif
299 #endif // _ALTITUDE3_H_
300  // End public_function group
303 
304 // ------------------------------------------------------------------------- END
altitude3_cfg_t::i2c_address
uint8_t i2c_address
Definition: altitude3.h:163
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:115
altitude3_param_t
Definition: altitude3.h:109
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:78
altitude3_t
Click ctx object definition.
Definition: altitude3.h:135
altitude3_cfg_t::update_check_cfg
uint8_t update_check_cfg
Definition: altitude3.h:165
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:146
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:142
sensor_data_t::pressure
uint32_t pressure
Definition: altitude3.h:126
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:158
altitude3_soft_reset
void altitude3_soft_reset(altitude3_t *ctx)
Software Reset function.
altitude3_cfg_t
Click configuration structure definition.
Definition: altitude3.h:154
sensor_data_t::temperature
int8_t temperature
Definition: altitude3.h:125
altitude3_param_t::min_delay_us
uint32_t min_delay_us
Definition: altitude3.h:111
altitude3_param_t::offst_factor
uint16_t offst_factor
Definition: altitude3.h:117
sensor_data_t::altitude
int16_t altitude
Definition: altitude3.h:127
altitude3_param_t::lut_lower
float lut_lower
Definition: altitude3.h:114
altitude3_cfg_t::scl
pin_name_t scl
Definition: altitude3.h:157
altitude3_param_t::quadr_factor
double quadr_factor
Definition: altitude3.h:116
altitude3_default_cfg
void altitude3_default_cfg(altitude3_t *ctx)
Click Default Configuration function.
sensor_data_t
Definition: altitude3.h:122
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:144
altitude3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: altitude3.h:162
altitude3_t::i2c
i2c_master_t i2c
Definition: altitude3.h:138