vacuum  2.0.0.0
vacuum.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 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  uint8_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  uint32_t i2c_speed;
113  uint8_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 
148 
156 void vacuum_default_cfg ( vacuum_t *ctx );
157 
165 uint16_t vacuum_read_data ( vacuum_t *ctx );
166 
174 float vacuum_get_voltage ( vacuum_t *ctx );
175 
183 float vacuum_get_pressure ( vacuum_t *ctx );
184 
193 
201 void vacuum_calibration ( vacuum_t *ctx );
202 
203 #ifdef __cplusplus
204 }
205 #endif
206 #endif // _VACCUM_H_
207  // End public_function group
210 
211 // ------------------------------------------------------------------------- END
vacuum_cfg_setup
void vacuum_cfg_setup(vacuum_cfg_t *cfg)
Config Object Initialization function.
vacuum_t::an
digital_out_t an
Definition: vacuum.h:83
vacuum_get_voltage
float vacuum_get_voltage(vacuum_t *ctx)
Voltage reading function.
vacuum_t::slave_address
uint8_t slave_address
Definition: vacuum.h:91
vacuum_get_percentage_of_vacuum
float vacuum_get_percentage_of_vacuum(vacuum_t *ctx)
Function for converting ADC value to percentage of Vacuum.
vacuum_cfg_t::an
pin_name_t an
Definition: vacuum.h:108
vacuum_cfg_t::scl
pin_name_t scl
Definition: vacuum.h:103
vacuum_init
VACCUM_RETVAL vacuum_init(vacuum_t *ctx, vacuum_cfg_t *cfg)
Initialization function.
vacuum_t::pressure
uint16_t pressure
Definition: vacuum.h:92
vacuum_t
Click ctx object definition.
Definition: vacuum.h:79
VACCUM_RETVAL
#define VACCUM_RETVAL
Definition: vacuum.h:63
vacuum_get_pressure
float vacuum_get_pressure(vacuum_t *ctx)
Function for converting ADC value to pressure data.
vacuum_default_cfg
void vacuum_default_cfg(vacuum_t *ctx)
Click Default Configuration function.
vacuum_cfg_t::sda
pin_name_t sda
Definition: vacuum.h:104
vacuum_t::i2c
i2c_master_t i2c
Definition: vacuum.h:87
vacuum_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: vacuum.h:112
vacuum_calibration
void vacuum_calibration(vacuum_t *ctx)
Sensor calibration.
vacuum_cfg_t
Click configuration structure definition.
Definition: vacuum.h:99
vacuum_cfg_t::i2c_address
uint8_t i2c_address
Definition: vacuum.h:113
vacuum_read_data
uint16_t vacuum_read_data(vacuum_t *ctx)
Function for reads 12 bit ADC data.