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
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 UVA_REG_CHIP_ID 0x00
60 #define UVA_REG_MODE 0x01
61 #define UVA_REG_RES_UV 0x04
62 #define UVA_REG_RANGE_UVA 0x05
63 #define UVA_REG_MODE_CTRL 0x0A
64 #define UVA_REG_SOFT_RESET 0x0B
65 #define UVA_REG_UVA_LSB 0x15
66 #define UVA_REG_UVA_MSB 0x16
67 #define UVA_REG_NVM_READ_CTRL 0x30
68 #define UVA_REG_NVM_MSB 0x31
69 #define UVA_REG_NVM_LSB 0x32
70  // uva_reg
72 
87 #define UVA_CHIP_ID 0x62
88 
93 #define UVA_MODE_NO_OPERATION 0x00
94 #define UVA_MODE_UVA_OPERATION 0x10
95 #define UVA_MODE_NORMAL 0x00
96 #define UVA_MODE_LOW_POWER 0x01
97 #define UVA_MODE_AUTO_SHUTDOWN 0x02
98 #define UVA_MODE_SHUTDOWN 0x03
99 
104 #define UVA_RESOLUTION_800MS 0x00
105 #define UVA_RESOLUTION_400MS 0x01
106 #define UVA_RESOLUTION_200MS 0x02
107 #define UVA_RESOLUTION_100MS 0x03
108 
113 #define UVA_RANGE_X1 0x00
114 #define UVA_RANGE_X2 0x01
115 #define UVA_RANGE_X4 0x02
116 #define UVA_RANGE_X8 0x03
117 #define UVA_RANGE_X16 0x04
118 #define UVA_RANGE_X32 0x05
119 #define UVA_RANGE_X64 0x06
120 #define UVA_RANGE_X128 0x07
121 
126 #define UVA_MODE_CTRL_SLEEP_2_TIMES 0x00
127 #define UVA_MODE_CTRL_SLEEP_4_TIMES 0x01
128 #define UVA_MODE_CTRL_SLEEP_8_TIMES 0x02
129 #define UVA_MODE_CTRL_SLEEP_16_TIMES 0x03
130 #define UVA_MODE_CTRL_SLEEP_32_TIMES 0x04
131 #define UVA_MODE_CTRL_SLEEP_64_TIMES 0x05
132 #define UVA_MODE_CTRL_SLEEP_128_TIMES 0x06
133 #define UVA_MODE_CTRL_SLEEP_256_TIMES 0x07
134 
139 #define UVA_SOFT_RESET 0xA5
140 
145 #define UVA_NVM_READ_ADDRESS_OFFSET 0x0A
146 #define UVA_NVM_READ_ADDRESS_A_SCALE 0x0B
147 
153 #define UVA_SET_DEV_ADDR 0x39
154  // uva_set
156 
171 #define UVA_MAP_MIKROBUS( cfg, mikrobus ) \
172  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
173  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
174  // uva_map // uva
177 
182 typedef struct
183 {
184  // Modules
185  i2c_master_t i2c;
187  // I2C slave address
188  uint8_t slave_address;
190 } uva_t;
191 
196 typedef struct
197 {
198  pin_name_t scl;
199  pin_name_t sda;
201  uint32_t i2c_speed;
202  uint8_t i2c_address;
204 } uva_cfg_t;
205 
210 typedef enum
211 {
212  UVA_OK = 0,
213  UVA_ERROR = -1
214 
216 
232 void uva_cfg_setup ( uva_cfg_t *cfg );
233 
248 err_t uva_init ( uva_t *ctx, uva_cfg_t *cfg );
249 
263 err_t uva_default_cfg ( uva_t *ctx );
264 
280 err_t uva_generic_write ( uva_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
281 
297 err_t uva_generic_read ( uva_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
298 
312 err_t uva_write_register ( uva_t *ctx, uint8_t reg, uint8_t data_in );
313 
327 err_t uva_read_register ( uva_t *ctx, uint8_t reg, uint8_t *data_out );
328 
341 
354 err_t uva_read_data ( uva_t *ctx, uint16_t *uva_data );
355 
367 err_t uva_soft_reset ( uva_t *ctx );
368 
369 #ifdef __cplusplus
370 }
371 #endif
372 #endif // UVA_H
373  // uva
375 
376 // ------------------------------------------------------------------------ END
uva_read_data
err_t uva_read_data(uva_t *ctx, uint16_t *uva_data)
UVA read data function.
uva_generic_read
err_t uva_generic_read(uva_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
UVA I2C reading function.
uva_read_register
err_t uva_read_register(uva_t *ctx, uint8_t reg, uint8_t *data_out)
UVA read register function.
UVA_OK
@ UVA_OK
Definition: uva.h:212
uva_check_communication
err_t uva_check_communication(uva_t *ctx)
UVA check communication function.
uva_cfg_t::sda
pin_name_t sda
Definition: uva.h:199
uva_cfg_t::scl
pin_name_t scl
Definition: uva.h:198
uva_return_value_t
uva_return_value_t
UVA Click return value data.
Definition: uva.h:211
uva_init
err_t uva_init(uva_t *ctx, uva_cfg_t *cfg)
UVA initialization function.
uva_soft_reset
err_t uva_soft_reset(uva_t *ctx)
UVA soft reset function.
uva_cfg_setup
void uva_cfg_setup(uva_cfg_t *cfg)
UVA configuration object setup function.
uva_t::slave_address
uint8_t slave_address
Definition: uva.h:188
uva_default_cfg
err_t uva_default_cfg(uva_t *ctx)
UVA default configuration function.
UVA_ERROR
@ UVA_ERROR
Definition: uva.h:213
uva_t::i2c
i2c_master_t i2c
Definition: uva.h:185
uva_cfg_t
UVA Click configuration object.
Definition: uva.h:197
uva_write_register
err_t uva_write_register(uva_t *ctx, uint8_t reg, uint8_t data_in)
UVA write register function.
uva_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uva.h:201
uva_generic_write
err_t uva_generic_write(uva_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
UVA I2C writing function.
uva_t
UVA Click context object.
Definition: uva.h:183
uva_cfg_t::i2c_address
uint8_t i2c_address
Definition: uva.h:202