isoadc2 2.0.0.0
isoadc2.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 ISOADC2_H
29#define ISOADC2_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 ADC_MASK 0x0FFF
75#define ADC_RES 4095
76#define VREF 2500
77
86#define ISOADC2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
87#define ISOADC2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
88
89 // isoadc2_set
90
105#define ISOADC2_MAP_MIKROBUS( cfg, mikrobus ) \
106 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
107 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
108 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
109 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
110 cfg.crt = MIKROBUS( mikrobus, MIKROBUS_RST )
111
112 // isoadc2_map
113 // isoadc2
114
119typedef struct
120{
121 // Output pins
122 digital_out_t crt;
124 // Modules
125 spi_master_t spi;
127 pin_name_t chip_select;
129} isoadc2_t;
130
135typedef struct
136{
137 // Communication gpio pins
138 pin_name_t miso;
139 pin_name_t mosi;
140 pin_name_t sck;
141 pin_name_t cs;
143 // Additional gpio pins
144 pin_name_t crt;
146 // Static variable
147 uint32_t spi_speed;
148 spi_master_mode_t spi_mode;
149 spi_master_chip_select_polarity_t cs_polarity;
152
157typedef enum
158{
160 ISOADC2_ERROR = -1
161
163
180
195
210err_t isoadc2_generic_write ( isoadc2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
211
226err_t isoadc2_generic_read ( isoadc2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
227
239err_t isoadc2_read_adc ( isoadc2_t *ctx, uint16_t *adc_val );
240
252err_t isoadc2_get_mv ( isoadc2_t *ctx, uint16_t *voltage );
253
254#ifdef __cplusplus
255}
256#endif
257#endif // ISOADC2_H
258
259 // isoadc2
260
261// ------------------------------------------------------------------------ END
err_t isoadc2_generic_write(isoadc2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
ISO ADC 2 data writing function.
err_t isoadc2_read_adc(isoadc2_t *ctx, uint16_t *adc_val)
ISO ADC 2 ADC data reading function.
err_t isoadc2_generic_read(isoadc2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
ISO ADC 2 data reading function.
err_t isoadc2_get_mv(isoadc2_t *ctx, uint16_t *voltage)
ISO ADC 2 voltage data reading function.
err_t isoadc2_init(isoadc2_t *ctx, isoadc2_cfg_t *cfg)
ISO ADC 2 initialization function.
void isoadc2_cfg_setup(isoadc2_cfg_t *cfg)
ISO ADC 2 configuration object setup function.
isoadc2_return_value_t
ISO ADC 2 Click return value data.
Definition isoadc2.h:158
@ ISOADC2_OK
Definition isoadc2.h:159
@ ISOADC2_ERROR
Definition isoadc2.h:160
This file contains SPI specific macros, functions, etc.
ISO ADC 2 Click configuration object.
Definition isoadc2.h:136
pin_name_t crt
Definition isoadc2.h:144
spi_master_chip_select_polarity_t cs_polarity
Definition isoadc2.h:149
pin_name_t sck
Definition isoadc2.h:140
spi_master_mode_t spi_mode
Definition isoadc2.h:148
pin_name_t mosi
Definition isoadc2.h:139
uint32_t spi_speed
Definition isoadc2.h:147
pin_name_t miso
Definition isoadc2.h:138
pin_name_t cs
Definition isoadc2.h:141
ISO ADC 2 Click context object.
Definition isoadc2.h:120
spi_master_t spi
Definition isoadc2.h:125
digital_out_t crt
Definition isoadc2.h:122
pin_name_t chip_select
Definition isoadc2.h:127