alcohol3  2.0.0.0
alcohol3.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 ALCOHOL3_H
36 #define ALCOHOL3_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define ALCOHOL3_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
54 
60 #define ALCOHOL3_RETVAL uint8_t
61 
62 #define ALCOHOL3_OK 0x00
63 #define ALCOHOL3_INIT_ERROR 0xFF
64 
70 #define ALCOHOL3_DEVICE_SLAVE_ADDRESS 0x4D
71 
77 #define ALCOHOL3_PARAM_CO_OUT_MIN 1
78 #define ALCOHOL3_PARAM_CO_OUT_MAX 1000
79 #define ALCOHOL3_PARAM_SUPPLY_IN_MIN 0
80 #define ALCOHOL3_PARAM_SUPPLY_IN_MAX 4096
81 
88 // ppm to mg/L
89 
90 #define ALCOHOL3_CONV_MGL_PARAM_A 1.82
91 #define ALCOHOL3_CONV_MGL_PARAM_B 0.91
92 #define ALCOHOL3_CONV_MGL_PARAM_C 0.18
93 #define ALCOHOL3_CONV_MGL_PARAM_D 0.09
94 
95 #define ALCOHOL3_CONV_AIR_PPM_PARAM_A 1000
96 #define ALCOHOL3_CONV_AIR_PPM_PARAM_B 500
97 #define ALCOHOL3_CONV_AIR_PPM_PARAM_C 100
98 #define ALCOHOL3_CONV_AIR_PPM_PARAM_D 50
99 
106  // CO [ ppm ]
107 
108 #define ALCOHOL3_CO_PPM_0 0
109 #define ALCOHOL3_CO_PPM_10 10
110 #define ALCOHOL3_CO_PPM_50 50
111 #define ALCOHOL3_CO_PPM_100 100
112 #define ALCOHOL3_CO_PPM_500 500
113 
114 // Equivalent C2H5OH
115 
116 #define ALCOHOL3_EQU_TO_PPM_0 0
117 #define ALCOHOL3_EQU_TO_PPM_10 1
118 #define ALCOHOL3_EQU_TO_PPM_50 6
119 #define ALCOHOL3_EQU_TO_PPM_100 18
120 #define ALCOHOL3_EQU_TO_PPM_500 274
121  // End group macro
124 
125 // --------------------------------------------------------------- PUBLIC TYPES
134 typedef struct
135 {
136 
137  // Modules
138 
139  i2c_master_t i2c;
140 
141  // ctx variable
142 
143  uint8_t slave_address;
144 
145 } alcohol3_t;
146 
150 typedef struct
151 {
152  // Communication gpio pins
153 
154  pin_name_t scl;
155  pin_name_t sda;
156 
157  // static variable
158 
159  uint32_t i2c_speed;
160  uint8_t i2c_address;
161 
163  // End types group
165 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166 
172 #ifdef __cplusplus
173 extern "C"{
174 #endif
175 
184 void alcohol3_cfg_setup ( alcohol3_cfg_t *cfg );
185 
195 
203 void alcohol3_default_cfg ( alcohol3_t *ctx );
204 
215 void alcohol3_generic_write ( alcohol3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
216 
227 void alcohol3_generic_read ( alcohol3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
228 
236 uint16_t alcohol3_get_adc_data ( alcohol3_t *ctx );
237 
245 uint16_t alcohol3_get_co_in_ppm ( alcohol3_t *ctx );
246 
254 float alcohol3_get_co_in_mgl ( alcohol3_t *ctx );
255 
263 uint16_t alcohol3_ethanol_in_ppm ( alcohol3_t *ctx );
264 
273 
274 #ifdef __cplusplus
275 }
276 #endif
277 #endif // _ALCOHOL3_H_
278  // End public_function group
281 
282 // ------------------------------------------------------------------------- END
alcohol3_t
Click ctx object definition.
Definition: alcohol3.h:134
alcohol3_default_cfg
void alcohol3_default_cfg(alcohol3_t *ctx)
Click Default Configuration function.
alcohol3_cfg_t::sda
pin_name_t sda
Definition: alcohol3.h:155
alcohol3_get_co_in_ppm
uint16_t alcohol3_get_co_in_ppm(alcohol3_t *ctx)
Function for read CO (Carbon monoxide) data in ppm.
alcohol3_get_adc_data
uint16_t alcohol3_get_adc_data(alcohol3_t *ctx)
Function for read ADC data.
alcohol3_cfg_t
Click configuration structure definition.
Definition: alcohol3.h:150
alcohol3_cfg_setup
void alcohol3_cfg_setup(alcohol3_cfg_t *cfg)
Config Object Initialization function.
alcohol3_t::i2c
i2c_master_t i2c
Definition: alcohol3.h:139
ALCOHOL3_RETVAL
#define ALCOHOL3_RETVAL
Definition: alcohol3.h:60
alcohol3_generic_read
void alcohol3_generic_read(alcohol3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
alcohol3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: alcohol3.h:159
alcohol3_cfg_t::i2c_address
uint8_t i2c_address
Definition: alcohol3.h:160
alcohol3_get_co_in_mgl
float alcohol3_get_co_in_mgl(alcohol3_t *ctx)
Function for read CO (Carbon monoxide) data in mg/L.
alcohol3_get_percentage_bac
float alcohol3_get_percentage_bac(alcohol3_t *ctx)
Function for read percentage of alcohol in the blood (BAC).
alcohol3_init
ALCOHOL3_RETVAL alcohol3_init(alcohol3_t *ctx, alcohol3_cfg_t *cfg)
Initialization function.
alcohol3_cfg_t::scl
pin_name_t scl
Definition: alcohol3.h:154
alcohol3_t::slave_address
uint8_t slave_address
Definition: alcohol3.h:143
alcohol3_ethanol_in_ppm
uint16_t alcohol3_ethanol_in_ppm(alcohol3_t *ctx)
Function for read Ethanol (C2H5OH) data in ppm.
alcohol3_generic_write
void alcohol3_generic_write(alcohol3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.