alcohol2 2.0.0.0
alcohol2.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 ALCOHOL2_H
36#define ALCOHOL2_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_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define ALCOHOL2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
77#define ALCOHOL2_RETVAL uint8_t
78
79#define ALCOHOL2_OK 0x00
80#define ALCOHOL2_INIT_ERROR 0xFF
87#define ALCOHOL2_STATUS_REG 0x00
88#define ALCOHOL2_LOCK_REG 0x01
89#define ALCOHOL2_TIACN_REG 0x10
90#define ALCOHOL2_REFCN_REG 0x11
91#define ALCOHOL2_MODECN_REG 0x12
98#define ALCOHOL2_WRITE_MODE 0x00
99#define ALCOHOL2_READ_ONLY_MODE 0x01
106#define ALCOHOL2_EXT_TIA_RES 0x00
107#define ALCOHOL2_2750_OHM_TIA_RES 0x04
108#define ALCOHOL2_3500_OHM_TIA_RES 0x08
109#define ALCOHOL2_7K_OHM_TIA_RES 0x0C
110#define ALCOHOL2_14K_OHM_TIA_RES 0x10
111#define ALCOHOL2_35K_OHM_TIA_RES 0x14
112#define ALCOHOL2_120K_OHM_TIA_RES 0x18
113#define ALCOHOL2_350K_OHM_TIA_RES 0x1C
114#define ALCOHOL2_10_OHM_LOAD_RES 0x00
115#define ALCOHOL2_33_OHM_LOAD_RES 0x01
116#define ALCOHOL2_50_OHM_LOAD_RES 0x02
117#define ALCOHOL2_100_OHM_LOAD_RES 0x03
124#define ALCOHOL2_VREF_INT 0x00
125#define ALCOHOL2_VREF_EXT 0x80
126#define ALCOHOL2_20_PERCENTS_INT_ZERO 0x00
127#define ALCOHOL2_50_PERCENTS_INT_ZERO 0x20
128#define ALCOHOL2_67_PERCENTS_INT_ZERO 0x40
129#define ALCOHOL2_INT_ZERO_BYPASSED 0x60
130#define ALCOHOL2_BIAS_POL_NEGATIVE 0x00
131#define ALCOHOL2_BIAS_POL_POSITIVE 0x10
132#define ALCOHOL2_0_PERCENTS_BIAS 0x00
133#define ALCOHOL2_1_PERCENT_BIAS 0x01
134#define ALCOHOL2_2_PERCENTS_BIAS 0x02
135#define ALCOHOL2_4_PERCENTS_BIAS 0x03
136#define ALCOHOL2_6_PERCENTS_BIAS 0x04
137#define ALCOHOL2_8_PERCENTS_BIAS 0x05
138#define ALCOHOL2_10_PERCENTS_BIAS 0x06
139#define ALCOHOL2_12_PERCENTS_BIAS 0x07
140#define ALCOHOL2_14_PERCENTS_BIAS 0x08
141#define ALCOHOL2_16_PERCENTS_BIAS 0x09
142#define ALCOHOL2_18_PERCENTS_BIAS 0x0A
143#define ALCOHOL2_20_PERCENTS_BIAS 0x0B
144#define ALCOHOL2_22_PERCENTS_BIAS 0x0C
145#define ALCOHOL2_24_PERCENTS_BIAS 0x0D
152#define ALCOHOL2_FET_DIS 0x00
153#define ALCOHOL2_FET_EN 0x80
154#define ALCOHOL2_DEEP_SLEEP_MODE 0x00
155#define ALCOHOL2_2_LEAD_MODE 0x01
156#define ALCOHOL2_STANDBY_MODE 0x02
157#define ALCOHOL2_3_LEAD_MODE 0x03
158#define ALCOHOL2_TEMP_MODE_TIA_OFF 0x06
159#define ALCOHOL2_TEMP_MODE_TIA_ON 0x07
166#define ALCOHOL2_DEVICE_EN 0x00
167#define ALCOHOL2_DEVICE_DIS 0x01
174#define ADC_DEVICE_ADDR 0x4D
177 // End group macro
178// --------------------------------------------------------------- PUBLIC TYPES
187typedef struct
188{
189 // Output pins
190
191 digital_out_t rst;
192
193
194 // Input pins
195
196 digital_in_t an;
197
198 // Modules
199
200 i2c_master_t i2c;
201
202 // ctx variable
203
205
206} alcohol2_t;
207
211typedef struct
212{
213 // Communication gpio pins
214
215 pin_name_t scl;
216 pin_name_t sda;
217
218 // Additional gpio pins
219
220 pin_name_t an;
221 pin_name_t rst;
222
223 // static variable
224
225 uint32_t i2c_speed;
226 uint8_t i2c_address;
227
229
230 // End types group
231
232// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
233
239#ifdef __cplusplus
240extern "C"{
241#endif
242
252
262
271
282void alcohol2_generic_write ( alcohol2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
283
294void alcohol2_generic_read ( alcohol2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
295
305void alcohol2_write_byte ( alcohol2_t *ctx, uint8_t reg, uint8_t w_data );
306
315uint8_t alcohol2_read_byte ( alcohol2_t *ctx, uint8_t reg );
316
325void alcohol2_enable ( alcohol2_t *ctx, uint8_t state );
326
335
344
345#ifdef __cplusplus
346}
347#endif
348#endif // _ALCOHOL2_H_
349
350 // End public_function group
352
353// ------------------------------------------------------------------------- END
#define ALCOHOL2_RETVAL
Definition alcohol2.h:77
void alcohol2_default_cfg(alcohol2_t *ctx)
Click Default Configuration function.
void alcohol2_cfg_setup(alcohol2_cfg_t *cfg)
Config Object Initialization function.
void alcohol2_wait_ready(alcohol2_t *ctx)
Function waits until I2C is ready for the next command.
uint8_t alcohol2_read_byte(alcohol2_t *ctx, uint8_t reg)
Function reads one byte from the register.
void alcohol2_enable(alcohol2_t *ctx, uint8_t state)
Device Enable function.
void alcohol2_generic_read(alcohol2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint16_t alcohol2_read_alcohol(alcohol2_t *ctx)
Function for read Alcohol data.
void alcohol2_generic_write(alcohol2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
ALCOHOL2_RETVAL alcohol2_init(alcohol2_t *ctx, alcohol2_cfg_t *cfg)
Initialization function.
void alcohol2_write_byte(alcohol2_t *ctx, uint8_t reg, uint8_t w_data)
Function writes one byte to the register.
Click configuration structure definition.
Definition alcohol2.h:212
uint32_t i2c_speed
Definition alcohol2.h:225
pin_name_t scl
Definition alcohol2.h:215
pin_name_t sda
Definition alcohol2.h:216
pin_name_t rst
Definition alcohol2.h:221
pin_name_t an
Definition alcohol2.h:220
uint8_t i2c_address
Definition alcohol2.h:226
Click ctx object definition.
Definition alcohol2.h:188
i2c_master_t i2c
Definition alcohol2.h:200
digital_in_t an
Definition alcohol2.h:196
digital_out_t rst
Definition alcohol2.h:191
uint8_t slave_address
Definition alcohol2.h:204