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
37#include "drv_digital_out.h"
38#include "drv_digital_in.h"
39#include "drv_spi_master.h"
40
41// -------------------------------------------------------------- PUBLIC MACROS
52#define ADC7_MAP_MIKROBUS( cfg, mikrobus ) \
53 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
54 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
55 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
56 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
57 cfg.drl = MIKROBUS( mikrobus, MIKROBUS_AN ); \
58 cfg.pre = MIKROBUS( mikrobus, MIKROBUS_RST ); \
59 cfg.mck = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
60 cfg.bsy = MIKROBUS( mikrobus, MIKROBUS_INT )
67#define ADC7_RETVAL uint8_t
68
69#define ADC7_OK 0x00
70#define ADC7_INIT_ERROR 0xFF
77#define ADC7_SINC1_FILT 0x01
78#define ADC7_SINC2_FILT 0x02
79#define ADC7_SINC3_FILT 0x03
80#define ADC7_SINC4_FILT 0x04
81#define ADC7_SSINC_FILT 0x05
82#define ADC7_FLAT_PASSBAND_FILT 0x06
83#define ADC7_AVERAGING_FILT 0x07
90#define ADC7_DOWNSAMPL_FACT_4 0x02
91#define ADC7_DOWNSAMPL_FACT_8 0x03
92#define ADC7_DOWNSAMPL_FACT_16 0x04
93#define ADC7_DOWNSAMPL_FACT_32 0x05
94#define ADC7_DOWNSAMPL_FACT_64 0x06
95#define ADC7_DOWNSAMPL_FACT_128 0x07
96#define ADC7_DOWNSAMPL_FACT_256 0x08
97#define ADC7_DOWNSAMPL_FACT_512 0x09
98#define ADC7_DOWNSAMPL_FACT_1024 0x0A
99#define ADC7_DOWNSAMPL_FACT_2048 0x0B
100#define ADC7_DOWNSAMPL_FACT_4096 0x0C
101#define ADC7_DOWNSAMPL_FACT_8192 0x0D
102#define ADC7_DOWNSAMPL_FACT_16384 0x0E
109#define ADC7_GAIN_EXPAN_EN 0x01
110#define ADC7_GAIN_COMPR_EN 0x02
111#define ADC7_GAIN_DISABLE 0x00
118#define ADC7_DATA_NOT_READY 0x01
119#define ADC7_DATA_IS_READY 0x00
120#define ADC7_DEVICE_IS_BUSY 0x01
121#define ADC7_DEVICE_NOT_BUSY 0x00
122#define ADC7_WRONG_GAIN_CONFIG 0x02
123#define ADC7_WRONG_DOWNSAMPL_FACT 0x03
124#define ADC7_WRONG_FILT_TYPE 0x04
131#define ADC7_HIGH_STATE 0x01
132#define ADC7_LOW_STATE 0x00 // End group macro
136// --------------------------------------------------------------- PUBLIC TYPES
145typedef struct
146{
147 digital_out_t cs;
148
149 // Output pins
150
151 digital_out_t pre;
152 digital_out_t mck;
153
154 // Input pins
155
156 digital_in_t drl;
157 digital_in_t bsy;
158
159 // Modules
160
161 spi_master_t spi;
162 pin_name_t chip_select;
163
164 uint16_t num_sampl;
165 float volt_ref;
167
168
169} adc7_t;
170
174typedef struct
175{
176 // Communication gpio pins
177
178 pin_name_t miso;
179 pin_name_t mosi;
180 pin_name_t sck;
181 pin_name_t cs;
182
183 // Additional gpio pins
184
185 pin_name_t drl;
186 pin_name_t pre;
187 pin_name_t mck;
188 pin_name_t bsy;
189
190 // static variable
191
192 uint32_t spi_speed;
193 spi_master_mode_t spi_mode;
194 spi_master_chip_select_polarity_t cs_polarity;
195
199
200} adc7_cfg_t;
201 // End types group
203// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
204
209#ifdef __cplusplus
210extern "C"{
211#endif
212
222
231
241
255uint8_t adc7_set_config ( adc7_t* ctx, uint8_t gain_config,
256 uint8_t down_samp_factor, uint8_t filter_type );
257
268
278uint8_t adc7_check_busy ( adc7_t* ctx );
279
289void adc7_set_clock ( adc7_t* ctx, uint8_t state );
290
300void adc7_preset_mode ( adc7_t* ctx, uint8_t state );
301
314uint8_t adc7_read_bytes ( adc7_t* ctx, uint8_t n_bytes, uint8_t* data_out );
315
327
339uint8_t adc7_read_results ( adc7_t* ctx, float* voltage );
340
341
342#ifdef __cplusplus
343}
344#endif
345#endif // _ADC7_H_
346 // End public_function group
349
350// ------------------------------------------------------------------------- END
#define ADC7_RETVAL
Definition: adc7.h:67
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:175
float dev_value_lsb
Definition: adc7.h:198
pin_name_t pre
Definition: adc7.h:186
pin_name_t drl
Definition: adc7.h:185
uint16_t dev_num_sampl
Definition: adc7.h:196
pin_name_t bsy
Definition: adc7.h:188
spi_master_chip_select_polarity_t cs_polarity
Definition: adc7.h:194
pin_name_t sck
Definition: adc7.h:180
spi_master_mode_t spi_mode
Definition: adc7.h:193
pin_name_t mck
Definition: adc7.h:187
pin_name_t mosi
Definition: adc7.h:179
uint32_t spi_speed
Definition: adc7.h:192
pin_name_t miso
Definition: adc7.h:178
pin_name_t cs
Definition: adc7.h:181
float dev_volt_ref
Definition: adc7.h:197
Click ctx object definition.
Definition: adc7.h:146
digital_out_t cs
Definition: adc7.h:147
digital_in_t drl
Definition: adc7.h:156
spi_master_t spi
Definition: adc7.h:161
digital_out_t mck
Definition: adc7.h:152
float value_lsb
Definition: adc7.h:166
digital_out_t pre
Definition: adc7.h:151
float volt_ref
Definition: adc7.h:165
digital_in_t bsy
Definition: adc7.h:157
pin_name_t chip_select
Definition: adc7.h:162
uint16_t num_sampl
Definition: adc7.h:164