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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define UVB_REG_CHIP_ID 0x00
70 #define UVB_REG_MODE 0x01
71 #define UVB_REG_RES_UV 0x04
72 #define UVB_REG_RANGE_UVB 0x07
73 #define UVB_REG_MODE_CTRL 0x0A
74 #define UVB_REG_SOFT_RESET 0x0B
75 #define UVB_REG_UVB_LSB 0x17
76 #define UVB_REG_UVB_MSB 0x18
77 #define UVB_REG_NVM_READ_CTRL 0x30
78 #define UVB_REG_NVM_MSB 0x31
79 #define UVB_REG_NVM_LSB 0x32
80  // uvb_reg
82 
97 #define UVB_MODE_NO_OPERATION 0x00
98 #define UVB_MODE_UVB_OPERATION 0x20
99 #define UVB_MODE_NORMAL 0x00
100 #define UVB_MODE_LOW_POWER 0x01
101 #define UVB_MODE_AUTO_SHUTDOWN 0x02
102 #define UVB_MODE_SHUTDOWN 0x03
103 
108 #define UVB_RESOLUTION_800ms 0x00
109 #define UVB_RESOLUTION_400ms 0x01
110 #define UVB_RESOLUTION_200ms 0x02
111 #define UVB_RESOLUTION_100ms 0x03
112 
117 #define UVB_RANGE_x1 0x00
118 #define UVB_RANGE_x2 0x01
119 #define UVB_RANGE_x4 0x02
120 #define UVB_RANGE_x8 0x03
121 #define UVB_RANGE_x16 0x04
122 #define UVB_RANGE_x32 0x05
123 #define UVB_RANGE_x64 0x06
124 #define UVB_RANGE_x128 0x07
125 
130 #define UVB_MCTRL_SLEEP_2_TIMES 0x00
131 #define UVB_MCTRL_SLEEP_4_TIMES 0x01
132 #define UVB_MCTRL_SLEEP_8_TIMES 0x02
133 #define UVB_MCTRL_SLEEP_16_TIMES 0x03
134 #define UVB_MCTRL_SLEEP_32_TIMES 0x04
135 #define UVB_MCTRL_SLEEP_64_TIMES 0x05
136 #define UVB_MCTRL_SLEEP_128_TIMES 0x06
137 #define UVB_MCTRL_SLEEP_256_TIMES 0x07
138 
139 #define UVB_DEF_CHIP_ID 0x62
140 
141 
147 #define UVB_SET_DEV_ADDR 0x39
148  // uvb_set
150 
165 #define UVB_MAP_MIKROBUS( cfg, mikrobus ) \
166  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
167  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
168  // uvb_map // uvb
171 
176 typedef struct
177 {
178  // Modules
179  i2c_master_t i2c;
181  // I2C slave address
182  uint8_t slave_address;
184 } uvb_t;
185 
190 typedef struct
191 {
192  pin_name_t scl;
193  pin_name_t sda;
195  uint32_t i2c_speed;
196  uint8_t i2c_address;
198 } uvb_cfg_t;
199 
204 typedef enum
205 {
206  UVB_OK = 0,
207  UVB_ERROR = -1
208 
210 
226 void uvb_cfg_setup ( uvb_cfg_t *cfg );
227 
241 err_t uvb_init ( uvb_t *ctx, uvb_cfg_t *cfg );
242 
256 err_t uvb_default_cfg ( uvb_t *ctx );
257 
272 err_t uvb_generic_write ( uvb_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
273 
288 err_t uvb_generic_read ( uvb_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
289 
299 void uvb_configuration ( uvb_t *ctx, uint8_t reg, uint8_t cfg );
300 
309 uint8_t uvb_read_byte ( uvb_t *ctx, uint8_t reg );
310 
322 
330 uint16_t uvb_get_uv_data ( uvb_t *ctx );
331 
332 #ifdef __cplusplus
333 }
334 #endif
335 #endif // UVB_H
336  // uvb
338 
339 // ------------------------------------------------------------------------ END
uvb_return_value_t
uvb_return_value_t
UVB Click return value data.
Definition: uvb.h:205
uvb_init
err_t uvb_init(uvb_t *ctx, uvb_cfg_t *cfg)
UVB initialization function.
uvb_t::slave_address
uint8_t slave_address
Definition: uvb.h:182
uvb_cfg_t::i2c_address
uint8_t i2c_address
Definition: uvb.h:196
uvb_default_cfg
err_t uvb_default_cfg(uvb_t *ctx)
UVB default configuration function.
uvb_cfg_t::scl
pin_name_t scl
Definition: uvb.h:192
uvb_generic_write
err_t uvb_generic_write(uvb_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
UVB I2C writing function.
uvb_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uvb.h:195
uvb_configuration
void uvb_configuration(uvb_t *ctx, uint8_t reg, uint8_t cfg)
Configuration register.
uvb_generic_read
err_t uvb_generic_read(uvb_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
UVB I2C reading function.
uvb_read_byte
uint8_t uvb_read_byte(uvb_t *ctx, uint8_t reg)
Read one byte data from register.
UVB_ERROR
@ UVB_ERROR
Definition: uvb.h:207
uvb_cfg_setup
void uvb_cfg_setup(uvb_cfg_t *cfg)
UVB configuration object setup function.
uvb_cfg_t
UVB Click configuration object.
Definition: uvb.h:191
uvb_t::i2c
i2c_master_t i2c
Definition: uvb.h:179
uvb_t
UVB Click context object.
Definition: uvb.h:177
uvb_check_communication
err_t uvb_check_communication(uvb_t *ctx)
Check communication.
uvb_get_uv_data
uint16_t uvb_get_uv_data(uvb_t *ctx)
Get UVB data.
UVB_OK
@ UVB_OK
Definition: uvb.h:206
uvb_cfg_t::sda
pin_name_t sda
Definition: uvb.h:193