altitude4 2.0.0.0
altitude4.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 ALTITUDE4_H
36#define ALTITUDE4_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_i2c_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
53#define ALTITUDE4_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
62#define ALTITUDE4_RETVAL uint8_t
63
64#define ALTITUDE4_OK 0x00
65#define ALTITUDE4_INIT_ERROR 0xFF
72#define ALTITUDE4_SLAVE_ADDRESS 0x27
73
74#define ALTITUDE4_START_CMD_MODE 0xA9
75#define ALTITUDE4_EXIT_CMD_MODE 0xA8
76#define ALTITUDE4_INC_MEM_PAGE_CNT 0x5E
77#define ALTITUDE4_CREATE_MEM_PAGE_CHECKSUM 0xAA
78#define ALTITUDE4_SENS_DATA 0xAC
82#define FRNDINT( x ) ( ( double ) ( long ) ( x ) )
83 // End group macro
85// --------------------------------------------------------------- PUBLIC TYPES
94 typedef struct
95 {
96 float pressure;
98 float altitude;
99
101
105typedef struct
106{
107 // Modules
108
109 i2c_master_t i2c;
110
111 // ctx variable
112
114
116
120typedef struct
121{
122 // Communication gpio pins
123
124 pin_name_t scl;
125 pin_name_t sda;
126
127 // static variable
128
129 uint32_t i2c_speed;
130 uint8_t i2c_address;
131
133
137union both
138{
139 struct flt
140 {
141 unsigned char mant[ 2 ];
142 unsigned hmant : 7;
143 unsigned exp : 8;
144 unsigned sign : 1;
145
147
148 double fl;
149};
150 // End types group
152// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153
159#ifdef __cplusplus
160extern "C"{
161#endif
162
172
181
193void altitude4_generic_read ( altitude4_t *ctx, uint8_t reg, uint8_t *r_buf, uint8_t len );
194
205void altitude4_generic_write ( altitude4_t *ctx, uint8_t reg, uint8_t *w_buf, uint8_t len );
206
217
218#ifdef __cplusplus
219}
220#endif
221#endif // _ALTITUDE4_H_
222 // End public_function group
225
226// ------------------------------------------------------------------------- END
#define ALTITUDE4_RETVAL
Definition: altitude4.h:62
void altitude4_generic_write(altitude4_t *ctx, uint8_t reg, uint8_t *w_buf, uint8_t len)
Generic write function.
void altitude4_cfg_setup(altitude4_cfg_t *cfg)
Config Object Initialization function.
void altitude4_generic_read(altitude4_t *ctx, uint8_t reg, uint8_t *r_buf, uint8_t len)
Generic read function.
uint8_t altitude4_read_sensor(altitude4_t *ctx, altitude4_sensor_t *sens_data)
Read sensor function.
ALTITUDE4_RETVAL altitude4_init(altitude4_t *ctx, altitude4_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition: altitude4.h:121
uint32_t i2c_speed
Definition: altitude4.h:129
pin_name_t scl
Definition: altitude4.h:124
pin_name_t sda
Definition: altitude4.h:125
uint8_t i2c_address
Definition: altitude4.h:130
Sensor object definition.
Definition: altitude4.h:95
float altitude
Definition: altitude4.h:98
float pressure
Definition: altitude4.h:96
float temperature
Definition: altitude4.h:97
Click ctx object definition.
Definition: altitude4.h:106
i2c_master_t i2c
Definition: altitude4.h:109
uint8_t slave_address
Definition: altitude4.h:113
Definition: altitude4.h:140
unsigned sign
Definition: altitude4.h:144
unsigned hmant
Definition: altitude4.h:142
unsigned char mant[2]
Definition: altitude4.h:141
unsigned exp
Definition: altitude4.h:143
Floating point union definition.
Definition: altitude4.h:138
double fl
Definition: altitude4.h:148
struct both::flt flt