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 
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_spi_master.h"
47 
69 #define ADC11_MAP_MIKROBUS( cfg, mikrobus ) \
70  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
71  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
72  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
73  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
74  // adc11_map // adc11
77 
82 typedef struct
83 {
84  // Modules
85 
86  spi_master_t spi;
88  pin_name_t chip_select;
90 } adc11_t;
91 
96 typedef struct
97 {
98  // Communication gpio pins
99 
100  pin_name_t miso;
101  pin_name_t mosi;
102  pin_name_t sck;
103  pin_name_t cs;
105  // static variable
106 
107  uint32_t spi_speed;
108  spi_master_mode_t spi_mode;
109  spi_master_chip_select_polarity_t cs_polarity;
111 } adc11_cfg_t;
112 
117 typedef struct
118 {
119  uint16_t zero_adc_val;
120 
122 
127 typedef enum
128 {
129  ADC11_OK = 0,
130  ADC11_ERROR = -1
131 
133 
150 
165 err_t adc11_init ( adc11_t *ctx, adc11_cfg_t *cfg );
166 
181 err_t adc11_generic_read ( adc11_t *ctx, uint16_t *adc_data );
182 
199 
216 
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 #endif // ADC11_H
222  // adc11
224 
225 // ------------------------------------------------------------------------ END
voltage
float voltage
Definition: main.c:33
adc11_cfg_t::sck
pin_name_t sck
Definition: adc11.h:102
adc11_calibration_data_t
ADC 11 Click calibration object.
Definition: adc11.h:118
adc11_cfg_t::miso
pin_name_t miso
Definition: adc11.h:100
adc11_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: adc11.h:108
adc11_calibration_data_t::zero_adc_val
uint16_t zero_adc_val
Definition: adc11.h:119
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:88
adc11_cfg_t::mosi
pin_name_t mosi
Definition: adc11.h:101
ADC11_OK
@ ADC11_OK
Definition: adc11.h:129
adc11_cfg_t
ADC 11 Click configuration object.
Definition: adc11.h:97
adc11_return_value_t
adc11_return_value_t
ADC 11 Click return value data.
Definition: adc11.h:128
adc11_t
ADC 11 Click context object.
Definition: adc11.h:83
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:103
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:109
ADC11_ERROR
@ ADC11_ERROR
Definition: adc11.h:130
adc11_t::spi
spi_master_t spi
Definition: adc11.h:86
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:107