proximity19  2.1.0.0
proximity19.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 PROXIMITY19_H
29 #define PROXIMITY19_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
69 #define PROXIMITY19_REG_SYSTEM_CONTROL 0x40
70 #define PROXIMITY19_REG_MODE_CONTROL0 0x41
71 #define PROXIMITY19_REG_MODE_CONTROL1 0x42
72 #define PROXIMITY19_REG_MODE_CONTROL2 0x43
73 #define PROXIMITY19_REG_PS_DATA_LSB 0x44
74 #define PROXIMITY19_REG_PS_DATA_MSB 0x45
75 #define PROXIMITY19_REG_PS_OFFSET_LSB 0x46
76 #define PROXIMITY19_REG_PS_OFFSET_MSB 0x47
77 #define PROXIMITY19_REG_INTERRUPT 0x4A
78 #define PROXIMITY19_REG_PS_TH_HIGH_LSB 0x4B
79 #define PROXIMITY19_REG_PS_TH_HIGH_MSB 0x4C
80 #define PROXIMITY19_REG_PS_TH_LOW_LSB 0x4D
81 #define PROXIMITY19_REG_PS_TH_LOW_MSB 0x4E
82 #define PROXIMITY19_REG_MANUFACT_ID 0x92
83 
84  // proximity19_reg
86 
101 #define PROXIMITY19_SW_RESET 0x80
102 #define PROXIMITY19_PART_ID_BITMASK 0x7F
103 #define PROXIMITY19_PART_ID_VAL 0x1C
104 
109 #define PROXIMITY19_PS_GAIN_X1 0x00
110 #define PROXIMITY19_PS_GAIN_X2 0x01
111 #define PROXIMITY19_PS_GAIN_BITMASK 0xF3
112 #define PROXIMITY19_PD_SEL_NO 0x00
113 #define PROXIMITY19_PD_SEL_FAR 0x01
114 #define PROXIMITY19_PD_SEL_NEAR 0x02
115 #define PROXIMITY19_PD_SEL_BOTH 0x03
116 #define PROXIMITY19_PD_SEL_BITMASK 0x03
117 
122 #define PROXIMITY19_PERIOD_10_MS 0x00
123 #define PROXIMITY19_PERIOD_50_MS 0x01
124 #define PROXIMITY19_PERIOD_100_MS 0x02
125 #define PROXIMITY19_PERIOD_500_MS 0x03
126 #define PROXIMITY19_PERIOD_5_MS 0x04
127 #define PROXIMITY19_PERIOD_BITMASK 0x70
128 #define PROXIMITY19_PS_PULSE_50_US 0x00
129 #define PROXIMITY19_PS_PULSE_100_US 0x01
130 #define PROXIMITY19_PS_PULSE_200_US 0x02
131 #define PROXIMITY19_PS_PULSE_400_US 0x03
132 #define PROXIMITY19_PS_PULSE_BITMASK 0x0C
133 #define PROXIMITY19_VCSEL_CURR_3_MA 0x00
134 #define PROXIMITY19_VCSEL_CURR_4_MA 0x01
135 #define PROXIMITY19_VCSEL_CURR_5_MA 0x02
136 #define PROXIMITY19_VCSEL_CURR_BITMASK 0x03
137 
142 #define PROXIMITY19_PS_DISABLE 0x00
143 #define PROXIMITY19_PS_ENABLE 0x01
144 
149 #define PROXIMITY19_PS_TH_RES 0x0F
150 
155 #define PROXIMITY19_PS_RES_MSB_BITMASK 0x07
156 #define PROXIMITY19_PS_OFFSET_BITMASK 0x01
157 #define PROXIMITY19_DET_RANGE_MIN 1.0f
158 #define PROXIMITY19_DET_RANGE_MAX 14.0f
159 
164 #define PROXIMITY19_DATA_RANGE_50_US 0x03FEu
165 #define PROXIMITY19_DATA_RANGE_100_US 0x03FEu
166 #define PROXIMITY19_DATA_RANGE_200_US 0x07FEu
167 #define PROXIMITY19_DATA_RANGE_400_US 0x0FFEu
168 
173 #define PROXIMITY19_GAIN_X1 1.0f
174 #define PROXIMITY19_GAIN_X2 2.0f
175 #define PROXIMITY19_GAIN_X2_BOTH_PD 3.0f
176 
181 #define PROXIMITY19_MANUFACT_ID 0xE0
182 
188 #define PROXIMITY19_DEVICE_ADDRESS 0x39
189  // proximity19_set
191 
206 #define PROXIMITY19_MAP_MIKROBUS( cfg, mikrobus ) \
207  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
208  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
209  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
210  // proximity19_map // proximity19
213 
218 typedef struct
219 {
220  // Input pins
221  digital_in_t int_pin;
223  // Modules
224  i2c_master_t i2c;
226  // I2C slave address
227  uint8_t slave_address;
229  uint16_t data_range;
230  float gain;
232 } proximity19_t;
233 
238 typedef struct
239 {
240  pin_name_t scl;
241  pin_name_t sda;
243  pin_name_t int_pin;
245  uint32_t i2c_speed;
246  uint8_t i2c_address;
249 
254 typedef enum
255 {
257  PROXIMITY19_ERROR = -1
258 
260 
277 
292 
306 
321 err_t proximity19_generic_write ( proximity19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
322 
337 err_t proximity19_generic_read ( proximity19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
338 
351 
364 err_t proximity19_get_part_id ( proximity19_t *ctx, uint8_t *part_id );
365 
378 err_t proximity19_set_ps_gain ( proximity19_t *ctx, uint8_t ps_gain );
379 
392 err_t proximity19_set_pd_sel ( proximity19_t *ctx, uint8_t pd_sel );
393 
406 err_t proximity19_set_period ( proximity19_t *ctx, uint8_t period );
407 
420 err_t proximity19_set_pulse_width ( proximity19_t *ctx, uint8_t pulse_width );
421 
434 err_t proximity19_set_vcsel_current ( proximity19_t *ctx, uint8_t vcsel_current );
435 
449 
463 
476 err_t proximity19_get_ps_data ( proximity19_t *ctx, uint16_t *ps_data );
477 
490 err_t proximity19_get_distance ( proximity19_t *ctx, float *distance );
491 
504 err_t proximity19_set_ps_offset ( proximity19_t *ctx, uint16_t ps_offset );
505 
518 err_t proximity19_int_cfg ( proximity19_t *ctx, uint8_t int_cfg );
519 
533 err_t proximity19_set_ps_th ( proximity19_t *ctx, uint16_t ps_th_high, uint16_t ps_th_low );
534 
547 err_t proximity19_get_manufact_id ( proximity19_t *ctx, uint8_t *manufact_id );
548 
562 
563 #ifdef __cplusplus
564 }
565 #endif
566 #endif // PROXIMITY19_H
567  // proximity19
569 
570 // ------------------------------------------------------------------------ END
proximity19_set_pd_sel
err_t proximity19_set_pd_sel(proximity19_t *ctx, uint8_t pd_sel)
Proximity 19 set PD photodiode function.
proximity19_set_pulse_width
err_t proximity19_set_pulse_width(proximity19_t *ctx, uint8_t pulse_width)
Proximity 19 set pulse width function.
proximity19_t::i2c
i2c_master_t i2c
Definition: proximity19.h:224
proximity19_set_ps_gain
err_t proximity19_set_ps_gain(proximity19_t *ctx, uint8_t ps_gain)
Proximity 19 set PS gain function.
proximity19_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity19.h:245
proximity19_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity19.h:243
proximity19_set_vcsel_current
err_t proximity19_set_vcsel_current(proximity19_t *ctx, uint8_t vcsel_current)
Proximity 19 set VCSEL current function.
proximity19_get_part_id
err_t proximity19_get_part_id(proximity19_t *ctx, uint8_t *part_id)
Proximity 19 get part ID function.
proximity19_set_ps_offset
err_t proximity19_set_ps_offset(proximity19_t *ctx, uint16_t ps_offset)
Proximity 19 set PS offset function.
proximity19_cfg_setup
void proximity19_cfg_setup(proximity19_cfg_t *cfg)
Proximity 19 configuration object setup function.
proximity19_t::gain
float gain
Definition: proximity19.h:230
proximity19_sw_reset
err_t proximity19_sw_reset(proximity19_t *ctx)
Proximity 19 software reset function.
proximity19_cfg_t
Proximity 19 Click configuration object.
Definition: proximity19.h:239
proximity19_get_ps_data
err_t proximity19_get_ps_data(proximity19_t *ctx, uint16_t *ps_data)
Proximity 19 get PS data function.
proximity19_generic_write
err_t proximity19_generic_write(proximity19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Proximity 19 I2C writing function.
proximity19_t::slave_address
uint8_t slave_address
Definition: proximity19.h:227
PROXIMITY19_OK
@ PROXIMITY19_OK
Definition: proximity19.h:256
proximity19_cfg_t::scl
pin_name_t scl
Definition: proximity19.h:240
proximity19_default_cfg
err_t proximity19_default_cfg(proximity19_t *ctx)
Proximity 19 default configuration function.
proximity19_t
Proximity 19 Click context object.
Definition: proximity19.h:219
proximity19_get_manufact_id
err_t proximity19_get_manufact_id(proximity19_t *ctx, uint8_t *manufact_id)
Proximity 19 get manufacture ID function.
proximity19_cfg_t::sda
pin_name_t sda
Definition: proximity19.h:241
proximity19_ps_disable
err_t proximity19_ps_disable(proximity19_t *ctx)
Proximity 19 PS standby function.
proximity19_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity19.h:246
proximity19_t::data_range
uint16_t data_range
Definition: proximity19.h:229
proximity19_set_period
err_t proximity19_set_period(proximity19_t *ctx, uint8_t period)
Proximity 19 set period function.
PROXIMITY19_ERROR
@ PROXIMITY19_ERROR
Definition: proximity19.h:257
proximity19_set_ps_th
err_t proximity19_set_ps_th(proximity19_t *ctx, uint16_t ps_th_high, uint16_t ps_th_low)
Proximity 19 set PS threshold function.
proximity19_t::int_pin
digital_in_t int_pin
Definition: proximity19.h:221
proximity19_return_value_t
proximity19_return_value_t
Proximity 19 Click return value data.
Definition: proximity19.h:255
proximity19_generic_read
err_t proximity19_generic_read(proximity19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Proximity 19 I2C reading function.
proximity19_get_int_pin
uint8_t proximity19_get_int_pin(proximity19_t *ctx)
Proximity 19 get interrupt function.
proximity19_get_distance
err_t proximity19_get_distance(proximity19_t *ctx, float *distance)
Proximity 19 get distance function.
proximity19_ps_enable
err_t proximity19_ps_enable(proximity19_t *ctx)
Proximity 19 PS enable function.
proximity19_init
err_t proximity19_init(proximity19_t *ctx, proximity19_cfg_t *cfg)
Proximity 19 initialization function.
proximity19_int_cfg
err_t proximity19_int_cfg(proximity19_t *ctx, uint8_t int_cfg)
Proximity 19 interrupt configuration function.