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 "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 AMBIENT22_REG_RESULT 0x00
70 #define AMBIENT22_REG_CONFIGURATION 0x01
71 #define AMBIENT22_REG_LOW_LIMIT 0x02
72 #define AMBIENT22_REG_HIGH_LIMIT 0x03
73 #define AMBIENT22_REG_MANUFACTURER_ID 0x7E
74 #define AMBIENT22_REG_DEVICE_ID 0x7F
75  // ambient22_reg
77 
92 #define AMBIENT22_CONFIG_RN_AUTO_SCALE 0xC000u
93 #define AMBIENT22_CONFIG_RN_MASK 0xF000u
94 #define AMBIENT22_CONFIG_CT_100_mS 0x0000u
95 #define AMBIENT22_CONFIG_CT_800_mS 0x0800u
96 #define AMBIENT22_CONFIG_CT_MASK 0x0800u
97 #define AMBIENT22_CONFIG_M_SHUTDOWN 0x0000u
98 #define AMBIENT22_CONFIG_M_SINGLE 0x0200u
99 #define AMBIENT22_CONFIG_M_CONTINUOUS 0x0400u
100 #define AMBIENT22_CONFIG_M_MASK 0x0600u
101 #define AMBIENT22_CONFIG_OVF_MASK 0x0100u
102 #define AMBIENT22_CONFIG_CRF_MASK 0x0080u
103 #define AMBIENT22_CONFIG_FH_MASK 0x0040u
104 #define AMBIENT22_CONFIG_FL_MASK 0x0020u
105 #define AMBIENT22_CONFIG_L_TRANSPARENT 0x0000u
106 #define AMBIENT22_CONFIG_L_LATCH 0x0010u
107 #define AMBIENT22_CONFIG_L_MASK 0x0010u
108 #define AMBIENT22_CONFIG_POL_LOW 0x0000u
109 #define AMBIENT22_CONFIG_POL_HIGH 0x0008u
110 #define AMBIENT22_CONFIG_POL_MASK 0x0008u
111 #define AMBIENT22_CONFIG_ME_MASK 0x0004u
112 #define AMBIENT22_CONFIG_FC_ONE 0x0000u
113 #define AMBIENT22_CONFIG_FC_TWO 0x0001u
114 #define AMBIENT22_CONFIG_FC_FOUR 0x0002u
115 #define AMBIENT22_CONFIG_FC_EIGHT 0x0003u
116 #define AMBIENT22_CONFIG_FC_MASK 0x0003u
117 
122 #define AMBIENT22_RESULT_EXP 0xF000u
123 #define AMBIENT22_RESULT_FRACT 0x0FFFu
124 #define AMBIENT22_RESULT_MIN 0x0000u
125 #define AMBIENT22_RESULT_MAX 0xBFFFu
126 #define AMBIENT22_RESULT_LUX_PER_LSB 0.02f
127 
132 #define AMBIENT22_MANUFACTURER_ID 0x5449u
133 #define AMBIENT22_DEVICE_ID 0x3001u
134 
140 #define AMBIENT22_DEVICE_ADDRESS_0 0x44
141 #define AMBIENT22_DEVICE_ADDRESS_1 0x45
142  // ambient22_set
144 
159 #define AMBIENT22_MAP_MIKROBUS( cfg, mikrobus ) \
160  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
161  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
162  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
163  // ambient22_map // ambient22
166 
171 typedef struct
172 {
173  // Input pins
174  digital_in_t int_pin;
176  // Modules
177  i2c_master_t i2c;
179  // I2C slave address
180  uint8_t slave_address;
182 } ambient22_t;
183 
188 typedef struct
189 {
190  pin_name_t scl;
191  pin_name_t sda;
193  pin_name_t int_pin;
195  uint32_t i2c_speed;
196  uint8_t i2c_address;
199 
204 typedef enum
205 {
207  AMBIENT22_ERROR = -1
208 
210 
227 
242 
256 
269 err_t ambient22_write_register ( ambient22_t *ctx, uint8_t reg, uint16_t data_in );
270 
283 err_t ambient22_read_register ( ambient22_t *ctx, uint8_t reg, uint16_t *data_out );
284 
297 
310 err_t ambient22_read_lux ( ambient22_t *ctx, float *lux );
311 
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 #endif // AMBIENT22_H
326  // ambient22
328 
329 // ------------------------------------------------------------------------ END
ambient22_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient22.h:195
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:189
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:172
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:193
ambient22_return_value_t
ambient22_return_value_t
Ambient 22 Click return value data.
Definition: ambient22.h:205
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:196
ambient22_t::int_pin
digital_in_t int_pin
Definition: ambient22.h:174
ambient22_cfg_t::sda
pin_name_t sda
Definition: ambient22.h:191
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:180
ambient22_cfg_t::scl
pin_name_t scl
Definition: ambient22.h:190
AMBIENT22_ERROR
@ AMBIENT22_ERROR
Definition: ambient22.h:207
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:177
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:206