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 "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 #include "drv_spi_master.h"
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define MANOMETER2_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
66  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
67  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
68 
75 #define MANOMETER2_RETVAL uint8_t
76 
77 #define MANOMETER2_OK 0x00
78 #define MANOMETER2_INIT_ERROR 0xFF
79 
85 #define MANOMETER2_I2C_ADDRESS_0 0x76
86 #define MANOMETER2_I2C_ADDRESS_1 0x77
87 
93 #define MANOMETER2_RESET 0x1E
94 #define MANOMETER2_RESET_CMD 0xA6
95 #define MANOMETER2_ADC_READ 0x00
96 #define MANOMETER2_D1_CONVERT_256 0x40
97 #define MANOMETER2_D1_CONVERT_512 0x42
98 #define MANOMETER2_D1_CONVERT_1024 0x44
99 #define MANOMETER2_D1_CONVERT_2048 0x46
100 #define MANOMETER2_D1_CONVERT_4096 0x48
101 #define MANOMETER2_D2_CONVERT_256 0x50
102 #define MANOMETER2_D2_CONVERT_512 0x52
103 #define MANOMETER2_D2_CONVERT_1024 0x54
104 #define MANOMETER2_D2_CONVERT_2048 0x56
105 #define MANOMETER2_D2_CONVERT_4096 0x58
106 #define MANOMETER2_C1_READ 0xA2
107 #define MANOMETER2_C2_READ 0xA4
108 #define MANOMETER2_C3_READ 0xA6
109 #define MANOMETER2_C4_READ 0xA8
110 #define MANOMETER2_C5_READ 0xAA
111 #define MANOMETER2_C6_READ 0xAC
112 #define MANOMETER2_CONVERT_256 0
113 #define MANOMETER2_CONVERT_512 1
114 #define MANOMETER2_CONVERT_1024 2
115 #define MANOMETER2_CONVERT_2048 3
116 #define MANOMETER2_CONVERT_4096 4
117 
123 #define MANOMETER2_Q1 14
124 #define MANOMETER2_Q2 16
125 #define MANOMETER2_Q3 7
126 #define MANOMETER2_Q4 5
127 #define MANOMETER2_Q5 7
128 #define MANOMETER2_Q6 21
129  // End group macro
132 // --------------------------------------------------------------- PUBLIC TYPES
139 typedef struct
140 {
141  uint16_t coef1;
142  uint16_t coef2;
143  uint16_t coef3;
144  uint16_t coef4;
145  uint16_t coef5;
146  uint16_t coef6;
147 
149 
153 typedef struct manometer2_s
154 {
155  // Output pins
156 
157  digital_out_t cs;
158 
159  // Modules
160 
161  i2c_master_t i2c;
162  spi_master_t spi;
163 
164  // ctx variable
165 
166  uint8_t slave_address;
167 
169 
171 
175 typedef struct
176 {
177  // Communication gpio pins
178 
179  pin_name_t scl;
180  pin_name_t sda;
181  pin_name_t cs;
182 
183  // static variable
184 
185  uint32_t i2c_speed;
186  uint8_t i2c_address;
187 
189  // End types group
191 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
197 #ifdef __cplusplus
198 extern "C"{
199 #endif
200 
210 
220 
229 
239 void manometer2_write_data ( manometer2_t *ctx, uint8_t reg_address, uint8_t write_command );
240 
252 uint16_t manometer2_read_data ( manometer2_t *ctx, uint8_t reg_address );
253 
265 uint32_t manometer2_read_command ( manometer2_t *ctx, uint8_t reg_address );
266 
275 
284 
296 float manometer2_get_temperature ( manometer2_t *ctx, uint8_t oversampling_ratio );
297 
309 float manometer2_get_pressure ( manometer2_t *ctx, uint8_t oversampling_ratio );
310 
311 #ifdef __cplusplus
312 }
313 #endif
314 #endif // _MANOMETER2_H_
315  // End public_function group
318 
319 // ------------------------------------------------------------------------- END
manometer2_s::cs
digital_out_t cs
Definition: manometer2.h:157
MANOMETER2_RETVAL
#define MANOMETER2_RETVAL
Definition: manometer2.h:75
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:144
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:143
manometer2_s::coef
manometer2_coef_t coef
Definition: manometer2.h:168
manometer2_coef_t::coef2
uint16_t coef2
Definition: manometer2.h:142
manometer2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: manometer2.h:185
manometer2_s
Click ctx object definition.
Definition: manometer2.h:154
manometer2_reset
void manometer2_reset(manometer2_t *ctx)
Reset.
manometer2_coef_t::coef5
uint16_t coef5
Definition: manometer2.h:145
manometer2_cfg_t::sda
pin_name_t sda
Definition: manometer2.h:180
manometer2_t
struct manometer2_s manometer2_t
Click ctx object definition.
manometer2_s::i2c
i2c_master_t i2c
Definition: manometer2.h:161
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:141
manometer2_cfg_t::scl
pin_name_t scl
Definition: manometer2.h:179
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:146
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:186
manometer2_s::spi
spi_master_t spi
Definition: manometer2.h:162
manometer2_cfg_t
Click configuration structure definition.
Definition: manometer2.h:176
manometer2_coef_t
Definition: manometer2.h:140
manometer2_s::slave_address
uint8_t slave_address
Definition: manometer2.h:166
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:181
manometer2_init
MANOMETER2_RETVAL manometer2_init(manometer2_t *ctx, manometer2_cfg_t *cfg)
Initialization function.