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 );
79#define ADC2_RETVAL uint8_t
80
81#define ADC2_OK 0x00
82#define ADC2_INIT_ERROR 0xFF
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
99 // End group macro
100// --------------------------------------------------------------- PUBLIC TYPES
109typedef 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
127typedef 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
144 // End types group
145// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
146
151#ifdef __cplusplus
152extern "C"{
153#endif
154
164
174
185
194void adc2_set_vref ( adc2_t *ctx, float vref );
195
196#ifdef __cplusplus
197}
198#endif
199#endif // _ADC2_H_
200
201 // End public_function group
203
204// ------------------------------------------------------------------------- END
#define ADC2_RETVAL
Definition adc2.h:79
void adc2_set_vref(adc2_t *ctx, float vref)
Setting reference voltage.
float adc2_read_adc_data(adc2_t *ctx)
Read adc data function.
void adc2_cfg_setup(adc2_cfg_t *cfg)
Config Object Initialization function.
ADC2_RETVAL adc2_init(adc2_t *ctx, adc2_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition adc2.h:128
spi_master_chip_select_polarity_t cs_polarity
Definition adc2.h:140
pin_name_t sck
Definition adc2.h:133
spi_master_mode_t spi_mode
Definition adc2.h:139
pin_name_t mosi
Definition adc2.h:132
uint32_t spi_speed
Definition adc2.h:138
pin_name_t miso
Definition adc2.h:131
pin_name_t cs
Definition adc2.h:134
Click ctx object definition.
Definition adc2.h:110
digital_out_t cs
Definition adc2.h:111
uint8_t ovf_l
Definition adc2.h:120
spi_master_t spi
Definition adc2.h:115
float vref
Definition adc2.h:118
uint8_t ovf_h
Definition adc2.h:119
pin_name_t chip_select
Definition adc2.h:116