uva 2.0.0.0
uva.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef UVA_H
29#define UVA_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define UVA_REG_CHIP_ID 0x00
74#define UVA_REG_MODE 0x01
75#define UVA_REG_RES_UV 0x04
76#define UVA_REG_RANGE_UVA 0x05
77#define UVA_REG_MODE_CTRL 0x0A
78#define UVA_REG_SOFT_RESET 0x0B
79#define UVA_REG_UVA_LSB 0x15
80#define UVA_REG_UVA_MSB 0x16
81#define UVA_REG_NVM_READ_CTRL 0x30
82#define UVA_REG_NVM_MSB 0x31
83#define UVA_REG_NVM_LSB 0x32
84
85 // uva_reg
86
101#define UVA_CHIP_ID 0x62
102
107#define UVA_MODE_NO_OPERATION 0x00
108#define UVA_MODE_UVA_OPERATION 0x10
109#define UVA_MODE_NORMAL 0x00
110#define UVA_MODE_LOW_POWER 0x01
111#define UVA_MODE_AUTO_SHUTDOWN 0x02
112#define UVA_MODE_SHUTDOWN 0x03
113
118#define UVA_RESOLUTION_800MS 0x00
119#define UVA_RESOLUTION_400MS 0x01
120#define UVA_RESOLUTION_200MS 0x02
121#define UVA_RESOLUTION_100MS 0x03
122
127#define UVA_RANGE_X1 0x00
128#define UVA_RANGE_X2 0x01
129#define UVA_RANGE_X4 0x02
130#define UVA_RANGE_X8 0x03
131#define UVA_RANGE_X16 0x04
132#define UVA_RANGE_X32 0x05
133#define UVA_RANGE_X64 0x06
134#define UVA_RANGE_X128 0x07
135
140#define UVA_MODE_CTRL_SLEEP_2_TIMES 0x00
141#define UVA_MODE_CTRL_SLEEP_4_TIMES 0x01
142#define UVA_MODE_CTRL_SLEEP_8_TIMES 0x02
143#define UVA_MODE_CTRL_SLEEP_16_TIMES 0x03
144#define UVA_MODE_CTRL_SLEEP_32_TIMES 0x04
145#define UVA_MODE_CTRL_SLEEP_64_TIMES 0x05
146#define UVA_MODE_CTRL_SLEEP_128_TIMES 0x06
147#define UVA_MODE_CTRL_SLEEP_256_TIMES 0x07
148
153#define UVA_SOFT_RESET 0xA5
154
159#define UVA_NVM_READ_ADDRESS_OFFSET 0x0A
160#define UVA_NVM_READ_ADDRESS_A_SCALE 0x0B
161
167#define UVA_SET_DEV_ADDR 0x39
168
169 // uva_set
170
185#define UVA_MAP_MIKROBUS( cfg, mikrobus ) \
186 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
187 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
188
189 // uva_map
190 // uva
191
196typedef struct
197{
198 // Modules
199 i2c_master_t i2c;
201 // I2C slave address
204} uva_t;
205
210typedef struct
211{
212 pin_name_t scl;
213 pin_name_t sda;
215 uint32_t i2c_speed;
216 uint8_t i2c_address;
218} uva_cfg_t;
219
224typedef enum
225{
227 UVA_ERROR = -1
228
230
247
262err_t uva_init ( uva_t *ctx, uva_cfg_t *cfg );
263
277err_t uva_default_cfg ( uva_t *ctx );
278
294err_t uva_generic_write ( uva_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
295
311err_t uva_generic_read ( uva_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
312
326err_t uva_write_register ( uva_t *ctx, uint8_t reg, uint8_t data_in );
327
341err_t uva_read_register ( uva_t *ctx, uint8_t reg, uint8_t *data_out );
342
355
368err_t uva_read_data ( uva_t *ctx, uint16_t *uva_data );
369
381err_t uva_soft_reset ( uva_t *ctx );
382
383#ifdef __cplusplus
384}
385#endif
386#endif // UVA_H
387
388 // uva
389
390// ------------------------------------------------------------------------ END
err_t uva_soft_reset(uva_t *ctx)
UVA soft reset function.
err_t uva_generic_read(uva_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
UVA I2C reading function.
err_t uva_write_register(uva_t *ctx, uint8_t reg, uint8_t data_in)
UVA write register function.
err_t uva_read_register(uva_t *ctx, uint8_t reg, uint8_t *data_out)
UVA read register function.
err_t uva_check_communication(uva_t *ctx)
UVA check communication function.
err_t uva_init(uva_t *ctx, uva_cfg_t *cfg)
UVA initialization function.
err_t uva_generic_write(uva_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
UVA I2C writing function.
err_t uva_read_data(uva_t *ctx, uint16_t *uva_data)
UVA read data function.
err_t uva_default_cfg(uva_t *ctx)
UVA default configuration function.
void uva_cfg_setup(uva_cfg_t *cfg)
UVA configuration object setup function.
UVA Click configuration object.
Definition uva.h:211
uint32_t i2c_speed
Definition uva.h:215
pin_name_t scl
Definition uva.h:212
pin_name_t sda
Definition uva.h:213
uint8_t i2c_address
Definition uva.h:216
UVA Click context object.
Definition uva.h:197
i2c_master_t i2c
Definition uva.h:199
uint8_t slave_address
Definition uva.h:202
uva_return_value_t
UVA Click return value data.
Definition uva.h:225
@ UVA_OK
Definition uva.h:226
@ UVA_ERROR
Definition uva.h:227