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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_analog_in.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define OZONE2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
64  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
65  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
66  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN )
68 
74 #define OZONE2_OK 0
75 #define OZONE2_INIT_ERROR (-1)
76  // End group macro
79 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef enum
89 {
92 
94 
98 typedef struct
99 {
100  // Input pins objects
101 
102  analog_in_t an;
103  digital_in_t miso;
104 
105  // Module object
106 
107  spi_master_t spi;
108  pin_name_t chip_select;
109 
110  // ADC selection
111 
113 
114 } ozone2_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122 
123  pin_name_t miso;
124  pin_name_t mosi;
125  pin_name_t sck;
126  pin_name_t cs;
127 
128  // Additional gpio pins
129 
130  pin_name_t an;
131 
132  // SPI settings
133 
134  uint32_t spi_speed;
135  spi_master_mode_t spi_mode;
136  spi_master_chip_select_polarity_t cs_polarity;
137 
138  // ADC settings
139 
140  analog_in_resolution_t resolution;
141  float vref;
142 
143  // ADC selection
144 
146 
147 } ozone2_cfg_t;
148 
149 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
155 #ifdef __cplusplus
156 extern "C"{
157 #endif
158 
169 
181 err_t ozone2_init ( ozone2_t *ctx, ozone2_cfg_t *cfg );
182 
193 err_t ozone2_read_signal_voltage ( ozone2_t *ctx, float *data_out );
194 
206 err_t ozone2_read_measurement ( ozone2_t *ctx, uint16_t *data_out );
207 
208 #ifdef __cplusplus
209 }
210 #endif
211 #endif // OZONE2_H
212  // End public_function group // End click Driver group
215 
216 // ------------------------------------------------------------------------ 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:89
OZONE2_ADC_SEL_SPI
@ OZONE2_ADC_SEL_SPI
Definition: ozone2.h:91
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:126
ozone2_t::spi
spi_master_t spi
Definition: ozone2.h:107
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:123
ozone2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: ozone2.h:136
ozone2_cfg_t::mosi
pin_name_t mosi
Definition: ozone2.h:124
OZONE2_ADC_SEL_AN
@ OZONE2_ADC_SEL_AN
Definition: ozone2.h:90
ozone2_t::miso
digital_in_t miso
Definition: ozone2.h:103
ozone2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: ozone2.h:135
ozone2_cfg_t::an
pin_name_t an
Definition: ozone2.h:130
ozone2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: ozone2.h:140
ozone2_t::chip_select
pin_name_t chip_select
Definition: ozone2.h:108
ozone2_t::adc_sel
ozone2_adc_sel_t adc_sel
Definition: ozone2.h:112
ozone2_t::an
analog_in_t an
Definition: ozone2.h:102
ozone2_cfg_t::sck
pin_name_t sck
Definition: ozone2.h:125
ozone2_cfg_t::vref
float vref
Definition: ozone2.h:141
ozone2_t
Click ctx object definition.
Definition: ozone2.h:99
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:134
ozone2_cfg_t
Click configuration structure definition.
Definition: ozone2.h:120