adc3  2.0.0.0
adc3.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 ADC3_H
36 #define ADC3_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 ADC3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define ADC3_RETVAL uint8_t
62 
63 #define ADC3_OK 0x00
64 #define ADC3_INIT_ERROR 0xFF
65 
71 #define ADC3_I2C_SLAVE_ADDR 0x68
72 
78 #define ADC3_CFG_REG 0x00
79 
84 #define ADC3_PGA_GAIN_X1 0x00
85 #define ADC3_PGA_GAIN_X2 0x01
86 #define ADC3_PGA_GAIN_X4 0x02
87 #define ADC3_PGA_GAIN_X8 0x03
88 
93 #define ADC3_SAMPLE_RATE_12 0x00
94 #define ADC3_SAMPLE_RATE_14 0x04
95 #define ADC3_SAMPLE_RATE_16 0x08
96 
101 #define ADC3_CONV_ONE_SHOT 0x00
102 #define ADC3_CONV_CONTINOUS 0x10
103 
108 #define ADC3_SELECT_CHANNEL_1 0x00
109 #define ADC3_SELECT_CHANNEL_2 0x20
110 #define ADC3_SELECT_CHANNEL_3 0x40
111 #define ADC3_SELECT_CHANNEL_4 0x60
112 
117 #define ADC3_DATA_START_VALUE 0
118 #define ADC3_DATA_RESOL_RATE_12 0x0F
119 #define ADC3_DATA_RESULT_RATE_12 0x07FF
120 #define ADC3_DATA_RESOL_RATE_14 0x3F
121 #define ADC3_DATA_RESULT_RATE_14 0x1FFF
122 #define ADC3_DATA_RESOL_RATE_16 0xFF
123 #define ADC3_DATA_RESULT_RATE_16 0x7FFF
124 
130 #define ADC3_RDY_SET 0x80
131 #define ADC3_RDY_CLEAR 0x00
132 
137 #define ADC3_GENERAL_CALL_RESET 0x06
138 #define ADC3_GENERAL_CALL_LATCH 0x04
139 #define ADC3_GENERAL_CALL_CONVERSION 0x08
140  // End group macro
143 
144 // --------------------------------------------------------------- PUBLIC TYPES
153 typedef struct
154 {
155  // Modules
156 
157  i2c_master_t i2c;
158 
159  // ctx variable
160 
161  uint8_t slave_address;
162 
163 } adc3_t;
164 
168 typedef struct
169 {
170  // Communication gpio pins
171 
172  pin_name_t scl;
173  pin_name_t sda;
174 
175  // static variable
176 
177  uint32_t i2c_speed;
178  uint8_t i2c_address;
179 
180 } adc3_cfg_t;
181  // End types group
183 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
184 
190 #ifdef __cplusplus
191 extern "C"{
192 #endif
193 
202 void adc3_cfg_setup ( adc3_cfg_t *cfg );
203 
212 ADC3_RETVAL adc3_init ( adc3_t *ctx, adc3_cfg_t *cfg );
213 
221 void adc3_default_cfg ( adc3_t *ctx );
222 
233 void adc3_generic_write ( adc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
234 
245 void adc3_generic_read ( adc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
246 
255 void adc3_reset ( adc3_t *ctx );
256 
265 void adc3_latch ( adc3_t *ctx );
266 
276 void adc3_conversion ( adc3_t *ctx );
277 
291 int16_t adc3_read_measurement ( adc3_t *ctx, uint8_t channel, uint8_t resolution, uint8_t gain );
292 
306 float adc3_read_voltage ( adc3_t *ctx, uint8_t channel, uint8_t resolution, uint8_t gain );
307 
308 #ifdef __cplusplus
309 }
310 #endif
311 #endif // _ADC3_H_
312  // End public_function group
315 
316 // ------------------------------------------------------------------------- END
adc3_init
ADC3_RETVAL adc3_init(adc3_t *ctx, adc3_cfg_t *cfg)
Initialization function.
adc3_cfg_setup
void adc3_cfg_setup(adc3_cfg_t *cfg)
Config Object Initialization function.
adc3_cfg_t::i2c_address
uint8_t i2c_address
Definition: adc3.h:178
adc3_conversion
void adc3_conversion(adc3_t *ctx)
General call conversion function.
adc3_cfg_t::scl
pin_name_t scl
Definition: adc3.h:172
adc3_cfg_t::sda
pin_name_t sda
Definition: adc3.h:173
adc3_latch
void adc3_latch(adc3_t *ctx)
General call latch function.
ADC3_RETVAL
#define ADC3_RETVAL
Definition: adc3.h:61
adc3_t::i2c
i2c_master_t i2c
Definition: adc3.h:157
adc3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: adc3.h:177
adc3_default_cfg
void adc3_default_cfg(adc3_t *ctx)
Click Default Configuration function.
adc3_read_measurement
int16_t adc3_read_measurement(adc3_t *ctx, uint8_t channel, uint8_t resolution, uint8_t gain)
ADC3 read measurement function.
adc3_t
Click ctx object definition.
Definition: adc3.h:153
adc3_reset
void adc3_reset(adc3_t *ctx)
General call reset function.
adc3_cfg_t
Click configuration structure definition.
Definition: adc3.h:168
adc3_t::slave_address
uint8_t slave_address
Definition: adc3.h:161
adc3_generic_read
void adc3_generic_read(adc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
adc3_read_voltage
float adc3_read_voltage(adc3_t *ctx, uint8_t channel, uint8_t resolution, uint8_t gain)
Read voltage function.
adc3_generic_write
void adc3_generic_write(adc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.