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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define UVB_REG_CHIP_ID 0x00
60 #define UVB_REG_MODE 0x01
61 #define UVB_REG_RES_UV 0x04
62 #define UVB_REG_RANGE_UVB 0x07
63 #define UVB_REG_MODE_CTRL 0x0A
64 #define UVB_REG_SOFT_RESET 0x0B
65 #define UVB_REG_UVB_LSB 0x17
66 #define UVB_REG_UVB_MSB 0x18
67 #define UVB_REG_NVM_READ_CTRL 0x30
68 #define UVB_REG_NVM_MSB 0x31
69 #define UVB_REG_NVM_LSB 0x32
70  // uvb_reg
72 
87 #define UVB_MODE_NO_OPERATION 0x00
88 #define UVB_MODE_UVB_OPERATION 0x20
89 #define UVB_MODE_NORMAL 0x00
90 #define UVB_MODE_LOW_POWER 0x01
91 #define UVB_MODE_AUTO_SHUTDOWN 0x02
92 #define UVB_MODE_SHUTDOWN 0x03
93 
98 #define UVB_RESOLUTION_800ms 0x00
99 #define UVB_RESOLUTION_400ms 0x01
100 #define UVB_RESOLUTION_200ms 0x02
101 #define UVB_RESOLUTION_100ms 0x03
102 
107 #define UVB_RANGE_x1 0x00
108 #define UVB_RANGE_x2 0x01
109 #define UVB_RANGE_x4 0x02
110 #define UVB_RANGE_x8 0x03
111 #define UVB_RANGE_x16 0x04
112 #define UVB_RANGE_x32 0x05
113 #define UVB_RANGE_x64 0x06
114 #define UVB_RANGE_x128 0x07
115 
120 #define UVB_MCTRL_SLEEP_2_TIMES 0x00
121 #define UVB_MCTRL_SLEEP_4_TIMES 0x01
122 #define UVB_MCTRL_SLEEP_8_TIMES 0x02
123 #define UVB_MCTRL_SLEEP_16_TIMES 0x03
124 #define UVB_MCTRL_SLEEP_32_TIMES 0x04
125 #define UVB_MCTRL_SLEEP_64_TIMES 0x05
126 #define UVB_MCTRL_SLEEP_128_TIMES 0x06
127 #define UVB_MCTRL_SLEEP_256_TIMES 0x07
128 
129 #define UVB_DEF_CHIP_ID 0x62
130 
131 
137 #define UVB_SET_DEV_ADDR 0x39
138  // uvb_set
140 
155 #define UVB_MAP_MIKROBUS( cfg, mikrobus ) \
156  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
157  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
158  // uvb_map // uvb
161 
166 typedef struct
167 {
168  // Modules
169  i2c_master_t i2c;
171  // I2C slave address
172  uint8_t slave_address;
174 } uvb_t;
175 
180 typedef struct
181 {
182  pin_name_t scl;
183  pin_name_t sda;
185  uint32_t i2c_speed;
186  uint8_t i2c_address;
188 } uvb_cfg_t;
189 
194 typedef enum
195 {
196  UVB_OK = 0,
197  UVB_ERROR = -1
198 
200 
216 void uvb_cfg_setup ( uvb_cfg_t *cfg );
217 
231 err_t uvb_init ( uvb_t *ctx, uvb_cfg_t *cfg );
232 
246 err_t uvb_default_cfg ( uvb_t *ctx );
247 
262 err_t uvb_generic_write ( uvb_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
263 
278 err_t uvb_generic_read ( uvb_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
279 
289 void uvb_configuration ( uvb_t *ctx, uint8_t reg, uint8_t cfg );
290 
299 uint8_t uvb_read_byte ( uvb_t *ctx, uint8_t reg );
300 
311 err_t uvb_check_communication ( uvb_t *ctx );
312 
320 uint16_t uvb_get_uv_data ( uvb_t *ctx );
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 #endif // UVB_H
326  // uvb
328 
329 // ------------------------------------------------------------------------ END
uvb_return_value_t
uvb_return_value_t
UVB Click return value data.
Definition: uvb.h:193
uvb_init
err_t uvb_init(uvb_t *ctx, uvb_cfg_t *cfg)
UVB initialization function.
uvb_default_cfg
err_t uvb_default_cfg(uvb_t *ctx)
UVB default configuration function.
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_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
Definition: uvb.h:196
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:179
uvb_t
UVB Click context object.
Definition: uvb.h:165
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
Definition: uvb.h:195