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 // 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 )
69#define AMBIENT5_RETVAL uint8_t
70
71#define AMBIENT5_OK 0x00
72#define AMBIENT5_INIT_ERROR 0xFF
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 // 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 // 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 // End group power_saving_mode
123
124
125 // End group macro
127// --------------------------------------------------------------- PUBLIC TYPES
136typedef 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
150
151} ambient5_t;
152
156typedef 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
183extern "C"{
184#endif
185
196
207
215
224void ambient5_set_register ( ambient5_t* ctx, uint8_t reg_addr,
225 uint16_t reg_value );
226
235uint16_t ambient5_get_register ( ambient5_t* ctx, uint8_t reg );
236
246
258
270
282
293 float low_light_level_threshold );
294
305 float high_light_level_threshold );
306
315
326
327#ifdef __cplusplus
328}
329#endif
330#endif // _AMBIENT5_H_
331 // End public_function group
334
335// ------------------------------------------------------------------------- END
#define AMBIENT5_RETVAL
Definition: ambient5.h:69
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:157
uint32_t i2c_speed
Definition: ambient5.h:169
pin_name_t scl
Definition: ambient5.h:160
pin_name_t int_pin
Definition: ambient5.h:165
pin_name_t sda
Definition: ambient5.h:161
uint8_t i2c_address
Definition: ambient5.h:170
Click ctx object definition.
Definition: ambient5.h:137
digital_in_t int_pin
Definition: ambient5.h:141
i2c_master_t i2c
Definition: ambient5.h:145
uint8_t slave_address
Definition: ambient5.h:149