proxfusion  2.0.0.0
proxfusion.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 PROXFUSION_H
36 #define PROXFUSION_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 // -------------------------------------------------------------- PUBLIC MACROS
65 #define PROXFUSION_MAP_MIKROBUS( cfg, mikrobus ) \
66  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
67  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
68  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
69 
75 #define PROXFUSION_OK 0
76 #define PROXFUSION_ERROR -1
77 
83 #define PROXFUSION_REG_PR_NUMBER 0x00
84 #define PROXFUSION_REG_SW_NUMBER 0x01
85 #define PROXFUSION_REG_HW_NUMBER 0x02
86 
92 #define PROXFUSION_PR_OK 0x41
93 #define PROXFUSION_SW_IQS620_OK 0x04
94 #define PROXFUSION_SW_IQS620A_OK 0x08
95 #define PROXFUSION_HW_OK 0x82
96 
102 #define PROXFUSION_FREG_SYSTEM 0x10
103 #define PROXFUSION_FREG_GLOBAL_EVENTS 0x11
104 #define PROXFUSION_FREG_UI 0x12
105 #define PROXFUSION_FREG_SAR_HYSTERESIS_UI 0x13
106 #define PROXFUSION_FREG_HALL_EFFECT_UI 0x16
107 
113 #define PROXFUSION_REG_CH_0_LSB 0x20
114 #define PROXFUSION_REG_CH_0_MSB 0x21
115 #define PROXFUSION_REG_CH_1_LSB 0x22
116 #define PROXFUSION_REG_CH_1_MSB 0x23
117 #define PROXFUSION_REG_CH_2_LSB 0x24
118 #define PROXFUSION_REG_CH_2_MSB 0x25
119 #define PROXFUSION_REG_CH_3_LSB 0x26
120 #define PROXFUSION_REG_CH_3_MSB 0x27
121 #define PROXFUSION_REG_CH_4_LSB 0x28
122 #define PROXFUSION_REG_CH_4_MSB 0x29
123 #define PROXFUSION_REG_CH_5_LSB 0x2A
124 #define PROXFUSION_REG_CH_5_MSB 0x2B
125 
131 #define PROXFUSION_REG_LTA_CH_0_LSB 0x30
132 #define PROXFUSION_REG_LTA_CH_0_MSB 0x31
133 #define PROXFUSION_REG_LTA_CH_1_LSB 0x32
134 #define PROXFUSION_REG_LTA_CH_1_MSB 0x33
135 #define PROXFUSION_REG_LTA_CH_2_LSB 0x34
136 #define PROXFUSION_REG_LTA_CH_2_MSB 0x35
137 
143 #define PROXFUSION_REG_SETTINGS_0_0 0x40
144 #define PROXFUSION_REG_SETTINGS_0_1 0x41
145 #define PROXFUSION_REG_SETTINGS_0_2 0x42
146 #define PROXFUSION_REG_SETTINGS_1_0 0x43
147 #define PROXFUSION_REG_SETTINGS_1_1 0x44
148 #define PROXFUSION_REG_SETTINGS_1_2 0x45
149 #define PROXFUSION_REG_SETTINGS_2_0 0x46
150 #define PROXFUSION_REG_SETTINGS_2_1 0x47
151 #define PROXFUSION_REG_SETTINGS_2_2 0x48
152 #define PROXFUSION_REG_SETTINGS_3_0 0x49
153 #define PROXFUSION_REG_SETTINGS_3_1 0x4A
154 #define PROXFUSION_REG_SETTINGS_3_2 0x4B
155 
161 #define PROXFUSION_REG_SETTINGS_4 0x50
162 #define PROXFUSION_REG_SETTINGS_5 0x51
163 #define PROXFUSION_REG_COMPENSATION_CH_0 0x52
164 #define PROXFUSION_REG_COMPENSATION_CH_1 0x53
165 #define PROXFUSION_REG_COMPENSATION_CH_2 0x54
166 #define PROXFUSION_REG_MULTIPLIERS_CH_0 0x55
167 #define PROXFUSION_REG_MULTIPLIERS_CH_1 0x56
168 #define PROXFUSION_REG_MULTIPLIERS_CH_2 0x57
169 
175 #define PROXFUSION_REG_PROX_CH_0 0x60
176 #define PROXFUSION_REG_TOUCH_CH_0 0x61
177 #define PROXFUSION_REG_PROX_CH_1 0x62
178 #define PROXFUSION_REG_TOUCH_CH_1 0x63
179 #define PROXFUSION_REG_PROX_CH_2 0x64
180 #define PROXFUSION_REG_TOUCH_CH_2 0x65
181 #define PROXFUSION_REG_UI_HALY_TIME 0x66
182 
188 #define PROXFUSION_REG_SAR_SETTINGS_CH0 0x70
189 #define PROXFUSION_REG_SAR_SETTINGS_CH1 0x71
190 #define PROXFUSION_REG_QRD_THRESHOLD 0x72
191 #define PROXFUSION_REG_FILTER_HALT_THRESHOLD 0x73
192 #define PROXFUSION_REG_PROX_THRESHOLD 0x74
193 
199 #define PROXFUSION_REG_HYS_UI_SETTINGS 0x80
200 #define PROXFUSION_REG_HYS_FILTER_THRESHOLD 0x81
201 #define PROXFUSION_REG_HYS_PROX_THRESHOLD 0x82
202 #define PROXFUSION_REG_HYS_TOUCH_THRESHOLD 0x83
203 
209 #define PROXFUSION_REG_HALL_SETTINGS_0 0x90
210 #define PROXFUSION_REG_HALL_SETTINGS_1 0x91
211 #define PROXFUSION_REG_HALL_COMPENSATION_4_5 0x92
212 #define PROXFUSION_REG_HALL_MULTIPLIERS_4_5 0x93
213 
219 #define PROXFUSION_REG_HALL_SWITCH_UI 0xA0
220 #define PROXFUSION_REG_HALL_SWITCH_PROX 0xA1
221 #define PROXFUSION_REG_HALL_SWITCH_TOUCH 0xA2
222 
228 #define PROXFUSION_REG_I2C_SETTINGS 0xDA
229 
235 #define PROXFUSION_SYSTEM_RESET ( 0x02 << 6 )
236 #define PROXFUSION_SYSTEM_ATI_RESET ( 0x02 )
237 #define PROXFUSION_EVENT_MODE_0 ( 0x00 << 5 )
238 #define PROXFUSION_EVENT_MODE_1 ( 0x01 << 5 )
239 #define PROXFUSION_CLOCK_16MHz ( 0x00 << 4 )
240 #define PROXFUSION_CLOCK_4MHz ( 0x01 << 4 )
241 #define PROXFUSION_ATI_DESABLED ( 0x00 << 3 )
242 #define PROXFUSION_ATI_ENABLED ( 0x01 << 3 )
243 #define PROXFUSION_ATI_BAND_1_8 ( 0x00 << 3 )
244 #define PROXFUSION_ATI_BAND_1_16 ( 0x01 << 3 )
245 
251 #define PROXFUSION_MASK_SAR_ACTIVE 0x80
252 #define PROXFUSION_MASK_PMU_EVENT 0x40
253 #define PROXFUSION_MASK_SYS_EVENT 0x20
254 #define PROXFUSION_MASK_TEMP_EVENT 0x10
255 #define PROXFUSION_MASK_HYSTERESIS_EVENT 0x08
256 #define PROXFUSION_MASK_HALL_EVENT 0x04
257 #define PROXFUSION_MASK_SAR_EVENT 0x02
258 #define PROXFUSION_MASK_PROX_SENSE_EVENT 0x01
259 
265 #define PROXFUSION_SLAVE_ADDRESS 0x44
266  // End group macro
269 // --------------------------------------------------------------- PUBLIC TYPES
278 typedef struct
279 {
280  // Input pins
281  digital_in_t int_pin;
282 
283  // Modules
284  i2c_master_t i2c;
285 
286  // ctx variable
287  uint8_t slave_address;
288 
289 } proxfusion_t;
290 
294 typedef struct
295 {
296  // Communication gpio pins
297  pin_name_t scl;
298  pin_name_t sda;
299 
300  // Additional gpio pins
301  pin_name_t int_pin;
302 
303  // static variable
304  uint32_t i2c_speed;
305  uint8_t i2c_address;
306 
308  // End types group
310 
311 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
312 
318 #ifdef __cplusplus
319 extern "C"{
320 #endif
321 
331 
344 
368 
382 err_t proxfusion_generic_write ( proxfusion_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
383 
397 err_t proxfusion_generic_read ( proxfusion_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len );
398 
407 
426 err_t proxfusion_set_system_reg ( proxfusion_t *ctx, uint8_t cfg );
427 
447 err_t proxfusion_set_event_reg ( proxfusion_t *ctx, uint8_t cfg );
448 
449 #ifdef __cplusplus
450 }
451 #endif
452 #endif // _PROXFUSION_H_
453  // End public_function group
456 
457 // ------------------------------------------------------------------------- END
proxfusion_init
err_t proxfusion_init(proxfusion_t *ctx, proxfusion_cfg_t *cfg)
Initialization function.
proxfusion_cfg_t::scl
pin_name_t scl
Definition: proxfusion.h:297
proxfusion_t::slave_address
uint8_t slave_address
Definition: proxfusion.h:287
proxfusion_cfg_setup
void proxfusion_cfg_setup(proxfusion_cfg_t *cfg)
Config Object Initialization function.
proxfusion_cfg_t::int_pin
pin_name_t int_pin
Definition: proxfusion.h:301
proxfusion_generic_read
err_t proxfusion_generic_read(proxfusion_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len)
Generic read function.
proxfusion_t::int_pin
digital_in_t int_pin
Definition: proxfusion.h:281
proxfusion_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proxfusion.h:304
proxfusion_get_touch
uint8_t proxfusion_get_touch(proxfusion_t *ctx)
Touch event.
proxfusion_cfg_t::i2c_address
uint8_t i2c_address
Definition: proxfusion.h:305
proxfusion_default_cfg
err_t proxfusion_default_cfg(proxfusion_t *ctx)
Click Default Configuration function.
proxfusion_cfg_t
Click configuration structure definition.
Definition: proxfusion.h:295
proxfusion_t::i2c
i2c_master_t i2c
Definition: proxfusion.h:284
proxfusion_generic_write
err_t proxfusion_generic_write(proxfusion_t *ctx, uint8_t reg, uint8_t *data_buffer, uint8_t len)
Generic write function.
proxfusion_set_system_reg
err_t proxfusion_set_system_reg(proxfusion_t *ctx, uint8_t cfg)
Sets system register.
proxfusion_cfg_t::sda
pin_name_t sda
Definition: proxfusion.h:298
proxfusion_t
Click ctx object definition.
Definition: proxfusion.h:279
proxfusion_set_event_reg
err_t proxfusion_set_event_reg(proxfusion_t *ctx, uint8_t cfg)
Selecting events.