uv5  2.1.0.0
uv5.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 UV5_H
29 #define UV5_H
30 
31 #ifdef __cplusplus
32 extern "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 UV5_CFG_STATE_REG_OSR 0x00
74 #define UV5_CFG_STATE_REG_AGEN 0x02
75 #define UV5_CFG_STATE_REG_CREG1 0x06
76 #define UV5_CFG_STATE_REG_CREG2 0x07
77 #define UV5_CFG_STATE_REG_CREG3 0x08
78 #define UV5_CFG_STATE_REG_BREAK 0x09
79 #define UV5_CFG_STATE_REG_EDGES 0x0A
80 #define UV5_CFG_STATE_REG_OPTREG 0x0B
81 #define UV5_MESASURE_STATE_REG_OSR 0x00
82 #define UV5_MESASURE_STATE_REG_TEMP 0x01
83 #define UV5_MESASURE_STATE_REG_MRES1 0x02
84 #define UV5_MESASURE_STATE_REG_MRES2 0x03
85 #define UV5_MESASURE_STATE_REG_MRES3 0x04
86 #define UV5_MESASURE_STATE_REG_OUTCONV_L 0x05
87 #define UV5_MESASURE_STATE_REG_OUTCONV_H 0x06
88  // uv5_reg
90 
110 #define UV5_START_MEASURMENT 0x80
111 #define UV5_POWER_DOWN 0x40
112 #define UV5_SW_RESET 0x08
113 #define UV5_CONFIGURATION_MODE 0x02
114 #define UV5_MEASUREMENT_MODE 0x03
115 
120 #define UV5_DEVID 0x20
121 #define UV5_MUT 0x01
122 
127 #define UV5_GAIN_2048X 0x00
128 #define UV5_GAIN_1024X 0x10
129 #define UV5_GAIN_512X 0x20
130 #define UV5_GAIN_256X 0x30
131 #define UV5_GAIN_128X 0x40
132 #define UV5_GAIN_64X 0x50
133 #define UV5_GAIN_32X 0x60
134 #define UV5_GAIN_16X 0x70
135 #define UV5_GAIN_8X 0x80
136 #define UV5_GAIN_4X 0x90
137 #define UV5_GAIN_2X 0xA0
138 #define UV5_GAIN_1X 0xB0
139 #define UV5_TIME_1_MS 0x00
140 #define UV5_TIME_2_MS 0x01
141 #define UV5_TIME_4_MS 0x02
142 #define UV5_TIME_8_MS 0x03
143 #define UV5_TIME_16_MS 0x04
144 #define UV5_TIME_32_MS 0x05
145 #define UV5_TIME_64_MS 0x06
146 #define UV5_TIME_128_MS 0x07
147 #define UV5_TIME_256_MS 0x08
148 #define UV5_TIME_512_MS 0x09
149 #define UV5_TIME_1024_MS 0x0A
150 #define UV5_TIME_2048_MS 0x0B
151 #define UV5_TIME_4096_MS 0x0C
152 #define UV5_TIME_8192_MS 0x0D
153 #define UV5_TIME_16384_MS 0x0E
154 
159 #define UV5_EN_TM 0x40
160 #define UV5_EN_DIV 0x08
161 #define UV5_DIV_256 0x07
162 #define UV5_DIV_128 0x06
163 #define UV5_DIV_64 0x05
164 #define UV5_DIV_32 0x04
165 #define UV5_DIV_16 0x03
166 #define UV5_DIV_8 0x02
167 #define UV5_DIV_4 0x01
168 #define UV5_DIV_2 0x00
169 
174 #define UV5_MMODE_CONT 0x00
175 #define UV5_MMODE_CMD 0x40
176 #define UV5_MMODE_SYNS 0x80
177 #define UV5_MMODE_SYND 0xC0
178 #define UV5_STANDBY_ON 0x10
179 #define UV5_READY_PUSH_PULL 0x00
180 #define UV5_READY_OPEN_DRAIN 0x08
181 #define UV5_CCLK_1024_KHZ 0x00
182 #define UV5_CCLK_2048_KHZ 0x01
183 #define UV5_CCLK_4096_KHZ 0x02
184 #define UV5_CCLK_8192_KHZ 0x03
185 
186 #define UV5_TEMPERATURE_CALC_CONST 0.05
187 #define UV5_TEMPERATURE_CALC_VALUE 66.9
188 
194 #define UV5_DEVICE_ADDRESS_00 0x74
195 #define UV5_DEVICE_ADDRESS_01 0x75
196 #define UV5_DEVICE_ADDRESS_10 0x76
197 #define UV5_DEVICE_ADDRESS_11 0x77
198  // uv5_set
200 
215 #define UV5_MAP_MIKROBUS( cfg, mikrobus ) \
216  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
217  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
218  cfg.syn = MIKROBUS( mikrobus, MIKROBUS_RST ); \
219  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
220  // uv5_map // uv5
223 
228 typedef struct
229 {
230  // Output pins
231  digital_out_t syn;
233  // Input pins
234  digital_in_t rdy;
236  // Modules
237  i2c_master_t i2c;
239  // I2C slave address
240  uint8_t slave_address;
242 } uv5_t;
243 
248 typedef struct
249 {
250  pin_name_t scl;
251  pin_name_t sda;
253  pin_name_t syn;
254  pin_name_t rdy;
256  uint32_t i2c_speed;
257  uint8_t i2c_address;
259 } uv5_cfg_t;
260 
265 typedef enum
266 {
267  UV5_OK = 0,
268  UV5_ERROR = -1
269 
271 
287 void uv5_cfg_setup ( uv5_cfg_t *cfg );
288 
302 err_t uv5_init ( uv5_t *ctx, uv5_cfg_t *cfg );
303 
316 err_t uv5_default_cfg ( uv5_t *ctx );
317 
332 err_t uv5_generic_write ( uv5_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
333 
348 err_t uv5_generic_read ( uv5_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
349 
350 
364 err_t uv5_write_cfg_reg ( uv5_t *ctx, uint8_t reg, uint8_t data_in );
365 
379 err_t uv5_write_measu_reg ( uv5_t *ctx, uint8_t reg, uint8_t *data_in );
380 
394 err_t uv5_read_cfg_reg ( uv5_t *ctx, uint8_t reg, uint8_t *data_out );
395 
409 err_t uv5_read_measu_reg ( uv5_t *ctx, uint8_t reg, uint8_t *data_out );
410 
420 void uv5_set_syn_pin ( uv5_t *ctx, uint8_t pin_state );
421 
431 uint8_t uv5_get_rdy_pin ( uv5_t *ctx );
432 
443 err_t uv5_sw_reset ( uv5_t *ctx );
444 
456 err_t uv5_temperature_read ( uv5_t *ctx, float *temp_data );
457 
469 err_t uv5_channel_uva_read ( uv5_t *ctx, uint16_t *uva_data );
470 
482 err_t uv5_channel_uvb_read ( uv5_t *ctx, uint16_t *uvb_data );
483 
495 err_t uv5_channel_uvc_read ( uv5_t *ctx, uint16_t *uvc_data );
496 
497 #ifdef __cplusplus
498 }
499 #endif
500 #endif // UV5_H
501  // uv5
503 
504 // ------------------------------------------------------------------------ END
uv5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uv5.h:256
uv5_channel_uvc_read
err_t uv5_channel_uvc_read(uv5_t *ctx, uint16_t *uvc_data)
UV 5 read raw UVC data function.
uv5_set_syn_pin
void uv5_set_syn_pin(uv5_t *ctx, uint8_t pin_state)
UV 5 set SYN pin state function.
uv5_sw_reset
err_t uv5_sw_reset(uv5_t *ctx)
UV 5 software reset function.
uv5_cfg_t::sda
pin_name_t sda
Definition: uv5.h:251
uv5_t::i2c
i2c_master_t i2c
Definition: uv5.h:237
uv5_t::slave_address
uint8_t slave_address
Definition: uv5.h:240
uv5_get_rdy_pin
uint8_t uv5_get_rdy_pin(uv5_t *ctx)
UV 5 get READY pin state function.
uv5_generic_read
err_t uv5_generic_read(uv5_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
UV 5 I2C reading function.
uv5_read_cfg_reg
err_t uv5_read_cfg_reg(uv5_t *ctx, uint8_t reg, uint8_t *data_out)
UV 5 configuration mode register reading function.
uv5_cfg_setup
void uv5_cfg_setup(uv5_cfg_t *cfg)
UV 5 configuration object setup function.
uv5_cfg_t::scl
pin_name_t scl
Definition: uv5.h:250
uv5_t::rdy
digital_in_t rdy
Definition: uv5.h:234
uv5_t
UV 5 Click context object.
Definition: uv5.h:229
uv5_read_measu_reg
err_t uv5_read_measu_reg(uv5_t *ctx, uint8_t reg, uint8_t *data_out)
UV 5 measurement mode register reading function.
uv5_cfg_t
UV 5 Click configuration object.
Definition: uv5.h:249
uv5_default_cfg
err_t uv5_default_cfg(uv5_t *ctx)
UV 5 default configuration function.
uv5_temperature_read
err_t uv5_temperature_read(uv5_t *ctx, float *temp_data)
UV 5 read temperature function.
uv5_return_value_t
uv5_return_value_t
UV 5 Click return value data.
Definition: uv5.h:266
uv5_channel_uvb_read
err_t uv5_channel_uvb_read(uv5_t *ctx, uint16_t *uvb_data)
UV 5 read raw UVB data function.
uv5_write_cfg_reg
err_t uv5_write_cfg_reg(uv5_t *ctx, uint8_t reg, uint8_t data_in)
UV 5 configuration mode register write function.
uv5_generic_write
err_t uv5_generic_write(uv5_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
UV 5 I2C writing function.
uv5_cfg_t::syn
pin_name_t syn
Definition: uv5.h:253
uv5_write_measu_reg
err_t uv5_write_measu_reg(uv5_t *ctx, uint8_t reg, uint8_t *data_in)
UV 5 measurement mode register write function.
uv5_t::syn
digital_out_t syn
Definition: uv5.h:231
uv5_cfg_t::rdy
pin_name_t rdy
Definition: uv5.h:254
uv5_channel_uva_read
err_t uv5_channel_uva_read(uv5_t *ctx, uint16_t *uva_data)
UV 5 read raw UVA data function.
UV5_ERROR
@ UV5_ERROR
Definition: uv5.h:268
UV5_OK
@ UV5_OK
Definition: uv5.h:267
uv5_cfg_t::i2c_address
uint8_t i2c_address
Definition: uv5.h:257
uv5_init
err_t uv5_init(uv5_t *ctx, uv5_cfg_t *cfg)
UV 5 initialization function.