uv2  2.0.0.0
uv2.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 UV2_H
36 #define UV2_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 UV2_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define UV2_RETVAL uint8_t
72 
73 #define UV2_OK 0x00
74 #define UV2_INIT_ERROR 0xFF
75 
81 #define UV2_I2C_ADDRESS 0x10
82 #define UV2_DEV_ID 0x26
83 
89 #define UV2_REG_CONF 0x00
90 #define UV2_REG_UVA 0x07
91 #define UV2_REG_UVB 0x09
92 #define UV2_REG_UVCOMP1 0x0A
93 #define UV2_REG_UVCOMP2 0x0B
94 #define UV2_REG_DEVID 0x0C
95 
101 #define UV2_CONF_IT_50MS 0x00
102 #define UV2_CONF_IT_100MS 0x10
103 #define UV2_CONF_IT_200MS 0x20
104 #define UV2_CONF_IT_400MS 0x30
105 #define UV2_CONF_IT_800MS 0x40
106 #define UV2_CONF_IT_MASK 0x8F
107 
113 #define UV2_CONF_HD_NORM 0x00
114 #define UV2_CONF_HD_HIGH 0x08
115 
121 #define UV2_CONF_MODE_TRIG 0x00
122 #define UV2_CONF_ONE_TRIG 0x04
123 
129 #define UV2_CONF_AF_OFF 0x00
130 #define UV2_CONF_AF_ON 0x02
131 
137 #define UV2_CONF_SD_PWR_ON 0x00
138 #define UV2_CONF_SD_PWR_OFF 0x01
139 
145 #define UV2_UVI_UVA_VIS_COEFF 3.33
146 #define UV2_UVI_UVA_IR_COEFF 2.50
147 #define UV2_UVI_UVB_VIS_COEFF 3.66
148 #define UV2_UVI_UVB_IR_COEFF 2.75
149 
155 #define UV2_UVI_UVA_RESPONSE 0.00110
156 #define UV2_UVI_UVB_RESPONSE 0.00125
157 
163 #define UV2_WRITE_MSB_BITS 0x00
164  // End group macro
167 // --------------------------------------------------------------- PUBLIC TYPES
176 typedef struct
177 {
178  // Modules
179 
180  i2c_master_t i2c;
181 
182  // ctx variable
183 
184  uint8_t slave_address;
185 
186 } uv2_t;
187 
191 typedef struct
192 {
193  // Communication gpio pins
194 
195  pin_name_t scl;
196  pin_name_t sda;
197 
198  // static variable
199 
200  uint32_t i2c_speed;
201  uint8_t i2c_address;
202 
203 } uv2_cfg_t;
204  // End types group
206 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
207 
213 #ifdef __cplusplus
214 extern "C"{
215 #endif
216 
225 void uv2_cfg_setup ( uv2_cfg_t *cfg );
226 
236 
244 void uv2_default_cfg ( uv2_t *ctx );
245 
256 void uv2_generic_write ( uv2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
257 
268 void uv2_generic_read ( uv2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
269 
280 void uv2_write_data ( uv2_t *ctx, uint8_t reg_address, uint8_t write_data );
281 
291 uint16_t uv2_read_data ( uv2_t *ctx, uint8_t reg_address );
292 
302 void uv2_set_config ( uv2_t *ctx, uint8_t config_value );
303 
313 void uv2_set_integration_time ( uv2_t *ctx, uint16_t intg_time );
314 
324 
334 
344 
354 void uv2_set_active_force_mode ( uv2_t *ctx, uint8_t force_mode );
355 
364 void uv2_set_power_on ( uv2_t *ctx );
365 
374 void uv2_set_power_off ( uv2_t *ctx );
375 
383 uint8_t uv2_check_id ( uv2_t *ctx );
384 
393 uint16_t uv2_get_uva ( uv2_t *ctx );
394 
403 uint16_t uv2_get_uvb ( uv2_t *ctx );
404 
413 float uv2_get_uv_index ( uv2_t *ctx );
414 
415 #ifdef __cplusplus
416 }
417 #endif
418 #endif // _UV2_H_
419  // End public_function group
422 
423 // ------------------------------------------------------------------------- END
uv2_cfg_t::i2c_address
uint8_t i2c_address
Definition: uv2.h:201
uv2_generic_read
void uv2_generic_read(uv2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uv2_get_uv_index
float uv2_get_uv_index(uv2_t *ctx)
Get UV index function.
uv2_set_normal_dynamic
void uv2_set_normal_dynamic(uv2_t *ctx)
Set normal dynamic function.
uv2_t::slave_address
uint8_t slave_address
Definition: uv2.h:184
uv2_cfg_t
Click configuration structure definition.
Definition: uv2.h:192
uv2_set_power_off
void uv2_set_power_off(uv2_t *ctx)
Set power OFF function.
uv2_init
UV2_RETVAL uv2_init(uv2_t *ctx, uv2_cfg_t *cfg)
Initialization function.
uv2_cfg_setup
void uv2_cfg_setup(uv2_cfg_t *cfg)
Config Object Initialization function.
uv2_set_config
void uv2_set_config(uv2_t *ctx, uint8_t config_value)
Set configuration function.
uv2_set_trigger_measurement
void uv2_set_trigger_measurement(uv2_t *ctx)
Set trigger one measurement function.
uv2_set_power_on
void uv2_set_power_on(uv2_t *ctx)
Set power ON function.
uv2_default_cfg
void uv2_default_cfg(uv2_t *ctx)
Click Default Configuration function.
uv2_check_id
uint8_t uv2_check_id(uv2_t *ctx)
Check sensor ID function.
uv2_cfg_t::scl
pin_name_t scl
Definition: uv2.h:195
UV2_RETVAL
#define UV2_RETVAL
Definition: uv2.h:71
uv2_get_uvb
uint16_t uv2_get_uvb(uv2_t *ctx)
Get UVB data function.
uv2_write_data
void uv2_write_data(uv2_t *ctx, uint8_t reg_address, uint8_t write_data)
Write 16-bit data function.
uv2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uv2.h:200
uv2_set_integration_time
void uv2_set_integration_time(uv2_t *ctx, uint16_t intg_time)
Set integration time function.
uv2_set_active_force_mode
void uv2_set_active_force_mode(uv2_t *ctx, uint8_t force_mode)
Set active force mode function.
uv2_cfg_t::sda
pin_name_t sda
Definition: uv2.h:196
uv2_set_high_dynamic
void uv2_set_high_dynamic(uv2_t *ctx)
Set high dynamic function.
uv2_get_uva
uint16_t uv2_get_uva(uv2_t *ctx)
Get UVA data function.
uv2_generic_write
void uv2_generic_write(uv2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uv2_t::i2c
i2c_master_t i2c
Definition: uv2.h:180
uv2_t
Click ctx object definition.
Definition: uv2.h:177
uv2_read_data
uint16_t uv2_read_data(uv2_t *ctx, uint8_t reg_address)
Read 16-bit data from 8-bit address function.