light4 2.1.0.0
light4.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 LIGHT4_H
29#define LIGHT4_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "mikrosdk_version.h"
36
37#ifdef __GNUC__
38#if mikroSDK_GET_VERSION < 20800ul
39#include "rcu_delays.h"
40#else
41#include "delays.h"
42#endif
43#endif
44
45#include "drv_digital_out.h"
46#include "drv_digital_in.h"
47#include "drv_i2c_master.h"
48
69#define LIGHT4_REG_UV_CALIB 0x08
70#define LIGHT4_REG_MOD_CHANNEL_CTRL 0x40
71#define LIGHT4_REG_ENABLE 0x80
72#define LIGHT4_REG_MEAS_MODE0 0x81
73#define LIGHT4_REG_MEAS_MODE1 0x82
74#define LIGHT4_REG_SAMPLE_TIME0 0x83
75#define LIGHT4_REG_SAMPLE_TIME1 0x84
76#define LIGHT4_REG_ALS_NR_SAMPLES0 0x85
77#define LIGHT4_REG_ALS_NR_SAMPLES1 0x86
78#define LIGHT4_REG_FD_NR_SAMPLES0 0x87
79#define LIGHT4_REG_FD_NR_SAMPLES1 0x88
80#define LIGHT4_REG_WTIME 0x89
81#define LIGHT4_REG_AILT0 0x8A
82#define LIGHT4_REG_AILT1 0x8B
83#define LIGHT4_REG_AILT2 0x8C
84#define LIGHT4_REG_AIHT0 0x8D
85#define LIGHT4_REG_AIHT1 0x8B
86#define LIGHT4_REG_AIHT2 0x8F
87#define LIGHT4_REG_AUX_ID 0x90
88#define LIGHT4_REG_REV_ID 0x91
89#define LIGHT4_REG_ID 0x92
90#define LIGHT4_REG_STATUS 0x93
91#define LIGHT4_REG_ALS_STATUS 0x94
92#define LIGHT4_REG_ALS_DATA0_LSB 0x95
93#define LIGHT4_REG_ALS_DATA0_MSB 0x96
94#define LIGHT4_REG_ALS_DATA1_LSB 0x97
95#define LIGHT4_REG_ALS_DATA1_MSB 0x98
96#define LIGHT4_REG_ALS_DATA2_LSB 0x99
97#define LIGHT4_REG_ALS_DATA2_MSB 0x9A
98#define LIGHT4_REG_ALS_STATUS2 0x9B
99#define LIGHT4_REG_ALS_STATUS3 0x9C
100#define LIGHT4_REG_STATUS2 0x9D
101#define LIGHT4_REG_STATUS3 0x9E
102#define LIGHT4_REG_STATUS4 0x9F
103#define LIGHT4_REG_STATUS5 0xA0
104#define LIGHT4_REG_CFG0 0xA1
105#define LIGHT4_REG_CFG1 0xA2
106#define LIGHT4_REG_CFG2 0xA3
107#define LIGHT4_REG_CFG3 0xA4
108#define LIGHT4_REG_CFG4 0xA5
109#define LIGHT4_REG_CFG5 0xA6
110#define LIGHT4_REG_CFG6 0xA7
111#define LIGHT4_REG_CFG7 0xA8
112#define LIGHT4_REG_CFG8 0xA9
113#define LIGHT4_REG_CFG9 0xAA
114#define LIGHT4_REG_AGC_NR_SAMPLES_LSB 0xAC
115#define LIGHT4_REG_AGC_NR_SAMPLES_MSB 0xAD
116#define LIGHT4_REG_TRIGGER_MODE 0xAE
117#define LIGHT4_REG_CONTROL 0xB1
118#define LIGHT4_REG_INTENAB 0xBA
119#define LIGHT4_REG_SIEN 0xBB
120#define LIGHT4_REG_MOD_COMP_CFG1 0xCE
121#define LIGHT4_REG_MEAS_SEQR_FD_0 0xCF
122#define LIGHT4_REG_MEAS_SEQR_ALS_FD_1 0xD0
123#define LIGHT4_REG_MEAS_SEQR_APERS_AND_VSYNC_WAIT 0xD1
124#define LIGHT4_REG_MEAS_SEQR_RESIDUAL_0 0xD2
125#define LIGHT4_REG_MEAS_SEQR_RESIDUAL_1_AND_WAIT 0xD3
126#define LIGHT4_REG_MEAS_SEQR_STEP0_MOD_GAINX_L 0xD4
127#define LIGHT4_REG_MEAS_SEQR_STEP0_MOD_GAINX_H 0xD5
128#define LIGHT4_REG_MEAS_SEQR_STEP1_MOD_GAINX_L 0xD6
129#define LIGHT4_REG_MEAS_SEQR_STEP1_MOD_GAINX_H 0xD7
130#define LIGHT4_REG_MEAS_SEQR_STEP2_MOD_GAINX_L 0xD8
131#define LIGHT4_REG_MEAS_SEQR_STEP2_MOD_GAINX_H 0xD9
132#define LIGHT4_REG_MEAS_SEQR_STEP3_MOD_GAINX_L 0xDA
133#define LIGHT4_REG_MEAS_SEQR_STEP3_MOD_GAINX_H 0xDB
134#define LIGHT4_REG_MEAS_SEQR_STEP0_MOD_PHDX_L 0xDC
135#define LIGHT4_REG_MEAS_SEQR_STEP0_MOD_PHDX_H 0xDD
136#define LIGHT4_REG_MEAS_SEQR_STEP1_MOD_PHDX_L 0xDE
137#define LIGHT4_REG_MEAS_SEQR_STEP1_MOD_PHDX_H 0xDF
138#define LIGHT4_REG_MEAS_SEQR_STEP2_MOD_PHDX_L 0xE0
139#define LIGHT4_REG_MEAS_SEQR_STEP2_MOD_PHDX_H 0xE1
140#define LIGHT4_REG_MEAS_SEQR_STEP3_MOD_PHDX_L 0xE2
141#define LIGHT4_REG_MEAS_SEQR_STEP3_MOD_PHDX_H 0xE3
142#define LIGHT4_REG_MOD_CALIB_CFG0 0xE4
143#define LIGHT4_REG_MOD_CALIB_CFG2 0xE6
144#define LIGHT4_REG_VSYNC_PERIOD_LSB 0xF2
145#define LIGHT4_REG_VSYNC_PERIOD_MSB 0xF3
146#define LIGHT4_REG_VSYNC_PERIOD_TARGET_LSB 0xF4
147#define LIGHT4_REG_VSYNC_PERIOD_TARGET_MSB 0xF5
148#define LIGHT4_REG_VSYNC_CONTROL 0xF6
149#define LIGHT4_REG_VSYNC_CFG 0xF7
150#define LIGHT4_REG_VSYNC_GPIO_INT 0xF8
151#define LIGHT4_REG_MOD_FIFO_DATA_CFG0 0xF9
152#define LIGHT4_REG_MOD_FIFO_DATA_CFG1 0xFA
153#define LIGHT4_REG_MOD_FIFO_DATA_CFG2 0xFB
154#define LIGHT4_REG_FIFO_THR 0xDC
155#define LIGHT4_REG_FIFO_STATUS0 0xFD
156#define LIGHT4_REG_FIFO_STATUS1 0xFE
157#define LIGHT4_REG_FIFO_DATA 0xFF
158 // light4_reg
160
175#define LIGHT4_FDEN 0x40
176#define LIGHT4_AEN 0x02
177#define LIGHT4_PON 0x01
178
183#define LIGHT4_MOD2_DISABLE 0x04
184#define LIGHT4_MOD1_DISABLE 0x02
185#define LIGHT4_MOD0_DISABLE 0x01
186#define LIGHT4_MOD_ENABLE_ALL 0x00
187
192#define LIGHT4_MIEN 0x80
193#define LIGHT4_AIEN 0x04
194#define LIGHT4_FIEN 0x02
195#define LIGHT4_SIEN 0x01
196
201#define LIGHT4_SOFT_RESET 0x08
202#define LIGHT4_FIFO_CLR 0x02
203#define LIGHT4_CLEAR_SAI_ACTIVE 0x01
204
209#define LIGHT4_MEAS_SEQR_STEP_MASK 0xC0
210#define LIGHT4_ALS_DATA0_ANALOG_SATURATION_STATUS 0x20
211#define LIGHT4_ALS_DATA1_ANALOG_SATURATION_STATUS 0x10
212#define LIGHT4_ALS_DATA2_ANALOG_SATURATION_STATUS 0x08
213#define LIGHT4_ALS_DATA0_SCALED_STATUS 0x04
214#define LIGHT4_ALS_DATA1_SCALED_STATUS 0x02
215#define LIGHT4_ALS_DATA2_SCALED_STATUS 0x01
216
221#define LIGHT4_PIN_STATE_HIGH 0x01
222#define LIGHT4_PIN_STATE_LOW 0x00
223
228#define LIGHT4_AUX_ID 0x06
229#define LIGHT4_REV_ID 0x11
230#define LIGHT4_DEVICE_ID 0x5C
231
232#define LIGHT4_CHANNEL0_SEL 0x00
233#define LIGHT4_CHANNEL1_SEL 0x01
234#define LIGHT4_CHANNEL2_SEL 0x02
235
236
242#define LIGHT4_DEVICE_ADDRESS 0x39
243 // light4_set
245
260#define LIGHT4_MAP_MIKROBUS( cfg, mikrobus ) \
261 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
262 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
263 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
264 cfg.snc = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
265 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
266 // light4_map // light4
269
274typedef struct
275{
276 // Output pins
277 digital_out_t en;
278 digital_out_t snc;
280 // Input pins
281 digital_in_t int_pin;
283 // Modules
284 i2c_master_t i2c;
286 // I2C slave address
289} light4_t;
290
295typedef struct
296{
297 pin_name_t scl;
298 pin_name_t sda;
300 pin_name_t en;
301 pin_name_t snc;
302 pin_name_t int_pin;
304 uint32_t i2c_speed;
305 uint8_t i2c_address;
308
313typedef enum
314{
318
320
337
351err_t light4_init ( light4_t *ctx, light4_cfg_t *cfg );
352
366
381err_t light4_generic_write ( light4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
382
397err_t light4_generic_read ( light4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
398
408void light4_set_en_pin ( light4_t *ctx, uint8_t pin_state );
409
419void light4_set_snc_pin ( light4_t *ctx, uint8_t pin_state );
420
430
444err_t light4_write_reg ( light4_t *ctx, uint8_t reg, uint8_t data_in );
445
459err_t light4_read_reg ( light4_t *ctx, uint8_t reg, uint8_t *data_out );
460
473
487err_t light4_read_channel_data ( light4_t *ctx, uint8_t channel_sel, float *channel_data );
488
489#ifdef __cplusplus
490}
491#endif
492#endif // LIGHT4_H
493 // light4
495
496// ------------------------------------------------------------------------ END
err_t light4_init(light4_t *ctx, light4_cfg_t *cfg)
Light 4 initialization function.
err_t light4_generic_write(light4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Light 4 I2C writing function.
err_t light4_read_reg(light4_t *ctx, uint8_t reg, uint8_t *data_out)
Light 4 Register reading function.
void light4_cfg_setup(light4_cfg_t *cfg)
Light 4 configuration object setup function.
err_t light4_generic_read(light4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Light 4 I2C reading function.
err_t light4_read_channel_data(light4_t *ctx, uint8_t channel_sel, float *channel_data)
Light 4 get channel data function.
void light4_set_snc_pin(light4_t *ctx, uint8_t pin_state)
Light 4 set SNC pin function.
err_t light4_write_reg(light4_t *ctx, uint8_t reg, uint8_t data_in)
Light 4 Register writing function.
err_t light4_default_cfg(light4_t *ctx)
Light 4 default configuration function.
void light4_set_en_pin(light4_t *ctx, uint8_t pin_state)
Light 4 set EN pin function.
uint8_t light4_get_int_pin(light4_t *ctx)
Light 4 get INT pin function.
err_t light4_sw_reset(light4_t *ctx)
Light 4 Software reset function.
light4_return_value_t
Light 4 Click return value data.
Definition: light4.h:314
@ LIGHT4_OK
Definition: light4.h:315
@ LIGHT4_ERROR
Definition: light4.h:316
@ LIGHT4_ANALOG_SAT
Definition: light4.h:317
Light 4 Click configuration object.
Definition: light4.h:296
uint32_t i2c_speed
Definition: light4.h:304
pin_name_t snc
Definition: light4.h:301
pin_name_t scl
Definition: light4.h:297
pin_name_t en
Definition: light4.h:300
pin_name_t int_pin
Definition: light4.h:302
pin_name_t sda
Definition: light4.h:298
uint8_t i2c_address
Definition: light4.h:305
Light 4 Click context object.
Definition: light4.h:275
digital_in_t int_pin
Definition: light4.h:281
digital_out_t snc
Definition: light4.h:278
i2c_master_t i2c
Definition: light4.h:284
digital_out_t en
Definition: light4.h:277
uint8_t slave_address
Definition: light4.h:287