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
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 ADC3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
75#define ADC3_RETVAL uint8_t
76
77#define ADC3_OK 0x00
78#define ADC3_INIT_ERROR 0xFF
85#define ADC3_I2C_SLAVE_ADDR 0x68
92#define ADC3_CFG_REG 0x00
98#define ADC3_PGA_GAIN_X1 0x00
99#define ADC3_PGA_GAIN_X2 0x01
100#define ADC3_PGA_GAIN_X4 0x02
101#define ADC3_PGA_GAIN_X8 0x03
107#define ADC3_SAMPLE_RATE_12 0x00
108#define ADC3_SAMPLE_RATE_14 0x04
109#define ADC3_SAMPLE_RATE_16 0x08
115#define ADC3_CONV_ONE_SHOT 0x00
116#define ADC3_CONV_CONTINOUS 0x10
122#define ADC3_SELECT_CHANNEL_1 0x00
123#define ADC3_SELECT_CHANNEL_2 0x20
124#define ADC3_SELECT_CHANNEL_3 0x40
125#define ADC3_SELECT_CHANNEL_4 0x60
131#define ADC3_DATA_START_VALUE 0
132#define ADC3_DATA_RESOL_RATE_12 0x0F
133#define ADC3_DATA_RESULT_RATE_12 0x07FF
134#define ADC3_DATA_RESOL_RATE_14 0x3F
135#define ADC3_DATA_RESULT_RATE_14 0x1FFF
136#define ADC3_DATA_RESOL_RATE_16 0xFF
137#define ADC3_DATA_RESULT_RATE_16 0x7FFF
138
144#define ADC3_RDY_SET 0x80
145#define ADC3_RDY_CLEAR 0x00
151#define ADC3_GENERAL_CALL_RESET 0x06
152#define ADC3_GENERAL_CALL_LATCH 0x04
153#define ADC3_GENERAL_CALL_CONVERSION 0x08
156 // End group macro
157
158// --------------------------------------------------------------- PUBLIC TYPES
167typedef struct
168{
169 // Modules
170
171 i2c_master_t i2c;
172
173 // ctx variable
174
176
177} adc3_t;
178
182typedef struct
183{
184 // Communication gpio pins
185
186 pin_name_t scl;
187 pin_name_t sda;
188
189 // static variable
190
191 uint32_t i2c_speed;
192 uint8_t i2c_address;
193
194} adc3_cfg_t;
195
196 // End types group
197// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
198
204#ifdef __cplusplus
205extern "C"{
206#endif
207
217
227
236
247void adc3_generic_write ( adc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
248
259void adc3_generic_read ( adc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
260
269void adc3_reset ( adc3_t *ctx );
270
279void adc3_latch ( adc3_t *ctx );
280
291
305int16_t adc3_read_measurement ( adc3_t *ctx, uint8_t channel, uint8_t resolution, uint8_t gain );
306
320float adc3_read_voltage ( adc3_t *ctx, uint8_t channel, uint8_t resolution, uint8_t gain );
321
322#ifdef __cplusplus
323}
324#endif
325#endif // _ADC3_H_
326
327 // End public_function group
329
330// ------------------------------------------------------------------------- END
#define ADC3_RETVAL
Definition adc3.h:75
ADC3_RETVAL adc3_init(adc3_t *ctx, adc3_cfg_t *cfg)
Initialization function.
int16_t adc3_read_measurement(adc3_t *ctx, uint8_t channel, uint8_t resolution, uint8_t gain)
ADC3 read measurement function.
void adc3_reset(adc3_t *ctx)
General call reset function.
void adc3_generic_read(adc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void adc3_default_cfg(adc3_t *ctx)
Click Default Configuration function.
void adc3_latch(adc3_t *ctx)
General call latch function.
void adc3_generic_write(adc3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void adc3_conversion(adc3_t *ctx)
General call conversion function.
void adc3_cfg_setup(adc3_cfg_t *cfg)
Config Object Initialization function.
float adc3_read_voltage(adc3_t *ctx, uint8_t channel, uint8_t resolution, uint8_t gain)
Read voltage function.
Click configuration structure definition.
Definition adc3.h:183
uint32_t i2c_speed
Definition adc3.h:191
pin_name_t scl
Definition adc3.h:186
pin_name_t sda
Definition adc3.h:187
uint8_t i2c_address
Definition adc3.h:192
Click ctx object definition.
Definition adc3.h:168
i2c_master_t i2c
Definition adc3.h:171
uint8_t slave_address
Definition adc3.h:175