uv3 2.0.0.0
uv3.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef UV3_H
36#define UV3_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define UV3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.ack = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define UV3_RETVAL uint8_t
77
78#define UV3_OK 0x00
79#define UV3_INIT_ERROR 0xFF
86#define UV3_I2C_ADDR_DEFAULT 0x38
87#define UV3_ADDR_ARA 0x0C
88#define UV3_ADDR_CMD 0x38
89#define UV3_ADDR_DATA_LSB 0x38
90#define UV3_ADDR_DATA_MSB 0x39
97#define UV3_CMD_DEFAULT 0x02
98#define UV3_CMD_SD 0x01
99#define UV3_CMD_IT_0_5T 0x00
100#define UV3_CMD_IT_1T 0x04
101#define UV3_CMD_IT_2T 0x08
102#define UV3_CMD_IT_4T 0x0C
109#define UV3_RAD_LOW 0x01
110#define UV3_RAD_MODERATE 0x02
111#define UV3_RAD_HIGH 0x03
112#define UV3_RAD_VERY_HIGH 0x04
113#define UV3_RAD_EXTREME 0x05
116 // End group macro
117// --------------------------------------------------------------- PUBLIC TYPES
126typedef struct
127{
128 // Input pins
129
130 digital_in_t ack;
131
132 // Modules
133
134 i2c_master_t i2c;
135
136 // ctx variable
137
139
140} uv3_t;
141
145typedef struct
146{
147 // Communication gpio pins
148
149 pin_name_t scl;
150 pin_name_t sda;
151
152 // Additional gpio pins
153
154 pin_name_t ack;
155
156 // static variable
157
158 uint32_t i2c_speed;
159 uint8_t i2c_address;
160
161} uv3_cfg_t;
162
163 // End types group
164// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
165
171#ifdef __cplusplus
172extern "C"{
173#endif
174
184
194
202void uv3_default_cfg ( uv3_t *ctx );
203
214void uv3_write_command ( uv3_t *ctx, uint8_t slave_addr, uint8_t command );
215
227uint8_t uv3_read_byte ( uv3_t *ctx, uint8_t slave_addr );
228
237void uv3_clear_ack ( uv3_t *ctx );
238
248
258
277void uv3_set_integration_time ( uv3_t *ctx, uint8_t int_data );
278
287uint16_t uv3_read_measurements ( uv3_t *ctx );
288
307uint8_t uv3_risk_level ( uint16_t uv_data );
308
318uint8_t uv3_get_interrupt ( uv3_t *ctx );
319
320
321#ifdef __cplusplus
322}
323#endif
324#endif // _UV3_H_
325
326 // End public_function group
328
329// ------------------------------------------------------------------------- END
#define UV3_RETVAL
Definition uv3.h:76
void uv3_default_cfg(uv3_t *ctx)
Click Default Configuration function.
UV3_RETVAL uv3_init(uv3_t *ctx, uv3_cfg_t *cfg)
Initialization function.
void uv3_set_integration_time(uv3_t *ctx, uint8_t int_data)
Set integration time function.
void uv3_enable_sensor(uv3_t *ctx)
Enable sensor function.
void uv3_disable_mode(uv3_t *ctx)
Disable sensor function.
uint8_t uv3_get_interrupt(uv3_t *ctx)
Get state of interrupt pin function.
uint8_t uv3_risk_level(uint16_t uv_data)
Calculate UV risk level function.
uint8_t uv3_read_byte(uv3_t *ctx, uint8_t slave_addr)
Read function.
uint16_t uv3_read_measurements(uv3_t *ctx)
Get UV data measurements function.
void uv3_cfg_setup(uv3_cfg_t *cfg)
Config Object Initialization function.
void uv3_write_command(uv3_t *ctx, uint8_t slave_addr, uint8_t command)
Write function.
void uv3_clear_ack(uv3_t *ctx)
Read ARA to clear interrupt function.
Click configuration structure definition.
Definition uv3.h:146
uint32_t i2c_speed
Definition uv3.h:158
pin_name_t ack
Definition uv3.h:154
pin_name_t scl
Definition uv3.h:149
pin_name_t sda
Definition uv3.h:150
uint8_t i2c_address
Definition uv3.h:159
Click ctx object definition.
Definition uv3.h:127
digital_in_t ack
Definition uv3.h:130
i2c_master_t i2c
Definition uv3.h:134
uint8_t slave_address
Definition uv3.h:138