adc8  2.0.0.0
adc8.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 ADC8_H
36 #define ADC8_H
37 
38 #include "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define ADC8_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
55 
61 #define ADC8_RETVAL uint8_t
62 
63 #define ADC8_OK 0x00
64 #define ADC8_INIT_ERROR 0xFF
65 
71 #define ADC8_REG_CONFIGURATION 0x01
72 #define ADC8_REG_CONVERSION 0x00
73 #define ADC8_REG_THRESHOLD_LOW 0x02
74 #define ADC8_REG_THRESHOLD_HIGH 0x03
75 
81 #define ADC8_CFG_CONVERSION_ENABLE 0x0000
82 #define ADC8_CFG_CONVERSION_DISABLE 0x8000
83 
89 #define ADC8_CFG_MUX_AINP0_AINN1 0x0000
90 #define ADC8_CFG_MUX_AINP0_AINN3 0x1000
91 #define ADC8_CFG_MUX_AINP1_AINN3 0x2000
92 #define ADC8_CFG_MUX_AINP2_AINN3 0x3000
93 #define ADC8_CFG_MUX_AINP0_GND 0x4000
94 #define ADC8_CFG_MUX_AINP1_GND 0x5000
95 #define ADC8_CFG_MUX_AINP2_GND 0x6000
96 #define ADC8_CFG_MUX_AINP3_GND 0x7000
97 
103 #define ADC8_CFG_GAIN_6144mV 0x0000
104 #define ADC8_CFG_GAIN_4096mV 0x0200
105 #define ADC8_CFG_GAIN_2048mV 0x0400
106 #define ADC8_CFG_GAIN_1024mV 0x0600
107 #define ADC8_CFG_GAIN_512mV 0x0800
108 #define ADC8_CFG_GAIN_256mV 0x0A00
109 
115 #define ADC8_CFG_MODE_CONTINUOUS 0x0000
116 #define ADC8_CFG_MODE_SINGLE 0x0100
117 
123 #define ADC8_CFG_SPS_8 0x0000
124 #define ADC8_CFG_SPS_16 0x0020
125 #define ADC8_CFG_SPS_32 0x0040
126 #define ADC8_CFG_SPS_64 0x0060
127 #define ADC8_CFG_SPS_128 0x0080
128 #define ADC8_CFG_SPS_250 0x00A0
129 #define ADC8_CFG_SPS_475 0x00C0
130 #define ADC8_CFG_SPS_860 0x00E0
131 
137 #define ADC8_CFG_COMP_MODE_TRADITIONAL 0x0000
138 #define ADC8_CFG_COMP_MODE_WINDOW 0x0010
139 
145 #define ADC8_CFG_COMP_POL_LOW 0x0000
146 #define ADC8_CFG_COMP_POL_HIGH 0x0008
147 
153 #define ADC8_CFG_COMP_LAT_ENABLE 0x0000
154 #define ADC8_CFG_COMP_LAT_DISABLE 0x0004
155 
156 #define ADC8_CFG_COMP_QUE_1_CONV 0x0000
157 #define ADC8_CFG_COMP_QUE_2_CONV 0x0001
158 #define ADC8_CFG_COMP_QUE_4_CONV 0x0002
159 #define ADC8_CFG_COMP_QUE_ALERT_CONV 0x0003
160 
166 #define ADC8_DEVICE_SLAVE_ADDR_GND 0x48
167 #define ADC8_DEVICE_SLAVE_ADDR_VDD 0x49
168 #define ADC8_DEVICE_SLAVE_ADDR_SDA 0x4A
169 #define ADC8_DEVICE_SLAVE_ADDR_SCL 0x4B
170 
176 #define ADC8_SINGLE_CHANNEL_0 0x00
177 #define ADC8_SINGLE_CHANNEL_1 0x01
178 #define ADC8_SINGLE_CHANNEL_2 0x02
179 #define ADC8_SINGLE_CHANNEL_3 0x03
180 #define ADC8_DIFF_CHANNEL_0_1 0x04
181 #define ADC8_DIFF_CHANNEL_0_3 0x05
182 #define ADC8_DIFF_CHANNEL_1_3 0x06
183 #define ADC8_DIFF_CHANNEL_2_3 0x07
184  // End group macro
187 // --------------------------------------------------------------- PUBLIC TYPES
196 typedef struct
197 {
198  // Input pins
199 
200  digital_in_t int_pin;
201 
202  // Modules
203 
204  i2c_master_t i2c;
205 
206  // ctx variable
207 
208  hal_i2c_address_t slave_address;
209 
210  float max_voltage;
211  uint16_t cfg_reg_value;
212  uint8_t diff_flag;
213 
214 } adc8_t;
215 
219 typedef struct
220 {
221  // Communication gpio pins
222 
223  pin_name_t scl;
224  pin_name_t sda;
225 
226  // Additional gpio pins
227 
228  pin_name_t int_pin;
229 
230  // static variable
231 
232  hal_i2c_speed_t i2c_speed;
233  hal_i2c_address_t i2c_address;
234 
235 } adc8_cfg_t;
236 
240 typedef struct
241 {
242  float ch_0;
243  float ch_1;
244  float ch_2;
245  float ch_3;
246 
248 
252 typedef struct
253 {
254  float ch_0_1;
255  float ch_0_3;
256  float ch_1_3;
257  float ch_2_3;
258 
260  // End types group
262 
263 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
264 
270 #ifdef __cplusplus
271 extern "C"{
272 #endif
273 
282 void adc8_cfg_setup ( adc8_cfg_t *cfg );
283 
291 ADC8_RETVAL adc8_init ( adc8_t *ctx, adc8_cfg_t *cfg );
292 
312 void adc8_default_cfg ( adc8_t *ctx );
313 
324 void adc8_generic_write ( adc8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
325 
337 void adc8_generic_read ( adc8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
338 
357 void adc8_set_cfg_register ( adc8_t *ctx, uint16_t cfg );
358 
367 uint16_t adc8_get_adc_value ( adc8_t *ctx, uint8_t channel );
368 
377 float adc8_get_voltage ( adc8_t *ctx, uint8_t channel );
378 
386 uint8_t adc8_get_interrupt_state( adc8_t *ctx );
387 
397 
406 void adc8_get_diff_channel( adc8_t *ctx, adc8_diff_volt_t *volt );
407 
408 #ifdef __cplusplus
409 }
410 #endif
411 #endif // _ADC8_H_
412  // End public_function group
415 
416 // ------------------------------------------------------------------------- END
float ch_0_1
Definition: adc8.h:254
void adc8_cfg_setup(adc8_cfg_t *cfg)
Config Object Initialization function.
uint8_t diff_flag
Definition: adc8.h:212
i2c_master_t i2c
Definition: adc8.h:204
float ch_1
Definition: adc8.h:243
float ch_2_3
Definition: adc8.h:257
digital_in_t int_pin
Definition: adc8.h:200
void adc8_generic_write(adc8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
pin_name_t sda
Definition: adc8.h:224
hal_i2c_address_t i2c_address
Definition: adc8.h:233
float ch_3
Definition: adc8.h:245
float ch_0
Definition: adc8.h:242
Click configuration structure definition.
Definition: adc8.h:219
void adc8_generic_read(adc8_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
float adc8_get_voltage(adc8_t *ctx, uint8_t channel)
Read Voltage in mV.
hal_i2c_speed_t i2c_speed
Definition: adc8.h:232
void adc8_set_cfg_register(adc8_t *ctx, uint16_t cfg)
Device configuration for measurement.
float ch_1_3
Definition: adc8.h:256
float max_voltage
Definition: adc8.h:210
#define ADC8_RETVAL
Definition: adc8.h:61
hal_i2c_address_t slave_address
Definition: adc8.h:208
ADC8_RETVAL adc8_init(adc8_t *ctx, adc8_cfg_t *cfg)
Initialization function.
Click ctx object definition.
Definition: adc8.h:196
Diff channel (volt) type.
Definition: adc8.h:252
pin_name_t int_pin
Definition: adc8.h:228
uint16_t cfg_reg_value
Definition: adc8.h:211
uint8_t adc8_get_interrupt_state(adc8_t *ctx)
Get interrupt pin state.
float ch_0_3
Definition: adc8.h:255
float ch_2
Definition: adc8.h:244
void adc8_get_single_channel(adc8_t *ctx, adc8_single_volt_t *volt)
Get [Package} Single channel voltage.
pin_name_t scl
Definition: adc8.h:223
Single channel (volt) type.
Definition: adc8.h:240
void adc8_default_cfg(adc8_t *ctx)
Click Default Configuration function.
void adc8_get_diff_channel(adc8_t *ctx, adc8_diff_volt_t *volt)
Get [Package] Diff channel voltage.
uint16_t adc8_get_adc_value(adc8_t *ctx, uint8_t channel)
Get ADC value on the channel.