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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define UV3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.ack = MIKROBUS( mikrobus, MIKROBUS_INT )
56 
62 #define UV3_RETVAL uint8_t
63 
64 #define UV3_OK 0x00
65 #define UV3_INIT_ERROR 0xFF
66 
72 #define UV3_I2C_ADDR_DEFAULT 0x38
73 #define UV3_ADDR_ARA 0x0C
74 #define UV3_ADDR_CMD 0x38
75 #define UV3_ADDR_DATA_LSB 0x38
76 #define UV3_ADDR_DATA_MSB 0x39
77 
83 #define UV3_CMD_DEFAULT 0x02
84 #define UV3_CMD_SD 0x01
85 #define UV3_CMD_IT_0_5T 0x00
86 #define UV3_CMD_IT_1T 0x04
87 #define UV3_CMD_IT_2T 0x08
88 #define UV3_CMD_IT_4T 0x0C
89 
95 #define UV3_RAD_LOW 0x01
96 #define UV3_RAD_MODERATE 0x02
97 #define UV3_RAD_HIGH 0x03
98 #define UV3_RAD_VERY_HIGH 0x04
99 #define UV3_RAD_EXTREME 0x05
100  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
112 typedef struct
113 {
114  // Input pins
115 
116  digital_in_t ack;
117 
118  // Modules
119 
120  i2c_master_t i2c;
121 
122  // ctx variable
123 
124  uint8_t slave_address;
125 
126 } uv3_t;
127 
131 typedef struct
132 {
133  // Communication gpio pins
134 
135  pin_name_t scl;
136  pin_name_t sda;
137 
138  // Additional gpio pins
139 
140  pin_name_t ack;
141 
142  // static variable
143 
144  uint32_t i2c_speed;
145  uint8_t i2c_address;
146 
147 } uv3_cfg_t;
148  // End types group
150 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
151 
157 #ifdef __cplusplus
158 extern "C"{
159 #endif
160 
169 void uv3_cfg_setup ( uv3_cfg_t *cfg );
170 
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
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:62
uv3_default_cfg
void uv3_default_cfg(uv3_t *ctx)
Click Default Configuration function.
uv3_t
Click ctx object definition.
Definition: uv3.h:112
uv3_disable_mode
void uv3_disable_mode(uv3_t *ctx)
Disable sensor function.
uv3_t::i2c
i2c_master_t i2c
Definition: uv3.h:120
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:131
uv3_t::ack
digital_in_t ack
Definition: uv3.h:116
uv3_cfg_t::sda
pin_name_t sda
Definition: uv3.h:136
uv3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uv3.h:144
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:124
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:140
uv3_cfg_t::scl
pin_name_t scl
Definition: uv3.h:135
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:145
uv3_cfg_setup
void uv3_cfg_setup(uv3_cfg_t *cfg)
Config Object Initialization function.