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 
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 PROXIMITY19_REG_SYSTEM_CONTROL 0x40
74 #define PROXIMITY19_REG_MODE_CONTROL0 0x41
75 #define PROXIMITY19_REG_MODE_CONTROL1 0x42
76 #define PROXIMITY19_REG_MODE_CONTROL2 0x43
77 #define PROXIMITY19_REG_PS_DATA_LSB 0x44
78 #define PROXIMITY19_REG_PS_DATA_MSB 0x45
79 #define PROXIMITY19_REG_PS_OFFSET_LSB 0x46
80 #define PROXIMITY19_REG_PS_OFFSET_MSB 0x47
81 #define PROXIMITY19_REG_INTERRUPT 0x4A
82 #define PROXIMITY19_REG_PS_TH_HIGH_LSB 0x4B
83 #define PROXIMITY19_REG_PS_TH_HIGH_MSB 0x4C
84 #define PROXIMITY19_REG_PS_TH_LOW_LSB 0x4D
85 #define PROXIMITY19_REG_PS_TH_LOW_MSB 0x4E
86 #define PROXIMITY19_REG_MANUFACT_ID 0x92
87 
88  // proximity19_reg
90 
105 #define PROXIMITY19_SW_RESET 0x80
106 #define PROXIMITY19_PART_ID_BITMASK 0x7F
107 #define PROXIMITY19_PART_ID_VAL 0x1C
108 
113 #define PROXIMITY19_PS_GAIN_X1 0x00
114 #define PROXIMITY19_PS_GAIN_X2 0x01
115 #define PROXIMITY19_PS_GAIN_BITMASK 0xF3
116 #define PROXIMITY19_PD_SEL_NO 0x00
117 #define PROXIMITY19_PD_SEL_FAR 0x01
118 #define PROXIMITY19_PD_SEL_NEAR 0x02
119 #define PROXIMITY19_PD_SEL_BOTH 0x03
120 #define PROXIMITY19_PD_SEL_BITMASK 0x03
121 
126 #define PROXIMITY19_PERIOD_10_MS 0x00
127 #define PROXIMITY19_PERIOD_50_MS 0x01
128 #define PROXIMITY19_PERIOD_100_MS 0x02
129 #define PROXIMITY19_PERIOD_500_MS 0x03
130 #define PROXIMITY19_PERIOD_5_MS 0x04
131 #define PROXIMITY19_PERIOD_BITMASK 0x70
132 #define PROXIMITY19_PS_PULSE_50_US 0x00
133 #define PROXIMITY19_PS_PULSE_100_US 0x01
134 #define PROXIMITY19_PS_PULSE_200_US 0x02
135 #define PROXIMITY19_PS_PULSE_400_US 0x03
136 #define PROXIMITY19_PS_PULSE_BITMASK 0x0C
137 #define PROXIMITY19_VCSEL_CURR_3_MA 0x00
138 #define PROXIMITY19_VCSEL_CURR_4_MA 0x01
139 #define PROXIMITY19_VCSEL_CURR_5_MA 0x02
140 #define PROXIMITY19_VCSEL_CURR_BITMASK 0x03
141 
146 #define PROXIMITY19_PS_DISABLE 0x00
147 #define PROXIMITY19_PS_ENABLE 0x01
148 
153 #define PROXIMITY19_PS_TH_RES 0x0F
154 
159 #define PROXIMITY19_PS_RES_MSB_BITMASK 0x07
160 #define PROXIMITY19_PS_OFFSET_BITMASK 0x01
161 #define PROXIMITY19_DET_RANGE_MIN 1.0f
162 #define PROXIMITY19_DET_RANGE_MAX 14.0f
163 
168 #define PROXIMITY19_DATA_RANGE_50_US 0x03FEu
169 #define PROXIMITY19_DATA_RANGE_100_US 0x03FEu
170 #define PROXIMITY19_DATA_RANGE_200_US 0x07FEu
171 #define PROXIMITY19_DATA_RANGE_400_US 0x0FFEu
172 
177 #define PROXIMITY19_GAIN_X1 1.0f
178 #define PROXIMITY19_GAIN_X2 2.0f
179 #define PROXIMITY19_GAIN_X2_BOTH_PD 3.0f
180 
185 #define PROXIMITY19_MANUFACT_ID 0xE0
186 
192 #define PROXIMITY19_DEVICE_ADDRESS 0x39
193  // proximity19_set
195 
210 #define PROXIMITY19_MAP_MIKROBUS( cfg, mikrobus ) \
211  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
212  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
213  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
214  // proximity19_map // proximity19
217 
222 typedef struct
223 {
224  // Input pins
225  digital_in_t int_pin;
227  // Modules
228  i2c_master_t i2c;
230  // I2C slave address
231  uint8_t slave_address;
233  uint16_t data_range;
234  float gain;
236 } proximity19_t;
237 
242 typedef struct
243 {
244  pin_name_t scl;
245  pin_name_t sda;
247  pin_name_t int_pin;
249  uint32_t i2c_speed;
250  uint8_t i2c_address;
253 
258 typedef enum
259 {
261  PROXIMITY19_ERROR = -1
262 
264 
281 
296 
310 
325 err_t proximity19_generic_write ( proximity19_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
326 
341 err_t proximity19_generic_read ( proximity19_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
342 
355 
368 err_t proximity19_get_part_id ( proximity19_t *ctx, uint8_t *part_id );
369 
382 err_t proximity19_set_ps_gain ( proximity19_t *ctx, uint8_t ps_gain );
383 
396 err_t proximity19_set_pd_sel ( proximity19_t *ctx, uint8_t pd_sel );
397 
410 err_t proximity19_set_period ( proximity19_t *ctx, uint8_t period );
411 
424 err_t proximity19_set_pulse_width ( proximity19_t *ctx, uint8_t pulse_width );
425 
438 err_t proximity19_set_vcsel_current ( proximity19_t *ctx, uint8_t vcsel_current );
439 
453 
467 
480 err_t proximity19_get_ps_data ( proximity19_t *ctx, uint16_t *ps_data );
481 
494 err_t proximity19_get_distance ( proximity19_t *ctx, float *distance );
495 
508 err_t proximity19_set_ps_offset ( proximity19_t *ctx, uint16_t ps_offset );
509 
522 err_t proximity19_int_cfg ( proximity19_t *ctx, uint8_t int_cfg );
523 
537 err_t proximity19_set_ps_th ( proximity19_t *ctx, uint16_t ps_th_high, uint16_t ps_th_low );
538 
551 err_t proximity19_get_manufact_id ( proximity19_t *ctx, uint8_t *manufact_id );
552 
566 
567 #ifdef __cplusplus
568 }
569 #endif
570 #endif // PROXIMITY19_H
571  // proximity19
573 
574 // ------------------------------------------------------------------------ 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:228
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:249
proximity19_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity19.h:247
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:234
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:243
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:231
PROXIMITY19_OK
@ PROXIMITY19_OK
Definition: proximity19.h:260
proximity19_cfg_t::scl
pin_name_t scl
Definition: proximity19.h:244
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:223
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:245
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:250
proximity19_t::data_range
uint16_t data_range
Definition: proximity19.h:233
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:261
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:225
proximity19_return_value_t
proximity19_return_value_t
Proximity 19 Click return value data.
Definition: proximity19.h:259
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.