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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define ADC_MASK 0x0FFF
61 #define ADC_RES 4095
62 #define VREF 2500
63 
72 #define ISOADC2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
73 #define ISOADC2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
74  // isoadc2_set
76 
91 #define ISOADC2_MAP_MIKROBUS( cfg, mikrobus ) \
92  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
93  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
94  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
95  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
96  cfg.crt = MIKROBUS( mikrobus, MIKROBUS_RST )
97  // isoadc2_map // isoadc2
100 
105 typedef struct
106 {
107  // Output pins
108  digital_out_t crt;
110  // Modules
111  spi_master_t spi;
113  pin_name_t chip_select;
115 } isoadc2_t;
116 
121 typedef struct
122 {
123  // Communication gpio pins
124  pin_name_t miso;
125  pin_name_t mosi;
126  pin_name_t sck;
127  pin_name_t cs;
129  // Additional gpio pins
130  pin_name_t crt;
132  // Static variable
133  uint32_t spi_speed;
134  spi_master_mode_t spi_mode;
135  spi_master_chip_select_polarity_t cs_polarity;
137 } isoadc2_cfg_t;
138 
143 typedef enum
144 {
146  ISOADC2_ERROR = -1
147 
149 
166 
180 err_t isoadc2_init ( isoadc2_t *ctx, isoadc2_cfg_t *cfg );
181 
196 err_t isoadc2_generic_write ( isoadc2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
197 
212 err_t isoadc2_generic_read ( isoadc2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
213 
225 err_t isoadc2_read_adc ( isoadc2_t *ctx, uint16_t *adc_val );
226 
238 err_t isoadc2_get_mv ( isoadc2_t *ctx, uint16_t *voltage );
239 
240 #ifdef __cplusplus
241 }
242 #endif
243 #endif // ISOADC2_H
244  // isoadc2
246 
247 // ------------------------------------------------------------------------ END
isoadc2_cfg_t::cs
pin_name_t cs
Definition: isoadc2.h:127
ISOADC2_ERROR
@ ISOADC2_ERROR
Definition: isoadc2.h:146
isoadc2_t
ISO ADC 2 Click context object.
Definition: isoadc2.h:106
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:135
isoadc2_cfg_t::miso
pin_name_t miso
Definition: isoadc2.h:124
ISOADC2_OK
@ ISOADC2_OK
Definition: isoadc2.h:145
isoadc2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: isoadc2.h:134
isoadc2_cfg_t::crt
pin_name_t crt
Definition: isoadc2.h:130
isoadc2_cfg_t::spi_speed
uint32_t spi_speed
Definition: isoadc2.h:133
isoadc2_cfg_t
ISO ADC 2 Click configuration object.
Definition: isoadc2.h:122
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:144
isoadc2_cfg_t::sck
pin_name_t sck
Definition: isoadc2.h:126
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:108
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:125
isoadc2_t::spi
spi_master_t spi
Definition: isoadc2.h:111
isoadc2_t::chip_select
pin_name_t chip_select
Definition: isoadc2.h:113