38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_i2c_master.h"
53#define CAPTOUCH5_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
55 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
63#define CAPTOUCH5_RETVAL uint8_t
65#define CAPTOUCH5_OK 0x00
66#define CAPTOUCH5_INIT_ERROR 0xFF
69#define CAPTOUCH5_I2C_SLAVE_ADDRESS 0x37
75#define CAPTOUCH5_REG_SENSOR_EN 0x00
76#define CAPTOUCH5_REG_FSS_EN 0x02
77#define CAPTOUCH5_REG_SENSITIVITY0 0x08
78#define CAPTOUCH5_REG_SENSITIVITY1 0x09
79#define CAPTOUCH5_REG_SENSITIVITY2 0x0A
80#define CAPTOUCH5_REG_SENSITIVITY3 0x0B
81#define CAPTOUCH5_REG_BASE_THRESHOLD0 0x0C
82#define CAPTOUCH5_REG_BASE_THRESHOLD1 0x0D
83#define CAPTOUCH5_REG_FINGER_THRESHOLD2 0x0E
84#define CAPTOUCH5_REG_FINGER_THRESHOLD3 0x0F
85#define CAPTOUCH5_REG_FINGER_THRESHOLD4 0x10
86#define CAPTOUCH5_REG_FINGER_THRESHOLD5 0x11
87#define CAPTOUCH5_REG_FINGER_THRESHOLD6 0x12
88#define CAPTOUCH5_REG_FINGER_THRESHOLD7 0x13
89#define CAPTOUCH5_REG_FINGER_THRESHOLD8 0x14
90#define CAPTOUCH5_REG_FINGER_THRESHOLD9 0x15
91#define CAPTOUCH5_REG_FINGER_THRESHOLD10 0x16
92#define CAPTOUCH5_REG_FINGER_THRESHOLD11 0x17
93#define CAPTOUCH5_REG_FINGER_THRESHOLD12 0x18
94#define CAPTOUCH5_REG_FINGER_THRESHOLD13 0x19
95#define CAPTOUCH5_REG_FINGER_THRESHOLD14 0x1A
96#define CAPTOUCH5_REG_FINGER_THRESHOLD15 0x1B
97#define CAPTOUCH5_REG_SENSOR_DEBOUNCE 0x1C
98#define CAPTOUCH5_REG_BUTTON_HYS 0x1D
99#define CAPTOUCH5_REG_BUTTON_LBR 0x1F
100#define CAPTOUCH5_REG_BUTTON_NNT 0x20
101#define CAPTOUCH5_REG_BUTTON_NT 0x21
102#define CAPTOUCH5_REG_PROX_EN 0x26
103#define CAPTOUCH5_REG_PROX_CFG 0x27
104#define CAPTOUCH5_REG_PROX_TOUCH_TH0 0x28
105#define CAPTOUCH5_REG_PROX_TOUCH_TH1 0x2A
106#define CAPTOUCH5_REG_PROX_RESOLUTION0 0x2E
107#define CAPTOUCH5_REG_PROX_RESOLUTION1 0x2F
108#define CAPTOUCH5_REG_PROX_HYS 0x30
109#define CAPTOUCH5_REG_PROX_LBR 0x32
110#define CAPTOUCH5_REG_PROX_NNT 0x33
111#define CAPTOUCH5_REG_PROX_NT 0x34
112#define CAPTOUCH5_REG_BUZZER_CFG 0x3E
113#define CAPTOUCH5_REG_BUZZER_ON_TIME 0x3F
114#define CAPTOUCH5_REG_SPO_CFG 0x4C
115#define CAPTOUCH5_REG_DEVICE_CFG0 0x4D
116#define CAPTOUCH5_REG_DEVICE_CFG1 0x4E
117#define CAPTOUCH5_REG_DEVICE_CFG2 0x4F
118#define CAPTOUCH5_REG_DEVICE_CFG3 0x50
119#define CAPTOUCH5_REG_I2C_ADDR 0x51
120#define CAPTOUCH5_REG_REFRESH_CTRL 0x52
121#define CAPTOUCH5_REG_STATE_TIMEOUT 0x55
122#define CAPTOUCH5_REG_SLIDER_CFG 0x5D
123#define CAPTOUCH5_REG_SLIDER1_CFG 0x61
124#define CAPTOUCH5_REG_SLIDER1_RESOLUTION 0x62
125#define CAPTOUCH5_REG_SLIDER1_THRESHOLD 0x63
126#define CAPTOUCH5_REG_SLIDER2_CFG 0x67
127#define CAPTOUCH5_REG_SLIDER2_RESOLUTION 0x68
128#define CAPTOUCH5_REG_SLIDER2_THRESHOLD 0x69
129#define CAPTOUCH5_REG_SLIDER_LBR 0x71
130#define CAPTOUCH5_REG_SLIDER_NNT 0x72
131#define CAPTOUCH5_REG_SLIDER_NT 0x73
132#define CAPTOUCH5_REG_SCRATCHPAD0 0x7A
133#define CAPTOUCH5_REG_SCRATCHPAD1 0x7B
134#define CAPTOUCH5_REG_CONFIG_CRC 0x7E
135#define CAPTOUCH5_REG_SENSOR_ID 0x82
136#define CAPTOUCH5_REG_CTRL_CMD 0x86
137#define CAPTOUCH5_REG_CTRL_CMD_STATUS 0x88
138#define CAPTOUCH5_REG_CTRL_CMD_ERR 0x89
139#define CAPTOUCH5_REG_SYSTEM_STATUS 0x8A
140#define CAPTOUCH5_REG_PREV_CTRL_CMD_CODE 0x8C
141#define CAPTOUCH5_REG_FAMILY_ID 0x8F
142#define CAPTOUCH5_REG_DEVICE_ID 0x90
143#define CAPTOUCH5_REG_DEVICE_REV 0x92
144#define CAPTOUCH5_REG_CALC_CRC 0x94
145#define CAPTOUCH5_REG_TOTAL_WORKING_SNS 0x97
146#define CAPTOUCH5_REG_SNS_CP_HIGH 0x98
147#define CAPTOUCH5_REG_SNS_VDD_SHORT 0x9A
148#define CAPTOUCH5_REG_SNS_GND_SHORT 0x9C
149#define CAPTOUCH5_REG_CMOD_SHIELD_TEST 0xA0
150#define CAPTOUCH5_REG_BUTTON_STAT 0xAA
151#define CAPTOUCH5_REG_LATCHED_BUTTON_STAT 0xAC
152#define CAPTOUCH5_REG_PROX_STAT 0xAE
153#define CAPTOUCH5_REG_LATCHED_PROx_STAT 0xAF
154#define CAPTOUCH5_REG_SLIDER1_POSITION 0xB0
155#define CAPTOUCH5_REG_LIFTOFF_SLIDER1_POSITION 0xB1
156#define CAPTOUCH5_REG_SLIDER2_POSITION 0xB2
157#define CAPTOUCH5_REG_LIFTOFF_SLIDER2_POSITION 0xB3
158#define CAPTOUCH5_REG_SYNC_COUNTER0 0xB9
159#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR0 0xBA
160#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR1 0xBC
161#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR2 0xBE
162#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR3 0xC0
163#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR4 0xC2
164#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR5 0xC4
165#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR6 0xC6
166#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR7 0xC8
167#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR8 0xCA
168#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR9 0xCC
169#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR10 0xCE
170#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR11 0xD0
171#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR12 0xD2
172#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR13 0xD4
173#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR14 0xD6
174#define CAPTOUCH5_REG_DIFFERENCE_COUNT_SENSOR15 0xD8
175#define CAPTOUCH5_REG_SYNC_COUNTER1 0xDB
176#define CAPTOUCH5_REG_DEBUG_SENSOR_ID 0xDC
177#define CAPTOUCH5_REG_DEBUG_CP 0xDD
178#define CAPTOUCH5_REG_DIFFERENCE_COUNT0 0xDE
179#define CAPTOUCH5_REG_DEBUG_BASELINE0 0xE0
180#define CAPTOUCH5_REG_DEBUG_RAW_COUNT0 0xE2
181#define CAPTOUCH5_REG_DEBUG_AVG_RAW_COUNT0 0xE4
182#define CAPTOUCH5_REG_SYNC_COUNTER2 0xE7
189#define CAPTOUCH5_BUTTON_PRESSED 1
190#define CAPTOUCH5_BUTTON_NOT_PRESSED 0
197#define CAPTOUCH5_CFG0_IIR_FILTER_ENABLED 1
198#define CAPTOUCH5_CFG0_IIR_FILTER_DISABLED 1
199#define CAPTOUCH5_CFG0_MED_FILTER_ENABLED 1
200#define CAPTOUCH5_CFG0_MED_FILTER_DISABLED 1
207#define CAPTOUCH5_CFG1_SYS_DIAGNOSTIC_ENABLED 1
208#define CAPTOUCH5_CFG1_SYS_DIAGNOSTIC_DISABLED 1
215#define CAPTOUCH5_CFG2_SHIELD_ENABLED 1
216#define CAPTOUCH5_CFG2_SHIELD_DISABLED 0
217#define CAPTOUCH5_CFG2_GUARD_SENS_ENABLED 1
218#define CAPTOUCH5_CFG2_GUARD_SENS_DISABLED 0
219#define CAPTOUCH5_CFG2_EMC_ENABLED 1
220#define CAPTOUCH5_CFG2_EMC_DISABLED 0
221#define CAPTOUCH5_CFG2_AUTOMATIC_THRESHOLD_ENABLED 1
222#define CAPTOUCH5_CFG2_AUTOMATIC_THRESHOLD_DISABLED 0
223#define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_DISABLED 0
224#define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_ENABLED_5_SEC 1
225#define CAPTOUCH5_CFG2_BUTTON_SLIDER_AUTO_RESET_ENABLED_20_SEC 2
226#define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_DISABLED 0
227#define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_ENABLED_5_SEC 1
228#define CAPTOUCH5_CFG2_PROXIMIYU_AUTO_RESET_ENABLED_20_SEC 2
235#define CAPTOUCH5_CFG3_POWER_SUPPLY_INTERNALLY 0
236#define CAPTOUCH5_CFG3_POWER_SUPPLY_EXTERNALLY 1
243#define CAPTOUCH5_SLIDER_SENS_0p1 0
244#define CAPTOUCH5_SLIDER_SENS_0p2 1
245#define CAPTOUCH5_SLIDER_SENS_0p3 2
246#define CAPTOUCH5_SLIDER_SENS_0p4 3
253#define CAPTOUCH5_BUTTON_SENS_ENABLED 0xFFFF
254#define CAPTOUCH5_BUTTON_SENS_DISABLED 0x0000
261#define CAPTOUCH5_DEVICE_ID 2566
262#define CAPTOUCH5_FAMILY_ID 154
270#define CAPTOUCH5_ERROR 1
271#define CAPTOUCH5_NO_ERROR 0
#define CAPTOUCH5_RETVAL
Definition: captouch5.h:63
void captouch5_config_slider(captouch5_t *ctx, uint8_t slider_data)
Function for configuring slider.
uint8_t captouch5_read_byte(captouch5_t *ctx, uint8_t reg_addr)
Generic read 8bit data function.
uint16_t captouch5_read_slider_position(captouch5_t *ctx)
Function for reading slider position.
void captouch5_generic_write(captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
void captouch5_default_cfg(captouch5_t *ctx, T_CAPTOUCH5_DEVICE_CONFIG *device_cfg)
Click Default Configuration function.
void captouch5_write_two_bytes(captouch5_t *ctx, uint8_t reg_addr, uint16_t data_buf)
Generic write 16bit data function.
void captouch5_config_sensors(captouch5_t *ctx, uint16_t sens_data)
Function for configuring sensor.
void captouch5_device_config(captouch5_t *ctx, T_CAPTOUCH5_DEVICE_CONFIG *device_cfg)
Function for configuring device.
uint16_t captouch5_get_device_id(captouch5_t *ctx)
Function for geting device id.
void captouch5_generic_read(captouch5_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
void captouch5_write_byte(captouch5_t *ctx, uint8_t reg_addr, uint8_t data_buf)
Generic write 8bit data function.
uint16_t captouch5_read_two_bytes(captouch5_t *ctx, uint8_t reg_addr)
Generic read 16bit data function.
uint8_t captouch5_process(captouch5_t *ctx)
Function for checking error.
void captouch5_software_reset(captouch5_t *ctx)
Function to reset device.
uint8_t captouch5_get_family_id(captouch5_t *ctx)
Function for geting family id.
void captouch5_read_button_status(captouch5_t *ctx, T_CAPTOUCH5_BUTTONS *buttons)
Function read button status.
void captouch5_cfg_setup(captouch5_cfg_t *cfg)
Config Object Initialization function.
CAPTOUCH5_RETVAL captouch5_init(captouch5_t *ctx, captouch5_cfg_t *cfg)
Initialization function.
Definition: captouch5.h:316
uint8_t button4
Definition: captouch5.h:320
uint8_t button3
Definition: captouch5.h:319
uint8_t button2
Definition: captouch5.h:318
uint8_t button1
Definition: captouch5.h:317
Definition: captouch5.h:324
uint8_t iirFilter
Definition: captouch5.h:325
uint8_t medFilter
Definition: captouch5.h:326
Definition: captouch5.h:330
uint8_t sysDiagnostic
Definition: captouch5.h:331
Definition: captouch5.h:335
uint8_t autoThreshold
Definition: captouch5.h:338
uint8_t shieldSens
Definition: captouch5.h:341
uint8_t emcSolution
Definition: captouch5.h:339
uint8_t guardSens
Definition: captouch5.h:340
uint8_t buttonAutoReset
Definition: captouch5.h:337
uint8_t proximityAutoReset
Definition: captouch5.h:336
Definition: captouch5.h:345
uint8_t powerSupply
Definition: captouch5.h:346
Definition: captouch5.h:351
T_CAPTOUCH5_CONFIG0 cfg0
Definition: captouch5.h:352
T_CAPTOUCH5_CONFIG3 cfg3
Definition: captouch5.h:355
T_CAPTOUCH5_CONFIG1 cfg1
Definition: captouch5.h:353
T_CAPTOUCH5_CONFIG2 cfg2
Definition: captouch5.h:354
Click configuration structure definition.
Definition: captouch5.h:301
uint32_t i2c_speed
Definition: captouch5.h:309
pin_name_t scl
Definition: captouch5.h:304
pin_name_t sda
Definition: captouch5.h:305
uint8_t i2c_address
Definition: captouch5.h:310
Click ctx object definition.
Definition: captouch5.h:285
i2c_master_t i2c
Definition: captouch5.h:289
uint8_t slave_address
Definition: captouch5.h:293