ambient5  2.0.0.0
ambient5.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  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef AMBIENT5_H
36 #define AMBIENT5_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define AMBIENT5_DEVICE_ADDRESS 0x10
63  // End group slave_addr
64 
69 #define AMBIENT5_MAP_MIKROBUS( cfg, mikrobus ) \
70  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
71  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
72  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
73 
79 #define AMBIENT5_RETVAL uint8_t
80 
81 #define AMBIENT5_OK 0x00
82 #define AMBIENT5_INIT_ERROR 0xFF
83 
89 #define AMBIENT5_CONFIGURATION 0x00
90 #define AMBIENT5_HIGH_THRESHOLD 0x01
91 #define AMBIENT5_LOW_THRESHOLD 0x02
92 #define AMBIENT5_POWER_SAVING_MODE 0x03
93 #define AMBIENT5_HIGH_RESOLUTION_OUTPUT_DATA 0x04
94 #define AMBIENT5_WHITE_CHANNEL_OUTPUT_DATA 0x05
95 #define AMBIENT5_INTERRUPT_STATUS 0x06
96  // End group register
97 
102 #define AMBIENT5_GAIN_x1 0x0000
103 #define AMBIENT5_GAIN_x2 0x0800
104 #define AMBIENT5_GAIN_x1_8 0x1000
105 #define AMBIENT5_GAIN_x1_4 0x1800
106 #define AMBIENT5_INTEGRATION_TIME_25ms 0x0300
107 #define AMBIENT5_INTEGRATION_TIME_50ms 0x0200
108 #define AMBIENT5_INTEGRATION_TIME_100ms 0x0000
109 #define AMBIENT5_INTEGRATION_TIME_200ms 0x0040
110 #define AMBIENT5_INTEGRATION_TIME_400ms 0x0080
111 #define AMBIENT5_INTEGRATION_TIME_800ms 0x00C0
112 #define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_1 0x0000
113 #define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_2 0x0010
114 #define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_4 0x0020
115 #define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_8 0x0030
116 #define AMBIENT5_INTERRUPT_DISABLE 0x0000
117 #define AMBIENT5_INTERRUPT_ENABLE 0x0002
118 #define AMBIENT5_POWER_ON 0x0000
119 #define AMBIENT5_SHUT_DOWN 0x0001
120  // End group configuration_register
121 
126 #define AMBIENT5_MODE_1 0x0000
127 #define AMBIENT5_MODE_2 0x0002
128 #define AMBIENT5_MODE_3 0x0004
129 #define AMBIENT5_MODE_4 0x0006
130 #define AMBIENT5_POWER_SAVING_MODE_DISABLE 0x0000
131 #define AMBIENT5_POWER_SAVING_MODE_ENABLE 0x0001
132  // End group power_saving_mode
133 
134 
135  // End group macro
137 // --------------------------------------------------------------- PUBLIC TYPES
146 typedef struct
147 {
148 
149  // Input pins
150 
151  digital_in_t int_pin;
152 
153  // Modules
154 
155  i2c_master_t i2c;
156 
157  // ctx variable
158 
159  uint8_t slave_address;
160 
161 } ambient5_t;
162 
166 typedef struct
167 {
168  // Communication gpio pins
169 
170  pin_name_t scl;
171  pin_name_t sda;
172 
173  // Additional gpio pins
174 
175  pin_name_t int_pin;
176 
177  // static variable
178 
179  uint32_t i2c_speed;
180  uint8_t i2c_address;
181 
183  // End types group
185 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
186 
192 #ifdef __cplusplus
193 extern "C"{
194 #endif
195 
206 
217 
225 
234 void ambient5_set_register ( ambient5_t* ctx, uint8_t reg_addr,
235  uint16_t reg_value );
236 
245 uint16_t ambient5_get_register ( ambient5_t* ctx, uint8_t reg );
246 
256 
268 
280 
292 
303  float low_light_level_threshold );
304 
315  float high_light_level_threshold );
316 
325 
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 #endif // _AMBIENT5_H_
341  // End public_function group
344 
345 // ------------------------------------------------------------------------- END
ambient5_get_register
uint16_t ambient5_get_register(ambient5_t *ctx, uint8_t reg)
Get register function.
ambient5_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient5.h:175
ambient5_t::int_pin
digital_in_t int_pin
Definition: ambient5.h:151
ambient5_default_cfg
void ambient5_default_cfg(ambient5_t *ctx)
Default configuration function.
ambient5_t::i2c
i2c_master_t i2c
Definition: ambient5.h:155
ambient5_set_register
void ambient5_set_register(ambient5_t *ctx, uint8_t reg_addr, uint16_t reg_value)
Set register function.
ambient5_cfg_setup
void ambient5_cfg_setup(ambient5_cfg_t *cfg)
Config Object Initialization function.
ambient5_cfg_t::scl
pin_name_t scl
Definition: ambient5.h:170
ambient5_cfg_t
Click configuration structure definition.
Definition: ambient5.h:167
ambient5_init
AMBIENT5_RETVAL ambient5_init(ambient5_t *ctx, ambient5_cfg_t *cfg)
Initialization function.
ambient5_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient5.h:180
ambient5_get_high_resolution_light_level
float ambient5_get_high_resolution_light_level(ambient5_t *ctx)
Get high resolution light level.
ambient5_t
Click ctx object definition.
Definition: ambient5.h:147
ambient5_checkIntPin
uint8_t ambient5_checkIntPin(ambient5_t *ctx)
Checking INT pin state.
ambient5_set_low_light_level_threshold
void ambient5_set_low_light_level_threshold(ambient5_t *ctx, float low_light_level_threshold)
Set low light level threshold.
ambient5_get_refresh_time
uint16_t ambient5_get_refresh_time(ambient5_t *ctx)
Get refresh time.
ambient5_power_on
void ambient5_power_on(ambient5_t *ctx)
Set high light level threshold.
AMBIENT5_RETVAL
#define AMBIENT5_RETVAL
Definition: ambient5.h:79
ambient5_get_white_channel_light_level
float ambient5_get_white_channel_light_level(ambient5_t *ctx)
Get white channel light level.
ambient5_get_resolution
float ambient5_get_resolution(ambient5_t *ctx)
Get resolution.
ambient5_cfg_t::sda
pin_name_t sda
Definition: ambient5.h:171
ambient5_t::slave_address
uint8_t slave_address
Definition: ambient5.h:159
ambient5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient5.h:179
ambient5_set_high_light_level_threshold
void ambient5_set_high_light_level_threshold(ambient5_t *ctx, float high_light_level_threshold)
Set high light level threshold.