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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define PROXIMITY9_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 PROXIMITY9_RETVAL uint8_t
64 
65 #define PROXIMITY9_OK 0x00
66 #define PROXIMITY9_INIT_ERROR 0xFF
67 
73 #define PROXIMITY9_DEV_ADDR 0x60
74 
80 #define PROXIMITY9_ALS_CONF_REG 0x00
81 #define PROXIMITY9_ALS_THRSHD_H_REG 0x01
82 #define PROXIMITY9_ALS_THRSHD_L_REG 0x02
83 #define PROXIMITY9_PS_CONF_REG 0x03
84 #define PROXIMITY9_PS_MS_REG 0x04
85 #define PROXIMITY9_PS_CANC_REG 0x05
86 #define PROXIMITY9_PS_THRSHD_L_REG 0x06
87 #define PROXIMITY9_PS_THRSHD_H_REG 0x07
88 #define PROXIMITY9_PS_DATA_REG 0x08
89 #define PROXIMITY9_ALS_DATA_REG 0x09
90 #define PROXIMITY9_WHITE_DATA_REG 0x0A
91 #define PROXIMITY9_INT_FLAG_REG 0x0B
92 #define PROXIMITY9_DEV_ID_REG 0x0C
93 
99 #define PROXIMITY9_ALS_IT_80_MS 0x00
100 #define PROXIMITY9_ALS_IT_160_MS 0x40
101 #define PROXIMITY9_ALS_IT_320_MS 0x80
102 #define PROXIMITY9_ALS_IT_640_MS 0xC0
103 #define PROXIMITY9_ALS_PERS_1 0x00
104 #define PROXIMITY9_ALS_PERS_2 0x04
105 #define PROXIMITY9_ALS_PERS_4 0x08
106 #define PROXIMITY9_ALS_PERS_8 0x0C
107 #define PROXIMITY9_ALS_INT_EN 0x02
108 #define PROXIMITY9_ALS_SHUTDOWN 0x01
109 
115 #define PROXIMITY9_PS_IR_ON_1_OFF_40 0x00
116 #define PROXIMITY9_PS_IR_ON_1_OFF_80 0x40
117 #define PROXIMITY9_PS_IR_ON_1_OFF_160 0x80
118 #define PROXIMITY9_PS_IR_ON_1_OFF_320 0xC0
119 #define PROXIMITY9_PS_PERS_1 0x00
120 #define PROXIMITY9_PS_PERS_2 0x10
121 #define PROXIMITY9_PS_PERS_3 0x20
122 #define PROXIMITY9_PS_PERS_4 0x30
123 #define PROXIMITY9_PS_IT_1T 0x00
124 #define PROXIMITY9_PS_IT_1T5 0x02
125 #define PROXIMITY9_PS_IT_2T 0x04
126 #define PROXIMITY9_PS_IT_2T5 0x06
127 #define PROXIMITY9_PS_IT_3T 0x08
128 #define PROXIMITY9_PS_IT_3T5 0x0A
129 #define PROXIMITY9_PS_IT_4T 0x0C
130 #define PROXIMITY9_PS_IT_8T 0x0E
131 #define PROXIMITY9_PS_SHUTDOWN 0x01
132 
133 #define PROXIMITY9_PS_OUTPUT_12BIT 0x0000
134 #define PROXIMITY9_PS_OUTPUT_16BIT 0x0800
135 #define PROXIMITY9_PS_INT_TRIGGER_CLOSE 0x0100
136 #define PROXIMITY9_PS_INT_TRIGGER_AWAY 0x0200
137 #define PROXIMITY9_PS_INT_TRIGGER_BOTH 0x0300
138 
144 #define PROXIMITY9_PS_SMART_PERS_EN 0x10
145 #define PROXIMITY9_PS_ACT_FORCE_EN 0x08
146 #define PROXIMITY9_PS_TRIG_ONE_CYCLE 0x04
147 
148 #define PROXIMITY9_WHITE_CH_DIS 0x8000
149 #define PROXIMITY9_PS_NORMAL_OP_MODE 0x0000
150 #define PROXIMITY9_PS_DET_LOGIC_MODE 0x4000
151 #define PROXIMITY9_LED_I_50_MA 0x0000
152 #define PROXIMITY9_LED_I_75_MA 0x0100
153 #define PROXIMITY9_LED_I_100_MA 0x0200
154 #define PROXIMITY9_LED_I_120_MA 0x0300
155 #define PROXIMITY9_LED_I_140_MA 0x0400
156 #define PROXIMITY9_LED_I_160_MA 0x0500
157 #define PROXIMITY9_LED_I_180_MA 0x0600
158 #define PROXIMITY9_LED_I_200_MA 0x0700
159 
165 #define PROXIMITY9_PS_ENTER_PROT_MODE_FLAG 0x40
166 #define PROXIMITY9_ALS_IF_L_FLAG 0x20
167 #define PROXIMITY9_ALS_IF_H_FLAG 0x10
168 #define PROXIMITY9_PS_IF_CLOSE_FLAG 0x02
169 #define PROXIMITY9_PS_IF_AWAY_FLAG 0x01
170 #define PROXIMITY9_INT_CLEARED 0x00
171 
177 #define PROXIMITY9_INVALID_ADDR 0x01
178 #define PROXIMITY9_OK 0x00
179  // End group macro
182 // --------------------------------------------------------------- PUBLIC TYPES
191 typedef struct
192 {
193  // Input pins
194 
195  digital_in_t int_pin;
196 
197  // Modules
198 
199  i2c_master_t i2c;
200 
201  // ctx variable
202 
203  uint8_t slave_address;
204 
205  float als_sens;
206 
207 } proximity9_t;
208 
212 typedef struct
213 {
214  // Communication gpio pins
215 
216  pin_name_t scl;
217  pin_name_t sda;
218 
219  // Additional gpio pins
220 
221  pin_name_t int_pin;
222 
223  // static variable
224 
225  uint32_t i2c_speed;
226  uint8_t i2c_address;
227 
229  // End types group
231 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
232 
238 #ifdef __cplusplus
239 extern "C"{
240 #endif
241 
251 
261 
288 
299 void proximity9_generic_write ( proximity9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
300 
312 void proximity9_generic_read ( proximity9_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
313 
325 PROXIMITY9_RETVAL proximity9_read_register ( proximity9_t *ctx, uint8_t reg_addr, uint16_t *data_out );
326 
338 PROXIMITY9_RETVAL proximity9_write_register ( proximity9_t *ctx, uint8_t reg_addr, uint16_t data_in );
339 
350 
361 uint8_t proximity9_check_int_flag ( proximity9_t *ctx, uint8_t bit_mask );
362 
373 
374 #ifdef __cplusplus
375 }
376 #endif
377 #endif // _PROXIMITY9_H_
378  // End public_function group
381 
382 // ------------------------------------------------------------------------- END
proximity9_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity9.h:221
proximity9_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity9.h:226
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:205
proximity9_t::i2c
i2c_master_t i2c
Definition: proximity9.h:199
proximity9_cfg_t
Click configuration structure definition.
Definition: proximity9.h:213
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:192
proximity9_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity9.h:225
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:203
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:63
proximity9_cfg_t::sda
pin_name_t sda
Definition: proximity9.h:217
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:216
proximity9_t::int_pin
digital_in_t int_pin
Definition: proximity9.h:195