light2  2.1.0.0
light2.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 LIGHT2_H
29 #define LIGHT2_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 LIGHT2_REG_COMMAND 0x00
74 #define LIGHT2_REG_DATA_LSB 0x01
75 #define LIGHT2_REG_DATA_MSB 0x02
76  // light2_reg
78 
93 #define LIGHT2_EN_DEVICE 0x80
94 #define LIGHT2_ONE_TIME_MEASURE 0x00
95 #define LIGHT2_EN_CONT_MEASURE 0x40
96 #define LIGHT2_AMBIENT_LIGHT_SENS 0x00
97 #define LIGHT2_IR_LIGHT_SENS 0x20
98 #define LIGHT2_16_BIT_ADC 0x00
99 #define LIGHT2_12_BIT_ADC 0x04
100 #define LIGHT2_8_BIT_ADC 0x08
101 #define LIGHT2_4_BIT_ADC 0x0C
102 #define LIGHT2_ADC_RESOLUTION_MASK 0x0C
103 #define LIGHT2_ADC_DATA_OUT 0x10
104 #define LIGHT2_TIMER_DATA_OUT 0x14
105 #define LIGHT2_RANGE_1 0x00
106 #define LIGHT2_RANGE_2 0x01
107 #define LIGHT2_RANGE_3 0x02
108 #define LIGHT2_RANGE_4 0x03
109 #define LIGHT2_RANGE_MASK 0x03
110 
115 #define LIGHT2_RANGE_1_MAX 1000
116 #define LIGHT2_RANGE_2_MAX 4000
117 #define LIGHT2_RANGE_3_MAX 16000
118 #define LIGHT2_RANGE_4_MAX 64000
119 
124 #define LIGHT2_16_BIT_MAX 0xFFFFu
125 #define LIGHT2_12_BIT_MAX 0x0FFFu
126 #define LIGHT2_8_BIT_MAX 0x00FFu
127 #define LIGHT2_4_BIT_MAX 0x000Fu
128 
134 #define LIGHT2_DEVICE_ADDRESS_0 0x44
135 #define LIGHT2_DEVICE_ADDRESS_1 0x45
136  // light2_set
138 
153 #define LIGHT2_MAP_MIKROBUS( cfg, mikrobus ) \
154  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
155  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
156  // light2_map // light2
159 
164 typedef struct
165 {
166  // Modules
167  i2c_master_t i2c;
169  // I2C slave address
170  uint8_t slave_address;
172  float a_const;
174 } light2_t;
175 
180 typedef struct
181 {
182  pin_name_t scl;
183  pin_name_t sda;
185  uint32_t i2c_speed;
186  uint8_t i2c_address;
188 } light2_cfg_t;
189 
194 typedef enum
195 {
197  LIGHT2_ERROR = -1
198 
200 
217 
231 err_t light2_init ( light2_t *ctx, light2_cfg_t *cfg );
232 
246 
261 err_t light2_generic_write ( light2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
262 
277 err_t light2_generic_read ( light2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
278 
291 err_t light2_write_config ( light2_t *ctx, uint8_t data_in );
292 
305 err_t light2_read_raw_data ( light2_t *ctx, uint16_t *data_out );
306 
319 
332 err_t light2_get_light_data ( light2_t *ctx, float *light_data );
333 
334 #ifdef __cplusplus
335 }
336 #endif
337 #endif // LIGHT2_H
338  // light2
340 
341 // ------------------------------------------------------------------------ END
light2_t::a_const
float a_const
Definition: light2.h:172
light2_get_cal_const
err_t light2_get_cal_const(light2_t *ctx)
Light 2 get calculation constant function.
light2_t::i2c
i2c_master_t i2c
Definition: light2.h:167
LIGHT2_ERROR
@ LIGHT2_ERROR
Definition: light2.h:197
light2_cfg_t::scl
pin_name_t scl
Definition: light2.h:182
light2_write_config
err_t light2_write_config(light2_t *ctx, uint8_t data_in)
Light 2 write config function.
light2_cfg_t::sda
pin_name_t sda
Definition: light2.h:183
light2_read_raw_data
err_t light2_read_raw_data(light2_t *ctx, uint16_t *data_out)
Light 2 raw data reading function.
light2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: light2.h:185
light2_cfg_setup
void light2_cfg_setup(light2_cfg_t *cfg)
Light 2 configuration object setup function.
light2_cfg_t
Light 2 Click configuration object.
Definition: light2.h:181
light2_init
err_t light2_init(light2_t *ctx, light2_cfg_t *cfg)
Light 2 initialization function.
light2_return_value_t
light2_return_value_t
Light 2 Click return value data.
Definition: light2.h:195
light2_t::slave_address
uint8_t slave_address
Definition: light2.h:170
LIGHT2_OK
@ LIGHT2_OK
Definition: light2.h:196
light2_generic_read
err_t light2_generic_read(light2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Light 2 I2C reading function.
light2_get_light_data
err_t light2_get_light_data(light2_t *ctx, float *light_data)
Light 2 get light data function.
light2_t
Light 2 Click context object.
Definition: light2.h:165
light2_cfg_t::i2c_address
uint8_t i2c_address
Definition: light2.h:186
light2_generic_write
err_t light2_generic_write(light2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Light 2 I2C writing function.
light2_default_cfg
err_t light2_default_cfg(light2_t *ctx)
Light 2 default configuration function.