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 "drv_analog_in.h"
39 #include "drv_spi_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define UV_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
53  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
54  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
55  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
58  // End group macro
61 // --------------------------------------------------------------- PUBLIC TYPES
70 typedef void ( *uv_callback_t )( uint8_t* );
71 
75 typedef struct
76 {
77  // Digital Output pins.
78 
79  digital_out_t en;
80 
81  // Analog Input pins.
82 
83  analog_in_t an;
84 
85  // Comm Modules.
86 
87  spi_master_t spi;
88  pin_name_t chip_select;
89 
90  // Callback handler.
91 
93 
94 } uv_t;
95 
99 typedef struct
100 {
101  // Communication gpio pins.
102 
103  pin_name_t miso;
104  pin_name_t mosi;
105  pin_name_t sck;
106  pin_name_t cs;
107 
108  // Additional gpio pins.
109 
110  pin_name_t an;
111  pin_name_t en;
112 
113  // Static variables.
114 
115  uint32_t spi_speed;
116  spi_master_mode_t spi_mode;
117  spi_master_chip_select_polarity_t cs_polarity;
119  analog_in_resolution_t resolution;
120  analog_in_vref_t vref_input;
121  float vref_value;
123 } uv_cfg_t;
124  // End group type
126 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
132 #ifdef __cplusplus
133 extern "C"{
134 #endif
135 
145 void uv_cfg_setup ( uv_cfg_t *cfg );
146 
160 err_t uv_init ( uv_t *ctx, uv_cfg_t *cfg );
161 
171 void uv_set_callback_handler ( uv_t *ctx, uv_callback_t handler );
172 
185 err_t uv_read_adc_value ( uv_t *ctx, uint16_t *data_out );
186 
199 err_t uv_read_adc_voltage ( uv_t *ctx, float *data_out );
200 
215 err_t uv_read_an_pin_value ( uv_t *ctx, uint16_t *data_out );
216 
232 err_t uv_read_an_pin_voltage ( uv_t *ctx, float *data_out );
233 
247 void uv_calc_index ( uv_t *ctx, float data_in, uint8_t *data_out );
248 
256 void uv_device_enable ( uv_t *ctx );
257 
265 void uv_device_disable ( uv_t *ctx );
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 #endif // UV_H
271  // End public_function group
274 
275 // ------------------------------------------------------------------------- END
uv_t::spi
spi_master_t spi
Definition: uv.h:87
uv_cfg_t::vref_value
float vref_value
Definition: uv.h:121
uv_cfg_t::spi_speed
uint32_t spi_speed
Definition: uv.h:115
uv_t
Click context object definition.
Definition: uv.h:75
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:103
uv_cfg_t::an
pin_name_t an
Definition: uv.h:110
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:105
uv_t::handler
uv_callback_t handler
Definition: uv.h:92
uv_cfg_t::cs
pin_name_t cs
Definition: uv.h:106
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:111
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:116
uv_cfg_t::resolution
analog_in_resolution_t resolution
Definition: uv.h:119
uv_t::an
analog_in_t an
Definition: uv.h:83
uv_cfg_t::mosi
pin_name_t mosi
Definition: uv.h:104
uv_init
err_t uv_init(uv_t *ctx, uv_cfg_t *cfg)
Initialization function.
uv_cfg_t::vref_input
analog_in_vref_t vref_input
Definition: uv.h:120
uv_cfg_t
Click configuration structure definition.
Definition: uv.h:99
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:117
uv_t::chip_select
pin_name_t chip_select
Definition: uv.h:88
uv_callback_t
void(* uv_callback_t)(uint8_t *)
Click callback handler definition.
Definition: uv.h:70
uv_device_enable
void uv_device_enable(uv_t *ctx)
Device Power ON function.
uv_t::en
digital_out_t en
Definition: uv.h:79
uv_calc_index
void uv_calc_index(uv_t *ctx, float data_in, uint8_t *data_out)
UV Index Calculation function.