manometer2  2.0.0.0
manometer2.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 MANOMETER2_H
36 #define MANOMETER2_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 
57 // -------------------------------------------------------------- PUBLIC MACROS
68 #define MANOMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
69  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
72 
79 #define MANOMETER2_RETVAL uint8_t
80 
81 #define MANOMETER2_OK 0x00
82 #define MANOMETER2_INIT_ERROR 0xFF
83 
89 #define MANOMETER2_I2C_ADDRESS_0 0x76
90 #define MANOMETER2_I2C_ADDRESS_1 0x77
91 
97 #define MANOMETER2_RESET 0x1E
98 #define MANOMETER2_RESET_CMD 0xA6
99 #define MANOMETER2_ADC_READ 0x00
100 #define MANOMETER2_D1_CONVERT_256 0x40
101 #define MANOMETER2_D1_CONVERT_512 0x42
102 #define MANOMETER2_D1_CONVERT_1024 0x44
103 #define MANOMETER2_D1_CONVERT_2048 0x46
104 #define MANOMETER2_D1_CONVERT_4096 0x48
105 #define MANOMETER2_D2_CONVERT_256 0x50
106 #define MANOMETER2_D2_CONVERT_512 0x52
107 #define MANOMETER2_D2_CONVERT_1024 0x54
108 #define MANOMETER2_D2_CONVERT_2048 0x56
109 #define MANOMETER2_D2_CONVERT_4096 0x58
110 #define MANOMETER2_C1_READ 0xA2
111 #define MANOMETER2_C2_READ 0xA4
112 #define MANOMETER2_C3_READ 0xA6
113 #define MANOMETER2_C4_READ 0xA8
114 #define MANOMETER2_C5_READ 0xAA
115 #define MANOMETER2_C6_READ 0xAC
116 #define MANOMETER2_CONVERT_256 0
117 #define MANOMETER2_CONVERT_512 1
118 #define MANOMETER2_CONVERT_1024 2
119 #define MANOMETER2_CONVERT_2048 3
120 #define MANOMETER2_CONVERT_4096 4
121 
127 #define MANOMETER2_Q1 14
128 #define MANOMETER2_Q2 16
129 #define MANOMETER2_Q3 7
130 #define MANOMETER2_Q4 5
131 #define MANOMETER2_Q5 7
132 #define MANOMETER2_Q6 21
133  // End group macro
136 // --------------------------------------------------------------- PUBLIC TYPES
143 typedef struct
144 {
145  uint16_t coef1;
146  uint16_t coef2;
147  uint16_t coef3;
148  uint16_t coef4;
149  uint16_t coef5;
150  uint16_t coef6;
151 
153 
157 typedef struct manometer2_s
158 {
159  // Output pins
160 
161  digital_out_t cs;
162 
163  // Modules
164 
165  i2c_master_t i2c;
166  spi_master_t spi;
167 
168  // ctx variable
169 
170  uint8_t slave_address;
171 
173 
175 
179 typedef struct
180 {
181  // Communication gpio pins
182 
183  pin_name_t scl;
184  pin_name_t sda;
185  pin_name_t cs;
186 
187  // static variable
188 
189  uint32_t i2c_speed;
190  uint8_t i2c_address;
191 
193  // End types group
195 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
201 #ifdef __cplusplus
202 extern "C"{
203 #endif
204 
214 
224 
233 
243 void manometer2_write_data ( manometer2_t *ctx, uint8_t reg_address, uint8_t write_command );
244 
256 uint16_t manometer2_read_data ( manometer2_t *ctx, uint8_t reg_address );
257 
269 uint32_t manometer2_read_command ( manometer2_t *ctx, uint8_t reg_address );
270 
279 
288 
300 float manometer2_get_temperature ( manometer2_t *ctx, uint8_t oversampling_ratio );
301 
313 float manometer2_get_pressure ( manometer2_t *ctx, uint8_t oversampling_ratio );
314 
315 #ifdef __cplusplus
316 }
317 #endif
318 #endif // _MANOMETER2_H_
319  // End public_function group
322 
323 // ------------------------------------------------------------------------- END
manometer2_s::cs
digital_out_t cs
Definition: manometer2.h:161
MANOMETER2_RETVAL
#define MANOMETER2_RETVAL
Definition: manometer2.h:79
manometer2_write_data
void manometer2_write_data(manometer2_t *ctx, uint8_t reg_address, uint8_t write_command)
Generic write data function.
manometer2_coef_t::coef4
uint16_t coef4
Definition: manometer2.h:148
manometer2_get_pressure
float manometer2_get_pressure(manometer2_t *ctx, uint8_t oversampling_ratio)
Get pressure data function.
manometer2_cfg_setup
void manometer2_cfg_setup(manometer2_cfg_t *cfg)
Config Object Initialization function.
manometer2_coef_t::coef3
uint16_t coef3
Definition: manometer2.h:147
manometer2_s::coef
manometer2_coef_t coef
Definition: manometer2.h:172
manometer2_coef_t::coef2
uint16_t coef2
Definition: manometer2.h:146
manometer2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: manometer2.h:189
manometer2_s
Click ctx object definition.
Definition: manometer2.h:158
manometer2_reset
void manometer2_reset(manometer2_t *ctx)
Reset.
manometer2_coef_t::coef5
uint16_t coef5
Definition: manometer2.h:149
manometer2_cfg_t::sda
pin_name_t sda
Definition: manometer2.h:184
manometer2_t
struct manometer2_s manometer2_t
Click ctx object definition.
manometer2_s::i2c
i2c_master_t i2c
Definition: manometer2.h:165
manometer2_read_data
uint16_t manometer2_read_data(manometer2_t *ctx, uint8_t reg_address)
Generic read data function.
manometer2_coef_t::coef1
uint16_t coef1
Definition: manometer2.h:145
manometer2_cfg_t::scl
pin_name_t scl
Definition: manometer2.h:183
manometer2_get_temperature
float manometer2_get_temperature(manometer2_t *ctx, uint8_t oversampling_ratio)
Get temperature data function.
manometer2_read_command
uint32_t manometer2_read_command(manometer2_t *ctx, uint8_t reg_address)
Generic read data function.
manometer2_coef_t::coef6
uint16_t coef6
Definition: manometer2.h:150
manometer2_read_coef
void manometer2_read_coef(manometer2_t *ctx)
Function read coeffitient.
manometer2_cfg_t::i2c_address
uint8_t i2c_address
Definition: manometer2.h:190
manometer2_s::spi
spi_master_t spi
Definition: manometer2.h:166
manometer2_cfg_t
Click configuration structure definition.
Definition: manometer2.h:180
manometer2_coef_t
Definition: manometer2.h:144
manometer2_s::slave_address
uint8_t slave_address
Definition: manometer2.h:170
manometer2_default_cfg
void manometer2_default_cfg(manometer2_t *ctx)
Click Default Configuration function.
manometer2_cfg_t::cs
pin_name_t cs
Definition: manometer2.h:185
manometer2_init
MANOMETER2_RETVAL manometer2_init(manometer2_t *ctx, manometer2_cfg_t *cfg)
Initialization function.