ambient17  2.0.0.0
ambient17.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 AMBIENT17_H
29 #define AMBIENT17_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 AMBIENT17_REG_ENABLE 0x00
74 #define AMBIENT17_REG_ATIME 0x01
75 #define AMBIENT17_REG_WTIME 0x03
76 #define AMBIENT17_REG_AILTL 0x04
77 #define AMBIENT17_REG_AILTH 0x05
78 #define AMBIENT17_REG_AIHTL 0x06
79 #define AMBIENT17_REG_AIHTH 0x07
80 #define AMBIENT17_REG_PERS 0x0C
81 #define AMBIENT17_REG_CONFIG 0x0D
82 #define AMBIENT17_REG_CONTROL 0x0F
83 #define AMBIENT17_REG_ID 0x12
84 #define AMBIENT17_REG_STATUS 0x13
85 #define AMBIENT17_REG_C0DATA 0x14
86 #define AMBIENT17_REG_C0DATAH 0x15
87 #define AMBIENT17_REG_C1DATA 0x16
88 #define AMBIENT17_REG_C1DATAH 0x17
89  // ambient17_reg
91 
106 #define AMBIENT17_CMD_BIT 0x80
107 #define AMBIENT17_TYPE_REPEATED 0x00
108 #define AMBIENT17_TYPE_AUTO_INC 0x20
109 #define AMBIENT17_TYPE_SPEC_FUNC 0x60
110 #define AMBIENT17_SPEC_FUNC_INT_CLEAR 0x06
111 
116 #define AMBIENT17_ENABLE_SLEEP_AFTER_INT 0x40
117 #define AMBIENT17_ENABLE_ALS_INT 0x10
118 #define AMBIENT17_ENABLE_WAIT 0x08
119 #define AMBIENT17_ENABLE_ALS 0x02
120 #define AMBIENT17_ENABLE_OSC 0x01
121 
126 #define AMBIENT17_STATUS_AINT 0x10
127 #define AMBIENT17_STATUS_AVALID 0x01
128 
133 #define AMBIENT17_ATIME_MAX 699.88
134 #define AMBIENT17_ATIME_MIN 2.73
135 #define AMBIENT17_ATIME_STEP 2.73
136 #define AMBIENT17_DEFAULT_ATIME 200.0
137 
142 #define AMBIENT17_WTIME_MAX 699.88
143 #define AMBIENT17_WTIME_MIN 2.73
144 #define AMBIENT17_WTIME_STEP 2.73
145 #define AMBIENT17_DEFAULT_WTIME 200.0
146 
151 #define AMBIENT17_AGAIN_1X 0x00
152 #define AMBIENT17_AGAIN_8X 0x01
153 #define AMBIENT17_AGAIN_16X 0x02
154 #define AMBIENT17_AGAIN_120X 0x03
155 
160 #define AMBIENT17_CH0_COFF0 1.0
161 #define AMBIENT17_CH1_COFF0 1.87
162 #define AMBIENT17_CH0_COFF1 0.63
163 #define AMBIENT17_CH1_COFF1 1.0
164 #define AMBIENT17_GA_VALUE 1.0
165 #define AMBIENT17_GA_MULTIPLIER 60.0
166 
171 #define AMBIENT17_DEVICE_ID 0x34
172 
178 #define AMBIENT17_DEVICE_ADDRESS 0x39
179  // ambient17_set
181 
196 #define AMBIENT17_MAP_MIKROBUS( cfg, mikrobus ) \
197  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
198  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
199  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
200  // ambient17_map // ambient17
203 
208 typedef struct
209 {
210  // Input pins
211  digital_in_t int_pin;
213  // Modules
214  i2c_master_t i2c;
216  // I2C slave address
217  uint8_t slave_address;
219  float atime_ms;
220  uint8_t again;
221  float cpl;
223 } ambient17_t;
224 
229 typedef struct
230 {
231  pin_name_t scl;
232  pin_name_t sda;
234  pin_name_t int_pin;
236  uint32_t i2c_speed;
237  uint8_t i2c_address;
240 
245 typedef enum
246 {
248  AMBIENT17_ERROR = -1
249 
251 
268 
283 
297 
312 err_t ambient17_generic_write ( ambient17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
313 
328 err_t ambient17_generic_read ( ambient17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
329 
342 err_t ambient17_write_register ( ambient17_t *ctx, uint8_t reg, uint8_t data_in );
343 
356 err_t ambient17_read_register ( ambient17_t *ctx, uint8_t reg, uint8_t *data_out );
357 
369 
379 
391 
403 err_t ambient17_set_atime ( ambient17_t *ctx, float atime_ms );
404 
416 err_t ambient17_set_wtime ( ambient17_t *ctx, float wtime_ms );
417 
433 err_t ambient17_set_again ( ambient17_t *ctx, uint8_t again );
434 
447 err_t ambient17_read_raw_data ( ambient17_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
448 
461 err_t ambient17_measure_light_level ( ambient17_t *ctx, uint16_t *lux );
462 
463 #ifdef __cplusplus
464 }
465 #endif
466 #endif // AMBIENT17_H
467  // ambient17
469 
470 // ------------------------------------------------------------------------ END
ambient17_check_communication
err_t ambient17_check_communication(ambient17_t *ctx)
Ambient 17 check communication function.
ambient17_set_wtime
err_t ambient17_set_wtime(ambient17_t *ctx, float wtime_ms)
Ambient 17 set wtime function.
ambient17_set_atime
err_t ambient17_set_atime(ambient17_t *ctx, float atime_ms)
Ambient 17 set atime function.
ambient17_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient17.h:237
ambient17_generic_read
err_t ambient17_generic_read(ambient17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Ambient 17 I2C reading function.
ambient17_cfg_t
Ambient 17 Click configuration object.
Definition: ambient17.h:230
AMBIENT17_ERROR
@ AMBIENT17_ERROR
Definition: ambient17.h:248
ambient17_read_register
err_t ambient17_read_register(ambient17_t *ctx, uint8_t reg, uint8_t *data_out)
Ambient 17 read register function.
ambient17_t::int_pin
digital_in_t int_pin
Definition: ambient17.h:211
ambient17_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient17.h:234
ambient17_t
Ambient 17 Click context object.
Definition: ambient17.h:209
ambient17_get_int_pin
uint8_t ambient17_get_int_pin(ambient17_t *ctx)
Ambient 17 get INT pin function.
ambient17_measure_light_level
err_t ambient17_measure_light_level(ambient17_t *ctx, uint16_t *lux)
Ambient 17 measure light level function.
ambient17_t::slave_address
uint8_t slave_address
Definition: ambient17.h:217
AMBIENT17_OK
@ AMBIENT17_OK
Definition: ambient17.h:247
ambient17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient17.h:236
ambient17_t::cpl
float cpl
Definition: ambient17.h:221
ambient17_cfg_t::scl
pin_name_t scl
Definition: ambient17.h:231
ambient17_init
err_t ambient17_init(ambient17_t *ctx, ambient17_cfg_t *cfg)
Ambient 17 initialization function.
ambient17_t::atime_ms
float atime_ms
Definition: ambient17.h:219
ambient17_read_raw_data
err_t ambient17_read_raw_data(ambient17_t *ctx, uint16_t *ch_0, uint16_t *ch_1)
Ambient 17 read raw data function.
ambient17_return_value_t
ambient17_return_value_t
Ambient 17 Click return value data.
Definition: ambient17.h:246
ambient17_cfg_setup
void ambient17_cfg_setup(ambient17_cfg_t *cfg)
Ambient 17 configuration object setup function.
ambient17_t::i2c
i2c_master_t i2c
Definition: ambient17.h:214
ambient17_generic_write
err_t ambient17_generic_write(ambient17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Ambient 17 I2C writing function.
ambient17_default_cfg
err_t ambient17_default_cfg(ambient17_t *ctx)
Ambient 17 default configuration function.
ambient17_set_again
err_t ambient17_set_again(ambient17_t *ctx, uint8_t again)
Ambient 17 set again function.
ambient17_cfg_t::sda
pin_name_t sda
Definition: ambient17.h:232
ambient17_clear_interrupts
err_t ambient17_clear_interrupts(ambient17_t *ctx)
Ambient 17 clear interrupts function.
ambient17_write_register
err_t ambient17_write_register(ambient17_t *ctx, uint8_t reg, uint8_t data_in)
Ambient 17 write register function.
ambient17_t::again
uint8_t again
Definition: ambient17.h:220