adc2  2.0.0.0
adc2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef ADC2_H
36 #define ADC2_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_spi_master.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
68 #define ADC2_MAP_MIKROBUS( cfg, mikrobus ) \
69  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
73 
79 #define ADC2_RETVAL uint8_t
80 
81 #define ADC2_OK 0x00
82 #define ADC2_INIT_ERROR 0xFF
83 
86 #define ADC2_VCC_3v3 3300.0
87 #define ADC2_VCC_5V 5000.0
88 #define ADC2_VCC_4v096 4096.0
89 
94 #define ADC2_INTERRUPT_FLAG -4000000
95 #define ADC2_OVERFLOW_HIGH_FLAG 3000000
96 #define ADC2_OVERFLOW_LOW_FLAG -3000000
97  // End group macro
100 // --------------------------------------------------------------- PUBLIC TYPES
109 typedef struct
110 {
111  digital_out_t cs;
112 
113  // Modules
114 
115  spi_master_t spi;
116  pin_name_t chip_select;
117 
118  float vref;
119  uint8_t ovf_h;
120  uint8_t ovf_l;
121 
122 } adc2_t;
123 
127 typedef struct
128 {
129  // Communication gpio pins
130 
131  pin_name_t miso;
132  pin_name_t mosi;
133  pin_name_t sck;
134  pin_name_t cs;
135 
136  // static variable
137 
138  uint32_t spi_speed;
139  spi_master_mode_t spi_mode;
140  spi_master_chip_select_polarity_t cs_polarity;
141 
142 } adc2_cfg_t;
143  // End types group
145 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
146 
151 #ifdef __cplusplus
152 extern "C"{
153 #endif
154 
164 
174 
184 float adc2_read_adc_data ( adc2_t *ctx );
185 
194 void adc2_set_vref ( adc2_t *ctx, float vref );
195 
196 #ifdef __cplusplus
197 }
198 #endif
199 #endif // _ADC2_H_
200  // End public_function group
203 
204 // ------------------------------------------------------------------------- END
adc2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: adc2.h:139
adc2_t::vref
float vref
Definition: adc2.h:118
adc2_t::ovf_l
uint8_t ovf_l
Definition: adc2.h:120
adc2_cfg_t::mosi
pin_name_t mosi
Definition: adc2.h:132
adc2_cfg_t::miso
pin_name_t miso
Definition: adc2.h:131
adc2_cfg_t::spi_speed
uint32_t spi_speed
Definition: adc2.h:138
adc2_t::ovf_h
uint8_t ovf_h
Definition: adc2.h:119
adc2_read_adc_data
float adc2_read_adc_data(adc2_t *ctx)
Read adc data function.
ADC2_RETVAL
#define ADC2_RETVAL
Definition: adc2.h:79
adc2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: adc2.h:140
adc2_t
Click ctx object definition.
Definition: adc2.h:110
adc2_t::spi
spi_master_t spi
Definition: adc2.h:115
adc2_cfg_setup
void adc2_cfg_setup(adc2_cfg_t *cfg)
Config Object Initialization function.
adc2_t::chip_select
pin_name_t chip_select
Definition: adc2.h:116
adc2_init
ADC2_RETVAL adc2_init(adc2_t *ctx, adc2_cfg_t *cfg)
Initialization function.
adc2_cfg_t::sck
pin_name_t sck
Definition: adc2.h:133
adc2_cfg_t
Click configuration structure definition.
Definition: adc2.h:128
adc2_set_vref
void adc2_set_vref(adc2_t *ctx, float vref)
Setting reference voltage.
adc2_cfg_t::cs
pin_name_t cs
Definition: adc2.h:134
adc2_t::cs
digital_out_t cs
Definition: adc2.h:111