proximity10  2.0.0.0
proximity10.h
Go to the documentation of this file.
1 
2 /*
3  * MikroSDK - MikroE Software Development Kit
4  * Copyright© 2020 MikroElektronika d.o.o.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without restriction,
9  * including without limitation the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
23  * OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
34 // ----------------------------------------------------------------------------
35 
36 #ifndef PROXIMITY10_H
37 #define PROXIMITY10_H
38 
39 #include "drv_digital_out.h"
40 #include "drv_digital_in.h"
41 #include "drv_i2c_master.h"
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define PROXIMITY10_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 PROXIMITY10_RETVAL uint8_t
64 
65 #define PROXIMITY10_OK 0x00
66 #define PROXIMITY10_INIT_ERROR 0xFF
67 
73 #define PROXIMITY10_DEFAULT_DEV_ADDR 0x5A
74 
80 #define PROXIMITY10_PART_ID_REG 0x00
81 #define PROXIMITY10_REV_ID_REG 0x01
82 #define PROXIMITY10_SEQ_ID_REG 0x02
83 #define PROXIMITY10_INT_CFG_REG 0x03
84 #define PROXIMITY10_IRQ_EN_REG 0x04
85 #define PROXIMITY10_IRQ_MODE1_REG 0x05
86 #define PROXIMITY10_IRQ_MODE2_REG 0x06
87 #define PROXIMITY10_HW_KEY_REG 0x07
88 #define PROXIMITY10_MEAS_RATE_REG 0x08
89 #define PROXIMITY10_ALS_RATE_REG 0x09
90 #define PROXIMITY10_PS_RATE_REG 0x0A
91 #define PROXIMITY10_ALS_LOW_TH_REG 0x0B
92 #define PROXIMITY10_ALS_HIGH_TH_REG 0x0D
93 #define PROXIMITY10_PS_LED21_REG 0x0F
94 #define PROXIMITY10_PS_LED3_REG 0x10
95 #define PROXIMITY10_PS1_TH_REG 0x11
96 #define PROXIMITY10_PS2_TH_REG 0x13
97 #define PROXIMITY10_PS3_TH_REG 0x15
98 #define PROXIMITY10_PARAM_WR_REG 0x17
99 #define PROXIMITY10_COMMAND_REG 0x18
100 #define PROXIMITY10_RESPONSE_REG 0x20
101 #define PROXIMITY10_IRQ_STATUS_REG 0x21
102 #define PROXIMITY10_ALS_VIS_DATA_REG 0x22
103 #define PROXIMITY10_ALS_IR_DATA_REG 0x24
104 #define PROXIMITY10_PS1_DATA_REG 0x26
105 #define PROXIMITY10_PS2_DATA_REG 0x28
106 #define PROXIMITY10_PS3_DATA_REG 0x2A
107 #define PROXIMITY10_AUX_DATA_REG 0x2C
108 #define PROXIMITY10_PARAM_RD_REG 0x2E
109 #define PROXIMITY10_CHIP_STATUS_REG 0x30
110 #define PROXIMITY10_ANA_IN_KEY_REG 0x3B
111 
117 #define PROXIMITY10_INT_HOST_CLEAR 0x00
118 #define PROXIMITY10_INT_AUTO_CLEAR 0x02
119 #define PROXIMITY10_INT_PIN_EN 0x01
120 
121 #define PROXIMITY10_CMD_INT_EN 0x20
122 #define PROXIMITY10_PS3_INT_EN 0x10
123 #define PROXIMITY10_PS2_INT_EN 0x08
124 #define PROXIMITY10_PS1_INT_EN 0x04
125 #define PROXIMITY10_ALS_INT1_EN 0x02
126 #define PROXIMITY10_ALS_INT0_EN 0x01
127 #define PROXIMITY10_ALL_INT_DIS 0x00
128 
129 #define PROXIMITY10_PS2_INT_MEAS_COMPLETE 0x00
130 #define PROXIMITY10_PS2_INT_MEAS_CROSS_TH 0x40
131 #define PROXIMITY10_PS2_INT_MEAS_GREATER_TH 0xC0
132 #define PROXIMITY10_PS1_INT_MEAS_COMPLETE 0x00
133 #define PROXIMITY10_PS1_INT_MEAS_CROSS_TH 0x10
134 #define PROXIMITY10_PS1_INT_MEAS_GREATER_TH 0x30
135 #define PROXIMITY10_CMD_INT_RESP_WRITTEN 0x00
136 #define PROXIMITY10_CMD_INT_RESP_ERROR 0x04
137 #define PROXIMITY10_PS3_INT_MEAS_COMPLETE 0x00
138 #define PROXIMITY10_PS3_INT_MEAS_CROSS_TH 0x01
139 #define PROXIMITY10_PS3_INT_MEAS_GREATER_TH 0x03
140 
141 #define PROXIMITY10_HW_KEY 0x17
142 
143 #define PROXIMITY10_DEV_WAKEUP_EVERY_10MS 0x84
144 #define PROXIMITY10_DEV_WAKEUP_EVERY_20MS 0x94
145 #define PROXIMITY10_DEV_WAKEUP_EVERY_100MS 0xB9
146 #define PROXIMITY10_DEV_WAKEUP_EVERY_496MS 0xDF
147 #define PROXIMITY10_DEV_WAKEUP_EVERY_1984MS 0xFF
148 
149 #define PROXIMITY10_AUTONOM_MEAS_DIS 0x00
150 #define PROXIMITY10_MEAS_AFTER_EVERY_WAKEUP 0x08
151 #define PROXIMITY10_MEAS_AFTER_10_TIMES_WAKEUP 0x32
152 #define PROXIMITY10_MEAS_AFTER_100_TIMES_WAKEUP 0x69
153 
154 #define PROXIMITY10_LED_NO_CURRENT 0x00
155 #define PROXIMITY10_LED_MIN_CURRENT 0x01
156 #define PROXIMITY10_LED_MAX_CURRENT 0x0F
157 
163 #define PROXIMITY10_INVALID_CMD_ENCOUNT 0x80
164 #define PROXIMITY10_ADC_OVRFLOW_ENCOUNT_PS1 0x88
165 #define PROXIMITY10_ADC_OVRFLOW_ENCOUNT_PS2 0x89
166 #define PROXIMITY10_ADC_OVRFLOW_ENCOUNT_PS3 0x8A
167 #define PROXIMITY10_ADC_OVRFLOW_ENCOUNT_ALS_VIS 0x8C
168 #define PROXIMITY10_ADC_OVRFLOW_ENCOUNT_ALS_IR 0x8D
169 #define PROXIMITY10_ADC_OVRFLOW_ENCOUNT_AUX 0x8E
170 
176 #define PROXIMITY10_CMD_INT_FLAG 0x20
177 #define PROXIMITY10_PS3_INT_FLAG 0x10
178 #define PROXIMITY10_PS2_INT_FLAG 0x08
179 #define PROXIMITY10_PS1_INT_FLAG 0x04
180 #define PROXIMITY10_ALS_INT_FLAG 0x03
181 #define PROXIMITY10_INT_CLEARED 0x00
182 
183 #define PROXIMITY10_RUNNING_FLAG 0x04
184 #define PROXIMITY10_SUSPEND_FLAG 0x02
185 #define PROXIMITY10_SLEEP_FLAG 0x01
186 
192 #define PROXIMITY10_I2C_ADDR_PARAM 0x00
193 #define PROXIMITY10_CHLIST_PARAM 0x01
194 #define PROXIMITY10_PSLED12_SEL_PARAM 0x02
195 #define PROXIMITY10_PSLED3_SEL_PARAM 0x03
196 #define PROXIMITY10_PS_ENCODING_PARAM 0x05
197 #define PROXIMITY10_ALS_ENCODING_PARAM 0x06
198 #define PROXIMITY10_PS1_ADCMUX_PARAM 0x07
199 #define PROXIMITY10_PS2_ADCMUX_PARAM 0x08
200 #define PROXIMITY10_PS3_ADCMUX_PARAM 0x09
201 #define PROXIMITY10_PS_ADC_COUNT_PARAM 0x0A
202 #define PROXIMITY10_PS_ADC_GAIN_PARAM 0x0B
203 #define PROXIMITY10_PS_ADC_MISC_PARAM 0x0C
204 #define PROXIMITY10_ALS_IR_ADCMUX_PARAM 0x0E
205 #define PROXIMITY10_AUX_ADCMUX_PARAM 0x0F
206 #define PROXIMITY10_ALS_VIS_ADC_COUNT_PARAM 0x10
207 #define PROXIMITY10_ALS_VIS_ADC_GAIN_PARAM 0x11
208 #define PROXIMITY10_ALS_VIS_ADC_MISC_PARAM 0x12
209 #define PROXIMITY10_ALS_HYST_PARAM 0x16
210 #define PROXIMITY10_PS_HYST_PARAM 0x17
211 #define PROXIMITY10_PS_HISTORY_PARAM 0x18
212 #define PROXIMITY10_ALS_HISTORY_PARAM 0x19
213 #define PROXIMITY10_ADC_OFFSET_PARAM 0x1A
214 #define PROXIMITY10_LED_REC_PARAM 0x1C
215 #define PROXIMITY10_ALS_IR_ADC_COUNT_PARAM 0x1D
216 #define PROXIMITY10_ALS_IR_ADC_GAIN_PARAM 0x1E
217 #define PROXIMITY10_ALS_IR_ADC_MISC_PARAM 0x1F
218 
224 #define PROXIMITY10_EN_AUX 0x40
225 #define PROXIMITY10_EN_ALS_IR 0x20
226 #define PROXIMITY10_EN_ALS_VIS 0x10
227 #define PROXIMITY10_EN_PS3 0x04
228 #define PROXIMITY10_EN_PS2 0x02
229 #define PROXIMITY10_EN_PS1 0x01
230 
231 #define PROXIMITY10_NO_LED_DRIVE 0x00
232 #define PROXIMITY10_LED1_DRIVE_EN 0x01
233 #define PROXIMITY10_LED2_DRIVE_EN 0x02
234 #define PROXIMITY10_LED3_DRIVE_EN 0x04
235 
236 #define PROXIMITY10_ADC_REC_1_CLOCK 0x00
237 #define PROXIMITY10_ADC_REC_7_CLOCK 0x10
238 #define PROXIMITY10_ADC_REC_15_CLOCK 0x20
239 #define PROXIMITY10_ADC_REC_31_CLOCK 0x30
240 #define PROXIMITY10_ADC_REC_63_CLOCK 0x40
241 #define PROXIMITY10_ADC_REC_127_CLOCK 0x50
242 #define PROXIMITY10_ADC_REC_255_CLOCK 0x60
243 #define PROXIMITY10_ADC_REC_511_CLOCK 0x70
244 
245 #define PROXIMITY10_ADC_CLOCK_DIV_1 0x00
246 #define PROXIMITY10_ADC_CLOCK_DIV_2 0x01
247 #define PROXIMITY10_ADC_CLOCK_DIV_4 0x02
248 #define PROXIMITY10_ADC_CLOCK_DIV_8 0x03
249 #define PROXIMITY10_ADC_CLOCK_DIV_16 0x04
250 #define PROXIMITY10_ADC_CLOCK_DIV_32 0x05
251 #define PROXIMITY10_ADC_CLOCK_DIV_64 0x06
252 #define PROXIMITY10_ADC_CLOCK_DIV_128 0x07
253 
254 #define PROXIMITY10_NORMAL_SIGNAL_RANGE 0x00
255 #define PROXIMITY10_HIGH_SIGNAL_RANGE 0x20
256 #define PROXIMITY10_RAW_ADC_MEAS_MODE 0x00
257 #define PROXIMITY10_NORMAL_PROX_MEAS_MODE 0x04
258 
259 #define PROXIMITY10_ADC_INPUT_SMALL_IR 0x00
260 #define PROXIMITY10_ADC_INPUT_LARGE_IR 0x03
261 #define PROXIMITY10_ADC_INPUT_VIS_PHOTODIODE 0x02
262 #define PROXIMITY10_ADC_INPUT_NO_PHOTODIODE 0x06
263 #define PROXIMITY10_ADC_INPUT_GND 0x25
264 #define PROXIMITY10_ADC_INPUT_TEMP 0x65
265 #define PROXIMITY10_ADC_INPUT_VDD 0x75
266 
267 #define PROXIMITY10_2_CONS_SAMPLES 0x03
268 #define PROXIMITY10_3_CONS_SAMPLES 0x07
269 #define PROXIMITY10_8_CONS_SAMPLES 0xFF
270 
276 #define PROXIMITY10_PARAM_QUERY_CMD 0x80
277 #define PROXIMITY10_PARAM_SET_CMD 0xA0
278 #define PROXIMITY10_PARAM_AND_CMD 0xC0
279 #define PROXIMITY10_PARAM_OR_CMD 0xE0
280 #define PROXIMITY10_NOP_CMD 0x00
281 #define PROXIMITY10_RESET_CMD 0x01
282 #define PROXIMITY10_BUSADDR_CMD 0x02
283 #define PROXIMITY10_PS_FORCE_CMD 0x05
284 #define PROXIMITY10_ALS_FORCE_CMD 0x06
285 #define PROXIMITY10_PSALS_FORCE_CMD 0x07
286 #define PROXIMITY10_PS_PAUSE_CMD 0x09
287 #define PROXIMITY10_ALS_PAUSE_CMD 0x0A
288 #define PROXIMITY10_PSALS_PAUSE_CMD 0x0B
289 #define PROXIMITY10_PS_AUTO_CMD 0x0D
290 #define PROXIMITY10_ALS_AUTO_CMD 0x0E
291 #define PROXIMITY10_PSALS_AUTO_CMD 0x0F
292 
298 #define PROXIMITY10_INT_CLEAR_DIS 0x00
299 #define PROXIMITY10_INT_CLEAR_EN 0x01
300 #define PROXIMITY10_CLEAR_INT_CMD 0xFF
301 
307 #define PROXIMITY10_OK 0x00
308 #define PROXIMITY10_INVALID_REG_ADDR 0x01
309 #define PROXIMITY10_INVALID_PARAM_ADDR 0x02
310 #define PROXIMITY10_INVALID_CMD 0x03
311  // End group macro
314 // --------------------------------------------------------------- PUBLIC TYPES
323 typedef struct
324 {
325  // Input pins
326 
327  digital_in_t int_pin;
328 
329  // Modules
330 
331  i2c_master_t i2c;
332 
333  // ctx variable
334 
335  uint8_t slave_address;
336 
337 } proximity10_t;
338 
342 typedef struct
343 {
344  // Communication gpio pins
345 
346  pin_name_t scl;
347  pin_name_t sda;
348 
349  // Additional gpio pins
350 
351  pin_name_t int_pin;
352 
353  // static variable
354 
355  uint32_t i2c_speed;
356  uint8_t i2c_address;
357 
359  // End types group
361 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
362 
368 #ifdef __cplusplus
369 extern "C"{
370 #endif
371 
381 
391 
400 
411 uint8_t proximity10_generic_write ( proximity10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
412 
423 uint8_t proximity10_generic_read ( proximity10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
424 
436 uint8_t proximity10_check_int_status ( proximity10_t *ctx, uint8_t bit_mask, uint8_t clear_en );
437 
448 uint8_t proximity10_check_chip_status ( proximity10_t *ctx, uint8_t bit_mask );
449 
460 
473 uint8_t proximity10_send_command ( proximity10_t *ctx, uint8_t prox_command );
474 
487 uint8_t proximity10_param_query ( proximity10_t *ctx, uint8_t param_addr );
488 
501 uint8_t proximity10_param_set ( proximity10_t *ctx, uint8_t param_addr, uint8_t param_value );
502 
515 uint8_t proximity10_param_and ( proximity10_t *ctx, uint8_t param_addr, uint8_t param_value );
516 
529 uint8_t proximity10_param_or ( proximity10_t *ctx, uint8_t param_addr, uint8_t param_value );
530 
531 #ifdef __cplusplus
532 }
533 #endif
534 #endif // _PROXIMITY10_H_
535  // End public_function group
538 
539 // ------------------------------------------------------------------------- END
proximity10_cfg_t::scl
pin_name_t scl
Definition: proximity10.h:346
proximity10_param_or
uint8_t proximity10_param_or(proximity10_t *ctx, uint8_t param_addr, uint8_t param_value)
Parameter OR function.
proximity10_check_chip_status
uint8_t proximity10_check_chip_status(proximity10_t *ctx, uint8_t bit_mask)
Check Chip Status function.
proximity10_t::i2c
i2c_master_t i2c
Definition: proximity10.h:331
proximity10_generic_read
uint8_t proximity10_generic_read(proximity10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
proximity10_cfg_setup
void proximity10_cfg_setup(proximity10_cfg_t *cfg)
Config Object Initialization function.
PROXIMITY10_RETVAL
#define PROXIMITY10_RETVAL
Definition: proximity10.h:63
proximity10_param_and
uint8_t proximity10_param_and(proximity10_t *ctx, uint8_t param_addr, uint8_t param_value)
Parameter AND function.
proximity10_param_query
uint8_t proximity10_param_query(proximity10_t *ctx, uint8_t param_addr)
Parameter Query function.
proximity10_cfg_t
Click configuration structure definition.
Definition: proximity10.h:342
proximity10_generic_write
uint8_t proximity10_generic_write(proximity10_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
proximity10_t::int_pin
digital_in_t int_pin
Definition: proximity10.h:327
proximity10_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity10.h:355
proximity10_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity10.h:356
proximity10_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity10.h:351
proximity10_t::slave_address
uint8_t slave_address
Definition: proximity10.h:335
proximity10_init
PROXIMITY10_RETVAL proximity10_init(proximity10_t *ctx, proximity10_cfg_t *cfg)
Initialization function.
proximity10_check_int_status
uint8_t proximity10_check_int_status(proximity10_t *ctx, uint8_t bit_mask, uint8_t clear_en)
Check INT Flags function.
proximity10_check_int_pin
uint8_t proximity10_check_int_pin(proximity10_t *ctx)
Check INT Pin function.
proximity10_param_set
uint8_t proximity10_param_set(proximity10_t *ctx, uint8_t param_addr, uint8_t param_value)
Parameter Set function.
proximity10_default_cfg
void proximity10_default_cfg(proximity10_t *ctx)
Click Default Configuration function.
proximity10_t
Click ctx object definition.
Definition: proximity10.h:323
proximity10_send_command
uint8_t proximity10_send_command(proximity10_t *ctx, uint8_t prox_command)
Command Send function.
proximity10_cfg_t::sda
pin_name_t sda
Definition: proximity10.h:347