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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define ADC_MASK 0x0FFF
71 #define ADC_RES 4095
72 #define VREF 2500
73 
82 #define ISOADC2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
83 #define ISOADC2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
84  // isoadc2_set
86 
101 #define ISOADC2_MAP_MIKROBUS( cfg, mikrobus ) \
102  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
103  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
104  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
105  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
106  cfg.crt = MIKROBUS( mikrobus, MIKROBUS_RST )
107  // isoadc2_map // isoadc2
110 
115 typedef struct
116 {
117  // Output pins
118  digital_out_t crt;
120  // Modules
121  spi_master_t spi;
123  pin_name_t chip_select;
125 } isoadc2_t;
126 
131 typedef struct
132 {
133  // Communication gpio pins
134  pin_name_t miso;
135  pin_name_t mosi;
136  pin_name_t sck;
137  pin_name_t cs;
139  // Additional gpio pins
140  pin_name_t crt;
142  // Static variable
143  uint32_t spi_speed;
144  spi_master_mode_t spi_mode;
145  spi_master_chip_select_polarity_t cs_polarity;
147 } isoadc2_cfg_t;
148 
153 typedef enum
154 {
156  ISOADC2_ERROR = -1
157 
159 
176 
190 err_t isoadc2_init ( isoadc2_t *ctx, isoadc2_cfg_t *cfg );
191 
206 err_t isoadc2_generic_write ( isoadc2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
207 
222 err_t isoadc2_generic_read ( isoadc2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
223 
235 err_t isoadc2_read_adc ( isoadc2_t *ctx, uint16_t *adc_val );
236 
248 err_t isoadc2_get_mv ( isoadc2_t *ctx, uint16_t *voltage );
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif // ISOADC2_H
254  // isoadc2
256 
257 // ------------------------------------------------------------------------ END
isoadc2_cfg_t::cs
pin_name_t cs
Definition: isoadc2.h:137
ISOADC2_ERROR
@ ISOADC2_ERROR
Definition: isoadc2.h:156
isoadc2_t
ISO ADC 2 Click context object.
Definition: isoadc2.h:116
spi_specifics.h
This file contains SPI specific macros, functions, etc.
isoadc2_read_adc
err_t isoadc2_read_adc(isoadc2_t *ctx, uint16_t *adc_val)
ISO ADC 2 ADC data reading function.
isoadc2_get_mv
err_t isoadc2_get_mv(isoadc2_t *ctx, uint16_t *voltage)
ISO ADC 2 voltage data reading function.
isoadc2_cfg_setup
void isoadc2_cfg_setup(isoadc2_cfg_t *cfg)
ISO ADC 2 configuration object setup function.
isoadc2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: isoadc2.h:145
isoadc2_cfg_t::miso
pin_name_t miso
Definition: isoadc2.h:134
ISOADC2_OK
@ ISOADC2_OK
Definition: isoadc2.h:155
isoadc2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: isoadc2.h:144
isoadc2_cfg_t::crt
pin_name_t crt
Definition: isoadc2.h:140
isoadc2_cfg_t::spi_speed
uint32_t spi_speed
Definition: isoadc2.h:143
isoadc2_cfg_t
ISO ADC 2 Click configuration object.
Definition: isoadc2.h:132
isoadc2_generic_write
err_t isoadc2_generic_write(isoadc2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
ISO ADC 2 data writing function.
isoadc2_return_value_t
isoadc2_return_value_t
ISO ADC 2 Click return value data.
Definition: isoadc2.h:154
isoadc2_cfg_t::sck
pin_name_t sck
Definition: isoadc2.h:136
isoadc2_init
err_t isoadc2_init(isoadc2_t *ctx, isoadc2_cfg_t *cfg)
ISO ADC 2 initialization function.
isoadc2_t::crt
digital_out_t crt
Definition: isoadc2.h:118
isoadc2_generic_read
err_t isoadc2_generic_read(isoadc2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
ISO ADC 2 data reading function.
isoadc2_cfg_t::mosi
pin_name_t mosi
Definition: isoadc2.h:135
isoadc2_t::spi
spi_master_t spi
Definition: isoadc2.h:121
isoadc2_t::chip_select
pin_name_t chip_select
Definition: isoadc2.h:123