proximity16 2.1.0.0
proximity16.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef PROXIMITY16_H
29#define PROXIMITY16_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
73#define PROXIMITY16_DCI_ZONE_CONFIG 0x5450
74#define PROXIMITY16_DCI_FREQ_HZ 0x5458
75#define PROXIMITY16_DCI_INT_TIME 0x545C
76#define PROXIMITY16_DCI_FW_NB_TARGET 0x5478
77#define PROXIMITY16_DCI_RANGING_MODE 0xAD30
78#define PROXIMITY16_DCI_DSS_CONFIG 0xAD38
79#define PROXIMITY16_DCI_TARGET_ORDER 0xAE64
80#define PROXIMITY16_DCI_SHARPENER 0xAED8
81#define PROXIMITY16_DCI_INTERNAL_CP 0xB39C
82#define PROXIMITY16_DCI_MOTION_DETECTOR_CFG 0xBFAC
83#define PROXIMITY16_DCI_SINGLE_RANGE 0xCD5C
84#define PROXIMITY16_DCI_OUTPUT_CONFIG 0xCD60
85#define PROXIMITY16_DCI_OUTPUT_ENABLES 0xCD68
86#define PROXIMITY16_DCI_OUTPUT_LIST 0xCD78
87#define PROXIMITY16_DCI_PIPE_CONTROL 0xCF78
88
93#define PROXIMITY16_UI_CMD_STATUS 0x2C00
94#define PROXIMITY16_UI_CMD_START 0x2C04
95#define PROXIMITY16_UI_CMD_END 0x2FFF
96
97 // proximity16_reg
98
113#define PROXIMITY16_TEMP_BUFFER_SIZE 1024
114#define PROXIMITY16_NVM_DATA_SIZE 492
115#define PROXIMITY16_OFFSET_BUFFER_SIZE 488
116#define PROXIMITY16_XTALK_BUFFER_SIZE 776
117
122#define PROXIMITY16_RESOLUTION_4X4 16
123#define PROXIMITY16_RESOLUTION_8X8 64
124
129#define PROXIMITY16_RANGING_MODE_CONTINUOUS 1
130#define PROXIMITY16_RANGING_MODE_AUTONOMOUS 3
131
136#define PROXIMITY16_START_BH 0x0000000Dul
137#define PROXIMITY16_METADATA_BH 0x54B400C0ul
138#define PROXIMITY16_COMMONDATA_BH 0x54C00040ul
139#define PROXIMITY16_AMBIENT_RATE_BH 0x54D00104ul
140#define PROXIMITY16_SPAD_COUNT_BH 0x55D00404ul
141#define PROXIMITY16_NB_TARGET_DETECTED_BH 0xCF7C0401ul
142#define PROXIMITY16_SIGNAL_RATE_BH 0xCFBC0404ul
143#define PROXIMITY16_RANGE_SIGMA_MM_BH 0xD2BC0402ul
144#define PROXIMITY16_DISTANCE_BH 0xD33C0402ul
145#define PROXIMITY16_REFLECTANCE_BH 0xD43C0401ul
146#define PROXIMITY16_TARGET_STATUS_BH 0xD47C0401ul
147#define PROXIMITY16_MOTION_DETECT_BH 0xCC5008C0ul
148#define PROXIMITY16_METADATA_IDX 0x54B4
149#define PROXIMITY16_SPAD_COUNT_IDX 0x55D0
150#define PROXIMITY16_AMBIENT_RATE_IDX 0x54D0
151#define PROXIMITY16_NB_TARGET_DETECTED_IDX 0xCF7C
152#define PROXIMITY16_SIGNAL_RATE_IDX 0xCFBC
153#define PROXIMITY16_RANGE_SIGMA_MM_IDX 0xD2BC
154#define PROXIMITY16_DISTANCE_IDX 0xD33C
155#define PROXIMITY16_REFLECTANCE_EST_PC_IDX 0xD43C
156#define PROXIMITY16_TARGET_STATUS_IDX 0xD47C
157#define PROXIMITY16_MOTION_DETEC_IDX 0xCC50
158
163#define PROXIMITY16_DEF_RESOLUTION PROXIMITY16_RESOLUTION_8X8
164#define PROXIMITY16_DEF_RANGING_FREQ_HZ 2
165#define PROXIMITY16_DEF_RANGING_MODE PROXIMITY16_RANGING_MODE_AUTONOMOUS
166#define PROXIMITY16_DEF_INTEGRATION_TIME_MS 20
167
173#define PROXIMITY16_DEVICE_ADDRESS 0x29
174
175 // proximity16_set
176
191#define PROXIMITY16_MAP_MIKROBUS( cfg, mikrobus ) \
192 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
193 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
194 cfg.i2c_rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
195 cfg.lpn = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
196 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
197
198 // proximity16_map
199 // proximity16
200
205typedef struct
206{
207 // Output pins
208 digital_out_t i2c_rst;
209 digital_out_t lpn;
211 // Input pins
212 digital_in_t int_pin;
214 // Modules
215 i2c_master_t i2c;
217 // I2C slave address
225 uint8_t offset_data[ PROXIMITY16_OFFSET_BUFFER_SIZE ];
227 uint8_t temp_buf[ PROXIMITY16_TEMP_BUFFER_SIZE ];
228
230
235typedef struct
236{
237 pin_name_t scl;
238 pin_name_t sda;
240 pin_name_t i2c_rst;
241 pin_name_t lpn;
242 pin_name_t int_pin;
244 uint32_t i2c_speed;
245 uint8_t i2c_address;
248
259
264typedef struct
265{
268
270 uint8_t nb_target_detected[ PROXIMITY16_RESOLUTION_8X8 ];
271
273 int16_t distance_mm[ PROXIMITY16_RESOLUTION_8X8 ];
274
276 uint8_t target_status[ PROXIMITY16_RESOLUTION_8X8 ];
277
279
284typedef union
285{
286 uint32_t bytes;
287 struct
288 {
289 uint32_t type : 4;
290 uint32_t size : 12;
291 uint32_t idx : 16;
292 };
294
311
326
340
355err_t proximity16_write_multi ( proximity16_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len );
356
371err_t proximity16_read_multi ( proximity16_t *ctx, uint16_t reg, uint8_t *data_out, uint16_t len );
372
385err_t proximity16_write_byte ( proximity16_t *ctx, uint16_t reg, uint8_t data_in );
386
399err_t proximity16_read_byte ( proximity16_t *ctx, uint16_t reg, uint8_t *data_out );
400
413err_t proximity16_write_data ( proximity16_t *ctx, uint8_t *data_in, uint16_t len );
414
426
436
446void proximity16_set_i2c_rst_pin ( proximity16_t *ctx, uint8_t state );
447
457void proximity16_set_lpn_pin ( proximity16_t *ctx, uint8_t state );
458
468
481
496err_t proximity16_dci_write_data ( proximity16_t *ctx, uint16_t index, uint8_t *data_in, uint16_t data_size );
497
513err_t proximity16_dci_read_data ( proximity16_t *ctx, uint16_t index, uint8_t *data_out, uint16_t data_size );
514
532err_t proximity16_dci_replace_data ( proximity16_t *ctx, uint16_t index, uint8_t *data_in, uint16_t data_size,
533 uint8_t *new_data, uint16_t new_data_size, uint16_t new_data_pos );
534
546err_t proximity16_set_resolution ( proximity16_t *ctx, uint8_t resolution );
547
559err_t proximity16_get_resolution ( proximity16_t *ctx, uint8_t *resolution );
560
573err_t proximity16_set_ranging_frequency_hz ( proximity16_t *ctx, uint8_t frequency_hz );
574
587err_t proximity16_get_ranging_frequency_hz ( proximity16_t *ctx, uint8_t *frequency_hz );
588
602err_t proximity16_set_integration_time_ms ( proximity16_t *ctx, uint32_t integration_time_ms );
603
615err_t proximity16_get_integration_time_ms ( proximity16_t *ctx, uint32_t *integration_time_ms );
616
629err_t proximity16_set_ranging_mode ( proximity16_t *ctx, uint8_t ranging_mode );
630
643err_t proximity16_get_ranging_mode ( proximity16_t *ctx, uint8_t *ranging_mode );
644
656
669
683
684#ifdef __cplusplus
685}
686#endif
687#endif // PROXIMITY16_H
688
689 // proximity16
690
691// ------------------------------------------------------------------------ END
#define PROXIMITY16_RESOLUTION_8X8
Definition proximity16.h:123
#define PROXIMITY16_OFFSET_BUFFER_SIZE
Definition proximity16.h:115
#define PROXIMITY16_TEMP_BUFFER_SIZE
Proximity 16 buffers size setting.
Definition proximity16.h:113
err_t proximity16_set_integration_time_ms(proximity16_t *ctx, uint32_t integration_time_ms)
Proximity 16 set integration time ms function.
err_t proximity16_init(proximity16_t *ctx, proximity16_cfg_t *cfg)
Proximity 16 initialization function.
err_t proximity16_set_resolution(proximity16_t *ctx, uint8_t resolution)
Proximity 16 set resolution function.
err_t proximity16_default_cfg(proximity16_t *ctx)
Proximity 16 default configuration function.
err_t proximity16_dci_replace_data(proximity16_t *ctx, uint16_t index, uint8_t *data_in, uint16_t data_size, uint8_t *new_data, uint16_t new_data_size, uint16_t new_data_pos)
Proximity 16 dci replace data function.
void proximity16_set_lpn_pin(proximity16_t *ctx, uint8_t state)
Proximity 16 set lpn function.
err_t proximity16_sensor_init(proximity16_t *ctx)
Proximity 16 sensor init function.
err_t proximity16_stop_ranging(proximity16_t *ctx)
Proximity 16 stop ranging function.
err_t proximity16_get_resolution(proximity16_t *ctx, uint8_t *resolution)
Proximity 16 get resolution function.
err_t proximity16_dci_read_data(proximity16_t *ctx, uint16_t index, uint8_t *data_out, uint16_t data_size)
Proximity 16 dci read data function.
void proximity16_reset_i2c(proximity16_t *ctx)
Proximity 16 reset i2c function.
void proximity16_set_i2c_rst_pin(proximity16_t *ctx, uint8_t state)
Proximity 16 set i2c rst function.
err_t proximity16_check_communication(proximity16_t *ctx)
Proximity 16 check communication function.
err_t proximity16_write_byte(proximity16_t *ctx, uint16_t reg, uint8_t data_in)
Proximity 16 write byte function.
err_t proximity16_get_ranging_mode(proximity16_t *ctx, uint8_t *ranging_mode)
Proximity 16 get ranging mode function.
err_t proximity16_set_ranging_frequency_hz(proximity16_t *ctx, uint8_t frequency_hz)
Proximity 16 set ranging frequency hz function.
err_t proximity16_dci_write_data(proximity16_t *ctx, uint16_t index, uint8_t *data_in, uint16_t data_size)
Proximity 16 dci write data function.
void proximity16_cfg_setup(proximity16_cfg_t *cfg)
Proximity 16 configuration object setup function.
err_t proximity16_read_multi(proximity16_t *ctx, uint16_t reg, uint8_t *data_out, uint16_t len)
Proximity 16 read multi function.
err_t proximity16_write_multi(proximity16_t *ctx, uint16_t reg, uint8_t *data_in, uint8_t len)
Proximity 16 write multi function.
err_t proximity16_start_ranging(proximity16_t *ctx)
Proximity 16 start ranging function.
err_t proximity16_get_ranging_frequency_hz(proximity16_t *ctx, uint8_t *frequency_hz)
Proximity 16 get ranging frequency hz function.
uint8_t proximity16_get_int_pin(proximity16_t *ctx)
Proximity 16 get int pin function.
err_t proximity16_set_ranging_mode(proximity16_t *ctx, uint8_t ranging_mode)
Proximity 16 set ranging mode function.
err_t proximity16_read_byte(proximity16_t *ctx, uint16_t reg, uint8_t *data_out)
Proximity 16 read byte function.
err_t proximity16_get_integration_time_ms(proximity16_t *ctx, uint32_t *integration_time_ms)
Proximity 16 get integration time ms function.
err_t proximity16_write_data(proximity16_t *ctx, uint8_t *data_in, uint16_t len)
Proximity 16 write data function.
err_t proximity16_get_ranging_data(proximity16_t *ctx, proximity16_results_data_t *results)
Proximity 16 get ranging data function.
proximity16_return_value_t
Proximity 16 Click return value data.
Definition proximity16.h:254
@ PROXIMITY16_OK
Definition proximity16.h:255
@ PROXIMITY16_ERROR
Definition proximity16.h:256
Proximity 16 Click configuration object.
Definition proximity16.h:236
pin_name_t i2c_rst
Definition proximity16.h:240
uint32_t i2c_speed
Definition proximity16.h:244
pin_name_t scl
Definition proximity16.h:237
pin_name_t int_pin
Definition proximity16.h:242
pin_name_t sda
Definition proximity16.h:238
pin_name_t lpn
Definition proximity16.h:241
uint8_t i2c_address
Definition proximity16.h:245
Proximity 16 Click results data structure.
Definition proximity16.h:265
int8_t silicon_temp_degc
Definition proximity16.h:267
Proximity 16 Click context object.
Definition proximity16.h:206
uint32_t data_read_size
Definition proximity16.h:223
uint8_t stream_count
Definition proximity16.h:221
digital_out_t i2c_rst
Definition proximity16.h:208
digital_out_t lpn
Definition proximity16.h:209
digital_in_t int_pin
Definition proximity16.h:212
i2c_master_t i2c
Definition proximity16.h:215
uint8_t slave_address
Definition proximity16.h:218
Proximity 16 Click block header union data definition.
Definition proximity16.h:285
uint32_t idx
Definition proximity16.h:291
uint32_t size
Definition proximity16.h:290
uint32_t bytes
Definition proximity16.h:286
uint32_t type
Definition proximity16.h:289