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 "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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define ALTITUDE4_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
66 
72 #define ALTITUDE4_RETVAL uint8_t
73 
74 #define ALTITUDE4_OK 0x00
75 #define ALTITUDE4_INIT_ERROR 0xFF
76 
82 #define ALTITUDE4_SLAVE_ADDRESS 0x27
83 
84 #define ALTITUDE4_START_CMD_MODE 0xA9
85 #define ALTITUDE4_EXIT_CMD_MODE 0xA8
86 #define ALTITUDE4_INC_MEM_PAGE_CNT 0x5E
87 #define ALTITUDE4_CREATE_MEM_PAGE_CHECKSUM 0xAA
88 #define ALTITUDE4_SENS_DATA 0xAC
89 
92 #define FRNDINT( x ) ( ( double ) ( long ) ( x ) )
93  // End group macro
95 // --------------------------------------------------------------- PUBLIC TYPES
104  typedef struct
105  {
106  float pressure;
107  float temperature;
108  float altitude;
109 
111 
115 typedef struct
116 {
117  // Modules
118 
119  i2c_master_t i2c;
120 
121  // ctx variable
122 
123  uint8_t slave_address;
124 
125 } altitude4_t;
126 
130 typedef struct
131 {
132  // Communication gpio pins
133 
134  pin_name_t scl;
135  pin_name_t sda;
136 
137  // static variable
138 
139  uint32_t i2c_speed;
140  uint8_t i2c_address;
141 
143 
147 union both
148 {
149  struct flt
150  {
151  unsigned char mant[ 2 ];
152  unsigned hmant : 7;
153  unsigned exp : 8;
154  unsigned sign : 1;
155 
156  } flt;
157 
158  double fl;
159 };
160  // End types group
162 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163 
169 #ifdef __cplusplus
170 extern "C"{
171 #endif
172 
182 
191 
203 void altitude4_generic_read ( altitude4_t *ctx, uint8_t reg, uint8_t *r_buf, uint8_t len );
204 
215 void altitude4_generic_write ( altitude4_t *ctx, uint8_t reg, uint8_t *w_buf, uint8_t len );
216 
227 
228 #ifdef __cplusplus
229 }
230 #endif
231 #endif // _ALTITUDE4_H_
232  // End public_function group
235 
236 // ------------------------------------------------------------------------- END
both::flt::mant
unsigned char mant[2]
Definition: altitude4.h:151
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:106
altitude4_cfg_t::i2c_address
uint8_t i2c_address
Definition: altitude4.h:140
altitude4_sensor_t::altitude
float altitude
Definition: altitude4.h:108
altitude4_t
Click ctx object definition.
Definition: altitude4.h:116
both::flt::sign
unsigned sign
Definition: altitude4.h:154
altitude4_cfg_setup
void altitude4_cfg_setup(altitude4_cfg_t *cfg)
Config Object Initialization function.
both::flt
Definition: altitude4.h:150
altitude4_cfg_t::sda
pin_name_t sda
Definition: altitude4.h:135
altitude4_cfg_t::scl
pin_name_t scl
Definition: altitude4.h:134
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:139
altitude4_sensor_t::temperature
float temperature
Definition: altitude4.h:107
altitude4_t::i2c
i2c_master_t i2c
Definition: altitude4.h:119
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:148
ALTITUDE4_RETVAL
#define ALTITUDE4_RETVAL
Definition: altitude4.h:72
altitude4_cfg_t
Click configuration structure definition.
Definition: altitude4.h:131
altitude4_sensor_t
Sensor object definition.
Definition: altitude4.h:105
both::flt::hmant
unsigned hmant
Definition: altitude4.h:152
both::flt::exp
unsigned exp
Definition: altitude4.h:153
altitude4_t::slave_address
uint8_t slave_address
Definition: altitude4.h:123
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:158
both::flt
struct both::flt flt