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
32extern "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 UV5_CFG_STATE_REG_OSR 0x00
60#define UV5_CFG_STATE_REG_AGEN 0x02
61#define UV5_CFG_STATE_REG_CREG1 0x06
62#define UV5_CFG_STATE_REG_CREG2 0x07
63#define UV5_CFG_STATE_REG_CREG3 0x08
64#define UV5_CFG_STATE_REG_BREAK 0x09
65#define UV5_CFG_STATE_REG_EDGES 0x0A
66#define UV5_CFG_STATE_REG_OPTREG 0x0B
67#define UV5_MESASURE_STATE_REG_OSR 0x00
68#define UV5_MESASURE_STATE_REG_TEMP 0x01
69#define UV5_MESASURE_STATE_REG_MRES1 0x02
70#define UV5_MESASURE_STATE_REG_MRES2 0x03
71#define UV5_MESASURE_STATE_REG_MRES3 0x04
72#define UV5_MESASURE_STATE_REG_OUTCONV_L 0x05
73#define UV5_MESASURE_STATE_REG_OUTCONV_H 0x06
74 // uv5_reg
76
96#define UV5_START_MEASURMENT 0x80
97#define UV5_POWER_DOWN 0x40
98#define UV5_SW_RESET 0x08
99#define UV5_CONFIGURATION_MODE 0x02
100#define UV5_MEASUREMENT_MODE 0x03
101
106#define UV5_DEVID 0x20
107#define UV5_MUT 0x01
108
113#define UV5_GAIN_2048X 0x00
114#define UV5_GAIN_1024X 0x10
115#define UV5_GAIN_512X 0x20
116#define UV5_GAIN_256X 0x30
117#define UV5_GAIN_128X 0x40
118#define UV5_GAIN_64X 0x50
119#define UV5_GAIN_32X 0x60
120#define UV5_GAIN_16X 0x70
121#define UV5_GAIN_8X 0x80
122#define UV5_GAIN_4X 0x90
123#define UV5_GAIN_2X 0xA0
124#define UV5_GAIN_1X 0xB0
125#define UV5_TIME_1_MS 0x00
126#define UV5_TIME_2_MS 0x01
127#define UV5_TIME_4_MS 0x02
128#define UV5_TIME_8_MS 0x03
129#define UV5_TIME_16_MS 0x04
130#define UV5_TIME_32_MS 0x05
131#define UV5_TIME_64_MS 0x06
132#define UV5_TIME_128_MS 0x07
133#define UV5_TIME_256_MS 0x08
134#define UV5_TIME_512_MS 0x09
135#define UV5_TIME_1024_MS 0x0A
136#define UV5_TIME_2048_MS 0x0B
137#define UV5_TIME_4096_MS 0x0C
138#define UV5_TIME_8192_MS 0x0D
139#define UV5_TIME_16384_MS 0x0E
140
145#define UV5_EN_TM 0x40
146#define UV5_EN_DIV 0x08
147#define UV5_DIV_256 0x07
148#define UV5_DIV_128 0x06
149#define UV5_DIV_64 0x05
150#define UV5_DIV_32 0x04
151#define UV5_DIV_16 0x03
152#define UV5_DIV_8 0x02
153#define UV5_DIV_4 0x01
154#define UV5_DIV_2 0x00
155
160#define UV5_MMODE_CONT 0x00
161#define UV5_MMODE_CMD 0x40
162#define UV5_MMODE_SYNS 0x80
163#define UV5_MMODE_SYND 0xC0
164#define UV5_STANDBY_ON 0x10
165#define UV5_READY_PUSH_PULL 0x00
166#define UV5_READY_OPEN_DRAIN 0x08
167#define UV5_CCLK_1024_KHZ 0x00
168#define UV5_CCLK_2048_KHZ 0x01
169#define UV5_CCLK_4096_KHZ 0x02
170#define UV5_CCLK_8192_KHZ 0x03
171
172#define UV5_TEMPERATURE_CALC_CONST 0.05
173#define UV5_TEMPERATURE_CALC_VALUE 66.9
174
180#define UV5_DEVICE_ADDRESS_00 0x74
181#define UV5_DEVICE_ADDRESS_01 0x75
182#define UV5_DEVICE_ADDRESS_10 0x76
183#define UV5_DEVICE_ADDRESS_11 0x77
184 // uv5_set
186
201#define UV5_MAP_MIKROBUS( cfg, mikrobus ) \
202 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
203 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
204 cfg.syn = MIKROBUS( mikrobus, MIKROBUS_RST ); \
205 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
206 // uv5_map // uv5
209
214typedef struct
215{
216 // Output pins
217 digital_out_t syn;
219 // Input pins
220 digital_in_t rdy;
222 // Modules
223 i2c_master_t i2c;
225 // I2C slave address
228} uv5_t;
229
234typedef struct
235{
236 pin_name_t scl;
237 pin_name_t sda;
239 pin_name_t syn;
240 pin_name_t rdy;
242 uint32_t i2c_speed;
243 uint8_t i2c_address;
245} uv5_cfg_t;
246
251typedef enum
252{
254 UV5_ERROR = -1
255
257
274
288err_t uv5_init ( uv5_t *ctx, uv5_cfg_t *cfg );
289
302err_t uv5_default_cfg ( uv5_t *ctx );
303
318err_t uv5_generic_write ( uv5_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
319
334err_t uv5_generic_read ( uv5_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
335
336
350err_t uv5_write_cfg_reg ( uv5_t *ctx, uint8_t reg, uint8_t data_in );
351
365err_t uv5_write_measu_reg ( uv5_t *ctx, uint8_t reg, uint8_t *data_in );
366
380err_t uv5_read_cfg_reg ( uv5_t *ctx, uint8_t reg, uint8_t *data_out );
381
395err_t uv5_read_measu_reg ( uv5_t *ctx, uint8_t reg, uint8_t *data_out );
396
406void uv5_set_syn_pin ( uv5_t *ctx, uint8_t pin_state );
407
417uint8_t uv5_get_rdy_pin ( uv5_t *ctx );
418
429err_t uv5_sw_reset ( uv5_t *ctx );
430
442err_t uv5_temperature_read ( uv5_t *ctx, float *temp_data );
443
455err_t uv5_channel_uva_read ( uv5_t *ctx, uint16_t *uva_data );
456
468err_t uv5_channel_uvb_read ( uv5_t *ctx, uint16_t *uvb_data );
469
481err_t uv5_channel_uvc_read ( uv5_t *ctx, uint16_t *uvc_data );
482
483#ifdef __cplusplus
484}
485#endif
486#endif // UV5_H
487 // uv5
489
490// ------------------------------------------------------------------------ END
err_t uv5_channel_uvc_read(uv5_t *ctx, uint16_t *uvc_data)
UV 5 read raw UVC data function.
err_t uv5_temperature_read(uv5_t *ctx, float *temp_data)
UV 5 read temperature function.
void uv5_cfg_setup(uv5_cfg_t *cfg)
UV 5 configuration object setup function.
err_t uv5_channel_uvb_read(uv5_t *ctx, uint16_t *uvb_data)
UV 5 read raw UVB data function.
err_t uv5_generic_read(uv5_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
UV 5 I2C reading function.
err_t uv5_init(uv5_t *ctx, uv5_cfg_t *cfg)
UV 5 initialization function.
err_t uv5_generic_write(uv5_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
UV 5 I2C writing function.
err_t uv5_default_cfg(uv5_t *ctx)
UV 5 default configuration function.
err_t uv5_read_cfg_reg(uv5_t *ctx, uint8_t reg, uint8_t *data_out)
UV 5 configuration mode register reading function.
err_t uv5_write_cfg_reg(uv5_t *ctx, uint8_t reg, uint8_t data_in)
UV 5 configuration mode register write function.
err_t uv5_sw_reset(uv5_t *ctx)
UV 5 software reset function.
err_t uv5_read_measu_reg(uv5_t *ctx, uint8_t reg, uint8_t *data_out)
UV 5 measurement mode register reading function.
void uv5_set_syn_pin(uv5_t *ctx, uint8_t pin_state)
UV 5 set SYN pin state function.
uint8_t uv5_get_rdy_pin(uv5_t *ctx)
UV 5 get READY pin state function.
err_t uv5_channel_uva_read(uv5_t *ctx, uint16_t *uva_data)
UV 5 read raw UVA data function.
err_t uv5_write_measu_reg(uv5_t *ctx, uint8_t reg, uint8_t *data_in)
UV 5 measurement mode register write function.
UV 5 Click configuration object.
Definition: uv5.h:235
uint32_t i2c_speed
Definition: uv5.h:242
pin_name_t scl
Definition: uv5.h:236
pin_name_t rdy
Definition: uv5.h:240
pin_name_t sda
Definition: uv5.h:237
pin_name_t syn
Definition: uv5.h:239
uint8_t i2c_address
Definition: uv5.h:243
UV 5 Click context object.
Definition: uv5.h:215
digital_out_t syn
Definition: uv5.h:217
i2c_master_t i2c
Definition: uv5.h:223
uint8_t slave_address
Definition: uv5.h:226
digital_in_t rdy
Definition: uv5.h:220
uv5_return_value_t
UV 5 Click return value data.
Definition: uv5.h:252
@ UV5_ERROR
Definition: uv5.h:254
@ UV5_OK
Definition: uv5.h:253