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
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_spi_master.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
54#define ADC2_MAP_MIKROBUS( cfg, mikrobus ) \
55 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
65#define ADC2_RETVAL uint8_t
66
67#define ADC2_OK 0x00
68#define ADC2_INIT_ERROR 0xFF
72#define ADC2_VCC_3v3 3300.0
73#define ADC2_VCC_5V 5000.0
74#define ADC2_VCC_4v096 4096.0
75
80#define ADC2_INTERRUPT_FLAG -4000000
81#define ADC2_OVERFLOW_HIGH_FLAG 3000000
82#define ADC2_OVERFLOW_LOW_FLAG -3000000 // End group macro
86// --------------------------------------------------------------- PUBLIC TYPES
95typedef struct
96{
97 digital_out_t cs;
98
99 // Modules
100
101 spi_master_t spi;
102 pin_name_t chip_select;
103
104 float vref;
105 uint8_t ovf_h;
106 uint8_t ovf_l;
107
108} adc2_t;
109
113typedef struct
114{
115 // Communication gpio pins
116
117 pin_name_t miso;
118 pin_name_t mosi;
119 pin_name_t sck;
120 pin_name_t cs;
121
122 // static variable
123
124 uint32_t spi_speed;
125 spi_master_mode_t spi_mode;
126 spi_master_chip_select_polarity_t cs_polarity;
127
128} adc2_cfg_t;
129 // End types group
131// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
132
137#ifdef __cplusplus
138extern "C"{
139#endif
140
150
160
171
180void adc2_set_vref ( adc2_t *ctx, float vref );
181
182#ifdef __cplusplus
183}
184#endif
185#endif // _ADC2_H_
186 // End public_function group
189
190// ------------------------------------------------------------------------- END
#define ADC2_RETVAL
Definition: adc2.h:65
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:114
spi_master_chip_select_polarity_t cs_polarity
Definition: adc2.h:126
pin_name_t sck
Definition: adc2.h:119
spi_master_mode_t spi_mode
Definition: adc2.h:125
pin_name_t mosi
Definition: adc2.h:118
uint32_t spi_speed
Definition: adc2.h:124
pin_name_t miso
Definition: adc2.h:117
pin_name_t cs
Definition: adc2.h:120
Click ctx object definition.
Definition: adc2.h:96
digital_out_t cs
Definition: adc2.h:97
uint8_t ovf_l
Definition: adc2.h:106
spi_master_t spi
Definition: adc2.h:101
float vref
Definition: adc2.h:104
uint8_t ovf_h
Definition: adc2.h:105
pin_name_t chip_select
Definition: adc2.h:102