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
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_spi_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define UV_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
67 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
68 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
69 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
74 // End group macro
75// --------------------------------------------------------------- PUBLIC TYPES
84typedef void ( *uv_callback_t )( uint8_t* );
85
89typedef struct
90{
91 // Digital Output pins.
92 digital_out_t en;
93
94 // Analog Input pins.
95 analog_in_t an;
96
97 // Comm Modules.
98 spi_master_t spi;
99 pin_name_t chip_select;
100
101 // Callback handler.
103
104} uv_t;
105
109typedef struct
110{
111 // Communication gpio pins.
112 pin_name_t miso;
113 pin_name_t mosi;
114 pin_name_t sck;
115 pin_name_t cs;
116
117 // Additional gpio pins.
118 pin_name_t an;
119 pin_name_t en;
120
121 // Static variables.
122 uint32_t spi_speed;
123 spi_master_mode_t spi_mode;
124 spi_master_chip_select_polarity_t cs_polarity;
126 analog_in_resolution_t resolution;
129} uv_cfg_t;
130
131 // End group type
132// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
138#ifdef __cplusplus
139extern "C"{
140#endif
141
151void uv_cfg_setup ( uv_cfg_t *cfg );
152
166err_t uv_init ( uv_t *ctx, uv_cfg_t *cfg );
167
178
191err_t uv_read_adc_value ( uv_t *ctx, uint16_t *data_out );
192
205err_t uv_read_adc_voltage ( uv_t *ctx, float *data_out );
206
221err_t uv_read_an_pin_value ( uv_t *ctx, uint16_t *data_out );
222
238err_t uv_read_an_pin_voltage ( uv_t *ctx, float *data_out );
239
253void uv_calc_index ( uv_t *ctx, float data_in, uint8_t *data_out );
254
262void uv_device_enable ( uv_t *ctx );
263
272
273#ifdef __cplusplus
274}
275#endif
276#endif // UV_H
277
278 // End public_function group
280
281// ------------------------------------------------------------------------- END
err_t uv_read_adc_voltage(uv_t *ctx, float *data_out)
ADC Voltage Reading function.
err_t uv_read_an_pin_voltage(uv_t *ctx, float *data_out)
AN Pin Voltage Reading function.
void uv_device_enable(uv_t *ctx)
Device Power ON function.
err_t uv_read_adc_value(uv_t *ctx, uint16_t *data_out)
ADC Reading function.
void uv_calc_index(uv_t *ctx, float data_in, uint8_t *data_out)
UV Index Calculation function.
void uv_cfg_setup(uv_cfg_t *cfg)
Config Object Initialization function.
void uv_set_callback_handler(uv_t *ctx, uv_callback_t handler)
Callback Handler Setting function.
err_t uv_read_an_pin_value(uv_t *ctx, uint16_t *data_out)
AN Pin Reading function.
void uv_device_disable(uv_t *ctx)
Device Power OFF function.
err_t uv_init(uv_t *ctx, uv_cfg_t *cfg)
Initialization function.
void(* uv_callback_t)(uint8_t *)
Click callback handler definition.
Definition uv.h:84
Click configuration structure definition.
Definition uv.h:110
analog_in_resolution_t resolution
Definition uv.h:126
float vref_value
Definition uv.h:127
spi_master_chip_select_polarity_t cs_polarity
Definition uv.h:124
pin_name_t sck
Definition uv.h:114
spi_master_mode_t spi_mode
Definition uv.h:123
pin_name_t mosi
Definition uv.h:113
uint32_t spi_speed
Definition uv.h:122
pin_name_t en
Definition uv.h:119
pin_name_t miso
Definition uv.h:112
pin_name_t an
Definition uv.h:118
pin_name_t cs
Definition uv.h:115
Click context object definition.
Definition uv.h:90
spi_master_t spi
Definition uv.h:98
uv_callback_t handler
Definition uv.h:102
digital_out_t en
Definition uv.h:92
analog_in_t an
Definition uv.h:95
pin_name_t chip_select
Definition uv.h:99