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