ozone2  2.0.0.0
ozone2.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 OZONE2_H
36 #define OZONE2_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_analog_in.h"
53 #include "drv_digital_in.h"
54 #include "drv_spi_master.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define OZONE2_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
68  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
69  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
70  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
71  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
72 
78 #define OZONE2_OK 0
79 #define OZONE2_INIT_ERROR (-1)
80  // End group macro
83 // --------------------------------------------------------------- PUBLIC TYPES
92 typedef enum
93 {
96 
98 
102 typedef struct
103 {
104  // Input pins objects
105 
106  analog_in_t an;
107  digital_in_t miso;
108 
109  // Module object
110 
111  spi_master_t spi;
112  pin_name_t chip_select;
113 
114  // ADC selection
115 
117 
118 } ozone2_t;
119 
123 typedef struct
124 {
125  // Communication gpio pins
126 
127  pin_name_t miso;
128  pin_name_t mosi;
129  pin_name_t sck;
130  pin_name_t cs;
131 
132  // Additional gpio pins
133 
134  pin_name_t an;
135 
136  // SPI settings
137 
138  uint32_t spi_speed;
139  spi_master_mode_t spi_mode;
140  spi_master_chip_select_polarity_t cs_polarity;
141 
142  // ADC settings
143 
144  analog_in_resolution_t resolution;
145  float vref;
146 
147  // ADC selection
148 
150 
151 } ozone2_cfg_t;
152 
153 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
159 #ifdef __cplusplus
160 extern "C"{
161 #endif
162 
173 
185 err_t ozone2_init ( ozone2_t *ctx, ozone2_cfg_t *cfg );
186 
197 err_t ozone2_read_signal_voltage ( ozone2_t *ctx, float *data_out );
198 
210 err_t ozone2_read_measurement ( ozone2_t *ctx, uint16_t *data_out );
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 #endif // OZONE2_H
216  // End public_function group // End click Driver group
219 
220 // ------------------------------------------------------------------------ END
ozone2_init
err_t ozone2_init(ozone2_t *ctx, ozone2_cfg_t *cfg)
Initialization function.
ozone2_adc_sel_t
ozone2_adc_sel_t
Click AD conversion type selectors.
Definition: ozone2.h:93
OZONE2_ADC_SEL_SPI
@ OZONE2_ADC_SEL_SPI
Definition: ozone2.h:95
ozone2_read_measurement
err_t ozone2_read_measurement(ozone2_t *ctx, uint16_t *data_out)
Measurement Read function.
ozone2_cfg_t::cs
pin_name_t cs
Definition: ozone2.h:130
ozone2_t::spi
spi_master_t spi
Definition: ozone2.h:111
ozone2_read_signal_voltage
err_t ozone2_read_signal_voltage(ozone2_t *ctx, float *data_out)
Measurement Voltage Read function.
ozone2_cfg_t::miso
pin_name_t miso
Definition: ozone2.h:127
ozone2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ozone2.h:140
ozone2_cfg_t::mosi
pin_name_t mosi
Definition: ozone2.h:128
OZONE2_ADC_SEL_AN
@ OZONE2_ADC_SEL_AN
Definition: ozone2.h:94
ozone2_t::miso
digital_in_t miso
Definition: ozone2.h:107
ozone2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: ozone2.h:139
ozone2_cfg_t::an
pin_name_t an
Definition: ozone2.h:134
ozone2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ozone2.h:144
ozone2_t::chip_select
pin_name_t chip_select
Definition: ozone2.h:112
ozone2_t::adc_sel
ozone2_adc_sel_t adc_sel
Definition: ozone2.h:116
ozone2_t::an
analog_in_t an
Definition: ozone2.h:106
ozone2_cfg_t::sck
pin_name_t sck
Definition: ozone2.h:129
ozone2_cfg_t::vref
float vref
Definition: ozone2.h:145
ozone2_t
Click ctx object definition.
Definition: ozone2.h:103
ozone2_cfg_setup
void ozone2_cfg_setup(ozone2_cfg_t *cfg)
Config Object Initialization function.
ozone2_cfg_t::spi_speed
uint32_t spi_speed
Definition: ozone2.h:138
ozone2_cfg_t
Click configuration structure definition.
Definition: ozone2.h:124