adc11  2.0.0.0
adc11.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 ADC11_H
29 #define ADC11_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_spi_master.h"
51 
73 #define ADC11_MAP_MIKROBUS( cfg, mikrobus ) \
74  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
75  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
76  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
77  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
78  // adc11_map // adc11
81 
86 typedef struct
87 {
88  // Modules
89 
90  spi_master_t spi;
92  pin_name_t chip_select;
94 } adc11_t;
95 
100 typedef struct
101 {
102  // Communication gpio pins
103 
104  pin_name_t miso;
105  pin_name_t mosi;
106  pin_name_t sck;
107  pin_name_t cs;
109  // static variable
110 
111  uint32_t spi_speed;
112  spi_master_mode_t spi_mode;
113  spi_master_chip_select_polarity_t cs_polarity;
115 } adc11_cfg_t;
116 
121 typedef struct
122 {
123  uint16_t zero_adc_val;
124 
126 
131 typedef enum
132 {
133  ADC11_OK = 0,
134  ADC11_ERROR = -1
135 
137 
154 
169 err_t adc11_init ( adc11_t *ctx, adc11_cfg_t *cfg );
170 
185 err_t adc11_generic_read ( adc11_t *ctx, uint16_t *adc_data );
186 
203 
220 
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 #endif // ADC11_H
226  // adc11
228 
229 // ------------------------------------------------------------------------ END
voltage
float voltage
Definition: main.c:33
adc11_cfg_t::sck
pin_name_t sck
Definition: adc11.h:106
adc11_calibration_data_t
ADC 11 Click calibration object.
Definition: adc11.h:122
adc11_cfg_t::miso
pin_name_t miso
Definition: adc11.h:104
adc11_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: adc11.h:112
adc11_calibration_data_t::zero_adc_val
uint16_t zero_adc_val
Definition: adc11.h:123
adc11_generic_read
err_t adc11_generic_read(adc11_t *ctx, uint16_t *adc_data)
ADC 11 data reading function.
adc11_cfg_setup
void adc11_cfg_setup(adc11_cfg_t *cfg)
ADC 11 configuration object setup function.
adc11_t::chip_select
pin_name_t chip_select
Definition: adc11.h:92
adc11_cfg_t::mosi
pin_name_t mosi
Definition: adc11.h:105
ADC11_OK
@ ADC11_OK
Definition: adc11.h:133
adc11_cfg_t
ADC 11 Click configuration object.
Definition: adc11.h:101
adc11_return_value_t
adc11_return_value_t
ADC 11 Click return value data.
Definition: adc11.h:132
adc11_t
ADC 11 Click context object.
Definition: adc11.h:87
adc11_init
err_t adc11_init(adc11_t *ctx, adc11_cfg_t *cfg)
ADC 11 initialization function.
adc11_cfg_t::cs
pin_name_t cs
Definition: adc11.h:107
adc11_get_voltage
err_t adc11_get_voltage(adc11_t *ctx, adc11_calibration_data_t *adc_val, float *voltage)
ADC 11 get voltage function.
adc11_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: adc11.h:113
ADC11_ERROR
@ ADC11_ERROR
Definition: adc11.h:134
adc11_t::spi
spi_master_t spi
Definition: adc11.h:90
adc11_set_calibration
err_t adc11_set_calibration(adc11_t *ctx, adc11_calibration_data_t *adc_val)
ADC 11 set calibration function.
adc_data
uint16_t adc_data
Definition: main.c:35
adc11_cfg_t::spi_speed
uint32_t spi_speed
Definition: adc11.h:111