proximity8  2.0.0.0
proximity8.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef PROXIMITY8_H
36 #define PROXIMITY8_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define PROXIMITY8_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
56  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
57 
63 #define PROXIMITY8_RETVAL uint8_t
64 
65 #define PROXIMITY8_OK 0x00
66 #define PROXIMITY8_INIT_ERROR 0xFF
67 
73 #define PROXIMITY8_REG_PS_CONFIG_12 0x03
74 #define PROXIMITY8_REG_PS_CONFIG_34 0x04
75 #define PROXIMITY8_REG_THRESHOLD_LOW 0x05
76 #define PROXIMITY8_REG_THRESHOLD_HIGH 0x06
77 #define PROXIMITY8_REG_CANCELLATION_LEVEL 0x07
78 #define PROXIMITY8_REG_PS_CONFIG_5 0x08
79 #define PROXIMITY8_REG_PROX_DATA 0xF2
80 #define PROXIMITY8_REG_INTERRUPT_FLAG 0xF3
81 #define PROXIMITY8_REG_DEVICE_ID 0xF4
82 
88 #define PROXIMITY8_CFG12_PS_IT_1T 0x0000
89 #define PROXIMITY8_CFG12_PS_IT_2T 0x4000
90 #define PROXIMITY8_CFG12_PS_IT_4T 0x8000
91 #define PROXIMITY8_CFG12_PS_IT_8T 0xC000
92 #define PROXIMITY8_CFG12_MPS_1 0x0000
93 #define PROXIMITY8_CFG12_MPS_2 0x1000
94 #define PROXIMITY8_CFG12_MPS_4 0x2000
95 #define PROXIMITY8_CFG12_MPS_8 0x3000
96 #define PROXIMITY8_CFG12_ITB_25us 0x0000
97 #define PROXIMITY8_CFG12_ITB_50us 0x0800
98 #define PROXIMITY8_CFG12_PERIOD_8ms 0x0000
99 #define PROXIMITY8_CFG12_PERIOD_16ms 0x0040
100 #define PROXIMITY8_CFG12_PERIOD_32ms 0x0080
101 #define PROXIMITY8_CFG12_PERIOD_64ms 0x00C0
102 #define PROXIMITY8_CFG12_PERS_1 0x0000
103 #define PROXIMITY8_CFG12_PERS_2 0x0010
104 #define PROXIMITY8_CFG12_PERS_3 0x0020
105 #define PROXIMITY8_CFG12_PERS_4 0x0030
106 #define PROXIMITY8_CFG12_INT_ENABLE 0x0008
107 #define PROXIMITY8_CFG12_INT_DISABLE 0x0004
108 #define PROXIMITY8_CFG12_SMART_PERS_DISABLE 0x0000
109 #define PROXIMITY8_CFG12_SMART_PERS_ENABLE 0x0002
110 #define PROXIMITY8_CFG12_SD_POWER_ON 0x0000
111 #define PROXIMITY8_CFG12_SD_SHUT_DOWN 0x0001
112 
118 #define PROXIMITY8_CFG34_OFF_SUNLIGHT_CANCEL 0x0000
119 #define PROXIMITY8_CFG34_ON_SUNLIGHT_CANCEL 0x8000
120 #define PROXIMITY8_CFG34_SC_CUR_X1 0x0000
121 #define PROXIMITY8_CFG34_SC_CUR_X2 0x2000
122 #define PROXIMITY8_CFG34_SC_CUR_X4 0x4000
123 #define PROXIMITY8_CFG34_SC_CUR_X8 0x6000
124 #define PROXIMITY8_CFG34_PS_OUTPUT_12bit 0x0000
125 #define PROXIMITY8_CFG34_PS_OUTPUT_16bit 0x1000
126 #define PROXIMITY8_CFG34_VCSEL_I_7mA 0x0000
127 #define PROXIMITY8_CFG34_VCSEL_I_11mA 0x0100
128 #define PROXIMITY8_CFG34_VCSEL_I_14mA 0x0200
129 #define PROXIMITY8_CFG34_VCSEL_I_17mA 0x0300
130 #define PROXIMITY8_CFG34_VCSEL_I_20mA 0x0400
131 #define PROXIMITY8_CFG34_AF_MODE_AUTO 0x0000
132 #define PROXIMITY8_CFG34_AF_MODE_FORCE 0x0040
133 #define PROXIMITY8_CFG34_FOR_TRIG_ACTIVE 0x0000
134 #define PROXIMITY8_CFG34_FOR_TRIG_ONE_TIME 0x0020
135 
141 #define PROXIMITY8_DEVICE_ID 0x0588
142 #define PROXIMITY8_DEVICE_SLAVE_ADDRESS 0x60
143  // End group macro
146 // --------------------------------------------------------------- PUBLIC TYPES
155 typedef struct
156 {
157  // Input pins
158 
159  digital_in_t int_pin;
160 
161  // Modules
162 
163  i2c_master_t i2c;
164 
165  // ctx variable
166 
167  hal_i2c_address_t slave_address;
168 
169 } proximity8_t;
170 
174 typedef struct
175 {
176  // Communication gpio pins
177 
178  pin_name_t scl;
179  pin_name_t sda;
180 
181  // Additional gpio pins
182 
183  pin_name_t int_pin;
184 
185  // static variable
186 
187  hal_i2c_speed_t i2c_speed;
188  hal_i2c_address_t i2c_address;
189 
191  // End types group
193 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
194 
200 #ifdef __cplusplus
201 extern "C"{
202 #endif
203 
213 
222 
231 
242 void proximity8_generic_write ( proximity8_t *ctx, uint8_t reg, uint16_t *data_buf, uint8_t len );
243 
254 void proximity8_generic_read ( proximity8_t *ctx, uint8_t reg, uint16_t *data_buf );
255 
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 #endif // _PROXIMITY8_H_
271  // End public_function group
274 
275 // ------------------------------------------------------------------------- END
hal_i2c_address_t i2c_address
Definition: proximity8.h:188
pin_name_t scl
Definition: proximity8.h:178
i2c_master_t i2c
Definition: proximity8.h:163
hal_i2c_speed_t i2c_speed
Definition: proximity8.h:187
void proximity8_default_cfg(proximity8_t *ctx)
Click Default Configuration function.
void proximity8_cfg_setup(proximity8_cfg_t *cfg)
Config Object Initialization function.
#define PROXIMITY8_RETVAL
Definition: proximity8.h:63
pin_name_t int_pin
Definition: proximity8.h:183
pin_name_t sda
Definition: proximity8.h:179
PROXIMITY8_RETVAL proximity8_init(proximity8_t *ctx, proximity8_cfg_t *cfg)
Initialization function.
uint8_t proximity8_get_interrupt_state(proximity8_t *ctx)
Get interrupt state on the INT pin.
Click configuration structure definition.
Definition: proximity8.h:174
void proximity8_generic_read(proximity8_t *ctx, uint8_t reg, uint16_t *data_buf)
Generic read function.
hal_i2c_address_t slave_address
Definition: proximity8.h:167
Click ctx object definition.
Definition: proximity8.h:155
digital_in_t int_pin
Definition: proximity8.h:159
void proximity8_generic_write(proximity8_t *ctx, uint8_t reg, uint16_t *data_buf, uint8_t len)
Generic write function.