uvb 2.0.0.0
uvb.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 UVB_H
29#define UVB_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 UVB_REG_CHIP_ID 0x00
74#define UVB_REG_MODE 0x01
75#define UVB_REG_RES_UV 0x04
76#define UVB_REG_RANGE_UVB 0x07
77#define UVB_REG_MODE_CTRL 0x0A
78#define UVB_REG_SOFT_RESET 0x0B
79#define UVB_REG_UVB_LSB 0x17
80#define UVB_REG_UVB_MSB 0x18
81#define UVB_REG_NVM_READ_CTRL 0x30
82#define UVB_REG_NVM_MSB 0x31
83#define UVB_REG_NVM_LSB 0x32
84
85 // uvb_reg
86
101#define UVB_MODE_NO_OPERATION 0x00
102#define UVB_MODE_UVB_OPERATION 0x20
103#define UVB_MODE_NORMAL 0x00
104#define UVB_MODE_LOW_POWER 0x01
105#define UVB_MODE_AUTO_SHUTDOWN 0x02
106#define UVB_MODE_SHUTDOWN 0x03
107
112#define UVB_RESOLUTION_800ms 0x00
113#define UVB_RESOLUTION_400ms 0x01
114#define UVB_RESOLUTION_200ms 0x02
115#define UVB_RESOLUTION_100ms 0x03
116
121#define UVB_RANGE_x1 0x00
122#define UVB_RANGE_x2 0x01
123#define UVB_RANGE_x4 0x02
124#define UVB_RANGE_x8 0x03
125#define UVB_RANGE_x16 0x04
126#define UVB_RANGE_x32 0x05
127#define UVB_RANGE_x64 0x06
128#define UVB_RANGE_x128 0x07
129
134#define UVB_MCTRL_SLEEP_2_TIMES 0x00
135#define UVB_MCTRL_SLEEP_4_TIMES 0x01
136#define UVB_MCTRL_SLEEP_8_TIMES 0x02
137#define UVB_MCTRL_SLEEP_16_TIMES 0x03
138#define UVB_MCTRL_SLEEP_32_TIMES 0x04
139#define UVB_MCTRL_SLEEP_64_TIMES 0x05
140#define UVB_MCTRL_SLEEP_128_TIMES 0x06
141#define UVB_MCTRL_SLEEP_256_TIMES 0x07
142
143#define UVB_DEF_CHIP_ID 0x62
144
145
151#define UVB_SET_DEV_ADDR 0x39
152
153 // uvb_set
154
169#define UVB_MAP_MIKROBUS( cfg, mikrobus ) \
170 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
171 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
172
173 // uvb_map
174 // uvb
175
180typedef struct
181{
182 // Modules
183 i2c_master_t i2c;
185 // I2C slave address
188} uvb_t;
189
194typedef struct
195{
196 pin_name_t scl;
197 pin_name_t sda;
199 uint32_t i2c_speed;
200 uint8_t i2c_address;
202} uvb_cfg_t;
203
208typedef enum
209{
211 UVB_ERROR = -1
212
214
231
245err_t uvb_init ( uvb_t *ctx, uvb_cfg_t *cfg );
246
260err_t uvb_default_cfg ( uvb_t *ctx );
261
276err_t uvb_generic_write ( uvb_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
277
292err_t uvb_generic_read ( uvb_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
293
303void uvb_configuration ( uvb_t *ctx, uint8_t reg, uint8_t cfg );
304
313uint8_t uvb_read_byte ( uvb_t *ctx, uint8_t reg );
314
326
334uint16_t uvb_get_uv_data ( uvb_t *ctx );
335
336#ifdef __cplusplus
337}
338#endif
339#endif // UVB_H
340
341 // uvb
342
343// ------------------------------------------------------------------------ END
void uvb_cfg_setup(uvb_cfg_t *cfg)
UVB configuration object setup function.
void uvb_configuration(uvb_t *ctx, uint8_t reg, uint8_t cfg)
Configuration register.
err_t uvb_generic_write(uvb_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
UVB I2C writing function.
uint16_t uvb_get_uv_data(uvb_t *ctx)
Get UVB data.
uint8_t uvb_read_byte(uvb_t *ctx, uint8_t reg)
Read one byte data from register.
err_t uvb_check_communication(uvb_t *ctx)
Check communication.
err_t uvb_default_cfg(uvb_t *ctx)
UVB default configuration function.
err_t uvb_generic_read(uvb_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
UVB I2C reading function.
err_t uvb_init(uvb_t *ctx, uvb_cfg_t *cfg)
UVB initialization function.
UVB Click configuration object.
Definition uvb.h:195
uint32_t i2c_speed
Definition uvb.h:199
pin_name_t scl
Definition uvb.h:196
pin_name_t sda
Definition uvb.h:197
uint8_t i2c_address
Definition uvb.h:200
UVB Click context object.
Definition uvb.h:181
i2c_master_t i2c
Definition uvb.h:183
uint8_t slave_address
Definition uvb.h:186
uvb_return_value_t
UVB Click return value data.
Definition uvb.h:209
@ UVB_ERROR
Definition uvb.h:211
@ UVB_OK
Definition uvb.h:210