captouch4  2.1.0.0
captouch4.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef CAPTOUCH4_H
29 #define CAPTOUCH4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_i2c_master.h"
52 
73 #define CAPTOUCH4_REG_PRODUCT_NUM 0x00
74 #define CAPTOUCH4_REG_VERSION_NUM 0x01
75 #define CAPTOUCH4_REG_SYSFLAGS0 0x10
76 #define CAPTOUCH4_REG_MOVEMENT_VALUE 0x41
77 #define CAPTOUCH4_REG_CS_H 0x42
78 #define CAPTOUCH4_REG_CS_L 0x43
79 #define CAPTOUCH4_REG_LTA_H 0x83
80 #define CAPTOUCH4_REG_LTA_L 0x84
81 #define CAPTOUCH4_REG_TOUCH_THRESHOLD_H 0x90
82 #define CAPTOUCH4_REG_TOUCH_THRESHOLD_L 0x91
83 #define CAPTOUCH4_REG_MULTIPLIERS 0xC4
84 #define CAPTOUCH4_REG_COMPENSATION 0xC5
85 #define CAPTOUCH4_REG_PROX_SETTINGS0 0xC6
86 #define CAPTOUCH4_REG_PROX_SETTINGS1 0xC7
87 #define CAPTOUCH4_REG_PROX_SETTINGS2 0xC8
88 #define CAPTOUCH4_REG_ATI_TARGET 0xC9
89 #define CAPTOUCH4_REG_LP_PERIOD 0xCA
90 #define CAPTOUCH4_REG_PROX_THRESHOLD 0xCB
91 #define CAPTOUCH4_REG_TOUCH_THRESHOLD 0xCC
92 #define CAPTOUCH4_REG_MOVEMENT_THRESHOLD 0xCD
93 #define CAPTOUCH4_REG_AUTO_RESEED_LIMIT 0xCE
94 #define CAPTOUCH4_REG_TEST_MODE 0x0F
95 #define CAPTOUCH4_REG_OTP_BANK_0 0x10
96 #define CAPTOUCH4_REG_OTP_BANK_1 0x11
97 #define CAPTOUCH4_REG_OTP_BANK_2 0x12
98 #define CAPTOUCH4_REG_OTP_BANK_3 0x13
99 #define CAPTOUCH4_REG_OTP_BANK_4 0x14
100  // captouch4_reg
102 
117 #define CAPTOUCH4_TEST_MODE_OK 0xA5
118 #define CAPTOUCH4_OTP_BANK_2_OUT_I2C_NO_WKP 0x05
119 
124 #define CAPTOUCH4_SYSFLAGS0_MOVEMENT 0x80
125 #define CAPTOUCH4_SYSFLAGS0_MOVEMENT_LATCH 0x40
126 #define CAPTOUCH4_SYSFLAGS0_PROX 0x20
127 #define CAPTOUCH4_SYSFLAGS0_TOUCH 0x10
128 #define CAPTOUCH4_SYSFLAGS0_SHOW_RESET 0x08
129 #define CAPTOUCH4_SYSFLAGS0_ATI_BUSY 0x04
130 #define CAPTOUCH4_SYSFLAGS0_FILTER_HALT 0x02
131 #define CAPTOUCH4_SYSFLAGS0_LP_ACTIVE 0x01
132 #define CAPTOUCH4_SYSFLAGS0_CLEAR 0x01
133 
138 #define CAPTOUCH4_PRODUCT_NUMBER 0x3D
139 #define CAPTOUCH4_VERSION_NUMBER 0x02
140 
145 #define CAPTOUCH4_I2C_TIMEOUT 100000ul
146 
152 #define CAPTOUCH4_DEVICE_ADDRESS 0x47
153  // captouch4_set
155 
170 #define CAPTOUCH4_MAP_MIKROBUS( cfg, mikrobus ) \
171  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
172  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
173  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
174  // captouch4_map // captouch4
177 
182 typedef struct
183 {
184  digital_out_t en;
186  // Modules
187  pin_name_t scl;
188  pin_name_t sda;
190  uint8_t i2c_started;
192  // I2C slave address
193  uint8_t slave_address;
195 } captouch4_t;
196 
201 typedef struct
202 {
203  pin_name_t scl;
204  pin_name_t sda;
205  pin_name_t en;
207  uint8_t i2c_address;
210 
215 typedef enum
216 {
218  CAPTOUCH4_ERROR = -1
219 
221 
238 
253 
267 
280 err_t captouch4_write_reg ( captouch4_t *ctx, uint8_t reg, uint8_t data_in );
281 
296 err_t captouch4_read_reg ( captouch4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
297 
310 
322 
334 
346 err_t captouch4_read_system_flags ( captouch4_t *ctx, uint8_t *sysflags );
347 
359 err_t captouch4_read_movement ( captouch4_t *ctx, uint8_t *movement );
360 
374 err_t captouch4_read_cap_counts ( captouch4_t *ctx, uint16_t *cap_counts );
375 
388 err_t captouch4_read_lta ( captouch4_t *ctx, uint16_t *lta );
389 
390 #ifdef __cplusplus
391 }
392 #endif
393 #endif // CAPTOUCH4_H
394  // captouch4
396 
397 // ------------------------------------------------------------------------ END
captouch4_read_cap_counts
err_t captouch4_read_cap_counts(captouch4_t *ctx, uint16_t *cap_counts)
Cap Touch 4 read cap counts function.
captouch4_enable_device
void captouch4_enable_device(captouch4_t *ctx)
Cap Touch 4 enable device function.
captouch4_cfg_t::en
pin_name_t en
Definition: captouch4.h:205
captouch4_read_lta
err_t captouch4_read_lta(captouch4_t *ctx, uint16_t *lta)
Cap Touch 4 read lta function.
captouch4_init
err_t captouch4_init(captouch4_t *ctx, captouch4_cfg_t *cfg)
Cap Touch 4 initialization function.
captouch4_cfg_setup
void captouch4_cfg_setup(captouch4_cfg_t *cfg)
Cap Touch 4 configuration object setup function.
captouch4_read_reg
err_t captouch4_read_reg(captouch4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Cap Touch 4 read reg function.
captouch4_cfg_t::scl
pin_name_t scl
Definition: captouch4.h:203
captouch4_read_system_flags
err_t captouch4_read_system_flags(captouch4_t *ctx, uint8_t *sysflags)
Cap Touch 4 read system flags function.
captouch4_t::i2c_started
uint8_t i2c_started
Definition: captouch4.h:190
captouch4_t
Cap Touch 4 Click context object.
Definition: captouch4.h:183
captouch4_read_movement
err_t captouch4_read_movement(captouch4_t *ctx, uint8_t *movement)
Cap Touch 4 read movement function.
captouch4_t::scl
pin_name_t scl
Definition: captouch4.h:187
CAPTOUCH4_ERROR
@ CAPTOUCH4_ERROR
Definition: captouch4.h:218
CAPTOUCH4_OK
@ CAPTOUCH4_OK
Definition: captouch4.h:217
captouch4_write_reg
err_t captouch4_write_reg(captouch4_t *ctx, uint8_t reg, uint8_t data_in)
Cap Touch 4 write reg function.
captouch4_check_communication
err_t captouch4_check_communication(captouch4_t *ctx)
Cap Touch 4 check communication function.
captouch4_default_cfg
err_t captouch4_default_cfg(captouch4_t *ctx)
Cap Touch 4 default configuration function.
captouch4_return_value_t
captouch4_return_value_t
Cap Touch 4 Click return value data.
Definition: captouch4.h:216
captouch4_cfg_t::i2c_address
uint8_t i2c_address
Definition: captouch4.h:207
captouch4_t::slave_address
uint8_t slave_address
Definition: captouch4.h:193
captouch4_cfg_t::sda
pin_name_t sda
Definition: captouch4.h:204
captouch4_cfg_t
Cap Touch 4 Click configuration object.
Definition: captouch4.h:202
captouch4_disable_device
void captouch4_disable_device(captouch4_t *ctx)
Cap Touch 4 disable device function.
captouch4_t::en
digital_out_t en
Definition: captouch4.h:184
captouch4_t::sda
pin_name_t sda
Definition: captouch4.h:188