vacuum  2.0.0.0
vacuum.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef VACCUM_H
36 #define VACCUM_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 VACCUM_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN );
57 
63 #define VACCUM_RETVAL uint8_t
64 
65 #define VACCUM_OK 0x00
66 #define VACCUM_INIT_ERROR 0xFF
67  // End group macro
70 // --------------------------------------------------------------- PUBLIC TYPES
79 typedef struct
80 {
81  // Output pins
82 
83  digital_out_t an;
84 
85  // Modules
86 
87  i2c_master_t i2c;
88 
89  // ctx variable
90 
91  hal_i2c_address_t slave_address;
92  uint16_t pressure;
93 
94 } vacuum_t;
95 
99 typedef struct
100 {
101  // Communication gpio pins
102 
103  pin_name_t scl;
104  pin_name_t sda;
105 
106  // Additional gpio pins
107 
108  pin_name_t an;
109 
110  // static variable
111 
112  hal_i2c_speed_t i2c_speed;
113  hal_i2c_address_t i2c_address;
114 
115 } vacuum_cfg_t;
116  // End variable group
118 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
119 
125 #ifdef __cplusplus
126 extern "C"{
127 #endif
128 
137 void vacuum_cfg_setup ( vacuum_cfg_t *cfg );
138 
147 
155 void vacuum_default_cfg ( vacuum_t *ctx );
156 
167 void vacuum_generic_write ( vacuum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
168 
180 void vacuum_generic_read ( vacuum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
181 
190 uint16_t vacuum_read_data ( vacuum_t *ctx );
191 
200 float vacuum_get_voltage ( vacuum_t *ctx );
201 
210 float vacuum_get_pressure ( vacuum_t *ctx );
211 
221 
230 void vacuum_calibration ( vacuum_t *ctx );
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 #endif // _VACCUM_H_
236  // End public_function group
239 
240 // ------------------------------------------------------------------------- END
float vacuum_get_pressure(vacuum_t *ctx)
Function for converting ADC value to pressure data.
VACCUM_RETVAL vacuum_init(vacuum_t *ctx, vacuum_cfg_t *cfg)
Initialization function.
void vacuum_generic_write(vacuum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void vacuum_calibration(vacuum_t *ctx)
Sensor calibration.
pin_name_t sda
Definition: vacuum.h:104
hal_i2c_speed_t i2c_speed
Definition: vacuum.h:112
void vacuum_default_cfg(vacuum_t *ctx)
Click Default Configuration function.
float vacuum_get_percentage_of_vacuum(vacuum_t *ctx)
Function for converting ADC value to percentage of Vacuum.
uint16_t pressure
Definition: vacuum.h:92
Click configuration structure definition.
Definition: vacuum.h:99
pin_name_t scl
Definition: vacuum.h:103
#define VACCUM_RETVAL
Definition: vacuum.h:63
hal_i2c_address_t i2c_address
Definition: vacuum.h:113
float vacuum_get_voltage(vacuum_t *ctx)
Voltage reading function.
Click ctx object definition.
Definition: vacuum.h:79
void vacuum_generic_read(vacuum_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void vacuum_cfg_setup(vacuum_cfg_t *cfg)
Config Object Initialization function.
uint16_t vacuum_read_data(vacuum_t *ctx)
Function for reads 12 bit ADC data.
digital_out_t an
Definition: vacuum.h:83
i2c_master_t i2c
Definition: vacuum.h:87
hal_i2c_address_t slave_address
Definition: vacuum.h:91
pin_name_t an
Definition: vacuum.h:108