ambient11  2.0.0.0
ambient11.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 AMBIENT11_H
36 #define AMBIENT11_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 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define AMBIENT11_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
69  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
70  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
71 
77 #define AMBIENT11_RETVAL uint8_t
78 
79 #define AMBIENT11_OK 0x00
80 #define AMBIENT11_INIT_ERROR 0xFF
81 
87 #define AMBIENT11_SLAVE_ADDRESS 0x29
88 
94 #define AMBIENT11_ALS_CONF_WR 0x00
95 #define AMBIENT11_TRSHLD_WINDOW_SET_HIGH 0x01
96 #define AMBIENT11_TRSHLD_WINDOW_SET_LOW 0x02
97 #define AMBIENT11_ALS_CONF_RD 0x04
98 #define AMBIENT11_WHITE_VAL 0x05
99 #define AMBIENT11_TRSHLD_TRIG_INT 0x06
100 
106 #define AMBIENT11_ALS_CONF_SENS_LOW 0x1000
107 #define AMBIENT11_ALS_CONF_DG_DOUBLE 0x0800
108 #define AMBIENT11_ALS_CONF_GAIN_DOUBLE_SENS 0x0400
109 #define AMBIENT11_ALS_CONF_IT_25 0x0300
110 #define AMBIENT11_ALS_CONF_IT_50 0x0200
111 #define AMBIENT11_ALS_CONF_IT_100 0x0000
112 #define AMBIENT11_ALS_CONF_IT_200 0x0040
113 #define AMBIENT11_ALS_CONF_IT_400 0x0080
114 #define AMBIENT11_ALS_CONF_IT_800 0x00C0
115 #define AMBIENT11_ALS_CONF_PERS_1 0x0000
116 #define AMBIENT11_ALS_CONF_PERS_2 0x0010
117 #define AMBIENT11_ALS_CONF_PERS_4 0x0020
118 #define AMBIENT11_ALS_CONF_PERS_8 0x0030
119 #define AMBIENT11_ALS_CONF_INT_CHAN 0x0008
120 #define AMBIENT11_ALS_CONF_CHAN_EN 0x0004
121 #define AMBIENT11_ALS_CONF_INT_EN 0x0002
122 #define AMBIENT11_ALS_CONF_SHUT_DOWN 0x0001
123  // End group macro
126 // --------------------------------------------------------------- PUBLIC TYPES
135 typedef struct
136 {
137  // Output pins
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 
149  uint8_t slave_address;
150 
151 } ambient11_t;
152 
156 typedef 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
183 extern "C"{
184 #endif
185 
195 
205 
214 
225 void ambient11_generic_write ( ambient11_t *ctx, uint8_t wr_cmd, uint16_t wr_data );
226 
237 uint16_t ambient11_generic_read ( ambient11_t *ctx, uint8_t reg_addr );
238 
251 float ambient11_calc_illumination ( ambient11_t *ctx, float typical_res );
252 
261 
262 #ifdef __cplusplus
263 }
264 #endif
265 #endif // _AMBIENT11_H_
266  // End public_function group
269 
270 // ------------------------------------------------------------------------- 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:157
ambient11_cfg_t::scl
pin_name_t scl
Definition: ambient11.h:160
ambient11_t::int_pin
digital_in_t int_pin
Definition: ambient11.h:141
ambient11_t
Click ctx object definition.
Definition: ambient11.h:136
ambient11_default_cfg
void ambient11_default_cfg(ambient11_t *ctx)
Click Default Configuration function.
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:161
ambient11_t::i2c
i2c_master_t i2c
Definition: ambient11.h:145
ambient11_t::slave_address
uint8_t slave_address
Definition: ambient11.h:149
ambient11_cfg_t::int_pin
pin_name_t int_pin
Definition: ambient11.h:165
ambient11_cfg_t::i2c_address
uint8_t i2c_address
Definition: ambient11.h:170
AMBIENT11_RETVAL
#define AMBIENT11_RETVAL
Definition: ambient11.h:77
ambient11_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ambient11.h:169