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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define AMBIENT5_DEVICE_ADDRESS 0x10
67 // End group slave_addr
68
73#define AMBIENT5_MAP_MIKROBUS( cfg, mikrobus ) \
74 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
75 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
76 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
83#define AMBIENT5_RETVAL uint8_t
84
85#define AMBIENT5_OK 0x00
86#define AMBIENT5_INIT_ERROR 0xFF
93#define AMBIENT5_CONFIGURATION 0x00
94#define AMBIENT5_HIGH_THRESHOLD 0x01
95#define AMBIENT5_LOW_THRESHOLD 0x02
96#define AMBIENT5_POWER_SAVING_MODE 0x03
97#define AMBIENT5_HIGH_RESOLUTION_OUTPUT_DATA 0x04
98#define AMBIENT5_WHITE_CHANNEL_OUTPUT_DATA 0x05
99#define AMBIENT5_INTERRUPT_STATUS 0x06
100 // End group register
101
106#define AMBIENT5_GAIN_x1 0x0000
107#define AMBIENT5_GAIN_x2 0x0800
108#define AMBIENT5_GAIN_x1_8 0x1000
109#define AMBIENT5_GAIN_x1_4 0x1800
110#define AMBIENT5_INTEGRATION_TIME_25ms 0x0300
111#define AMBIENT5_INTEGRATION_TIME_50ms 0x0200
112#define AMBIENT5_INTEGRATION_TIME_100ms 0x0000
113#define AMBIENT5_INTEGRATION_TIME_200ms 0x0040
114#define AMBIENT5_INTEGRATION_TIME_400ms 0x0080
115#define AMBIENT5_INTEGRATION_TIME_800ms 0x00C0
116#define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_1 0x0000
117#define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_2 0x0010
118#define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_4 0x0020
119#define AMBIENT5_PERSISTANCE_PROTECT_NUMBER_8 0x0030
120#define AMBIENT5_INTERRUPT_DISABLE 0x0000
121#define AMBIENT5_INTERRUPT_ENABLE 0x0002
122#define AMBIENT5_POWER_ON 0x0000
123#define AMBIENT5_SHUT_DOWN 0x0001
124 // End group configuration_register
125
130#define AMBIENT5_MODE_1 0x0000
131#define AMBIENT5_MODE_2 0x0002
132#define AMBIENT5_MODE_3 0x0004
133#define AMBIENT5_MODE_4 0x0006
134#define AMBIENT5_POWER_SAVING_MODE_DISABLE 0x0000
135#define AMBIENT5_POWER_SAVING_MODE_ENABLE 0x0001
136 // End group power_saving_mode
137
138
139
140 // End group macro
141// --------------------------------------------------------------- PUBLIC TYPES
150typedef struct
151{
152
153 // Input pins
154
155 digital_in_t int_pin;
156
157 // Modules
158
159 i2c_master_t i2c;
160
161 // ctx variable
162
164
165} ambient5_t;
166
170typedef struct
171{
172 // Communication gpio pins
173
174 pin_name_t scl;
175 pin_name_t sda;
176
177 // Additional gpio pins
178
179 pin_name_t int_pin;
180
181 // static variable
182
183 uint32_t i2c_speed;
184 uint8_t i2c_address;
185
187
188 // End types group
189// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
190
196#ifdef __cplusplus
197extern "C"{
198#endif
199
210
221
229
238void ambient5_set_register ( ambient5_t* ctx, uint8_t reg_addr,
239 uint16_t reg_value );
240
249uint16_t ambient5_get_register ( ambient5_t* ctx, uint8_t reg );
250
260
272
284
296
307 float low_light_level_threshold );
308
319 float high_light_level_threshold );
320
329
340
341#ifdef __cplusplus
342}
343#endif
344#endif // _AMBIENT5_H_
345
346 // End public_function group
348
349// ------------------------------------------------------------------------- END
#define AMBIENT5_RETVAL
Definition ambient5.h:83
AMBIENT5_RETVAL ambient5_init(ambient5_t *ctx, ambient5_cfg_t *cfg)
Initialization function.
void ambient5_default_cfg(ambient5_t *ctx)
Default configuration function.
uint8_t ambient5_checkIntPin(ambient5_t *ctx)
Checking INT pin state.
float ambient5_get_white_channel_light_level(ambient5_t *ctx)
Get white channel light level.
uint16_t ambient5_get_refresh_time(ambient5_t *ctx)
Get refresh time.
void ambient5_power_on(ambient5_t *ctx)
Set high light level threshold.
void ambient5_cfg_setup(ambient5_cfg_t *cfg)
Config Object Initialization function.
float ambient5_get_high_resolution_light_level(ambient5_t *ctx)
Get high resolution light level.
float ambient5_get_resolution(ambient5_t *ctx)
Get resolution.
uint16_t ambient5_get_register(ambient5_t *ctx, uint8_t reg)
Get register function.
void ambient5_set_low_light_level_threshold(ambient5_t *ctx, float low_light_level_threshold)
Set low light level threshold.
void ambient5_set_register(ambient5_t *ctx, uint8_t reg_addr, uint16_t reg_value)
Set register function.
void ambient5_set_high_light_level_threshold(ambient5_t *ctx, float high_light_level_threshold)
Set high light level threshold.
Click configuration structure definition.
Definition ambient5.h:171
uint32_t i2c_speed
Definition ambient5.h:183
pin_name_t scl
Definition ambient5.h:174
pin_name_t int_pin
Definition ambient5.h:179
pin_name_t sda
Definition ambient5.h:175
uint8_t i2c_address
Definition ambient5.h:184
Click ctx object definition.
Definition ambient5.h:151
digital_in_t int_pin
Definition ambient5.h:155
i2c_master_t i2c
Definition ambient5.h:159
uint8_t slave_address
Definition ambient5.h:163