ambient6  2.0.0.0
ambient6.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef AMBIENT6_H
36 #define AMBIENT6_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define AMBIENT6_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
54 
60 #define AMBIENT6_RETVAL uint8_t
61 
62 #define AMBIENT6_OK 0x00
63 #define AMBIENT6_INIT_ERROR 0xFF
64 
70 #define AMBIENT6_CMD_CONFIGURATION 0x00
71 #define AMBIENT6_CMD_THRESHOLD_HIGH_SETTINGS 0x01
72 #define AMBIENT6_CMD_THRESHOLD_LOW_SETTINGS 0x02
73 #define AMBIENT6_CMD_MODE_SETTINGS 0x03
74 #define AMBIENT6_CMD_ALS_DATA 0x04
75 #define AMBIENT6_CMD_WHITE_DATA 0x05
76 #define AMBIENT6_CMD_ALS_THRESHOLD_INTERRUPT 0x06
77 
83 #define AMBIENT6_CFG_ALS_SENSITIVITY_X1 0x0000 << 11
84 #define AMBIENT6_CFG_ALS_SENSITIVITY_X2 0x0001 << 11
85 #define AMBIENT6_CFG_ALS_SENSITIVITY_X1_8 0x0002 << 11
86 #define AMBIENT6_CFG_ALS_SENSITIVITY_X1_4 0x0003 << 11
87 #define AMBIENT6_CFG_ALS_TIME_SETTING_25MS 0x000C << 6
88 #define AMBIENT6_CFG_ALS_TIME_SETTING_50MS 0x0008 << 6
89 #define AMBIENT6_CFG_ALS_TIME_SETTING_100MS 0x0000
90 #define AMBIENT6_CFG_ALS_TIME_SETTING_200MS 0x0001 << 6
91 #define AMBIENT6_CFG_ALS_TIME_SETTING_400MS 0x0002 << 6
92 #define AMBIENT6_CFG_ALS_TIME_SETTING_800MS 0x0003 << 6
93 #define AMBIENT6_CFG_PERSISTENCE_NUMBER_1 0x0000 << 4
94 #define AMBIENT6_CFG_PERSISTENCE_NUMBER_2 0x0001 << 4
95 #define AMBIENT6_CFG_PERSISTENCE_NUMBER_4 0x0002 << 4
96 #define AMBIENT6_CFG_PERSISTENCE_NUMBER_8 0x0003 << 4
97 #define AMBIENT6_CFG_ALS_INT_DISABLE 0x0000
98 #define AMBIENT6_CFG_ALS_INT_ENABLE 0x0001 << 1
99 #define AMBIENT6_CFG_ALS_POWER_ON 0x0000
100 #define AMBIENT6_CFG_ALS_SHUT_DOWN 0x0001
101 
107 #define AMBIENT6_POWER_MODE_1 0x0000
108 #define AMBIENT6_POWER_MODE_2 0x0002
109 #define AMBIENT6_POWER_MODE_3 0x0004
110 #define AMBIENT6_POWER_MODE_4 0x0006
111 #define AMBIENT6_POWER_MODE_ENABLE 0x0001
112 #define AMBIENT6_POWER_MODE_DISABLE 0x0000
113 
119 #define AMBIENT6_DEVICE_SLAVE_ADDRESS 0x10
120  // End group macro
123 // --------------------------------------------------------------- PUBLIC TYPES
132 typedef struct
133 {
134  // Modules
135 
136  i2c_master_t i2c;
137 
138  // ctx variable
139 
140  hal_i2c_address_t slave_address;
141 
142  float c_gain;
143  float c_time;
144 
145 } ambient6_t;
146 
150 typedef struct
151 {
152  // Communication gpio pins
153 
154  pin_name_t scl;
155  pin_name_t sda;
156 
157  // static variable
158 
159  hal_i2c_speed_t i2c_speed;
160  hal_i2c_address_t i2c_address;
161 
163  // End types group
165 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
166 
172 #ifdef __cplusplus
173 extern "C"{
174 #endif
175 
184 void ambient6_cfg_setup ( ambient6_cfg_t *cfg );
185 
194 
214 void ambient6_default_cfg ( ambient6_t *ctx );
215 
226 void ambient6_generic_write ( ambient6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227 
239 void ambient6_generic_read ( ambient6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
240 
250 uint16_t ambient6_get_ambient_data ( ambient6_t *ctx );
251 
268 void ambient6_settings ( ambient6_t *ctx, uint16_t config_data);
269 
279 
280 
281 #ifdef __cplusplus
282 }
283 #endif
284 #endif // _AMBIENT6_H_
285  // End public_function group
288 
289 // ------------------------------------------------------------------------- END
ambient6_cfg_t::sda
pin_name_t sda
Definition: ambient6.h:155
ambient6_cfg_t::scl
pin_name_t scl
Definition: ambient6.h:154
ambient6_t::c_gain
float c_gain
Definition: ambient6.h:142
ambient6_generic_write
void ambient6_generic_write(ambient6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
ambient6_cfg_t
Click configuration structure definition.
Definition: ambient6.h:150
AMBIENT6_RETVAL
#define AMBIENT6_RETVAL
Definition: ambient6.h:60
ambient6_init
AMBIENT6_RETVAL ambient6_init(ambient6_t *ctx, ambient6_cfg_t *cfg)
Initialization function.
ambient6_cfg_t::i2c_address
hal_i2c_address_t i2c_address
Definition: ambient6.h:160
ambient6_t::c_time
float c_time
Definition: ambient6.h:143
ambient6_cfg_setup
void ambient6_cfg_setup(ambient6_cfg_t *cfg)
Config Object Initialization function.
ambient6_t
Click ctx object definition.
Definition: ambient6.h:132
ambient6_get_ambient_data
uint16_t ambient6_get_ambient_data(ambient6_t *ctx)
Functions for read 16bit Ambient Data (ALS)
ambient6_get_ambient_light
float ambient6_get_ambient_light(ambient6_t *ctx)
Functions for get Ambient Light Data.
ambient6_settings
void ambient6_settings(ambient6_t *ctx, uint16_t config_data)
Functions for configuration device for measurement.
ambient6_t::i2c
i2c_master_t i2c
Definition: ambient6.h:136
ambient6_default_cfg
void ambient6_default_cfg(ambient6_t *ctx)
Click Default Configuration function.
ambient6_t::slave_address
hal_i2c_address_t slave_address
Definition: ambient6.h:140
ambient6_generic_read
void ambient6_generic_read(ambient6_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
ambient6_cfg_t::i2c_speed
hal_i2c_speed_t i2c_speed
Definition: ambient6.h:159