ambient2  2.0.0.0
ambient2.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
32 // ----------------------------------------------------------------------------
33 
34 #ifndef _AMBIENT2_H_
35 #define _AMBIENT2_H_
36 
37 #include "mikrosdk_version.h"
38 
39 #ifdef __GNUC__
40 #if mikroSDK_GET_VERSION < 20800ul
41 #include "rcu_delays.h"
42 #else
43 #include "delays.h"
44 #endif
45 #endif
46 
47 #include "drv_digital_in.h"
48 #include "drv_i2c_master.h"
49 
50 // -------------------------------------------------------------- PUBLIC MACROS
60 #define AMBIENT2_CFG_RANGE_40_95_LX_MIN 0x0
61 #define AMBIENT2_CFG_RANGE_81_9_LX 0x1000
62 #define AMBIENT2_CFG_RANGE_163_8_LX 0x2000
63 #define AMBIENT2_CFG_RANGE_327_6_LX 0x3000
64 #define AMBIENT2_CFG_RANGE_655_2_LX 0x4000
65 #define AMBIENT2_CFG_RANGE_1310_4_LX 0x5000
66 #define AMBIENT2_CFG_RANGE_2620_8_LX 0x6000
67 #define AMBIENT2_CFG_RANGE_5241_6_LX 0x7000
68 #define AMBIENT2_CFG_RANGE_10483_2_LX 0x8000
69 #define AMBIENT2_CFG_RANGE_20966_4_LX 0x9000
70 #define AMBIENT2_CFG_RANGE_41932_8_LX 0xA000
71 #define AMBIENT2_CFG_RANGE_83865_6_LX_MAX 0xB000
72 #define AMBIENT2_CFG_RANGE_AUTO_SCALE 0xC000
73 
79 #define AMBIENT2_CFG_CONV_TIME_100MS 0x0
80 #define AMBIENT2_CFG_CONV_TIME_800MS 0x800
81 
87 #define AMBIENT2_CFG_CONV_MODE_SHUTDOWN 0x0
88 #define AMBIENT2_CFG_CONV_MODE_SINGLE_SHOT 0x200
89 #define AMBIENT2_CFG_CONV_MODE_CONT_CONV 0x400
90 
96 #define AMBIENT2_CFG_LATCH_COMP_HYSTERESIS_STYLE 0x0
97 #define AMBIENT2_CFG_LATCH_COMP_WINDOW_STYLE 0x10
98 
104 #define AMBIENT2_CFG_POL_INT_ACTIVE_LOW 0x0
105 #define AMBIENT2_CFG_POL_INT_ACTIVE_HIGH 0x8
106 
112 #define AMBIENT2_CFG_MASK_EXPONENT 0x4
113 
119 #define AMBIENT2_CFG_FAULT_1_COUNT 0x0
120 #define AMBIENT2_CFG_FAULT_2_COUNTS 0x1
121 #define AMBIENT2_CFG_FAULT_4_COUNTS 0x2
122 #define AMBIENT2_CFG_FAULT_8_COUNTS 0x3
123 
129 #define AMBIENT2_FLAG_MASK_OVERFLOW 0x100
130 #define AMBIENT2_FLAG_MASK_CONV_READY 0x80
131 #define AMBIENT2_FLAG_MASK_HIGH 0x40
132 #define AMBIENT2_FLAG_MASK_LOW 0x20
133 
139 #define AMBIENT2_ID_MANUFACTURER 0x5449
140 #define AMBIENT2_ID_DEVICE 0x3001
141 
147 #define AMBIENT2_MAP_MIKROBUS( cfg, mikrobus ) \
148  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
149  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
150  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
151  // End macros group
154 // --------------------------------------------------------------- PUBLIC TYPES
163 typedef uint16_t ambient2_data_t;
164 
168 typedef enum
169 {
170  AMBIENT2_OK = 0x0,
173 
175 
179 typedef enum
180 {
185 
187 
191 typedef enum
192 {
199 
201 
205 typedef struct
206 {
209  uint8_t amb_light_per;
210 
212 
216 typedef struct
217 {
218  // Event pin.
219  digital_in_t int_pin;
220 
221  // Module.
222  i2c_master_t i2c;
223 
224  // Device slave address.
225  uint8_t slave_addr;
226 
227  // Ambient light sensor data.
229 
230 } ambient2_t;
231 
235 typedef struct
236 {
237  // Communication gpio pins.
238  pin_name_t scl;
239  pin_name_t sda;
240 
241  // Additional gpio pin.
242  pin_name_t int_pin;
243 
244  // Module configuration variables.
245  uint32_t i2c_speed;
246  uint8_t i2c_addr;
247 
249  // End types group
251 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
257 #ifdef __cplusplus
258 extern "C"{
259 #endif
260 
270 
282 
291 
303 
316 
327 
337 uint8_t ambient2_get_int( ambient2_t *ctx );
338 
339 #ifdef __cplusplus
340 }
341 #endif
342 #endif // _AMBIENT2_H_
343  // End public_function group
346 
347 // ------------------------------------------------------------------------ END
ambient2_generic_write
void ambient2_generic_write(ambient2_t *ctx, ambient2_reg_addr_t reg_addr, ambient2_data_t data_in)
Generic Write function.
ambient2_cfg_t::i2c_addr
uint8_t i2c_addr
Definition: ambient2.h:246
AMBIENT2_I2C_ADDRESS_SDA
@ AMBIENT2_I2C_ADDRESS_SDA
Definition: ambient2.h:183
ambient2_sens_data_t::amb_light_range
float amb_light_range
Definition: ambient2.h:208
ambient2_t
Click context object definition.
Definition: ambient2.h:217
ambient2_t::slave_addr
uint8_t slave_addr
Definition: ambient2.h:225
AMBIENT2_REG_LOW_LIMIT
@ AMBIENT2_REG_LOW_LIMIT
Definition: ambient2.h:195
ambient2_get_sens_results
void ambient2_get_sens_results(ambient2_t *ctx)
Sensor Results Read function.
AMBIENT2_REG_HIGH_LIMIT
@ AMBIENT2_REG_HIGH_LIMIT
Definition: ambient2.h:196
ambient2_sens_data_t::amb_light_per
uint8_t amb_light_per
Definition: ambient2.h:209
ambient2_init
ambient2_err_t ambient2_init(ambient2_t *ctx, ambient2_cfg_t *cfg)
Click Initialization function.
ambient2_reg_addr_t
ambient2_reg_addr_t
Click register address selection.
Definition: ambient2.h:192
AMBIENT2_I2C_ADDRESS_VDD
@ AMBIENT2_I2C_ADDRESS_VDD
Definition: ambient2.h:182
ambient2_cfg_t
Click configuration structure definition.
Definition: ambient2.h:236
ambient2_get_int
uint8_t ambient2_get_int(ambient2_t *ctx)
INT Pin Check function.
ambient_addr_t
ambient_addr_t
Click I2C address selection.
Definition: ambient2.h:180
AMBIENT2_I2C_ADDRESS_SCL
@ AMBIENT2_I2C_ADDRESS_SCL
Definition: ambient2.h:184
ambient2_cfg_setup
void ambient2_cfg_setup(ambient2_cfg_t *cfg)
Configuration Object Setup function.
ambient2_default_cfg
void ambient2_default_cfg(ambient2_t *ctx)
Click Default Configuration function.
ambient2_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient2.h:242
AMBIENT2_ERR_UNSUPPORTED_PIN
@ AMBIENT2_ERR_UNSUPPORTED_PIN
Definition: ambient2.h:172
ambient2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient2.h:245
AMBIENT2_I2C_ADDRESS_GND
@ AMBIENT2_I2C_ADDRESS_GND
Definition: ambient2.h:181
ambient2_t::int_pin
digital_in_t int_pin
Definition: ambient2.h:219
AMBIENT2_REG_DEVICE_ID
@ AMBIENT2_REG_DEVICE_ID
Definition: ambient2.h:198
ambient2_t::i2c
i2c_master_t i2c
Definition: ambient2.h:222
ambient2_cfg_t::sda
pin_name_t sda
Definition: ambient2.h:239
AMBIENT2_OK
@ AMBIENT2_OK
Definition: ambient2.h:170
AMBIENT2_REG_MANUFACTURER_ID
@ AMBIENT2_REG_MANUFACTURER_ID
Definition: ambient2.h:197
ambient2_err_t
ambient2_err_t
Click error code definition.
Definition: ambient2.h:169
AMBIENT2_ERR_INIT_DRV
@ AMBIENT2_ERR_INIT_DRV
Definition: ambient2.h:171
AMBIENT2_REG_CONFIGURATION
@ AMBIENT2_REG_CONFIGURATION
Definition: ambient2.h:194
ambient2_data_t
uint16_t ambient2_data_t
Click registers data type.
Definition: ambient2.h:163
ambient2_cfg_t::scl
pin_name_t scl
Definition: ambient2.h:238
ambient2_t::sens_data
ambient2_sens_data_t sens_data
Definition: ambient2.h:228
ambient2_generic_read
ambient2_data_t ambient2_generic_read(ambient2_t *ctx, ambient2_reg_addr_t reg_addr)
Generic Read function.
AMBIENT2_REG_RESULT
@ AMBIENT2_REG_RESULT
Definition: ambient2.h:193
ambient2_sens_data_t
Click sensor data definition.
Definition: ambient2.h:206
ambient2_sens_data_t::amb_light_lx
float amb_light_lx
Definition: ambient2.h:207