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 
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 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define ALTITUDE4_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
70 
76 #define ALTITUDE4_RETVAL uint8_t
77 
78 #define ALTITUDE4_OK 0x00
79 #define ALTITUDE4_INIT_ERROR 0xFF
80 
86 #define ALTITUDE4_SLAVE_ADDRESS 0x27
87 
88 #define ALTITUDE4_START_CMD_MODE 0xA9
89 #define ALTITUDE4_EXIT_CMD_MODE 0xA8
90 #define ALTITUDE4_INC_MEM_PAGE_CNT 0x5E
91 #define ALTITUDE4_CREATE_MEM_PAGE_CHECKSUM 0xAA
92 #define ALTITUDE4_SENS_DATA 0xAC
93 
96 #define FRNDINT( x ) ( ( double ) ( long ) ( x ) )
97  // End group macro
99 // --------------------------------------------------------------- PUBLIC TYPES
108  typedef struct
109  {
110  float pressure;
111  float temperature;
112  float altitude;
113 
115 
119 typedef struct
120 {
121  // Modules
122 
123  i2c_master_t i2c;
124 
125  // ctx variable
126 
127  uint8_t slave_address;
128 
129 } altitude4_t;
130 
134 typedef struct
135 {
136  // Communication gpio pins
137 
138  pin_name_t scl;
139  pin_name_t sda;
140 
141  // static variable
142 
143  uint32_t i2c_speed;
144  uint8_t i2c_address;
145 
147 
151 union both
152 {
153  struct flt
154  {
155  unsigned char mant[ 2 ];
156  unsigned hmant : 7;
157  unsigned exp : 8;
158  unsigned sign : 1;
159 
160  } flt;
161 
162  double fl;
163 };
164  // End types group
166 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
167 
173 #ifdef __cplusplus
174 extern "C"{
175 #endif
176 
186 
195 
207 void altitude4_generic_read ( altitude4_t *ctx, uint8_t reg, uint8_t *r_buf, uint8_t len );
208 
219 void altitude4_generic_write ( altitude4_t *ctx, uint8_t reg, uint8_t *w_buf, uint8_t len );
220 
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 #endif // _ALTITUDE4_H_
236  // End public_function group
239 
240 // ------------------------------------------------------------------------- END
both::flt::mant
unsigned char mant[2]
Definition: altitude4.h:155
altitude4_read_sensor
uint8_t altitude4_read_sensor(altitude4_t *ctx, altitude4_sensor_t *sens_data)
Read sensor function.
altitude4_sensor_t::pressure
float pressure
Definition: altitude4.h:110
altitude4_cfg_t::i2c_address
uint8_t i2c_address
Definition: altitude4.h:144
altitude4_sensor_t::altitude
float altitude
Definition: altitude4.h:112
altitude4_t
Click ctx object definition.
Definition: altitude4.h:120
both::flt::sign
unsigned sign
Definition: altitude4.h:158
altitude4_cfg_setup
void altitude4_cfg_setup(altitude4_cfg_t *cfg)
Config Object Initialization function.
both::flt
Definition: altitude4.h:154
altitude4_cfg_t::sda
pin_name_t sda
Definition: altitude4.h:139
altitude4_cfg_t::scl
pin_name_t scl
Definition: altitude4.h:138
altitude4_init
ALTITUDE4_RETVAL altitude4_init(altitude4_t *ctx, altitude4_cfg_t *cfg)
Initialization function.
altitude4_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: altitude4.h:143
altitude4_sensor_t::temperature
float temperature
Definition: altitude4.h:111
altitude4_t::i2c
i2c_master_t i2c
Definition: altitude4.h:123
altitude4_generic_read
void altitude4_generic_read(altitude4_t *ctx, uint8_t reg, uint8_t *r_buf, uint8_t len)
Generic read function.
both
Floating point union definition.
Definition: altitude4.h:152
ALTITUDE4_RETVAL
#define ALTITUDE4_RETVAL
Definition: altitude4.h:76
altitude4_cfg_t
Click configuration structure definition.
Definition: altitude4.h:135
altitude4_sensor_t
Sensor object definition.
Definition: altitude4.h:109
both::flt::hmant
unsigned hmant
Definition: altitude4.h:156
both::flt::exp
unsigned exp
Definition: altitude4.h:157
altitude4_t::slave_address
uint8_t slave_address
Definition: altitude4.h:127
altitude4_generic_write
void altitude4_generic_write(altitude4_t *ctx, uint8_t reg, uint8_t *w_buf, uint8_t len)
Generic write function.
both::fl
double fl
Definition: altitude4.h:162
both::flt
struct both::flt flt