adc19  2.0.0.0
adc19.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef ADC19_H
29 #define ADC19_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define ADC19_INPUT_CHANNEL_1 1
71 #define ADC19_INPUT_CHANNEL_2 2
72 
77 #define ADC19_RESOLUTION_12BIT 0x0FFF
78 #define ADC19_VREF_3V3 3.3
79 #define ADC19_VREF_5V 5.0
80 
89 #define ADC19_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
90 #define ADC19_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
91  // adc19_set
93 
108 #define ADC19_MAP_MIKROBUS( cfg, mikrobus ) \
109  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
110  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
111  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
112  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
113  // adc19_map // adc19
116 
121 typedef struct
122 {
123  // Modules
124  spi_master_t spi;
126  pin_name_t chip_select;
128  float vref;
130 } adc19_t;
131 
136 typedef struct
137 {
138  // Communication gpio pins
139  pin_name_t miso;
140  pin_name_t mosi;
141  pin_name_t sck;
142  pin_name_t cs;
144  // static variable
145  uint32_t spi_speed;
146  spi_master_mode_t spi_mode;
147  spi_master_chip_select_polarity_t cs_polarity;
149 } adc19_cfg_t;
150 
155 typedef enum
156 {
157  ADC19_OK = 0,
158  ADC19_ERROR = -1
159 
161 
178 
192 err_t adc19_init ( adc19_t *ctx, adc19_cfg_t *cfg );
193 
203 void adc19_set_vref ( adc19_t *ctx, float vref );
204 
216 err_t adc19_set_input_channel ( adc19_t *ctx, uint8_t input_ch );
217 
230 err_t adc19_get_voltage ( adc19_t *ctx, float *voltage );
231 
232 #ifdef __cplusplus
233 }
234 #endif
235 #endif // ADC19_H
236  // adc19
238 
239 // ------------------------------------------------------------------------ END
adc19_cfg_t::sck
pin_name_t sck
Definition: adc19.h:141
ADC19_ERROR
@ ADC19_ERROR
Definition: adc19.h:158
spi_specifics.h
This file contains SPI specific macros, functions, etc.
adc19_cfg_setup
void adc19_cfg_setup(adc19_cfg_t *cfg)
ADC 19 configuration object setup function.
adc19_t::vref
float vref
Definition: adc19.h:128
ADC19_OK
@ ADC19_OK
Definition: adc19.h:157
adc19_cfg_t::spi_speed
uint32_t spi_speed
Definition: adc19.h:145
adc19_t::spi
spi_master_t spi
Definition: adc19.h:124
adc19_get_voltage
err_t adc19_get_voltage(adc19_t *ctx, float *voltage)
ADC 19 get voltage function.
adc19_cfg_t
ADC 19 Click configuration object.
Definition: adc19.h:137
adc19_cfg_t::cs
pin_name_t cs
Definition: adc19.h:142
adc19_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: adc19.h:147
adc19_set_input_channel
err_t adc19_set_input_channel(adc19_t *ctx, uint8_t input_ch)
ADC 19 set input channel function.
adc19_cfg_t::mosi
pin_name_t mosi
Definition: adc19.h:140
adc19_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: adc19.h:146
adc19_init
err_t adc19_init(adc19_t *ctx, adc19_cfg_t *cfg)
ADC 19 initialization function.
adc19_t::chip_select
pin_name_t chip_select
Definition: adc19.h:126
adc19_set_vref
void adc19_set_vref(adc19_t *ctx, float vref)
ADC 19 set vref function.
adc19_return_value_t
adc19_return_value_t
ADC 19 Click return value data.
Definition: adc19.h:156
adc19_t
ADC 19 Click context object.
Definition: adc19.h:122
adc19_cfg_t::miso
pin_name_t miso
Definition: adc19.h:139