ldctouch  2.0.0.0
ldctouch.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 LDCTOUCH_H
29 #define LDCTOUCH_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define LDCTOUCH_REG_STATUS 0x00
60 #define LDCTOUCH_REG_OUT 0x01
61 #define LDCTOUCH_REG_DATA0_LSB 0x02
62 #define LDCTOUCH_REG_DATA0_MSB 0x03
63 #define LDCTOUCH_REG_DATA1_LSB 0x04
64 #define LDCTOUCH_REG_DATA1_MSB 0x05
65 #define LDCTOUCH_REG_DATA2_LSB 0x06
66 #define LDCTOUCH_REG_DATA2_MSB 0x07
67 #define LDCTOUCH_REG_DATA3_LSB 0x08
68 #define LDCTOUCH_REG_DATA3_MSB 0x09
69 #define LDCTOUCH_REG_RESET 0x0A
70 #define LDCTOUCH_REG_EN 0x0C
71 #define LDCTOUCH_REG_NP_SCAN_RATE 0x0D
72 #define LDCTOUCH_REG_GAIN0 0x0E
73 #define LDCTOUCH_REG_LP_SCAN_RATE 0x0F
74 #define LDCTOUCH_REG_GAIN1 0x10
75 #define LDCTOUCH_REG_INTPOL 0x11
76 #define LDCTOUCH_REG_GAIN2 0x12
77 #define LDCTOUCH_REG_LP_BASE_INC 0x13
78 #define LDCTOUCH_REG_GAIN3 0x14
79 #define LDCTOUCH_REG_NP_BASE_INC 0x15
80 #define LDCTOUCH_REG_BTPAUSE_MAXWIN 0x16
81 #define LDCTOUCH_REG_LC_DIVIDER 0x17
82 #define LDCTOUCH_REG_HYST 0x18
83 #define LDCTOUCH_REG_TWIST 0x19
84 #define LDCTOUCH_REG_COMMON_DEFORM 0x1A
85 #define LDCTOUCH_REG_OPOL_DPOL 0x1C
86 #define LDCTOUCH_REG_CNTSC 0x1E
87 #define LDCTOUCH_REG_SENSOR0_CONFIG 0x20
88 #define LDCTOUCH_REG_SENSOR1_CONFIG 0x22
89 #define LDCTOUCH_REG_SENSOR2_CONFIG 0x24
90 #define LDCTOUCH_REG_FTF0 0x25
91 #define LDCTOUCH_REG_SENSOR3_CONFIG 0x26
92 #define LDCTOUCH_REG_FTF1_2 0x28
93 #define LDCTOUCH_REG_FTF3 0x2B
94 #define LDCTOUCH_REG_RAW_DATA0_3 0x59
95 #define LDCTOUCH_REG_RAW_DATA0_2 0x5A
96 #define LDCTOUCH_REG_RAW_DATA0_1 0x5B
97 #define LDCTOUCH_REG_RAW_DATA1_3 0x5C
98 #define LDCTOUCH_REG_RAW_DATA1_2 0x5D
99 #define LDCTOUCH_REG_RAW_DATA1_1 0x5E
100 #define LDCTOUCH_REG_RAW_DATA2_3 0x5F
101 #define LDCTOUCH_REG_RAW_DATA2_2 0x60
102 #define LDCTOUCH_REG_RAW_DATA2_1 0x61
103 #define LDCTOUCH_REG_RAW_DATA3_3 0x62
104 #define LDCTOUCH_REG_RAW_DATA3_2 0x63
105 #define LDCTOUCH_REG_RAW_DATA3_1 0x64
106 #define LDCTOUCH_REG_MANUFACTURER_ID_LSB 0xFC
107 #define LDCTOUCH_REG_MANUFACTURER_ID_MSB 0xFD
108 #define LDCTOUCH_REG_DEVICE_ID_LSB 0xFE
109 #define LDCTOUCH_REG_DEVICE_ID_MSB 0xFF
110  // ldctouch_reg
112 
127 #define LDCTOUCH_STATUS_OUT 0x80
128 #define LDCTOUCH_STATUS_CHIP_READY 0x40
129 #define LDCTOUCH_STATUS_READY_TO_WRITE 0x20
130 #define LDCTOUCH_STATUS_MAXOUT 0x10
131 #define LDCTOUCH_STATUS_FSM_WD 0x08
132 #define LDCTOUCH_STATUS_LC_WD 0x04
133 #define LDCTOUCH_STATUS_TIMEOUT 0x02
134 #define LDCTOUCH_STATUS_REGISTER_FLAG 0x01
135 
140 #define LDCTOUCH_MODE_NORMAL 0x00
141 #define LDCTOUCH_MODE_CONFIG 0x01
142 #define LDCTOUCH_MODE_FULL_RESET 0x10
143 
148 #define LDCTOUCH_EN_CH3_LP 0x80
149 #define LDCTOUCH_EN_CH2_LP 0x40
150 #define LDCTOUCH_EN_CH1_LP 0x20
151 #define LDCTOUCH_EN_CH0_LP 0x10
152 #define LDCTOUCH_EN_CH3_NP 0x08
153 #define LDCTOUCH_EN_CH2_NP 0x04
154 #define LDCTOUCH_EN_CH1_NP 0x02
155 #define LDCTOUCH_EN_CH0_NP 0x01
156 
161 #define LDCTOUCH_OPOL3_ACTIVE_HIGH 0x80
162 #define LDCTOUCH_OPOL3_ACTIVE_LOW 0x00
163 #define LDCTOUCH_OPOL2_ACTIVE_HIGH 0x40
164 #define LDCTOUCH_OPOL2_ACTIVE_LOW 0x00
165 #define LDCTOUCH_OPOL1_ACTIVE_HIGH 0x20
166 #define LDCTOUCH_OPOL1_ACTIVE_LOW 0x00
167 #define LDCTOUCH_OPOL0_ACTIVE_HIGH 0x10
168 #define LDCTOUCH_OPOL0_ACTIVE_LOW 0x00
169 #define LDCTOUCH_DPOL3_DATA_INCREASES 0x08
170 #define LDCTOUCH_DPOL3_DATA_DECREASES 0x00
171 #define LDCTOUCH_DPOL2_DATA_INCREASES 0x04
172 #define LDCTOUCH_DPOL2_DATA_DECREASES 0x00
173 #define LDCTOUCH_DPOL1_DATA_INCREASES 0x02
174 #define LDCTOUCH_DPOL1_DATA_DECREASES 0x00
175 #define LDCTOUCH_DPOL0_DATA_INCREASES 0x01
176 #define LDCTOUCH_DPOL0_DATA_DECREASES 0x00
177 
182 #define LDCTOUCH_BUTTON_MODE_FINGER 0x00
183 #define LDCTOUCH_BUTTON_MODE_METAL 0x01
184 #define LDCTOUCH_BUTTON_MODE LDCTOUCH_BUTTON_MODE_FINGER
185 
190 #define LDCTOUCH_MANUFACTURER_ID_LSB 0x49
191 #define LDCTOUCH_MANUFACTURER_ID_MSB 0x54
192 #define LDCTOUCH_DEVICE_ID_LSB 0x00
193 #define LDCTOUCH_DEVICE_ID_MSB 0x40
194 
200 #define LDCTOUCH_DEVICE_ADDRESS 0x2A
201  // ldctouch_set
203 
218 #define LDCTOUCH_MAP_MIKROBUS( cfg, mikrobus ) \
219  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
220  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
221  cfg.s2 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
222  cfg.s0 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
223  cfg.s1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
224  cfg.s3 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
225  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
226  // ldctouch_map // ldctouch
229 
234 typedef struct
235 {
236  // Input pins
237  digital_in_t s0;
238  digital_in_t s1;
239  digital_in_t s2;
240  digital_in_t s3;
241  digital_in_t int_pin;
243  // Modules
244  i2c_master_t i2c;
246  // I2C slave address
247  uint8_t slave_address;
249 } ldctouch_t;
250 
255 typedef struct
256 {
257  pin_name_t scl;
258  pin_name_t sda;
260  pin_name_t s0;
261  pin_name_t s1;
262  pin_name_t s2;
263  pin_name_t s3;
264  pin_name_t int_pin;
266  uint32_t i2c_speed;
267  uint8_t i2c_address;
270 
275 typedef struct
276 {
277  uint8_t status;
278  uint8_t out_state;
279  int16_t ch0_raw_button;
280  int16_t ch1_raw_button;
281  int16_t ch2_raw_button;
282  int16_t ch3_raw_button;
283 
285 
290 typedef enum
291 {
293  LDCTOUCH_ERROR = -1
294 
296 
313 
328 
342 
357 err_t ldctouch_generic_write ( ldctouch_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
358 
373 err_t ldctouch_generic_read ( ldctouch_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
374 
387 err_t ldctouch_write_register ( ldctouch_t *ctx, uint8_t reg, uint8_t data_in );
388 
401 err_t ldctouch_read_register ( ldctouch_t *ctx, uint8_t reg, uint8_t *data_out );
402 
412 
422 
432 
442 
452 
465 
479 err_t ldctouch_set_operation_mode ( ldctouch_t *ctx, uint8_t mode );
480 
493 err_t ldctouch_get_data ( ldctouch_t *ctx, ldctouch_data_t *button_data );
494 
495 #ifdef __cplusplus
496 }
497 #endif
498 #endif // LDCTOUCH_H
499  // ldctouch
501 
502 // ------------------------------------------------------------------------ END
ldctouch_get_s1_pin
uint8_t ldctouch_get_s1_pin(ldctouch_t *ctx)
LDC Touch get s1 pin function.
ldctouch_cfg_t::int_pin
pin_name_t int_pin
Definition: ldctouch.h:264
ldctouch_get_s0_pin
uint8_t ldctouch_get_s0_pin(ldctouch_t *ctx)
LDC Touch get s0 pin function.
ldctouch_get_data
err_t ldctouch_get_data(ldctouch_t *ctx, ldctouch_data_t *button_data)
LDC Touch get data function.
ldctouch_get_int_pin
uint8_t ldctouch_get_int_pin(ldctouch_t *ctx)
LDC Touch get int pin function.
ldctouch_t::i2c
i2c_master_t i2c
Definition: ldctouch.h:244
ldctouch_generic_read
err_t ldctouch_generic_read(ldctouch_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
LDC Touch I2C reading function.
ldctouch_data_t::ch0_raw_button
int16_t ch0_raw_button
Definition: ldctouch.h:279
ldctouch_return_value_t
ldctouch_return_value_t
LDC Touch Click return value data.
Definition: ldctouch.h:291
ldctouch_data_t::ch1_raw_button
int16_t ch1_raw_button
Definition: ldctouch.h:280
ldctouch_cfg_t::s0
pin_name_t s0
Definition: ldctouch.h:260
ldctouch_cfg_t::s1
pin_name_t s1
Definition: ldctouch.h:261
ldctouch_cfg_t
LDC Touch Click configuration object.
Definition: ldctouch.h:256
LDCTOUCH_ERROR
@ LDCTOUCH_ERROR
Definition: ldctouch.h:293
ldctouch_data_t::ch2_raw_button
int16_t ch2_raw_button
Definition: ldctouch.h:281
ldctouch_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: ldctouch.h:266
LDCTOUCH_OK
@ LDCTOUCH_OK
Definition: ldctouch.h:292
ldctouch_get_s3_pin
uint8_t ldctouch_get_s3_pin(ldctouch_t *ctx)
LDC Touch get s3 pin function.
ldctouch_t
LDC Touch Click context object.
Definition: ldctouch.h:235
ldctouch_t::s2
digital_in_t s2
Definition: ldctouch.h:239
ldctouch_t::slave_address
uint8_t slave_address
Definition: ldctouch.h:247
ldctouch_read_register
err_t ldctouch_read_register(ldctouch_t *ctx, uint8_t reg, uint8_t *data_out)
LDC Touch read register function.
ldctouch_cfg_t::i2c_address
uint8_t i2c_address
Definition: ldctouch.h:267
ldctouch_data_t::out_state
uint8_t out_state
Definition: ldctouch.h:278
ldctouch_cfg_t::scl
pin_name_t scl
Definition: ldctouch.h:257
ldctouch_data_t::ch3_raw_button
int16_t ch3_raw_button
Definition: ldctouch.h:282
ldctouch_t::s3
digital_in_t s3
Definition: ldctouch.h:240
ldctouch_cfg_setup
void ldctouch_cfg_setup(ldctouch_cfg_t *cfg)
LDC Touch configuration object setup function.
ldctouch_generic_write
err_t ldctouch_generic_write(ldctouch_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
LDC Touch I2C writing function.
ldctouch_init
err_t ldctouch_init(ldctouch_t *ctx, ldctouch_cfg_t *cfg)
LDC Touch initialization function.
ldctouch_cfg_t::sda
pin_name_t sda
Definition: ldctouch.h:258
ldctouch_data_t::status
uint8_t status
Definition: ldctouch.h:277
ldctouch_set_operation_mode
err_t ldctouch_set_operation_mode(ldctouch_t *ctx, uint8_t mode)
LDC Touch set operation mode function.
ldctouch_write_register
err_t ldctouch_write_register(ldctouch_t *ctx, uint8_t reg, uint8_t data_in)
LDC Touch write register function.
ldctouch_default_cfg
err_t ldctouch_default_cfg(ldctouch_t *ctx)
LDC Touch default configuration function.
ldctouch_t::int_pin
digital_in_t int_pin
Definition: ldctouch.h:241
ldctouch_t::s0
digital_in_t s0
Definition: ldctouch.h:237
ldctouch_get_s2_pin
uint8_t ldctouch_get_s2_pin(ldctouch_t *ctx)
LDC Touch get s2 pin function.
ldctouch_cfg_t::s2
pin_name_t s2
Definition: ldctouch.h:262
ldctouch_cfg_t::s3
pin_name_t s3
Definition: ldctouch.h:263
ldctouch_t::s1
digital_in_t s1
Definition: ldctouch.h:238
ldctouch_check_communication
err_t ldctouch_check_communication(ldctouch_t *ctx)
LDC Touch check communication function.
ldctouch_data_t
LDC Touch Click data object.
Definition: ldctouch.h:276