proximity8  2.0.0.0
proximity8.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef PROXIMITY8_H
36 #define PROXIMITY8_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define PROXIMITY8_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define PROXIMITY8_RETVAL uint8_t
73 
74 #define PROXIMITY8_OK 0x00
75 #define PROXIMITY8_INIT_ERROR 0xFF
76 
82 #define PROXIMITY8_REG_PS_CONFIG_12 0x03
83 #define PROXIMITY8_REG_PS_CONFIG_34 0x04
84 #define PROXIMITY8_REG_THRESHOLD_LOW 0x05
85 #define PROXIMITY8_REG_THRESHOLD_HIGH 0x06
86 #define PROXIMITY8_REG_CANCELLATION_LEVEL 0x07
87 #define PROXIMITY8_REG_PS_CONFIG_5 0x08
88 #define PROXIMITY8_REG_PROX_DATA 0xF2
89 #define PROXIMITY8_REG_INTERRUPT_FLAG 0xF3
90 #define PROXIMITY8_REG_DEVICE_ID 0xF4
91 
97 #define PROXIMITY8_CFG12_PS_IT_1T 0x0000
98 #define PROXIMITY8_CFG12_PS_IT_2T 0x4000
99 #define PROXIMITY8_CFG12_PS_IT_4T 0x8000
100 #define PROXIMITY8_CFG12_PS_IT_8T 0xC000
101 #define PROXIMITY8_CFG12_MPS_1 0x0000
102 #define PROXIMITY8_CFG12_MPS_2 0x1000
103 #define PROXIMITY8_CFG12_MPS_4 0x2000
104 #define PROXIMITY8_CFG12_MPS_8 0x3000
105 #define PROXIMITY8_CFG12_ITB_25us 0x0000
106 #define PROXIMITY8_CFG12_ITB_50us 0x0800
107 #define PROXIMITY8_CFG12_PERIOD_8ms 0x0000
108 #define PROXIMITY8_CFG12_PERIOD_16ms 0x0040
109 #define PROXIMITY8_CFG12_PERIOD_32ms 0x0080
110 #define PROXIMITY8_CFG12_PERIOD_64ms 0x00C0
111 #define PROXIMITY8_CFG12_PERS_1 0x0000
112 #define PROXIMITY8_CFG12_PERS_2 0x0010
113 #define PROXIMITY8_CFG12_PERS_3 0x0020
114 #define PROXIMITY8_CFG12_PERS_4 0x0030
115 #define PROXIMITY8_CFG12_INT_ENABLE 0x0008
116 #define PROXIMITY8_CFG12_INT_DISABLE 0x0004
117 #define PROXIMITY8_CFG12_SMART_PERS_DISABLE 0x0000
118 #define PROXIMITY8_CFG12_SMART_PERS_ENABLE 0x0002
119 #define PROXIMITY8_CFG12_SD_POWER_ON 0x0000
120 #define PROXIMITY8_CFG12_SD_SHUT_DOWN 0x0001
121 
127 #define PROXIMITY8_CFG34_OFF_SUNLIGHT_CANCEL 0x0000
128 #define PROXIMITY8_CFG34_ON_SUNLIGHT_CANCEL 0x8000
129 #define PROXIMITY8_CFG34_SC_CUR_X1 0x0000
130 #define PROXIMITY8_CFG34_SC_CUR_X2 0x2000
131 #define PROXIMITY8_CFG34_SC_CUR_X4 0x4000
132 #define PROXIMITY8_CFG34_SC_CUR_X8 0x6000
133 #define PROXIMITY8_CFG34_PS_OUTPUT_12bit 0x0000
134 #define PROXIMITY8_CFG34_PS_OUTPUT_16bit 0x1000
135 #define PROXIMITY8_CFG34_VCSEL_I_7mA 0x0000
136 #define PROXIMITY8_CFG34_VCSEL_I_11mA 0x0100
137 #define PROXIMITY8_CFG34_VCSEL_I_14mA 0x0200
138 #define PROXIMITY8_CFG34_VCSEL_I_17mA 0x0300
139 #define PROXIMITY8_CFG34_VCSEL_I_20mA 0x0400
140 #define PROXIMITY8_CFG34_AF_MODE_AUTO 0x0000
141 #define PROXIMITY8_CFG34_AF_MODE_FORCE 0x0040
142 #define PROXIMITY8_CFG34_FOR_TRIG_ACTIVE 0x0000
143 #define PROXIMITY8_CFG34_FOR_TRIG_ONE_TIME 0x0020
144 
150 #define PROXIMITY8_DEVICE_ID 0x0588
151 #define PROXIMITY8_DEVICE_SLAVE_ADDRESS 0x60
152  // End group macro
155 // --------------------------------------------------------------- PUBLIC TYPES
164 typedef struct
165 {
166  // Input pins
167 
168  digital_in_t int_pin;
169 
170  // Modules
171 
172  i2c_master_t i2c;
173 
174  // ctx variable
175 
176  uint8_t slave_address;
177 
178 } proximity8_t;
179 
183 typedef struct
184 {
185  // Communication gpio pins
186 
187  pin_name_t scl;
188  pin_name_t sda;
189 
190  // Additional gpio pins
191 
192  pin_name_t int_pin;
193 
194  // static variable
195 
196  uint32_t i2c_speed;
197  uint8_t i2c_address;
198 
200  // End types group
202 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
203 
209 #ifdef __cplusplus
210 extern "C"{
211 #endif
212 
222 
232 
241 
252 void proximity8_generic_write ( proximity8_t *ctx, uint8_t reg, uint16_t *data_buf, uint8_t len );
253 
263 void proximity8_generic_read ( proximity8_t *ctx, uint8_t reg, uint16_t *data_buf );
264 
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 #endif // _PROXIMITY8_H_
280  // End public_function group
283 
284 // ------------------------------------------------------------------------- END
proximity8_init
PROXIMITY8_RETVAL proximity8_init(proximity8_t *ctx, proximity8_cfg_t *cfg)
Initialization function.
proximity8_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity8.h:192
proximity8_cfg_t::sda
pin_name_t sda
Definition: proximity8.h:188
proximity8_t::slave_address
uint8_t slave_address
Definition: proximity8.h:176
proximity8_cfg_t
Click configuration structure definition.
Definition: proximity8.h:184
proximity8_t
Click ctx object definition.
Definition: proximity8.h:165
proximity8_t::int_pin
digital_in_t int_pin
Definition: proximity8.h:168
PROXIMITY8_RETVAL
#define PROXIMITY8_RETVAL
Definition: proximity8.h:72
proximity8_get_interrupt_state
uint8_t proximity8_get_interrupt_state(proximity8_t *ctx)
Get interrupt state on the INT pin.
proximity8_cfg_setup
void proximity8_cfg_setup(proximity8_cfg_t *cfg)
Config Object Initialization function.
proximity8_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity8.h:196
proximity8_generic_read
void proximity8_generic_read(proximity8_t *ctx, uint8_t reg, uint16_t *data_buf)
Generic read function.
proximity8_generic_write
void proximity8_generic_write(proximity8_t *ctx, uint8_t reg, uint16_t *data_buf, uint8_t len)
Generic write function.
proximity8_cfg_t::scl
pin_name_t scl
Definition: proximity8.h:187
proximity8_t::i2c
i2c_master_t i2c
Definition: proximity8.h:172
proximity8_default_cfg
void proximity8_default_cfg(proximity8_t *ctx)
Click Default Configuration function.
proximity8_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity8.h:197