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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define AMBIENT5_DEVICE_ADDRESS 0x10
53  // End group slave_addr
54 
59 #define AMBIENT5_MAP_MIKROBUS( cfg, mikrobus ) \
60  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
61  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
62  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
63 
69 #define AMBIENT5_RETVAL uint8_t
70 
71 #define AMBIENT5_OK 0x00
72 #define AMBIENT5_INIT_ERROR 0xFF
73 
79 #define AMBIENT5_CONFIGURATION 0x00
80 #define AMBIENT5_HIGH_THRESHOLD 0x01
81 #define AMBIENT5_LOW_THRESHOLD 0x02
82 #define AMBIENT5_POWER_SAVING_MODE 0x03
83 #define AMBIENT5_HIGH_RESOLUTION_OUTPUT_DATA 0x04
84 #define AMBIENT5_WHITE_CHANNEL_OUTPUT_DATA 0x05
85 #define AMBIENT5_INTERRUPT_STATUS 0x06
86  // End group register
87 
92 #define AMBIENT5_GAIN_x1 0x0000
93 #define AMBIENT5_GAIN_x2 0x0800
94 #define AMBIENT5_GAIN_x1_8 0x1000
95 #define AMBIENT5_GAIN_x1_4 0x1800
96 #define AMBIENT5_INTEGRATION_TIME_25ms 0x0300
97 #define AMBIENT5_INTEGRATION_TIME_50ms 0x0200
98 #define AMBIENT5_INTEGRATION_TIME_100ms 0x0000
99 #define AMBIENT5_INTEGRATION_TIME_200ms 0x0040
100 #define AMBIENT5_INTEGRATION_TIME_400ms 0x0080
101 #define AMBIENT5_INTEGRATION_TIME_800ms 0x00C0
102 #define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_1 0x0000
103 #define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_2 0x0010
104 #define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_4 0x0020
105 #define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_8 0x0030
106 #define AMBIENT5_INTERRUPT_DISABLE 0x0000
107 #define AMBIENT5_INTERRUPT_ENABLE 0x0002
108 #define AMBIENT5_POWER_ON 0x0000
109 #define AMBIENT5_SHUT_DOWN 0x0001
110  // End group configuration_register
111 
116 #define AMBIENT5_MODE_1 0x0000
117 #define AMBIENT5_MODE_2 0x0002
118 #define AMBIENT5_MODE_3 0x0004
119 #define AMBIENT5_MODE_4 0x0006
120 #define AMBIENT5_POWER_SAVING_MODE_DISABLE 0x0000
121 #define AMBIENT5_POWER_SAVING_MODE_ENABLE 0x0001
122  // End group power_saving_mode
123 
124 
125  // End group macro
127 // --------------------------------------------------------------- PUBLIC TYPES
136 typedef struct
137 {
138 
139  // Input pins
140 
141  digital_in_t int_pin;
142 
143  // Modules
144 
145  i2c_master_t i2c;
146 
147  // ctx variable
148 
149  uint8_t slave_address;
150 
151 } ambient5_t;
152 
156 typedef struct
157 {
158  // Communication gpio pins
159 
160  pin_name_t scl;
161  pin_name_t sda;
162 
163  // Additional gpio pins
164 
165  pin_name_t int_pin;
166 
167  // static variable
168 
169  uint32_t i2c_speed;
170  uint8_t i2c_address;
171 
173  // End types group
175 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
176 
182 #ifdef __cplusplus
183 extern "C"{
184 #endif
185 
195 void ambient5_cfg_setup ( ambient5_cfg_t *cfg );
196 
207 
214 void ambient5_default_cfg ( ambient5_t *ctx );
215 
224 void ambient5_set_register ( ambient5_t* ctx, uint8_t reg_addr,
225  uint16_t reg_value );
226 
235 int16_t ambient5_get_register ( ambient5_t* ctx, uint8_t reg );
236 
245 float ambient5_get_resolution ( ambient5_t* ctx );
246 
257 uint16_t ambient5_get_refresh_time ( ambient5_t* ctx );
258 
270 
282 
293  float low_light_level_threshold );
294 
305  float high_light_level_threshold );
306 
314 void ambient5_power_on ( ambient5_t* ctx );
315 
325 uint8_t ambient5_checkIntPin ( ambient5_t* ctx );
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 #endif // _AMBIENT5_H_
331  // End public_function group
334 
335 // ------------------------------------------------------------------------- END
ambient5_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient5.h:165
ambient5_get_register
int16_t ambient5_get_register(ambient5_t *ctx, uint8_t reg)
Get register function.
ambient5_t::int_pin
digital_in_t int_pin
Definition: ambient5.h:141
ambient5_default_cfg
void ambient5_default_cfg(ambient5_t *ctx)
Default configuration function.
ambient5_t::i2c
i2c_master_t i2c
Definition: ambient5.h:145
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:160
ambient5_cfg_t
Click configuration structure definition.
Definition: ambient5.h:156
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:170
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:136
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:69
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:161
ambient5_t::slave_address
uint8_t slave_address
Definition: ambient5.h:149
ambient5_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient5.h:169
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.