uv3  2.0.0.0
uv3.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 UV3_H
36 #define UV3_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_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define UV3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.ack = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define UV3_RETVAL uint8_t
73 
74 #define UV3_OK 0x00
75 #define UV3_INIT_ERROR 0xFF
76 
82 #define UV3_I2C_ADDR_DEFAULT 0x38
83 #define UV3_ADDR_ARA 0x0C
84 #define UV3_ADDR_CMD 0x38
85 #define UV3_ADDR_DATA_LSB 0x38
86 #define UV3_ADDR_DATA_MSB 0x39
87 
93 #define UV3_CMD_DEFAULT 0x02
94 #define UV3_CMD_SD 0x01
95 #define UV3_CMD_IT_0_5T 0x00
96 #define UV3_CMD_IT_1T 0x04
97 #define UV3_CMD_IT_2T 0x08
98 #define UV3_CMD_IT_4T 0x0C
99 
105 #define UV3_RAD_LOW 0x01
106 #define UV3_RAD_MODERATE 0x02
107 #define UV3_RAD_HIGH 0x03
108 #define UV3_RAD_VERY_HIGH 0x04
109 #define UV3_RAD_EXTREME 0x05
110  // End group macro
113 // --------------------------------------------------------------- PUBLIC TYPES
122 typedef struct
123 {
124  // Input pins
125 
126  digital_in_t ack;
127 
128  // Modules
129 
130  i2c_master_t i2c;
131 
132  // ctx variable
133 
134  uint8_t slave_address;
135 
136 } uv3_t;
137 
141 typedef struct
142 {
143  // Communication gpio pins
144 
145  pin_name_t scl;
146  pin_name_t sda;
147 
148  // Additional gpio pins
149 
150  pin_name_t ack;
151 
152  // static variable
153 
154  uint32_t i2c_speed;
155  uint8_t i2c_address;
156 
157 } uv3_cfg_t;
158  // End types group
160 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
161 
167 #ifdef __cplusplus
168 extern "C"{
169 #endif
170 
179 void uv3_cfg_setup ( uv3_cfg_t *cfg );
180 
190 
198 void uv3_default_cfg ( uv3_t *ctx );
199 
210 void uv3_write_command ( uv3_t *ctx, uint8_t slave_addr, uint8_t command );
211 
223 uint8_t uv3_read_byte ( uv3_t *ctx, uint8_t slave_addr );
224 
233 void uv3_clear_ack ( uv3_t *ctx );
234 
243 void uv3_enable_sensor ( uv3_t *ctx );
244 
253 void uv3_disable_mode ( uv3_t *ctx );
254 
273 void uv3_set_integration_time ( uv3_t *ctx, uint8_t int_data );
274 
283 uint16_t uv3_read_measurements ( uv3_t *ctx );
284 
303 uint8_t uv3_risk_level ( uint16_t uv_data );
304 
314 uint8_t uv3_get_interrupt ( uv3_t *ctx );
315 
316 
317 #ifdef __cplusplus
318 }
319 #endif
320 #endif // _UV3_H_
321  // End public_function group
324 
325 // ------------------------------------------------------------------------- END
uv3_read_measurements
uint16_t uv3_read_measurements(uv3_t *ctx)
Get UV data measurements function.
uv3_get_interrupt
uint8_t uv3_get_interrupt(uv3_t *ctx)
Get state of interrupt pin function.
uv3_enable_sensor
void uv3_enable_sensor(uv3_t *ctx)
Enable sensor function.
UV3_RETVAL
#define UV3_RETVAL
Definition: uv3.h:72
uv3_default_cfg
void uv3_default_cfg(uv3_t *ctx)
Click Default Configuration function.
uv3_t
Click ctx object definition.
Definition: uv3.h:123
uv3_disable_mode
void uv3_disable_mode(uv3_t *ctx)
Disable sensor function.
uv3_t::i2c
i2c_master_t i2c
Definition: uv3.h:130
uv3_read_byte
uint8_t uv3_read_byte(uv3_t *ctx, uint8_t slave_addr)
Read function.
uv3_cfg_t
Click configuration structure definition.
Definition: uv3.h:142
uv3_t::ack
digital_in_t ack
Definition: uv3.h:126
uv3_cfg_t::sda
pin_name_t sda
Definition: uv3.h:146
uv3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uv3.h:154
uv3_clear_ack
void uv3_clear_ack(uv3_t *ctx)
Read ARA to clear interrupt function.
uv3_risk_level
uint8_t uv3_risk_level(uint16_t uv_data)
Calculate UV risk level function.
uv3_t::slave_address
uint8_t slave_address
Definition: uv3.h:134
uv3_write_command
void uv3_write_command(uv3_t *ctx, uint8_t slave_addr, uint8_t command)
Write function.
uv3_cfg_t::ack
pin_name_t ack
Definition: uv3.h:150
uv3_cfg_t::scl
pin_name_t scl
Definition: uv3.h:145
uv3_init
UV3_RETVAL uv3_init(uv3_t *ctx, uv3_cfg_t *cfg)
Initialization function.
uv3_set_integration_time
void uv3_set_integration_time(uv3_t *ctx, uint8_t int_data)
Set integration time function.
uv3_cfg_t::i2c_address
uint8_t i2c_address
Definition: uv3.h:155
uv3_cfg_setup
void uv3_cfg_setup(uv3_cfg_t *cfg)
Config Object Initialization function.