ambient22  2.1.0.0
ambient22.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 AMBIENT22_H
29 #define AMBIENT22_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 AMBIENT22_REG_RESULT 0x00
60 #define AMBIENT22_REG_CONFIGURATION 0x01
61 #define AMBIENT22_REG_LOW_LIMIT 0x02
62 #define AMBIENT22_REG_HIGH_LIMIT 0x03
63 #define AMBIENT22_REG_MANUFACTURER_ID 0x7E
64 #define AMBIENT22_REG_DEVICE_ID 0x7F
65  // ambient22_reg
67 
82 #define AMBIENT22_CONFIG_RN_AUTO_SCALE 0xC000u
83 #define AMBIENT22_CONFIG_RN_MASK 0xF000u
84 #define AMBIENT22_CONFIG_CT_100_mS 0x0000u
85 #define AMBIENT22_CONFIG_CT_800_mS 0x0800u
86 #define AMBIENT22_CONFIG_CT_MASK 0x0800u
87 #define AMBIENT22_CONFIG_M_SHUTDOWN 0x0000u
88 #define AMBIENT22_CONFIG_M_SINGLE 0x0200u
89 #define AMBIENT22_CONFIG_M_CONTINUOUS 0x0400u
90 #define AMBIENT22_CONFIG_M_MASK 0x0600u
91 #define AMBIENT22_CONFIG_OVF_MASK 0x0100u
92 #define AMBIENT22_CONFIG_CRF_MASK 0x0080u
93 #define AMBIENT22_CONFIG_FH_MASK 0x0040u
94 #define AMBIENT22_CONFIG_FL_MASK 0x0020u
95 #define AMBIENT22_CONFIG_L_TRANSPARENT 0x0000u
96 #define AMBIENT22_CONFIG_L_LATCH 0x0010u
97 #define AMBIENT22_CONFIG_L_MASK 0x0010u
98 #define AMBIENT22_CONFIG_POL_LOW 0x0000u
99 #define AMBIENT22_CONFIG_POL_HIGH 0x0008u
100 #define AMBIENT22_CONFIG_POL_MASK 0x0008u
101 #define AMBIENT22_CONFIG_ME_MASK 0x0004u
102 #define AMBIENT22_CONFIG_FC_ONE 0x0000u
103 #define AMBIENT22_CONFIG_FC_TWO 0x0001u
104 #define AMBIENT22_CONFIG_FC_FOUR 0x0002u
105 #define AMBIENT22_CONFIG_FC_EIGHT 0x0003u
106 #define AMBIENT22_CONFIG_FC_MASK 0x0003u
107 
112 #define AMBIENT22_RESULT_EXP 0xF000u
113 #define AMBIENT22_RESULT_FRACT 0x0FFFu
114 #define AMBIENT22_RESULT_MIN 0x0000u
115 #define AMBIENT22_RESULT_MAX 0xBFFFu
116 #define AMBIENT22_RESULT_LUX_PER_LSB 0.02f
117 
122 #define AMBIENT22_MANUFACTURER_ID 0x5449u
123 #define AMBIENT22_DEVICE_ID 0x3001u
124 
130 #define AMBIENT22_DEVICE_ADDRESS_0 0x44
131 #define AMBIENT22_DEVICE_ADDRESS_1 0x45
132  // ambient22_set
134 
149 #define AMBIENT22_MAP_MIKROBUS( cfg, mikrobus ) \
150  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
151  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
152  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
153  // ambient22_map // ambient22
156 
161 typedef struct
162 {
163  // Input pins
164  digital_in_t int_pin;
166  // Modules
167  i2c_master_t i2c;
169  // I2C slave address
170  uint8_t slave_address;
172 } ambient22_t;
173 
178 typedef struct
179 {
180  pin_name_t scl;
181  pin_name_t sda;
183  pin_name_t int_pin;
185  uint32_t i2c_speed;
186  uint8_t i2c_address;
189 
194 typedef enum
195 {
197  AMBIENT22_ERROR = -1
198 
200 
217 
232 
246 
259 err_t ambient22_write_register ( ambient22_t *ctx, uint8_t reg, uint16_t data_in );
260 
273 err_t ambient22_read_register ( ambient22_t *ctx, uint8_t reg, uint16_t *data_out );
274 
287 
300 err_t ambient22_read_lux ( ambient22_t *ctx, float *lux );
301 
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 #endif // AMBIENT22_H
316  // ambient22
318 
319 // ------------------------------------------------------------------------ END
ambient22_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient22.h:185
ambient22_init
err_t ambient22_init(ambient22_t *ctx, ambient22_cfg_t *cfg)
Ambient 22 initialization function.
ambient22_cfg_t
Ambient 22 Click configuration object.
Definition: ambient22.h:179
ambient22_read_register
err_t ambient22_read_register(ambient22_t *ctx, uint8_t reg, uint16_t *data_out)
Ambient 22 read register function.
ambient22_default_cfg
err_t ambient22_default_cfg(ambient22_t *ctx)
Ambient 22 default configuration function.
ambient22_t
Ambient 22 Click context object.
Definition: ambient22.h:162
ambient22_check_communication
err_t ambient22_check_communication(ambient22_t *ctx)
Ambient 22 check communication function.
ambient22_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient22.h:183
ambient22_return_value_t
ambient22_return_value_t
Ambient 22 Click return value data.
Definition: ambient22.h:195
ambient22_get_int_pin
uint8_t ambient22_get_int_pin(ambient22_t *ctx)
Ambient 22 get int pin function.
ambient22_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient22.h:186
ambient22_t::int_pin
digital_in_t int_pin
Definition: ambient22.h:164
ambient22_cfg_t::sda
pin_name_t sda
Definition: ambient22.h:181
ambient22_cfg_setup
void ambient22_cfg_setup(ambient22_cfg_t *cfg)
Ambient 22 configuration object setup function.
ambient22_t::slave_address
uint8_t slave_address
Definition: ambient22.h:170
ambient22_cfg_t::scl
pin_name_t scl
Definition: ambient22.h:180
AMBIENT22_ERROR
@ AMBIENT22_ERROR
Definition: ambient22.h:197
ambient22_write_register
err_t ambient22_write_register(ambient22_t *ctx, uint8_t reg, uint16_t data_in)
Ambient 22 write register function.
ambient22_t::i2c
i2c_master_t i2c
Definition: ambient22.h:167
ambient22_read_lux
err_t ambient22_read_lux(ambient22_t *ctx, float *lux)
Ambient 22 read lux function.
AMBIENT22_OK
@ AMBIENT22_OK
Definition: ambient22.h:196