proximity9  2.0.0.0
proximity9.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 PROXIMITY9_H
36 #define PROXIMITY9_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_in.h"
49 #include "drv_i2c_master.h"
50 
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define PROXIMITY9_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 PROXIMITY9_RETVAL uint8_t
73 
74 #define PROXIMITY9_OK 0x00
75 #define PROXIMITY9_INIT_ERROR 0xFF
76 
82 #define PROXIMITY9_DEV_ADDR 0x60
83 
89 #define PROXIMITY9_ALS_CONF_REG 0x00
90 #define PROXIMITY9_ALS_THRSHD_H_REG 0x01
91 #define PROXIMITY9_ALS_THRSHD_L_REG 0x02
92 #define PROXIMITY9_PS_CONF_REG 0x03
93 #define PROXIMITY9_PS_MS_REG 0x04
94 #define PROXIMITY9_PS_CANC_REG 0x05
95 #define PROXIMITY9_PS_THRSHD_L_REG 0x06
96 #define PROXIMITY9_PS_THRSHD_H_REG 0x07
97 #define PROXIMITY9_PS_DATA_REG 0x08
98 #define PROXIMITY9_ALS_DATA_REG 0x09
99 #define PROXIMITY9_WHITE_DATA_REG 0x0A
100 #define PROXIMITY9_INT_FLAG_REG 0x0B
101 #define PROXIMITY9_DEV_ID_REG 0x0C
102 
108 #define PROXIMITY9_ALS_IT_80_MS 0x00
109 #define PROXIMITY9_ALS_IT_160_MS 0x40
110 #define PROXIMITY9_ALS_IT_320_MS 0x80
111 #define PROXIMITY9_ALS_IT_640_MS 0xC0
112 #define PROXIMITY9_ALS_PERS_1 0x00
113 #define PROXIMITY9_ALS_PERS_2 0x04
114 #define PROXIMITY9_ALS_PERS_4 0x08
115 #define PROXIMITY9_ALS_PERS_8 0x0C
116 #define PROXIMITY9_ALS_INT_EN 0x02
117 #define PROXIMITY9_ALS_SHUTDOWN 0x01
118 
124 #define PROXIMITY9_PS_IR_ON_1_OFF_40 0x00
125 #define PROXIMITY9_PS_IR_ON_1_OFF_80 0x40
126 #define PROXIMITY9_PS_IR_ON_1_OFF_160 0x80
127 #define PROXIMITY9_PS_IR_ON_1_OFF_320 0xC0
128 #define PROXIMITY9_PS_PERS_1 0x00
129 #define PROXIMITY9_PS_PERS_2 0x10
130 #define PROXIMITY9_PS_PERS_3 0x20
131 #define PROXIMITY9_PS_PERS_4 0x30
132 #define PROXIMITY9_PS_IT_1T 0x00
133 #define PROXIMITY9_PS_IT_1T5 0x02
134 #define PROXIMITY9_PS_IT_2T 0x04
135 #define PROXIMITY9_PS_IT_2T5 0x06
136 #define PROXIMITY9_PS_IT_3T 0x08
137 #define PROXIMITY9_PS_IT_3T5 0x0A
138 #define PROXIMITY9_PS_IT_4T 0x0C
139 #define PROXIMITY9_PS_IT_8T 0x0E
140 #define PROXIMITY9_PS_SHUTDOWN 0x01
141 
142 #define PROXIMITY9_PS_OUTPUT_12BIT 0x0000
143 #define PROXIMITY9_PS_OUTPUT_16BIT 0x0800
144 #define PROXIMITY9_PS_INT_TRIGGER_CLOSE 0x0100
145 #define PROXIMITY9_PS_INT_TRIGGER_AWAY 0x0200
146 #define PROXIMITY9_PS_INT_TRIGGER_BOTH 0x0300
147 
153 #define PROXIMITY9_PS_SMART_PERS_EN 0x10
154 #define PROXIMITY9_PS_ACT_FORCE_EN 0x08
155 #define PROXIMITY9_PS_TRIG_ONE_CYCLE 0x04
156 
157 #define PROXIMITY9_WHITE_CH_DIS 0x8000
158 #define PROXIMITY9_PS_NORMAL_OP_MODE 0x0000
159 #define PROXIMITY9_PS_DET_LOGIC_MODE 0x4000
160 #define PROXIMITY9_LED_I_50_MA 0x0000
161 #define PROXIMITY9_LED_I_75_MA 0x0100
162 #define PROXIMITY9_LED_I_100_MA 0x0200
163 #define PROXIMITY9_LED_I_120_MA 0x0300
164 #define PROXIMITY9_LED_I_140_MA 0x0400
165 #define PROXIMITY9_LED_I_160_MA 0x0500
166 #define PROXIMITY9_LED_I_180_MA 0x0600
167 #define PROXIMITY9_LED_I_200_MA 0x0700
168 
174 #define PROXIMITY9_PS_ENTER_PROT_MODE_FLAG 0x40
175 #define PROXIMITY9_ALS_IF_L_FLAG 0x20
176 #define PROXIMITY9_ALS_IF_H_FLAG 0x10
177 #define PROXIMITY9_PS_IF_CLOSE_FLAG 0x02
178 #define PROXIMITY9_PS_IF_AWAY_FLAG 0x01
179 #define PROXIMITY9_INT_CLEARED 0x00
180 
186 #define PROXIMITY9_INVALID_ADDR 0x01
187 #define PROXIMITY9_OK 0x00
188  // End group macro
191 // --------------------------------------------------------------- PUBLIC TYPES
200 typedef struct
201 {
202  // Input pins
203 
204  digital_in_t int_pin;
205 
206  // Modules
207 
208  i2c_master_t i2c;
209 
210  // ctx variable
211 
212  uint8_t slave_address;
213 
214  float als_sens;
215 
216 } proximity9_t;
217 
221 typedef struct
222 {
223  // Communication gpio pins
224 
225  pin_name_t scl;
226  pin_name_t sda;
227 
228  // Additional gpio pins
229 
230  pin_name_t int_pin;
231 
232  // static variable
233 
234  uint32_t i2c_speed;
235  uint8_t i2c_address;
236 
238  // End types group
240 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
241 
247 #ifdef __cplusplus
248 extern "C"{
249 #endif
250 
260 
270 
297 
308 void proximity9_generic_write ( proximity9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
309 
321 void proximity9_generic_read ( proximity9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
322 
334 PROXIMITY9_RETVAL proximity9_read_register ( proximity9_t *ctx, uint8_t reg_addr, uint16_t *data_out );
335 
347 PROXIMITY9_RETVAL proximity9_write_register ( proximity9_t *ctx, uint8_t reg_addr, uint16_t data_in );
348 
359 
370 uint8_t proximity9_check_int_flag ( proximity9_t *ctx, uint8_t bit_mask );
371 
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 #endif // _PROXIMITY9_H_
387  // End public_function group
390 
391 // ------------------------------------------------------------------------- END
proximity9_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity9.h:230
proximity9_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity9.h:235
proximity9_check_int_pin
uint8_t proximity9_check_int_pin(proximity9_t *ctx)
INT Pin Check function.
proximity9_t::als_sens
float als_sens
Definition: proximity9.h:214
proximity9_t::i2c
i2c_master_t i2c
Definition: proximity9.h:208
proximity9_cfg_t
Click configuration structure definition.
Definition: proximity9.h:222
proximity9_generic_read
void proximity9_generic_read(proximity9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
proximity9_t
Click ctx object definition.
Definition: proximity9.h:201
proximity9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity9.h:234
proximity9_default_cfg
void proximity9_default_cfg(proximity9_t *ctx)
Click Default Configuration function.
proximity9_init
PROXIMITY9_RETVAL proximity9_init(proximity9_t *ctx, proximity9_cfg_t *cfg)
Initialization function.
proximity9_read_register
PROXIMITY9_RETVAL proximity9_read_register(proximity9_t *ctx, uint8_t reg_addr, uint16_t *data_out)
Generic Read function.
proximity9_t::slave_address
uint8_t slave_address
Definition: proximity9.h:212
proximity9_cfg_setup
void proximity9_cfg_setup(proximity9_cfg_t *cfg)
Config Object Initialization function.
proximity9_write_register
PROXIMITY9_RETVAL proximity9_write_register(proximity9_t *ctx, uint8_t reg_addr, uint16_t data_in)
Generic Write function.
proximity9_check_int_flag
uint8_t proximity9_check_int_flag(proximity9_t *ctx, uint8_t bit_mask)
INT Flag Check function.
proximity9_get_als_lux
float proximity9_get_als_lux(proximity9_t *ctx)
ALS Get function.
PROXIMITY9_RETVAL
#define PROXIMITY9_RETVAL
Definition: proximity9.h:72
proximity9_cfg_t::sda
pin_name_t sda
Definition: proximity9.h:226
proximity9_generic_write
void proximity9_generic_write(proximity9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
proximity9_cfg_t::scl
pin_name_t scl
Definition: proximity9.h:225
proximity9_t::int_pin
digital_in_t int_pin
Definition: proximity9.h:204