adc21 2.1.0.0
adc21.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 ADC21_H
29#define ADC21_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52#include "spi_specifics.h"
53
74#define ADC21_CHANNEL_0 0
75#define ADC21_CHANNEL_1 1
76#define ADC21_CHANNEL_2 2
77#define ADC21_CHANNEL_3 3
78#define ADC21_CHANNEL_4 4
79#define ADC21_CHANNEL_5 5
80#define ADC21_CHANNEL_6 6
81#define ADC21_CHANNEL_7 7
82
87#define ADC21_DATA_RESOLUTION 0x0FFF
88#define ADC21_AVCC_3V3 3.3
89#define ADC21_AVCC_5V 5.0
90
99#define ADC21_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
100#define ADC21_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
101
102 // adc21_set
103
118#define ADC21_MAP_MIKROBUS( cfg, mikrobus ) \
119 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
120 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
121 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
122 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS );
123
124 // adc21_map
125 // adc21
126
131typedef struct
132{
133 // Modules
134 spi_master_t spi;
136 pin_name_t chip_select;
138} adc21_t;
139
144typedef struct
145{
146 // Communication gpio pins
147 pin_name_t miso;
148 pin_name_t mosi;
149 pin_name_t sck;
150 pin_name_t cs;
152 // static variable
153 uint32_t spi_speed;
154 spi_master_mode_t spi_mode;
155 spi_master_chip_select_polarity_t cs_polarity;
158
163typedef enum
164{
166 ADC21_ERROR = -1
167
169
186
200err_t adc21_init ( adc21_t *ctx, adc21_cfg_t *cfg );
201
214err_t adc21_read_raw_adc ( adc21_t *ctx, uint8_t channel, uint16_t *raw_adc );
215
230err_t adc21_read_voltage ( adc21_t *ctx, uint8_t channel, float avcc, float *voltage );
231
232#ifdef __cplusplus
233}
234#endif
235#endif // ADC21_H
236
237 // adc21
238
239// ------------------------------------------------------------------------ END
adc21_return_value_t
ADC 21 Click return value data.
Definition adc21.h:164
@ ADC21_ERROR
Definition adc21.h:166
@ ADC21_OK
Definition adc21.h:165
err_t adc21_init(adc21_t *ctx, adc21_cfg_t *cfg)
ADC 21 initialization function.
err_t adc21_read_raw_adc(adc21_t *ctx, uint8_t channel, uint16_t *raw_adc)
ADC 21 read raw adc function.
void adc21_cfg_setup(adc21_cfg_t *cfg)
ADC 21 configuration object setup function.
err_t adc21_read_voltage(adc21_t *ctx, uint8_t channel, float avcc, float *voltage)
ADC 21 read voltage function.
This file contains SPI specific macros, functions, etc.
ADC 21 Click configuration object.
Definition adc21.h:145
spi_master_chip_select_polarity_t cs_polarity
Definition adc21.h:155
pin_name_t sck
Definition adc21.h:149
spi_master_mode_t spi_mode
Definition adc21.h:154
pin_name_t mosi
Definition adc21.h:148
uint32_t spi_speed
Definition adc21.h:153
pin_name_t miso
Definition adc21.h:147
pin_name_t cs
Definition adc21.h:150
ADC 21 Click context object.
Definition adc21.h:132
spi_master_t spi
Definition adc21.h:134
pin_name_t chip_select
Definition adc21.h:136