ambient19  2.0.0.0
ambient19.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 AMBIENT19_H
29 #define AMBIENT19_H
30 
31 #ifdef __cplusplus
32 extern "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 AMBIENT19_REG_SYSM_CTRL 0x00
60 #define AMBIENT19_REG_INT_CTRL 0x01
61 #define AMBIENT19_REG_INT_FLAG 0x02
62 #define AMBIENT19_REG_WAIT_TIME 0x03
63 #define AMBIENT19_REG_ALS_GAIN 0x04
64 #define AMBIENT19_REG_ALS_TIME 0x05
65 #define AMBIENT19_REG_LED_CTRL 0x06
66 #define AMBIENT19_REG_PS_GAIN 0x07
67 #define AMBIENT19_REG_PS_PULSE 0x08
68 #define AMBIENT19_REG_PS_TIME 0x09
69 #define AMBIENT19_REG_PERSISTENCE 0x0B
70 #define AMBIENT19_REG_ALS_THRES_LL 0x0C
71 #define AMBIENT19_REG_ALS_THRES_LH 0x0D
72 #define AMBIENT19_REG_ALS_THRES_HL 0x0E
73 #define AMBIENT19_REG_ALS_THRES_HH 0x0F
74 #define AMBIENT19_REG_PS_THRES_LL 0x10
75 #define AMBIENT19_REG_PS_THRES_LH 0x11
76 #define AMBIENT19_REG_PS_THRES_HL 0x12
77 #define AMBIENT19_REG_PS_THRES_HH 0x13
78 #define AMBIENT19_REG_PS_OFFSET_L 0x14
79 #define AMBIENT19_REG_PS_OFFSET_H 0x15
80 #define AMBIENT19_REG_INT_SOURCE 0x16
81 #define AMBIENT19_REG_ERROR_FLAG 0x17
82 #define AMBIENT19_REG_PS_DATA_L 0x18
83 #define AMBIENT19_REG_PS_DATA_H 0x19
84 #define AMBIENT19_REG_IR_DATA_L 0x1A
85 #define AMBIENT19_REG_IR_DATA_H 0x1B
86 #define AMBIENT19_REG_CH0_DATA_L 0x1C
87 #define AMBIENT19_REG_CH0_DATA_H 0x1D
88 #define AMBIENT19_REG_CH1_DATA_L 0x1E
89 #define AMBIENT19_REG_CH1_DATA_H 0x1F
90 #define AMBIENT19_REG_PNO_LB 0xBC
91 #define AMBIENT19_REG_PNO_HB 0xBD
92  // ambient19_reg
94 
109 #define AMBIENT19_SYSM_CTRL_SWRST 0x80
110 #define AMBIENT19_SYSM_EN_WAIT 0x40
111 #define AMBIENT19_SYSM_EN_PS 0x02
112 #define AMBIENT19_SYSM_EN_ALS 0x01
113 
118 #define AMBIENT19_INT_CTRL_PS_INT_MODE 0x80
119 #define AMBIENT19_INT_CTRL_SINT_MODE 0x40
120 #define AMBIENT19_INT_CTRL_PS_SYNC 0x20
121 #define AMBIENT19_INT_CTRL_ALS_SYNC 0x10
122 #define AMBIENT19_INT_CTRL_EN_PINT 0x02
123 #define AMBIENT19_INT_CTRL_EN_AINT 0x01
124 
129 #define AMBIENT19_INT_FLAG_INT_POR 0x80
130 #define AMBIENT19_INT_FLAG_DATA_FLAG 0x40
131 #define AMBIENT19_INT_FLAG_OBJ 0x20
132 #define AMBIENT19_INT_FLAG_INT_PS 0x02
133 #define AMBIENT19_INT_FLAG_INT_ALS 0x01
134 
139 #define AMBIENT19_WAIT_TIME_MAX 1280.0
140 #define AMBIENT19_WAIT_TIME_MIN 5.0
141 #define AMBIENT19_WAIT_TIME_STEP 5.0
142 #define AMBIENT19_WAIT_TIME_DEFAULT 100.0
143 
148 #define AMBIENT19_ALS_GAIN_1X 0x00
149 #define AMBIENT19_ALS_GAIN_4X 0x01
150 #define AMBIENT19_ALS_GAIN_8X 0x02
151 #define AMBIENT19_ALS_GAIN_32X 0x03
152 #define AMBIENT19_ALS_GAIN_96X 0x04
153 
158 #define AMBIENT19_ALS_TIME_MAX 674.888
159 #define AMBIENT19_ALS_TIME_MIN 5.513
160 #define AMBIENT19_ALS_TIME_STEP 2.625
161 #define AMBIENT19_ALS_TIME_DEFAULT 400.0
162 
167 #define AMBIENT19_LED_CTRL_IRDR_SEL_50mA 0x00
168 #define AMBIENT19_LED_CTRL_IRDR_SEL_100mA 0x40
169 #define AMBIENT19_LED_CTRL_IRDR_SEL_150mA 0x80
170 #define AMBIENT19_LED_CTRL_IRDR_SEL_200mA 0xC0
171 #define AMBIENT19_LED_CTRL_IRDR_SEL_BIT_MASK 0xC0
172 #define AMBIENT19_LED_CTRL_ITW_PS_MAX 875.213
173 #define AMBIENT19_LED_CTRL_ITW_PS_MIN 13.675
174 #define AMBIENT19_LED_CTRL_ITW_PS_STEP 13.675
175 #define AMBIENT19_LED_CTRL_ITW_PS_BIT_MASK 0x3F
176 
181 #define AMBIENT19_PS_GAIN_1X 0x00
182 #define AMBIENT19_PS_GAIN_2X 0x01
183 #define AMBIENT19_PS_GAIN_4X 0x02
184 #define AMBIENT19_PS_GAIN_8X 0x03
185 
190 #define AMBIENT19_PS_TIME_MAX_COUNT_4095 0x0F
191 
196 #define AMBIENT19_PERSISTANCE_EVERY_ALS_CONV 0x00
197 
202 #define AMBIENT19_INT_SOURCE_CH0_DATA 0x00
203 #define AMBIENT19_INT_SOURCE_CH1_DATA 0x01
204 
209 #define AMBIENT19_LUX_K1 0.52
210 #define AMBIENT19_LUX_K2 0.94
211 #define AMBIENT19_LUX_K3 1.12 // calculated using lux meter
212 
217 #define AMBIENT19_PRODUCT_NUM_LOW 0x14
218 #define AMBIENT19_PRODUCT_NUM_HIGH 0x16
219 
225 #define AMBIENT19_DEVICE_ADDRESS 0x38
226  // ambient19_set
228 
243 #define AMBIENT19_MAP_MIKROBUS( cfg, mikrobus ) \
244  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
245  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
246  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
247  // ambient19_map // ambient19
250 
255 typedef struct
256 {
257  // Input pins
258  digital_in_t int_pin;
260  // Modules
261  i2c_master_t i2c;
263  // I2C slave address
264  uint8_t slave_address;
266  uint8_t pga_als;
267  uint8_t alsconv;
269 } ambient19_t;
270 
275 typedef struct
276 {
277  pin_name_t scl;
278  pin_name_t sda;
280  pin_name_t int_pin;
282  uint32_t i2c_speed;
283  uint8_t i2c_address;
286 
291 typedef enum
292 {
294  AMBIENT19_ERROR = -1
295 
297 
314 
329 
343 
358 err_t ambient19_generic_write ( ambient19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
359 
374 err_t ambient19_generic_read ( ambient19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
375 
388 err_t ambient19_write_register ( ambient19_t *ctx, uint8_t reg, uint8_t data_in );
389 
402 err_t ambient19_read_register ( ambient19_t *ctx, uint8_t reg, uint8_t *data_out );
403 
415 
425 
437 
449 err_t ambient19_set_wait_time ( ambient19_t *ctx, float wait_time_ms );
450 
462 err_t ambient19_set_als_time ( ambient19_t *ctx, float als_time_ms );
463 
480 err_t ambient19_set_als_gain ( ambient19_t *ctx, uint8_t als_gain );
481 
494 err_t ambient19_read_raw_als ( ambient19_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
495 
508 err_t ambient19_read_raw_proximity ( ambient19_t *ctx, uint16_t *ps_data, uint16_t *ir_data );
509 
522 err_t ambient19_measure_light_level ( ambient19_t *ctx, uint16_t *lux );
523 
524 #ifdef __cplusplus
525 }
526 #endif
527 #endif // AMBIENT19_H
528  // ambient19
530 
531 // ------------------------------------------------------------------------ END
ambient19_cfg_t::sda
pin_name_t sda
Definition: ambient19.h:278
ambient19_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient19.h:280
ambient19_read_register
err_t ambient19_read_register(ambient19_t *ctx, uint8_t reg, uint8_t *data_out)
Ambient 19 read register function.
ambient19_default_cfg
err_t ambient19_default_cfg(ambient19_t *ctx)
Ambient 19 default configuration function.
ambient19_t
Ambient 19 Click context object.
Definition: ambient19.h:256
ambient19_cfg_t
Ambient 19 Click configuration object.
Definition: ambient19.h:276
ambient19_t::slave_address
uint8_t slave_address
Definition: ambient19.h:264
ambient19_cfg_setup
void ambient19_cfg_setup(ambient19_cfg_t *cfg)
Ambient 19 configuration object setup function.
ambient19_set_als_time
err_t ambient19_set_als_time(ambient19_t *ctx, float als_time_ms)
Ambient 19 set als time function.
ambient19_read_raw_als
err_t ambient19_read_raw_als(ambient19_t *ctx, uint16_t *ch_0, uint16_t *ch_1)
Ambient 19 read raw als function.
ambient19_return_value_t
ambient19_return_value_t
Ambient 19 Click return value data.
Definition: ambient19.h:292
ambient19_init
err_t ambient19_init(ambient19_t *ctx, ambient19_cfg_t *cfg)
Ambient 19 initialization function.
ambient19_generic_write
err_t ambient19_generic_write(ambient19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Ambient 19 I2C writing function.
ambient19_t::pga_als
uint8_t pga_als
Definition: ambient19.h:266
AMBIENT19_ERROR
@ AMBIENT19_ERROR
Definition: ambient19.h:294
ambient19_t::alsconv
uint8_t alsconv
Definition: ambient19.h:267
ambient19_set_wait_time
err_t ambient19_set_wait_time(ambient19_t *ctx, float wait_time_ms)
Ambient 19 set wait time function.
ambient19_t::int_pin
digital_in_t int_pin
Definition: ambient19.h:258
ambient19_get_int_pin
uint8_t ambient19_get_int_pin(ambient19_t *ctx)
Ambient 19 get INT pin function.
ambient19_write_register
err_t ambient19_write_register(ambient19_t *ctx, uint8_t reg, uint8_t data_in)
Ambient 19 write register function.
ambient19_read_raw_proximity
err_t ambient19_read_raw_proximity(ambient19_t *ctx, uint16_t *ps_data, uint16_t *ir_data)
Ambient 19 read raw proximity function.
ambient19_cfg_t::scl
pin_name_t scl
Definition: ambient19.h:277
AMBIENT19_OK
@ AMBIENT19_OK
Definition: ambient19.h:293
ambient19_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient19.h:283
ambient19_generic_read
err_t ambient19_generic_read(ambient19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Ambient 19 I2C reading function.
ambient19_check_communication
err_t ambient19_check_communication(ambient19_t *ctx)
Ambient 19 check communication function.
ambient19_set_als_gain
err_t ambient19_set_als_gain(ambient19_t *ctx, uint8_t als_gain)
Ambient 19 set als gain function.
ambient19_t::i2c
i2c_master_t i2c
Definition: ambient19.h:261
ambient19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient19.h:282
ambient19_clear_interrupts
err_t ambient19_clear_interrupts(ambient19_t *ctx)
Ambient 19 clear interrupts function.
ambient19_measure_light_level
err_t ambient19_measure_light_level(ambient19_t *ctx, uint16_t *lux)
Ambient 19 measure light level function.