illuminance  2.0.0.0
illuminance.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 ILLUMINANCE_H
29 #define ILLUMINANCE_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 ILLUMINANCE_REG_CONTROL 0x00
70 #define ILLUMINANCE_REG_TIMING 0x01
71 #define ILLUMINANCE_REG_INTERRUPT 0x02
72 #define ILLUMINANCE_REG_THL_LOW 0x03
73 #define ILLUMINANCE_REG_THL_HIGH 0x04
74 #define ILLUMINANCE_REG_THH_LOW 0x05
75 #define ILLUMINANCE_REG_THH_HIGH 0x06
76 #define ILLUMINANCE_REG_ANALOG 0x07
77 #define ILLUMINANCE_REG_ID 0x12
78 #define ILLUMINANCE_REG_DATA0_LOW 0x14
79 #define ILLUMINANCE_REG_DATA0_HIGH 0x15
80 #define ILLUMINANCE_REG_DATA1_LOW 0x16
81 #define ILLUMINANCE_REG_DATA1_HIGH 0x17
82 #define ILLUMINANCE_REG_TIMER_LOW 0x18
83 #define ILLUMINANCE_REG_TIMER_HIGH 0x19
84 #define ILLUMINANCE_REG_ID2 0x1E
85  // illuminance_reg
87 
102 #define ILLUMINANCE_CMD_BIT 0x80
103 #define ILLUMINANCE_TRANSACTION_REPEATED 0x00
104 #define ILLUMINANCE_TRANSACTION_AUTO_INC 0x20
105 #define ILLUMINANCE_TRANSACTION_SPEC_FUNC 0x60
106 #define ILLUMINANCE_SPEC_FUNC_INT_CLEAR 0x01
107 #define ILLUMINANCE_SPEC_FUNC_STOP_MAN_INT 0x02
108 #define ILLUMINANCE_SPEC_FUNC_START_MAN_INT 0x03
109 
114 #define ILLUMINANCE_CONTROL_ADC_INTR 0x20
115 #define ILLUMINANCE_CONTROL_ADC_VALID 0x10
116 #define ILLUMINANCE_CONTROL_ADC_ENABLE 0x02
117 #define ILLUMINANCE_CONTROL_POWER_ON 0x01
118 
123 #define ILLUMINANCE_ATIME_MAX 688.5
124 #define ILLUMINANCE_ATIME_MIN 2.7
125 #define ILLUMINANCE_ATIME_STEP 2.7
126 #define ILLUMINANCE_DEFAULT_ATIME 200.0
127 
132 #define ILLUMINANCE_ENABLE_INTERRUPT 0x10
133 
138 #define ILLUMINANCE_GAIN_1X 0x00
139 #define ILLUMINANCE_GAIN_8X 0x01
140 #define ILLUMINANCE_GAIN_16X 0x02
141 #define ILLUMINANCE_GAIN_111X 0x03
142 
147 #define ILLUMINANCE_ID_PARTNO 0x90
148 #define ILLUMINANCE_ID2 0x30
149 
155 #define ILLUMINANCE_SET_DEV_ADDR_GND 0x29
156 #define ILLUMINANCE_SET_DEV_ADDR_FLOAT 0x39
157 #define ILLUMINANCE_SET_DEV_ADDR_VCC 0x49
158  // illuminance_set
160 
175 #define ILLUMINANCE_MAP_MIKROBUS( cfg, mikrobus ) \
176  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
177  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
178  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
179  // illuminance_map // illuminance
182 
187 typedef struct
188 {
189  // Input pins
190  digital_in_t int_pin;
192  // Modules
193  i2c_master_t i2c;
195  // I2C slave address
196  uint8_t slave_address;
198  float atime_ms;
199  uint8_t gain;
201 } illuminance_t;
202 
207 typedef struct
208 {
209  pin_name_t scl;
210  pin_name_t sda;
212  pin_name_t int_pin;
214  uint32_t i2c_speed;
215  uint8_t i2c_address;
218 
223 typedef enum
224 {
226  ILLUMINANCE_ERROR = -1
227 
229 
246 
262 
277 
292 err_t illuminance_generic_write ( illuminance_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
293 
308 err_t illuminance_generic_read ( illuminance_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
309 
322 err_t illuminance_write_register ( illuminance_t *ctx, uint8_t reg, uint8_t data_in );
323 
336 err_t illuminance_read_register ( illuminance_t *ctx, uint8_t reg, uint8_t *data_out );
337 
347 
359 
371 err_t illuminance_set_atime ( illuminance_t *ctx, float atime_ms );
372 
384 err_t illuminance_set_gain ( illuminance_t *ctx, uint8_t gain );
385 
398 err_t illuminance_read_raw_data ( illuminance_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
399 
400 #ifdef __cplusplus
401 }
402 #endif
403 #endif // ILLUMINANCE_H
404  // illuminance
406 
407 // ------------------------------------------------------------------------ END
illuminance_t::atime_ms
float atime_ms
Definition: illuminance.h:198
illuminance_cfg_t::sda
pin_name_t sda
Definition: illuminance.h:210
illuminance_default_cfg
err_t illuminance_default_cfg(illuminance_t *ctx)
Illuminance default configuration function.
illuminance_t::int_pin
digital_in_t int_pin
Definition: illuminance.h:190
illuminance_read_register
err_t illuminance_read_register(illuminance_t *ctx, uint8_t reg, uint8_t *data_out)
Illuminance read register function.
illuminance_get_int_pin
uint8_t illuminance_get_int_pin(illuminance_t *ctx)
Illuminance get int pin function.
ILLUMINANCE_OK
@ ILLUMINANCE_OK
Definition: illuminance.h:225
illuminance_init
err_t illuminance_init(illuminance_t *ctx, illuminance_cfg_t *cfg)
Illuminance initialization function.
illuminance_check_communication
err_t illuminance_check_communication(illuminance_t *ctx)
Illuminance check communication function.
illuminance_set_atime
err_t illuminance_set_atime(illuminance_t *ctx, float atime_ms)
Illuminance set atime function.
illuminance_t::gain
uint8_t gain
Definition: illuminance.h:199
ILLUMINANCE_ERROR
@ ILLUMINANCE_ERROR
Definition: illuminance.h:226
illuminance_t::slave_address
uint8_t slave_address
Definition: illuminance.h:196
illuminance_generic_read
err_t illuminance_generic_read(illuminance_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Illuminance I2C reading function.
illuminance_return_value_t
illuminance_return_value_t
Illuminance Click return value data.
Definition: illuminance.h:224
illuminance_cfg_t::i2c_address
uint8_t i2c_address
Definition: illuminance.h:215
illuminance_cfg_t::int_pin
pin_name_t int_pin
Definition: illuminance.h:212
illuminance_t::i2c
i2c_master_t i2c
Definition: illuminance.h:193
illuminance_cfg_t::scl
pin_name_t scl
Definition: illuminance.h:209
illuminance_write_register
err_t illuminance_write_register(illuminance_t *ctx, uint8_t reg, uint8_t data_in)
Illuminance write register function.
illuminance_t
Illuminance Click context object.
Definition: illuminance.h:188
illuminance_cfg_t
Illuminance Click configuration object.
Definition: illuminance.h:208
illuminance_set_gain
err_t illuminance_set_gain(illuminance_t *ctx, uint8_t gain)
Illuminance set gain function.
illuminance_read_raw_data
err_t illuminance_read_raw_data(illuminance_t *ctx, uint16_t *ch_0, uint16_t *ch_1)
Illuminance read raw data function.
illuminance_cfg_setup
void illuminance_cfg_setup(illuminance_cfg_t *cfg)
Illuminance configuration object setup function.
illuminance_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: illuminance.h:214
illuminance_generic_write
err_t illuminance_generic_write(illuminance_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Illuminance I2C writing function.