alcohol2  2.0.0.0
alcohol2.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 ALCOHOL2_H
36 #define ALCOHOL2_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define ALCOHOL2_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
57 
63 #define ALCOHOL2_RETVAL uint8_t
64 
65 #define ALCOHOL2_OK 0x00
66 #define ALCOHOL2_INIT_ERROR 0xFF
67 
73 #define ALCOHOL2_STATUS_REG 0x00
74 #define ALCOHOL2_LOCK_REG 0x01
75 #define ALCOHOL2_TIACN_REG 0x10
76 #define ALCOHOL2_REFCN_REG 0x11
77 #define ALCOHOL2_MODECN_REG 0x12
78 
84 #define ALCOHOL2_WRITE_MODE 0x00
85 #define ALCOHOL2_READ_ONLY_MODE 0x01
86 
92 #define ALCOHOL2_EXT_TIA_RES 0x00
93 #define ALCOHOL2_2750_OHM_TIA_RES 0x04
94 #define ALCOHOL2_3500_OHM_TIA_RES 0x08
95 #define ALCOHOL2_7K_OHM_TIA_RES 0x0C
96 #define ALCOHOL2_14K_OHM_TIA_RES 0x10
97 #define ALCOHOL2_35K_OHM_TIA_RES 0x14
98 #define ALCOHOL2_120K_OHM_TIA_RES 0x18
99 #define ALCOHOL2_350K_OHM_TIA_RES 0x1C
100 #define ALCOHOL2_10_OHM_LOAD_RES 0x00
101 #define ALCOHOL2_33_OHM_LOAD_RES 0x01
102 #define ALCOHOL2_50_OHM_LOAD_RES 0x02
103 #define ALCOHOL2_100_OHM_LOAD_RES 0x03
104 
110 #define ALCOHOL2_VREF_INT 0x00
111 #define ALCOHOL2_VREF_EXT 0x80
112 #define ALCOHOL2_20_PERCENTS_INT_ZERO 0x00
113 #define ALCOHOL2_50_PERCENTS_INT_ZERO 0x20
114 #define ALCOHOL2_67_PERCENTS_INT_ZERO 0x40
115 #define ALCOHOL2_INT_ZERO_BYPASSED 0x60
116 #define ALCOHOL2_BIAS_POL_NEGATIVE 0x00
117 #define ALCOHOL2_BIAS_POL_POSITIVE 0x10
118 #define ALCOHOL2_0_PERCENTS_BIAS 0x00
119 #define ALCOHOL2_1_PERCENT_BIAS 0x01
120 #define ALCOHOL2_2_PERCENTS_BIAS 0x02
121 #define ALCOHOL2_4_PERCENTS_BIAS 0x03
122 #define ALCOHOL2_6_PERCENTS_BIAS 0x04
123 #define ALCOHOL2_8_PERCENTS_BIAS 0x05
124 #define ALCOHOL2_10_PERCENTS_BIAS 0x06
125 #define ALCOHOL2_12_PERCENTS_BIAS 0x07
126 #define ALCOHOL2_14_PERCENTS_BIAS 0x08
127 #define ALCOHOL2_16_PERCENTS_BIAS 0x09
128 #define ALCOHOL2_18_PERCENTS_BIAS 0x0A
129 #define ALCOHOL2_20_PERCENTS_BIAS 0x0B
130 #define ALCOHOL2_22_PERCENTS_BIAS 0x0C
131 #define ALCOHOL2_24_PERCENTS_BIAS 0x0D
132 
138 #define ALCOHOL2_FET_DIS 0x00
139 #define ALCOHOL2_FET_EN 0x80
140 #define ALCOHOL2_DEEP_SLEEP_MODE 0x00
141 #define ALCOHOL2_2_LEAD_MODE 0x01
142 #define ALCOHOL2_STANDBY_MODE 0x02
143 #define ALCOHOL2_3_LEAD_MODE 0x03
144 #define ALCOHOL2_TEMP_MODE_TIA_OFF 0x06
145 #define ALCOHOL2_TEMP_MODE_TIA_ON 0x07
146 
152 #define ALCOHOL2_DEVICE_EN 0x00
153 #define ALCOHOL2_DEVICE_DIS 0x01
154 
160 #define ADC_DEVICE_ADDR 0x4D
161  // End group macro
164 // --------------------------------------------------------------- PUBLIC TYPES
173 typedef struct
174 {
175  // Output pins
176 
177  digital_out_t rst;
178 
179 
180  // Input pins
181 
182  digital_in_t an;
183 
184  // Modules
185 
186  i2c_master_t i2c;
187 
188  // ctx variable
189 
190  hal_i2c_address_t slave_address;
191 
192 } alcohol2_t;
193 
197 typedef struct
198 {
199  // Communication gpio pins
200 
201  pin_name_t scl;
202  pin_name_t sda;
203 
204  // Additional gpio pins
205 
206  pin_name_t an;
207  pin_name_t rst;
208 
209  // static variable
210 
211  hal_i2c_speed_t i2c_speed;
212  hal_i2c_address_t i2c_address;
213 
215  // End types group
217 
218 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
219 
225 #ifdef __cplusplus
226 extern "C"{
227 #endif
228 
237 
245 void alcohol2_default_cfg ( alcohol2_t *ctx );
246 
257 void alcohol2_generic_write ( alcohol2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
258 
269 void alcohol2_generic_read ( alcohol2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
270 
280 void alcohol2_write_byte ( alcohol2_t *ctx, uint8_t reg, uint8_t w_data );
281 
290 uint8_t alcohol2_read_byte ( alcohol2_t *ctx, uint8_t reg );
291 
300 void alcohol2_enable ( alcohol2_t *ctx, uint8_t state );
301 
309 uint16_t alcohol2_read_alcohol ( alcohol2_t *ctx );
310 
318 void alcohol2_wait_ready( alcohol2_t *ctx );
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 #endif // _ALCOHOL2_H_
324  // End public_function group
327 
328 // ------------------------------------------------------------------------- END
hal_i2c_address_t slave_address
Definition: alcohol2.h:190
void alcohol2_enable(alcohol2_t *ctx, uint8_t state)
Device Enable function.
i2c_master_t i2c
Definition: alcohol2.h:186
hal_i2c_address_t i2c_address
Definition: alcohol2.h:212
pin_name_t scl
Definition: alcohol2.h:201
void alcohol2_default_cfg(alcohol2_t *ctx)
Click Default Configuration function.
void alcohol2_write_byte(alcohol2_t *ctx, uint8_t reg, uint8_t w_data)
Function writes one byte to the register.
void alcohol2_generic_read(alcohol2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void alcohol2_generic_write(alcohol2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t alcohol2_read_byte(alcohol2_t *ctx, uint8_t reg)
Function reads one byte from the register.
pin_name_t rst
Definition: alcohol2.h:207
Click ctx object definition.
Definition: alcohol2.h:173
hal_i2c_speed_t i2c_speed
Definition: alcohol2.h:211
ALCOHOL2_RETVAL alcohol2_init(alcohol2_t *ctx, alcohol2_cfg_t *cfg)
Initialization function.
pin_name_t sda
Definition: alcohol2.h:202
#define ALCOHOL2_RETVAL
Definition: alcohol2.h:63
digital_out_t rst
Definition: alcohol2.h:177
uint16_t alcohol2_read_alcohol(alcohol2_t *ctx)
Function for read Alcohol data.
Click configuration structure definition.
Definition: alcohol2.h:197
void alcohol2_wait_ready(alcohol2_t *ctx)
Function waits until I2C is ready for the next command.
digital_in_t an
Definition: alcohol2.h:182
pin_name_t an
Definition: alcohol2.h:206