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 "drv_digital_out.h"
36 #include "drv_spi_master.h"
37 
59 #define ADC11_MAP_MIKROBUS( cfg, mikrobus ) \
60  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
61  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
62  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
63  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
64  // adc11_map // adc11
67 
72 typedef struct
73 {
74  // Modules
75 
76  spi_master_t spi;
78  pin_name_t chip_select;
80 } adc11_t;
81 
86 typedef struct
87 {
88  // Communication gpio pins
89 
90  pin_name_t miso;
91  pin_name_t mosi;
92  pin_name_t sck;
93  pin_name_t cs;
95  // static variable
96 
97  uint32_t spi_speed;
98  spi_master_mode_t spi_mode;
99  spi_master_chip_select_polarity_t cs_polarity;
101 } adc11_cfg_t;
102 
107 typedef struct
108 {
109  uint16_t zero_adc_val;
110 
112 
117 typedef enum
118 {
119  ADC11_OK = 0,
120  ADC11_ERROR = -1
121 
123 
140 
155 err_t adc11_init ( adc11_t *ctx, adc11_cfg_t *cfg );
156 
171 err_t adc11_generic_read ( adc11_t *ctx, uint16_t *adc_data );
172 
189 
206 
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 #endif // ADC11_H
212  // adc11
214 
215 // ------------------------------------------------------------------------ END
voltage
float voltage
Definition: main.c:33
adc11_cfg_t::sck
pin_name_t sck
Definition: adc11.h:92
adc11_calibration_data_t
ADC 11 Click calibration object.
Definition: adc11.h:108
adc11_cfg_t::miso
pin_name_t miso
Definition: adc11.h:90
adc11_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: adc11.h:98
adc11_calibration_data_t::zero_adc_val
uint16_t zero_adc_val
Definition: adc11.h:109
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:78
adc11_cfg_t::mosi
pin_name_t mosi
Definition: adc11.h:91
ADC11_OK
@ ADC11_OK
Definition: adc11.h:119
adc11_cfg_t
ADC 11 Click configuration object.
Definition: adc11.h:87
adc11_return_value_t
adc11_return_value_t
ADC 11 Click return value data.
Definition: adc11.h:118
adc11_t
ADC 11 Click context object.
Definition: adc11.h:73
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:93
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:99
ADC11_ERROR
@ ADC11_ERROR
Definition: adc11.h:120
adc11_t::spi
spi_master_t spi
Definition: adc11.h:76
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:97