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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define AMBIENT17_REG_ENABLE 0x00
60 #define AMBIENT17_REG_ATIME 0x01
61 #define AMBIENT17_REG_WTIME 0x03
62 #define AMBIENT17_REG_AILTL 0x04
63 #define AMBIENT17_REG_AILTH 0x05
64 #define AMBIENT17_REG_AIHTL 0x06
65 #define AMBIENT17_REG_AIHTH 0x07
66 #define AMBIENT17_REG_PERS 0x0C
67 #define AMBIENT17_REG_CONFIG 0x0D
68 #define AMBIENT17_REG_CONTROL 0x0F
69 #define AMBIENT17_REG_ID 0x12
70 #define AMBIENT17_REG_STATUS 0x13
71 #define AMBIENT17_REG_C0DATA 0x14
72 #define AMBIENT17_REG_C0DATAH 0x15
73 #define AMBIENT17_REG_C1DATA 0x16
74 #define AMBIENT17_REG_C1DATAH 0x17
75  // ambient17_reg
77 
92 #define AMBIENT17_CMD_BIT 0x80
93 #define AMBIENT17_TYPE_REPEATED 0x00
94 #define AMBIENT17_TYPE_AUTO_INC 0x20
95 #define AMBIENT17_TYPE_SPEC_FUNC 0x60
96 #define AMBIENT17_SPEC_FUNC_INT_CLEAR 0x06
97 
102 #define AMBIENT17_ENABLE_SLEEP_AFTER_INT 0x40
103 #define AMBIENT17_ENABLE_ALS_INT 0x10
104 #define AMBIENT17_ENABLE_WAIT 0x08
105 #define AMBIENT17_ENABLE_ALS 0x02
106 #define AMBIENT17_ENABLE_OSC 0x01
107 
112 #define AMBIENT17_STATUS_AINT 0x10
113 #define AMBIENT17_STATUS_AVALID 0x01
114 
119 #define AMBIENT17_ATIME_MAX 699.88
120 #define AMBIENT17_ATIME_MIN 2.73
121 #define AMBIENT17_ATIME_STEP 2.73
122 #define AMBIENT17_DEFAULT_ATIME 200.0
123 
128 #define AMBIENT17_WTIME_MAX 699.88
129 #define AMBIENT17_WTIME_MIN 2.73
130 #define AMBIENT17_WTIME_STEP 2.73
131 #define AMBIENT17_DEFAULT_WTIME 200.0
132 
137 #define AMBIENT17_AGAIN_1X 0x00
138 #define AMBIENT17_AGAIN_8X 0x01
139 #define AMBIENT17_AGAIN_16X 0x02
140 #define AMBIENT17_AGAIN_120X 0x03
141 
146 #define AMBIENT17_CH0_COFF0 1.0
147 #define AMBIENT17_CH1_COFF0 1.87
148 #define AMBIENT17_CH0_COFF1 0.63
149 #define AMBIENT17_CH1_COFF1 1.0
150 #define AMBIENT17_GA_VALUE 1.0
151 #define AMBIENT17_GA_MULTIPLIER 60.0
152 
157 #define AMBIENT17_DEVICE_ID 0x34
158 
164 #define AMBIENT17_DEVICE_ADDRESS 0x39
165  // ambient17_set
167 
182 #define AMBIENT17_MAP_MIKROBUS( cfg, mikrobus ) \
183  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
184  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
185  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
186  // ambient17_map // ambient17
189 
194 typedef struct
195 {
196  // Input pins
197  digital_in_t int_pin;
199  // Modules
200  i2c_master_t i2c;
202  // I2C slave address
203  uint8_t slave_address;
205  float atime_ms;
206  uint8_t again;
207  float cpl;
209 } ambient17_t;
210 
215 typedef struct
216 {
217  pin_name_t scl;
218  pin_name_t sda;
220  pin_name_t int_pin;
222  uint32_t i2c_speed;
223  uint8_t i2c_address;
226 
231 typedef enum
232 {
234  AMBIENT17_ERROR = -1
235 
237 
254 
269 
283 
298 err_t ambient17_generic_write ( ambient17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
299 
314 err_t ambient17_generic_read ( ambient17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
315 
328 err_t ambient17_write_register ( ambient17_t *ctx, uint8_t reg, uint8_t data_in );
329 
342 err_t ambient17_read_register ( ambient17_t *ctx, uint8_t reg, uint8_t *data_out );
343 
355 
365 
377 
389 err_t ambient17_set_atime ( ambient17_t *ctx, float atime_ms );
390 
402 err_t ambient17_set_wtime ( ambient17_t *ctx, float wtime_ms );
403 
419 err_t ambient17_set_again ( ambient17_t *ctx, uint8_t again );
420 
433 err_t ambient17_read_raw_data ( ambient17_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
434 
447 err_t ambient17_measure_light_level ( ambient17_t *ctx, uint16_t *lux );
448 
449 #ifdef __cplusplus
450 }
451 #endif
452 #endif // AMBIENT17_H
453  // ambient17
455 
456 // ------------------------------------------------------------------------ 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:223
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:216
AMBIENT17_ERROR
@ AMBIENT17_ERROR
Definition: ambient17.h:234
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:197
ambient17_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient17.h:220
ambient17_t
Ambient 17 Click context object.
Definition: ambient17.h:195
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:203
AMBIENT17_OK
@ AMBIENT17_OK
Definition: ambient17.h:233
ambient17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient17.h:222
ambient17_t::cpl
float cpl
Definition: ambient17.h:207
ambient17_cfg_t::scl
pin_name_t scl
Definition: ambient17.h:217
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:205
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:232
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:200
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:218
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:206