uv  2.0.0.0
uv.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 UV_H
36 #define UV_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_spi_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define UV_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
63  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
64  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
65  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
68  // End group macro
71 // --------------------------------------------------------------- PUBLIC TYPES
80 typedef void ( *uv_callback_t )( uint8_t* );
81 
85 typedef struct
86 {
87  // Digital Output pins.
88  digital_out_t en;
89 
90  // Analog Input pins.
91  analog_in_t an;
92 
93  // Comm Modules.
94  spi_master_t spi;
95  pin_name_t chip_select;
96 
97  // Callback handler.
99 
100 } uv_t;
101 
105 typedef struct
106 {
107  // Communication gpio pins.
108  pin_name_t miso;
109  pin_name_t mosi;
110  pin_name_t sck;
111  pin_name_t cs;
112 
113  // Additional gpio pins.
114  pin_name_t an;
115  pin_name_t en;
116 
117  // Static variables.
118  uint32_t spi_speed;
119  spi_master_mode_t spi_mode;
120  spi_master_chip_select_polarity_t cs_polarity;
122  analog_in_resolution_t resolution;
123  float vref_value;
125 } uv_cfg_t;
126  // End group type
128 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
134 #ifdef __cplusplus
135 extern "C"{
136 #endif
137 
147 void uv_cfg_setup ( uv_cfg_t *cfg );
148 
162 err_t uv_init ( uv_t *ctx, uv_cfg_t *cfg );
163 
174 
187 err_t uv_read_adc_value ( uv_t *ctx, uint16_t *data_out );
188 
201 err_t uv_read_adc_voltage ( uv_t *ctx, float *data_out );
202 
217 err_t uv_read_an_pin_value ( uv_t *ctx, uint16_t *data_out );
218 
234 err_t uv_read_an_pin_voltage ( uv_t *ctx, float *data_out );
235 
249 void uv_calc_index ( uv_t *ctx, float data_in, uint8_t *data_out );
250 
258 void uv_device_enable ( uv_t *ctx );
259 
267 void uv_device_disable ( uv_t *ctx );
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 #endif // UV_H
273  // End public_function group
276 
277 // ------------------------------------------------------------------------- END
uv_t::spi
spi_master_t spi
Definition: uv.h:94
uv_cfg_t::vref_value
float vref_value
Definition: uv.h:123
uv_cfg_t::spi_speed
uint32_t spi_speed
Definition: uv.h:118
uv_t
Click context object definition.
Definition: uv.h:86
uv_device_disable
void uv_device_disable(uv_t *ctx)
Device Power OFF function.
uv_set_callback_handler
void uv_set_callback_handler(uv_t *ctx, uv_callback_t handler)
Callback Handler Setting function.
uv_cfg_t::miso
pin_name_t miso
Definition: uv.h:108
uv_cfg_t::an
pin_name_t an
Definition: uv.h:114
uv_read_adc_voltage
err_t uv_read_adc_voltage(uv_t *ctx, float *data_out)
ADC Voltage Reading function.
uv_read_an_pin_voltage
err_t uv_read_an_pin_voltage(uv_t *ctx, float *data_out)
AN Pin Voltage Reading function.
uv_cfg_t::sck
pin_name_t sck
Definition: uv.h:110
uv_t::handler
uv_callback_t handler
Definition: uv.h:98
uv_cfg_t::cs
pin_name_t cs
Definition: uv.h:111
uv_read_an_pin_value
err_t uv_read_an_pin_value(uv_t *ctx, uint16_t *data_out)
AN Pin Reading function.
uv_cfg_t::en
pin_name_t en
Definition: uv.h:115
uv_cfg_setup
void uv_cfg_setup(uv_cfg_t *cfg)
Config Object Initialization function.
uv_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: uv.h:119
uv_cfg_t::resolution
analog_in_resolution_t resolution
Definition: uv.h:122
uv_t::an
analog_in_t an
Definition: uv.h:91
uv_cfg_t::mosi
pin_name_t mosi
Definition: uv.h:109
uv_init
err_t uv_init(uv_t *ctx, uv_cfg_t *cfg)
Initialization function.
uv_cfg_t
Click configuration structure definition.
Definition: uv.h:106
uv_read_adc_value
err_t uv_read_adc_value(uv_t *ctx, uint16_t *data_out)
ADC Reading function.
uv_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: uv.h:120
uv_t::chip_select
pin_name_t chip_select
Definition: uv.h:95
uv_callback_t
void(* uv_callback_t)(uint8_t *)
Click callback handler definition.
Definition: uv.h:80
uv_device_enable
void uv_device_enable(uv_t *ctx)
Device Power ON function.
uv_t::en
digital_out_t en
Definition: uv.h:88
uv_calc_index
void uv_calc_index(uv_t *ctx, float data_in, uint8_t *data_out)
UV Index Calculation function.