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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 #include "drv_spi_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define MANOMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
56  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
65 #define MANOMETER2_RETVAL uint8_t
66 
67 #define MANOMETER2_OK 0x00
68 #define MANOMETER2_INIT_ERROR 0xFF
69 
75 #define MANOMETER2_I2C_ADDRESS_0 0x76
76 #define MANOMETER2_I2C_ADDRESS_1 0x77
77 
83 #define MANOMETER2_RESET 0x1E
84 #define MANOMETER2_RESET_CMD 0xA6
85 #define MANOMETER2_ADC_READ 0x00
86 #define MANOMETER2_D1_CONVERT_256 0x40
87 #define MANOMETER2_D1_CONVERT_512 0x42
88 #define MANOMETER2_D1_CONVERT_1024 0x44
89 #define MANOMETER2_D1_CONVERT_2048 0x46
90 #define MANOMETER2_D1_CONVERT_4096 0x48
91 #define MANOMETER2_D2_CONVERT_256 0x50
92 #define MANOMETER2_D2_CONVERT_512 0x52
93 #define MANOMETER2_D2_CONVERT_1024 0x54
94 #define MANOMETER2_D2_CONVERT_2048 0x56
95 #define MANOMETER2_D2_CONVERT_4096 0x58
96 #define MANOMETER2_C1_READ 0xA2
97 #define MANOMETER2_C2_READ 0xA4
98 #define MANOMETER2_C3_READ 0xA6
99 #define MANOMETER2_C4_READ 0xA8
100 #define MANOMETER2_C5_READ 0xAA
101 #define MANOMETER2_C6_READ 0xAC
102 #define MANOMETER2_CONVERT_256 0
103 #define MANOMETER2_CONVERT_512 1
104 #define MANOMETER2_CONVERT_1024 2
105 #define MANOMETER2_CONVERT_2048 3
106 #define MANOMETER2_CONVERT_4096 4
107 
113 #define MANOMETER2_Q1 14
114 #define MANOMETER2_Q2 16
115 #define MANOMETER2_Q3 7
116 #define MANOMETER2_Q4 5
117 #define MANOMETER2_Q5 7
118 #define MANOMETER2_Q6 21
119  // End group macro
122 // --------------------------------------------------------------- PUBLIC TYPES
129 typedef struct
130 {
131  uint16_t coef1;
132  uint16_t coef2;
133  uint16_t coef3;
134  uint16_t coef4;
135  uint16_t coef5;
136  uint16_t coef6;
137 
139 
143 typedef struct manometer2_s
144 {
145  // Output pins
146 
147  digital_out_t cs;
148 
149  // Modules
150 
151  i2c_master_t i2c;
152  spi_master_t spi;
153 
154  // ctx variable
155 
156  uint8_t slave_address;
157 
159 
160 } manometer2_t;
161 
165 typedef struct
166 {
167  // Communication gpio pins
168 
169  pin_name_t scl;
170  pin_name_t sda;
171  pin_name_t cs;
172 
173  // static variable
174 
175  uint32_t i2c_speed;
176  uint8_t i2c_address;
177 
179  // End types group
181 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
187 #ifdef __cplusplus
188 extern "C"{
189 #endif
190 
200 
210 
219 
229 void manometer2_write_data ( manometer2_t *ctx, uint8_t reg_address, uint8_t write_command );
230 
242 uint16_t manometer2_read_data ( manometer2_t *ctx, uint8_t reg_address );
243 
255 uint32_t manometer2_read_command ( manometer2_t *ctx, uint8_t reg_address );
256 
264 void manometer2_reset ( manometer2_t *ctx );
265 
273 void manometer2_read_coef ( manometer2_t *ctx );
274 
286 float manometer2_get_temperature ( manometer2_t *ctx, uint8_t oversampling_ratio );
287 
299 float manometer2_get_pressure ( manometer2_t *ctx, uint8_t oversampling_ratio );
300 
301 #ifdef __cplusplus
302 }
303 #endif
304 #endif // _MANOMETER2_H_
305  // End public_function group
308 
309 // ------------------------------------------------------------------------- END
manometer2_s::cs
digital_out_t cs
Definition: manometer2.h:147
MANOMETER2_RETVAL
#define MANOMETER2_RETVAL
Definition: manometer2.h:65
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:134
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:133
manometer2_s::coef
manometer2_coef_t coef
Definition: manometer2.h:158
manometer2_coef_t::coef2
uint16_t coef2
Definition: manometer2.h:132
manometer2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: manometer2.h:175
manometer2_s
Click ctx object definition.
Definition: manometer2.h:143
manometer2_reset
void manometer2_reset(manometer2_t *ctx)
Reset.
manometer2_coef_t::coef5
uint16_t coef5
Definition: manometer2.h:135
manometer2_cfg_t::sda
pin_name_t sda
Definition: manometer2.h:170
manometer2_s::i2c
i2c_master_t i2c
Definition: manometer2.h:151
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:131
manometer2_cfg_t::scl
pin_name_t scl
Definition: manometer2.h:169
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:136
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:176
manometer2_s::spi
spi_master_t spi
Definition: manometer2.h:152
manometer2_t
struct manometer2_s manometer2_t
Click ctx object definition.
manometer2_cfg_t
Click configuration structure definition.
Definition: manometer2.h:165
manometer2_coef_t
Definition: manometer2.h:129
manometer2_s::slave_address
uint8_t slave_address
Definition: manometer2.h:156
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:171
manometer2_init
MANOMETER2_RETVAL manometer2_init(manometer2_t *ctx, manometer2_cfg_t *cfg)
Initialization function.