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 "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 UVA_REG_CHIP_ID 0x00
70 #define UVA_REG_MODE 0x01
71 #define UVA_REG_RES_UV 0x04
72 #define UVA_REG_RANGE_UVA 0x05
73 #define UVA_REG_MODE_CTRL 0x0A
74 #define UVA_REG_SOFT_RESET 0x0B
75 #define UVA_REG_UVA_LSB 0x15
76 #define UVA_REG_UVA_MSB 0x16
77 #define UVA_REG_NVM_READ_CTRL 0x30
78 #define UVA_REG_NVM_MSB 0x31
79 #define UVA_REG_NVM_LSB 0x32
80  // uva_reg
82 
97 #define UVA_CHIP_ID 0x62
98 
103 #define UVA_MODE_NO_OPERATION 0x00
104 #define UVA_MODE_UVA_OPERATION 0x10
105 #define UVA_MODE_NORMAL 0x00
106 #define UVA_MODE_LOW_POWER 0x01
107 #define UVA_MODE_AUTO_SHUTDOWN 0x02
108 #define UVA_MODE_SHUTDOWN 0x03
109 
114 #define UVA_RESOLUTION_800MS 0x00
115 #define UVA_RESOLUTION_400MS 0x01
116 #define UVA_RESOLUTION_200MS 0x02
117 #define UVA_RESOLUTION_100MS 0x03
118 
123 #define UVA_RANGE_X1 0x00
124 #define UVA_RANGE_X2 0x01
125 #define UVA_RANGE_X4 0x02
126 #define UVA_RANGE_X8 0x03
127 #define UVA_RANGE_X16 0x04
128 #define UVA_RANGE_X32 0x05
129 #define UVA_RANGE_X64 0x06
130 #define UVA_RANGE_X128 0x07
131 
136 #define UVA_MODE_CTRL_SLEEP_2_TIMES 0x00
137 #define UVA_MODE_CTRL_SLEEP_4_TIMES 0x01
138 #define UVA_MODE_CTRL_SLEEP_8_TIMES 0x02
139 #define UVA_MODE_CTRL_SLEEP_16_TIMES 0x03
140 #define UVA_MODE_CTRL_SLEEP_32_TIMES 0x04
141 #define UVA_MODE_CTRL_SLEEP_64_TIMES 0x05
142 #define UVA_MODE_CTRL_SLEEP_128_TIMES 0x06
143 #define UVA_MODE_CTRL_SLEEP_256_TIMES 0x07
144 
149 #define UVA_SOFT_RESET 0xA5
150 
155 #define UVA_NVM_READ_ADDRESS_OFFSET 0x0A
156 #define UVA_NVM_READ_ADDRESS_A_SCALE 0x0B
157 
163 #define UVA_SET_DEV_ADDR 0x39
164  // uva_set
166 
181 #define UVA_MAP_MIKROBUS( cfg, mikrobus ) \
182  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
183  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
184  // uva_map // uva
187 
192 typedef struct
193 {
194  // Modules
195  i2c_master_t i2c;
197  // I2C slave address
198  uint8_t slave_address;
200 } uva_t;
201 
206 typedef struct
207 {
208  pin_name_t scl;
209  pin_name_t sda;
211  uint32_t i2c_speed;
212  uint8_t i2c_address;
214 } uva_cfg_t;
215 
220 typedef enum
221 {
222  UVA_OK = 0,
223  UVA_ERROR = -1
224 
226 
242 void uva_cfg_setup ( uva_cfg_t *cfg );
243 
258 err_t uva_init ( uva_t *ctx, uva_cfg_t *cfg );
259 
273 err_t uva_default_cfg ( uva_t *ctx );
274 
290 err_t uva_generic_write ( uva_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
291 
307 err_t uva_generic_read ( uva_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
308 
322 err_t uva_write_register ( uva_t *ctx, uint8_t reg, uint8_t data_in );
323 
337 err_t uva_read_register ( uva_t *ctx, uint8_t reg, uint8_t *data_out );
338 
351 
364 err_t uva_read_data ( uva_t *ctx, uint16_t *uva_data );
365 
377 err_t uva_soft_reset ( uva_t *ctx );
378 
379 #ifdef __cplusplus
380 }
381 #endif
382 #endif // UVA_H
383  // uva
385 
386 // ------------------------------------------------------------------------ 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:222
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:209
uva_cfg_t::scl
pin_name_t scl
Definition: uva.h:208
uva_return_value_t
uva_return_value_t
UVA Click return value data.
Definition: uva.h:221
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:198
uva_default_cfg
err_t uva_default_cfg(uva_t *ctx)
UVA default configuration function.
UVA_ERROR
@ UVA_ERROR
Definition: uva.h:223
uva_t::i2c
i2c_master_t i2c
Definition: uva.h:195
uva_cfg_t
UVA Click configuration object.
Definition: uva.h:207
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:211
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:193
uva_cfg_t::i2c_address
uint8_t i2c_address
Definition: uva.h:212