ambient11  2.0.0.0
ambient11.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 AMBIENT11_H
36 #define AMBIENT11_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define AMBIENT11_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define AMBIENT11_RETVAL uint8_t
64 
65 #define AMBIENT11_OK 0x00
66 #define AMBIENT11_INIT_ERROR 0xFF
67 
73 #define AMBIENT11_SLAVE_ADDRESS 0x29
74 
80 #define AMBIENT11_ALS_CONF_WR 0x00
81 #define AMBIENT11_TRSHLD_WINDOW_SET_HIGH 0x01
82 #define AMBIENT11_TRSHLD_WINDOW_SET_LOW 0x02
83 #define AMBIENT11_ALS_CONF_RD 0x04
84 #define AMBIENT11_WHITE_VAL 0x05
85 #define AMBIENT11_TRSHLD_TRIG_INT 0x06
86 
92 #define AMBIENT11_ALS_CONF_SENS_LOW 0x1000
93 #define AMBIENT11_ALS_CONF_DG_DOUBLE 0x0800
94 #define AMBIENT11_ALS_CONF_GAIN_DOUBLE_SENS 0x0400
95 #define AMBIENT11_ALS_CONF_IT_25 0x0300
96 #define AMBIENT11_ALS_CONF_IT_50 0x0200
97 #define AMBIENT11_ALS_CONF_IT_100 0x0000
98 #define AMBIENT11_ALS_CONF_IT_200 0x0040
99 #define AMBIENT11_ALS_CONF_IT_400 0x0080
100 #define AMBIENT11_ALS_CONF_IT_800 0x00C0
101 #define AMBIENT11_ALS_CONF_PERS_1 0x0000
102 #define AMBIENT11_ALS_CONF_PERS_2 0x0010
103 #define AMBIENT11_ALS_CONF_PERS_4 0x0020
104 #define AMBIENT11_ALS_CONF_PERS_8 0x0030
105 #define AMBIENT11_ALS_CONF_INT_CHAN 0x0008
106 #define AMBIENT11_ALS_CONF_CHAN_EN 0x0004
107 #define AMBIENT11_ALS_CONF_INT_EN 0x0002
108 #define AMBIENT11_ALS_CONF_SHUT_DOWN 0x0001
109  // End group macro
112 // --------------------------------------------------------------- PUBLIC TYPES
121 typedef struct
122 {
123  // Output pins
124 
125  // Input pins
126 
127  digital_in_t int_pin;
128 
129  // Modules
130 
131  i2c_master_t i2c;
132 
133  // ctx variable
134 
135  hal_i2c_address_t slave_address;
136 
137 } ambient11_t;
138 
142 typedef struct
143 {
144  // Communication gpio pins
145 
146  pin_name_t scl;
147  pin_name_t sda;
148 
149  // Additional gpio pins
150 
151  pin_name_t int_pin;
152 
153  // static variable
154 
155  hal_i2c_speed_t i2c_speed;
156  hal_i2c_address_t i2c_address;
157 
159  // End types group
161 // ------------------------------------------------------------------ CONSTANTS // End constants group
170 // ------------------------------------------------------------------ VARIABLES // End variable group
178 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
179 
185 #ifdef __cplusplus
186 extern "C"{
187 #endif
188 
198 
207 
215 void ambient11_default_cfg ( ambient11_t *ctx );
216 
227 void ambient11_generic_write ( ambient11_t *ctx, uint8_t wr_cmd, uint16_t wr_data );
228 
240 uint16_t ambient11_generic_read ( ambient11_t *ctx, uint8_t reg_addr );
241 
254 float ambient11_calc_illumination ( ambient11_t *ctx, float typical_res );
255 
263 uint8_t ambient11_check_int ( ambient11_t *ctx );
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 #endif // _AMBIENT11_H_
269  // End public_function group
272 
273 // ------------------------------------------------------------------------- END
ambient11_cfg_setup
void ambient11_cfg_setup(ambient11_cfg_t *cfg)
Config Object Initialization function.
ambient11_calc_illumination
float ambient11_calc_illumination(ambient11_t *ctx, float typical_res)
Calculate Illumination function.
ambient11_generic_write
void ambient11_generic_write(ambient11_t *ctx, uint8_t wr_cmd, uint16_t wr_data)
Generic write function.
ambient11_cfg_t
Click configuration structure definition.
Definition: ambient11.h:142
ambient11_cfg_t::scl
pin_name_t scl
Definition: ambient11.h:146
ambient11_t::int_pin
digital_in_t int_pin
Definition: ambient11.h:127
ambient11_t
Click ctx object definition.
Definition: ambient11.h:121
ambient11_default_cfg
void ambient11_default_cfg(ambient11_t *ctx)
Click Default Configuration function.
ambient11_cfg_t::i2c_speed
hal_i2c_speed_t i2c_speed
Definition: ambient11.h:155
ambient11_init
AMBIENT11_RETVAL ambient11_init(ambient11_t *ctx, ambient11_cfg_t *cfg)
Initialization function.
ambient11_check_int
uint8_t ambient11_check_int(ambient11_t *ctx)
Check interrupt function.
ambient11_generic_read
uint16_t ambient11_generic_read(ambient11_t *ctx, uint8_t reg_addr)
Generic read function.
ambient11_cfg_t::sda
pin_name_t sda
Definition: ambient11.h:147
ambient11_t::i2c
i2c_master_t i2c
Definition: ambient11.h:131
ambient11_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient11.h:151
AMBIENT11_RETVAL
#define AMBIENT11_RETVAL
Definition: ambient11.h:63
ambient11_cfg_t::i2c_address
hal_i2c_address_t i2c_address
Definition: ambient11.h:156
ambient11_t::slave_address
hal_i2c_address_t slave_address
Definition: ambient11.h:135