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 "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define AMBIENT15_REG_CONTROL 0x00
70 #define AMBIENT15_REG_TIMING 0x01
71 #define AMBIENT15_REG_INTERRUPT 0x02
72 #define AMBIENT15_REG_THL_LOW 0x03
73 #define AMBIENT15_REG_THL_HIGH 0x04
74 #define AMBIENT15_REG_THH_LOW 0x05
75 #define AMBIENT15_REG_THH_HIGH 0x06
76 #define AMBIENT15_REG_ANALOG 0x07
77 #define AMBIENT15_REG_ID 0x12
78 #define AMBIENT15_REG_DATA0_LOW 0x14
79 #define AMBIENT15_REG_DATA0_HIGH 0x15
80 #define AMBIENT15_REG_DATA1_LOW 0x16
81 #define AMBIENT15_REG_DATA1_HIGH 0x17
82 #define AMBIENT15_REG_TIMER_LOW 0x18
83 #define AMBIENT15_REG_TIMER_HIGH 0x19
84 #define AMBIENT15_REG_ID2 0x1E
85  // ambient15_reg
87 
102 #define AMBIENT15_CMD_BIT 0x80
103 #define AMBIENT15_TRANSACTION_REPEATED 0x00
104 #define AMBIENT15_TRANSACTION_AUTO_INC 0x20
105 #define AMBIENT15_TRANSACTION_SPEC_FUNC 0x60
106 #define AMBIENT15_SPEC_FUNC_INT_CLEAR 0x01
107 #define AMBIENT15_SPEC_FUNC_STOP_MAN_INT 0x02
108 #define AMBIENT15_SPEC_FUNC_START_MAN_INT 0x03
109 
114 #define AMBIENT15_CONTROL_ADC_INTR 0x20
115 #define AMBIENT15_CONTROL_ADC_VALID 0x10
116 #define AMBIENT15_CONTROL_ADC_ENABLE 0x02
117 #define AMBIENT15_CONTROL_POWER_ON 0x01
118 
123 #define AMBIENT15_ATIME_MAX 688.5
124 #define AMBIENT15_ATIME_MIN 2.7
125 #define AMBIENT15_ATIME_STEP 2.7
126 #define AMBIENT15_DEFAULT_ATIME 200.0
127 
132 #define AMBIENT15_ENABLE_INTERRUPT 0x10
133 
138 #define AMBIENT15_GAIN_1X 0x00
139 #define AMBIENT15_GAIN_8X 0x01
140 #define AMBIENT15_GAIN_16X 0x02
141 #define AMBIENT15_GAIN_111X 0x03
142 
147 #define AMBIENT15_ID_PARTNO 0x90
148 #define AMBIENT15_ID2 0x80
149 
154 #define AMBIENT15_CH0_COFF0 1000ul
155 #define AMBIENT15_CH1_COFF0 2160ul
156 #define AMBIENT15_CH0_COFF1 950ul
157 #define AMBIENT15_CH1_COFF1 1110ul
158 
164 #define AMBIENT15_SET_DEV_ADDR_GND 0x29
165 #define AMBIENT15_SET_DEV_ADDR_FLOAT 0x39
166 #define AMBIENT15_SET_DEV_ADDR_VCC 0x49
167  // ambient15_set
169 
184 #define AMBIENT15_MAP_MIKROBUS( cfg, mikrobus ) \
185  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
186  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
187  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
188  // ambient15_map // ambient15
191 
196 typedef struct
197 {
198  // Input pins
199  digital_in_t int_pin;
201  // Modules
202  i2c_master_t i2c;
204  // I2C slave address
205  uint8_t slave_address;
207  float atime_ms;
208  uint8_t gain;
210 } ambient15_t;
211 
216 typedef struct
217 {
218  pin_name_t scl;
219  pin_name_t sda;
221  pin_name_t int_pin;
223  uint32_t i2c_speed;
224  uint8_t i2c_address;
227 
232 typedef enum
233 {
235  AMBIENT15_ERROR = -1
236 
238 
255 
271 
286 
302 err_t ambient15_generic_write ( ambient15_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
303 
319 err_t ambient15_generic_read ( ambient15_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
320 
334 err_t ambient15_write_register ( ambient15_t *ctx, uint8_t reg, uint8_t data_in );
335 
349 err_t ambient15_read_register ( ambient15_t *ctx, uint8_t reg, uint8_t *data_out );
350 
360 
373 
386 err_t ambient15_set_atime ( ambient15_t *ctx, float atime_ms );
387 
400 err_t ambient15_set_gain ( ambient15_t *ctx, uint8_t gain );
401 
415 err_t ambient15_read_raw_data ( ambient15_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
416 
430 err_t ambient15_measure_light_level ( ambient15_t *ctx, uint16_t *lux );
431 
432 #ifdef __cplusplus
433 }
434 #endif
435 #endif // AMBIENT15_H
436  // ambient15
438 
439 // ------------------------------------------------------------------------ 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:223
ambient15_cfg_t::scl
pin_name_t scl
Definition: ambient15.h:218
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:217
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:219
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:233
ambient15_t::slave_address
uint8_t slave_address
Definition: ambient15.h:205
ambient15_t
Ambient 15 Click context object.
Definition: ambient15.h:197
ambient15_t::int_pin
digital_in_t int_pin
Definition: ambient15.h:199
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:224
ambient15_t::atime_ms
float atime_ms
Definition: ambient15.h:207
AMBIENT15_ERROR
@ AMBIENT15_ERROR
Definition: ambient15.h:235
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:202
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:234
ambient15_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient15.h:221
ambient15_t::gain
uint8_t gain
Definition: ambient15.h:208
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.