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 "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 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define VACCUM_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
65  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
66  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
67 
73 #define VACCUM_RETVAL uint8_t
74 
75 #define VACCUM_OK 0x00
76 #define VACCUM_INIT_ERROR 0xFF
77  // End group macro
80 // --------------------------------------------------------------- PUBLIC TYPES
89 typedef struct
90 {
91  // Output pins
92 
93  digital_out_t an;
94 
95  // Modules
96 
97  i2c_master_t i2c;
98 
99  // ctx variable
100 
101  uint8_t slave_address;
102  uint16_t pressure;
103 
104 } vacuum_t;
105 
109 typedef struct
110 {
111  // Communication gpio pins
112 
113  pin_name_t scl;
114  pin_name_t sda;
115 
116  // Additional gpio pins
117 
118  pin_name_t an;
119 
120  // static variable
121 
122  uint32_t i2c_speed;
123  uint8_t i2c_address;
124 
125 } vacuum_cfg_t;
126  // End variable group
128 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
129 
135 #ifdef __cplusplus
136 extern "C"{
137 #endif
138 
148 
158 
167 
175 uint16_t vacuum_read_data ( vacuum_t *ctx );
176 
185 
194 
203 
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 #endif // _VACCUM_H_
217  // End public_function group
220 
221 // ------------------------------------------------------------------------- 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:93
vacuum_get_voltage
float vacuum_get_voltage(vacuum_t *ctx)
Voltage reading function.
vacuum_t::slave_address
uint8_t slave_address
Definition: vacuum.h:101
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:118
vacuum_cfg_t::scl
pin_name_t scl
Definition: vacuum.h:113
vacuum_init
VACCUM_RETVAL vacuum_init(vacuum_t *ctx, vacuum_cfg_t *cfg)
Initialization function.
vacuum_t::pressure
uint16_t pressure
Definition: vacuum.h:102
vacuum_t
Click ctx object definition.
Definition: vacuum.h:90
VACCUM_RETVAL
#define VACCUM_RETVAL
Definition: vacuum.h:73
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:114
vacuum_t::i2c
i2c_master_t i2c
Definition: vacuum.h:97
vacuum_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: vacuum.h:122
vacuum_calibration
void vacuum_calibration(vacuum_t *ctx)
Sensor calibration.
vacuum_cfg_t
Click configuration structure definition.
Definition: vacuum.h:110
vacuum_cfg_t::i2c_address
uint8_t i2c_address
Definition: vacuum.h:123
vacuum_read_data
uint16_t vacuum_read_data(vacuum_t *ctx)
Function for reads 12 bit ADC data.