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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define ADC19_INPUT_CHANNEL_1 1
61 #define ADC19_INPUT_CHANNEL_2 2
62 
67 #define ADC19_RESOLUTION_12BIT 0x0FFF
68 #define ADC19_VREF_3V3 3.3
69 #define ADC19_VREF_5V 5.0
70 
79 #define ADC19_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
80 #define ADC19_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
81  // adc19_set
83 
98 #define ADC19_MAP_MIKROBUS( cfg, mikrobus ) \
99  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
100  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
101  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
102  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
103  // adc19_map // adc19
106 
111 typedef struct
112 {
113  // Modules
114  spi_master_t spi;
116  pin_name_t chip_select;
118  float vref;
120 } adc19_t;
121 
126 typedef struct
127 {
128  // Communication gpio pins
129  pin_name_t miso;
130  pin_name_t mosi;
131  pin_name_t sck;
132  pin_name_t cs;
134  // static variable
135  uint32_t spi_speed;
136  spi_master_mode_t spi_mode;
137  spi_master_chip_select_polarity_t cs_polarity;
139 } adc19_cfg_t;
140 
145 typedef enum
146 {
147  ADC19_OK = 0,
148  ADC19_ERROR = -1
149 
151 
168 
182 err_t adc19_init ( adc19_t *ctx, adc19_cfg_t *cfg );
183 
193 void adc19_set_vref ( adc19_t *ctx, float vref );
194 
206 err_t adc19_set_input_channel ( adc19_t *ctx, uint8_t input_ch );
207 
220 err_t adc19_get_voltage ( adc19_t *ctx, float *voltage );
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 #endif // ADC19_H
226  // adc19
228 
229 // ------------------------------------------------------------------------ END
adc19_cfg_t::sck
pin_name_t sck
Definition: adc19.h:131
ADC19_ERROR
@ ADC19_ERROR
Definition: adc19.h:148
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:118
ADC19_OK
@ ADC19_OK
Definition: adc19.h:147
adc19_cfg_t::spi_speed
uint32_t spi_speed
Definition: adc19.h:135
adc19_t::spi
spi_master_t spi
Definition: adc19.h:114
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:127
adc19_cfg_t::cs
pin_name_t cs
Definition: adc19.h:132
adc19_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: adc19.h:137
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:130
adc19_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: adc19.h:136
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:116
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:146
adc19_t
ADC 19 Click context object.
Definition: adc19.h:112
adc19_cfg_t::miso
pin_name_t miso
Definition: adc19.h:129