ambient15  2.0.0.0
ambient15.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 AMBIENT15_H
29 #define AMBIENT15_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 AMBIENT15_REG_CONTROL 0x00
60 #define AMBIENT15_REG_TIMING 0x01
61 #define AMBIENT15_REG_INTERRUPT 0x02
62 #define AMBIENT15_REG_THL_LOW 0x03
63 #define AMBIENT15_REG_THL_HIGH 0x04
64 #define AMBIENT15_REG_THH_LOW 0x05
65 #define AMBIENT15_REG_THH_HIGH 0x06
66 #define AMBIENT15_REG_ANALOG 0x07
67 #define AMBIENT15_REG_ID 0x12
68 #define AMBIENT15_REG_DATA0_LOW 0x14
69 #define AMBIENT15_REG_DATA0_HIGH 0x15
70 #define AMBIENT15_REG_DATA1_LOW 0x16
71 #define AMBIENT15_REG_DATA1_HIGH 0x17
72 #define AMBIENT15_REG_TIMER_LOW 0x18
73 #define AMBIENT15_REG_TIMER_HIGH 0x19
74 #define AMBIENT15_REG_ID2 0x1E
75  // ambient15_reg
77 
92 #define AMBIENT15_CMD_BIT 0x80
93 #define AMBIENT15_TRANSACTION_REPEATED 0x00
94 #define AMBIENT15_TRANSACTION_AUTO_INC 0x20
95 #define AMBIENT15_TRANSACTION_SPEC_FUNC 0x60
96 #define AMBIENT15_SPEC_FUNC_INT_CLEAR 0x01
97 #define AMBIENT15_SPEC_FUNC_STOP_MAN_INT 0x02
98 #define AMBIENT15_SPEC_FUNC_START_MAN_INT 0x03
99 
104 #define AMBIENT15_CONTROL_ADC_INTR 0x20
105 #define AMBIENT15_CONTROL_ADC_VALID 0x10
106 #define AMBIENT15_CONTROL_ADC_ENABLE 0x02
107 #define AMBIENT15_CONTROL_POWER_ON 0x01
108 
113 #define AMBIENT15_ATIME_MAX 688.5
114 #define AMBIENT15_ATIME_MIN 2.7
115 #define AMBIENT15_ATIME_STEP 2.7
116 #define AMBIENT15_DEFAULT_ATIME 200.0
117 
122 #define AMBIENT15_ENABLE_INTERRUPT 0x10
123 
128 #define AMBIENT15_GAIN_1X 0x00
129 #define AMBIENT15_GAIN_8X 0x01
130 #define AMBIENT15_GAIN_16X 0x02
131 #define AMBIENT15_GAIN_111X 0x03
132 
137 #define AMBIENT15_ID_PARTNO 0x90
138 #define AMBIENT15_ID2 0x80
139 
144 #define AMBIENT15_CH0_COFF0 1000ul
145 #define AMBIENT15_CH1_COFF0 2160ul
146 #define AMBIENT15_CH0_COFF1 950ul
147 #define AMBIENT15_CH1_COFF1 1110ul
148 
154 #define AMBIENT15_SET_DEV_ADDR_GND 0x29
155 #define AMBIENT15_SET_DEV_ADDR_FLOAT 0x39
156 #define AMBIENT15_SET_DEV_ADDR_VCC 0x49
157  // ambient15_set
159 
174 #define AMBIENT15_MAP_MIKROBUS( cfg, mikrobus ) \
175  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
176  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
177  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
178  // ambient15_map // ambient15
181 
186 typedef struct
187 {
188  // Input pins
189  digital_in_t int_pin;
191  // Modules
192  i2c_master_t i2c;
194  // I2C slave address
195  uint8_t slave_address;
197  float atime_ms;
198  uint8_t gain;
200 } ambient15_t;
201 
206 typedef struct
207 {
208  pin_name_t scl;
209  pin_name_t sda;
211  pin_name_t int_pin;
213  uint32_t i2c_speed;
214  uint8_t i2c_address;
217 
222 typedef enum
223 {
225  AMBIENT15_ERROR = -1
226 
228 
245 
261 
276 
292 err_t ambient15_generic_write ( ambient15_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
293 
309 err_t ambient15_generic_read ( ambient15_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
310 
324 err_t ambient15_write_register ( ambient15_t *ctx, uint8_t reg, uint8_t data_in );
325 
339 err_t ambient15_read_register ( ambient15_t *ctx, uint8_t reg, uint8_t *data_out );
340 
350 
363 
376 err_t ambient15_set_atime ( ambient15_t *ctx, float atime_ms );
377 
390 err_t ambient15_set_gain ( ambient15_t *ctx, uint8_t gain );
391 
405 err_t ambient15_read_raw_data ( ambient15_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
406 
420 err_t ambient15_measure_light_level ( ambient15_t *ctx, uint16_t *lux );
421 
422 #ifdef __cplusplus
423 }
424 #endif
425 #endif // AMBIENT15_H
426  // ambient15
428 
429 // ------------------------------------------------------------------------ END
ambient15_generic_read
err_t ambient15_generic_read(ambient15_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Ambient 15 I2C reading function.
ambient15_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient15.h:213
ambient15_cfg_t::scl
pin_name_t scl
Definition: ambient15.h:208
ambient15_cfg_setup
void ambient15_cfg_setup(ambient15_cfg_t *cfg)
Ambient 15 configuration object setup function.
ambient15_cfg_t
Ambient 15 Click configuration object.
Definition: ambient15.h:207
ambient15_measure_light_level
err_t ambient15_measure_light_level(ambient15_t *ctx, uint16_t *lux)
Ambient 15 measure light level function.
ambient15_set_gain
err_t ambient15_set_gain(ambient15_t *ctx, uint8_t gain)
Ambient 15 set gain function.
ambient15_generic_write
err_t ambient15_generic_write(ambient15_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Ambient 15 I2C writing function.
ambient15_check_communication
err_t ambient15_check_communication(ambient15_t *ctx)
Ambient 15 check communication function.
ambient15_cfg_t::sda
pin_name_t sda
Definition: ambient15.h:209
ambient15_set_atime
err_t ambient15_set_atime(ambient15_t *ctx, float atime_ms)
Ambient 15 set atime function.
ambient15_return_value_t
ambient15_return_value_t
Ambient 15 Click return value data.
Definition: ambient15.h:223
ambient15_t::slave_address
uint8_t slave_address
Definition: ambient15.h:195
ambient15_t
Ambient 15 Click context object.
Definition: ambient15.h:187
ambient15_t::int_pin
digital_in_t int_pin
Definition: ambient15.h:189
ambient15_get_int_pin
uint8_t ambient15_get_int_pin(ambient15_t *ctx)
Ambient 15 get int pin function.
ambient15_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient15.h:214
ambient15_t::atime_ms
float atime_ms
Definition: ambient15.h:197
AMBIENT15_ERROR
@ AMBIENT15_ERROR
Definition: ambient15.h:225
ambient15_default_cfg
err_t ambient15_default_cfg(ambient15_t *ctx)
Ambient 15 default configuration function.
ambient15_write_register
err_t ambient15_write_register(ambient15_t *ctx, uint8_t reg, uint8_t data_in)
Ambient 15 write register function.
ambient15_t::i2c
i2c_master_t i2c
Definition: ambient15.h:192
ambient15_read_raw_data
err_t ambient15_read_raw_data(ambient15_t *ctx, uint16_t *ch_0, uint16_t *ch_1)
Ambient 15 read raw data function.
AMBIENT15_OK
@ AMBIENT15_OK
Definition: ambient15.h:224
ambient15_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient15.h:211
ambient15_t::gain
uint8_t gain
Definition: ambient15.h:198
ambient15_read_register
err_t ambient15_read_register(ambient15_t *ctx, uint8_t reg, uint8_t *data_out)
Ambient 15 read register function.
ambient15_init
err_t ambient15_init(ambient15_t *ctx, ambient15_cfg_t *cfg)
Ambient 15 initialization function.