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 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define ADC19_INPUT_CHANNEL_1 1
75 #define ADC19_INPUT_CHANNEL_2 2
76 
81 #define ADC19_RESOLUTION_12BIT 0x0FFF
82 #define ADC19_VREF_3V3 3.3
83 #define ADC19_VREF_5V 5.0
84 
93 #define ADC19_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
94 #define ADC19_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
95  // adc19_set
97 
112 #define ADC19_MAP_MIKROBUS( cfg, mikrobus ) \
113  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
114  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
115  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
116  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
117  // adc19_map // adc19
120 
125 typedef struct
126 {
127  // Modules
128  spi_master_t spi;
130  pin_name_t chip_select;
132  float vref;
134 } adc19_t;
135 
140 typedef struct
141 {
142  // Communication gpio pins
143  pin_name_t miso;
144  pin_name_t mosi;
145  pin_name_t sck;
146  pin_name_t cs;
148  // static variable
149  uint32_t spi_speed;
150  spi_master_mode_t spi_mode;
151  spi_master_chip_select_polarity_t cs_polarity;
153 } adc19_cfg_t;
154 
159 typedef enum
160 {
161  ADC19_OK = 0,
162  ADC19_ERROR = -1
163 
165 
182 
196 err_t adc19_init ( adc19_t *ctx, adc19_cfg_t *cfg );
197 
207 void adc19_set_vref ( adc19_t *ctx, float vref );
208 
220 err_t adc19_set_input_channel ( adc19_t *ctx, uint8_t input_ch );
221 
234 err_t adc19_get_voltage ( adc19_t *ctx, float *voltage );
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 #endif // ADC19_H
240  // adc19
242 
243 // ------------------------------------------------------------------------ END
adc19_cfg_t::sck
pin_name_t sck
Definition: adc19.h:145
ADC19_ERROR
@ ADC19_ERROR
Definition: adc19.h:162
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:132
ADC19_OK
@ ADC19_OK
Definition: adc19.h:161
adc19_cfg_t::spi_speed
uint32_t spi_speed
Definition: adc19.h:149
adc19_t::spi
spi_master_t spi
Definition: adc19.h:128
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:141
adc19_cfg_t::cs
pin_name_t cs
Definition: adc19.h:146
adc19_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: adc19.h:151
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:144
adc19_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: adc19.h:150
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:130
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:160
adc19_t
ADC 19 Click context object.
Definition: adc19.h:126
adc19_cfg_t::miso
pin_name_t miso
Definition: adc19.h:143