proxfusion2 2.0.0.0
proxfusion2.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 PROXFUSION2_H
36#define PROXFUSION2_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_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define PROXFUSION2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define PROXFUSION2_OK 0
77#define PROXFUSION2_ERROR -1
84#define PROXFUSION2_REG_PRODUCT_NUMBER 0x00
85#define PROXFUSION2_REG_SOFTWARE_NUMBER 0x01
86#define PROXFUSION2_REG_HARDWARE_NUMBER 0x02
93#define PROXFUSION2_REG_SYSTEM_FLAGS 0x10
94#define PROXFUSION2_REG_GLOBAL_EVENTS 0x11
95#define PROXFUSION2_REG_PROXFUSION_UI_FLAGS 0x12
96#define PROXFUSION2_REG_HYSTERESIS_UI_FLAGS 0x13
97#define PROXFUSION2_REG_HYSTERESIS_UI_OUTPUT_LSB 0x14
98#define PROXFUSION2_REG_HYSTERESIS_UI_OUTPUT_MSB 0x15
99#define PROXFUSION2_REG_ALS_UI_FLAGS 0x16
100#define PROXFUSION2_REG_ALS_UI_OUTPUT_LSB 0x17
101#define PROXFUSION2_REG_ALS_UI_OUTPUT_MSB 0x18
102#define PROXFUSION2_REG_HALL_EFFECT_UI_FLAGS 0x19
103#define PROXFUSION2_REG_HALL_EFFECT_UI_OUTPUT_LSB 0x1A
104#define PROXFUSION2_REG_HALL_EFFECT_UI_OUTPUT_MSB 0x1B
105#define PROXFUSION2_REG_TEMPERATURE_UI_FLAGS 0x1C
106#define PROXFUSION2_REG_TEMPERATURE_UI_OUTPUT_LSB 0x1D
107#define PROXFUSION2_REG_TEMPERATURE_UI_OUTPUT_MSB 0x1E
114#define PROXFUSION2_REG_CHANNEL_COUNTS_CH0_LSB 0x20
115#define PROXFUSION2_REG_CHANNEL_COUNTS_CH0_MSB 0x21
116#define PROXFUSION2_REG_CHANNEL_COUNTS_CH1_LSB 0x22
117#define PROXFUSION2_REG_CHANNEL_COUNTS_CH1_MSB 0x23
118#define PROXFUSION2_REG_CHANNEL_COUNTS_CH2_LSB 0x24
119#define PROXFUSION2_REG_CHANNEL_COUNTS_CH2_MSB 0x25
120#define PROXFUSION2_REG_CHANNEL_COUNTS_CH3_LSB 0x26
121#define PROXFUSION2_REG_CHANNEL_COUNTS_CH3_MSB 0x27
122#define PROXFUSION2_REG_CHANNEL_COUNTS_CH4_LSB 0x28
123#define PROXFUSION2_REG_CHANNEL_COUNTS_CH4_MSB 0x29
124#define PROXFUSION2_REG_CHANNEL_COUNTS_CH5_LSB 0x2A
125#define PROXFUSION2_REG_CHANNEL_COUNTS_CH5_MSB 0x2B
126#define PROXFUSION2_REG_CHANNEL_COUNTS_CH6_LSB 0x2C
127#define PROXFUSION2_REG_CHANNEL_COUNTS_CH6_MSB 0x2D
134#define PROXFUSION2_REG_LTA_VALUES_CH0_LSB 0x30
135#define PROXFUSION2_REG_LTA_VALUES_CH0_MSB 0x31
136#define PROXFUSION2_REG_LTA_VALUES_CH1_LSB 0x32
137#define PROXFUSION2_REG_LTA_VALUES_CH1_MSB 0x33
144#define PROXFUSION2_REG_PROXFUSION_SETTINGS_00 0x40
145#define PROXFUSION2_REG_PROXFUSION_SETTINGS_01 0x41
146#define PROXFUSION2_REG_PROXFUSION_SETTINGS_10 0x42
147#define PROXFUSION2_REG_PROXFUSION_SETTINGS_11 0x43
148
149#define PROXFUSION2_REG_PROXFUSION_SETTINGS_20 0x44
150#define PROXFUSION2_REG_PROXFUSION_SETTINGS_21 0x45
151#define PROXFUSION2_REG_PROXFUSION_SETTINGS_30 0x46
152#define PROXFUSION2_REG_PROXFUSION_SETTINGS_31 0x47
153#define PROXFUSION2_REG_PROXFUSION_SETTINGS_4 0x48
160#define PROXFUSION2_REG_PROX_THRESHOLD_CH0 0x50
161#define PROXFUSION2_REG_PROX_THRESHOLD_CH1 0x52
162#define PROXFUSION2_REG_TOUCH_THRESHOLD_CH0 0x51
163#define PROXFUSION2_REG_TOUCH_THRESHOLD_CH1 0x53
164#define PROXFUSION2_REG_DISCRETE_UI_HALT_TIME 0x54
171#define PROXFUSION2_REG_HYSTERESIS_UI_SETTINGS 0x60
172#define PROXFUSION2_REG_HYSTERESIS_UI_FILTER_HALT_THRESHOLD 0x61
173#define PROXFUSION2_REG_HYSTERESIS_UI_PROXIMITY_THRESHOLD 0x62
174#define PROXFUSION2_REG_HYSTERESIS_UI_TOUCH_THRESHOLD 0x63
181#define PROXFUSION2_REG_ALS_settings_0 0x70
182#define PROXFUSION2_REG_ALS_settings_1 0x71
183#define PROXFUSION2_REG_ALS_SETTINGS_FILTER_SPEED 0x72
184#define PROXFUSION2_REG_MULTIPLIERS_CH34 0x73
191#define PROXFUSION2_REG_ALS_DARK_THRESHOLD 0x80
192#define PROXFUSION2_REG_ALS_LIGHT_THRESHOLD 0x81
193#define PROXFUSION2_REG_ALS_RAW_TO_LUX_DIVIDER 0x82
194#define PROXFUSION2_REG_ALS_IR_COMPENSATION 0x83
201#define PROXFUSION2_REG_HALL_EFFECT_SETTINGS_0 0x90
202#define PROXFUSION2_REG_HALL_EFFECT_SETTINGS_1 0x91
203#define PROXFUSION2_REG_COMPENSATION_CH56 0x92
204#define PROXFUSION2_REG_MULTIPLIERS_CH56 0x93
211#define PROXFUSION2_REG_HALL_EFFECT_UI_SETTINGS 0xA0
212#define PROXFUSION2_REG_HALL_PROXIMITY_THRESHOLD 0xA1
213#define PROXFUSION2_REG_HALL_TOUCH_THRESHOLD 0xA2
220#define PROXFUSION2_REG_TEMPERATURE_UI_SETTINGS 0xC0
221#define PROXFUSION2_REG_MULTIPLIER_CH2 0xC1
222#define PROXFUSION2_REG_TEMPERATURE_CALIBRATION_0 0xC2
223#define PROXFUSION2_REG_TEMPERATURE_CALIBRATION_1 0xC3
230#define PROXFUSION2_REG_SYSTEM_SETTINGS 0xD0
231#define PROXFUSION2_REG_ACTIVE_CHANNELS 0xD1
232#define PROXFUSION2_REG_POWER_MODE_SETTINGS 0xD2
233#define PROXFUSION2_REG_NORMAL_POWER_MODE_REPORT_RATE 0xD3
234#define PROXFUSION2_REG_LOW_POWER_MODE_REPORT_RATE 0xD4
235#define PROXFUSION2_REG_UALTRA_LOW_POWER_MODE_REPORT_RATE 0xD5
236#define PROXFUSION2_REG_AUTO_MODE_TIMER 0xD6
237#define PROXFUSION2_REG_GLOBAL_EVENT_MASK 0xD7
238#define PROXFUSION2_REG_RDY_TIMEOUT_PERIOD 0xD8
239#define PROXFUSION2_REG_I2C_SETTINGS 0xD9
246#define PROXFUSION2_SF_SHOW_RESET 0x80
247#define PROXFUSION2_SF_NO_RESET 0x00
248#define PROXFUSION2_SF_NORMAL_MODE 0x00
249#define PROXFUSION2_SF_ULTRA_LOW_POWER_MODE 0x10
250#define PROXFUSION2_SF_LOW_POWER_MODE 0x08
251#define PROXFUSION2_SF_HALT_MODE 0x00
252#define PROXFUSION2_SF_ACTIVE_ATI 0x04
253#define PROXFUSION2_SF_NO_ATI 0x00
254#define PROXFUSION2_SF_NO_NEW_EVENT 0x00
255#define PROXFUSION2_SF_NEW_EVENT 0x02
256#define PROXFUSION2_SF_NOT_PERFORMING_NM_UPDATE 0x00
257#define PROXFUSION2_SF_BUSY_PERFORMING_NM_UPDATE 0x02
264#define PROXFUSION2_GE_POWER_MODE_EVENT_ACTIVE 0x40
265#define PROXFUSION2_GE_SYS_EVENT_ACTIVE 0x20
266#define PROXFUSION2_GE_TEMP_EVENT_ACTIVE 0x10
267#define PROXFUSION2_GE_HYSTERESIS_UI_EVENT_ACTIVE 0x08
268#define PROXFUSION2_GE_ALS_EVENT_ACTIVE 0x04
269#define PROXFUSION2_GE_HALL_EVENT_ACTIVE 0x02
270#define PROXFUSION2_GE_PROXSENSE_EVENT_ACTIVE 0x01
277#define PROXFUSION2_PFUIF_CH1_TOUCH_DELTA_BELOW 0x00
278#define PROXFUSION2_PFUIF_CH0_TOUCH_DELTA_BELOW 0x00
279#define PROXFUSION2_PFUIF_CH1_TOUCH_DELTA_ABOVE 0x20
280#define PROXFUSION2_PFUIF_CH0_TOUCH_DELTA_ABOVE 0x10
281#define PROXFUSION2_PFUIF_CH1_PROXIMITY_DELTA_BELOW 0x00
282#define PROXFUSION2_PFUIF_CH0_PROXIMITY_DELTA_BELOW 0x00
283#define PROXFUSION2_PFUIF_CH1_PROXIMITY_DELTA_ABOVE 0x02
284#define PROXFUSION2_PFUIF_CH0_PROXIMITY_DELTA_ABOVE 0x01
291#define PROXFUSION2_HIUIF_COUNTS_RISE_ABOVE_THE_LTA 0x00
292#define PROXFUSION2_HIUIF_COUNTS_FALL_BELOW_THE_LTA 0x04
293#define PROXFUSION2_HIUIF_DELTA_BELOW_TOUCH_THRESHOLD 0x00
294#define PROXFUSION2_HIUIF_DELTA_ABOVE_TOUCH_THRESHOLD 0x02
295#define PROXFUSION2_HIUIF_DELTA_BELOW_PROX_THRESHOLD 0x00
296#define PROXFUSION2_HIUIF_DELTA_ABOVE_PROX_THRESHOLD 0x01
303#define PROXFUSION2_ALSUIF_LIGHT_INDICATION 0x00
304#define PROXFUSION2_ALSUIF_DARK_INDICATION 0x80
311#define PROXFUSION2_HEUIF_FIELD_STRENGTH_BELOW_TOUCH_LEVEL 0x00
312#define PROXFUSION2_HEUIF_FIELD_STRENGTH_ABOVE_TOUCH_LEVEL 0x04
313#define PROXFUSION2_HEUIF_FIELD_STRENGTH_BELOW_PROX_LEVEL 0x00
314#define PROXFUSION2_HEUIF_FIELD_STRENGTH_ABOVE_PROX_LEVEL 0x02
315#define PROXFUSION2_HEUIF_NORTH_FIELD_PRESENT 0x00
316#define PROXFUSION2_HEUIF_SOUTH_FIELD_PRESENT 0x01
323#define PROXFUSION2_TUIF_TEMPERATURE_BELOW_TRIP_LEVEL 0x00
324#define PROXFUSION2_TUIF_TEMPERATURE_ABOVE_TRIP_LEVEL 0x80
331#define PROXFUSION2_PFS00_CAPACITIVE_SENSING_MODE 0x00
332#define PROXFUSION2_PFS00_TX0_AND_TX1_DISABLED 0x00
333#define PROXFUSION2_PFS00_RX0_AND_RX1_DISABLED 0x00
334#define PROXFUSION2_PFS00_RX0_ENABLE 0x01
335#define PROXFUSION2_PFS00_RX1_ENABLE 0x02
336#define PROXFUSION2_PFS00_RX0_AND_RX1_ENABLE 0x03
343#define PROXFUSION2_PFS01_INDUCTIVE_SENSOR_MODE 0x80
344#define PROXFUSION2_PFS01_MULTIPLIER_RANGE_LARGE 0x00
345#define PROXFUSION2_PFS01_MULTIPLIER_RANGE_SMALL 0x01
346#define PROXFUSION2_PFS01_TX0_AND_TX1_DISABLED 0x00
347#define PROXFUSION2_PFS01_TX0_AND_TX1_ENABLE 0x03
354#define PROXFUSION2_PFS10_CAPACITOR_15pF 0x00
355#define PROXFUSION2_PFS10_CAPACITOR_60pF 0x40
356#define PROXFUSION2_PFS10_FREQUENCY_DIVIDER_1_2 0x00
357#define PROXFUSION2_PFS10_FREQUENCY_DIVIDER_1_4 0x10
358#define PROXFUSION2_PFS10_FREQUENCY_DIVIDER_1_8 0x20
359#define PROXFUSION2_PFS10_FREQUENCY_DIVIDER_1_16 0x30
360#define PROXFUSION2_PFS10_ATI_MODE_DISABLE 0x00
361#define PROXFUSION2_PFS10_PARTIAL_ATI 0x01
362#define PROXFUSION2_PFS10_SEMI_PARTIAL_ATI 0x02
363#define PROXFUSION2_PFS10_FULL_ATI 0x03
370#define PROXFUSION2_PFS11_CAPACITOR_15pF 0x00
371#define PROXFUSION2_PFS11_CAPACITOR_60pF 0x40
372#define PROXFUSION2_PFS11_FREQUENCY_DIVIDER_1_2 0x00
373#define PROXFUSION2_PFS11_FREQUENCY_DIVIDER_1_4 0x10
374#define PROXFUSION2_PFS11_FREQUENCY_DIVIDER_1_8 0x20
375#define PROXFUSION2_PFS11_FREQUENCY_DIVIDER_1_16 0x30
376#define PROXFUSION2_PFS11_INTERNAL_RESISTOR_2_5uA_88kOhm 0x00
377#define PROXFUSION2_PFS11_INTERNAL_RESISTOR_5uA_66kOhm 0x04
378#define PROXFUSION2_PFS11_INTERNAL_RESISTOR_10uA_44kOhm 0x08
379#define PROXFUSION2_PFS11_INTERNAL_RESISTOR_20uA_22kOhm 0x0C
380#define PROXFUSION2_PFS11_ATI_MODE_DISABLE 0x00
381#define PROXFUSION2_PFS11_PARTIAL_ATI 0x01
382#define PROXFUSION2_PFS11_SEMI_PARTIAL_ATI 0x02
383#define PROXFUSION2_PFS11_FULL_ATI 0x03
390#define PROXFUSION2_PFS201_ATI_BASE_VALUE_75 0x00
391#define PROXFUSION2_PFS201_ATI_BASE_VALUE_100 0x40
392#define PROXFUSION2_PFS201_ATI_BASE_VALUE_150 0x80
393#define PROXFUSION2_PFS201_ATI_BASE_VALUE_200 0xC0
400#define PROXFUSION2_PFS4_HYSTERESIS_UI_DISABLED 0x00
401#define PROXFUSION2_PFS4_HYSTERESIS_UI_ENABLE 0x40
402#define PROXFUSION2_PFS4_BIDIRECTIONAL_DETECTION_DISABLED 0x00
403#define PROXFUSION2_PFS4_BIDIRECTIONAL_DETECTION_ENABLE 0x20
404#define PROXFUSION2_PFS4_AC_FILTER_ENABLED 0x00
405#define PROXFUSION2_PFS4_AC_FILTER_DISABLED 0x10
406#define PROXFUSION2_PFS4_LONG_TERM_AVERAGE_BETA_VALUE_7 0x00
407#define PROXFUSION2_PFS4_LONG_TERM_AVERAGE_BETA_VALUE_8 0x04
408#define PROXFUSION2_PFS4_LONG_TERM_AVERAGE_BETA_VALUE_9 0x08
409#define PROXFUSION2_PFS4_LONG_TERM_AVERAGE_BETA_VALUE_10 0x0C
410#define PROXFUSION2_PFS4_AC_FILTER_BETA_VALUE_1 0x00
411#define PROXFUSION2_PFS4_AC_FILTER_BETA_VALUE_2 0x01
412#define PROXFUSION2_PFS4_AC_FILTER_BETA_VALUE_3 0x02
413#define PROXFUSION2_PFS4_AC_FILTER_BETA_VALUE_4 0x03
420#define PROXFUSION2_HIUIS_TOUCH_HYSTERESIS_DISABLED 0x00
421#define PROXFUSION2_HIUIS_TOUCH_HYSTERESIS_1_8_OF_THRESHOLD 0x20
422#define PROXFUSION2_HIUIS_TOUCH_HYSTERESIS_1_4_OF_THRESHOLD 0x10
423#define PROXFUSION2_HIUIS_TOUCH_HYSTERESIS_1_16_OF_THRESHOLD 0x30
424#define PROXFUSION2_HIUIS_PROXIMITY_HYSTERESIS_DISABLED 0x00
425#define PROXFUSION2_HIUIS_PROXIMITY_HYSTERESIS_1_8_OF_THRESHOLD 0x02
426#define PROXFUSION2_HIUIS_PROXIMITY_HYSTERESIS_1_4_OF_THRESHOLD 0x01
427#define PROXFUSION2_HIUIS_PROXIMITY_HYSTERESIS_1_16_OF_THRESHOLD 0x03
434#define PROXFUSION2_TOUCH_DETECTED 0x01
435#define PROXFUSION2_TOUCH_NOT_DETECTED 0x00
436#define PROXFUSION2_AMBIENT_DARK 0x01
437#define PROXFUSION2_AMBIENT_LIGHT 0x00
438#define PROXFUSION2_HALL_NORTH 0x00
439#define PROXFUSION2_HALL_SOUTH 0x01
440#define PROXFUSION2_HALL_UNKNOWN 0x02
441#define PROXFUSION2_HYSTERESIS_UI_OUTPUT 0x14
442#define PROXFUSION2_ALS_UI_OUTPUT 0x17
443#define PROXFUSION2_HALL_EFFECT_UI_OUTPUT 0x1A
444#define PROXFUSION2_TEMPERATURE_UI_OUTPUT 0x1D
447 // End group macro
448// --------------------------------------------------------------- PUBLIC TYPES
457typedef struct
458{
459 // Input pins
460 digital_in_t rdy;
461
462 // Modules
463 i2c_master_t i2c;
464
465 // ctx variable
467
469
473typedef struct
474{
475 // Communication gpio pins
476 pin_name_t scl;
477 pin_name_t sda;
478
479 // Additional gpio pins
480 pin_name_t rdy;
481
482 // static variable
483 uint32_t i2c_speed;
484 uint8_t i2c_address;
485
487
488 // End types group
489
490// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
491
497#ifdef __cplusplus
498extern "C"{
499#endif
500
510
523
536
544void proxfusion2_write_byte ( proxfusion2_t *ctx, uint8_t reg, uint8_t d_data );
545
553uint8_t proxfusion2_read_byte ( proxfusion2_t *ctx, uint8_t reg );
554
562uint16_t proxfusion2_read_data ( proxfusion2_t *ctx, uint8_t reg );
563
572
581
590uint8_t proxfusion2_detect_dark_light ( proxfusion2_t *ctx, uint8_t *als_range );
591
600
601#ifdef __cplusplus
602}
603#endif
604#endif // _PROXFUSION2_H_
605
606 // End public_function group
608
609// ------------------------------------------------------------------------- END
uint8_t proxfusion2_read_byte(proxfusion2_t *ctx, uint8_t reg)
Function for reads one byte from register.
uint8_t proxfusion2_detect_hall(proxfusion2_t *ctx)
Function for read Hall-effect.
void proxfusion2_cfg_setup(proxfusion2_cfg_t *cfg)
Config Object Initialization function.
uint8_t proxfusion2_detect_dark_light(proxfusion2_t *ctx, uint8_t *als_range)
Function for read ambient light.
uint16_t proxfusion2_read_data(proxfusion2_t *ctx, uint8_t reg)
Function for reads two byte from register.
uint8_t proxfusion2_detect_touch(proxfusion2_t *ctx)
Function for detect Touch.
err_t proxfusion2_default_cfg(proxfusion2_t *ctx)
Click Default Configuration function.
err_t proxfusion2_init(proxfusion2_t *ctx, proxfusion2_cfg_t *cfg)
Initialization function.
err_t proxfusion2_check_communication(proxfusion2_t *ctx)
Function for check communication by reading the device ID registers.
void proxfusion2_write_byte(proxfusion2_t *ctx, uint8_t reg, uint8_t d_data)
Function for writing one byte into the register.
Click configuration structure definition.
Definition proxfusion2.h:474
uint32_t i2c_speed
Definition proxfusion2.h:483
pin_name_t scl
Definition proxfusion2.h:476
pin_name_t rdy
Definition proxfusion2.h:480
pin_name_t sda
Definition proxfusion2.h:477
uint8_t i2c_address
Definition proxfusion2.h:484
Click ctx object definition.
Definition proxfusion2.h:458
i2c_master_t i2c
Definition proxfusion2.h:463
uint8_t slave_address
Definition proxfusion2.h:466
digital_in_t rdy
Definition proxfusion2.h:460