uv3  2.0.0.0
uv3.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef UV3_H
36 #define UV3_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define UV3_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.ack = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define UV3_RETVAL uint8_t
64 
65 #define UV3_OK 0x00
66 #define UV3_INIT_ERROR 0xFF
67 
73 #define UV3_I2C_ADDR_DEFAULT 0x38
74 #define UV3_ADDR_ARA 0x0C
75 #define UV3_ADDR_CMD 0x38
76 #define UV3_ADDR_DATA_LSB 0x38
77 #define UV3_ADDR_DATA_MSB 0x39
78 
84 #define UV3_CMD_DEFAULT 0x02
85 #define UV3_CMD_SD 0x01
86 #define UV3_CMD_IT_0_5T 0x00
87 #define UV3_CMD_IT_1T 0x04
88 #define UV3_CMD_IT_2T 0x08
89 #define UV3_CMD_IT_4T 0x0C
90 
96 #define UV3_RAD_LOW 0x01
97 #define UV3_RAD_MODERATE 0x02
98 #define UV3_RAD_HIGH 0x03
99 #define UV3_RAD_VERY_HIGH 0x04
100 #define UV3_RAD_EXTREME 0x05
101  // End group macro
104 // --------------------------------------------------------------- PUBLIC TYPES
113 typedef struct
114 {
115  // Input pins
116 
117  digital_in_t ack;
118 
119  // Modules
120 
121  i2c_master_t i2c;
122 
123  // ctx variable
124 
125  hal_i2c_address_t slave_address;
126 
127 } uv3_t;
128 
132 typedef struct
133 {
134  // Communication gpio pins
135 
136  pin_name_t scl;
137  pin_name_t sda;
138 
139  // Additional gpio pins
140 
141  pin_name_t ack;
142 
143  // static variable
144 
145  hal_i2c_speed_t i2c_speed;
146  hal_i2c_address_t i2c_address;
147 
148 } uv3_cfg_t;
149  // End types group
151 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152 
158 #ifdef __cplusplus
159 extern "C"{
160 #endif
161 
170 void uv3_cfg_setup ( uv3_cfg_t *cfg );
171 
179 UV3_RETVAL uv3_init ( uv3_t *ctx, uv3_cfg_t *cfg );
180 
188 void uv3_default_cfg ( uv3_t *ctx );
189 
200 void uv3_write_command ( uv3_t *ctx, uint8_t slave_addr, uint8_t command );
201 
213 uint8_t uv3_read_byte ( uv3_t *ctx, uint8_t slave_addr );
214 
223 void uv3_clear_ack ( uv3_t *ctx );
224 
233 void uv3_enable_sensor ( uv3_t *ctx );
234 
243 void uv3_disable_mode ( uv3_t *ctx );
244 
263 void uv3_set_integration_time ( uv3_t *ctx, uint8_t int_data );
264 
273 uint16_t uv3_read_measurements ( uv3_t *ctx );
274 
293 uint8_t uv3_risk_level ( uint16_t uv_data );
294 
304 uint8_t uv3_get_interrupt ( uv3_t *ctx );
305 
306 
307 #ifdef __cplusplus
308 }
309 #endif
310 #endif // _UV3_H_
311  // End public_function group
314 
315 // ------------------------------------------------------------------------- END
hal_i2c_speed_t i2c_speed
Definition: uv3.h:145
void uv3_disable_mode(uv3_t *ctx)
Disable sensor function.
void uv3_default_cfg(uv3_t *ctx)
Click Default Configuration function.
void uv3_set_integration_time(uv3_t *ctx, uint8_t int_data)
Set integration time function.
UV3_RETVAL uv3_init(uv3_t *ctx, uv3_cfg_t *cfg)
Initialization function.
void uv3_clear_ack(uv3_t *ctx)
Read ARA to clear interrupt function.
hal_i2c_address_t slave_address
Definition: uv3.h:125
void uv3_cfg_setup(uv3_cfg_t *cfg)
Config Object Initialization function.
uint8_t uv3_risk_level(uint16_t uv_data)
Calculate UV risk level function.
void uv3_write_command(uv3_t *ctx, uint8_t slave_addr, uint8_t command)
Write function.
hal_i2c_address_t i2c_address
Definition: uv3.h:146
digital_in_t ack
Definition: uv3.h:117
Click ctx object definition.
Definition: uv3.h:113
pin_name_t ack
Definition: uv3.h:141
void uv3_enable_sensor(uv3_t *ctx)
Enable sensor function.
pin_name_t scl
Definition: uv3.h:136
uint16_t uv3_read_measurements(uv3_t *ctx)
Get UV data measurements function.
uint8_t uv3_get_interrupt(uv3_t *ctx)
Get state of interrupt pin function.
pin_name_t sda
Definition: uv3.h:137
i2c_master_t i2c
Definition: uv3.h:121
#define UV3_RETVAL
Definition: uv3.h:63
uint8_t uv3_read_byte(uv3_t *ctx, uint8_t slave_addr)
Read function.
Click configuration structure definition.
Definition: uv3.h:132