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 )
56 
62 #define ALTITUDE4_RETVAL uint8_t
63 
64 #define ALTITUDE4_OK 0x00
65 #define ALTITUDE4_INIT_ERROR 0xFF
66 
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
79 
82 #define FRNDINT( x ) ( ( double ) ( long ) ( x ) )
83  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
94  typedef struct
95  {
96  float pressure;
97  float temperature;
98  float altitude;
99 
101 
105 typedef struct
106 {
107  // Modules
108 
109  i2c_master_t i2c;
110 
111  // ctx variable
112 
113  uint8_t slave_address;
114 
115 } altitude4_t;
116 
120 typedef 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 
137 union both
138 {
139  struct flt
140  {
141  unsigned char mant[ 2 ];
142  unsigned hmant : 7;
143  unsigned exp : 8;
144  unsigned sign : 1;
145 
146  } flt;
147 
148  double fl;
149 };
150  // End types group
152 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
153 
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
172 
181 
193 void altitude4_generic_read ( altitude4_t *ctx, uint8_t reg, uint8_t *r_buf, uint8_t len );
194 
205 void 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
both::flt::mant
unsigned char mant[2]
Definition: altitude4.h:141
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:96
altitude4_cfg_t::i2c_address
uint8_t i2c_address
Definition: altitude4.h:130
altitude4_sensor_t::altitude
float altitude
Definition: altitude4.h:98
altitude4_t
Click ctx object definition.
Definition: altitude4.h:106
both::flt::sign
unsigned sign
Definition: altitude4.h:144
altitude4_cfg_setup
void altitude4_cfg_setup(altitude4_cfg_t *cfg)
Config Object Initialization function.
both::flt
Definition: altitude4.h:140
altitude4_cfg_t::sda
pin_name_t sda
Definition: altitude4.h:125
altitude4_cfg_t::scl
pin_name_t scl
Definition: altitude4.h:124
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:129
altitude4_sensor_t::temperature
float temperature
Definition: altitude4.h:97
altitude4_t::i2c
i2c_master_t i2c
Definition: altitude4.h:109
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:138
ALTITUDE4_RETVAL
#define ALTITUDE4_RETVAL
Definition: altitude4.h:62
altitude4_cfg_t
Click configuration structure definition.
Definition: altitude4.h:121
altitude4_sensor_t
Sensor object definition.
Definition: altitude4.h:95
both::flt::hmant
unsigned hmant
Definition: altitude4.h:142
both::flt::exp
unsigned exp
Definition: altitude4.h:143
altitude4_t::slave_address
uint8_t slave_address
Definition: altitude4.h:113
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:148
both::flt
struct both::flt flt