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 "drv_digital_in.h"
39 #include "drv_i2c_master.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define PROXIMITY2_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
53  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
54  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
55 
61 #define PROXIMITY2_RETVAL uint8_t
62 
63 #define PROXIMITY2_OK 0x00
64 #define PROXIMITY2_INIT_ERROR 0xFF
65 
71 #define PROXIMITY2_I2C_SLAVE_ADDR 0x4A
72 
78 #define PROXIMITY2_REG_INTER_STAT 0x00
79 #define PROXIMITY2_REG_MAIN_CONFIG 0x01
80 #define PROXIMITY2_REG_RECEIVE_CONFIG 0x02
81 #define PROXIMITY2_REG_TRANSMIT_CONFIG 0x03
82 #define PROXIMITY2_REG_ALS_HI_BY 0x04
83 #define PROXIMITY2_REG_ALS_LO_BY 0x05
84 #define PROXIMITY2_REG_PROX 0x16
85 #define PROXIMITY2_REG_ALS_UPTRSH_H 0x06
86 #define PROXIMITY2_REG_ALS_UPTRSH_L 0x07
87 #define PROXIMITY2_REG_ALS_LOTRSH_H 0x08
88 #define PROXIMITY2_REG_ALS_LOTRSH_L 0x09
89 #define PROXIMITY2_REG_TRSH_PERS_TIM 0x0A
90 #define PROXIMITY2_REG_PROX_TRSH_IND 0x0B
91 #define PROXIMITY2_REG_PROX_TRSH 0x0C
92 #define PROXIMITY2_REG_GREEN_GAIN 0x0F
93 #define PROXIMITY2_REG_IR_GAIN 0x10
94 
100 #define PROXIMITY2_RECE_CONFIG_ALSPGA_0_03125 0x00
101 #define PROXIMITY2_RECE_CONFIG_ALSPGA_0_125 0x01
102 #define PROXIMITY2_RECE_CONFIG_ALSPGA_0_5 0x02
103 #define PROXIMITY2_RECE_CONFIG_ALSPGA_4 0x03
104 #define PROXIMITY2_RECE_CONFIG_DEFAULT 0xF1
105 #define PROXIMITY2_MAIN_CONFIG_STDWN 0x00
106 #define PROXIMITY2_MAIN_CONFIG_DEFAULT 0x13
107 #define PROXIMITY2_MAIN_CONFIG_ALS_G_IR 0x04
108 #define PROXIMITY2_MAIN_CONFIG_ALS_G 0x08
109 #define PROXIMITY2_MAIN_CONFIG_ALS_IR 0x0C
110 #define PROXIMITY2_MAIN_CONFIG_ALS_PROX 0x10
111 #define PROXIMITY2_MAIN_CONFIG_PROX_ONLY 0x14
112 #define PROXIMITY2_RECE_CONFIG_ALSTIM_14 0x00
113 #define PROXIMITY2_RECE_CONFIG_ALSTIM_12 0x01
114 #define PROXIMITY2_RECE_CONFIG_ALSTIM_10 0x02
115 #define PROXIMITY2_RECE_CONFIG_ALSTIM_8 0x03
116 
122 #define PROXIMITY2_LED_DRV_DISABLE 0x00
123 #define PROXIMITY2_LED_DRV_CURRENT_10_MA 0x01
124 #define PROXIMITY2_LED_DRV_CURRENT_20_MA 0x02
125 #define PROXIMITY2_LED_DRV_CURRENT_30_MA 0x03
126 #define PROXIMITY2_LED_DRV_CURRENT_40_MA 0x04
127 #define PROXIMITY2_LED_DRV_CURRENT_50_MA 0x05
128 #define PROXIMITY2_LED_DRV_CURRENT_60_MA 0x06
129 #define PROXIMITY2_LED_DRV_CURRENT_70_MA 0x07
130 #define PROXIMITY2_LED_DRV_CURRENT_80_MA 0x0C
131 #define PROXIMITY2_LED_DRV_CURRENT_90_MA 0x0D
132 #define PROXIMITY2_LED_DRV_CURRENT_100_MA 0x0E
133 #define PROXIMITY2_LED_DRV_CURRENT_110_MA 0x0F
134 
140 #define PROXIMITY2_INTERRUPT_TRIGGERS_1 0x00
141 #define PROXIMITY2_INTERRUPT_TRIGGERS_2 0x01
142 #define PROXIMITY2_INTERRUPT_TRIGGERS_4 0x02
143 #define PROXIMITY2_INTERRUPT_TRIGGERS_16 0x03
144 
150 #define PROXIMITY2_PROXI_AVG_VAL 0x7F
151 #define PROXIMITY2_PROXI_MAX_VAL 0xFF
152 #define PROXIMITY2_PROXI_SENSITIVITY 5
153  // End group macro
156 // --------------------------------------------------------------- PUBLIC TYPES
165 typedef struct
166 {
167  // Input pins
168 
169  digital_in_t int_pin;
170 
171  // Modules
172 
173  i2c_master_t i2c;
174 
175  // ctx variable
176 
177  uint8_t slave_address;
178 
179 } proximity2_t;
180 
184 typedef struct
185 {
186  // Communication gpio pins
187 
188  pin_name_t scl;
189  pin_name_t sda;
190 
191  // Additional gpio pins
192 
193  pin_name_t int_pin;
194 
195  // static variable
196 
197  uint32_t i2c_speed;
198  uint8_t i2c_address;
199 
201  // End types group
203 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
204 
210 #ifdef __cplusplus
211 extern "C"{
212 #endif
213 
223 
233 
260 
271 void proximity2_generic_write ( proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
272 
283 void proximity2_generic_read ( proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
284 
296 
310 
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 #endif // _PROXIMITY2_H_
326  // End public_function group
329 
330 // ------------------------------------------------------------------------- END
proximity2_cfg_t
Click configuration structure definition.
Definition: proximity2.h:185
proximity2_cfg_t::scl
pin_name_t scl
Definition: proximity2.h:188
proximity2_cfg_setup
void proximity2_cfg_setup(proximity2_cfg_t *cfg)
Config Object Initialization function.
proximity2_t
Click ctx object definition.
Definition: proximity2.h:166
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:198
proximity2_t::int_pin
digital_in_t int_pin
Definition: proximity2.h:169
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:193
proximity2_cfg_t::sda
pin_name_t sda
Definition: proximity2.h:189
proximity2_default_cfg
void proximity2_default_cfg(proximity2_t *ctx)
Click Default Configuration function.
PROXIMITY2_RETVAL
#define PROXIMITY2_RETVAL
Definition: proximity2.h:61
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:173
proximity2_t::slave_address
uint8_t slave_address
Definition: proximity2.h:177
proximity2_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity2.h:197
proximity2_generic_write
void proximity2_generic_write(proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.