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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_in.h"
53 #include "drv_i2c_master.h"
54 
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define PROXIMITY9_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
70 
76 #define PROXIMITY9_RETVAL uint8_t
77 
78 #define PROXIMITY9_OK 0x00
79 #define PROXIMITY9_INIT_ERROR 0xFF
80 
86 #define PROXIMITY9_DEV_ADDR 0x60
87 
93 #define PROXIMITY9_ALS_CONF_REG 0x00
94 #define PROXIMITY9_ALS_THRSHD_H_REG 0x01
95 #define PROXIMITY9_ALS_THRSHD_L_REG 0x02
96 #define PROXIMITY9_PS_CONF_REG 0x03
97 #define PROXIMITY9_PS_MS_REG 0x04
98 #define PROXIMITY9_PS_CANC_REG 0x05
99 #define PROXIMITY9_PS_THRSHD_L_REG 0x06
100 #define PROXIMITY9_PS_THRSHD_H_REG 0x07
101 #define PROXIMITY9_PS_DATA_REG 0x08
102 #define PROXIMITY9_ALS_DATA_REG 0x09
103 #define PROXIMITY9_WHITE_DATA_REG 0x0A
104 #define PROXIMITY9_INT_FLAG_REG 0x0B
105 #define PROXIMITY9_DEV_ID_REG 0x0C
106 
112 #define PROXIMITY9_ALS_IT_80_MS 0x00
113 #define PROXIMITY9_ALS_IT_160_MS 0x40
114 #define PROXIMITY9_ALS_IT_320_MS 0x80
115 #define PROXIMITY9_ALS_IT_640_MS 0xC0
116 #define PROXIMITY9_ALS_PERS_1 0x00
117 #define PROXIMITY9_ALS_PERS_2 0x04
118 #define PROXIMITY9_ALS_PERS_4 0x08
119 #define PROXIMITY9_ALS_PERS_8 0x0C
120 #define PROXIMITY9_ALS_INT_EN 0x02
121 #define PROXIMITY9_ALS_SHUTDOWN 0x01
122 
128 #define PROXIMITY9_PS_IR_ON_1_OFF_40 0x00
129 #define PROXIMITY9_PS_IR_ON_1_OFF_80 0x40
130 #define PROXIMITY9_PS_IR_ON_1_OFF_160 0x80
131 #define PROXIMITY9_PS_IR_ON_1_OFF_320 0xC0
132 #define PROXIMITY9_PS_PERS_1 0x00
133 #define PROXIMITY9_PS_PERS_2 0x10
134 #define PROXIMITY9_PS_PERS_3 0x20
135 #define PROXIMITY9_PS_PERS_4 0x30
136 #define PROXIMITY9_PS_IT_1T 0x00
137 #define PROXIMITY9_PS_IT_1T5 0x02
138 #define PROXIMITY9_PS_IT_2T 0x04
139 #define PROXIMITY9_PS_IT_2T5 0x06
140 #define PROXIMITY9_PS_IT_3T 0x08
141 #define PROXIMITY9_PS_IT_3T5 0x0A
142 #define PROXIMITY9_PS_IT_4T 0x0C
143 #define PROXIMITY9_PS_IT_8T 0x0E
144 #define PROXIMITY9_PS_SHUTDOWN 0x01
145 
146 #define PROXIMITY9_PS_OUTPUT_12BIT 0x0000
147 #define PROXIMITY9_PS_OUTPUT_16BIT 0x0800
148 #define PROXIMITY9_PS_INT_TRIGGER_CLOSE 0x0100
149 #define PROXIMITY9_PS_INT_TRIGGER_AWAY 0x0200
150 #define PROXIMITY9_PS_INT_TRIGGER_BOTH 0x0300
151 
157 #define PROXIMITY9_PS_SMART_PERS_EN 0x10
158 #define PROXIMITY9_PS_ACT_FORCE_EN 0x08
159 #define PROXIMITY9_PS_TRIG_ONE_CYCLE 0x04
160 
161 #define PROXIMITY9_WHITE_CH_DIS 0x8000
162 #define PROXIMITY9_PS_NORMAL_OP_MODE 0x0000
163 #define PROXIMITY9_PS_DET_LOGIC_MODE 0x4000
164 #define PROXIMITY9_LED_I_50_MA 0x0000
165 #define PROXIMITY9_LED_I_75_MA 0x0100
166 #define PROXIMITY9_LED_I_100_MA 0x0200
167 #define PROXIMITY9_LED_I_120_MA 0x0300
168 #define PROXIMITY9_LED_I_140_MA 0x0400
169 #define PROXIMITY9_LED_I_160_MA 0x0500
170 #define PROXIMITY9_LED_I_180_MA 0x0600
171 #define PROXIMITY9_LED_I_200_MA 0x0700
172 
178 #define PROXIMITY9_PS_ENTER_PROT_MODE_FLAG 0x40
179 #define PROXIMITY9_ALS_IF_L_FLAG 0x20
180 #define PROXIMITY9_ALS_IF_H_FLAG 0x10
181 #define PROXIMITY9_PS_IF_CLOSE_FLAG 0x02
182 #define PROXIMITY9_PS_IF_AWAY_FLAG 0x01
183 #define PROXIMITY9_INT_CLEARED 0x00
184 
190 #define PROXIMITY9_INVALID_ADDR 0x01
191 #define PROXIMITY9_OK 0x00
192  // End group macro
195 // --------------------------------------------------------------- PUBLIC TYPES
204 typedef struct
205 {
206  // Input pins
207 
208  digital_in_t int_pin;
209 
210  // Modules
211 
212  i2c_master_t i2c;
213 
214  // ctx variable
215 
216  uint8_t slave_address;
217 
218  float als_sens;
219 
220 } proximity9_t;
221 
225 typedef struct
226 {
227  // Communication gpio pins
228 
229  pin_name_t scl;
230  pin_name_t sda;
231 
232  // Additional gpio pins
233 
234  pin_name_t int_pin;
235 
236  // static variable
237 
238  uint32_t i2c_speed;
239  uint8_t i2c_address;
240 
242  // End types group
244 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
245 
251 #ifdef __cplusplus
252 extern "C"{
253 #endif
254 
264 
274 
301 
312 void proximity9_generic_write ( proximity9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
313 
325 void proximity9_generic_read ( proximity9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
326 
338 PROXIMITY9_RETVAL proximity9_read_register ( proximity9_t *ctx, uint8_t reg_addr, uint16_t *data_out );
339 
351 PROXIMITY9_RETVAL proximity9_write_register ( proximity9_t *ctx, uint8_t reg_addr, uint16_t data_in );
352 
363 
374 uint8_t proximity9_check_int_flag ( proximity9_t *ctx, uint8_t bit_mask );
375 
386 
387 #ifdef __cplusplus
388 }
389 #endif
390 #endif // _PROXIMITY9_H_
391  // End public_function group
394 
395 // ------------------------------------------------------------------------- END
proximity9_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity9.h:234
proximity9_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity9.h:239
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:218
proximity9_t::i2c
i2c_master_t i2c
Definition: proximity9.h:212
proximity9_cfg_t
Click configuration structure definition.
Definition: proximity9.h:226
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:205
proximity9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity9.h:238
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:216
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:76
proximity9_cfg_t::sda
pin_name_t sda
Definition: proximity9.h:230
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:229
proximity9_t::int_pin
digital_in_t int_pin
Definition: proximity9.h:208