lightmixsens 2.0.0.0
lightmixsens.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 LIGHTMIXSENS_H
29#define LIGHTMIXSENS_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_i2c_master.h"
38
59#define LIGHTMIXSENS_REG_ENABLE 0x80
60#define LIGHTMIXSENS_REG_ATIME 0x81
61#define LIGHTMIXSENS_REG_PTIME 0x82
62#define LIGHTMIXSENS_REG_WTIME 0x83
63#define LIGHTMIXSENS_REG_AILT 0x84
64#define LIGHTMIXSENS_REG_AIHT 0x86
65#define LIGHTMIXSENS_REG_PILT 0x88
66#define LIGHTMIXSENS_REG_PIHT 0x8A
67#define LIGHTMIXSENS_REG_PERS 0x8C
68#define LIGHTMIXSENS_REG_CFG0 0x8D
69#define LIGHTMIXSENS_REG_PCFG0 0x8E
70#define LIGHTMIXSENS_REG_PCFG1 0x8F
71#define LIGHTMIXSENS_REG_CFG1 0x90
72#define LIGHTMIXSENS_REG_REVID 0x91
73#define LIGHTMIXSENS_REG_ID 0x92
74#define LIGHTMIXSENS_REG_STATUS 0x93
75#define LIGHTMIXSENS_REG_CDATA 0x94
76#define LIGHTMIXSENS_REG_RDATA 0x96
77#define LIGHTMIXSENS_REG_GDATA_IRDATA 0x98
78#define LIGHTMIXSENS_REG_BDATA 0x9A
79#define LIGHTMIXSENS_REG_PDATA 0x9C
80#define LIGHTMIXSENS_REG_REVID2 0x9E
81#define LIGHTMIXSENS_REG_CFG2 0x9F
82#define LIGHTMIXSENS_REG_CFG3 0xAB
83#define LIGHTMIXSENS_REG_POFFSET 0xC0
84#define LIGHTMIXSENS_REG_AZCFG 0xD6
85#define LIGHTMIXSENS_REG_CALIB 0xD7
86#define LIGHTMIXSENS_REG_CALIBCFG 0xD9
87#define LIGHTMIXSENS_REG_CALIBSTAT 0xDC
88#define LIGHTMIXSENS_REG_INTENAB 0xDD
89 // lightmixsens_reg
91
106#define LIGHTMIXSENS_ATIME_WTIME_CONST 2.8
107#define LIGHTMIXSENS_PTIME_CONST 88
108#define LIGHTMIXSENS_WTIME_INCR_FACTOR 12
109
110#define LIGHTMIXSENS_ENABLE_WAIT 0x08
111#define LIGHTMIXSENS_ENABLE_PROX 0x04
112#define LIGHTMIXSENS_ENABLE_ALS 0x02
113#define LIGHTMIXSENS_ENABLE_OSC 0x01
114#define LIGHTMIXSENS_DISABLE_ALL 0x00
115
116#define LIGHTMIXSENS_PCFG1_GAIN_1x 0x00
117#define LIGHTMIXSENS_PCFG1_GAIN_2x 0x40
118#define LIGHTMIXSENS_PCFG1_GAIN_4x 0x80
119#define LIGHTMIXSENS_PCFG1_GAIN_8x 0xC0
120#define LIGHTMIXSENS_PCFG1_DRIVE_6mA 0x00
121#define LIGHTMIXSENS_PCFG1_DRIVE_12mA 0x01
122#define LIGHTMIXSENS_PCFG1_DRIVE_18mA 0x02
123#define LIGHTMIXSENS_PCFG1_DRIVE_192mA 0x1F
124
125#define LIGHTMIXSENS_CFG0_WLONG 0x04
126
127#define LIGHTMIXSENS_CFG1_IR_TO_GREEN 0x08
128#define LIGHTMIXSENS_CFG1_AGAIN_1x 0x00
129#define LIGHTMIXSENS_CFG1_AGAIN_4x 0x01
130#define LIGHTMIXSENS_CFG1_AGAIN_16x 0x02
131#define LIGHTMIXSENS_CFG1_AGAIN_64x 0x03
132
133#define LIGHTMIXSENS_CFG2_AGAINMAX 0x10
134#define LIGHTMIXSENS_CFG2_AGAINL 0x04
135
136#define LIGHTMIXSENS_CFG3_INT_READ_CLEAR 0x80
137#define LIGHTMIXSENS_CFG3_SAI 0x10
138
143#define LIGHTMIXSENS_FLAG_ASAT 0x80
144#define LIGHTMIXSENS_FLAG_PSAT 0x40
145#define LIGHTMIXSENS_FLAG_PINT 0x20
146#define LIGHTMIXSENS_FLAG_AINT 0x10
147#define LIGHTMIXSENS_FLAG_CINT 0x08
148#define LIGHTMIXSENS_FLAG_PSAT_REFL 0x02
149#define LIGHTMIXSENS_FLAG_PSAT_AMB 0x01
150
155#define LIGHTMIXSENS_CALIB_ELECTRICAL 0x20
156#define LIGHTMIXSENS_CALIB_OFFSET_START 0x01
157
158#define LIGHTMIXSENS_CALIBCFG_PROX_TARGET_0 0x00
159#define LIGHTMIXSENS_CALIBCFG_PROX_TARGET_1 0x20
160#define LIGHTMIXSENS_CALIBCFG_PROX_TARGET_3 0x40
161#define LIGHTMIXSENS_CALIBCFG_PROX_TARGET_7 0x60
162#define LIGHTMIXSENS_CALIBCFG_PROX_TARGET_15 0x80
163#define LIGHTMIXSENS_CALIBCFG_PROX_TARGET_31 0xA0
164#define LIGHTMIXSENS_CALIBCFG_PROX_TARGET_63 0xC0
165#define LIGHTMIXSENS_CALIBCFG_PROX_TARGET_127 0xE0
166#define LIGHTMIXSENS_CALIBCFG_AUTO_OFFSET_ADJ 0x08
167#define LIGHTMIXSENS_CALIBCFG_PROX_AVG_DIS 0x00
168#define LIGHTMIXSENS_CALIBCFG_PROX_AVG_2 0x01
169#define LIGHTMIXSENS_CALIBCFG_PROX_AVG_4 0x02
170#define LIGHTMIXSENS_CALIBCFG_PROX_AVG_8 0x03
171#define LIGHTMIXSENS_CALIBCFG_PROX_AVG_16 0x04
172#define LIGHTMIXSENS_CALIBCFG_PROX_AVG_32 0x05
173#define LIGHTMIXSENS_CALIBCFG_PROX_AVG_64 0x06
174#define LIGHTMIXSENS_CALIBCFG_PROX_AVG_128 0x07
175
176#define LIGHTMIXSENS_CALIBSTAT_FINISHED 0x01
177#define LIGHTMIXSENS_DUMMY_DATA 0x00
178
184#define LIGHTMIXSENS_SET_DEV_ADDR 0x39
185 // lightmixsens_set
187
202#define LIGHTMIXSENS_MAP_MIKROBUS( cfg, mikrobus ) \
203 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
204 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
205 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
206 // lightmixsens_map // lightmixsens
209
214typedef struct
215{
216 // Input pins
217 digital_in_t int_pin;
219 // Modules
220 i2c_master_t i2c;
222 // I2C slave address
226
231typedef struct
232{
233 pin_name_t scl;
234 pin_name_t sda;
236 pin_name_t int_pin;
238 uint32_t i2c_speed;
239 uint8_t i2c_address;
242
247typedef struct
248{
255
260typedef enum
261{
264
266
283
298
313
328err_t lightmixsens_generic_write ( lightmixsens_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
329
344err_t lightmixsens_generic_read ( lightmixsens_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
345
346
359err_t lightmixsens_write_byte ( lightmixsens_t *ctx, uint8_t reg_addr, uint8_t data_in );
360
374err_t lightmixsens_write_word ( lightmixsens_t *ctx, uint8_t reg_addr, uint16_t data_in );
375
388err_t lightmixsens_read_byte ( lightmixsens_t *ctx, uint8_t reg_addr, uint8_t *data_out );
389
403err_t lightmixsens_read_word ( lightmixsens_t *ctx, uint8_t reg_addr, uint16_t *data_out );
404
415void lightmixsens_get_status ( lightmixsens_t *ctx, uint8_t flag_mask, uint8_t *status );
416
426
436
446
456
466
467#ifdef __cplusplus
468}
469#endif
470#endif // LIGHTMIXSENS_H
471 // lightmixsens
473
474// ------------------------------------------------------------------------ END
void lightmixsens_wait_atime(lightmixsens_t *ctx)
Wait ALS/Color Intregration Time Done function.
err_t lightmixsens_write_byte(lightmixsens_t *ctx, uint8_t reg_addr, uint8_t data_in)
Generic Write Byte function.
void lightmixsens_cfg_setup(lightmixsens_cfg_t *cfg)
Light mix sens configuration object setup function.
void lightmixsens_get_status(lightmixsens_t *ctx, uint8_t flag_mask, uint8_t *status)
Get Status function.
void lightmixsens_switch_ir_to_green(lightmixsens_t *ctx)
Switch IR To Green Channel function.
err_t lightmixsens_read_byte(lightmixsens_t *ctx, uint8_t reg_addr, uint8_t *data_out)
Generic Read Byte function.
err_t lightmixsens_generic_read(lightmixsens_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Light mix sens I2C reading function.
err_t lightmixsens_write_word(lightmixsens_t *ctx, uint8_t reg_addr, uint16_t data_in)
Generic Write Word function.
err_t lightmixsens_read_word(lightmixsens_t *ctx, uint8_t reg_addr, uint16_t *data_out)
Generic Read Word function.
void lightmixsens_wait_wtime(lightmixsens_t *ctx)
Wait WTIME + WLONG Done function.
err_t lightmixsens_init(lightmixsens_t *ctx, lightmixsens_cfg_t *cfg)
Light mix sens initialization function.
void lightmixsens_wait_ptime(lightmixsens_t *ctx)
Wait Proximity Sample Time Done function.
void lightmixsens_default_cfg(lightmixsens_t *ctx)
Light mix sens default configuration function.
err_t lightmixsens_generic_write(lightmixsens_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Light mix sens I2C writing function.
void lightmixsens_switch_ir_to_prox(lightmixsens_t *ctx)
Switch IR To Proximity function.
lightmixsens_return_value_t
Light mix sens Click return value data.
Definition: lightmixsens.h:261
@ LIGHTMIXSENS_OK
Definition: lightmixsens.h:262
@ LIGHTMIXSENS_ERROR
Definition: lightmixsens.h:263
Light mix sens Click configuration object.
Definition: lightmixsens.h:232
uint32_t i2c_speed
Definition: lightmixsens.h:238
pin_name_t scl
Definition: lightmixsens.h:233
pin_name_t int_pin
Definition: lightmixsens.h:236
pin_name_t sda
Definition: lightmixsens.h:234
uint8_t i2c_address
Definition: lightmixsens.h:239
Light mix sens Click data object.
Definition: lightmixsens.h:248
uint16_t lightmixsens_rdata
Definition: lightmixsens.h:250
uint16_t lightmixsens_cdata
Definition: lightmixsens.h:249
uint8_t lightmixsens_pdata
Definition: lightmixsens.h:253
uint16_t lightmixsens_bdata
Definition: lightmixsens.h:252
uint16_t lightmixsens_gdata
Definition: lightmixsens.h:251
Light mix sens Click context object.
Definition: lightmixsens.h:215
digital_in_t int_pin
Definition: lightmixsens.h:217
i2c_master_t i2c
Definition: lightmixsens.h:220
uint8_t slave_address
Definition: lightmixsens.h:223