adc  2.0.0.0
adc.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef _ADC_H_
36 #define _ADC_H_
37 
38 #include "drv_digital_out.h"
39 #include "drv_spi_master.h"
40 
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define ADC_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.sdo = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
54  cfg.sdi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
55  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
57  // End macros group
60 // --------------------------------------------------------------- PUBLIC TYPES
69 typedef enum
70 {
71  ADC_OK = 0x0,
73 
74 } adc_err_t;
75 
79 typedef enum
80 {
84 
85 } adc_vref_t;
86 
90 typedef enum
91 {
96 
97 } adc_ch_t;
98 
102 typedef struct
103 {
104  // SPI Module.
105  spi_master_t spi;
106 
107  // Single-Ended Channels Data.
108  uint16_t ch0;
109  uint16_t ch1;
110  uint16_t ch2;
111  uint16_t ch3;
112 
113  // Differential Channels Data.
114  uint16_t ch01;
115  uint16_t ch10;
116  uint16_t ch23;
117  uint16_t ch32;
118 
119  // Reference Voltage.
120  uint16_t vref;
121 
122 } adc_t;
123 
127 typedef struct
128 {
129  // Communication GPIO Pins.
130  pin_name_t sdo;
131  pin_name_t sdi;
132  pin_name_t sck;
133  pin_name_t cs;
134 
135  // SPI Configuration Variables.
136  hal_spi_speed_t spi_speed;
137  hal_spi_mode_t spi_mode;
138 
139  // Reference Voltage Selection.
141 
142 } adc_cfg_t;
143  // End types group
145 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
151 #ifdef __cplusplus
152 extern "C"{
153 #endif
154 
165 void
166 adc_cfg_setup( adc_cfg_t *cfg );
167 
180 adc_err_t
181 adc_init( adc_t *ctx, adc_cfg_t *cfg );
182 
196 uint16_t
197 adc_get_single_ended_ch( adc_t *ctx, adc_ch_t channel );
198 
212 uint16_t
213 adc_get_differential_ch( adc_t *ctx, adc_ch_t channel );
214 
215 #ifdef __cplusplus
216 }
217 #endif
218 #endif // _ADC_H_
219  // End public_function group
222 
223 // ------------------------------------------------------------------------ END
ADC_VREF_5000MV
Definition: adc.h:83
adc_t::ch1
uint16_t ch1
Definition: adc.h:109
adc_vref_t
adc_vref_t
Click reference voltage definition.
Definition: adc.h:79
ADC_CH1_OR_CH10
Definition: adc.h:93
adc_t::ch0
uint16_t ch0
Definition: adc.h:108
adc_t::ch23
uint16_t ch23
Definition: adc.h:116
ADC_VREF_3300MV
Definition: adc.h:81
adc_cfg_t::cs
pin_name_t cs
Definition: adc.h:133
adc_t
Click context object definition.
Definition: adc.h:102
ADC_CH2_OR_CH23
Definition: adc.h:94
adc_cfg_t::sdi
pin_name_t sdi
Definition: adc.h:131
adc_t::vref
uint16_t vref
Definition: adc.h:120
adc_cfg_t::sck
pin_name_t sck
Definition: adc.h:132
ADC_ERR_INIT_DRV
Definition: adc.h:72
adc_get_single_ended_ch
uint16_t adc_get_single_ended_ch(adc_t *ctx, adc_ch_t channel)
Get Single-Ended Channel function.
adc_t::ch3
uint16_t ch3
Definition: adc.h:111
adc_cfg_t::spi_speed
hal_spi_speed_t spi_speed
Definition: adc.h:136
adc_cfg_t::spi_mode
hal_spi_mode_t spi_mode
Definition: adc.h:137
ADC_VREF_4096MV
Definition: adc.h:82
adc_cfg_t
Click configuration structure definition.
Definition: adc.h:127
adc_get_differential_ch
uint16_t adc_get_differential_ch(adc_t *ctx, adc_ch_t channel)
Get Pseudo-Differential Pair function.
adc_t::ch2
uint16_t ch2
Definition: adc.h:110
adc_ch_t
adc_ch_t
Click channel definition.
Definition: adc.h:90
adc_cfg_setup
void adc_cfg_setup(adc_cfg_t *cfg)
Configuration Object Setup function.
ADC_CH3_OR_CH32
Definition: adc.h:95
adc_t::spi
spi_master_t spi
Definition: adc.h:105
adc_cfg_t::vref
adc_vref_t vref
Definition: adc.h:140
ADC_CH0_OR_CH01
Definition: adc.h:92
adc_t::ch01
uint16_t ch01
Definition: adc.h:114
ADC_OK
Definition: adc.h:71
adc_err_t
adc_err_t
Click error code definition.
Definition: adc.h:69
adc_t::ch32
uint16_t ch32
Definition: adc.h:117
adc_cfg_t::sdo
pin_name_t sdo
Definition: adc.h:130
adc_t::ch10
uint16_t ch10
Definition: adc.h:115
adc_init
adc_err_t adc_init(adc_t *ctx, adc_cfg_t *cfg)
Click Initialization function.