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
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_in.h"
53#include "drv_i2c_master.h"
54
55// -------------------------------------------------------------- PUBLIC MACROS
65#define PROXIMITY2_MAP_MIKROBUS( cfg, mikrobus ) \
66 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
75#define PROXIMITY2_RETVAL uint8_t
76
77#define PROXIMITY2_OK 0x00
78#define PROXIMITY2_INIT_ERROR 0xFF
85#define PROXIMITY2_I2C_SLAVE_ADDR 0x4A
92#define PROXIMITY2_REG_INTER_STAT 0x00
93#define PROXIMITY2_REG_MAIN_CONFIG 0x01
94#define PROXIMITY2_REG_RECEIVE_CONFIG 0x02
95#define PROXIMITY2_REG_TRANSMIT_CONFIG 0x03
96#define PROXIMITY2_REG_ALS_HI_BY 0x04
97#define PROXIMITY2_REG_ALS_LO_BY 0x05
98#define PROXIMITY2_REG_PROX 0x16
99#define PROXIMITY2_REG_ALS_UPTRSH_H 0x06
100#define PROXIMITY2_REG_ALS_UPTRSH_L 0x07
101#define PROXIMITY2_REG_ALS_LOTRSH_H 0x08
102#define PROXIMITY2_REG_ALS_LOTRSH_L 0x09
103#define PROXIMITY2_REG_TRSH_PERS_TIM 0x0A
104#define PROXIMITY2_REG_PROX_TRSH_IND 0x0B
105#define PROXIMITY2_REG_PROX_TRSH 0x0C
106#define PROXIMITY2_REG_GREEN_GAIN 0x0F
107#define PROXIMITY2_REG_IR_GAIN 0x10
114#define PROXIMITY2_RECE_CONFIG_ALSPGA_0_03125 0x00
115#define PROXIMITY2_RECE_CONFIG_ALSPGA_0_125 0x01
116#define PROXIMITY2_RECE_CONFIG_ALSPGA_0_5 0x02
117#define PROXIMITY2_RECE_CONFIG_ALSPGA_4 0x03
118#define PROXIMITY2_RECE_CONFIG_DEFAULT 0xF1
119#define PROXIMITY2_MAIN_CONFIG_STDWN 0x00
120#define PROXIMITY2_MAIN_CONFIG_DEFAULT 0x13
121#define PROXIMITY2_MAIN_CONFIG_ALS_G_IR 0x04
122#define PROXIMITY2_MAIN_CONFIG_ALS_G 0x08
123#define PROXIMITY2_MAIN_CONFIG_ALS_IR 0x0C
124#define PROXIMITY2_MAIN_CONFIG_ALS_PROX 0x10
125#define PROXIMITY2_MAIN_CONFIG_PROX_ONLY 0x14
126#define PROXIMITY2_RECE_CONFIG_ALSTIM_14 0x00
127#define PROXIMITY2_RECE_CONFIG_ALSTIM_12 0x01
128#define PROXIMITY2_RECE_CONFIG_ALSTIM_10 0x02
129#define PROXIMITY2_RECE_CONFIG_ALSTIM_8 0x03
136#define PROXIMITY2_LED_DRV_DISABLE 0x00
137#define PROXIMITY2_LED_DRV_CURRENT_10_MA 0x01
138#define PROXIMITY2_LED_DRV_CURRENT_20_MA 0x02
139#define PROXIMITY2_LED_DRV_CURRENT_30_MA 0x03
140#define PROXIMITY2_LED_DRV_CURRENT_40_MA 0x04
141#define PROXIMITY2_LED_DRV_CURRENT_50_MA 0x05
142#define PROXIMITY2_LED_DRV_CURRENT_60_MA 0x06
143#define PROXIMITY2_LED_DRV_CURRENT_70_MA 0x07
144#define PROXIMITY2_LED_DRV_CURRENT_80_MA 0x0C
145#define PROXIMITY2_LED_DRV_CURRENT_90_MA 0x0D
146#define PROXIMITY2_LED_DRV_CURRENT_100_MA 0x0E
147#define PROXIMITY2_LED_DRV_CURRENT_110_MA 0x0F
154#define PROXIMITY2_INTERRUPT_TRIGGERS_1 0x00
155#define PROXIMITY2_INTERRUPT_TRIGGERS_2 0x01
156#define PROXIMITY2_INTERRUPT_TRIGGERS_4 0x02
157#define PROXIMITY2_INTERRUPT_TRIGGERS_16 0x03
164#define PROXIMITY2_PROXI_AVG_VAL 0x7F
165#define PROXIMITY2_PROXI_MAX_VAL 0xFF
166#define PROXIMITY2_PROXI_SENSITIVITY 5
169 // End group macro
170// --------------------------------------------------------------- PUBLIC TYPES
179typedef struct
180{
181 // Input pins
182
183 digital_in_t int_pin;
184
185 // Modules
186
187 i2c_master_t i2c;
188
189 // ctx variable
190
192
194
198typedef struct
199{
200 // Communication gpio pins
201
202 pin_name_t scl;
203 pin_name_t sda;
204
205 // Additional gpio pins
206
207 pin_name_t int_pin;
208
209 // static variable
210
211 uint32_t i2c_speed;
212 uint8_t i2c_address;
213
215
216 // End types group
217// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
218
224#ifdef __cplusplus
225extern "C"{
226#endif
227
237
247
274
285void proximity2_generic_write ( proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
286
297void proximity2_generic_read ( proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
298
310
324
335
336#ifdef __cplusplus
337}
338#endif
339#endif // _PROXIMITY2_H_
340
341 // End public_function group
343
344// ------------------------------------------------------------------------- END
#define PROXIMITY2_RETVAL
Definition proximity2.h:75
void proximity2_generic_read(proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void proximity2_cfg_setup(proximity2_cfg_t *cfg)
Config Object Initialization function.
uint16_t proximity2_read_als(proximity2_t *ctx)
Read ALS Data Registers function.
void proximity2_generic_write(proximity2_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t proximity2_read_prox(proximity2_t *ctx)
Read PROX Data Register function.
uint8_t proximity2_get_int_pin_status(proximity2_t *ctx)
Get int pin status.
void proximity2_default_cfg(proximity2_t *ctx)
Click Default Configuration function.
PROXIMITY2_RETVAL proximity2_init(proximity2_t *ctx, proximity2_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition proximity2.h:199
uint32_t i2c_speed
Definition proximity2.h:211
pin_name_t scl
Definition proximity2.h:202
pin_name_t int_pin
Definition proximity2.h:207
pin_name_t sda
Definition proximity2.h:203
uint8_t i2c_address
Definition proximity2.h:212
Click ctx object definition.
Definition proximity2.h:180
digital_in_t int_pin
Definition proximity2.h:183
i2c_master_t i2c
Definition proximity2.h:187
uint8_t slave_address
Definition proximity2.h:191