ambient17  2.0.0.0
ambient17.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 AMBIENT17_H
29 #define AMBIENT17_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 AMBIENT17_REG_ENABLE 0x00
70 #define AMBIENT17_REG_ATIME 0x01
71 #define AMBIENT17_REG_WTIME 0x03
72 #define AMBIENT17_REG_AILTL 0x04
73 #define AMBIENT17_REG_AILTH 0x05
74 #define AMBIENT17_REG_AIHTL 0x06
75 #define AMBIENT17_REG_AIHTH 0x07
76 #define AMBIENT17_REG_PERS 0x0C
77 #define AMBIENT17_REG_CONFIG 0x0D
78 #define AMBIENT17_REG_CONTROL 0x0F
79 #define AMBIENT17_REG_ID 0x12
80 #define AMBIENT17_REG_STATUS 0x13
81 #define AMBIENT17_REG_C0DATA 0x14
82 #define AMBIENT17_REG_C0DATAH 0x15
83 #define AMBIENT17_REG_C1DATA 0x16
84 #define AMBIENT17_REG_C1DATAH 0x17
85  // ambient17_reg
87 
102 #define AMBIENT17_CMD_BIT 0x80
103 #define AMBIENT17_TYPE_REPEATED 0x00
104 #define AMBIENT17_TYPE_AUTO_INC 0x20
105 #define AMBIENT17_TYPE_SPEC_FUNC 0x60
106 #define AMBIENT17_SPEC_FUNC_INT_CLEAR 0x06
107 
112 #define AMBIENT17_ENABLE_SLEEP_AFTER_INT 0x40
113 #define AMBIENT17_ENABLE_ALS_INT 0x10
114 #define AMBIENT17_ENABLE_WAIT 0x08
115 #define AMBIENT17_ENABLE_ALS 0x02
116 #define AMBIENT17_ENABLE_OSC 0x01
117 
122 #define AMBIENT17_STATUS_AINT 0x10
123 #define AMBIENT17_STATUS_AVALID 0x01
124 
129 #define AMBIENT17_ATIME_MAX 699.88
130 #define AMBIENT17_ATIME_MIN 2.73
131 #define AMBIENT17_ATIME_STEP 2.73
132 #define AMBIENT17_DEFAULT_ATIME 200.0
133 
138 #define AMBIENT17_WTIME_MAX 699.88
139 #define AMBIENT17_WTIME_MIN 2.73
140 #define AMBIENT17_WTIME_STEP 2.73
141 #define AMBIENT17_DEFAULT_WTIME 200.0
142 
147 #define AMBIENT17_AGAIN_1X 0x00
148 #define AMBIENT17_AGAIN_8X 0x01
149 #define AMBIENT17_AGAIN_16X 0x02
150 #define AMBIENT17_AGAIN_120X 0x03
151 
156 #define AMBIENT17_CH0_COFF0 1.0
157 #define AMBIENT17_CH1_COFF0 1.87
158 #define AMBIENT17_CH0_COFF1 0.63
159 #define AMBIENT17_CH1_COFF1 1.0
160 #define AMBIENT17_GA_VALUE 1.0
161 #define AMBIENT17_GA_MULTIPLIER 60.0
162 
167 #define AMBIENT17_DEVICE_ID 0x34
168 
174 #define AMBIENT17_DEVICE_ADDRESS 0x39
175  // ambient17_set
177 
192 #define AMBIENT17_MAP_MIKROBUS( cfg, mikrobus ) \
193  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
194  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
195  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
196  // ambient17_map // ambient17
199 
204 typedef struct
205 {
206  // Input pins
207  digital_in_t int_pin;
209  // Modules
210  i2c_master_t i2c;
212  // I2C slave address
213  uint8_t slave_address;
215  float atime_ms;
216  uint8_t again;
217  float cpl;
219 } ambient17_t;
220 
225 typedef struct
226 {
227  pin_name_t scl;
228  pin_name_t sda;
230  pin_name_t int_pin;
232  uint32_t i2c_speed;
233  uint8_t i2c_address;
236 
241 typedef enum
242 {
244  AMBIENT17_ERROR = -1
245 
247 
264 
279 
293 
308 err_t ambient17_generic_write ( ambient17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
309 
324 err_t ambient17_generic_read ( ambient17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
325 
338 err_t ambient17_write_register ( ambient17_t *ctx, uint8_t reg, uint8_t data_in );
339 
352 err_t ambient17_read_register ( ambient17_t *ctx, uint8_t reg, uint8_t *data_out );
353 
365 
375 
387 
399 err_t ambient17_set_atime ( ambient17_t *ctx, float atime_ms );
400 
412 err_t ambient17_set_wtime ( ambient17_t *ctx, float wtime_ms );
413 
429 err_t ambient17_set_again ( ambient17_t *ctx, uint8_t again );
430 
443 err_t ambient17_read_raw_data ( ambient17_t *ctx, uint16_t *ch_0, uint16_t *ch_1 );
444 
457 err_t ambient17_measure_light_level ( ambient17_t *ctx, uint16_t *lux );
458 
459 #ifdef __cplusplus
460 }
461 #endif
462 #endif // AMBIENT17_H
463  // ambient17
465 
466 // ------------------------------------------------------------------------ END
ambient17_check_communication
err_t ambient17_check_communication(ambient17_t *ctx)
Ambient 17 check communication function.
ambient17_set_wtime
err_t ambient17_set_wtime(ambient17_t *ctx, float wtime_ms)
Ambient 17 set wtime function.
ambient17_set_atime
err_t ambient17_set_atime(ambient17_t *ctx, float atime_ms)
Ambient 17 set atime function.
ambient17_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient17.h:233
ambient17_generic_read
err_t ambient17_generic_read(ambient17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Ambient 17 I2C reading function.
ambient17_cfg_t
Ambient 17 Click configuration object.
Definition: ambient17.h:226
AMBIENT17_ERROR
@ AMBIENT17_ERROR
Definition: ambient17.h:244
ambient17_read_register
err_t ambient17_read_register(ambient17_t *ctx, uint8_t reg, uint8_t *data_out)
Ambient 17 read register function.
ambient17_t::int_pin
digital_in_t int_pin
Definition: ambient17.h:207
ambient17_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient17.h:230
ambient17_t
Ambient 17 Click context object.
Definition: ambient17.h:205
ambient17_get_int_pin
uint8_t ambient17_get_int_pin(ambient17_t *ctx)
Ambient 17 get INT pin function.
ambient17_measure_light_level
err_t ambient17_measure_light_level(ambient17_t *ctx, uint16_t *lux)
Ambient 17 measure light level function.
ambient17_t::slave_address
uint8_t slave_address
Definition: ambient17.h:213
AMBIENT17_OK
@ AMBIENT17_OK
Definition: ambient17.h:243
ambient17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient17.h:232
ambient17_t::cpl
float cpl
Definition: ambient17.h:217
ambient17_cfg_t::scl
pin_name_t scl
Definition: ambient17.h:227
ambient17_init
err_t ambient17_init(ambient17_t *ctx, ambient17_cfg_t *cfg)
Ambient 17 initialization function.
ambient17_t::atime_ms
float atime_ms
Definition: ambient17.h:215
ambient17_read_raw_data
err_t ambient17_read_raw_data(ambient17_t *ctx, uint16_t *ch_0, uint16_t *ch_1)
Ambient 17 read raw data function.
ambient17_return_value_t
ambient17_return_value_t
Ambient 17 Click return value data.
Definition: ambient17.h:242
ambient17_cfg_setup
void ambient17_cfg_setup(ambient17_cfg_t *cfg)
Ambient 17 configuration object setup function.
ambient17_t::i2c
i2c_master_t i2c
Definition: ambient17.h:210
ambient17_generic_write
err_t ambient17_generic_write(ambient17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Ambient 17 I2C writing function.
ambient17_default_cfg
err_t ambient17_default_cfg(ambient17_t *ctx)
Ambient 17 default configuration function.
ambient17_set_again
err_t ambient17_set_again(ambient17_t *ctx, uint8_t again)
Ambient 17 set again function.
ambient17_cfg_t::sda
pin_name_t sda
Definition: ambient17.h:228
ambient17_clear_interrupts
err_t ambient17_clear_interrupts(ambient17_t *ctx)
Ambient 17 clear interrupts function.
ambient17_write_register
err_t ambient17_write_register(ambient17_t *ctx, uint8_t reg, uint8_t data_in)
Ambient 17 write register function.
ambient17_t::again
uint8_t again
Definition: ambient17.h:216