adc7 2.0.0.0
adc7.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 ADC7_H
35#define ADC7_H
36
41#ifdef PREINIT_SUPPORTED
42#include "preinit.h"
43#endif
44
45#ifdef MikroCCoreVersion
46 #if MikroCCoreVersion >= 1
47 #include "delays.h"
48 #endif
49#endif
50
51#include "drv_digital_out.h"
52#include "drv_digital_in.h"
53#include "drv_spi_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
66#define ADC7_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
68 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
69 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71 cfg.drl = MIKROBUS( mikrobus, MIKROBUS_AN ); \
72 cfg.pre = MIKROBUS( mikrobus, MIKROBUS_RST ); \
73 cfg.mck = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
74 cfg.bsy = MIKROBUS( mikrobus, MIKROBUS_INT )
81#define ADC7_RETVAL uint8_t
82
83#define ADC7_OK 0x00
84#define ADC7_INIT_ERROR 0xFF
91#define ADC7_SINC1_FILT 0x01
92#define ADC7_SINC2_FILT 0x02
93#define ADC7_SINC3_FILT 0x03
94#define ADC7_SINC4_FILT 0x04
95#define ADC7_SSINC_FILT 0x05
96#define ADC7_FLAT_PASSBAND_FILT 0x06
97#define ADC7_AVERAGING_FILT 0x07
104#define ADC7_DOWNSAMPL_FACT_4 0x02
105#define ADC7_DOWNSAMPL_FACT_8 0x03
106#define ADC7_DOWNSAMPL_FACT_16 0x04
107#define ADC7_DOWNSAMPL_FACT_32 0x05
108#define ADC7_DOWNSAMPL_FACT_64 0x06
109#define ADC7_DOWNSAMPL_FACT_128 0x07
110#define ADC7_DOWNSAMPL_FACT_256 0x08
111#define ADC7_DOWNSAMPL_FACT_512 0x09
112#define ADC7_DOWNSAMPL_FACT_1024 0x0A
113#define ADC7_DOWNSAMPL_FACT_2048 0x0B
114#define ADC7_DOWNSAMPL_FACT_4096 0x0C
115#define ADC7_DOWNSAMPL_FACT_8192 0x0D
116#define ADC7_DOWNSAMPL_FACT_16384 0x0E
123#define ADC7_GAIN_EXPAN_EN 0x01
124#define ADC7_GAIN_COMPR_EN 0x02
125#define ADC7_GAIN_DISABLE 0x00
132#define ADC7_DATA_NOT_READY 0x01
133#define ADC7_DATA_IS_READY 0x00
134#define ADC7_DEVICE_IS_BUSY 0x01
135#define ADC7_DEVICE_NOT_BUSY 0x00
136#define ADC7_WRONG_GAIN_CONFIG 0x02
137#define ADC7_WRONG_DOWNSAMPL_FACT 0x03
138#define ADC7_WRONG_FILT_TYPE 0x04
145#define ADC7_HIGH_STATE 0x01
146#define ADC7_LOW_STATE 0x00
149 // End group macro
150// --------------------------------------------------------------- PUBLIC TYPES
159typedef struct
160{
161 digital_out_t cs;
162
163 // Output pins
164
165 digital_out_t pre;
166 digital_out_t mck;
167
168 // Input pins
169
170 digital_in_t drl;
171 digital_in_t bsy;
172
173 // Modules
174
175 spi_master_t spi;
176 pin_name_t chip_select;
177
178 uint16_t num_sampl;
179 float volt_ref;
181
182
183} adc7_t;
184
188typedef struct
189{
190 // Communication gpio pins
191
192 pin_name_t miso;
193 pin_name_t mosi;
194 pin_name_t sck;
195 pin_name_t cs;
196
197 // Additional gpio pins
198
199 pin_name_t drl;
200 pin_name_t pre;
201 pin_name_t mck;
202 pin_name_t bsy;
203
204 // static variable
205
206 uint32_t spi_speed;
207 spi_master_mode_t spi_mode;
208 spi_master_chip_select_polarity_t cs_polarity;
209
213
214} adc7_cfg_t;
215
216 // End types group
217// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
218
223#ifdef __cplusplus
224extern "C"{
225#endif
226
236
245
255
269uint8_t adc7_set_config ( adc7_t* ctx, uint8_t gain_config,
270 uint8_t down_samp_factor, uint8_t filter_type );
271
282
292uint8_t adc7_check_busy ( adc7_t* ctx );
293
303void adc7_set_clock ( adc7_t* ctx, uint8_t state );
304
314void adc7_preset_mode ( adc7_t* ctx, uint8_t state );
315
328uint8_t adc7_read_bytes ( adc7_t* ctx, uint8_t n_bytes, uint8_t* data_out );
329
341
353uint8_t adc7_read_results ( adc7_t* ctx, float* voltage );
354
355
356#ifdef __cplusplus
357}
358#endif
359#endif // _ADC7_H_
360
361 // End public_function group
363
364// ------------------------------------------------------------------------- END
#define ADC7_RETVAL
Definition adc7.h:81
uint8_t adc7_read_bytes(adc7_t *ctx, uint8_t n_bytes, uint8_t *data_out)
Read Bytes Function.
void adc7_default_cfg(adc7_t *ctx)
Default Configuration Initialization function.
uint8_t adc7_check_data_ready(adc7_t *ctx)
Data Ready Check Function.
uint8_t adc7_read_results(adc7_t *ctx, float *voltage)
Start Conversion Function.
ADC7_RETVAL adc7_init(adc7_t *ctx, adc7_cfg_t *cfg)
Initialization function.
uint8_t adc7_set_config(adc7_t *ctx, uint8_t gain_config, uint8_t down_samp_factor, uint8_t filter_type)
Configuration set function.
void adc7_cfg_setup(adc7_cfg_t *cfg)
Config Object Initialization function.
void adc7_set_clock(adc7_t *ctx, uint8_t state)
Set Clock.
uint8_t adc7_check_busy(adc7_t *ctx)
Busy Check Function.
void adc7_preset_mode(adc7_t *ctx, uint8_t state)
Preset Mode.
void adc7_start_conv_cycle(adc7_t *ctx)
Start Conversion Function.
Click configuration structure definition.
Definition adc7.h:189
float dev_value_lsb
Definition adc7.h:212
pin_name_t pre
Definition adc7.h:200
pin_name_t drl
Definition adc7.h:199
uint16_t dev_num_sampl
Definition adc7.h:210
pin_name_t bsy
Definition adc7.h:202
spi_master_chip_select_polarity_t cs_polarity
Definition adc7.h:208
pin_name_t sck
Definition adc7.h:194
spi_master_mode_t spi_mode
Definition adc7.h:207
pin_name_t mck
Definition adc7.h:201
pin_name_t mosi
Definition adc7.h:193
uint32_t spi_speed
Definition adc7.h:206
pin_name_t miso
Definition adc7.h:192
pin_name_t cs
Definition adc7.h:195
float dev_volt_ref
Definition adc7.h:211
Click ctx object definition.
Definition adc7.h:160
digital_out_t cs
Definition adc7.h:161
digital_in_t drl
Definition adc7.h:170
spi_master_t spi
Definition adc7.h:175
digital_out_t mck
Definition adc7.h:166
float value_lsb
Definition adc7.h:180
digital_out_t pre
Definition adc7.h:165
float volt_ref
Definition adc7.h:179
digital_in_t bsy
Definition adc7.h:171
pin_name_t chip_select
Definition adc7.h:176
uint16_t num_sampl
Definition adc7.h:178