proximity17  2.0.0.0
proximity17.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 PROXIMITY17_H
29 #define PROXIMITY17_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 PROXIMITY17_REG_ENABLE 0x80
70 #define PROXIMITY17_REG_PRATE 0x82
71 #define PROXIMITY17_REG_PILTL 0x88
72 #define PROXIMITY17_REG_PILTH 0x89
73 #define PROXIMITY17_REG_PIHTL 0x8A
74 #define PROXIMITY17_REG_PIHTH 0x8B
75 #define PROXIMITY17_REG_PERS 0x8C
76 #define PROXIMITY17_REG_CFG0 0x8D
77 #define PROXIMITY17_REG_PCFG0 0x8E
78 #define PROXIMITY17_REG_PCFG1 0x8F
79 #define PROXIMITY17_REG_REVID 0x91
80 #define PROXIMITY17_REG_ID 0x92
81 #define PROXIMITY17_REG_STATUS 0x9B
82 #define PROXIMITY17_REG_PDATAL 0x9C
83 #define PROXIMITY17_REG_PDATAH 0x9D
84 #define PROXIMITY17_REG_REVID2 0xA6
85 #define PROXIMITY17_REG_SOFTRST 0xA8
86 #define PROXIMITY17_REG_PWTIME 0xA9
87 #define PROXIMITY17_REG_CFG8 0xAA
88 #define PROXIMITY17_REG_CFG3 0xAB
89 #define PROXIMITY17_REG_CFG6 0xAE
90 #define PROXIMITY17_REG_PFILTER 0xB3
91 #define PROXIMITY17_REG_POFFSETL 0xC0
92 #define PROXIMITY17_REG_POFFSETH 0xC1
93 #define PROXIMITY17_REG_CALIB 0xD7
94 #define PROXIMITY17_REG_CALIBCFG 0xD9
95 #define PROXIMITY17_REG_CALIBSTAT 0xDC
96 #define PROXIMITY17_REG_INTENAB 0xDD
97 #define PROXIMITY17_REG_FAC_L 0xE5
98 #define PROXIMITY17_REG_FAC_H 0xE6
99 #define PROXIMITY17_REG_TEST9 0xF9
100  // proximity17_reg
102 
117 #define PROXIMITY17_ENABLE_PWEN 0x10
118 #define PROXIMITY17_ENABLE_PEN 0x04
119 #define PROXIMITY17_ENABLE_PON 0x01
120 
125 #define PROXIMITY17_SOFT_RESET 0x01
126 
131 #define PROXIMITY17_PGAIN_1X 0x00
132 #define PROXIMITY17_PGAIN_2X 0x40
133 #define PROXIMITY17_PGAIN_4X 0x80
134 #define PROXIMITY17_PGAIN_8X 0xC0
135 #define PROXIMITY17_PPULSE_MIN 0x00
136 #define PROXIMITY17_PPULSE_DEFAULT 0x0F
137 #define PROXIMITY17_PPULSE_MAX 0x3F
138 
143 #define PROXIMITY17_PPULSE_LEN_1US 0x00
144 #define PROXIMITY17_PPULSE_LEN_2US 0x20
145 #define PROXIMITY17_PPULSE_LEN_4US 0x40
146 #define PROXIMITY17_PPULSE_LEN_8US 0x60
147 #define PROXIMITY17_PPULSE_LEN_12US 0x80
148 #define PROXIMITY17_PPULSE_LEN_16US 0xA0
149 #define PROXIMITY17_PPULSE_LEN_24US 0xC0
150 #define PROXIMITY17_PPULSE_LEN_32US 0xE0
151 #define PROXIMITY17_PLDRIVE_2mA 0x00
152 #define PROXIMITY17_PLDRIVE_3mA 0x01
153 #define PROXIMITY17_PLDRIVE_4mA 0x02
154 #define PROXIMITY17_PLDRIVE_5mA 0x03
155 #define PROXIMITY17_PLDRIVE_6mA 0x04
156 #define PROXIMITY17_PLDRIVE_7mA 0x05
157 #define PROXIMITY17_PLDRIVE_8mA 0x06
158 #define PROXIMITY17_PLDRIVE_9mA 0x07
159 #define PROXIMITY17_PLDRIVE_10mA 0x08
160 
165 #define PROXIMITY17_PDSELECT_NO_PDIODE 0x00
166 #define PROXIMITY17_PDSELECT_FAR_PDIODE 0x01
167 #define PROXIMITY17_PDSELECT_NEAR_PDIODE 0x02
168 #define PROXIMITY17_PDSELECT_BOTH_PDIODE 0x03
169 
174 #define PROXIMITY17_STATUS_PHIGH 0x80
175 #define PROXIMITY17_STATUS_PLOW 0x40
176 #define PROXIMITY17_STATUS_PSAT 0x20
177 #define PROXIMITY17_STATUS_PINT 0x10
178 #define PROXIMITY17_STATUS_CINT 0x08
179 #define PROXIMITY17_STATUS_ZINT 0x04
180 #define PROXIMITY17_STATUS_PSAT_REFLECTIVE 0x02
181 #define PROXIMITY17_STATUS_PSAT_AMBIENT 0x01
182 #define PROXIMITY17_STATUS_CLEAR_ALL 0xFF
183 
188 #define PROXIMITY17_INTENAB_PIM 0x20
189 #define PROXIMITY17_INTENAB_PIEN 0x10
190 #define PROXIMITY17_INTENAB_PSIEN 0x08
191 #define PROXIMITY17_INTENAB_CIEN 0x04
192 #define PROXIMITY17_INTENAB_ZIEN 0x02
193 #define PROXIMITY17_INTENAB_DISABLE 0x00
194 
199 #define PROXIMITY17_CALAVG 0x80
200 #define PROXIMITY17_ELECTRICAL_CALIB 0x20
201 #define PROXIMITY17_CALPRATE 0x10
202 #define PROXIMITY17_START_OFFSET_CAL 0x01
203 
208 #define PROXIMITY17_BINSRCH_TARGET_3 0x00
209 #define PROXIMITY17_BINSRCH_TARGET_7 0x20
210 #define PROXIMITY17_BINSRCH_TARGET_15 0x40
211 #define PROXIMITY17_BINSRCH_TARGET_31 0x60
212 #define PROXIMITY17_BINSRCH_TARGET_63 0x80
213 #define PROXIMITY17_BINSRCH_TARGET_127 0xA0
214 #define PROXIMITY17_BINSRCH_TARGET_255 0xC0
215 #define PROXIMITY17_BINSRCH_TARGET_511 0xE0
216 #define PROXIMITY17_CALIBCFG_RESERVED 0x10
217 #define PROXIMITY17_AUTO_OFFSET_ADJ 0x08
218 #define PROXIMITY17_PROX_AVG_DISABLE 0x00
219 #define PROXIMITY17_PROX_AVG_2 0x01
220 #define PROXIMITY17_PROX_AVG_4 0x02
221 #define PROXIMITY17_PROX_AVG_8 0x03
222 #define PROXIMITY17_PROX_AVG_16 0x04
223 #define PROXIMITY17_PROX_AVG_32 0x05
224 #define PROXIMITY17_PROX_AVG_64 0x06
225 #define PROXIMITY17_PROX_AVG_128 0x07
226 
231 #define PROXIMITY17_OFFSET_ADJUSTED 0x04
232 #define PROXIMITY17_CALIB_FINISHED 0x01
233 
238 #define PROXIMITY17_APC_ENABLE 0x3F
239 #define PROXIMITY17_APC_DISABLE 0x7F
240 
245 #define PROXIMITY17_DEVICE_ID 0x44
246 
252 #define PROXIMITY17_DEVICE_ADDRESS 0x39
253  // proximity17_set
255 
270 #define PROXIMITY17_MAP_MIKROBUS( cfg, mikrobus ) \
271  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
272  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
273  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
274  // proximity17_map // proximity17
277 
282 typedef struct
283 {
284  // Input pins
285  digital_in_t int_pin;
287  // Modules
288  i2c_master_t i2c;
290  // I2C slave address
291  uint8_t slave_address;
293 } proximity17_t;
294 
299 typedef struct
300 {
301  pin_name_t scl;
302  pin_name_t sda;
304  pin_name_t int_pin;
306  uint32_t i2c_speed;
307  uint8_t i2c_address;
310 
315 typedef enum
316 {
318  PROXIMITY17_ERROR = -1
319 
321 
338 
353 
367 
382 err_t proximity17_generic_write ( proximity17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
383 
398 err_t proximity17_generic_read ( proximity17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
399 
412 err_t proximity17_write_register ( proximity17_t *ctx, uint8_t reg, uint8_t data_in );
413 
426 err_t proximity17_read_register ( proximity17_t *ctx, uint8_t reg, uint8_t *data_out );
427 
440 
452 
464 err_t proximity17_read_proximity ( proximity17_t *ctx, uint16_t *prox_data );
465 
475 
476 #ifdef __cplusplus
477 }
478 #endif
479 #endif // PROXIMITY17_H
480  // proximity17
482 
483 // ------------------------------------------------------------------------ END
proximity17_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity17.h:307
proximity17_soft_reset
err_t proximity17_soft_reset(proximity17_t *ctx)
Proximity 17 soft reset function.
proximity17_default_cfg
err_t proximity17_default_cfg(proximity17_t *ctx)
Proximity 17 default configuration function.
proximity17_cfg_t::scl
pin_name_t scl
Definition: proximity17.h:301
proximity17_check_communication
err_t proximity17_check_communication(proximity17_t *ctx)
Proximity 17 check communication function.
proximity17_write_register
err_t proximity17_write_register(proximity17_t *ctx, uint8_t reg, uint8_t data_in)
Proximity 17 write register function.
PROXIMITY17_OK
@ PROXIMITY17_OK
Definition: proximity17.h:317
proximity17_read_proximity
err_t proximity17_read_proximity(proximity17_t *ctx, uint16_t *prox_data)
Proximity 17 read proximity function.
PROXIMITY17_ERROR
@ PROXIMITY17_ERROR
Definition: proximity17.h:318
proximity17_return_value_t
proximity17_return_value_t
Proximity 17 Click return value data.
Definition: proximity17.h:316
proximity17_t::slave_address
uint8_t slave_address
Definition: proximity17.h:291
proximity17_cfg_t::sda
pin_name_t sda
Definition: proximity17.h:302
proximity17_cfg_t
Proximity 17 Click configuration object.
Definition: proximity17.h:300
proximity17_read_register
err_t proximity17_read_register(proximity17_t *ctx, uint8_t reg, uint8_t *data_out)
Proximity 17 read register function.
proximity17_generic_read
err_t proximity17_generic_read(proximity17_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
Proximity 17 I2C reading function.
proximity17_t::i2c
i2c_master_t i2c
Definition: proximity17.h:288
proximity17_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity17.h:304
proximity17_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity17.h:306
proximity17_cfg_setup
void proximity17_cfg_setup(proximity17_cfg_t *cfg)
Proximity 17 configuration object setup function.
proximity17_t
Proximity 17 Click context object.
Definition: proximity17.h:283
proximity17_generic_write
err_t proximity17_generic_write(proximity17_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
Proximity 17 I2C writing function.
proximity17_init
err_t proximity17_init(proximity17_t *ctx, proximity17_cfg_t *cfg)
Proximity 17 initialization function.
proximity17_t::int_pin
digital_in_t int_pin
Definition: proximity17.h:285
proximity17_get_int_pin
uint8_t proximity17_get_int_pin(proximity17_t *ctx)
Proximity 17 get int pin function.