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 )
61 
67 #define ADC7_RETVAL uint8_t
68 
69 #define ADC7_OK 0x00
70 #define ADC7_INIT_ERROR 0xFF
71 
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
84 
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
103 
109 #define ADC7_GAIN_EXPAN_EN 0x01
110 #define ADC7_GAIN_COMPR_EN 0x02
111 #define ADC7_GAIN_DISABLE 0x00
112 
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
125 
131 #define ADC7_HIGH_STATE 0x01
132 #define ADC7_LOW_STATE 0x00
133  // End group macro
136 // --------------------------------------------------------------- PUBLIC TYPES
145 typedef 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;
166  float value_lsb;
167 
168 
169 } adc7_t;
170 
174 typedef 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 
196  uint16_t dev_num_sampl;
199 
200 } adc7_cfg_t;
201  // End types group
203 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
204 
209 #ifdef __cplusplus
210 extern "C"{
211 #endif
212 
221 void adc7_cfg_setup ( adc7_cfg_t *cfg );
222 
230 void adc7_default_cfg ( adc7_t *ctx );
231 
240 ADC7_RETVAL adc7_init ( adc7_t *ctx, adc7_cfg_t *cfg );
241 
255 uint8_t adc7_set_config ( adc7_t* ctx, uint8_t gain_config,
256  uint8_t down_samp_factor, uint8_t filter_type );
257 
267 uint8_t adc7_check_data_ready ( adc7_t* ctx );
268 
278 uint8_t adc7_check_busy ( adc7_t* ctx );
279 
289 void adc7_set_clock ( adc7_t* ctx, uint8_t state );
290 
300 void adc7_preset_mode ( adc7_t* ctx, uint8_t state );
301 
314 uint8_t adc7_read_bytes ( adc7_t* ctx, uint8_t n_bytes, uint8_t* data_out );
315 
326 void adc7_start_conv_cycle ( adc7_t* ctx );
327 
339 uint8_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
adc7_cfg_t::pre
pin_name_t pre
Definition: adc7.h:186
adc7_cfg_setup
void adc7_cfg_setup(adc7_cfg_t *cfg)
Config Object Initialization function.
adc7_cfg_t::dev_value_lsb
float dev_value_lsb
Definition: adc7.h:198
adc7_cfg_t::sck
pin_name_t sck
Definition: adc7.h:180
adc7_cfg_t::mosi
pin_name_t mosi
Definition: adc7.h:179
adc7_read_bytes
uint8_t adc7_read_bytes(adc7_t *ctx, uint8_t n_bytes, uint8_t *data_out)
Read Bytes Function.
adc7_t::pre
digital_out_t pre
Definition: adc7.h:151
adc7_cfg_t::spi_speed
uint32_t spi_speed
Definition: adc7.h:192
adc7_set_clock
void adc7_set_clock(adc7_t *ctx, uint8_t state)
Set Clock.
adc7_cfg_t::dev_volt_ref
float dev_volt_ref
Definition: adc7.h:197
adc7_read_results
uint8_t adc7_read_results(adc7_t *ctx, float *voltage)
Start Conversion Function.
adc7_cfg_t::miso
pin_name_t miso
Definition: adc7.h:178
adc7_default_cfg
void adc7_default_cfg(adc7_t *ctx)
Default Configuration Initialization function.
adc7_check_busy
uint8_t adc7_check_busy(adc7_t *ctx)
Busy Check Function.
adc7_t
Click ctx object definition.
Definition: adc7.h:145
adc7_t::drl
digital_in_t drl
Definition: adc7.h:156
adc7_preset_mode
void adc7_preset_mode(adc7_t *ctx, uint8_t state)
Preset Mode.
adc7_cfg_t::bsy
pin_name_t bsy
Definition: adc7.h:188
ADC7_RETVAL
#define ADC7_RETVAL
Definition: adc7.h:67
adc7_start_conv_cycle
void adc7_start_conv_cycle(adc7_t *ctx)
Start Conversion Function.
adc7_cfg_t::mck
pin_name_t mck
Definition: adc7.h:187
adc7_cfg_t::drl
pin_name_t drl
Definition: adc7.h:185
adc7_t::volt_ref
float volt_ref
Definition: adc7.h:165
adc7_t::value_lsb
float value_lsb
Definition: adc7.h:166
adc7_t::chip_select
pin_name_t chip_select
Definition: adc7.h:162
adc7_t::spi
spi_master_t spi
Definition: adc7.h:161
adc7_cfg_t::dev_num_sampl
uint16_t dev_num_sampl
Definition: adc7.h:196
adc7_set_config
uint8_t adc7_set_config(adc7_t *ctx, uint8_t gain_config, uint8_t down_samp_factor, uint8_t filter_type)
Configuration set function.
adc7_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: adc7.h:193
adc7_t::cs
digital_out_t cs
Definition: adc7.h:147
adc7_t::mck
digital_out_t mck
Definition: adc7.h:152
adc7_cfg_t
Click configuration structure definition.
Definition: adc7.h:174
adc7_t::num_sampl
uint16_t num_sampl
Definition: adc7.h:164
adc7_init
ADC7_RETVAL adc7_init(adc7_t *ctx, adc7_cfg_t *cfg)
Initialization function.
adc7_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: adc7.h:194
adc7_t::bsy
digital_in_t bsy
Definition: adc7.h:157
adc7_cfg_t::cs
pin_name_t cs
Definition: adc7.h:181
adc7_check_data_ready
uint8_t adc7_check_data_ready(adc7_t *ctx)
Data Ready Check Function.