ambient6 2.0.0.0
ambient6.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 AMBIENT6_H
36#define AMBIENT6_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_i2c_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define AMBIENT6_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
74#define AMBIENT6_RETVAL uint8_t
75
76#define AMBIENT6_OK 0x00
77#define AMBIENT6_INIT_ERROR 0xFF
84#define AMBIENT6_CMD_CONFIGURATION 0x00
85#define AMBIENT6_CMD_THRESHOLD_HIGH_SETTINGS 0x01
86#define AMBIENT6_CMD_THRESHOLD_LOW_SETTINGS 0x02
87#define AMBIENT6_CMD_MODE_SETTINGS 0x03
88#define AMBIENT6_CMD_ALS_DATA 0x04
89#define AMBIENT6_CMD_WHITE_DATA 0x05
90#define AMBIENT6_CMD_ALS_THRESHOLD_INTERRUPT 0x06
97#define AMBIENT6_CFG_ALS_SENSITIVITY_X1 0x0000 << 11
98#define AMBIENT6_CFG_ALS_SENSITIVITY_X2 0x0001 << 11
99#define AMBIENT6_CFG_ALS_SENSITIVITY_X1_8 0x0002 << 11
100#define AMBIENT6_CFG_ALS_SENSITIVITY_X1_4 0x0003 << 11
101#define AMBIENT6_CFG_ALS_TIME_SETTING_25MS 0x000C << 6
102#define AMBIENT6_CFG_ALS_TIME_SETTING_50MS 0x0008 << 6
103#define AMBIENT6_CFG_ALS_TIME_SETTING_100MS 0x0000
104#define AMBIENT6_CFG_ALS_TIME_SETTING_200MS 0x0001 << 6
105#define AMBIENT6_CFG_ALS_TIME_SETTING_400MS 0x0002 << 6
106#define AMBIENT6_CFG_ALS_TIME_SETTING_800MS 0x0003 << 6
107#define AMBIENT6_CFG_PERSISTENCE_NUMBER_1 0x0000 << 4
108#define AMBIENT6_CFG_PERSISTENCE_NUMBER_2 0x0001 << 4
109#define AMBIENT6_CFG_PERSISTENCE_NUMBER_4 0x0002 << 4
110#define AMBIENT6_CFG_PERSISTENCE_NUMBER_8 0x0003 << 4
111#define AMBIENT6_CFG_ALS_INT_DISABLE 0x0000
112#define AMBIENT6_CFG_ALS_INT_ENABLE 0x0001 << 1
113#define AMBIENT6_CFG_ALS_POWER_ON 0x0000
114#define AMBIENT6_CFG_ALS_SHUT_DOWN 0x0001
121#define AMBIENT6_POWER_MODE_1 0x0000
122#define AMBIENT6_POWER_MODE_2 0x0002
123#define AMBIENT6_POWER_MODE_3 0x0004
124#define AMBIENT6_POWER_MODE_4 0x0006
125#define AMBIENT6_POWER_MODE_ENABLE 0x0001
126#define AMBIENT6_POWER_MODE_DISABLE 0x0000
133#define AMBIENT6_DEVICE_SLAVE_ADDRESS 0x10
136 // End group macro
137// --------------------------------------------------------------- PUBLIC TYPES
146typedef struct
147{
148 // Modules
149
150 i2c_master_t i2c;
151
152 // ctx variable
153
155
156 float c_gain;
157 float c_time;
158
159} ambient6_t;
160
164typedef struct
165{
166 // Communication gpio pins
167
168 pin_name_t scl;
169 pin_name_t sda;
170
171 // static variable
172
173 uint32_t i2c_speed;
174 uint8_t i2c_address;
175
177
178 // End types group
179// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
180
186#ifdef __cplusplus
187extern "C"{
188#endif
189
199
208
229
240void ambient6_generic_write ( ambient6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
241
253void ambient6_generic_read ( ambient6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
254
265
282void ambient6_settings ( ambient6_t *ctx, uint16_t config_data);
283
293
294
295#ifdef __cplusplus
296}
297#endif
298#endif // _AMBIENT6_H_
299
300 // End public_function group
302
303// ------------------------------------------------------------------------- END
#define AMBIENT6_RETVAL
Definition ambient6.h:74
float ambient6_get_ambient_light(ambient6_t *ctx)
Functions for get Ambient Light Data.
void ambient6_generic_read(ambient6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint16_t ambient6_get_ambient_data(ambient6_t *ctx)
Functions for read 16bit Ambient Data (ALS)
void ambient6_generic_write(ambient6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
AMBIENT6_RETVAL ambient6_init(ambient6_t *ctx, ambient6_cfg_t *cfg)
Initialization function.
void ambient6_cfg_setup(ambient6_cfg_t *cfg)
Config Object Initialization function.
void ambient6_settings(ambient6_t *ctx, uint16_t config_data)
Functions for configuration device for measurement.
void ambient6_default_cfg(ambient6_t *ctx)
Click Default Configuration function.
Click configuration structure definition.
Definition ambient6.h:165
uint32_t i2c_speed
Definition ambient6.h:173
pin_name_t scl
Definition ambient6.h:168
pin_name_t sda
Definition ambient6.h:169
uint8_t i2c_address
Definition ambient6.h:174
Click ctx object definition.
Definition ambient6.h:147
float c_gain
Definition ambient6.h:156
float c_time
Definition ambient6.h:157
i2c_master_t i2c
Definition ambient6.h:150
uint8_t slave_address
Definition ambient6.h:154