proximity2  2.0.0.0
proximity2.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 PROXIMITY2_H
36 #define PROXIMITY2_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_in.h"
49 #include "drv_i2c_master.h"
50 
51 // -------------------------------------------------------------- PUBLIC MACROS
61 #define PROXIMITY2_MAP_MIKROBUS( cfg, mikrobus ) \
62  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
63  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
64  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
65 
71 #define PROXIMITY2_RETVAL uint8_t
72 
73 #define PROXIMITY2_OK 0x00
74 #define PROXIMITY2_INIT_ERROR 0xFF
75 
81 #define PROXIMITY2_I2C_SLAVE_ADDR 0x4A
82 
88 #define PROXIMITY2_REG_INTER_STAT 0x00
89 #define PROXIMITY2_REG_MAIN_CONFIG 0x01
90 #define PROXIMITY2_REG_RECEIVE_CONFIG 0x02
91 #define PROXIMITY2_REG_TRANSMIT_CONFIG 0x03
92 #define PROXIMITY2_REG_ALS_HI_BY 0x04
93 #define PROXIMITY2_REG_ALS_LO_BY 0x05
94 #define PROXIMITY2_REG_PROX 0x16
95 #define PROXIMITY2_REG_ALS_UPTRSH_H 0x06
96 #define PROXIMITY2_REG_ALS_UPTRSH_L 0x07
97 #define PROXIMITY2_REG_ALS_LOTRSH_H 0x08
98 #define PROXIMITY2_REG_ALS_LOTRSH_L 0x09
99 #define PROXIMITY2_REG_TRSH_PERS_TIM 0x0A
100 #define PROXIMITY2_REG_PROX_TRSH_IND 0x0B
101 #define PROXIMITY2_REG_PROX_TRSH 0x0C
102 #define PROXIMITY2_REG_GREEN_GAIN 0x0F
103 #define PROXIMITY2_REG_IR_GAIN 0x10
104 
110 #define PROXIMITY2_RECE_CONFIG_ALSPGA_0_03125 0x00
111 #define PROXIMITY2_RECE_CONFIG_ALSPGA_0_125 0x01
112 #define PROXIMITY2_RECE_CONFIG_ALSPGA_0_5 0x02
113 #define PROXIMITY2_RECE_CONFIG_ALSPGA_4 0x03
114 #define PROXIMITY2_RECE_CONFIG_DEFAULT 0xF1
115 #define PROXIMITY2_MAIN_CONFIG_STDWN 0x00
116 #define PROXIMITY2_MAIN_CONFIG_DEFAULT 0x13
117 #define PROXIMITY2_MAIN_CONFIG_ALS_G_IR 0x04
118 #define PROXIMITY2_MAIN_CONFIG_ALS_G 0x08
119 #define PROXIMITY2_MAIN_CONFIG_ALS_IR 0x0C
120 #define PROXIMITY2_MAIN_CONFIG_ALS_PROX 0x10
121 #define PROXIMITY2_MAIN_CONFIG_PROX_ONLY 0x14
122 #define PROXIMITY2_RECE_CONFIG_ALSTIM_14 0x00
123 #define PROXIMITY2_RECE_CONFIG_ALSTIM_12 0x01
124 #define PROXIMITY2_RECE_CONFIG_ALSTIM_10 0x02
125 #define PROXIMITY2_RECE_CONFIG_ALSTIM_8 0x03
126 
132 #define PROXIMITY2_LED_DRV_DISABLE 0x00
133 #define PROXIMITY2_LED_DRV_CURRENT_10_MA 0x01
134 #define PROXIMITY2_LED_DRV_CURRENT_20_MA 0x02
135 #define PROXIMITY2_LED_DRV_CURRENT_30_MA 0x03
136 #define PROXIMITY2_LED_DRV_CURRENT_40_MA 0x04
137 #define PROXIMITY2_LED_DRV_CURRENT_50_MA 0x05
138 #define PROXIMITY2_LED_DRV_CURRENT_60_MA 0x06
139 #define PROXIMITY2_LED_DRV_CURRENT_70_MA 0x07
140 #define PROXIMITY2_LED_DRV_CURRENT_80_MA 0x0C
141 #define PROXIMITY2_LED_DRV_CURRENT_90_MA 0x0D
142 #define PROXIMITY2_LED_DRV_CURRENT_100_MA 0x0E
143 #define PROXIMITY2_LED_DRV_CURRENT_110_MA 0x0F
144 
150 #define PROXIMITY2_INTERRUPT_TRIGGERS_1 0x00
151 #define PROXIMITY2_INTERRUPT_TRIGGERS_2 0x01
152 #define PROXIMITY2_INTERRUPT_TRIGGERS_4 0x02
153 #define PROXIMITY2_INTERRUPT_TRIGGERS_16 0x03
154 
160 #define PROXIMITY2_PROXI_AVG_VAL 0x7F
161 #define PROXIMITY2_PROXI_MAX_VAL 0xFF
162 #define PROXIMITY2_PROXI_SENSITIVITY 5
163  // End group macro
166 // --------------------------------------------------------------- PUBLIC TYPES
175 typedef struct
176 {
177  // Input pins
178 
179  digital_in_t int_pin;
180 
181  // Modules
182 
183  i2c_master_t i2c;
184 
185  // ctx variable
186 
187  uint8_t slave_address;
188 
189 } proximity2_t;
190 
194 typedef struct
195 {
196  // Communication gpio pins
197 
198  pin_name_t scl;
199  pin_name_t sda;
200 
201  // Additional gpio pins
202 
203  pin_name_t int_pin;
204 
205  // static variable
206 
207  uint32_t i2c_speed;
208  uint8_t i2c_address;
209 
211  // End types group
213 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
214 
220 #ifdef __cplusplus
221 extern "C"{
222 #endif
223 
233 
243 
270 
281 void proximity2_generic_write ( proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
282 
293 void proximity2_generic_read ( proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
294 
306 
320 
331 
332 #ifdef __cplusplus
333 }
334 #endif
335 #endif // _PROXIMITY2_H_
336  // End public_function group
339 
340 // ------------------------------------------------------------------------- END
proximity2_cfg_t
Click configuration structure definition.
Definition: proximity2.h:195
proximity2_cfg_t::scl
pin_name_t scl
Definition: proximity2.h:198
proximity2_cfg_setup
void proximity2_cfg_setup(proximity2_cfg_t *cfg)
Config Object Initialization function.
proximity2_t
Click ctx object definition.
Definition: proximity2.h:176
proximity2_init
PROXIMITY2_RETVAL proximity2_init(proximity2_t *ctx, proximity2_cfg_t *cfg)
Initialization function.
proximity2_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity2.h:208
proximity2_t::int_pin
digital_in_t int_pin
Definition: proximity2.h:179
proximity2_read_als
uint16_t proximity2_read_als(proximity2_t *ctx)
Read ALS Data Registers function.
proximity2_generic_read
void proximity2_generic_read(proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
proximity2_read_prox
uint8_t proximity2_read_prox(proximity2_t *ctx)
Read PROX Data Register function.
proximity2_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity2.h:203
proximity2_cfg_t::sda
pin_name_t sda
Definition: proximity2.h:199
proximity2_default_cfg
void proximity2_default_cfg(proximity2_t *ctx)
Click Default Configuration function.
PROXIMITY2_RETVAL
#define PROXIMITY2_RETVAL
Definition: proximity2.h:71
proximity2_get_int_pin_status
uint8_t proximity2_get_int_pin_status(proximity2_t *ctx)
Get int pin status.
proximity2_t::i2c
i2c_master_t i2c
Definition: proximity2.h:183
proximity2_t::slave_address
uint8_t slave_address
Definition: proximity2.h:187
proximity2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity2.h:207
proximity2_generic_write
void proximity2_generic_write(proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.