altitude2 2.0.0.0
altitude2.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 ALTITUDE2_H
36#define ALTITUDE2_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#include "drv_spi_master.h"
56#include "math.h"
57
58// -------------------------------------------------------------- PUBLIC MACROS
69#define ALTITUDE2_MAP_MIKROBUS( cfg, mikrobus ) \
70 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
71 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
72 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
73 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
74 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
75 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
76
83#define ALTITUDE2_MASTER_I2C 0
84#define ALTITUDE2_MASTER_SPI 1
91#define ALTITUDE2_OK 0
92#define ALTITUDE2_ERROR -1
99#define ALTITUDE2_DEVICE_ADDR_0 0x76
100#define ALTITUDE2_DEVICE_ADDR_1 0x77
107#define ALTITUDE2_RATIO_256 0x00
108#define ALTITUDE2_RATIO_512 0x01
109#define ALTITUDE2_RATIO_1024 0x02
110#define ALTITUDE2_RATIO_2048 0x03
111#define ALTITUDE2_RATIO_4096 0x04
118#define ALTITUDE2_MANUFACTURER_RESERVED 0x00
119#define ALTITUDE2_C1_SENS 0x01
120#define ALTITUDE2_C2_OFF 0x02
121#define ALTITUDE2_C3_TCS 0x03
122#define ALTITUDE2_C4_TCO 0x04
123#define ALTITUDE2_C5_TREF 0x05
124#define ALTITUDE2_C6_TEMPSENS 0x06
125#define ALTITUDE2_CRC 0x07
128 // End group macro
129// --------------------------------------------------------------- PUBLIC TYPES
138typedef uint8_t altitude2_select_t;
139
143typedef void ( *altitude2_master_in_t )( struct altitude2_s*, uint8_t );
144typedef void ( *altitude2_master_out_t )( struct altitude2_s*, uint8_t, uint8_t*, uint8_t );
145
149typedef struct altitude2_s
150{
151 // Modules
152 i2c_master_t i2c;
153 spi_master_t spi;
154
155 // ctx variable
157 pin_name_t chip_select;
161
163 uint8_t ratio_temp;
164 uint8_t ratio_press;
165 uint16_t data_prom[ 6 ];
166
168
172typedef struct
173{
174 // Communication gpio pins
175 pin_name_t scl;
176 pin_name_t sda;
177 pin_name_t miso;
178 pin_name_t mosi;
179 pin_name_t sck;
180 pin_name_t cs;
181
182 // static variable
183 uint32_t i2c_speed;
184 uint8_t i2c_address;
185 uint32_t spi_speed;
186 spi_master_mode_t spi_mode;
187 spi_master_chip_select_polarity_t cs_polarity;
188
190
192
193 // End types group
194// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
200#ifdef __cplusplus
201extern "C"{
202#endif
203
213
222
232uint8_t altitude2_read_prom ( altitude2_t *ctx, uint8_t select_data, uint16_t *data_out );
233
241
251uint8_t altitude2_set_ratio( altitude2_t *ctx, uint8_t temp_ratio, uint8_t press_ratio );
252
265void altitude2_read_data( altitude2_t *ctx, float *temp_data, float *press_data, float *altitude_data );
266
267#ifdef __cplusplus
268}
269#endif
270#endif // _ALTITUDE2_H_
271
272 // End public_function group
274
275// ------------------------------------------------------------------------- END
uint8_t altitude2_read_prom(altitude2_t *ctx, uint8_t select_data, uint16_t *data_out)
Calibration data read function.
uint8_t altitude2_set_ratio(altitude2_t *ctx, uint8_t temp_ratio, uint8_t press_ratio)
Set ratio function.
void altitude2_read_data(altitude2_t *ctx, float *temp_data, float *press_data, float *altitude_data)
Data read function.
void altitude2_reset(altitude2_t *ctx)
Reset function.
void altitude2_cfg_setup(altitude2_cfg_t *cfg)
Config Object Initialization function.
err_t altitude2_init(altitude2_t *ctx, altitude2_cfg_t *cfg)
Initialization function.
struct altitude2_s altitude2_t
Click ctx object definition.
uint8_t altitude2_select_t
Communication type.
Definition altitude2.h:138
void(* altitude2_master_out_t)(struct altitude2_s *, uint8_t, uint8_t *, uint8_t)
Definition altitude2.h:144
void(* altitude2_master_in_t)(struct altitude2_s *, uint8_t)
Master Input/Output type.
Definition altitude2.h:143
Click configuration structure definition.
Definition altitude2.h:173
uint32_t i2c_speed
Definition altitude2.h:183
altitude2_select_t sel
Definition altitude2.h:189
spi_master_chip_select_polarity_t cs_polarity
Definition altitude2.h:187
pin_name_t sck
Definition altitude2.h:179
spi_master_mode_t spi_mode
Definition altitude2.h:186
pin_name_t mosi
Definition altitude2.h:178
uint32_t spi_speed
Definition altitude2.h:185
pin_name_t scl
Definition altitude2.h:175
pin_name_t miso
Definition altitude2.h:177
pin_name_t sda
Definition altitude2.h:176
pin_name_t cs
Definition altitude2.h:180
uint8_t i2c_address
Definition altitude2.h:184
Click ctx object definition.
Definition altitude2.h:150
altitude2_master_out_t send_comm_resp_f
Definition altitude2.h:159
spi_master_t spi
Definition altitude2.h:153
altitude2_select_t master_sel
Definition altitude2.h:160
uint8_t select_driver
Definition altitude2.h:162
altitude2_master_in_t send_comm_f
Definition altitude2.h:158
i2c_master_t i2c
Definition altitude2.h:152
uint8_t ratio_temp
Definition altitude2.h:163
uint8_t slave_address
Definition altitude2.h:156
pin_name_t chip_select
Definition altitude2.h:157
uint8_t ratio_press
Definition altitude2.h:164
uint16_t data_prom[6]
Definition altitude2.h:165