illuminance  2.0.0.0
illuminance.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 ILLUMINANCE_H
36 #define ILLUMINANCE_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define ILLUMINANCE_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define ILLUMINANCE_RETVAL uint8_t
64 
65 #define ILLUMINANCE_OK 0x00
66 #define ILLUMINANCE_INIT_ERROR 0xFF
67 
73 #define ILLUMINANCE_TSL2561_I2C_ADDR_LOW 0x29
74 #define ILLUMINANCE_TSL2561_I2C_ADDR_FLOAT 0x39
75 #define ILLUMINANCE_TSL2561_I2C_ADDR_HIGH 0x49
76 
82 #define ILLUMINANCE_TSL2561_REGISTER_CONTROL 0x00
83 #define ILLUMINANCE_TSL2561_REGISTER_TIMING 0x01
84 #define ILLUMINANCE_TSL2561_REGISTER_THRESHHOLDL_LOW 0x02
85 #define ILLUMINANCE_TSL2561_REGISTER_THRESHHOLDL_HIGH 0x03
86 #define ILLUMINANCE_TSL2561_REGISTER_THRESHHOLDH_LOW 0x04
87 #define ILLUMINANCE_TSL2561_REGISTER_THRESHHOLDH_HIGH 0x05
88 #define ILLUMINANCE_TSL2561_REGISTER_INTERRUPT 0x06
89 #define ILLUMINANCE_TSL2561_REGISTER_CRC 0x08
90 #define ILLUMINANCE_TSL2561_REGISTER_ID 0x0A
91 #define ILLUMINANCE_TSL2561_REGISTER_CHAN0_LOW 0x0C
92 #define ILLUMINANCE_TSL2561_REGISTER_CHAN0_HIGH 0x0D
93 #define ILLUMINANCE_TSL2561_REGISTER_CHAN1_LOW 0x0E
94 #define ILLUMINANCE_TSL2561_REGISTER_CHAN1_HIGH 0x0F
95 
101 #define ILLUMINANCE_TSL2561_INTEGRATIONTIME_13MS 0x00
102 #define ILLUMINANCE_TSL2561_INTEGRATIONTIME_101MS 0x01
103 #define ILLUMINANCE_TSL2561_INTEGRATIONTIME_402MS 0x02
104 #define ILLUMINANCE_TSL2561_GAIN_0X 0x00
105 #define ILLUMINANCE_TSL2561_GAIN_16X 0x10
106 #define ILLUMINANCE_TSL2561_COMMAND_BIT 0x80
107 #define ILLUMINANCE_TSL2561_CLEAR_BIT 0x40
108 #define ILLUMINANCE_TSL2561_WORD_BIT 0x20
109 #define ILLUMINANCE_TSL2561_BLOCK_BIT 0x10
110 #define ILLUMINANCE_TSL2561_CONTROL_POWERON 0x03
111 #define ILLUMINANCE_TSL2561_CONTROL_POWEROFF 0x00
112 #define ILLUMINANCE_TSL2561_CHSCALE_TINT0 0x7517
113 #define ILLUMINANCE_TSL2561_CHSCALE_TINT1 0x0FE7
114 #define ILLUMINANCE_TSL2561_LUX_SCALE 14
115 #define ILLUMINANCE_TSL2561_RATIO_SCALE 9
116 #define ILLUMINANCE_TSL2561_CH_SCALE 10
117 
123 #define ILLUMINANCE_TSL2561_K1T 0x0040
124 #define ILLUMINANCE_TSL2561_B1T 0x01f2
125 #define ILLUMINANCE_TSL2561_M1T 0x01be
126 #define ILLUMINANCE_TSL2561_K2T 0x0080
127 #define ILLUMINANCE_TSL2561_B2T 0x0214
128 #define ILLUMINANCE_TSL2561_M2T 0x02d1
129 #define ILLUMINANCE_TSL2561_K3T 0x00c0
130 #define ILLUMINANCE_TSL2561_B3T 0x023f
131 #define ILLUMINANCE_TSL2561_M3T 0x037b
132 #define ILLUMINANCE_TSL2561_K4T 0x0100
133 #define ILLUMINANCE_TSL2561_B4T 0x0270
134 #define ILLUMINANCE_TSL2561_M4T 0x03fe
135 #define ILLUMINANCE_TSL2561_K5T 0x0138
136 #define ILLUMINANCE_TSL2561_B5T 0x016f
137 #define ILLUMINANCE_TSL2561_M5T 0x01fc
138 #define ILLUMINANCE_TSL2561_K6T 0x019a
139 #define ILLUMINANCE_TSL2561_B6T 0x00d2
140 #define ILLUMINANCE_TSL2561_M6T 0x00fb
141 #define ILLUMINANCE_TSL2561_K7T 0x029a
142 #define ILLUMINANCE_TSL2561_B7T 0x0018
143 #define ILLUMINANCE_TSL2561_M7T 0x0012
144 #define ILLUMINANCE_TSL2561_K8T 0x029a
145 #define ILLUMINANCE_TSL2561_B8T 0x0000
146 #define ILLUMINANCE_TSL2561_M8T 0x0000
147  // End group macro
151 // --------------------------------------------------------------- PUBLIC TYPES
160 typedef struct
161 {
162 
163  // Input pins
164 
165  digital_in_t int_pin;
166 
167  // Modules
168 
169  i2c_master_t i2c;
170 
171  // ctx variable
172 
173  uint8_t slave_address;
174 
175 } illuminance_t;
176 
180 typedef struct
181 {
182  // Communication gpio pins
183 
184  pin_name_t scl;
185  pin_name_t sda;
186 
187  // Additional gpio pins
188 
189  pin_name_t int_pin;
190 
191  // static variable
192 
193  uint32_t i2c_speed;
194  uint8_t i2c_address;
195 
197  // End types group
199 
200 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
201 
207 #ifdef __cplusplus
208 extern "C"{
209 #endif
210 
220 
229 
239 
250 void illuminance_generic_write ( illuminance_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
251 
263 void illuminance_generic_read ( illuminance_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
264 
274 void illuminance_write_data( illuminance_t *ctx, uint8_t address, uint8_t write_command );
275 
286 uint8_t illuminance_read_data( illuminance_t *ctx, uint8_t addr );
287 
288 
298 void illuminance_get_result( illuminance_t *ctx, uint16_t *value_ch0, uint16_t *value_ch1 );
299 
313 uint16_t illuminance_calculate_lux( uint16_t value_gain, uint16_t value_int, uint16_t ch0, uint16_t ch1 );
314 
325 
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 #endif // _ILLUMINANCE_H_
331  // End public_function group
334 
335 // ------------------------------------------------------------------------- END
illuminance_cfg_t::sda
pin_name_t sda
Definition: illuminance.h:185
illuminance_t::int_pin
digital_in_t int_pin
Definition: illuminance.h:165
illuminance_default_cfg
void illuminance_default_cfg(illuminance_t *ctx)
Click Default Configuration function.
illuminance_get_interrupt
uint8_t illuminance_get_interrupt(illuminance_t *ctx)
Get interrupt pin status.
illuminance_calculate_lux
uint16_t illuminance_calculate_lux(uint16_t value_gain, uint16_t value_int, uint16_t ch0, uint16_t ch1)
Calculate lux value.
illuminance_cfg_setup
void illuminance_cfg_setup(illuminance_cfg_t *cfg)
Config Object Initialization function.
illuminance_read_data
uint8_t illuminance_read_data(illuminance_t *ctx, uint8_t addr)
Generic read data function.
illuminance_get_result
void illuminance_get_result(illuminance_t *ctx, uint16_t *value_ch0, uint16_t *value_ch1)
Get Visible & Infrared value.
illuminance_generic_read
void illuminance_generic_read(illuminance_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
illuminance_generic_write
void illuminance_generic_write(illuminance_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
illuminance_t::slave_address
uint8_t slave_address
Definition: illuminance.h:173
illuminance_write_data
void illuminance_write_data(illuminance_t *ctx, uint8_t address, uint8_t write_command)
Generic write data function.
illuminance_cfg_t::i2c_address
uint8_t i2c_address
Definition: illuminance.h:194
illuminance_cfg_t::int_pin
pin_name_t int_pin
Definition: illuminance.h:189
ILLUMINANCE_RETVAL
#define ILLUMINANCE_RETVAL
Definition: illuminance.h:63
illuminance_t::i2c
i2c_master_t i2c
Definition: illuminance.h:169
illuminance_init
ILLUMINANCE_RETVAL illuminance_init(illuminance_t *ctx, illuminance_cfg_t *cfg)
Initialization function.
illuminance_cfg_t::scl
pin_name_t scl
Definition: illuminance.h:184
illuminance_t
Click ctx object definition.
Definition: illuminance.h:160
illuminance_cfg_t
Click configuration structure definition.
Definition: illuminance.h:180
illuminance_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: illuminance.h:193