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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_i2c_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define ALCOHOL3_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
74#define ALCOHOL3_RETVAL uint8_t
75
76#define ALCOHOL3_OK 0x00
77#define ALCOHOL3_INIT_ERROR 0xFF
84#define ALCOHOL3_DEVICE_SLAVE_ADDRESS 0x4D
91#define ALCOHOL3_PARAM_CO_OUT_MIN 1
92#define ALCOHOL3_PARAM_CO_OUT_MAX 1000
93#define ALCOHOL3_PARAM_SUPPLY_IN_MIN 0
94#define ALCOHOL3_PARAM_SUPPLY_IN_MAX 4096
102// ppm to mg/L
103
104#define ALCOHOL3_CONV_MGL_PARAM_A 1.82
105#define ALCOHOL3_CONV_MGL_PARAM_B 0.91
106#define ALCOHOL3_CONV_MGL_PARAM_C 0.18
107#define ALCOHOL3_CONV_MGL_PARAM_D 0.09
108
109#define ALCOHOL3_CONV_AIR_PPM_PARAM_A 1000
110#define ALCOHOL3_CONV_AIR_PPM_PARAM_B 500
111#define ALCOHOL3_CONV_AIR_PPM_PARAM_C 100
112#define ALCOHOL3_CONV_AIR_PPM_PARAM_D 50
120 // CO [ ppm ]
121
122#define ALCOHOL3_CO_PPM_0 0
123#define ALCOHOL3_CO_PPM_10 10
124#define ALCOHOL3_CO_PPM_50 50
125#define ALCOHOL3_CO_PPM_100 100
126#define ALCOHOL3_CO_PPM_500 500
127
128// Equivalent C2H5OH
129
130#define ALCOHOL3_EQU_TO_PPM_0 0
131#define ALCOHOL3_EQU_TO_PPM_10 1
132#define ALCOHOL3_EQU_TO_PPM_50 6
133#define ALCOHOL3_EQU_TO_PPM_100 18
134#define ALCOHOL3_EQU_TO_PPM_500 274
137 // End group macro
138
139// --------------------------------------------------------------- PUBLIC TYPES
148typedef struct
149{
150
151 // Modules
152
153 i2c_master_t i2c;
154
155 // ctx variable
156
158
159} alcohol3_t;
160
164typedef struct
165{
166 // Communication gpio pins
167
168 pin_name_t scl;
169 pin_name_t sda;
170
171 // static variable
172
173 uint32_t i2c_speed;
174 uint8_t i2c_address;
175
177
178 // End types group
179// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
180
186#ifdef __cplusplus
187extern "C"{
188#endif
189
199
209
218
229void alcohol3_generic_write ( alcohol3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
230
241void alcohol3_generic_read ( alcohol3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
242
251
260
269
278
287
288#ifdef __cplusplus
289}
290#endif
291#endif // _ALCOHOL3_H_
292
293 // End public_function group
295
296// ------------------------------------------------------------------------- END
#define ALCOHOL3_RETVAL
Definition alcohol3.h:74
ALCOHOL3_RETVAL alcohol3_init(alcohol3_t *ctx, alcohol3_cfg_t *cfg)
Initialization function.
uint16_t alcohol3_get_adc_data(alcohol3_t *ctx)
Function for read ADC data.
void alcohol3_default_cfg(alcohol3_t *ctx)
Click Default Configuration function.
uint16_t alcohol3_get_co_in_ppm(alcohol3_t *ctx)
Function for read CO (Carbon monoxide) data in ppm.
void alcohol3_generic_read(alcohol3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
float alcohol3_get_co_in_mgl(alcohol3_t *ctx)
Function for read CO (Carbon monoxide) data in mg/L.
float alcohol3_get_percentage_bac(alcohol3_t *ctx)
Function for read percentage of alcohol in the blood (BAC).
void alcohol3_generic_write(alcohol3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint16_t alcohol3_ethanol_in_ppm(alcohol3_t *ctx)
Function for read Ethanol (C2H5OH) data in ppm.
void alcohol3_cfg_setup(alcohol3_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition alcohol3.h:165
uint32_t i2c_speed
Definition alcohol3.h:173
pin_name_t scl
Definition alcohol3.h:168
pin_name_t sda
Definition alcohol3.h:169
uint8_t i2c_address
Definition alcohol3.h:174
Click ctx object definition.
Definition alcohol3.h:149
i2c_master_t i2c
Definition alcohol3.h:153
uint8_t slave_address
Definition alcohol3.h:157