proximity 2.0.0.0
proximity.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 PROXIMITY_H
36#define PROXIMITY_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// -------------------------------------------------------------- PUBLIC MACROS
66#define PROXIMITY_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define PROXIMITY_RETVAL uint8_t
77
78#define PROXIMITY_OK 0x00
79#define PROXIMITY_INIT_ERROR 0xFF
86#define PROXIMITY_SLAVE_ADDR 0x13
87#define PROXIMITY_REGISTER_COMMAND 0x80
88#define PROXIMITY_REGISTER_ID 0x81
89#define PROXIMITY_REGISTER_PROX_RATE 0x82
90#define PROXIMITY_REGISTER_PROX_CURRENT 0x83
91#define PROXIMITY_REGISTER_AMBI_PARAMETER 0x84
92#define PROXIMITY_REGISTER_AMBI_VALUE 0x85
93#define PROXIMITY_REGISTER_PROX_VALUE 0x87
94#define PROXIMITY_REGISTER_INTERRUPT_CONTROL 0x89
95#define PROXIMITY_REGISTER_INTERRUPT_LOW_THRES 0x8a
96#define PROXIMITY_REGISTER_INTERRUPT_HIGH_THRES 0x8c
97#define PROXIMITY_REGISTER_INTERRUPT_STATUS 0x8e
98#define PROXIMITY_REGISTER_PROX_TIMING 0xf9
99#define PROXIMITY_REGISTER_AMBI_IR_LIGHT_LEVEL 0x90
106#define PROXIMITY_COMMAND_ALL_DISABLE 0x00
107#define PROXIMITY_COMMAND_SELFTIMED_MODE_ENABLE 0x01
108#define PROXIMITY_COMMAND_PROX_ENABLE 0x02
109#define PROXIMITY_COMMAND_AMBI_ENABLE 0x04
110#define PROXIMITY_COMMAND_PROX_ON_DEMAND 0x08
111#define PROXIMITY_COMMAND_AMBI_ON_DEMAND 0x10
112#define PROXIMITY_COMMAND_MASK_PROX_DATA_READY 0x20
113#define PROXIMITY_COMMAND_MASK_AMBI_DATA_READY 0x40
114#define PROXIMITY_COMMAND_MASK_LOCK 0x80
121#define PROXIMITY_PRODUCT_MASK_REVISION_ID 0x0f
122#define PROXIMITY_PRODUCT_MASK_PRODUCT_ID 0xf0
129#define PROXIMITY_MEASUREMENT_RATE_2 0x00
130#define PROXIMITY_MEASUREMENT_RATE_4 0x01
131#define PROXIMITY_MEASUREMENT_RATE_8 0x02
132#define PROXIMITY_MEASUREMENT_RATE_16 0x03
133#define PROXIMITY_MEASUREMENT_RATE_31 0x04
134#define PROXIMITY_MEASUREMENT_RATE_62 0x05
135#define PROXIMITY_MEASUREMENT_RATE_125 0x06
136#define PROXIMITY_MEASUREMENT_RATE_250 0x07
137#define PROXIMITY_MASK_MEASUREMENT_RATE 0x07
144#define PROXIMITY_MASK_LED_CURRENT 0x3f
145#define PROXIMITY_MASK_FUSE_PROG_ID 0xc0
152#define PROXIMITY_AMBI_PARA_AVERAGE_1 0x00
153#define PROXIMITY_AMBI_PARA_AVERAGE_2 0x01
154#define PROXIMITY_AMBI_PARA_AVERAGE_4 0x02
155#define PROXIMITY_AMBI_PARA_AVERAGE_8 0x03
156#define PROXIMITY_AMBI_PARA_AVERAGE_16 0x04
157#define PROXIMITY_AMBI_PARA_AVERAGE_32 0x05
158#define PROXIMITY_AMBI_PARA_AVERAGE_64 0x06
159#define PROXIMITY_AMBI_PARA_AVERAGE_128 0x07
160#define PROXIMITY_AMBI_MASK_PARA_AVERAGE 0x07
161#define PROXIMITY_AMBI_PARA_AUTO_OFFSET_ENABLE 0x08
162#define PROXIMITY_AMBI_MASK_PARA_AUTO_OFFSET 0x08
163#define PROXIMITY_AMBI_PARA_MEAS_RATE_1 0x00
164#define PROXIMITY_AMBI_PARA_MEAS_RATE_2 0x10
165#define PROXIMITY_AMBI_PARA_MEAS_RATE_3 0x20
166#define PROXIMITY_AMBI_PARA_MEAS_RATE_4 0x30
167#define PROXIMITY_AMBI_PARA_MEAS_RATE_5 0x40
168#define PROXIMITY_AMBI_PARA_MEAS_RATE_6 0x50
169#define PROXIMITY_AMBI_PARA_MEAS_RATE_8 0x60
170#define PROXIMITY_AMBI_PARA_MEAS_RATE_10 0x70
171#define PROXIMITY_AMBI_MASK_PARA_MEAS_RATE 0x70
172#define PROXIMITY_AMBI_PARA_CONT_CONV_ENABLE 0x80
173#define PROXIMITY_AMBI_MASK_PARA_CONT_CONV 0x80
180#define PROXIMITY_INTERRUPT_THRES_SEL_PROX 0x00
181#define PROXIMITY_INTERRUPT_THRES_SEL_ALS 0x01
182#define PROXIMITY_INTERRUPT_THRES_ENABLE 0x02
183#define PROXIMITY_INTERRUPT_ALS_READY_ENABLE 0x04
184#define PROXIMITY_INTERRUPT_PROX_READY_ENABLE 0x08
185#define PROXIMITY_INTERRUPT_COUNT_EXCEED_1 0x00
186#define PROXIMITY_INTERRUPT_COUNT_EXCEED_2 0x20
187#define PROXIMITY_INTERRUPT_COUNT_EXCEED_4 0x40
188#define PROXIMITY_INTERRUPT_COUNT_EXCEED_8 0x60
189#define PROXIMITY_INTERRUPT_COUNT_EXCEED_16 0x80
190#define PROXIMITY_INTERRUPT_COUNT_EXCEED_32 0xa0
191#define PROXIMITY_INTERRUPT_COUNT_EXCEED_64 0xc0
192#define PROXIMITY_INTERRUPT_COUNT_EXCEED_128 0xe0
193#define PROXIMITY_INTERRUPT_MASK_COUNT_EXCEED 0xe0
194#define PROXIMITY_INTERRUPT_STATUS_THRES_HI 0x01
195#define PROXIMITY_INTERRUPT_STATUS_THRES_LO 0x02
196#define PROXIMITY_INTERRUPT_STATUS_ALS_READY 0x04
197#define PROXIMITY_INTERRUPT_STATUS_PROX_READY 0x08
198#define PROXIMITY_INTERRUPT_MASK_STATUS_THRES_HI 0x01
199#define PROXIMITY_INTERRUPT_MASK_THRES_LO 0x02
200#define PROXIMITY_INTERRUPT_MASK_ALS_READY 0x04
201#define PROXIMITY_INTERRUPT_MASK_PROX_READY 0x08
203 // End group macro
204// --------------------------------------------------------------- PUBLIC TYPES
213typedef struct
214{
215
216 // Input pins
217
218 digital_in_t int_pin;
219
220 // Modules
221
222 i2c_master_t i2c;
223
224 // ctx variable
225
227
229
233typedef struct
234{
235 // Communication gpio pins
236
237 pin_name_t scl;
238 pin_name_t sda;
239
240 // Additional gpio pins
241
242 pin_name_t int_pin;
243
244 // static variable
245
246 uint32_t i2c_speed;
247 uint8_t i2c_address;
248
250
251 // End types group
252
258#ifdef __cplusplus
259extern "C"{
260#endif
261
271
281
289void proximity_write_byte ( proximity_t *ctx, uint8_t w_addr, uint8_t w_data);
290
299uint8_t proximity_read_byte ( proximity_t *ctx, uint8_t r_addr);
300
309void proximity_read_data ( proximity_t *ctx, uint8_t r_addr, uint8_t* rcv_data, uint8_t n_len);
310
319void proximity_write_data ( proximity_t *ctx, uint8_t w_addr, uint8_t* wr_data, uint8_t n_len);
320
326
332
340
348
349
350#ifdef __cplusplus
351}
352#endif
353#endif // _PROXIMITY_H_
354
355 // End public_function group
357
358// ------------------------------------------------------------------------- END
#define PROXIMITY_RETVAL
Definition proximity.h:76
void proximity_cfg_setup(proximity_cfg_t *cfg)
Config Object Initialization function.
void proximity_read_data(proximity_t *ctx, uint8_t r_addr, uint8_t *rcv_data, uint8_t n_len)
Functions for read data from register.
uint16_t proximity_read_ambient_light(proximity_t *ctx)
Functions for reads Ambient light.
void proximity_write_byte(proximity_t *ctx, uint8_t w_addr, uint8_t w_data)
Functions for write one byte in register.
void proximity_set_default_mode(proximity_t *ctx)
Functions for sets default mode.
void proximity_set_upper_threshold(proximity_t *ctx)
Functions for sets upper threshold.
void proximity_write_data(proximity_t *ctx, uint8_t w_addr, uint8_t *wr_data, uint8_t n_len)
Functions for write data.
PROXIMITY_RETVAL proximity_init(proximity_t *ctx, proximity_cfg_t *cfg)
Initialization function.
uint16_t proximity_read_prox_data(proximity_t *ctx)
Functions for reads Proximity data.
uint8_t proximity_read_byte(proximity_t *ctx, uint8_t r_addr)
Functions for read byte from register.
Click configuration structure definition.
Definition proximity.h:234
uint32_t i2c_speed
Definition proximity.h:246
pin_name_t scl
Definition proximity.h:237
pin_name_t int_pin
Definition proximity.h:242
pin_name_t sda
Definition proximity.h:238
uint8_t i2c_address
Definition proximity.h:247
Click ctx object definition.
Definition proximity.h:214
digital_in_t int_pin
Definition proximity.h:218
i2c_master_t i2c
Definition proximity.h:222
uint8_t slave_address
Definition proximity.h:226