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 )
70 
76 #define UV3_RETVAL uint8_t
77 
78 #define UV3_OK 0x00
79 #define UV3_INIT_ERROR 0xFF
80 
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
91 
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
103 
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
114  // End group macro
117 // --------------------------------------------------------------- PUBLIC TYPES
126 typedef 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 
138  uint8_t slave_address;
139 
140 } uv3_t;
141 
145 typedef 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  // End types group
164 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
165 
171 #ifdef __cplusplus
172 extern "C"{
173 #endif
174 
183 void uv3_cfg_setup ( uv3_cfg_t *cfg );
184 
194 
202 void uv3_default_cfg ( uv3_t *ctx );
203 
214 void uv3_write_command ( uv3_t *ctx, uint8_t slave_addr, uint8_t command );
215 
227 uint8_t uv3_read_byte ( uv3_t *ctx, uint8_t slave_addr );
228 
237 void uv3_clear_ack ( uv3_t *ctx );
238 
247 void uv3_enable_sensor ( uv3_t *ctx );
248 
257 void uv3_disable_mode ( uv3_t *ctx );
258 
277 void uv3_set_integration_time ( uv3_t *ctx, uint8_t int_data );
278 
287 uint16_t uv3_read_measurements ( uv3_t *ctx );
288 
307 uint8_t uv3_risk_level ( uint16_t uv_data );
308 
318 uint8_t uv3_get_interrupt ( uv3_t *ctx );
319 
320 
321 #ifdef __cplusplus
322 }
323 #endif
324 #endif // _UV3_H_
325  // End public_function group
328 
329 // ------------------------------------------------------------------------- END
uv3_read_measurements
uint16_t uv3_read_measurements(uv3_t *ctx)
Get UV data measurements function.
uv3_get_interrupt
uint8_t uv3_get_interrupt(uv3_t *ctx)
Get state of interrupt pin function.
uv3_enable_sensor
void uv3_enable_sensor(uv3_t *ctx)
Enable sensor function.
UV3_RETVAL
#define UV3_RETVAL
Definition: uv3.h:76
uv3_default_cfg
void uv3_default_cfg(uv3_t *ctx)
Click Default Configuration function.
uv3_t
Click ctx object definition.
Definition: uv3.h:127
uv3_disable_mode
void uv3_disable_mode(uv3_t *ctx)
Disable sensor function.
uv3_t::i2c
i2c_master_t i2c
Definition: uv3.h:134
uv3_read_byte
uint8_t uv3_read_byte(uv3_t *ctx, uint8_t slave_addr)
Read function.
uv3_cfg_t
Click configuration structure definition.
Definition: uv3.h:146
uv3_t::ack
digital_in_t ack
Definition: uv3.h:130
uv3_cfg_t::sda
pin_name_t sda
Definition: uv3.h:150
uv3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: uv3.h:158
uv3_clear_ack
void uv3_clear_ack(uv3_t *ctx)
Read ARA to clear interrupt function.
uv3_risk_level
uint8_t uv3_risk_level(uint16_t uv_data)
Calculate UV risk level function.
uv3_t::slave_address
uint8_t slave_address
Definition: uv3.h:138
uv3_write_command
void uv3_write_command(uv3_t *ctx, uint8_t slave_addr, uint8_t command)
Write function.
uv3_cfg_t::ack
pin_name_t ack
Definition: uv3.h:154
uv3_cfg_t::scl
pin_name_t scl
Definition: uv3.h:149
uv3_init
UV3_RETVAL uv3_init(uv3_t *ctx, uv3_cfg_t *cfg)
Initialization function.
uv3_set_integration_time
void uv3_set_integration_time(uv3_t *ctx, uint8_t int_data)
Set integration time function.
uv3_cfg_t::i2c_address
uint8_t i2c_address
Definition: uv3.h:159
uv3_cfg_setup
void uv3_cfg_setup(uv3_cfg_t *cfg)
Config Object Initialization function.